diff --git a/src/main/java/com/nis/restful/RestBusinessCode.java b/src/main/java/com/nis/restful/RestBusinessCode.java index 20153c7..c3486c1 100644 --- a/src/main/java/com/nis/restful/RestBusinessCode.java +++ b/src/main/java/com/nis/restful/RestBusinessCode.java @@ -168,6 +168,10 @@ public enum RestBusinessCode { * Maat配置的keepGroupIdList应该为空 */ GroupidShouldNull(4001025, "Maat配置的keepGroupIdList应该为空"), + /** + * 修改公共组的域配置时groupid要相同 + */ + GroupidShouldSame(4001025, "修改公共组的域配置时groupid要相同"), //分组配置数据完整性业务码10100~ @@ -580,6 +584,10 @@ public enum RestBusinessCode { * 当前service不允许单独添加域配置 */ ServiceNotAllowAddReion(5002009,"当前service不允许单独添加域配置"), + /** + * 公共组不存在 + */ + CommonGroupIsNotExist(5002010,"公共组不存在"), /** *配置文件内容有误 diff --git a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java index ac1ffff..28b84ad 100644 --- a/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java +++ b/src/main/java/com/nis/web/controller/restful/ConfigSourcesController.java @@ -474,7 +474,7 @@ public class ConfigSourcesController extends BaseRestController { @RequestMapping(value = "/cfg/v1/addRegionToCommonGroup", method = RequestMethod.POST) @ApiOperation(value = "公共组域配置新增接口", httpMethod = "POST", response = Map.class, notes = "接收公共组新增的域配置,增加到对应的分组中") - @ApiParam(value = "公关组对象", name = "commonGroupSource", required = true) + @ApiParam(value = "公关组对象", name = "addRegionToCommonGroup", required = true) public Map addRegionToCommonGroup(@RequestBody CommonGroupSource commonGroupSource, HttpServletRequest request, HttpServletResponse response) { @@ -521,10 +521,10 @@ public class ConfigSourcesController extends BaseRestController { return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, "MAAT公共组新增域配置成功" + sb.toString(), Constants.IS_DEBUG ? commonGroupSource : null); } - + @Deprecated @RequestMapping(value = "/cfg/v1/updateRegionToCommonGroup", method = RequestMethod.PUT) @ApiOperation(value = "MAAT公共组修改域配置接口", httpMethod = "PUT", response = Map.class, notes = "界面在删除公共组中的域或者修改公共组中的域时,需要将该组下所有的域下发过来,后台会删除老的域,并将新的域添加到该组下") - @ApiParam(value = "公共组对象", name = "commonGroupSource", required = true) + @ApiParam(value = "公共组对象", name = "updateRegionToCommonGroup", required = true) public Map updateRegionToCommonGroup(@RequestBody CommonGroupSource commonGroupSource, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); @@ -540,7 +540,7 @@ public class ConfigSourcesController extends BaseRestController { if (null != commonGroupSource && null != commonGroupSource.getCommonGroupList() && commonGroupSource.getCommonGroupList().size() > 0) { int opAction = commonGroupSource.getOpAction(); - checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); + checkOpAction(thread, System.currentTimeMillis() - start, opAction, Constants.OPACTION_PUT); configSourcesService.updateRegionToCommonGroup(thread, start, commonGroupSource.getCommonGroupList(), sb, false); @@ -572,9 +572,60 @@ public class ConfigSourcesController extends BaseRestController { "MAAT公共组修改域配置成功" + sb.toString(), Constants.IS_DEBUG ? commonGroupSource : null); } + @RequestMapping(value = "/cfg/v1/updateCommonGroupRegion", method = RequestMethod.PUT) + @ApiOperation(value = "修改MAAT公共组中的域配置接口", httpMethod = "PUT", response = Map.class, notes = "修改MAAT公共组中的域配置") + @ApiParam(value = "公共组对象", name = "updateCommonGroupRegion", required = true) + public Map updateCommonGroupRegion(@RequestBody CommonGroupSource commonGroupSource, HttpServletRequest request, + HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, + commonGroupSource); + StringBuffer sb = new StringBuffer(); + String requestId = UUID.randomUUID().toString(); + try { + if (getLock(requestId)) { + if (null == commonGroupSource.getOpTime()) { + commonGroupSource.setOpTime(new Date()); + } + if (null != commonGroupSource && null != commonGroupSource.getCommonGroupList() + && commonGroupSource.getCommonGroupList().size() > 0) { + int opAction = commonGroupSource.getOpAction(); + checkOpAction(thread, System.currentTimeMillis() - start, opAction, Constants.OPACTION_PUT); + configSourcesService.updateCommonGroupRegion(thread, start, commonGroupSource.getCommonGroupList(), + sb); + + } else { + throw new RestServiceException("公共组信息不能为空" + sb.toString(), + RestBusinessCode.ConfigSourceIsNull.getValue()); + } + } + } catch (Exception e) { + String errorTitle = "修改MAAT公共组中的域配置时出现异常:"; + thread.setExceptionInfo(errorTitle + ExceptionUtil.getExceptionMsg(e)); + logger.error(errorTitle + ExceptionUtil.getExceptionMsg(e)); + if (e instanceof RestServiceException) { + throw new RestServiceException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), ((RestServiceException) e).getErrorCode()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), + RestBusinessCode.service_runtime_error.getValue()); + } + } finally { + deblocking(requestId); + } + + return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, + "修改MAAT公共组中的域配置成功" + sb.toString(), Constants.IS_DEBUG ? commonGroupSource : null); + } + + @Deprecated @RequestMapping(value = "/cfg/v1/delCommonGroup", method = RequestMethod.PUT) @ApiOperation(value = "MAAT公共组修改域配置接口", httpMethod = "PUT", response = Map.class, notes = "界面在删除公共组中的域或者修改公共组中的域时,需要将该组下所有的域下发过来,后台会删除老的域,并将新的域添加到该组下") - @ApiParam(value = "公共组对象", name = "commonGroupSource", required = true) + @ApiParam(value = "公共组对象", name = "delCommonGroup", required = true) public Map delCommonGroup(@RequestBody CommonGroupSource commonGroupSource, HttpServletRequest request, HttpServletResponse response) { long start = System.currentTimeMillis(); @@ -590,7 +641,7 @@ public class ConfigSourcesController extends BaseRestController { if (null != commonGroupSource && null != commonGroupSource.getCommonGroupList() && commonGroupSource.getCommonGroupList().size() > 0) { int opAction = commonGroupSource.getOpAction(); - checkOpAction(thread, System.currentTimeMillis() - start, opAction, 2); + checkOpAction(thread, System.currentTimeMillis() - start, opAction, Constants.OPACTION_PUT); configSourcesService.delCommonGroup(thread, start, commonGroupSource.getCommonGroupList(), sb); } else { @@ -621,6 +672,56 @@ public class ConfigSourcesController extends BaseRestController { "MAAT公共组修改域配置成功" + sb.toString(), Constants.IS_DEBUG ? commonGroupSource : null); } + @RequestMapping(value = "/cfg/v1/delCommonGroupRegion", method = RequestMethod.PUT) + @ApiOperation(value = "删除MAAT公共组域配置接口", httpMethod = "PUT", response = Map.class, notes = "删除MAAT公共组域配置") + @ApiParam(value = "公共组对象", name = "delCommonGroupRegion", required = true) + public Map delCommonGroupRegion(@RequestBody CommonGroupSource commonGroupSource, HttpServletRequest request, + HttpServletResponse response) { + long start = System.currentTimeMillis(); + AuditLogThread thread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_PUT, request, + commonGroupSource); + StringBuffer sb = new StringBuffer(); + String requestId = UUID.randomUUID().toString(); + try { + if (getLock(requestId)) { + if (null == commonGroupSource.getOpTime()) { + commonGroupSource.setOpTime(new Date()); + } + if (null != commonGroupSource && null != commonGroupSource.getCommonGroupList() + && commonGroupSource.getCommonGroupList().size() > 0) { + int opAction = commonGroupSource.getOpAction(); + checkOpAction(thread, System.currentTimeMillis() - start, opAction, Constants.OPACTION_PUT); + configSourcesService.delCommonGroupRegion(thread, start, commonGroupSource.getCommonGroupList(), + sb); + + } else { + throw new RestServiceException("公共组信息不能为空" + sb.toString(), + RestBusinessCode.ConfigSourceIsNull.getValue()); + } + } + } catch (Exception e) { + String errorTitle = "删除MAAT公共组域配置时出现异常:"; + thread.setExceptionInfo(errorTitle + ExceptionUtil.getExceptionMsg(e)); + logger.error(errorTitle + ExceptionUtil.getExceptionMsg(e)); + if (e instanceof RestServiceException) { + throw new RestServiceException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), ((RestServiceException) e).getErrorCode()); + } else if (e instanceof ServiceRuntimeException) { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), ((ServiceRuntimeException) e).getErrorCode()); + } else { + throw new ServiceRuntimeException(thread, System.currentTimeMillis() - start, + errorTitle + ExceptionUtil.getExceptionMsg(e), + RestBusinessCode.service_runtime_error.getValue()); + } + } finally { + deblocking(requestId); + } + + return compileServiceResponse(thread, System.currentTimeMillis() - start, request, response, + "删除MAAT公共组域配置成功" + sb.toString(), Constants.IS_DEBUG ? commonGroupSource : null); + } + @RequestMapping(value = "/cfg/v1/getAllKVByCompileId", method = RequestMethod.GET) @ApiOperation(value = "根据配置id获取对应的编译,组,域等信息", httpMethod = "GET", response = Map.class, notes = "根据配置id获取对应的编译,组,域等信息") @ApiParam(value = "配置id", name = "getAllKVByCompileId", required = true) 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 38af07a..fa95379 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -1803,6 +1803,99 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } } + private void updateCommonGroupRegion(List> regionMapList, MaatXmlExpr maatXmlExpr, + Transaction transaction, int type, int idRelaRedisDBIndex, List expressionList) + throws Exception { + Map dbVersionMap = new HashMap<>();// 记录所有redisdb的maatversion,避免每次查询影响性能 + if (regionMapList != null && regionMapList.size() > 0) { + String[] keySplit = maatXmlExpr.getKeyExpression().split(";"); + + for (Map map : regionMapList) { + String maatKey = null; + StringBuffer keyBF = new StringBuffer(); + for (String keyStr : keySplit) { + if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("[")) { + keyStr = keyStr.trim().replace("[", "").replace("]", ""); + String keyVal = map.get(keyStr); + if (keyVal != null && !keyVal.equals("")) { + keyBF.append(keyVal); + } else { + throw new ServiceRuntimeException("未从map中获取到" + keyStr + "的值,请检查数据或配置文件是否正确", + RestBusinessCode.NotFoundValueByKey.getValue()); + } + } else if (!StringUtils.isEmpty(keyStr) && keyStr.trim().startsWith("{")) { + keyStr = keyStr.trim().replace("{", "").replace("}", ""); + if (keyStr.toLowerCase().contains("table_name")) { + String argTableName = map.get("table_name"); + if (argTableName == null) { + throw new ServiceRuntimeException("添加公共组域配置时,必须要传入表名,请检查参数,配置类型:" + type + ",对应的真实表名", + RestBusinessCode.NotFoundTableName.getValue()); + } else { + keyBF.append(argTableName); + } + } + } else { + keyBF.append(keyStr.trim()); + } + } + String groupId = null; + StringBuffer valBF = new StringBuffer(); + String[] valSplit = maatXmlExpr.getValueExpression().split(";"); + for (String valStr : valSplit) { + if (!StringUtils.isEmpty(valStr) && valStr.trim().startsWith("[")) { + valStr = valStr.trim().replace("[", "").replace("]", ""); + if (valStr.toLowerCase().equals("op_time") && type == 12) { + String user_region = map.get("user_region"); + valBF.append(user_region + "\t"); + } + String val = map.get(valStr); + if (val != null) { + valBF.append(val); + if (valStr.equals("group_id")) { + groupId = val; + } + } else { + // 所有在maat.xml中配置的属性都不可以为空 + throw new ServiceRuntimeException("未从map中获取到" + valStr + "的值,无法拼接redisValue,请检查数据或配置文件是否正确", + RestBusinessCode.NotFoundValueByKey.getValue()); + } + } else if (valStr.equals(" ")) { + valBF.append(" "); + } else if (valStr.equals("\\t")) {// xml中是字符串的\t这里判断的时候需要转义为\\t,但是添加的时候需要添加\t不是\\t + valBF.append("\t"); + } else if (valStr.equals("\\n")) { + valBF.append("\n"); + } else { + valBF.append(valStr.trim()); + } + } + + for (String db : Constants.COMMONGROUPDBARR) { + // 将域配置下发到每个db中,并更新MAAT_UPDATE_STATUS等信息 + int everyDb = Integer.parseInt(db); + transaction.select(everyDb); + maatKey = keyBF.toString(); + transaction.set(maatKey.toUpperCase(), valBF.toString()); + logger.info("向{}号redis数据库添加了一条配置,key是{},value是{}", everyDb, maatKey.toUpperCase(), + valBF.toString()); + + Double maatVersion = null; + if (!dbVersionMap.containsKey(everyDb)) { + String maatVersionStr = JedisUtils.get("MAAT_VERSION", everyDb); + if (maatVersionStr == null) { + maatVersionStr = "0"; + } + maatVersion = Double.valueOf(maatVersionStr) + 1D; + dbVersionMap.put(everyDb, maatVersion); + } else { + maatVersion = dbVersionMap.get(everyDb); + } + updateMaatInfo(expressionList, maatKey, transaction, maatVersion, everyDb, false); + } + } + } + } + @Override public boolean updateGroupRegion(List configList, boolean isAdd) { Jedis resource = JedisUtils.getResource(0); @@ -1866,6 +1959,70 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } } + @Override + public boolean updateGroupRegion(List configList) { + Jedis resource = JedisUtils.getResource(0); + Transaction transaction = resource.multi(); + try { + if (configList != null && configList.size() > 0) { + int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); + MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个 + MaatXmlExpr maatXmlExpr12 = null; + MaatXmlExpr maatXmlExpr13 = null; + MaatXmlExpr maatXmlExpr14 = null; + if (maatXmlConfig != null) { + List expressionList = maatXmlConfig.getExpressionList(); + if (expressionList != null && expressionList.size() > 0) { + for (MaatXmlExpr maatXmlExpr : expressionList) { + if (maatXmlExpr.getType().intValue() == 12) { + maatXmlExpr12 = maatXmlExpr; + } else if (maatXmlExpr.getType().intValue() == 13) { + maatXmlExpr13 = maatXmlExpr; + } else if (maatXmlExpr.getType().intValue() == 14) { + maatXmlExpr14 = maatXmlExpr; + } + } + } + + for (MaatConfig maatConfig : configList) { + + updateCommonGroupRegion(maatConfig.getIpRegionMapList(), maatXmlExpr12, transaction, 12, + idRelaRedisDBIndex, expressionList); + updateCommonGroupRegion(maatConfig.getNumRegionMapList(), maatXmlExpr13, transaction, 13, + idRelaRedisDBIndex, expressionList); + updateCommonGroupRegion(maatConfig.getStrRegionMapList(), maatXmlExpr14, transaction, 14, + idRelaRedisDBIndex, expressionList); + } + for (String db : Constants.COMMONGROUPDBARR) { + transaction.select(Integer.parseInt(db)); + transaction.incrBy("MAAT_VERSION", 1l); + logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db)); + // logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb, maatVersion); + } + + } + } else { + throw new ServiceRuntimeException("添加公共组域配置时,未发现对应的配置信息,请检查配置参数是否正确", + RestBusinessCode.ConfigSourceIsNull.getValue()); + } + transaction.exec(); + return true; + } catch (JedisConnectionException e) { + String error = "连接redis异常,保存公共组maat类域配置失败" + e.getMessage(); + logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); + throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue()); + } catch (Exception e) { + + String error = "保存公共组maat类域配置发生了异常" + e.getMessage(); + logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); + transaction.discard(); + throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue()); + } finally { + // 释放连接到连接池 + JedisUtils.returnResource(resource); + } + } + /** * 添加分组和域的关联关系 * @@ -2131,6 +2288,85 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } } + @Override + public boolean delCommonGroupRegion(Map> groupIdAndregionIdMap) { + Jedis resource = JedisUtils.getResource(0); + Transaction transaction = resource.multi(); + try { + if (groupIdAndregionIdMap != null && groupIdAndregionIdMap.size() > 0) { + int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); + transaction.select(idRelaRedisDBIndex); + //获取需要删除的regionkey + Set set = new HashSet<>(); + Set groupIdSet = groupIdAndregionIdMap.keySet(); + for (Long groupId : groupIdSet) { + Set regionSet = groupIdAndregionIdMap.get(groupId); + String commonGroup = "COMMONGROUPREGION:" + groupId; + String regionKey = JedisUtils.get(commonGroup, idRelaRedisDBIndex); + if (regionKey == null || regionKey.trim().equals("")) { + throw new ServiceRuntimeException("无法删除公共组下的域,公共组" + groupId + ",不存在,请检查数据是否正确", + RestBusinessCode.CommonGroupIsNotExist.getValue()); + } + 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))) { + set.add(key); + } + }else { + throw new ServiceRuntimeException("获取公共组下面域配置的id,域配置的key为" + key + ",请检查数据是否正确", + RestBusinessCode.CommonGroupIsNotExist.getValue()); + } + } + } + + MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(37);// maat类配置的表达式都一样,这里因为没有service所以就随便取了一个 + List expressionList = maatXmlConfig.getExpressionList(); + for (String db : Constants.COMMONGROUPDBARR) { + int everyDb = Integer.parseInt(db); + + Double maatVersion = null; + String maatVersionStr = JedisUtils.get("MAAT_VERSION", everyDb); + if (maatVersionStr == null) { + maatVersionStr = "0"; + } + maatVersion = Double.valueOf(maatVersionStr) + 1D; + transaction.select(everyDb); + for (String regionKey : set) { + String obsKey = regionKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + transaction.rename(regionKey, obsKey); + updateMaatInfo(expressionList, obsKey, transaction, maatVersion, everyDb, true); + } + } + for (String db : Constants.COMMONGROUPDBARR) { + transaction.select(Integer.parseInt(db)); + transaction.incrBy("MAAT_VERSION", 1l); + logger.info("向{}号redis数据库更新了MAAT_VERSION", Integer.parseInt(db)); + } + transaction.exec(); + return true; + } else { + throw new ServiceRuntimeException("删除公共组中域配置时,参数为空,请检查", RestBusinessCode.ConfigSourceIsNull.getValue()); + + } + + } catch (JedisConnectionException e) { + String error = "连接redis异常,删除公共组maat类域配置失败" + e.getMessage(); + logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); + throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue()); + } catch (Exception e) { + String error = "删除公共组maat类域配置发生了异常" + e.getMessage(); + logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); + transaction.discard(); + throw new ServiceRuntimeException(error, RestBusinessCode.SaveDataInError.getValue()); + } finally { + // 释放连接到连接池 + JedisUtils.returnResource(resource); + } + } + private void updateMaatInfo(List list, String maatKey, Transaction transaction, Double maatVersion, int redisDBIndex, Boolean idDel) { if (list != null && list.size() > 0) { diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java index 3ede067..fda1f31 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java @@ -38,20 +38,26 @@ public interface ConfigRedisService { * @param configMap * @return 成功返回true,失败返回false或抛出异常 */ - public boolean saveMaatConfig(Map> configMap,List commonGroupIdList); + public boolean saveMaatConfig(Map> configMap, List commonGroupIdList); /** - *接口 说明; - * 1:界面单独向某个公共组下添加域。 - * 2:对某个公共组下面的域配置进行修改,因为界面没有保存regionid,所以无法准确的去修改某个域配置, - * 因此界面每次都会传过来该组下所有的region,后台根据groupid先将老的region删除,然后在将新的region添加到对应的redisdb中 + * 接口 说明; 1:界面单独向某个公共组下添加域。 2:对某个公共组下面的域配置进行修改,因为界面没有保存regionid,所以无法准确的去修改某个域配置, + * 因此界面每次都会传过来该组下所有的region,后台根据groupid先将老的region删除,然后在将新的region添加到对应的redisdb中 * * * @param configList 配置集合 - * @param isAdd 标志是否是新增域,而不是修改域,修改域需要先删除老配置 + * @param isAdd 标志是否是新增域,而不是修改域,修改域需要先删除老配置 * @return 成功返回true,失败返回false或抛出异常 */ - public boolean updateGroupRegion(List configList,boolean isAdd); + public boolean updateGroupRegion(List configList, boolean isAdd); + + /** + * 修改公共组中的指定域配置 + * + * @param configList + * @return + */ + public boolean updateGroupRegion(List configList); /** * 获取指定key的自增长值 @@ -98,6 +104,14 @@ public interface ConfigRedisService { */ public boolean delCommonGroup(Set groupIdSet); + /** + * 删除公共组下面的域配置,key是groupid,value是regionid + * + * @param groupIdAndregionIdMap groupid和域id的对应关系 + * @return + */ + public boolean delCommonGroupRegion(Map> groupIdAndregionIdMap); + /** * 根据配置id获取对应的编译,组,域等信息 * 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 02643ea..5db38a8 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -124,7 +124,7 @@ public class ConfigSourcesService extends BaseService { StringBuffer sb) throws Exception { Map> maatMap = new HashMap>(); Map> configMap = new HashMap>(); - //公共组的groupid + // 公共组的groupid Set commonGroupIdSet = new HashSet<>(); for (ConfigCompile configCompile : configCompileList) { Integer service = Integer.valueOf(configCompile.getService().toString()); @@ -910,7 +910,7 @@ public class ConfigSourcesService extends BaseService { } // 调用接口入redis - logger.info("---------------调用Redis 公共组修改接口---------------------"); + logger.info("---------------调用Redis修改公共组方法---------------------"); if (isAdd) { configRedisService.updateGroupRegion(list, true); } else { @@ -918,6 +918,95 @@ public class ConfigSourcesService extends BaseService { } } + /** + * 修改公共组中的指定域配置 + * + * @param thread + * @param start + * @param groupReuseList + * @param sb + * @param isAdd + * @throws Exception + */ + public void updateCommonGroupRegion(AuditLogThread thread, long start, List groupReuseList, + StringBuffer sb) throws Exception { + List list = new ArrayList(); + Set groupIdSet = new HashSet<>(); + for (CommonGroup groupReuse : groupReuseList) { + MaatConfig maatConfig = new MaatConfig(); + List> dstMapList = null; + // 字符串域 + List> strongMapList = null; + if (!StringUtil.isEmpty(groupReuse.getStrRegionList())) { + dstMapList = new ArrayList>(); + for (StrRegion region : groupReuse.getStrRegionList()) { + groupIdSet.add(region.getGroupId()); + if (StringUtil.isEmpty(region.getDistrict())) { + dstMapList.add(convertObjectToMap(region, StrRegion.class)); + } else { + if (StringUtil.isEmpty(strongMapList)) { + strongMapList = new ArrayList>(); + } + strongMapList.add(convertObjectToMap(region, StrRegion.class)); + } + } + } + if (StringUtil.isEmpty(maatConfig.getStrRegionMapList())) { + maatConfig.setStrRegionMapList(dstMapList); + } else { + maatConfig.getStrRegionMapList().addAll(dstMapList); + } + + // 增强字符串域 + if (!StringUtil.isEmpty(strongMapList) && strongMapList.size() > 0) { + if (StringUtil.isEmpty(maatConfig.getStrStrRegionMapList())) { + maatConfig.setStrStrRegionMapList(strongMapList); + } else { + maatConfig.getStrStrRegionMapList().addAll(strongMapList); + } + } + // 数值域 + dstMapList = null; + if (!StringUtil.isEmpty(groupReuse.getNumRegionList())) { + dstMapList = new ArrayList>(); + for (NumRegion region : groupReuse.getNumRegionList()) { + groupIdSet.add(region.getGroupId()); + dstMapList.add(convertObjectToMap(region, NumRegion.class)); + } + } + + if (StringUtil.isEmpty(maatConfig.getNumRegionMapList())) { + maatConfig.setNumRegionMapList(dstMapList); + } else { + maatConfig.getNumRegionMapList().addAll(dstMapList); + } + + // Ip域 + dstMapList = null; + if (!StringUtil.isEmpty(groupReuse.getIpRegionList())) { + dstMapList = new ArrayList>(); + for (IpRegion region : groupReuse.getIpRegionList()) { + groupIdSet.add(region.getGroupId()); + dstMapList.add(convertObjectToMap(region, IpRegion.class)); + } + } + if (StringUtil.isEmpty(maatConfig.getIpRegionMapList())) { + maatConfig.setIpRegionMapList(dstMapList); + } else { + maatConfig.getIpRegionMapList().addAll(dstMapList); + } + list.add(maatConfig); + } + if (groupIdSet.size() > 2) { + throw new RestServiceException( + "在修改公共组下的域配置时组id不相同,注意:该接口每次请求只支持同一个groupid下的一个或多个域配置修改,不支持同时修改多个groupid的域配置", + RestBusinessCode.GroupidShouldSame.getValue()); + } + // 调用接口入redis + logger.info("---------------调用Redis修改公共组域配置方法---------------------"); + configRedisService.updateGroupRegion(list); + } + /** * 解析界面传过来的删除公共组数据,校验数据格式,并转化数据格式传到下一层 * @@ -934,7 +1023,54 @@ public class ConfigSourcesService extends BaseService { list.add(commonGroup.getGroupId()); } // 调用接口操作redis - logger.info("---------------调用Redis 删除公共组接口---------------------"); + logger.info("---------------调用Redis 删除公共组方法---------------------"); configRedisService.delCommonGroup(list); } + + public void delCommonGroupRegion(AuditLogThread thread, long start, List groupReuseList, + StringBuffer sb) throws Exception { + + Map> groupIdAndregionIdMap = new HashMap<>(); + for (CommonGroup commonGroup : groupReuseList) { + if (commonGroup.getIpRegionList() != null && commonGroup.getIpRegionList().size() > 0) { + for (IpRegion region : commonGroup.getIpRegionList()) { + Long groupId = region.getGroupId(); + if (groupIdAndregionIdMap.containsKey(groupId)) { + groupIdAndregionIdMap.get(groupId).add(region.getRegionId()); + } else { + Set set = new HashSet(); + set.add(region.getRegionId()); + groupIdAndregionIdMap.put(groupId, set); + } + } + } + if (commonGroup.getNumRegionList() != null && commonGroup.getNumRegionList().size() > 0) { + for (NumRegion region : commonGroup.getNumRegionList()) { + Long groupId = region.getGroupId(); + if (groupIdAndregionIdMap.containsKey(groupId)) { + groupIdAndregionIdMap.get(groupId).add(region.getRegionId()); + } else { + Set set = new HashSet(); + set.add(region.getRegionId()); + groupIdAndregionIdMap.put(groupId, set); + } + } + } + if (commonGroup.getStrRegionList() != null && commonGroup.getStrRegionList().size() > 0) { + for (StrRegion region : commonGroup.getStrRegionList()) { + Long groupId = region.getGroupId(); + if (groupIdAndregionIdMap.containsKey(groupId)) { + groupIdAndregionIdMap.get(groupId).add(region.getRegionId()); + } else { + Set set = new HashSet(); + set.add(region.getRegionId()); + groupIdAndregionIdMap.put(groupId, set); + } + } + } + } + // 调用接口操作redis + logger.info("---------------调用Redis 删除公共组域配置方法---------------------"); + configRedisService.delCommonGroupRegion(groupIdAndregionIdMap); + } }