123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- package com.ruoyi.demo.controller;
- import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
- import com.github.pagehelper.PageInfo;
- import com.ruoyi.common.core.domain.R;
- import com.ruoyi.demo.constant.RedisContant;
- import com.ruoyi.demo.entity.AttentionPool;
- import com.ruoyi.demo.entity.WdInfo;
- import com.ruoyi.demo.entity.bo.*;
- import com.ruoyi.demo.entity.vo.ChannelMapAceeptVo;
- import com.ruoyi.demo.mapper.AttentionPoolDao;
- import com.ruoyi.demo.service.ChannelMapService;
- import com.ruoyi.demo.valida.ChannelAreaGroup;
- import com.ruoyi.demo.valida.ChannelListGroup;
- import com.ruoyi.demo.valida.ChannelPointGroup;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.data.redis.core.RedisTemplate;
- import org.springframework.validation.annotation.Validated;
- import org.springframework.web.bind.annotation.GetMapping;
- import org.springframework.web.bind.annotation.RequestMapping;
- import org.springframework.web.bind.annotation.RestController;
- import java.util.HashMap;
- import java.util.List;
- import java.util.concurrent.TimeUnit;
- import java.util.stream.Collectors;
- @RestController
- @RequestMapping("/channelMap")
- public class ChannelMapController {
- @Autowired
- private ChannelMapService channelMapService;
- @Autowired
- private RedisTemplate redisTemplate;
- @Autowired
- AttentionPoolDao attentionPoolDao;
- @RequestMapping("/getArea")
- public R area(@Validated(value={ChannelAreaGroup.class}) ChannelMapAceeptVo channel) {
- String md5 = channel.getHash();
- //2.查看redis中是否存在有缓存
- WdCount wdCount = (WdCount) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_AREA).get(md5);
- if (wdCount != null) {
- return R.ok(wdCount);
- }
- //3.redis中没有,直接请求
- WdCount area = channelMapService.area(channel);
- if(area == null)
- return R.fail("请求参数错误");
- //4.保存到redis中
- redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_AREA).put(md5,area);
- redisTemplate.expire(RedisContant.CHANNEL_MAP_AREA,RedisContant.CHANNEL_MAP_AREA_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(area);
- }
- @RequestMapping("/list")
- public R list(@Validated(value={ChannelListGroup.class}) ChannelMapAceeptVo channel){
- String md5 = channel.getHash();
- HashMap pageInfo = (HashMap) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).get(md5);
- if(pageInfo != null){
- List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) pageInfo.get("data");
- attention(data);
- pageInfo.put("data",data);
- return R.ok(pageInfo);
- }
- HashMap hashMap = channelMapService.list(channel);
- if(hashMap == null)
- return R.fail("请求参数错误");
- //4.保存到redis中
- List<WdTopologicalInfoBo> data = (List<WdTopologicalInfoBo>) hashMap.get("data");
- attention(data);
- hashMap.put("data",data);
- redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_LIST).put(md5,hashMap);
- redisTemplate.expire(RedisContant.CHANNEL_MAP_LIST,RedisContant.CHANNEL_MAP_LIST_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(hashMap);
- }
- @RequestMapping("/point")
- public R point(@Validated(value={ChannelPointGroup.class}) ChannelMapAceeptVo channel){
- String md5 = channel.getHash();
- PageInfo<WdInfo> pageInfo = (PageInfo<WdInfo>) redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_POINT).get(md5);
- if(pageInfo != null){
- return R.ok(pageInfo);
- }
- PageInfo<WdInfo> point = channelMapService.point(channel.getChannel(), channel.getSearchText(), channel.getAddrCode(), channel.getPageNum(), channel.getPageSize());
- if(point == null)
- return R.fail("请求参数错误");
- //4.保存到redis中
- redisTemplate.boundHashOps(RedisContant.CHANNEL_MAP_POINT).put(md5,point);
- redisTemplate.expire(RedisContant.CHANNEL_MAP_POINT,RedisContant.CHANNEL_MAP_POINT_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(point);
- }
- //Todo 标记网点关注
- public void attention(List<WdTopologicalInfoBo> wdTopologicalInfoBos){
- List<String> collect = wdTopologicalInfoBos.stream().map(wdTopologicalInfoBo -> {
- return wdTopologicalInfoBo.getWdId();
- }).collect(Collectors.toList());
- //标志是否关注
- QueryWrapper<AttentionPool> queryWrapper1 = new QueryWrapper<>();
- queryWrapper1.select("wd_id");
- queryWrapper1.in("wd_id",collect);
- if(collect.size() > 0){
- List<AttentionPool> attentionPools = attentionPoolDao.selectList(queryWrapper1);
- List<String> collect1 = attentionPools.stream().map(attentionPool -> {
- return attentionPool.getWdId();
- }).collect(Collectors.toList());
- for (WdTopologicalInfoBo wdTopologicalInfoBo : wdTopologicalInfoBos) {
- boolean contains = collect1.contains(wdTopologicalInfoBo.getWdId());
- if (contains)
- wdTopologicalInfoBo.setAttention(1);
- else
- wdTopologicalInfoBo.setAttention(0);
- }
- }
- }
- @GetMapping("/getWdInfo")
- public R getWdInfo(String wdId){
- WdInfo wdInfo = channelMapService.getWdInfo(wdId);
- if(wdInfo == null)
- return R.ok(null);
- if("1".equals(wdInfo.getWdTypeCode())){
- return R.ok((StoreWdInfoBo)wdInfo);
- }else if("2".equals(wdInfo.getWdTypeCode())){
- return R.ok((HouseWdInfoBo)wdInfo);
- }else if("3".equals(wdInfo.getWdTypeCode())){
- return R.ok((BuildWdInfoBo)wdInfo);
- }else if("4".equals(wdInfo.getWdTypeCode())){
- return R.ok((TrafficWdInfoBo)wdInfo);
- }else if("5".equals(wdInfo.getWdTypeCode())){
- return R.ok((EnterpriseWdInfoBo)wdInfo);
- }
- return R.ok(wdInfo);
- }
- }
|