fix: 优化逻辑
This commit is contained in:
parent
fb54991df1
commit
3ecc8ccf8b
@ -1,5 +1,7 @@
|
||||
package com.yfd.platform.config;
|
||||
|
||||
import cn.hutool.crypto.digest.DigestUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@ -23,6 +25,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
@ -61,9 +64,9 @@ public class RedisConfig {
|
||||
.entryTtl(Duration.ofMinutes(30));
|
||||
|
||||
Map<String, RedisCacheConfiguration> cacheConfigs = new HashMap<>();
|
||||
cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6)));
|
||||
cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5)));
|
||||
cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2)));
|
||||
// cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6)));
|
||||
// cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5)));
|
||||
// cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2)));
|
||||
|
||||
return RedisCacheManager.builder(redisConnectionFactory)
|
||||
.cacheDefaults(defaultConfig)
|
||||
@ -92,10 +95,15 @@ public class RedisConfig {
|
||||
sb.append(param != null ? param.toString() : "null");
|
||||
sb.append(",");
|
||||
}
|
||||
if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') {
|
||||
if (!sb.isEmpty() && sb.charAt(sb.length() - 1) == ',') {
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
}
|
||||
return sb.toString();
|
||||
};
|
||||
}
|
||||
|
||||
@Bean("cacheKeyGenerator")
|
||||
public KeyGenerator cacheKeyGenerator() {
|
||||
return (target, method, params) -> target.getClass().getName() + "." + method.getName() + ":" + DigestUtil.md5Hex(JSONUtil.toJsonStr(params));
|
||||
}
|
||||
}
|
||||
@ -106,25 +106,25 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "engInfoCache", key = "'eng:baseId:' + #baseId")
|
||||
@Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdEngInfoBH> getByBaseId(String baseId) {
|
||||
return engInfoBHMapper.selectByBaseId(baseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "engInfoCache", key = "'eng:hycd:' + #hycd")
|
||||
@Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdEngInfoBH> getByHycd(String hycd) {
|
||||
return engInfoBHMapper.selectByHycd(hycd);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "engInfoCache", key = "'eng:rvcd:' + #rvcd + ':' + #reachcd")
|
||||
@Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdEngInfoBH> getByRvcd(String rvcd,String reachcd) {
|
||||
return engInfoBHMapper.selectByRvcd(rvcd,reachcd);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "engInfoCache", key = "'eng:dropdown:' + #sdEngInfoBHRequest.baseId + ':' + #sdEngInfoBHRequest.hbrvcd + ':' + #sdEngInfoBHRequest.rvcd + ':' + #sdEngInfoBHRequest.reachcd + ':' + #sdEngInfoBHRequest.ennm")
|
||||
@Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdEngInfoBH> selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) {
|
||||
String baseId = sdEngInfoBHRequest.getBaseId();
|
||||
String hbrvcd = sdEngInfoBHRequest.getHbrvcd();
|
||||
|
||||
@ -29,7 +29,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "dictCache", key = "'hycd:phycd:' + #phycd")
|
||||
@Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdHycdDic> getByPhycd(String phycd) {
|
||||
return this.lambdaQuery()
|
||||
.eq(SdHycdDic::getPhycd, phycd)
|
||||
@ -38,7 +38,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "dictCache", key = "'hycd:root'")
|
||||
@Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdHycdDic> getRootList() {
|
||||
return this.lambdaQuery()
|
||||
.eq(SdHycdDic::getPhycd, "0")
|
||||
@ -47,25 +47,25 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "dictCache", allEntries = true)
|
||||
@CacheEvict(cacheNames = "hycdCache", allEntries = true)
|
||||
public boolean addHycdDic(SdHycdDic hycdDic) {
|
||||
return this.save(hycdDic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "dictCache", allEntries = true)
|
||||
@CacheEvict(cacheNames = "hycdCache", allEntries = true)
|
||||
public boolean updateHycdDic(SdHycdDic hycdDic) {
|
||||
return this.updateById(hycdDic);
|
||||
}
|
||||
|
||||
@Override
|
||||
@CacheEvict(cacheNames = "dictCache", allEntries = true)
|
||||
@CacheEvict(cacheNames = "hycdCache", allEntries = true)
|
||||
public boolean deleteHycdDic(String hycd) {
|
||||
return this.removeById(hycd);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "dictCache", keyGenerator = "customKeyGenerator")
|
||||
@Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdHycdDic> selectForDropdown(String hynm, Integer grd, Integer lx,String phycd) {
|
||||
return this.lambdaQuery()
|
||||
.like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm)
|
||||
@ -77,7 +77,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
|
||||
}
|
||||
|
||||
@Override
|
||||
@Cacheable(cacheNames = "dictCache", keyGenerator = "customKeyGenerator")
|
||||
@Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
|
||||
public List<SdHycdDic> regDropdown(String hynm, Integer grd,Integer lx,String phycd) {
|
||||
return this.lambdaQuery()
|
||||
.like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user