ChannelMapController.java 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. package com.ruoyi.demo.controller;
  2. import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
  3. import com.github.pagehelper.PageInfo;
  4. import com.ruoyi.common.core.domain.R;
  5. import com.ruoyi.demo.constant.RedisContant;
  6. import com.ruoyi.demo.entity.AttentionPool;
  7. import com.ruoyi.demo.entity.WdInfo;
  8. import com.ruoyi.demo.entity.bo.*;
  9. import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
  10. import com.ruoyi.demo.mapper.AttentionPoolDao;
  11. import com.ruoyi.demo.service.ChannelMapService;
  12. import com.ruoyi.demo.valida.ChannelAreaGroup;
  13. import com.ruoyi.demo.valida.ChannelListGroup;
  14. import com.ruoyi.demo.valida.ChannelPointGroup;
  15. import org.springframework.beans.factory.annotation.Autowired;
  16. import org.springframework.data.redis.core.RedisTemplate;
  17. import org.springframework.validation.annotation.Validated;
  18. import org.springframework.web.bind.annotation.GetMapping;
  19. import org.springframework.web.bind.annotation.RequestMapping;
  20. import org.springframework.web.bind.annotation.RestController;
  21. import java.util.HashMap;
  22. import java.util.List;
  23. import java.util.concurrent.TimeUnit;
  24. import java.util.stream.Collectors;
  25. @RestController
  26. @RequestMapping("/channelMap")
  27. public class ChannelMapController {
  28. @Autowired
  29. private ChannelMapService channelMapService;
  30. @Autowired
  31. private RedisTemplate redisTemplate;
  32. @Autowired
  33. AttentionPoolDao attentionPoolDao;
  34. @RequestMapping("/getArea")
  35. public R area(@Validated(value={ChannelAreaGroup.class}) ChannelMapAceeptVo channel) {
  36. String md5 = channel.getHash();
  37. //2.查看redis中是否存在有缓存
  38. WdCount wdCount = (WdCount) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_AREA).get(md5);
  39. if (wdCount != null) {
  40. return R.ok(wdCount);
  41. }
  42. //3.redis中没有,直接请求
  43. WdCount area = channelMapService.area(channel);
  44. if(area == null)
  45. return R.fail("请求参数错误");
  46. //4.保存到redis中
  47. redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_AREA).put(md5,area);
  48. redisTemplate.expire(RedisContant.CHANNEL_MAP_AREA,RedisContant.CHANNEL_MAP_AREA_TIME, TimeUnit.MINUTES); //30分钟
  49. return R.ok(area);
  50. }
  51. @RequestMapping("/list")
  52. public R list(@Validated(value={ChannelListGroup.class}) ChannelMapAceeptVo channel){
  53. String md5 = channel.getHash();
  54. HashMap pageInfo = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).get(md5);
  55. if(pageInfo != null){
  56. List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) pageInfo.get("data");
  57. attention(data);
  58. pageInfo.put("data",data);
  59. return R.ok(pageInfo);
  60. }
  61. HashMap hashMap = channelMapService.list(channel);
  62. if(hashMap == null)
  63. return R.fail("请求参数错误");
  64. //4.保存到redis中
  65. List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) hashMap.get("data");
  66. attention(data);
  67. hashMap.put("data",data);
  68. redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).put(md5,hashMap);
  69. redisTemplate.expire(RedisContant.CHANNEL_MAP_LIST,RedisContant.CHANNEL_MAP_LIST_TIME, TimeUnit.MINUTES); //30分钟
  70. return R.ok(hashMap);
  71. }
  72. @RequestMapping("/point")
  73. public R point(@Validated(value={ChannelPointGroup.class}) ChannelMapAceeptVo channel){
  74. String md5 = channel.getHash();
  75. PageInfo<WdInfo> pageInfo = (PageInfo<WdInfo>) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_POINT).get(md5);
  76. if(pageInfo != null){
  77. return R.ok(pageInfo);
  78. }
  79. PageInfo<WdInfo> point = channelMapService.point(channel.getChannel(), channel.getSearchText(), channel.getAddrCode(), channel.getPageNum(), channel.getPageSize());
  80. if(point == null)
  81. return R.fail("请求参数错误");
  82. //4.保存到redis中
  83. redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_POINT).put(md5,point);
  84. redisTemplate.expire(RedisContant.CHANNEL_MAP_POINT,RedisContant.CHANNEL_MAP_POINT_TIME, TimeUnit.MINUTES); //30分钟
  85. return R.ok(point);
  86. }
  87. //Todo 标记网点关注
  88. public void attention(List<WdTopologicalInfoBo> wdTopologicalInfoBos){
  89. List<String> collect = wdTopologicalInfoBos.stream().map(wdTopologicalInfoBo -> {
  90. return wdTopologicalInfoBo.getWdId();
  91. }).collect(Collectors.toList());
  92. //标志是否关注
  93. QueryWrapper<AttentionPool> queryWrapper1 = new QueryWrapper<>();
  94. queryWrapper1.select("wd_id");
  95. queryWrapper1.in("wd_id",collect);
  96. if(collect.size() > 0){
  97. List<AttentionPool> attentionPools = attentionPoolDao.selectList(queryWrapper1);
  98. List<String> collect1 = attentionPools.stream().map(attentionPool -> {
  99. return attentionPool.getWdId();
  100. }).collect(Collectors.toList());
  101. for (WdTopologicalInfoBo wdTopologicalInfoBo : wdTopologicalInfoBos) {
  102. boolean contains = collect1.contains(wdTopologicalInfoBo.getWdId());
  103. if (contains)
  104. wdTopologicalInfoBo.setAttention(1);
  105. else
  106. wdTopologicalInfoBo.setAttention(0);
  107. }
  108. }
  109. }
  110. @GetMapping("/getWdInfo")
  111. public R getWdInfo(String wdId){
  112. WdInfo wdInfo = channelMapService.getWdInfo(wdId);
  113. if(wdInfo == null)
  114. return R.ok(null);
  115. if("1".equals(wdInfo.getWdTypeCode())){
  116. return R.ok((StoreWdInfoBo)wdInfo);
  117. }else if("2".equals(wdInfo.getWdTypeCode())){
  118. return R.ok((HouseWdInfoBo)wdInfo);
  119. }else if("3".equals(wdInfo.getWdTypeCode())){
  120. return R.ok((BuildWdInfoBo)wdInfo);
  121. }else if("4".equals(wdInfo.getWdTypeCode())){
  122. return R.ok((TrafficWdInfoBo)wdInfo);
  123. }else if("5".equals(wdInfo.getWdTypeCode())){
  124. return R.ok((EnterpriseWdInfoBo)wdInfo);
  125. }
  126. return R.ok(wdInfo);
  127. }
  128. }