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

相关推荐
o丁二黄o4 分钟前
【MyBatisPlus】MyBatisPlus介绍与使用
java
_MyFavorite_7 分钟前
JAVA重点基础、进阶知识及易错点总结(14)字节流 & 字符流
java·开发语言·python
TDengine (老段)12 分钟前
TDengine IDMP 工业数据建模 —— 元素与数据查询
大数据·数据库·人工智能·物联网·时序数据库·tdengine·涛思数据
蜡台12 分钟前
Mysql 安装与配置
数据库·mysql
zs宝来了13 分钟前
Redis 网络模型:IO 多路复用与 ae 事件循环
redis·epoll·事件循环·io多路复用·网络模型
lajidecrd13 分钟前
Ubuntu24安装PostgreSQL和PgVector
数据库·postgresql
羊小猪~~14 分钟前
Redis学习笔记(数据类型、持久化、事件、管道、发布订阅等)
开发语言·数据库·c++·redis·后端·学习·缓存
福娃筱欢20 分钟前
Oracle迁移KES提示ERROR: type “geometry“ does not exist
数据库·oracle
2501_9160088923 分钟前
iOS开发者工具有哪些?Xcode、Fastlane 与 kxapp 的组合使用
ide·vscode·macos·ios·个人开发·xcode·敏捷流程
mldlds23 分钟前
使用 Qt 插件和 SQLCipher 实现 SQLite 数据库加密与解密
数据库·qt·sqlite