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

相关推荐
芯有所享4 小时前
【芯片设计中的版本管理:Git与SVN的实战选择指南】
经验分享·git·svn
开发者联盟league4 小时前
解决git报错 filename too long
git
Seven974 小时前
一致性Hash算法:如何实现分布式系统中的高效数据分片?
java
摇滚侠4 小时前
IDEA 生成 try catch 快捷键
java·ide·intellij-idea
Teable任意门互动4 小时前
AI原生开源多维表格有哪些?主流开源多维表格对比解析
数据库·开源·excel·钉钉·飞书·开源软件·ai-native
jian110584 小时前
android studiod git在git reset origin/main以后,会有删了又新建的导包问题
git
TDengine (老段)4 小时前
MNode 内部机制深度解析 — SDB、事务引擎与 DDL 处理全链路
大数据·数据库·物联网·时序数据库·iot·tdengine·涛思数据
这个DBA有点耶4 小时前
数据库上云 vs 自建:从成本到人力的三维对比与决策框架
数据库·经验分享·sql·创业创新·dba
阿旭超级学得完4 小时前
C++11包装器(function和bind)
java·开发语言·c++·算法·哈希算法·散列表
shizhan_cloud4 小时前
MySQL 索引优化 + 慢查询日志
数据库·mysql