苍穹外卖day05----店铺营业状态设置

一.需求分析

1.产品原型

2.接口设计

1.设置营业状态

2.管理端查询营业状态

3.用户端查询营业状态

4.数据库设计

这里使用Redis数据库

二.代码开发

管理端

复制代码
package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Slf4j
@Api("店铺相关接口")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    @PutMapping("/{status}")
    @ApiOperation("设置营业状态")
    public Result setStatus(@PathVariable Integer status){
        log.info("设置营业状态:{}",status == 1 ? "营业中" : "打烊中");
        redisTemplate.opsForValue().set("SHOP_STATUS",status);
        return Result.success();
    }
    @GetMapping("/status")
    @ApiOperation("查询营业状态")
    public Result<Integer> getStatus(){
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("查询营业状态:{}",shopStatus == 1 ? "营业中" : "打烊中");
        return Result.success(shopStatus);
    }
}

用户端

复制代码
package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController("userShopController")
@RequestMapping("/user/shop")
@Slf4j
@Api("店铺相关接口")
public class ShopController {
    @Autowired
    private RedisTemplate redisTemplate;
    @GetMapping("/status")
    @ApiOperation("查询营业状态")
    public Result<Integer> getStatus(){
        Integer shopStatus = (Integer) redisTemplate.opsForValue().get("SHOP_STATUS");
        log.info("查询营业状态:{}",shopStatus == 1 ? "营业中" : "打烊中");
        return Result.success(shopStatus);
    }
}

注意点:1.注意启动Redis数据库,否则会报错

2.注意bean容器不要重名,否则会发生冲突,这里重新定义了bean容器

相关推荐
Litluecat16 小时前
信创迁移:Oracle切换海量数据库,慢sql扫描
数据库·sql·oracle·信创·海量
AutumnWind042016 小时前
【Intelij IDEA使用手册】
java·ide·intellij-idea
消失在人海中17 小时前
Oracle的CURRENT REDO丢失,数据丢失风险分析
数据库·oracle
喵了几个咪17 小时前
选择第三方IAM还是自建权限体系?中小型后台系统权限架构决策指南
数据库·oracle·架构
就叫_这个吧17 小时前
Java注解、元注解、自定义注解定义及应用
java·开发语言·注解
你疯了抱抱我18 小时前
【Mac】vscode 配置 GD32E230CXXX 开发环境
ide·vscode·macos·嵌入式
Sam_Deep_Thinking18 小时前
聊聊Java中的of
java·开发语言·架构
Elastic 中国社区官方博客18 小时前
Kibana:使用 AI Chat 及 MCP 轻松创建 AI 原生仪表板
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·信息可视化
NE_STOP19 小时前
Docker--管理监控平台的应用
java
杨云龙UP19 小时前
Oracle Health Check巡检脚本使用SOP V2.0:从HTML原始报告→生成Word专业巡检报告→交付客户_2026-06-03
linux·运维·数据库·sql·oracle·报告·巡检