获取MDM省市数据Bug修改

This commit is contained in:
pserimal
2023-06-28 17:22:24 +08:00
parent 3c57e28d47
commit 72e8eb9c80
2 changed files with 8 additions and 3 deletions

View File

@@ -241,6 +241,6 @@ public class RedisConstant {
/**
* 其他区域数据缓存
*/
public static final String MDM_AREA_OTHERS = "mdm:area:others";
public static final String MDM_AREA_OTHERS = "mdm:area:others:{0}";
}

View File

@@ -10,6 +10,7 @@ import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
import java.util.List;
@Service
@@ -42,13 +43,17 @@ public class MDMAreaServiceImpl implements MDMAreaService {
*/
@Override
public List<MDMAreaDO> getSonArea(String code) {
String provincesJson = redisUtilPool.getString(RedisConstant.MDM_AREA_OTHERS);
String provincesJson = redisUtilPool.getString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code));
if (StringUtils.isNotEmpty(provincesJson)) {
return (List<MDMAreaDO>) JSONObject.parseObject(provincesJson, List.class);
}
List<MDMAreaDO> areaDOList = mdmAreaMapper.getSonArea(code);
//数据库也没有该数据就缓存空值,但是只缓存一分钟
if (areaDOList == null || areaDOList.size() == 0) {
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), "", 60);
}
//过期时间三小时
redisUtilPool.setString(RedisConstant.MDM_AREA_PROVINCE, JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
redisUtilPool.setString(MessageFormat.format(RedisConstant.MDM_AREA_OTHERS, code), JSONObject.toJSONString(areaDOList), 3 * 60 * 60);
return areaDOList;
}