TopologicalStoreWdController.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. package com.ruoyi.demo.controller;
  2. import com.ruoyi.common.core.domain.R;
  3. import com.ruoyi.demo.constant.RedisContant;
  4. import com.ruoyi.demo.entity.TopologicalStoreWd;
  5. import com.ruoyi.demo.entity.bo.HeatMapBo;
  6. import com.ruoyi.demo.entity.bo.Histogram;
  7. import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
  8. import com.ruoyi.demo.entity.vo.TopologicalWdAceeptVo;
  9. import com.ruoyi.demo.service.TopologicalStoreWdService;
  10. import com.ruoyi.demo.valida.TopologicalWdGroup;
  11. import com.ruoyi.demo.valida.TopologicalWdListGroup;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.data.redis.core.RedisTemplate;
  14. import org.springframework.validation.annotation.Validated;
  15. import org.springframework.web.bind.annotation.GetMapping;
  16. import org.springframework.web.bind.annotation.RequestMapping;
  17. import org.springframework.web.bind.annotation.RestController;
  18. import java.util.HashMap;
  19. import java.util.List;
  20. import java.util.concurrent.TimeUnit;
  21. /**
  22. * 点位评估模块:
  23. */
  24. @RestController
  25. @RequestMapping("/poi/topologicalStoreWd")
  26. public class TopologicalStoreWdController {
  27. @Autowired
  28. TopologicalStoreWdService topologicalStoreWdService;
  29. @Autowired
  30. RedisTemplate redisTemplate;
  31. /**
  32. * 获取周边网点分类
  33. * @param topologicalWdAceeptVo
  34. * @return
  35. */
  36. @GetMapping("/category")
  37. public R category(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
  38. //1.查看redis中是否存在有缓存
  39. String md5 = topologicalWdAceeptVo.getHash();
  40. List<StoreWdCategoryCount>wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY).get(md5);
  41. if (wdCount != null) {
  42. return R.ok(wdCount);
  43. }
  44. //2.查询结果
  45. List<StoreWdCategoryCount> category = topologicalStoreWdService.category(topologicalWdAceeptVo);
  46. //3.存入redis
  47. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY).put(md5,category);
  48. redisTemplate.expire(RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY, RedisContant.TOPOLOGICAL_STORE_WD_CATEGORY_TIME, TimeUnit.MINUTES); //30分钟
  49. return R.ok(category);
  50. }
  51. /**
  52. * 获取周边门店网点列表
  53. * @param topologicalWdAceeptVo
  54. * @return
  55. */
  56. @GetMapping("/list")
  57. public R list(@Validated(value = {TopologicalWdListGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
  58. //1.查看redis中是否存在有缓存
  59. String md5 = topologicalWdAceeptVo.getHash();
  60. HashMap<String,Object> wdCount = (HashMap<String,Object>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_LIST).get(md5);
  61. if (wdCount != null) {
  62. return R.ok(wdCount);
  63. }
  64. //2.获取数据
  65. HashMap<String,Object> list = topologicalStoreWdService.list(topologicalWdAceeptVo);
  66. //3.存储redis
  67. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_LIST).put(md5,list);
  68. redisTemplate.expire(RedisContant.TOPOLOGICAL_STORE_WD_LIST,RedisContant.TOPOLOGICAL_STORE_WD_LIST_TIME, TimeUnit.MINUTES); //30分钟
  69. return R.ok(list);
  70. }
  71. /**
  72. * 获取商业网点分类数量统计
  73. * @param topologicalWdAceeptVo
  74. * @return
  75. */
  76. @GetMapping("/storeHistogram")
  77. public R storeHistogram(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
  78. //1.查看redis中是否存在有缓存
  79. String md5 = topologicalWdAceeptVo.getHash();
  80. List<Histogram> wdCount = (List<Histogram>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_STORE_HISTOGRAM).get(md5);
  81. if (wdCount != null) {
  82. return R.ok(wdCount);
  83. }
  84. //2.获取数据
  85. List<Histogram> list = topologicalStoreWdService.storeHistogram(topologicalWdAceeptVo);
  86. //3.存入redis
  87. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_STORE_HISTOGRAM).put(md5,list);
  88. redisTemplate.expire(RedisContant.TOPOLOGICAL_STORE_WD_STORE_HISTOGRAM,RedisContant.TOPOLOGICAL_STORE_WD_STORE_HISTOGRAM_TIME, TimeUnit.MINUTES); //30分钟
  89. return R.ok(list);
  90. }
  91. /**
  92. * 获取门店人均消费
  93. * @param topologicalWdAceeptVo
  94. * @return
  95. */
  96. @GetMapping("/perCapitaConsumpHistogram")
  97. public R perCapitaConsumpHistogram(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
  98. //1.查看redis中是否存在有缓存
  99. String md5 = topologicalWdAceeptVo.getHash();
  100. List<Histogram> wdCount = (List<Histogram>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_PER_CAPITA_CONSUMP_HISTOGRAM).get(md5);
  101. if (wdCount != null) {
  102. return R.ok(wdCount);
  103. }
  104. //2.获取数据
  105. List<Histogram> list = topologicalStoreWdService.perCapitaConsumpHistogram(topologicalWdAceeptVo);
  106. //存入redis
  107. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_PER_CAPITA_CONSUMP_HISTOGRAM).put(md5,list);
  108. redisTemplate.expire(RedisContant.TOPOLOGICAL_STORE_WD_PER_CAPITA_CONSUMP_HISTOGRAM,RedisContant.TOPOLOGICAL_STORE_WD_PER_CAPITA_CONSUMP_HISTOGRAM_TIME, TimeUnit.MINUTES); //30分钟
  109. return R.ok(list);
  110. }
  111. /**
  112. * 获取门店人均消费
  113. * @param topologicalWdAceeptVo
  114. * @return
  115. */
  116. @GetMapping("/heatMap")
  117. public R heatMap(@Validated(value = {TopologicalWdGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){
  118. //1.查看redis中是否存在有缓存
  119. String md5 = topologicalWdAceeptVo.getHash();
  120. List<HeatMapBo> wdCount = (List<HeatMapBo>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_HEAT_MAP).get(md5);
  121. if (wdCount != null) {
  122. return R.ok(wdCount);
  123. }
  124. //2.获取数据
  125. List<HeatMapBo> heatMapBos = topologicalStoreWdService.heatMap(topologicalWdAceeptVo);
  126. //存入redis
  127. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_STORE_WD_HEAT_MAP).put(md5,heatMapBos);
  128. redisTemplate.expire(RedisContant.TOPOLOGICAL_STORE_WD_HEAT_MAP,RedisContant.TOPOLOGICAL_STORE_WD_HEAT_MAP_TIME, TimeUnit.MINUTES); //30分钟
  129. return R.ok(heatMapBos);
  130. }
  131. }