package com.ruoyi.demo.controller; import com.ruoyi.common.core.domain.R; import com.ruoyi.demo.constant.RedisContant; import com.ruoyi.demo.entity.TopologicalEnterpriseWd; import com.ruoyi.demo.entity.vo.TopologicalWdAceeptVo; import com.ruoyi.demo.service.TopologicalEnterpriseWdService; import com.ruoyi.demo.valida.TopologicalWdListGroup; 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.PostMapping; 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; /** * 点位评估:周边企业 */ @RestController @RequestMapping("/poi/topologicalEnterpriseWd") public class TopologicalEnterpriseWdController { @Autowired TopologicalEnterpriseWdService topologicalEnterpriseWdService; @Autowired RedisTemplate redisTemplate; /** * 获取周边企业网点列表 * @param topologicalWdAceeptVo * @return */ @GetMapping("/list") public R list(@Validated(value = {TopologicalWdListGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){ String md5 = topologicalWdAceeptVo.getHash(); //2.查看redis中是否存在有缓存 HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LIST).get(md5); if (wdCount != null) { return R.ok(wdCount); } HashMap list = topologicalEnterpriseWdService.list(topologicalWdAceeptVo); redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LIST).put(md5,list); redisTemplate.expire(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LIST,RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LIST_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(list); } @GetMapping("/logisticsList") public R logisticsList(@Validated(value = {TopologicalWdListGroup.class}) TopologicalWdAceeptVo topologicalWdAceeptVo){ String md5 = topologicalWdAceeptVo.getHash(); //2.查看redis中是否存在有缓存 HashMap wdCount = (HashMap) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LOGISTICS_LIST).get(md5); if (wdCount != null) { return R.ok(wdCount); } HashMap list = topologicalEnterpriseWdService.logisticsList(topologicalWdAceeptVo); redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LOGISTICS_LIST).put(md5,list); redisTemplate.expire(RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LOGISTICS_LIST,RedisContant.TOPOLOGICAL_ENTERPRISE_WD_LOGISTICS_LIST_TIME, TimeUnit.MINUTES); return R.ok(list); } }