selectDeptList 增加二级缓存

This commit is contained in:
wangliwen 2022-06-27 16:38:29 +08:00
parent d5e66e60b5
commit d7e947f086
2 changed files with 18 additions and 11 deletions

View File

@ -23,6 +23,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
@ -202,7 +203,7 @@ public class ResourceController {
// 效验数据 // 效验数据
logger.info("source:" + source); logger.info("source:" + source);
ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class); ValidatorUtils.validateEntity(dto, AddGroup.class, DefaultGroup.class);
if ("f".equals(source)) { if ("f" .equals(source)) {
dto.setDelFlag(2); // 来自前端页面 走审批流程 dto.setDelFlag(2); // 来自前端页面 走审批流程
} }
logger.info(dto.toString()); logger.info(dto.toString());

View File

@ -9,7 +9,6 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.google.common.collect.Lists;
import io.renren.common.constant.Constant; import io.renren.common.constant.Constant;
import io.renren.common.domain.Tsingtao_xhaProperties; import io.renren.common.domain.Tsingtao_xhaProperties;
import io.renren.common.service.impl.CrudServiceImpl; import io.renren.common.service.impl.CrudServiceImpl;
@ -33,12 +32,13 @@ import okhttp3.FormBody;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import org.bytedeco.opencv.presets.opencv_core;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils; import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -67,6 +67,8 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
private static final Logger logger = LoggerFactory.getLogger(ResourceServiceImpl.class); private static final Logger logger = LoggerFactory.getLogger(ResourceServiceImpl.class);
private static final String selectDeptListKey = "selectDeptList";
@Value("${project.place}") @Value("${project.place}")
private Integer projectPlace; private Integer projectPlace;
@ -141,10 +143,10 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
break; break;
} }
}); });
if (params.containsKey("selectType") && "1".equals(params.get("selectType").toString())) { // 创建者查询时 if (params.containsKey("selectType") && "1" .equals(params.get("selectType").toString())) { // 创建者查询时
wrapper.ne("del_flag", 1); wrapper.ne("del_flag", 1);
} else if (params.containsKey("selectType") && "0".equals(params.get("selectType").toString())) { } else if (params.containsKey("selectType") && "0" .equals(params.get("selectType").toString())) {
if (params.containsKey("delFlag") && !"".equals(params.get("delFlag").toString())) { if (params.containsKey("delFlag") && !"" .equals(params.get("delFlag").toString())) {
wrapper.eq("del_flag", params.get("delFlag")); wrapper.eq("del_flag", params.get("delFlag"));
} else { } else {
wrapper.in(true, "del_flag", 0, 5); wrapper.in(true, "del_flag", 0, 5);
@ -156,6 +158,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override @Override
@Transactional @Transactional
@CacheEvict(key = selectDeptListKey, allEntries = true)
public void insertWithAttrs(ResourceDTO dto) { public void insertWithAttrs(ResourceDTO dto) {
ResourceEntity resourceEntity = new ResourceEntity(); ResourceEntity resourceEntity = new ResourceEntity();
BeanUtils.copyProperties(dto, resourceEntity); BeanUtils.copyProperties(dto, resourceEntity);
@ -179,6 +182,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override @Override
@Transactional @Transactional
@CacheEvict(key = selectDeptListKey, allEntries = true)
public void deleteWithAttrs(JSONObject jsonObject) { public void deleteWithAttrs(JSONObject jsonObject) {
JSONArray jsonArray = jsonObject.getJSONArray("ids"); JSONArray jsonArray = jsonObject.getJSONArray("ids");
List<Long> idList = jsonArray.toJavaList(Long.class); List<Long> idList = jsonArray.toJavaList(Long.class);
@ -192,6 +196,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
@Override @Override
@Transactional @Transactional
@CacheEvict(key = selectDeptListKey, allEntries = true)
public void updateWithAttrs(ResourceDTO dto) { public void updateWithAttrs(ResourceDTO dto) {
ResourceEntity resourceEntity = new ResourceEntity(); ResourceEntity resourceEntity = new ResourceEntity();
BeanUtils.copyProperties(dto, resourceEntity); BeanUtils.copyProperties(dto, resourceEntity);
@ -257,7 +262,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
break; break;
case TSINGTAO_XHA: { case TSINGTAO_XHA: {
if ("基础设施".equals(resourceDTO.getType())) { // 基础设施 if ("基础设施" .equals(resourceDTO.getType())) { // 基础设施
logger.info("西海岸基础设施"); logger.info("西海岸基础设施");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
OkHttpClient client = new OkHttpClient(); OkHttpClient client = new OkHttpClient();
@ -527,6 +532,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
@Override @Override
@CachePut(cacheNames = {selectDeptListKey}, key = "#p0")
public Object selectDeptList(JSONObject jsonObject) { public Object selectDeptList(JSONObject jsonObject) {
ArrayList<Map> resultList = new ArrayList<>(); ArrayList<Map> resultList = new ArrayList<>();
HashMap<String, Object> resourceMap = new HashMap<>(); HashMap<String, Object> resourceMap = new HashMap<>();
@ -541,7 +547,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
Map<String, List<Map<String, Object>>> listMap = typeMapList.stream().collect(Collectors.groupingBy(m -> m.get("type").toString())); Map<String, List<Map<String, Object>>> listMap = typeMapList.stream().collect(Collectors.groupingBy(m -> m.get("type").toString()));
//区级要根据行政区划多加一层结构 //区级要根据行政区划多加一层结构
listMap.entrySet().stream().filter(index -> !"区级".equals(index.getKey())).forEach(item -> { listMap.entrySet().stream().filter(index -> !"区级" .equals(index.getKey())).forEach(item -> {
HashMap<String, Object> map = new HashMap<>(); HashMap<String, Object> map = new HashMap<>();
map.put("type", item.getKey()); map.put("type", item.getKey());
Integer integer = resourceDao.selectTypeCountByDept(item.getKey(), jsonObject.getString("type")); Integer integer = resourceDao.selectTypeCountByDept(item.getKey(), jsonObject.getString("type"));
@ -735,7 +741,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
} }
@Override @Override
public List<Map<String,Object>> applicationAreaCapabilityList(Map params){ public List<Map<String, Object>> applicationAreaCapabilityList(Map params) {
return resourceDao.applicationAreaCapabilityList(params); return resourceDao.applicationAreaCapabilityList(params);
} }
@ -866,7 +872,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
AttrEntity attrEntity = new AttrEntity(); AttrEntity attrEntity = new AttrEntity();
attrEntity.setDelFlag(0); attrEntity.setDelFlag(0);
attrEntity.setAttrType("文件类型"); attrEntity.setAttrType("文件类型");
if ("f49561afc7204f008c4bb3cd821eb6ba".equals(index)) { if ("f49561afc7204f008c4bb3cd821eb6ba" .equals(index)) {
attrEntity.setAttrValue("政府公报"); attrEntity.setAttrValue("政府公报");
} else { } else {
attrEntity.setAttrValue("政策解读"); attrEntity.setAttrValue("政策解读");
@ -1187,7 +1193,7 @@ public class ResourceServiceImpl extends CrudServiceImpl<ResourceDao, ResourceEn
"INNER JOIN tb_data_resource c ON a.resource_id = c.id \n" + "INNER JOIN tb_data_resource c ON a.resource_id = c.id \n" +
"WHERE b.dept_id = ? AND c.type = ?\n" + "WHERE b.dept_id = ? AND c.type = ?\n" +
"ORDER BY a.create_date DESC \n" + "ORDER BY a.create_date DESC \n" +
"LIMIT ?,?\n",ps); "LIMIT ?,?\n", ps);
return result; return result;
} }