ChannelAnalyseController.java 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.StoreWdCategoryCount;
  7. import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo;
  8. import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
  9. import com.ruoyi.demo.entity.vo.TagAnalyse;
  10. import com.ruoyi.demo.service.ChannelAnalyseService;
  11. import org.springframework.beans.factory.annotation.Autowired;
  12. import org.springframework.data.redis.core.RedisTemplate;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RestController;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.concurrent.TimeUnit;
  18. @RestController
  19. @RequestMapping("/channelAnalyse")
  20. public class ChannelAnalyseController {
  21. @Autowired
  22. ChannelAnalyseService channelAnalyseService;
  23. @Autowired
  24. RedisTemplate redisTemplate;
  25. @RequestMapping("/cityTier")
  26. public R cityTier(ChannelMapAceeptVo channelMapAceeptVo){
  27. String md5 = channelMapAceeptVo.getHash();
  28. //2.查看redis中是否存在有缓存
  29. HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).get(md5);
  30. if (wdCount != null) {
  31. return R.ok(wdCount);
  32. }
  33. HashMap hashMap = channelAnalyseService.cityTier(channelMapAceeptVo);
  34. //4.保存到redis中
  35. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).put(md5,hashMap);
  36. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CITYTIER,RedisContant.CHANNEL_ANALYSE_CITYTIER_TIME, TimeUnit.MINUTES); //30分钟
  37. return R.ok(hashMap);
  38. }
  39. @RequestMapping("/brandList")
  40. public R brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){
  41. String md5 = channelAnalyseAceeptVo.getHash();
  42. //2.查看redis中是否存在有缓存
  43. PageInfo<Brand> wdCount = (PageInfo<Brand>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).get(md5);
  44. if (wdCount != null) {
  45. return R.ok(wdCount);
  46. }
  47. PageInfo<Brand> brandPageInfo = channelAnalyseService.brandList(channelAnalyseAceeptVo);
  48. //4.保存到redis中
  49. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).put(md5,brandPageInfo);
  50. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BRANDLIST,RedisContant.CHANNEL_ANALYSE_BRANDLIST_TIME, TimeUnit.MINUTES); //30分钟
  51. return R.ok(brandPageInfo);
  52. }
  53. @RequestMapping("/category")
  54. public R category(ChannelMapAceeptVo channelMapAceeptVo){
  55. String md5 = channelMapAceeptVo.getHash();
  56. //2.查看redis中是否存在有缓存
  57. List<StoreWdCategoryCount> wdCount = (List<StoreWdCategoryCount>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).get(md5);
  58. if (wdCount != null) {
  59. return R.ok(wdCount);
  60. }
  61. List<StoreWdCategoryCount> category = channelAnalyseService.category(channelMapAceeptVo);
  62. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).put(md5,category);
  63. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CATEGORY,RedisContant.CHANNEL_ANALYSE_CATEGORY_TIME, TimeUnit.MINUTES); //30分钟
  64. return R.ok(category);
  65. }
  66. @RequestMapping("/tagAnalyse")
  67. public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  68. Integer page = channelMapAceeptVo.getPageNum() == null ? 1:channelMapAceeptVo.getPageNum();
  69. channelMapAceeptVo.setPageNum(0);
  70. String md5 = channelMapAceeptVo.getHash();
  71. //2.查看redis中是否存在有缓存
  72. HashMap<String, Object> result = new HashMap<>();
  73. HashMap<String,Object> wdCount = (HashMap<String,Object>) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).get(md5);
  74. if (wdCount != null) {
  75. result.put("data",(List<TagAnalyse>) wdCount.get(page + ""));
  76. result.put("pages",(int)wdCount.get("pages"));
  77. result.put("total",(int)wdCount.get("total"));
  78. return R.ok(result);
  79. }
  80. HashMap<String, Object> hashMap = channelAnalyseService.tagAnalyse(channelMapAceeptVo);
  81. //4.保存到redis中
  82. redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).put(md5,hashMap);
  83. redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE,RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE_TIME, TimeUnit.MINUTES); //30分钟
  84. result.put("data",(List<TagAnalyse>) hashMap.get(page + ""));
  85. result.put("pages",(int)hashMap.get("pages"));
  86. result.put("total",(int)hashMap.get("total"));
  87. return R.ok(result);
  88. }
  89. // @RequestMapping("/businessAnalyse")
  90. // public R businessAnalyse(ChannelMapAceeptVo channelMapAceeptVo){
  91. // channelAnalyseService.businessAnalyse(channelMapAceeptVo);
  92. // return R.ok();
  93. // }
  94. }