设置店铺营业状态
This commit is contained in:
parent
cf32a6bd8f
commit
2a3d46113e
|
@ -3,23 +3,30 @@ package com.sky.config;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Configurable;
|
import org.springframework.beans.factory.annotation.Configurable;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||||
|
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
|
||||||
import org.springframework.data.redis.core.RedisTemplate;
|
import org.springframework.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
@Configurable
|
@Configuration
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class RedisConfiguration {
|
public class RedisConfiguration {
|
||||||
@Resource
|
|
||||||
RedisTemplate<String, String> redisTemplate;
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) {
|
public RedisTemplate<String, Object> redisTemplate(LettuceConnectionFactory lettuceConnectionFactory) {
|
||||||
// 设置redis的连接工厂对象
|
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
redisTemplate.setConnectionFactory(lettuceConnectionFactory);
|
||||||
|
// 设置key序列化为string
|
||||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||||
|
// 设置value序列化为JSON,使用GenericJackson2JsonRedisSerializer替换默认序列化
|
||||||
|
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||||
|
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||||
|
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||||
|
|
||||||
return redisTemplate;
|
return redisTemplate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
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.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController("adminShopController")
|
||||||
|
@RequestMapping("/admin/shop")
|
||||||
|
@Api(tags = "店铺相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
public static final String KEY = "SHOP_STATUS";
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 设置店铺营业状态
|
||||||
|
*
|
||||||
|
* @param status 状态
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@ApiOperation("设置店铺营业状态")
|
||||||
|
@PutMapping("/{status}")
|
||||||
|
public Result<String> setStatus(@PathVariable Integer status) {
|
||||||
|
log.info("设置店铺营业状态:{}", status == 1 ? "营业中" : "打样中");
|
||||||
|
redisTemplate.opsForValue().set(KEY, status);
|
||||||
|
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation(("获取店铺营业状态"))
|
||||||
|
@GetMapping("/{status}")
|
||||||
|
public Result<Integer> getStatus() {
|
||||||
|
Integer status = (Integer) 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.data.redis.core.RedisTemplate;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
@RestController("userShopController")
|
||||||
|
@RequestMapping("/admin/user")
|
||||||
|
@Api(tags = "用户店铺相关接口")
|
||||||
|
@Slf4j
|
||||||
|
public class ShopController {
|
||||||
|
public static final String KEY = "SHOP_STATUS";
|
||||||
|
@Resource
|
||||||
|
private RedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@ApiOperation("设置店铺营业状态")
|
||||||
|
@GetMapping("/{status}")
|
||||||
|
public Result setStatus(@PathVariable Integer status) {
|
||||||
|
log.info("设置店铺营业状态:{}", status == 1 ? "营业中" : "打样中");
|
||||||
|
redisTemplate.opsForValue().set(KEY, status);
|
||||||
|
return Result.success();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue