提交 ba509ec1 作者: 沈振路

书城redis

上级 3c7fb018
...@@ -6,9 +6,11 @@ import com.rabbitmq.client.Channel; ...@@ -6,9 +6,11 @@ import com.rabbitmq.client.Channel;
import com.yaoyaozw.customer.constants.CustomerCommonConstant; import com.yaoyaozw.customer.constants.CustomerCommonConstant;
import com.yaoyaozw.customer.constants.RabbitCommonNameConstant; import com.yaoyaozw.customer.constants.RabbitCommonNameConstant;
import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO; import com.yaoyaozw.customer.dto.integration.IntegrationRequestDTO;
import com.yaoyaozw.customer.mapper.KanbanCommonMapper;
import com.yaoyaozw.customer.service.AccountOrderService; import com.yaoyaozw.customer.service.AccountOrderService;
import com.yaoyaozw.customer.service.CustomerDelayPublishService; import com.yaoyaozw.customer.service.CustomerDelayPublishService;
import com.yaoyaozw.customer.service.CustomerGraphicsService; import com.yaoyaozw.customer.service.CustomerGraphicsService;
import com.yaoyaozw.customer.vo.AuthInfoVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitListener; import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.ChannelCallback; import org.springframework.amqp.rabbit.core.ChannelCallback;
...@@ -20,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -20,6 +22,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.Calendar; import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/** /**
* @author wgh * @author wgh
...@@ -30,6 +35,8 @@ import java.util.Calendar; ...@@ -30,6 +35,8 @@ import java.util.Calendar;
@RequestMapping("/customer-service/test") @RequestMapping("/customer-service/test")
public class TestController { public class TestController {
private final static String STORE_ENTITY_REDIS_KEY = "STORE_NAME_MAP";
@Autowired @Autowired
private CustomerGraphicsService customerGraphicsService; private CustomerGraphicsService customerGraphicsService;
@Autowired @Autowired
...@@ -40,6 +47,8 @@ public class TestController { ...@@ -40,6 +47,8 @@ public class TestController {
private RabbitTemplate rabbitTemplate; private RabbitTemplate rabbitTemplate;
@Autowired @Autowired
private RedisTemplate<String, Object> redisTemplate; private RedisTemplate<String, Object> redisTemplate;
@Autowired
private KanbanCommonMapper kanbanCommonMapper;
@GetMapping("/CustomerTest") @GetMapping("/CustomerTest")
public void test(){ public void test(){
...@@ -85,52 +94,12 @@ public class TestController { ...@@ -85,52 +94,12 @@ public class TestController {
accountOrderService.activeUserByOrder(integrationRequestDTO); accountOrderService.activeUserByOrder(integrationRequestDTO);
} }
@GetMapping("/ygLimit") @GetMapping("/putRedisStore")
public void ygLimit(){ public void redisStore() {
List<AuthInfoVO> allStoreList = kanbanCommonMapper.getAllStoreList();
limit(); Map<String, String> storeMap = allStoreList.stream().collect(Collectors.toMap(AuthInfoVO::getStoreType, AuthInfoVO::getStoreTypeName));
redisTemplate.opsForHash().putAll(STORE_ENTITY_REDIS_KEY, storeMap);
}
private void limit() {
boolean go;
synchronized (rabbitTemplate) {
// 从redis查询计数
Object count = redisTemplate.opsForValue().get(CustomerCommonConstant.YANG_GUANG_ACCESS_LIMIT_REDIS_KEY);
if (ObjectUtil.isNull(count)) {
// redis中没有,设置0
redisTemplate.opsForValue().set(CustomerCommonConstant.YANG_GUANG_ACCESS_LIMIT_REDIS_KEY, 0);
count = 0;
}
log.info("当前count: {}", count);
long stamp = System.currentTimeMillis();
// 判断计数是否达到上限
go = (Integer)count < 40;
if (go) {
// 没有达到上限,发送消息并且计数加1
rabbitTemplate.convertAndSend(RabbitCommonNameConstant.OPERATE_COMMON_EXCHANGE, RabbitCommonNameConstant.YG_LIMIT_TTL_ROUTE_KEY, stamp);
redisTemplate.opsForValue().increment(CustomerCommonConstant.YANG_GUANG_ACCESS_LIMIT_REDIS_KEY);
}
}
if (!go) {
// 计数达到上限了,休眠30秒,递归调用
try {
log.info("达到上限, 休眠15秒");
Thread.sleep(15000);
limit();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@RabbitListener(queues = RabbitCommonNameConstant.YG_LIMIT_DEATH_QUEUE)
public void listener() {
log.info("消费");
redisTemplate.opsForValue().decrement(CustomerCommonConstant.YANG_GUANG_ACCESS_LIMIT_REDIS_KEY);
} }
} }
...@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.mapper; ...@@ -2,6 +2,7 @@ package com.yaoyaozw.customer.mapper;
import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.dynamic.datasource.annotation.DS;
import com.yaoyaozw.customer.entity.CrowdPackageCondition; import com.yaoyaozw.customer.entity.CrowdPackageCondition;
import com.yaoyaozw.customer.vo.AuthInfoVO;
import com.yaoyaozw.customer.vo.kanban.CommonCostSetupVo; import com.yaoyaozw.customer.vo.kanban.CommonCostSetupVo;
import com.yaoyaozw.customer.vo.kanban.CommonOptionResponseVO; import com.yaoyaozw.customer.vo.kanban.CommonOptionResponseVO;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
...@@ -55,4 +56,9 @@ public interface KanbanCommonMapper { ...@@ -55,4 +56,9 @@ public interface KanbanCommonMapper {
List<CommonCostSetupVo> getWechatCostSetup(@Param("appid")String appid); List<CommonCostSetupVo> getWechatCostSetup(@Param("appid")String appid);
/**
* @return {@link List}<{@link AuthInfoVO}>
*/
List<AuthInfoVO> getAllStoreList();
} }
...@@ -51,4 +51,11 @@ ...@@ -51,4 +51,11 @@
</select> </select>
<select id="getAllStoreList" resultType="com.yaoyaozw.customer.vo.AuthInfoVO">
select
store_name as storeTypeName,
store_type as storeType
from store_entity
where is_deleted = 0 and pct_type = 'PROFIT_PCT'
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论