ChannelAnalyseController.java 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. package com.ruoyi.demo.controller;
  2. import com.github.pagehelper.PageInfo;
  3. import com.ruoyi.common.core.domain.R;
  4. import com.ruoyi.demo.constant.RedisContant;
  5. import com.ruoyi.demo.entity.Brand;
  6. import com.ruoyi.demo.entity.bo.Histogram;
  7. import com.ruoyi.demo.entity.bo.StoreWdCategoryCount;
  8. import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
  9. import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
  10. import com.ruoyi.demo.entity.vo.TagAnalyse;
  11. import com.ruoyi.demo.service.ChannelAnalyseService;
  12. import org.springframework.beans.factory.annotation.Autowired;
  13. import org.springframework.data.redis.core.RedisTemplate;
  14. import org.springframework.web.bind.annotation.GetMapping;
  15. import org.springframework.web.bind.annotation.RequestMapping;
  16. import org.springframework.web.bind.annotation.RestController;
  17. import java.util.ArrayList;
  18. import java.util.HashMap;
  19. import java.util.Hashtable;
  20. import java.util.List;
  21. import java.util.concurrent.TimeUnit;
  22. @RestController
  23. @RequestMapping("/channelAnalyse")
  24. public class ChannelAnalyseController {
  25. @Autowired
  26. ChannelAnalyseService channelAnalyseService;
  27. @Autowired
  28. RedisTemplate redisTemplate;
  29. @GetMapping("/cityTier")
  30. public R cityTier(ChannelMapAceeptVo channelMapAceeptVo){
  31. String md5 = channelMapAceeptVo.getHash();
  32. //2.查看redis中是否存在有缓存
  33. HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).get(md5);
  34. if (wdCount != null) {
  35. return R.ok(wdCount);
  36. }
  37. HashMap hashMap = channelAnalyseService.cityTier(channelMapAceeptVo);
  38. //4.保存到redis中
  39. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).put(md5,hashMap);
  40. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CITYTIER,RedisContant.CHANNEL_ANALYSE_CITYTIER_TIME, TimeUnit.MINUTES); //30分钟
  41. return R.ok(hashMap);
  42. }
  43. @GetMapping("/brandList")
  44. public R brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){
  45. String md5 = channelAnalyseAceeptVo.getHash();
  46. //2.查看redis中是否存在有缓存
  47. PageInfo<Brand> wdCount = (PageInfo<Brand>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).get(md5);
  48. if (wdCount != null) {
  49. return R.ok(wdCount);
  50. }
  51. PageInfo<Brand> brandPageInfo = channelAnalyseService.brandList(channelAnalyseAceeptVo);
  52. //4.保存到redis中
  53. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).put(md5,brandPageInfo);
  54. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BRANDLIST,RedisContant.CHANNEL_ANALYSE_BRANDLIST_TIME, TimeUnit.MINUTES); //30分钟
  55. return R.ok(brandPageInfo);
  56. }
  57. @GetMapping("/category")
  58. public R category(ChannelMapAceeptVo channelMapAceeptVo){
  59. String md5 = channelMapAceeptVo.getHash();
  60. //2.查看redis中是否存在有缓存
  61. List<StoreWdCategoryCount> wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).get(md5);
  62. if (wdCount != null) {
  63. return R.ok(wdCount);
  64. }
  65. List<StoreWdCategoryCount> category = channelAnalyseService.category(channelMapAceeptVo);
  66. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).put(md5,category);
  67. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CATEGORY,RedisContant.CHANNEL_ANALYSE_CATEGORY_TIME, TimeUnit.MINUTES); //30分钟
  68. return R.ok(category);
  69. }
  70. @GetMapping("/tagAnalyse")
  71. public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  72. Integer page = channelMapAceeptVo.getPageNum() == null ? 1:channelMapAceeptVo.getPageNum();
  73. channelMapAceeptVo.setPageNum(0);
  74. String md5 = channelMapAceeptVo.getHash();
  75. //2.查看redis中是否存在有缓存
  76. HashMap<String, Object> result = new HashMap<>();
  77. HashMap<String,Object> wdCount = (HashMap<String,Object>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).get(md5);
  78. if (wdCount != null) {
  79. result.put("data",(List<TagAnalyse>) wdCount.get(page + ""));
  80. result.put("pages",(int)wdCount.get("pages"));
  81. result.put("total",(int)wdCount.get("total"));
  82. return R.ok(result);
  83. }
  84. HashMap<String, Object> hashMap = channelAnalyseService.tagAnalyse(channelMapAceeptVo);
  85. //4.保存到redis中
  86. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).put(md5,hashMap);
  87. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE,RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE_TIME, TimeUnit.MINUTES); //30分钟
  88. result.put("data",(List<TagAnalyse>) hashMap.get(page + ""));
  89. result.put("pages",(int)hashMap.get("pages"));
  90. result.put("total",(int)hashMap.get("total"));
  91. return R.ok(result);
  92. }
  93. @GetMapping("/businessStatusAnalyse")
  94. public R businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  95. String md5 = channelMapAceeptVo.getHash();
  96. //2.查看redis中是否存在有缓存
  97. // HashMap<String,Integer> wdCount = (HashMap<String,Integer>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5);
  98. // if (wdCount != null) {
  99. // return R.ok(wdCount);
  100. // }
  101. HashMap<String,Integer> hashMap = channelAnalyseService.businessStatusAnalyse(channelMapAceeptVo);
  102. //4.保存到redis中
  103. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).put(md5,hashMap);
  104. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE,RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
  105. return R.ok(hashMap);
  106. }
  107. @GetMapping("/aroundBuildAnalyse")
  108. public R aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  109. String md5 = channelMapAceeptVo.getHash();
  110. //2.查看redis中是否存在有缓存
  111. ArrayList<Histogram> wdCount = (ArrayList<Histogram>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).get(md5);
  112. if (wdCount != null) {
  113. return R.ok(wdCount);
  114. }
  115. ArrayList<Histogram> hashtable = channelAnalyseService.aroundBuildAnalyse(channelMapAceeptVo);
  116. //4.保存到redis中
  117. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).put(md5,hashtable);
  118. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE,RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
  119. return R.ok(hashtable);
  120. }
  121. @GetMapping("/perCapitaConsumpAnalyse")
  122. public R perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  123. String md5 = channelMapAceeptVo.getHash();
  124. //2.查看redis中是否存在有缓存
  125. ArrayList<Histogram> wdCount = (ArrayList<Histogram>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE).get(md5);
  126. if (wdCount != null) {
  127. return R.ok(wdCount);
  128. }
  129. ArrayList<Histogram> hashtable = channelAnalyseService.perCapitaConsumpAnalyse(channelMapAceeptVo);
  130. //4.保存到redis中
  131. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE).put(md5,hashtable);
  132. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE,RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
  133. return R.ok(hashtable);
  134. }
  135. @GetMapping("/operateTimeAnalyse")
  136. public R operateTimeAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  137. String md5 = channelMapAceeptVo.getHash();
  138. //2.查看redis中是否存在有缓存
  139. ArrayList<Histogram> wdCount = (ArrayList<Histogram>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE).get(md5);
  140. if (wdCount != null) {
  141. return R.ok(wdCount);
  142. }
  143. ArrayList<Histogram> hashtable = channelAnalyseService.operateTimeAnalyse(channelMapAceeptVo);
  144. //4.保存到redis中
  145. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE).put(md5,hashtable);
  146. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE,RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟
  147. return R.ok(hashtable);
  148. }
  149. }