完成店铺营业状态设置功能
This commit is contained in:
parent
1dd0b6fe93
commit
45509ea96e
@ -0,0 +1,23 @@
|
||||
package com.sky.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class RedisConfiguration {
|
||||
@Bean
|
||||
public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
||||
log.info("开始创建redis模板对象...");
|
||||
RedisTemplate redisTemplate = new RedisTemplate();
|
||||
// 设置连接工厂
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
// 设置key的序列化器
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
@ -47,17 +47,36 @@ public class WebMvcConfiguration extends WebMvcConfigurationSupport {
|
||||
* @return
|
||||
*/
|
||||
@Bean
|
||||
public Docket docket() {
|
||||
public Docket docket1() {
|
||||
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"))
|
||||
.apis(RequestHandlerSelectors.basePackage("com.sky.controller.admin"))
|
||||
.paths(PathSelectors.any())
|
||||
.build();
|
||||
return docket;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Docket docket2() {
|
||||
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;
|
||||
|
@ -0,0 +1,42 @@
|
||||
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")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
public static final String KEY = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
/**
|
||||
* 设置店铺营业状态
|
||||
* @param status 1:营业中,0:打烊中
|
||||
* @return
|
||||
*/
|
||||
@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);
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
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.*;
|
||||
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/user/shop")
|
||||
@Api(tags = "店铺相关接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
public static final String KEY = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取店铺营业状态")
|
||||
public Result<Integer> getStatus() {
|
||||
Integer status = (Integer) redisTemplate.opsForValue().get(KEY);
|
||||
log.info("获取店铺营业状态为:{}", status == 1 ? "营业中" : "打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
@ -11,3 +11,7 @@ sky:
|
||||
access-key-secret: YyUv8YJZjHStekVVoh8ilpCevL2NY4
|
||||
endpoint: oss-cn-guangzhou.aliyuncs.com
|
||||
bucket-name: sky-take-out-1919810
|
||||
redis:
|
||||
host: localhost
|
||||
port: 6379
|
||||
database: 1
|
||||
|
@ -12,6 +12,10 @@ spring:
|
||||
url: jdbc:mysql://${sky.datasource.host}:${sky.datasource.port}/${sky.datasource.database}?serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&allowPublicKeyRetrieval=true
|
||||
username: ${sky.datasource.username}
|
||||
password: ${sky.datasource.password}
|
||||
redis:
|
||||
host: ${sky.redis.host}
|
||||
port: ${sky.redis.port}
|
||||
database: ${sky.redis.database}
|
||||
|
||||
mybatis:
|
||||
#mapper配置文件
|
||||
|
Loading…
Reference in New Issue
Block a user