外卖项目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 * @return
*/ */
@Bean @Bean
public Docket docket() { public Docket docket1() {
log.info("swagger接口文档自动生成"); log.info("swagger接口文档自动生成");
ApiInfo apiInfo = new ApiInfoBuilder() ApiInfo apiInfo = new ApiInfoBuilder()
.title("苍穹外卖项目接口文档") .title("苍穹外卖项目接口文档")
@@ -66,14 +66,35 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
.description("苍穹外卖项目接口文档") .description("苍穹外卖项目接口文档")
.build(); .build();
Docket docket = new Docket(DocumentationType.SWAGGER_2) Docket docket = new Docket(DocumentationType.SWAGGER_2)
.groupName("管理端接口")
.apiInfo(apiInfo) .apiInfo(apiInfo)
.select() .select()
.apis(RequestHandlerSelectors.basePackage("com.sky.controller")) .apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
.paths(PathSelectors.any()) .paths(PathSelectors.any())
.build(); .build();
return docket; 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 * @param registry
@@ -6,15 +6,12 @@ import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@Api(tags = "店铺相关的接口") @Api(tags = "店铺相关的接口")
@Slf4j @Slf4j
@RequestMapping("/admin/shop/") @RequestMapping("/admin/shop/")
@RestController @RestController("adminShopController")
public class ShopController { public class ShopController {
public static final String SHOP_STATUS = "SHOP_STATUS"; public static final String SHOP_STATUS = "SHOP_STATUS";
@@ -30,4 +27,14 @@ public class ShopController {
redisTemplate.opsForValue().set(SHOP_STATUS,status); redisTemplate.opsForValue().set(SHOP_STATUS,status);
return Result.success(); 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);
}
}