店铺营业状态接口
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -4,4 +4,4 @@
|
||||
*.class
|
||||
*Test.java
|
||||
**/test/
|
||||
*dev.properties
|
||||
resources/application-dev.properties
|
||||
@@ -0,0 +1,25 @@
|
||||
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);
|
||||
//设置序列化器
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
redisTemplate.setValueSerializer(new StringRedisSerializer());
|
||||
return redisTemplate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController("adminShopController")
|
||||
@RequestMapping("/admin/shop")
|
||||
@Api(tags = "店铺操作接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
private static final String KEY = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@PutMapping("/{status}")
|
||||
@ApiOperation("设置营业状态")
|
||||
public Result setStatus(@PathVariable String status) {
|
||||
log.info("设置店铺营业状态为: {}",status.equals("1") ? "营业中":"打烊中");
|
||||
redisTemplate.opsForValue().set(KEY, status);
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
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.*;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@RestController("userShopController")
|
||||
@RequestMapping("/admin/user")
|
||||
@Api(tags = "店铺操作接口")
|
||||
@Slf4j
|
||||
public class ShopController {
|
||||
|
||||
private static final String KEY = "SHOP_STATUS";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate redisTemplate;
|
||||
|
||||
@GetMapping("/status")
|
||||
@ApiOperation("获取营业状态")
|
||||
public Result<Integer> getStatus(){
|
||||
int status = Integer.parseInt((String) Objects.requireNonNull(redisTemplate.opsForValue().get(KEY)));
|
||||
log.info("获取到营业状态为: {}", status == 1 ? "营业中" : "打烊中");
|
||||
return Result.success(status);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user