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

相关推荐
解道Jdon14 小时前
VSCode 2026年2月更新:技能市场、CLI、钩子支持
ide·windows·git·svn·eclipse·github·visual studio
焦糖玛奇朵婷14 小时前
实测扭蛋机小程序:开发简单,互动有趣
java·大数据·程序人生·小程序·软件需求
Nan_Shu_61414 小时前
学习: 尚硅谷Java项目之小谷充电宝(3)
java·后端·学习
沙漏无语14 小时前
(二)TIDB搭建正式集群
linux·数据库·tidb
wzqllwy14 小时前
8 大经典排序算法(Java 实现):原理 + Demo + 核心分析
java·算法·排序算法
智能工业品检测-奇妙智能14 小时前
AIFlowy如何实现与现有Spring Boot项目的无缝集成?
java·spring boot·后端
linux修理工14 小时前
VSCODE 使用LMSTUDIO本地显卡amd588 开发app
ide·vscode·编辑器
從南走到北14 小时前
JAVA无人共享无人健身房物联网结合系统源码支持小程序+公众号+APP+H5
java·物联网·小程序
姚不倒14 小时前
三节点 TiDB 集群部署与负载均衡搭建实战
运维·数据库·分布式·负载均衡·tidb
Nuopiane14 小时前
MyPal3(3)
java·开发语言