一、产品原型
二、接口设计
设置营业状态
管理端查询营业状态
用户端查询营业状态
三、数据存储方式
基于Redis的字符串来进行存储
1表示营业 0表示打烊
四、代码开发
1、在shopController中编写方法
@RestController("adminShopController") //管理端 用户端一样设置,改下名称
@RequestMapping("/admin/shop")
@Api(tags = "店铺相关接口")
@Slf4j
public class ShopController {
public static final String key = "SHOP_STATUS";
@Autowired
private RedisTemplate redisTemplate;
//设置店铺营业状态
@PutMapping("/{status}")
@ApiOperation("设置店铺营业状态")
public Result setStatus(@PathVariable Integer status){
log.info("设置店铺的营业状态:{}",status == 1? "营业中":"打烊中");
redisTemplate.opsForValue().set(key,status);
return Result.success();
}
//获取店铺营业状态
@GetMapping("/status")
@ApiOperation("获取店铺营业状态")
public Result<Integer> getStatus(){
Integer status = (Integer) redisTemplate.opsForValue().get(key);
log.info("获取到店铺的营业状态为:{}",status==1?"营业中":"打烊中");
return Result.success(status);
}
}