外卖项目day05-店铺营业状态设置和实现----2

This commit is contained in:
xx
2026-11-29 14:46:43 +08:00
parent 50b31cd5c5
commit b150d3edc1
3 changed files with 68 additions and 7 deletions
@@ -58,7 +58,7 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
* @return
*/
@Bean
public Docket docket() {
public Docket docket1() {
log.info("swagger接口文档自动生成");
ApiInfo apiInfo = new ApiInfoBuilder()
.title("苍穹外卖项目接口文档")
@@ -66,14 +66,35 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
.description("苍穹外卖项目接口文档")
.build();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName("管理端接口")
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.sky.controller"))
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
.paths(PathSelectors.any())
.build();
return docket;
}
@Bean
public Docket docket2() {
log.info("swagger接口文档自动生成");
ApiInfo apiInfo = new ApiInfoBuilder()
.title("苍穹外卖项目接口文档")
.version("2.0")
.description("苍穹外卖项目接口文档")
.build();
Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName("用户端接口")
.apiInfo(apiInfo)
.select()
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.user"))
.paths(PathSelectors.any())
.build();
return docket;
}
/**
* 设置静态资源映射
* @param registry
@@ -6,15 +6,12 @@ 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.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
@Api(tags = "店铺相关的接口")
@Slf4j
@RequestMapping("/admin/shop/")
@RestController
@RestController("adminShopController")
public class ShopController {
public static final String SHOP_STATUS = "SHOP_STATUS";
@@ -30,4 +27,14 @@ public class ShopController {
redisTemplate.opsForValue().set(SHOP_STATUS,status);
return Result.success();
}
@GetMapping("/status")
@ApiOperation("获取营业状态")
public Result<Integer> getStatus(){
//直接获取redis中的key对应的值!!!
Integer status = (Integer)redisTemplate.opsForValue().get(SHOP_STATUS);
log.info("获取营业状态:{}",status==1?"营业中":"打烊中");
return Result.success(status);
}
}
@@ -0,0 +1,33 @@
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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import static com.sky.controller.admin.ShopController.SHOP_STATUS;
@Api(tags = "店铺相关的接口")
@Slf4j
@RequestMapping("/user/shop/")
@RestController(value = "userShopController")
public class ShopController {
@Autowired
private RedisTemplate redisTemplate;
@GetMapping("/status")
@ApiOperation("获取营业状态")
public Result<Integer> getStatus(){
//直接获取redis中的key对应的值!!!
Integer status = (Integer)redisTemplate.opsForValue().get(SHOP_STATUS);
log.info("获取营业状态:{}",status==1?"营业中":"打烊中");
return Result.success(status);
}
}