Commit b73413d2 authored by tangwei's avatar tangwei

增加字典缓存

parent bbf58d98
package com.yeejoin.amos.boot.biz.common.utils;
/**
* @description:
* @author: tw
* @createDate: 2021/6/22
* redis key
*/
public class RedisKey {
//动态表单
public static final String FORM = "form_";
//数据字典
public static final String DATADICTIONARY= "dataDictionary_";
}
package com.yeejoin.amos.boot.module.jcs.biz.controller; package com.yeejoin.amos.boot.module.jcs.biz.controller;
import com.yeejoin.amos.boot.biz.common.utils.RedisKey;
import com.yeejoin.amos.boot.biz.common.utils.RedisUtils; import com.yeejoin.amos.boot.biz.common.utils.RedisUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
...@@ -112,8 +113,8 @@ public class AlertFormController extends BaseController { ...@@ -112,8 +113,8 @@ public class AlertFormController extends BaseController {
@ApiOperation(httpMethod = "GET", value = "根据表态类型code查询表单数据项", notes = "根据表态类型code查询表单数据项") @ApiOperation(httpMethod = "GET", value = "根据表态类型code查询表单数据项", notes = "根据表态类型code查询表单数据项")
public ResponseModel selectFormdItem(HttpServletRequest request, @PathVariable String code){ public ResponseModel selectFormdItem(HttpServletRequest request, @PathVariable String code){
List<AlertFormVo> list=new ArrayList<AlertFormVo>(); List<AlertFormVo> list=new ArrayList<AlertFormVo>();
if(redisUtils.hasKey("form_"+code)){ if(redisUtils.hasKey(RedisKey.FORM+code)){
Object obj= redisUtils.get("form_"+code); Object obj= redisUtils.get(RedisKey.FORM+code);
return CommonResponseUtil.success(obj); return CommonResponseUtil.success(obj);
}else{ }else{
QueryWrapper queryWrapper = new QueryWrapper<>(); QueryWrapper queryWrapper = new QueryWrapper<>();
...@@ -121,7 +122,7 @@ public class AlertFormController extends BaseController { ...@@ -121,7 +122,7 @@ public class AlertFormController extends BaseController {
//警情动态表单数据 //警情动态表单数据
List<AlertForm> alertFormValue = iAlertFormService.list(queryWrapper); List<AlertForm> alertFormValue = iAlertFormService.list(queryWrapper);
list= FormList.getFormlist(alertFormValue); list= FormList.getFormlist(alertFormValue);
redisUtils.set("form_"+code,JSON.toJSON(list),86400); redisUtils.set(RedisKey.FORM+code,JSON.toJSON(list),86400);
return CommonResponseUtil.success(list); return CommonResponseUtil.success(list);
} }
} }
......
package com.yeejoin.amos.boot.module.jcs.biz.controller; package com.yeejoin.amos.boot.module.jcs.biz.controller;
import com.alibaba.fastjson.JSON;
import com.yeejoin.amos.boot.biz.common.utils.*;
import com.yeejoin.amos.boot.module.jcs.api.entity.AlertForm;
import com.yeejoin.amos.boot.module.jcs.api.vo.FormList;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
...@@ -15,10 +19,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage; ...@@ -15,10 +19,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yeejoin.amos.boot.module.jcs.api.entity.DataDictionary; import com.yeejoin.amos.boot.module.jcs.api.entity.DataDictionary;
import com.yeejoin.amos.boot.biz.common.utils.CommonResponseUtil;
import com.yeejoin.amos.boot.biz.common.utils.Menu;
import com.yeejoin.amos.boot.biz.common.utils.NameUtils;
import com.yeejoin.amos.boot.biz.common.utils.TreeParser;
import org.typroject.tyboot.core.restful.doc.TycloudOperation; import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseModel; import org.typroject.tyboot.core.restful.utils.ResponseModel;
...@@ -43,7 +43,8 @@ public class DataDictionaryController extends BaseController { ...@@ -43,7 +43,8 @@ public class DataDictionaryController extends BaseController {
@Autowired @Autowired
IDataDictionaryService iDataDictionaryService; IDataDictionaryService iDataDictionaryService;
@Autowired
RedisUtils redisUtils;
/** /**
* 新增数据字典 * 新增数据字典
* @return * @return
...@@ -152,9 +153,16 @@ public class DataDictionaryController extends BaseController { ...@@ -152,9 +153,16 @@ public class DataDictionaryController extends BaseController {
QueryWrapper queryWrapper = new QueryWrapper<>(); QueryWrapper queryWrapper = new QueryWrapper<>();
queryWrapper.eq("type", type); queryWrapper.eq("type", type);
queryWrapper.orderByAsc("sort_num"); queryWrapper.orderByAsc("sort_num");
Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper);
List<Menu> menus =TreeParser.getTree(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent"); if(redisUtils.hasKey(RedisKey.DATADICTIONARY+type)){
return CommonResponseUtil.success(menus); Object obj= redisUtils.get(RedisKey.DATADICTIONARY+type);
return CommonResponseUtil.success(obj);
}else{
Collection<DataDictionary> list=iDataDictionaryService.list(queryWrapper);
List<Menu> menus =TreeParser.getTree(null, list, DataDictionary.class.getName(),"getCode",0, "getName", "getParent");
redisUtils.set(RedisKey.DATADICTIONARY+type, JSON.toJSON(menus),86400);
return CommonResponseUtil.success(menus);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment