123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- package com.ruoyi.demo.controller;
- import com.ruoyi.common.core.domain.R;
- import com.ruoyi.demo.constant.RedisContant;
- import com.ruoyi.demo.entity.AddrCategory;
- import com.ruoyi.demo.entity.bo.WdCount;
- import com.ruoyi.demo.entity.vo.AddrCategoryBody;
- import com.ruoyi.demo.entity.vo.TypeByBody;
- import com.ruoyi.demo.service.CommonService;
- 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.List;
- import java.util.concurrent.TimeUnit;
- /**
- * 基础功能-下拉框
- */
- @RestController
- @RequestMapping("/common")
- public class CommonController {
- @Autowired
- CommonService commonService;
- @Autowired
- RedisTemplate redisTemplate;
- /**
- * 获取犇云分类下拉框
- * @return
- */
- @GetMapping("/tag")
- public R tag(){
- //1.查看redis中是否已存在
- List<TypeByBody> wdCount = (List<TypeByBody>) redisTemplate.boundValueOps(RedisContant.COMMON_TAG).get();
- if (wdCount != null) {
- return R.ok(wdCount);
- }
- //2.查询数据
- List<TypeByBody> tag = commonService.tag();
- //3.保存到redis中
- redisTemplate.boundValueOps(RedisContant.COMMON_TAG).set(tag);
- redisTemplate.expire(RedisContant.COMMON_TAG,RedisContant.COMMON_TAG_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(tag);
- }
- /**
- * 获取地区码下拉框
- * @return
- */
- @GetMapping("/addrCodeMap")
- public R addrCodeMap(){
- //1.查看redis中是否存在数据
- List<AddrCategoryBody> wdCount = (List<AddrCategoryBody>) redisTemplate.boundValueOps(RedisContant.COMMON_ADDR_CODE_MAP).get();
- if (wdCount != null) {
- return R.ok(wdCount);
- }
- //2.查询数据
- List<AddrCategoryBody> addrCategoryBodies = commonService.addrCodeMap();
- //3.存入redis
- redisTemplate.boundValueOps(RedisContant.COMMON_ADDR_CODE_MAP).set(wdCount);
- redisTemplate.expire(RedisContant.COMMON_ADDR_CODE_MAP,RedisContant.COMMON_ADDR_CODE_MAP_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(addrCategoryBodies);
- }
- /**
- * 分等级(省、市、区)查询地区
- * @param code 地区Code:level=province(不需要)、level=city(code=省码)、level=zone(code=市码)
- * @param level 搜索等级:province(查询全省)、city(查某个省的市)、zone(查某个市的区)
- * @return
- */
- @GetMapping("/addrCodeLevel")
- public R addrCodeLevel(String code,String level){
- //1.查看redis中是否存在数据
- List<AddrCategory> wdCount = (List<AddrCategory> ) redisTemplate.boundHashOps(RedisContant.COMMON_LEVEL).get(code+level);
- if (wdCount != null) {
- return R.ok(wdCount);
- }
- //2查询数据
- List<AddrCategory> addrCategories = commonService.addrCodeLevel(code,level);
- //3.存入redis
- redisTemplate.boundHashOps(RedisContant.COMMON_LEVEL).put(code+level,addrCategories);
- redisTemplate.expire(RedisContant.COMMON_LEVEL,RedisContant.COMMON_LEVEL_TIME, TimeUnit.MINUTES); //30分钟
- return R.ok(addrCategories);
- }
- }
|