fix: 优化逻辑

This commit is contained in:
tangwei 2026-07-03 10:27:57 +08:00
parent fb54991df1
commit 3ecc8ccf8b
3 changed files with 23 additions and 15 deletions

View File

@ -1,5 +1,7 @@
package com.yfd.platform.config; 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.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor; import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
@ -23,6 +25,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
import java.time.Duration; import java.time.Duration;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
@Configuration @Configuration
@EnableCaching @EnableCaching
@ -61,9 +64,9 @@ public class RedisConfig {
.entryTtl(Duration.ofMinutes(30)); .entryTtl(Duration.ofMinutes(30));
Map<String, RedisCacheConfiguration> cacheConfigs = new HashMap<>(); Map<String, RedisCacheConfiguration> cacheConfigs = new HashMap<>();
cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6))); // cacheConfigs.put("dictCache", defaultConfig.entryTtl(Duration.ofHours(6)));
cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5))); // cacheConfigs.put("dataCache", defaultConfig.entryTtl(Duration.ofMinutes(5)));
cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2))); // cacheConfigs.put("engInfoCache", defaultConfig.entryTtl(Duration.ofHours(2)));
return RedisCacheManager.builder(redisConnectionFactory) return RedisCacheManager.builder(redisConnectionFactory)
.cacheDefaults(defaultConfig) .cacheDefaults(defaultConfig)
@ -92,10 +95,15 @@ public class RedisConfig {
sb.append(param != null ? param.toString() : "null"); sb.append(param != null ? param.toString() : "null");
sb.append(","); sb.append(",");
} }
if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ',') { if (!sb.isEmpty() && sb.charAt(sb.length() - 1) == ',') {
sb.deleteCharAt(sb.length() - 1); sb.deleteCharAt(sb.length() - 1);
} }
return sb.toString(); return sb.toString();
}; };
} }
@Bean("cacheKeyGenerator")
public KeyGenerator cacheKeyGenerator() {
return (target, method, params) -> target.getClass().getName() + "." + method.getName() + ":" + DigestUtil.md5Hex(JSONUtil.toJsonStr(params));
}
} }

View File

@ -106,25 +106,25 @@ public class SdEngInfoBHServiceImpl extends ServiceImpl<SdEngInfoBHMapper, SdEng
} }
@Override @Override
@Cacheable(cacheNames = "engInfoCache", key = "'eng:baseId:' + #baseId") @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdEngInfoBH> getByBaseId(String baseId) { public List<SdEngInfoBH> getByBaseId(String baseId) {
return engInfoBHMapper.selectByBaseId(baseId); return engInfoBHMapper.selectByBaseId(baseId);
} }
@Override @Override
@Cacheable(cacheNames = "engInfoCache", key = "'eng:hycd:' + #hycd") @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdEngInfoBH> getByHycd(String hycd) { public List<SdEngInfoBH> getByHycd(String hycd) {
return engInfoBHMapper.selectByHycd(hycd); return engInfoBHMapper.selectByHycd(hycd);
} }
@Override @Override
@Cacheable(cacheNames = "engInfoCache", key = "'eng:rvcd:' + #rvcd + ':' + #reachcd") @Cacheable(cacheNames = "engInfoCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdEngInfoBH> getByRvcd(String rvcd,String reachcd) { public List<SdEngInfoBH> getByRvcd(String rvcd,String reachcd) {
return engInfoBHMapper.selectByRvcd(rvcd,reachcd); return engInfoBHMapper.selectByRvcd(rvcd,reachcd);
} }
@Override @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) { public List<SdEngInfoBH> selectForDropdown(SdEngInfoBHRequest sdEngInfoBHRequest) {
String baseId = sdEngInfoBHRequest.getBaseId(); String baseId = sdEngInfoBHRequest.getBaseId();
String hbrvcd = sdEngInfoBHRequest.getHbrvcd(); String hbrvcd = sdEngInfoBHRequest.getHbrvcd();

View File

@ -29,7 +29,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
} }
@Override @Override
@Cacheable(cacheNames = "dictCache", key = "'hycd:phycd:' + #phycd") @Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdHycdDic> getByPhycd(String phycd) { public List<SdHycdDic> getByPhycd(String phycd) {
return this.lambdaQuery() return this.lambdaQuery()
.eq(SdHycdDic::getPhycd, phycd) .eq(SdHycdDic::getPhycd, phycd)
@ -38,7 +38,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
} }
@Override @Override
@Cacheable(cacheNames = "dictCache", key = "'hycd:root'") @Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdHycdDic> getRootList() { public List<SdHycdDic> getRootList() {
return this.lambdaQuery() return this.lambdaQuery()
.eq(SdHycdDic::getPhycd, "0") .eq(SdHycdDic::getPhycd, "0")
@ -47,25 +47,25 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
} }
@Override @Override
@CacheEvict(cacheNames = "dictCache", allEntries = true) @CacheEvict(cacheNames = "hycdCache", allEntries = true)
public boolean addHycdDic(SdHycdDic hycdDic) { public boolean addHycdDic(SdHycdDic hycdDic) {
return this.save(hycdDic); return this.save(hycdDic);
} }
@Override @Override
@CacheEvict(cacheNames = "dictCache", allEntries = true) @CacheEvict(cacheNames = "hycdCache", allEntries = true)
public boolean updateHycdDic(SdHycdDic hycdDic) { public boolean updateHycdDic(SdHycdDic hycdDic) {
return this.updateById(hycdDic); return this.updateById(hycdDic);
} }
@Override @Override
@CacheEvict(cacheNames = "dictCache", allEntries = true) @CacheEvict(cacheNames = "hycdCache", allEntries = true)
public boolean deleteHycdDic(String hycd) { public boolean deleteHycdDic(String hycd) {
return this.removeById(hycd); return this.removeById(hycd);
} }
@Override @Override
@Cacheable(cacheNames = "dictCache", keyGenerator = "customKeyGenerator") @Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdHycdDic> selectForDropdown(String hynm, Integer grd, Integer lx,String phycd) { public List<SdHycdDic> selectForDropdown(String hynm, Integer grd, Integer lx,String phycd) {
return this.lambdaQuery() return this.lambdaQuery()
.like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm) .like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm)
@ -77,7 +77,7 @@ public class SdHycdDicServiceImpl extends ServiceImpl<SdHycdDicMapper, SdHycdDic
} }
@Override @Override
@Cacheable(cacheNames = "dictCache", keyGenerator = "customKeyGenerator") @Cacheable(cacheNames = "hycdCache#3600", keyGenerator = "cacheKeyGenerator")
public List<SdHycdDic> regDropdown(String hynm, Integer grd,Integer lx,String phycd) { public List<SdHycdDic> regDropdown(String hynm, Integer grd,Integer lx,String phycd) {
return this.lambdaQuery() return this.lambdaQuery()
.like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm) .like(hynm != null && !hynm.isEmpty(), SdHycdDic::getHynm, hynm)