package com.ruoyi.demo.controller; import com.github.pagehelper.PageInfo; import com.ruoyi.common.core.domain.R; import com.ruoyi.demo.constant.RedisContant; import com.ruoyi.demo.entity.Brand; import com.ruoyi.demo.entity.bo.Histogram; import com.ruoyi.demo.entity.bo.StoreWdCategoryCount; import com.ruoyi.demo.entity.vo.ChannelAnalyseAceeptVo; import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo; import com.ruoyi.demo.entity.vo.TagAnalyse; import com.ruoyi.demo.service.ChannelAnalyseService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import java.util.ArrayList; import java.util.HashMap; import java.util.Hashtable; import java.util.List; import java.util.concurrent.TimeUnit; @RestController @RequestMapping("/channelAnalyse") public class ChannelAnalyseController { @Autowired ChannelAnalyseService channelAnalyseService; @Autowired RedisTemplate redisTemplate; @GetMapping("/cityTier") public R cityTier(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).get(md5); if (wdCount != null) { return R.ok(wdCount); } HashMap hashMap = channelAnalyseService.cityTier(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CITYTIER).put(md5,hashMap); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CITYTIER,RedisContant.CHANNEL_ANALYSE_CITYTIER_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(hashMap); } @GetMapping("/brandList") public R brandList(ChannelAnalyseAceeptVo channelAnalyseAceeptVo){ String md5 = channelAnalyseAceeptVo.getHash(); //2.查看redis中是否存在有缓存 PageInfo wdCount = (PageInfo) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).get(md5); if (wdCount != null) { return R.ok(wdCount); } PageInfo brandPageInfo = channelAnalyseService.brandList(channelAnalyseAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BRANDLIST).put(md5,brandPageInfo); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BRANDLIST,RedisContant.CHANNEL_ANALYSE_BRANDLIST_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(brandPageInfo); } @GetMapping("/category") public R category(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 List wdCount = (List) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).get(md5); if (wdCount != null) { return R.ok(wdCount); } List category = channelAnalyseService.category(channelMapAceeptVo); redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_CATEGORY).put(md5,category); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_CATEGORY,RedisContant.CHANNEL_ANALYSE_CATEGORY_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(category); } @GetMapping("/tagAnalyse") public R tagAnalyse(ChannelMapAceeptVo channelMapAceeptVo){ Integer page = channelMapAceeptVo.getPageNum() == null ? 1:channelMapAceeptVo.getPageNum(); channelMapAceeptVo.setPageNum(0); String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 HashMap result = new HashMap<>(); HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).get(md5); if (wdCount != null) { result.put("data",(List) wdCount.get(page + "")); result.put("pages",(int)wdCount.get("pages")); result.put("total",(int)wdCount.get("total")); return R.ok(result); } HashMap hashMap = channelAnalyseService.tagAnalyse(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE).put(md5,hashMap); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE,RedisContant.CHANNEL_ANALYSE_TAG_ANLYSE_TIME, TimeUnit.MINUTES); //30分钟 result.put("data",(List) hashMap.get(page + "")); result.put("pages",(int)hashMap.get("pages")); result.put("total",(int)hashMap.get("total")); return R.ok(result); } @GetMapping("/businessStatusAnalyse") public R businessStatusAnalyse(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).get(md5); if (wdCount != null) { return R.ok(wdCount); } HashMap hashMap = channelAnalyseService.businessStatusAnalyse(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE).put(md5,hashMap); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE,RedisContant.CHANNEL_ANALYSE_BUSINESS_STATUS_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(hashMap); } @GetMapping("/aroundBuildAnalyse") public R aroundBuildAnalyse(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 ArrayList wdCount = (ArrayList) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).get(md5); if (wdCount != null) { return R.ok(wdCount); } ArrayList hashtable = channelAnalyseService.aroundBuildAnalyse(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE).put(md5,hashtable); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE,RedisContant.CHANNEL_ANALYSE_AROUND_BUILD_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(hashtable); } @GetMapping("/perCapitaConsumpAnalyse") public R perCapitaConsumpAnalyse(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 ArrayList wdCount = (ArrayList) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE).get(md5); if (wdCount != null) { return R.ok(wdCount); } ArrayList hashtable = channelAnalyseService.perCapitaConsumpAnalyse(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE).put(md5,hashtable); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE,RedisContant.CHANNEL_ANALYSE_PER_CAPITA_CONSUMP_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(hashtable); } @GetMapping("/operateTimeAnalyse") public R operateTimeAnalyse(ChannelMapAceeptVo channelMapAceeptVo){ String md5 = channelMapAceeptVo.getHash(); //2.查看redis中是否存在有缓存 ArrayList wdCount = (ArrayList) redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE).get(md5); if (wdCount != null) { return R.ok(wdCount); } ArrayList hashtable = channelAnalyseService.operateTimeAnalyse(channelMapAceeptVo); //4.保存到redis中 redisTemplate.boundHashOps(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE).put(md5,hashtable); redisTemplate.expire(RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE,RedisContant.CHANNEL_ANALYSE_OPERATE_TIME_ANALYSE_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(hashtable); } }