diff --git a/src/main/java/com/nis/web/service/configuration/ConfigSynchronizationService.java b/src/main/java/com/nis/web/service/configuration/ConfigSynchronizationService.java index a6cf1f8b5..ec81e2d1b 100644 --- a/src/main/java/com/nis/web/service/configuration/ConfigSynchronizationService.java +++ b/src/main/java/com/nis/web/service/configuration/ConfigSynchronizationService.java @@ -23,9 +23,11 @@ import com.google.common.collect.Lists; import com.nis.domain.FunctionServiceDict; import com.nis.domain.Page; import com.nis.domain.basics.AsnIpCfg; +import com.nis.domain.configuration.AppFeatureIndex; import com.nis.domain.configuration.AppPolicyCfg; import com.nis.domain.configuration.AvFileSampleCfg; import com.nis.domain.configuration.BaseCfg; +import com.nis.domain.configuration.BaseIpCfg; import com.nis.domain.configuration.BaseStringCfg; import com.nis.domain.configuration.CfgIndexInfo; import com.nis.domain.configuration.ComplexkeywordCfg; @@ -51,6 +53,7 @@ import com.nis.util.DateUtils; import com.nis.util.DictUtils; import com.nis.util.ServiceConfigTemplateUtil; import com.nis.util.StringUtil; +import com.nis.web.dao.configuration.CommonPolicyDao; import com.nis.web.dao.configuration.ConfigSynchronizationDao; import com.nis.web.security.UserUtils; import com.nis.web.service.BaseService; @@ -64,6 +67,8 @@ import com.nis.web.service.BaseService; public class ConfigSynchronizationService extends BaseService{ @Autowired protected ConfigSynchronizationDao configSynchronizationDao; + @Autowired + protected CommonPolicyDao commonPolicyDao; /** * 配置全量更新下发 @@ -92,13 +97,26 @@ public class ConfigSynchronizationService extends BaseService{ if("1".equals(serviceType)){//maat类配置 List> cfgList = (List>) service.get("cfgList"); List> userRegionList = (List>) service.get("userRegionList"); - if("cfg_index_info".equals(tableName)){ + if(cfgList.size()>0){ + Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a"); + handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false,tableName); + }else{ + int cfgType = Integer.parseInt(service.get("cfgType").toString()); + if("ddos_ip_cfg".equals(tableName)){ + Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a"); + handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false); + }else{ + Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a"); + handleSingleMaatData(cfgType,userRegionList,page,entity,request,response,false); + } + } + /*if("cfg_index_info".equals(tableName)){ Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a"); handleNtcMaatData(cfgList,userRegionList,page,entity,request,response,false); }else if("ddos_ip_cfg".equals(tableName)){ Page page=new Page(request,response,Constants.MAAT_JSON_SEND_SIZE,"a"); handleDdosMaatData(cfgList,userRegionList,page,entity,request,response,false); - } + }*/ }else if("2".equals(serviceType)){//回调类配置 entity.setTableName(tableName); entity.setServiceId(Integer.valueOf(serviceId)); @@ -127,21 +145,48 @@ public class ConfigSynchronizationService extends BaseService{ * @throws IllegalArgumentException */ public void handleNtcMaatData(List>cfgList,List>userRegionList, - Page page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response, - boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ + Page page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response, + boolean isUpdateCfg,String tableName) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ boolean hasData = true; while(hasData){ entity.setPage(page); - List list = configSynchronizationDao.getCfgIndexList(entity); - if(!StringUtil.isEmpty(list)){ - hasData=auditNtcMaatData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg); - if(hasData) { - page.setPageNo(page.getNext()); + List list = Lists.newArrayList(); + if("cfg_index_info".equals(tableName)){ + list = configSynchronizationDao.getCfgIndexList(entity); + if(!StringUtil.isEmpty(list)){ + hasData=auditNtcMaatData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg); + if(hasData) { + page.setPageNo(page.getNext()); + } + }else{ + hasData = false; + } + }else if("app_policy_cfg".equals(tableName)){ + list = configSynchronizationDao.getAppPolicyList(entity); + if(!StringUtil.isEmpty(list)){ + hasData=auditAppPolicyData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg); + if(hasData) { + page.setPageNo(page.getNext()); + } + }else{ + hasData = false; + } + }else if("app_feature_index".equals(tableName)){ + list = configSynchronizationDao.getAppFeatureIndexList(entity); + if(!StringUtil.isEmpty(list)){ + hasData=auditAppFeatureData(cfgList,userRegionList,page,entity,list,hasData,isUpdateCfg); + if(hasData) { + page.setPageNo(page.getNext()); + } + }else{ + hasData = false; } }else{ + logger.info("全量同步未知业务"); hasData = false; } + } } /** @@ -192,6 +237,9 @@ public class ConfigSynchronizationService extends BaseService{ asnGroupIds.add(cfg.getUserRegion4()); } } + if(isUpdateCfg) { + auditBatch(compileIds, entity.getTableName(), entity); + } if(cfgList!=null){ for(Map m:cfgList){ String tableName = m.get("tableName").toString(); @@ -212,6 +260,16 @@ public class ConfigSynchronizationService extends BaseService{ }else if("5".equals(m.get("cfgType"))){ fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds)); } + + if(isUpdateCfg) { + if(tableName.equals("asn_ip_cfg")){ + if(!StringUtil.isEmpty(asnGroupIds)) { + auditBatch(asnGroupIds, tableName, entity); + } + }else{ + auditBatch(compileIds, tableName, entity); + } + } } } //批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),分组复用的域配置不需要重新获取regionId,groupId @@ -284,12 +342,12 @@ public class ConfigSynchronizationService extends BaseService{ for(int index=0;index> cfgList, + List> userRegionList, + Page page, + BaseCfg entity, + List list, + boolean hasData, + boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ + ToMaatBean maatBean; + MaatCfg maatCfg; + List configCompileList; + List groupRelationList; + List ipRegionList; + List strRegionList; + List numRegionList; + List digestRegionList; + List areaIpRegionList; + + List ipList = new ArrayList(); + List strList = new ArrayList(); + List complexStrList = new ArrayList(); + List numList = new ArrayList(); + List fileList = new ArrayList(); + maatBean = new ToMaatBean(); + configCompileList = new ArrayList(); + List compileIds = new ArrayList(); + List asnGroupIds = new ArrayList(); + for(AppPolicyCfg cfg:list){ + compileIds.add(cfg.getCompileId()); + } + if(cfgList!=null){ + for(Map m:cfgList){ + String tableName = m.get("tableName").toString(); + if("1".equals(m.get("cfgType"))){ + ipList.addAll(configSynchronizationDao.getIpPortList(tableName, compileIds)); + }else if("2".equals(m.get("cfgType"))){ + strList.addAll(configSynchronizationDao.getStrList(tableName,compileIds)); + }else if("3".equals(m.get("cfgType"))){ + complexStrList.addAll(configSynchronizationDao.getComplexStrList(tableName,compileIds)); + }else if("4".equals(m.get("cfgType"))){ + + }else if("5".equals(m.get("cfgType"))){ + fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds)); + } + } + } + //批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),compileIds.size()表示app策略本身有一个字符串域 + List regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+compileIds.size()+complexStrList.size()+numList.size()+fileList.size()); + List groupIds = ConfigServiceUtil.getId(2, strList.size()+compileIds.size()+complexStrList.size()+numList.size()+fileList.size()); + for(AppPolicyCfg cfg:list){ + maatCfg = new MaatCfg(); + maatCfg.initDefaultValue(); + groupRelationList = new ArrayList(); + ipRegionList = new ArrayList(); + strRegionList = new ArrayList(); + numRegionList = new ArrayList(); + digestRegionList = new ArrayList(); + areaIpRegionList = new ArrayList(); + List list1 = new ArrayList(); + List list2 = new ArrayList(); + List list3 = new ArrayList(); + List list4 = new ArrayList(); + List list5 = new ArrayList(); + String userRegion = ""; + //处理自定义域 + if(userRegionList!=null){ + for(Map n:userRegionList){ + Object userRegionPosition = n.get("userRegionPosition"); + if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){ + //通过反射机制获取自定义域字段值 + String regionColumn = n.get("regionColumn").toString(); + Class aClass = null; + if(userRegionPosition.toString().equals(("0"))){ + aClass = BaseCfg.class; + }else{ + aClass = AppPolicyCfg.class; + } + Object value = ""; + Field field = aClass.getDeclaredField(regionColumn); + field.setAccessible(true); + value = field.get(cfg); + if(!StringUtil.isEmpty(value)){ + if(StringUtil.isEmpty(n.get("regionKey"))){ + userRegion = value.toString(); + }else{ + userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT; + } + } + } + } + if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){ + userRegion = userRegion.substring(0, userRegion.length()-1); + } + } + //将app码与行为码设置为字符串域 + StringBuffer cfgKeywords = new StringBuffer(); + BaseStringCfg strCfg = new BaseStringCfg(); + if(cfg.getServiceId().equals(35)||cfg.getServiceId().equals(147)||cfg.getServiceId().equals(1059)){//基础协议 + cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + cfg.getAppCode()); + }else if(cfg.getServiceId().equals(33)||cfg.getServiceId().equals(145)||cfg.getServiceId().equals(1056)){ + cfgKeywords.append(Constants.APP_ID_REGION + "=" + cfg.getAppCode()); + if(cfg.getBehavCode()!=null){ + cfgKeywords.append(Constants.KEYWORD_EXPR); + cfgKeywords.append(Constants.BEHAV_ID_REGION + "=" + cfg.getBehavCode()); + } + }else if(cfg.getServiceId().equals(36)||cfg.getServiceId().equals(148)||cfg.getServiceId().equals(1060)){//隧道加密协议 + cfgKeywords.append(Constants.PROTO_ID_REGION + "=" + cfg.getAppCode()); + if(cfg.getBehavCode()!=null){ + cfgKeywords.append(Constants.KEYWORD_EXPR); + cfgKeywords.append(Constants.BEHAV_ID_REGION + "=" + cfg.getBehavCode()); + } + } + cfg.setCfgKeywords(cfgKeywords.toString()); + BeanUtils.copyProperties(cfg, strCfg); + strList.add(strCfg); + + + if(ipList.size()>0){ + List ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId + for(int index=0;index0){ + ipList.removeAll(list1); + Map map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList); + groupRelationList=map.get("groupList"); + ipRegionList=map.get("dstList"); + if(map.get("numRegionList")!=null){ + numRegionList.addAll(map.get("numRegionList")); + } + } + if(list2.size()>0){ + strList.removeAll(list2); + Map map = cfgToMaatConvert(strRegionList,list2,2,groupRelationList); + groupRelationList=map.get("groupList"); + strRegionList=map.get("dstList"); + } + + if(list3.size()>0){ + complexStrList.removeAll(list3); + Map map = cfgToMaatConvert(strRegionList,list3,3,groupRelationList); + groupRelationList=map.get("groupList"); + strRegionList=map.get("dstList"); + } + if(list4.size()>0){ + numList.removeAll(list4); + Map map = cfgToMaatConvert(numRegionList,list4,4,groupRelationList); + groupRelationList=map.get("groupList"); + numRegionList=map.get("dstList"); + } + if(list5.size()>0){ + fileList.removeAll(list5); + Map map = cfgToMaatConvert(digestRegionList,list5,5,groupRelationList); + groupRelationList=map.get("groupList"); + digestRegionList=map.get("dstList"); + } + + BeanUtils.copyProperties(cfg, maatCfg); + maatCfg.setAction(cfg.getAction()); + maatCfg.setAuditTime(StringUtil.isEmpty(cfg.getAuditTime()) ? new Date():cfg.getAuditTime()); + maatCfg.setIpRegionList(ipRegionList); + maatCfg.setStrRegionList(strRegionList); + maatCfg.setNumRegionList(numRegionList); + maatCfg.setDigestRegionList(digestRegionList); + maatCfg.setGroupRelationList(groupRelationList); + maatCfg.setGroupNum(groupRelationList.size()); + maatCfg.setAreaIpRegionList(areaIpRegionList); + maatCfg.setIsValid(entity.getIsValid()); + maatCfg.setAuditTime(new Date()); + if(!StringUtil.isEmpty(userRegion)){ + maatCfg.setUserRegion(userRegion); + } + configCompileList.add(maatCfg); + } + page.setList(list); + if(page.isLastPage()){ + hasData = false; + } + if(!StringUtil.isEmpty(configCompileList.size())){ + maatBean.setConfigCompileList(configCompileList); + maatBean.setAuditTime(new Date()); + maatBean.setCreatorName(UserUtils.getUser().getName()); + maatBean.setVersion(Constants.MAAT_VERSION); + maatBean.setOpAction(Constants.INSERT_ACTION); + String json=gsonToJson(maatBean); + //调用服务接口下发配置数据 + if(isUpdateCfg) { + logger.info("配置批量下发:"+json); + //调用服务接口同步回调类配置 + ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); + if(result!=null){ + logger.info("配置批量下发响应信息:"+result.getMsg()); + } + }else { + //调用服务接口配置全量更新 +// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED")); + } + } + return hasData; + } + /** + * APP特征批量下发 + * @param cfgList + * @param userRegionList + * @param page + * @param entity + * @param list + * @param hasData + * @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态 + * @return + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public boolean auditAppFeatureData(List> cfgList, + List> userRegionList, + Page page, + BaseCfg entity, + List list, + boolean hasData, + boolean isUpdateCfg)throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ + ToMaatBean maatBean; + MaatCfg maatCfg; + List configCompileList; + List groupRelationList; + List ipRegionList; + List strRegionList; + List numRegionList; + List digestRegionList; + List areaIpRegionList; + + List ipList = new ArrayList(); + List strList = new ArrayList(); + List complexStrList = new ArrayList(); + List numList = new ArrayList(); + List fileList = new ArrayList(); + maatBean = new ToMaatBean(); + configCompileList = new ArrayList(); + List compileIds = new ArrayList(); + List asnGroupIds = new ArrayList(); + for(AppFeatureIndex cfg:list){ + compileIds.add(cfg.getCompileId()); + if(entity.getServiceId().equals(37)||entity.getServiceId().equals(149)){ + asnGroupIds.add(cfg.getUserRegion4()); + } + } + if(cfgList!=null){ + for(Map m:cfgList){ + String tableName = m.get("tableName").toString(); + if("1".equals(m.get("cfgType"))){ + ipList.addAll(configSynchronizationDao.getAppIpPortList(tableName, compileIds)); + }else if("2".equals(m.get("cfgType"))){ + strList.addAll(configSynchronizationDao.getStrList(tableName,compileIds)); + }else if("3".equals(m.get("cfgType"))){ + complexStrList.addAll(configSynchronizationDao.getComplexStrList(tableName,compileIds)); + }else if("4".equals(m.get("cfgType"))){ + + }else if("5".equals(m.get("cfgType"))){ + fileList.addAll(configSynchronizationDao.getFileDigestList(tableName, compileIds)); + } + } + } + //批量获取regionId,groupId(相同编译下的IP类配置多条ip只获取一个组号),分组复用的域配置不需要重新获取regionId,groupId + List regionIds = ConfigServiceUtil.getId(3, ipList.size()+strList.size()+complexStrList.size()+numList.size()+fileList.size()); + List groupIds = ConfigServiceUtil.getId(2, strList.size()+complexStrList.size()+numList.size()+fileList.size()); + for(AppFeatureIndex cfg:list){ + maatCfg = new MaatCfg(); + maatCfg.initDefaultValue(); + groupRelationList = new ArrayList(); + ipRegionList = new ArrayList(); + strRegionList = new ArrayList(); + numRegionList = new ArrayList(); + digestRegionList = new ArrayList(); + areaIpRegionList = new ArrayList(); + List list1 = new ArrayList(); + List list2 = new ArrayList(); + List list3 = new ArrayList(); + List list4 = new ArrayList(); + List list5 = new ArrayList(); + String userRegion = ""; + //处理自定义域 + if(userRegionList!=null){ + for(Map n:userRegionList){ + Object userRegionPosition = n.get("userRegionPosition"); + if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){ + //通过反射机制获取自定义域字段值 + String regionColumn = n.get("regionColumn").toString(); + Class aClass = null; + if(userRegionPosition.toString().equals(("0"))){ + aClass = BaseCfg.class; + }else{ + aClass = AppFeatureIndex.class; + } + Object value = ""; + Field field = aClass.getDeclaredField(regionColumn); + field.setAccessible(true); + value = field.get(cfg); + if(!StringUtil.isEmpty(value)){ + if(StringUtil.isEmpty(n.get("regionKey"))){ + userRegion = value.toString(); + }else{ + userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT; + } + } + } + } + if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){ + userRegion = userRegion.substring(0, userRegion.length()-1); + } + } + if(ipList.size()>0){ + List ipGroupId = ConfigServiceUtil.getId(2,1);//多条IP只获取一个groupId + for(int index=0;index0){ + ipList.removeAll(list1); + Map map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList); + groupRelationList=map.get("groupList"); + ipRegionList=map.get("dstList"); + if(map.get("numRegionList")!=null){ + numRegionList.addAll(map.get("numRegionList")); + } + } + if(list2.size()>0){ + strList.removeAll(list2); + Map map = cfgToMaatConvert(strRegionList,list2,2,groupRelationList); + groupRelationList=map.get("groupList"); + strRegionList=map.get("dstList"); + } + if(list3.size()>0){ + complexStrList.removeAll(list3); + Map map = cfgToMaatConvert(strRegionList,list3,3,groupRelationList); + groupRelationList=map.get("groupList"); + strRegionList=map.get("dstList"); + } + if(list4.size()>0){ + numList.removeAll(list4); + Map map = cfgToMaatConvert(numRegionList,list4,4,groupRelationList); + groupRelationList=map.get("groupList"); + numRegionList=map.get("dstList"); + } + if(list5.size()>0){ + fileList.removeAll(list5); + Map map = cfgToMaatConvert(digestRegionList,list5,5,groupRelationList); + groupRelationList=map.get("groupList"); + digestRegionList=map.get("dstList"); + } + + BeanUtils.copyProperties(cfg, maatCfg); + maatCfg.setAction(cfg.getAction()); + maatCfg.setAuditTime(StringUtil.isEmpty(cfg.getAuditTime()) ? new Date():cfg.getAuditTime()); + maatCfg.setIpRegionList(ipRegionList); + maatCfg.setStrRegionList(strRegionList); + maatCfg.setNumRegionList(numRegionList); + maatCfg.setDigestRegionList(digestRegionList); + maatCfg.setGroupRelationList(groupRelationList); + maatCfg.setGroupNum(groupRelationList.size()); + maatCfg.setAreaIpRegionList(areaIpRegionList); + maatCfg.setIsValid(entity.getIsValid()); + maatCfg.setAuditTime(new Date()); + if(!StringUtil.isEmpty(userRegion)){ + maatCfg.setUserRegion(userRegion); + } + configCompileList.add(maatCfg); + } + page.setList(list); + if(page.isLastPage()){ + hasData = false; + } + if(!StringUtil.isEmpty(configCompileList.size())){ + maatBean.setConfigCompileList(configCompileList); + maatBean.setAuditTime(new Date()); + maatBean.setCreatorName(UserUtils.getUser().getName()); + maatBean.setVersion(Constants.MAAT_VERSION); + maatBean.setOpAction(Constants.INSERT_ACTION); + String json=gsonToJson(maatBean); + //调用服务接口下发配置数据 + if(isUpdateCfg) { + logger.info("配置批量下发:"+json); + //调用服务接口同步回调类配置 + ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); + if(result!=null){ + logger.info("配置批量下发响应信息:"+result.getMsg()); + } + }else { + //调用服务接口配置全量更新 +// JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED")); + } + } + return hasData; + } /** * 处理ddos配置 * @param serviceId @@ -488,7 +1077,42 @@ public class ConfigSynchronizationService extends BaseService{ } } } - + /** + * 处理单域maat配置 + * @param serviceId + * @param request + * @param response + * @throws SecurityException + * @throws NoSuchFieldException + * @throws IllegalAccessException + * @throws IllegalArgumentException + */ + public void handleSingleMaatData(int cfgType,List>userRegionList, + Page page,BaseCfg entity,HttpServletRequest request,HttpServletResponse response, + boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ + + boolean hasData = true; + while(hasData){ + entity.setPage(page); + List list = Lists.newArrayList(); + if(cfgType==1){ + list = configSynchronizationDao.getIpPortListByService(entity); + }else if(cfgType==2){ + list = configSynchronizationDao.getStrListByService(entity); + }else if(cfgType==3){ + list = configSynchronizationDao.getComplexStrListByService(entity); + } + if(!StringUtil.isEmpty(list)){ + hasData=auditSingleMaatData(cfgType,userRegionList, + page,entity,list,hasData,isUpdateCfg); + if(hasData) { + page.setPageNo(page.getNext()); + } + }else{ + hasData = false; + } + } + } /** * ddos配置批量下发 * @param cfgList @@ -627,6 +1251,161 @@ public class ConfigSynchronizationService extends BaseService{ } return hasData; } + /** + * 单域配置批量下发 + * @param cfgList + * @param userRegionList + * @param page + * @param entity + * @param list + * @param hasData + * @param isUpdateCfg 业务配置全部生效时需同步更新库表配置状态 + * @return + * @throws NoSuchFieldException + * @throws SecurityException + * @throws IllegalArgumentException + * @throws IllegalAccessException + */ + public boolean auditSingleMaatData(int cfgType, + List>userRegionList, + Page page, + BaseCfg entity, + List list, + boolean hasData, + boolean isUpdateCfg) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException{ + ToMaatBean maatBean; + MaatCfg maatCfg; + List configCompileList; + List groupRelationList; + List ipRegionList; + List strRegionList; + List numRegionList; + List digestRegionList; + List areaIpRegionList; + + + List ipList = new ArrayList(); + maatBean = new ToMaatBean(); + configCompileList = new ArrayList(); + //批量获取regionId,groupId + List regionIds = ConfigServiceUtil.getId(3, list.size()); + List groupIds = ConfigServiceUtil.getId(2, list.size()); + IpPortCfg ipCfg = null; + BaseStringCfg strCfg = null; + ComplexkeywordCfg complexStr = null; + for(int i=0;i n:userRegionList){ + Object userRegionPosition = n.get("userRegionPosition"); + if(userRegionPosition!=null && (userRegionPosition.toString().equals("1")||userRegionPosition.toString().equals("0"))){ + //通过反射机制获取自定义域字段值 + String regionColumn = n.get("regionColumn").toString(); + Class aClass = null; + if(userRegionPosition.toString().equals(("0"))){ + aClass = BaseCfg.class; + }else{ + if(cfgType==1){ + aClass = IpPortCfg.class; + }else if(cfgType==2){ + aClass = BaseStringCfg.class; + }else if(cfgType==3){ + aClass = ComplexkeywordCfg.class; + } + + } + Object value = ""; + Field field = aClass.getDeclaredField(regionColumn); + field.setAccessible(true); + value = field.get(cfg); + if(!StringUtil.isEmpty(value)){ + if(StringUtil.isEmpty(n.get("regionKey"))){ + userRegion = value.toString(); + }else{ + userRegion += n.get("regionKey")+"="+value+Constants.USER_REGION_SPLIT; + } + } + } + } + if(userRegion.endsWith(Constants.USER_REGION_SPLIT)){ + userRegion = userRegion.substring(0, userRegion.length()-1); + } + } + list1.add(cfg); + if(list1.size()>0){ + ipList.removeAll(list1); + if(cfgType==1){ + Map map = cfgToMaatConvert(ipRegionList,list1,1,groupRelationList); + groupRelationList=map.get("groupList"); + ipRegionList=map.get("dstList"); + if(map.get("numRegionList")!=null){ + numRegionList.addAll(map.get("numRegionList")); + } + }else if(cfgType==2||cfgType==3){ + Map map = cfgToMaatConvert(strRegionList,list1,2,groupRelationList); + groupRelationList=map.get("groupList"); + strRegionList=map.get("dstList"); + } + } + BeanUtils.copyProperties(cfg, maatCfg); + maatCfg.setAction(cfg.getAction()); + maatCfg.setAuditTime(StringUtil.isEmpty(cfg.getAuditTime()) ? new Date():cfg.getAuditTime()); + maatCfg.setIpRegionList(ipRegionList); + maatCfg.setStrRegionList(strRegionList); + maatCfg.setNumRegionList(numRegionList); + maatCfg.setDigestRegionList(digestRegionList); + maatCfg.setGroupRelationList(groupRelationList); + maatCfg.setGroupNum(groupRelationList.size()); + maatCfg.setAreaIpRegionList(areaIpRegionList); + maatCfg.setIsValid(entity.getIsValid()); + if(!StringUtil.isEmpty(userRegion)){ + maatCfg.setUserRegion(userRegion); + } + configCompileList.add(maatCfg); + } + page.setList(list); + if(page.isLastPage()){ + hasData = false; + } + if(!StringUtil.isEmpty(configCompileList.size())){ + maatBean.setConfigCompileList(configCompileList); + maatBean.setAuditTime(new Date()); + maatBean.setCreatorName(UserUtils.getUser().getName()); + maatBean.setVersion(Constants.MAAT_VERSION); + maatBean.setOpAction(Constants.INSERT_ACTION); + String json=gsonToJson(maatBean); + //调用服务接口下发配置数据 + if(isUpdateCfg) { + logger.info("配置批量下发:"+json); + //调用服务接口同步回调类配置 + ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); + if(result!=null){ + logger.info("配置批量下发响应信息:"+result.getMsg()); + } + }else { + //调用服务接口配置全量更新 + JSONObject result = ConfigServiceUtil.configSync(json,1,entity.getServiceId(),null,(hasData?null:"FINISHED")); + } + + } + return hasData; + } /** * 处理app业务maat类配置 * @param serviceId @@ -759,4 +1538,15 @@ public class ConfigSynchronizationService extends BaseService{ return hasData; } + public void auditBatch(List compileIds,String tableName,BaseCfg entity) { + if(!StringUtil.isEmpty(compileIds) && !StringUtil.isEmpty(tableName)) { + commonPolicyDao.auditCfgBatch(tableName + , entity.getIsAudit() + , entity.getIsValid() + , entity.getAuditTime() + , entity.getAuditorId() + , compileIds, null); + } + + } }