diff --git a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java index fa95379..0350191 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -1137,8 +1137,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) { String compileId = getRegionInfo(groupAndCompileStr);// COMPILEGROUP:24070 if (compileId != null && !compileId.trim().equals("")) { - if (isStart || (keepGroupId != null && keepGroupId.size() > 0 - && !keepGroupId.contains(Long.parseLong(groupIdReal)))) { + if (isStart || keepGroupId == null || keepGroupId.size() == 0 + || (keepGroupId != null && keepGroupId.size() > 0 + && !keepGroupId.contains(Long.parseLong(groupIdReal)))) { // 如果是生效则根据关联关系将组下的域都改为生效 // 如果是失效并且当前组不是需要保留的组,则将该组下的域置为失效 if (compileId.equals(compileStr)) {// 判断编译id是否一致 @@ -2296,7 +2297,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (groupIdAndregionIdMap != null && groupIdAndregionIdMap.size() > 0) { int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); transaction.select(idRelaRedisDBIndex); - //获取需要删除的regionkey + // 获取需要删除的regionkey Set set = new HashSet<>(); Set groupIdSet = groupIdAndregionIdMap.keySet(); for (Long groupId : groupIdSet) { @@ -2310,12 +2311,12 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { String[] keyAndDBArr = org.apache.commons.lang.StringUtils.split(regionKey, ";"); for (String keyAndDB : keyAndDBArr) { String key = keyAndDB.substring(0, keyAndDB.indexOf("-")); - String regionId = key.substring(keyAndDB.indexOf(",")+1); - if(regionId!=null&&!regionId.trim().equals("")) { - if(regionSet.contains(Long.parseLong(regionId))) { + String regionId = key.substring(keyAndDB.indexOf(",") + 1); + if (regionId != null && !regionId.trim().equals("")) { + if (regionSet.contains(Long.parseLong(regionId))) { set.add(key); } - }else { + } else { throw new ServiceRuntimeException("获取公共组下面域配置的id,域配置的key为" + key + ",请检查数据是否正确", RestBusinessCode.CommonGroupIsNotExist.getValue()); } @@ -2348,7 +2349,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { transaction.exec(); return true; } else { - throw new ServiceRuntimeException("删除公共组中域配置时,参数为空,请检查", RestBusinessCode.ConfigSourceIsNull.getValue()); + throw new ServiceRuntimeException("删除公共组中域配置时,参数为空,请检查", + RestBusinessCode.ConfigSourceIsNull.getValue()); } diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 5db38a8..1352b16 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -126,6 +126,10 @@ public class ConfigSourcesService extends BaseService { Map> configMap = new HashMap>(); // 公共组的groupid Set commonGroupIdSet = new HashSet<>(); + // 判断公共组下面是否有域配置,没有域配置时就不往下面下发了,避免添加版本号 + + boolean isHaveCommonRegion = false; + for (ConfigCompile configCompile : configCompileList) { Integer service = Integer.valueOf(configCompile.getService().toString()); MaatConfig maatConfig = new MaatConfig(); @@ -152,6 +156,11 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getStrRegionList())) { dstMaplList = new ArrayList>(); for (StrRegion region : configCompile.getStrRegionList()) { + + if (commonGroupIdSet.contains(region.getGroupId())) { + isHaveCommonRegion = true; + } + if (StringUtil.isEmpty(region.getDistrict())) { dstMaplList.add(convertObjectToMap(region, StrRegion.class)); } else { @@ -172,6 +181,9 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getNumRegionList())) { dstMaplList = new ArrayList>(); for (NumRegion region : configCompile.getNumRegionList()) { + if (commonGroupIdSet.contains(region.getGroupId())) { + isHaveCommonRegion = true; + } dstMaplList.add(convertObjectToMap(region, NumRegion.class)); } } @@ -182,6 +194,9 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getIpRegionList())) { dstMaplList = new ArrayList>(); for (IpRegion region : configCompile.getIpRegionList()) { + if (commonGroupIdSet.contains(region.getGroupId())) { + isHaveCommonRegion = true; + } dstMaplList.add(convertObjectToMap(region, IpRegion.class)); } } @@ -192,6 +207,9 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getDigestRegionList())) { dstMaplList = new ArrayList>(); for (DigestRegion region : configCompile.getDigestRegionList()) { + if (commonGroupIdSet.contains(region.getGroupId())) { + isHaveCommonRegion = true; + } dstMaplList.add(convertObjectToMap(region, DigestRegion.class)); } } @@ -207,6 +225,9 @@ public class ConfigSourcesService extends BaseService { if (!StringUtil.isEmpty(configCompile.getIpClientRangeList())) { dstMaplList = new ArrayList>(); for (IpRegion region : configCompile.getIpClientRangeList()) { + if (commonGroupIdSet.contains(region.getGroupId())) { + isHaveCommonRegion = true; + } dstMaplList.add(convertObjectToMap(region, IpRegion.class)); } } @@ -258,7 +279,13 @@ public class ConfigSourcesService extends BaseService { } } logger.info("---------------调用Redis maat配置新增接口---------------------"); - configRedisService.saveMaatConfig(configMap, new ArrayList<>(commonGroupIdSet)); + + if (isHaveCommonRegion) { + configRedisService.saveMaatConfig(configMap, new ArrayList<>(commonGroupIdSet)); + } else { + configRedisService.saveMaatConfig(configMap, new ArrayList());//下层有直接使用的地方,不可直接传入null + } + } /**