TopologicalCommonController.java 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package com.ruoyi.demo.controller;
  2. import com.ruoyi.common.core.domain.R;
  3. import com.ruoyi.demo.constant.RedisContant;
  4. import com.ruoyi.demo.entity.WdInfo;
  5. import com.ruoyi.demo.entity.vo.TopologicalWdAceeptVo;
  6. import com.ruoyi.demo.service.TopologicalCommonService;
  7. import com.ruoyi.demo.service.WdInfoService;
  8. import io.swagger.v3.oas.models.security.SecurityScheme;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.data.redis.core.RedisTemplate;
  11. import org.springframework.web.bind.annotation.RequestMapping;
  12. import org.springframework.web.bind.annotation.RestController;
  13. import java.util.HashMap;
  14. import java.util.List;
  15. import java.util.concurrent.TimeUnit;
  16. @RestController
  17. @RequestMapping("/poi/common")
  18. public class TopologicalCommonController {
  19. @Autowired
  20. TopologicalCommonService topologicalCommonService;
  21. @Autowired
  22. WdInfoService wdInfoService;
  23. @Autowired
  24. RedisTemplate redisTemplate;
  25. @RequestMapping("/prefixSearch")
  26. public R prefixSearch(String searchText,Integer size){
  27. List<WdInfo> wdInfos = topologicalCommonService.prefixSearch(searchText,size);
  28. return R.ok(wdInfos);
  29. }
  30. @RequestMapping("/range")
  31. public R range(){
  32. HashMap hashMap = new HashMap<>();
  33. hashMap.put("500m",500);
  34. hashMap.put("1km",1000);
  35. hashMap.put("2km",2000);
  36. return R.ok(hashMap);
  37. }
  38. @RequestMapping("/map")
  39. public R map(TopologicalWdAceeptVo topologicalWdAceeptVo){
  40. String md5 = topologicalWdAceeptVo.getHash();
  41. //2.查看redis中是否存在有缓存
  42. List<WdInfo> wdCount = (List<WdInfo>) redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_COMMON_MAP).get(md5);
  43. if (wdCount != null) {
  44. return R.ok(wdCount);
  45. }
  46. List<WdInfo> map = topologicalCommonService.map(topologicalWdAceeptVo);
  47. redisTemplate.boundHashOps(RedisContant.TOPOLOGICAL_COMMON_MAP).put(md5,map);
  48. redisTemplate.expire(RedisContant.TOPOLOGICAL_COMMON_MAP,RedisContant.TOPOLOGICAL_COMMON_MAP_TIME, TimeUnit.MINUTES); //30分钟
  49. return R.ok(map);
  50. }
  51. }