苍穹外卖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容器

相关推荐
arronKler1 天前
大数据量高并发的数据库优化
服务器·数据库·oracle
祖传F871 天前
SQL DATE()函数会抹去时间戳
数据库·sql
LiLiYuan.1 天前
【Java 6种线程状态】
java·开发语言
untE EADO1 天前
在 MySQL 中使用 `REPLACE` 函数
android·数据库·mysql
Absurd5871 天前
Redis如何限制列表最大长度_利用LTRIM指令截断List保留最新记录
jvm·数据库·python
2401_882273721 天前
SQL函数面试题解析_函数性能与设计考点
jvm·数据库·python
l1t1 天前
DeepSeek总结的DuckDB internals 的 设计与实现 (DiDi)
数据库·duckdb
a9511416421 天前
mysql查询分析中如何快速识别全表扫描_通过EXPLAIN中的type列检查
jvm·数据库·python
coNh OOSI1 天前
Redis——Windows安装
数据库·windows·redis
weixin_424999361 天前
mysql如何防止索引被错误使用_mysql查询计划强制约束
jvm·数据库·python