package com.ruoyi.demo.controller; import com.ruoyi.common.core.domain.R; import com.ruoyi.demo.constant.RedisContant; import com.ruoyi.demo.entity.WdInfo; import com.ruoyi.demo.entity.vo.TopologicalWdAceeptVo; import com.ruoyi.demo.service.TopologicalCommonService; import com.ruoyi.demo.service.WdInfoService; import io.swagger.v3.oas.models.security.SecurityScheme; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.RedisTemplate; 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/common") public class TopologicalCommonController { @Autowired TopologicalCommonService topologicalCommonService; @Autowired WdInfoService wdInfoService; @Autowired RedisTemplate redisTemplate; @RequestMapping("/prefixSearch") public R prefixSearch(String searchText,Integer size){ List wdInfos = topologicalCommonService.prefixSearch(searchText,size); return R.ok(wdInfos); } @RequestMapping("/range") public R range(){ HashMap hashMap = new HashMap<>(); hashMap.put("500m",500); hashMap.put("1km",1000); hashMap.put("2km",2000); return R.ok(hashMap); } @RequestMapping("/map") public R map(TopologicalWdAceeptVo topologicalWdAceeptVo){ String md5 = topologicalWdAceeptVo.getHash(); //2.查看redis中是否存在有缓存 List wdCount = (List) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_COMMON_MAP).get(md5); if (wdCount != null) { return R.ok(wdCount); } List map = topologicalCommonService.map(topologicalWdAceeptVo); redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_COMMON_MAP).put(md5,map); redisTemplate.expire(RedisContant.TOPOLOGICAL_COMMON_MAP,RedisContant.TOPOLOGICAL_COMMON_MAP_TIME, TimeUnit.MINUTES); //30分钟 return R.ok(map); } }