diff --git a/src/main/java/com/nis/web/dao/SchedulerDao.java b/src/main/java/com/nis/web/dao/SchedulerDao.java index 356190c24..7453f7ebf 100644 --- a/src/main/java/com/nis/web/dao/SchedulerDao.java +++ b/src/main/java/com/nis/web/dao/SchedulerDao.java @@ -22,12 +22,18 @@ public interface SchedulerDao extends CrudDao { */ List findNewlyCfg(@Param("id")Long id,@Param("limit")Long limit,@Param("type")int type,@Param("delFlag")Integer delFlag); + /** + * 删除定时任务 + * @param cfg + * @return + */ + int deleteByCompileIds(@Param("compileIds")String compileIds,@Param("type")Integer type); /** * 更新 del_flag 字段为删除标识 * @param cfg * @return */ - int deleteByCompileIds(String compileIds); + int inValidByCompileIds(@Param("compileIds")String compileIds); /** * 查找 配置 下发 最新记录 diff --git a/src/main/java/com/nis/web/dao/SchedulerDao.xml b/src/main/java/com/nis/web/dao/SchedulerDao.xml index 4a38bc71d..2b1dc710e 100644 --- a/src/main/java/com/nis/web/dao/SchedulerDao.xml +++ b/src/main/java/com/nis/web/dao/SchedulerDao.xml @@ -94,7 +94,6 @@ from schedule_cfg a - del_Flag = #{DEL_FLAG_NORMAL} and id = #{id} @@ -116,12 +115,15 @@ and table_name = #{tableName} + and type = 1 + + and name is null ${whereStr} - order by a.id + order by a.id desc @@ -242,12 +244,17 @@ - + update schedule_cfg del_flag = 0 - WHERE compile_Id in (#{compileIds}) and del_flag =1 + WHERE compile_Id in (${compileIds}) and del_flag =1 + + + + delete from schedule_cfg + WHERE compile_Id in (${compileIds}) and type=#{type} diff --git a/src/main/java/com/nis/web/service/BaseService.java b/src/main/java/com/nis/web/service/BaseService.java index 84ebd0695..7d80eafa1 100644 --- a/src/main/java/com/nis/web/service/BaseService.java +++ b/src/main/java/com/nis/web/service/BaseService.java @@ -3053,7 +3053,7 @@ public abstract class BaseService { * @param tableName * @throws SQLException */ - public void handelScheduleCfg(Object parameterObject,String tableName){ + public void handelScheduleCfg(Object parameterObject,String tableName,BaseCfg cfg){ logger.info("handelScheduleCfg==》开始处理定时任务"); List cfgList = Lists.newArrayList(); //确保 单个,批量都适用 @@ -3072,31 +3072,16 @@ public abstract class BaseService { } //存放需要删除的定时任务(根据compileId删除之前所有的定时任务) - String compileIds=""; - //存放需要删除的定时任务trigger的sche - List delScheduleList = Lists.newArrayList(); + String delCompileIds=""; + //存放需要失效的定时任务 + String inValidCompileIds=""; //存放需要新增的定时任务 List addScheduleList = Lists.newArrayList(); for(BaseCfg baseCfg : cfgList) { - //定时任务删除需要新增一条无效的sche用来清理旧的trigger - if(baseCfg.getIsValid()==-1 || baseCfg.getIsAudit()==2 || baseCfg.getIsAudit()==3) { - ScheduleCfg scheduleCfgdel =new ScheduleCfg(); - scheduleCfgdel.setDelFlag(0); - scheduleCfgdel.setType(1); - scheduleCfgdel.setTableName(tableName); - scheduleCfgdel.setName("DELETE TRIGGER SCHE"); - scheduleCfgdel.setCompileId(baseCfg.getCompileId()); - scheduleCfgdel.setFunctionId(baseCfg.getFunctionId()); - scheduleCfgdel.setIsValid(baseCfg.getIsValid()); - scheduleCfgdel.setIsAudit(baseCfg.getIsAudit()); - scheduleCfgdel.setCfgId(baseCfg.getCfgId()); - scheduleCfgdel.setCreateTime(new Date()); - scheduleCfgdel.setCreatorId(UserUtils.getUser().getId()); - scheduleCfgdel.setServiceId(baseCfg.getServiceId()); - delScheduleList.add(scheduleCfgdel); - }else { - //有新的定时任务时,不需要在新增无效sche来清理旧的trigger,扫描到新增的sche时,也会有清理操作 + //有新的定时任务时,新增新的 + if(cfg.getIsValid()==0 && cfg.getIsAudit()==0){ + delCompileIds+=baseCfg.getCompileId()+","; ScheduleCfg scheduleCfgAdd = copyScheduleCfgFromBaseCfg(baseCfg, tableName); if(scheduleCfgAdd!=null){ scheduleCfgAdd.setIsValid(0); @@ -3105,18 +3090,22 @@ public abstract class BaseService { addScheduleList.add(scheduleCfgAdd); } } - compileIds+=baseCfg.getCompileId()+","; + //需要失效的定时任务 + if(cfg.getIsValid()==-1 || cfg.getIsAudit()==2 ||cfg.getIsAudit()==3){ + inValidCompileIds+=baseCfg.getCompileId()+","; + } } - //将之前的定时任务置为无效 - if(!StringUtil.isEmpty(compileIds)) { - compileIds=compileIds.substring(0,compileIds.length()-1); + //将type=2定时任务删除 + if(!StringUtil.isEmpty(inValidCompileIds) || !StringUtil.isEmpty(delCompileIds) ) { + String syncDelCompileIds=delCompileIds+inValidCompileIds; + syncDelCompileIds=syncDelCompileIds.substring(0,syncDelCompileIds.length()-1); SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); SqlSession batchSqlSession = null; try { batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); - ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(compileIds.toString()); + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(syncDelCompileIds,2); batchSqlSession.commit(); } finally { if(batchSqlSession != null) { @@ -3124,16 +3113,31 @@ public abstract class BaseService { } } } - //新增sche,用于删除旧的定时任务 - if(!StringUtil.isEmpty(delScheduleList)) { - compileIds=compileIds.substring(0,compileIds.length()-1); + + //将type=1定时任务删除 + if(!StringUtil.isEmpty(delCompileIds) ) { + delCompileIds=delCompileIds.substring(0,delCompileIds.length()-1); SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); SqlSession batchSqlSession = null; try { batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); - for(ScheduleCfg entity : delScheduleList) { - ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).insert(entity); + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).deleteByCompileIds(delCompileIds,1); + batchSqlSession.commit(); + } finally { + if(batchSqlSession != null) { + batchSqlSession.close(); } + } + } + + //将定时任务失效 + if(!StringUtil.isEmpty(inValidCompileIds)) { + inValidCompileIds=inValidCompileIds.substring(0,inValidCompileIds.length()-1); + SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSession batchSqlSession = null; + try { + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, false); + ((SchedulerDao) batchSqlSession.getMapper(SchedulerDao.class)).inValidByCompileIds(inValidCompileIds); batchSqlSession.commit(); } finally { if(batchSqlSession != null) { @@ -3144,7 +3148,6 @@ public abstract class BaseService { //新增sche,用于新增新定时任务 if(!StringUtil.isEmpty(addScheduleList)) { - compileIds=compileIds.substring(0,compileIds.length()-1); SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); SqlSession batchSqlSession = null; try { diff --git a/src/main/java/com/nis/web/service/ScheduleService.java b/src/main/java/com/nis/web/service/ScheduleService.java index 876662fd8..3ca0c9443 100644 --- a/src/main/java/com/nis/web/service/ScheduleService.java +++ b/src/main/java/com/nis/web/service/ScheduleService.java @@ -30,7 +30,10 @@ public class ScheduleService extends BaseService{ BaseCfg baseCfg = dao.getCfgTableInfo(cfg.getTableName(),compileId);//查询当前配置的最新状态 ScheduleCfg curSchedule = dao.get(cfg.getId());//查询当前任务的最新状态 Integer curIsValid = baseCfg.getIsValid();//当前配置的最新 是否有效信息 - Integer curScheduleFlag = curSchedule.getDelFlag();//当前任务最新状态是否有效 + Integer curScheduleFlag =0; + if(curSchedule!=null){ + curScheduleFlag = curSchedule.getDelFlag();//当前任务最新状态是否有效 + } if(curScheduleFlag == 0) { logger.info(String.format("当前任务已失效 : id:%s,delFlag:%s", cfg.getId(),curScheduleFlag)); return; diff --git a/src/main/java/com/nis/web/service/configuration/CommonPolicyService.java b/src/main/java/com/nis/web/service/configuration/CommonPolicyService.java index 082bc9f0e..0c1ca65fa 100644 --- a/src/main/java/com/nis/web/service/configuration/CommonPolicyService.java +++ b/src/main/java/com/nis/web/service/configuration/CommonPolicyService.java @@ -129,7 +129,7 @@ public class CommonPolicyService extends CrudService { +public class IpCfgService extends CrudService { @Autowired protected IpCfgDao ipCfgDao; @Autowired @@ -61,41 +62,41 @@ public class IpCfgService extends CrudService { @Autowired protected AreaIpCfgDao areaIpCfgDao; @Autowired - //protected SpecificServiceCfgDao specificServiceCfgDao; + // protected SpecificServiceCfgDao specificServiceCfgDao; protected AsnGroupInfoDao asnGroupInfoDao; @Autowired protected ConfigGroupInfoDao configGroupInfoDao; @Autowired protected AsnIpCfgDao asnIpCfgDao; + /** * - * addIpCfg(新增IP类配置) - * (继承BaseIpCfg这个类方可使用) + * addIpCfg(新增IP类配置) (继承BaseIpCfg这个类方可使用) + * * @param baseIpCfg - * @return - *int - * @exception - * @since 1.0.0 + * @return int + * @exception @since + * 1.0.0 */ - @Transactional(readOnly=false,rollbackFor=RuntimeException.class) - public void addIpCfg(BaseIpCfg cfg){ - //调用服务接口获取compileId + @Transactional(readOnly = false, rollbackFor = RuntimeException.class) + public void addIpCfg(BaseIpCfg cfg) { + // 调用服务接口获取compileId Integer compileId = 0; try { - List compileIds = ConfigServiceUtil.getId(1,1); - if(!StringUtil.isEmpty(compileIds)){ + List compileIds = ConfigServiceUtil.getId(1, 1); + if (!StringUtil.isEmpty(compileIds)) { compileId = compileIds.get(0); } } catch (MaatConvertException e) { e.printStackTrace(); logger.info("获取编译ID出错"); - throw new MaatConvertException(":"+e.getMessage()); + throw new MaatConvertException(":" + e.getMessage()); } - if(compileId!=0){ + if (compileId != 0) { cfg.setCompileId(compileId); setAreaEffectiveIds(cfg); - if(cfg.getAreaCfg()!=null&&cfg.getAreaCfg().size()>0){ - for(AreaIpCfg c:cfg.getAreaCfg()){ + if (cfg.getAreaCfg() != null && cfg.getAreaCfg().size() > 0) { + for (AreaIpCfg c : cfg.getAreaCfg()) { c.initDefaultValue(); BeanUtils.copyProperties(cfg, c,new String[]{"cfgId","ipType","direction", "protocol","protocolId","areaEffectiveIds","cfgRegionCode", @@ -105,28 +106,29 @@ public class IpCfgService extends CrudService { this.saveIpBatch(cfg.getAreaCfg()); } ipCfgDao.insert(cfg); - }else{ + } else { throw new MaatConvertException(": compileId is 0"); } - - } - @Transactional(readOnly=false,rollbackFor=RuntimeException.class) - public void saveIpCfg(CfgIndexInfo entity){ - //设置区域运营商信息 + + } + + @Transactional(readOnly = false, rollbackFor = RuntimeException.class) + public void saveIpCfg(CfgIndexInfo entity) { + // 设置区域运营商信息 setAreaEffectiveIds(entity); - - int isValid=0; - if(!StringUtil.isEmpty(entity.getIsValid()) && entity.getIsValid()==1) { - isValid=1; + + int isValid = 0; + if (!StringUtil.isEmpty(entity.getIsValid()) && entity.getIsValid() == 1) { + isValid = 1; } entity.setIsValid(0); entity.setIsAudit(0); - - if(entity.getCfgId()==null){ + + if (entity.getCfgId() == null) { Integer compileId = 0; try { List idList = ConfigServiceUtil.getId(1, 1); - if(idList!=null && idList.size()>0){ + if (idList != null && idList.size() > 0) { compileId = idList.get(0); } } catch (MaatConvertException e) { @@ -137,47 +139,49 @@ public class IpCfgService extends CrudService { entity.setCreateTime(new Date()); entity.setCreatorId(entity.getCurrentUser().getId()); ipCfgDao.saveCfgIndex(entity); - if(entity.getIpPortList()!=null){ - for(IpPortCfg cfg:entity.getIpPortList()){ - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); + if (entity.getIpPortList() != null) { + for (IpPortCfg cfg : entity.getIpPortList()) { + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgRegionCode", "cfgType" }); ipCfgDao.saveIpPortCfg(cfg); } } - if(entity.getNtcSubscribeIdCfgList()!=null){ - for(NtcSubscribeIdCfg cfg:entity.getNtcSubscribeIdCfgList()){ - if(StringUtils.isNotBlank(cfg.getCfgKeywords())){ - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); + if (entity.getNtcSubscribeIdCfgList() != null) { + for (NtcSubscribeIdCfg cfg : entity.getNtcSubscribeIdCfgList()) { + if (StringUtils.isNotBlank(cfg.getCfgKeywords())) { + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgRegionCode", "cfgType" }); stringCfgDao.saveSubscribeIdCfg(cfg); } } } - //保存区域IP信息 - if(entity.getAreaCfg()!=null){ - for(AreaIpCfg cfg:entity.getAreaCfg()){ + // 保存区域IP信息 + if (entity.getAreaCfg() != null) { + for (AreaIpCfg cfg : entity.getAreaCfg()) { cfg.initDefaultValue(); - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgRegionCode", "cfgType" }); areaIpCfgDao.saveAreaIpCfg(cfg); } } - //保存asn组织信息 字符串域信息 - if(StringUtils.isNotBlank(entity.getUserRegion4())){ - List functionRegionDicts=DictUtils.getFunctionRegionDictList(entity.getFunctionId()); - FunctionRegionDict regionDict=null; - for(FunctionRegionDict dict:functionRegionDicts) { - if("asn".equals(dict.getConfigServiceType())) { - regionDict=dict; + // 保存asn组织信息 字符串域信息 + if (StringUtils.isNotBlank(entity.getUserRegion4())) { + List functionRegionDicts = DictUtils + .getFunctionRegionDictList(entity.getFunctionId()); + FunctionRegionDict regionDict = null; + for (FunctionRegionDict dict : functionRegionDicts) { + if ("asn".equals(dict.getConfigServiceType())) { + regionDict = dict; } } - if(regionDict!=null) { - AsnGroupInfo asnSearch=new AsnGroupInfo(); + if (regionDict != null) { + AsnGroupInfo asnSearch = new AsnGroupInfo(); asnSearch.setOrganization(entity.getUserRegion4()); asnSearch.setAsnId(Long.valueOf(entity.getUserRegion5())); - AsnGroupInfo info=asnGroupInfoDao.getGroupInfo(asnSearch); - if(info != null){ - BaseStringCfg asnKeywordCfg=new AsnKeywordCfg(); - BeanUtils.copyProperties(entity, asnKeywordCfg,new String[]{"cfgId","cfgDesc","cfgRegionCode","cfgType","userRegion1","userRegion2","userRegion3"}); + AsnGroupInfo info = asnGroupInfoDao.getGroupInfo(asnSearch); + if (info != null) { + BaseStringCfg asnKeywordCfg = new AsnKeywordCfg(); + BeanUtils.copyProperties(entity, asnKeywordCfg, new String[] { "cfgId", "cfgDesc", + "cfgRegionCode", "cfgType", "userRegion1", "userRegion2", "userRegion3" }); asnKeywordCfg.setTableName(AsnKeywordCfg.getTablename()); - asnKeywordCfg.setCfgKeywords("AS"+info.getAsnId()); + asnKeywordCfg.setCfgKeywords("AS" + info.getAsnId()); asnKeywordCfg.setExprType(0); asnKeywordCfg.setMatchMethod(3); asnKeywordCfg.setExType("0"); @@ -191,21 +195,21 @@ public class IpCfgService extends CrudService { stringCfgDao.saveStringCfgBatch(asnKeywordCfg); } } - + } - //TODO 处理定时任务【如果有定时任务则新增】 - handelScheduleCfg(entity, entity.getIndexTable()); - - if(isValid==1) { + // TODO 处理定时任务【如果有定时任务则新增】 + handelScheduleCfg(entity, entity.getIndexTable(), entity); + + if (isValid == 1) { entity.setIsAudit(1); entity.setIsValid(1); - auditIpCfg(entity, entity.getIsAudit(),Constants.INSERT_ACTION); + auditIpCfg(entity, entity.getIsAudit(), Constants.INSERT_ACTION); } - }else{ + } else { entity.setEditTime(new Date()); entity.setEditorId(entity.getCurrentUser().getId()); ipCfgDao.updateCfgIndex(entity); - //无效子配置后,再新增子配置 + // 无效子配置后,再新增子配置 ipCfgDao.deleteIpCfg(entity); stringCfgDao.deleteSubscribeIdCfgByCfgIndexInfo(entity); AreaIpCfg area = new AreaIpCfg(); @@ -214,49 +218,51 @@ public class IpCfgService extends CrudService { areaIpCfgDao.deleteAreaIpCfg(area); entity.setCreateTime(new Date()); entity.setCreatorId(entity.getCurrentUser().getId()); - if(entity.getIpPortList()!=null){ - for(IpPortCfg cfg:entity.getIpPortList()){ - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); + if (entity.getIpPortList() != null) { + for (IpPortCfg cfg : entity.getIpPortList()) { + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgRegionCode", "cfgType" }); ipCfgDao.saveIpPortCfg(cfg); } } - if(entity.getNtcSubscribeIdCfgList()!=null){ - for(NtcSubscribeIdCfg cfg:entity.getNtcSubscribeIdCfgList()){ - if(StringUtils.isNotBlank(cfg.getCfgKeywords())){ - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); + if (entity.getNtcSubscribeIdCfgList() != null) { + for (NtcSubscribeIdCfg cfg : entity.getNtcSubscribeIdCfgList()) { + if (StringUtils.isNotBlank(cfg.getCfgKeywords())) { + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgRegionCode", "cfgType" }); stringCfgDao.saveSubscribeIdCfg(cfg); } } } - //保存区域IP信息 - if(entity.getAreaCfg()!=null){ - for(AreaIpCfg cfg:entity.getAreaCfg()){ + // 保存区域IP信息 + if (entity.getAreaCfg() != null) { + for (AreaIpCfg cfg : entity.getAreaCfg()) { cfg.initDefaultValue(); - BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgDesc", "cfgRegionCode", "cfgType" }); areaIpCfgDao.saveAreaIpCfg(cfg); } } - //保存asn组织信息 字符串域信息 - if(StringUtils.isNotBlank(entity.getUserRegion4())){ - List functionRegionDicts=DictUtils.getFunctionRegionDictList(entity.getFunctionId()); - FunctionRegionDict regionDict=null; - for(FunctionRegionDict dict:functionRegionDicts) { - if("asn".equals(dict.getConfigServiceType())) { - regionDict=dict; + // 保存asn组织信息 字符串域信息 + if (StringUtils.isNotBlank(entity.getUserRegion4())) { + List functionRegionDicts = DictUtils + .getFunctionRegionDictList(entity.getFunctionId()); + FunctionRegionDict regionDict = null; + for (FunctionRegionDict dict : functionRegionDicts) { + if ("asn".equals(dict.getConfigServiceType())) { + regionDict = dict; } } - if(regionDict!=null) { - //先删除asn keyword + if (regionDict != null) { + // 先删除asn keyword stringCfgDao.deleteAsnKeyword(entity); - AsnGroupInfo asnSearch=new AsnGroupInfo(); + AsnGroupInfo asnSearch = new AsnGroupInfo(); asnSearch.setOrganization(entity.getUserRegion4()); asnSearch.setAsnId(Long.valueOf(entity.getUserRegion5())); - AsnGroupInfo info=asnGroupInfoDao.getGroupInfo(asnSearch); - if(info != null){ - BaseStringCfg asnKeywordCfg=new AsnKeywordCfg(); - BeanUtils.copyProperties(entity, asnKeywordCfg,new String[]{"cfgId","cfgDesc","cfgRegionCode","cfgType","userRegion1","userRegion2","userRegion3"}); + AsnGroupInfo info = asnGroupInfoDao.getGroupInfo(asnSearch); + if (info != null) { + BaseStringCfg asnKeywordCfg = new AsnKeywordCfg(); + BeanUtils.copyProperties(entity, asnKeywordCfg, new String[] { "cfgId", "cfgDesc", + "cfgRegionCode", "cfgType", "userRegion1", "userRegion2", "userRegion3" }); asnKeywordCfg.setTableName(AsnKeywordCfg.getTablename()); - asnKeywordCfg.setCfgKeywords("AS"+info.getAsnId()); + asnKeywordCfg.setCfgKeywords("AS" + info.getAsnId()); asnKeywordCfg.setExprType(0); asnKeywordCfg.setMatchMethod(3); asnKeywordCfg.setExType("0"); @@ -272,21 +278,22 @@ public class IpCfgService extends CrudService { stringCfgDao.saveStringCfgBatch(asnKeywordCfg); } } - + } - //TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 - handelScheduleCfg(entity, entity.getIndexTable()); - - if(isValid==1) { + // TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable(), entity); + + if (isValid == 1) { entity.setIsAudit(1); entity.setIsValid(1); - auditIpCfg(entity, entity.getIsAudit(),Constants.UPDATE_ACTION); + auditIpCfg(entity, entity.getIsAudit(), Constants.UPDATE_ACTION); } } } - public void updateIpCfgValid(Integer isValid,String ids,Integer functionId){ + + public void updateIpCfgValid(Integer isValid, String ids, Integer functionId) { String[] idArray = ids.split(","); - for(String id :idArray){ + for (String id : idArray) { CfgIndexInfo entity = new CfgIndexInfo(); entity.setCfgId(Long.parseLong(id)); entity.setIsValid(isValid); @@ -295,61 +302,59 @@ public class IpCfgService extends CrudService { entity.setTableName(CfgIndexInfo.getTablename()); entity.setFunctionId(functionId); ipCfgDao.updateCfgValid(entity); - //查询子配置 - entity = this.getIpPortCfg(Long.parseLong(id),entity.getCompileId()); - if(entity.getIpPortList()!=null && entity.getIpPortList().size()>0){ + // 查询子配置 + entity = this.getIpPortCfg(Long.parseLong(id), entity.getCompileId()); + if (entity.getIpPortList() != null && entity.getIpPortList().size() > 0) { IpPortCfg cfg = new IpPortCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(IpPortCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } - if(entity.getNtcSubscribeIdCfgList()!=null && entity.getNtcSubscribeIdCfgList().size()>0) - { + if (entity.getNtcSubscribeIdCfgList() != null && entity.getNtcSubscribeIdCfgList().size() > 0) { NtcSubscribeIdCfg cfg = new NtcSubscribeIdCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(NtcSubscribeIdCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } - if(entity.getAsnKeywords()!=null && entity.getAsnKeywords().size()>0) - { + if (entity.getAsnKeywords() != null && entity.getAsnKeywords().size() > 0) { AsnKeywordCfg cfg = new AsnKeywordCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(AsnKeywordCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } - //保存区域IP信息 - if(entity.getAreaCfg()!=null && entity.getAreaCfg().size()>0){ + // 保存区域IP信息 + if (entity.getAreaCfg() != null && entity.getAreaCfg().size() > 0) { AreaIpCfg cfg = new AreaIpCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(AreaIpCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } - //TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 - handelScheduleCfg(entity, entity.getIndexTable()); + // TODO 处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable(), entity); } - + } + /** * - * updateIpCfg(更新IP类配置) - * (继承BaseIpCfg这个类方可使用) + * updateIpCfg(更新IP类配置) (继承BaseIpCfg这个类方可使用) + * * @param baseIpCfg - * @return - *int - * @exception - * @since 1.0.0 + * @return int + * @exception @since + * 1.0.0 */ - @Transactional(readOnly=false,rollbackFor=RuntimeException.class) - public void updateIpCfg(BaseIpCfg cfg){ - AreaIpCfg area=new AreaIpCfg(); + @Transactional(readOnly = false, rollbackFor = RuntimeException.class) + public void updateIpCfg(BaseIpCfg cfg) { + AreaIpCfg area = new AreaIpCfg(); area.setCompileId(cfg.getCompileId()); area.setFunctionId(cfg.getFunctionId()); areaIpCfgDao.deleteAreaIpCfg(area); - //区域IPsetAreaEffectiveIds设置 + // 区域IPsetAreaEffectiveIds设置 setAreaEffectiveIds(cfg); - Date date=new Date(); - if(cfg.getAreaCfg()!=null&&cfg.getAreaCfg().size()>0){ - for(AreaIpCfg c:cfg.getAreaCfg()){ + Date date = new Date(); + if (cfg.getAreaCfg() != null && cfg.getAreaCfg().size() > 0) { + for (AreaIpCfg c : cfg.getAreaCfg()) { c.initDefaultValue(); BeanUtils.copyProperties(cfg, c,new String[]{"cfgId","ipType","direction", "protocol","protocolId","areaEffectiveIds","cfgRegionCode", @@ -362,10 +367,11 @@ public class IpCfgService extends CrudService { } ipCfgDao.update(cfg); } + @Deprecated - public void audit(BaseIpCfg cfg) throws Exception{ - //更新IP配置与区域IP的状态 - List beans=new ArrayList<>(); + public void audit(BaseIpCfg cfg) throws Exception { + // 更新IP配置与区域IP的状态 + List beans = new ArrayList<>(); beans.add(cfg); ipCfgDao.audit(cfg); List beans1=new ArrayList<>(); @@ -394,52 +400,52 @@ public class IpCfgService extends CrudService { List numRegionList = new ArrayList<>(); List digestRegionList = new ArrayList<>(); List areaIpRegionList = new ArrayList<>(); - ToMaatBean maatBean = new ToMaatBean(); + ToMaatBean maatBean = new ToMaatBean(); MaatCfg maatCfg = new MaatCfg(); maatCfg.initDefaultValue(); BeanUtils.copyProperties(cfg, maatCfg); - String json=""; - //获取region - List dictList = DictUtils.getFunctionRegionDictList(cfg.getFunctionId()); - int maatType=0; - //判断下发类型是走maat还是callback - String regionValue=cfg.getCfgType(); - if(regionValue!=null) { - for(FunctionRegionDict region:dictList) { - if(regionValue.equals(region.getConfigRegionValue())) { - maatType=region.getIsMaat(); + String json = ""; + // 获取region + List dictList = DictUtils.getFunctionRegionDictList(cfg.getFunctionId()); + int maatType = 0; + // 判断下发类型是走maat还是callback + String regionValue = cfg.getCfgType(); + if (regionValue != null) { + for (FunctionRegionDict region : dictList) { + if (regionValue.equals(region.getConfigRegionValue())) { + maatType = region.getIsMaat(); break; } } } - Properties props=this.getMsgProp(); - if(cfg.getIsAudit()==Constants.AUDIT_YES){ - if(maatType==Constants.CALLBACK_TYPE){ - List ipList=new ArrayList<>(); - InlineIp ip=convertCallBackIp(cfg,null); + Properties props = this.getMsgProp(); + if (cfg.getIsAudit() == Constants.AUDIT_YES) { + if (maatType == Constants.CALLBACK_TYPE) { + List ipList = new ArrayList<>(); + InlineIp ip = convertCallBackIp(cfg, null); ipList.add(ip); - //调用服务接口下发配置数据 - json=gsonToJson(ipList); - logger.info("IP配置下发配置参数:"+json); - //调用服务接口下发配置 + // 调用服务接口下发配置数据 + json = gsonToJson(ipList); + logger.info("IP配置下发配置参数:" + json); + // 调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json); - if(result!=null){ - logger.info("IP配置配置下发响应信息:"+result.getMsg()); + if (result != null) { + logger.info("IP配置配置下发响应信息:" + result.getMsg()); } } catch (Exception e) { - logger.error("IP配置配置下发失败",e); + logger.error("IP配置配置下发失败", e); throw e; } - }else if(maatType==Constants.MAAT_TYPE){ - Map map = cfgConvert(ipRegionList,beans,1,cfg,groupRelationList); - ipRegionList=map.get("dstList"); - groupRelationList=map.get("groupList"); - numRegionList=map.get("numRegionList")==null?new ArrayList<>():map.get("numRegionList"); - Map areaMap = cfgConvert(areaIpRegionList,beans1,1,cfg,groupRelationList); - groupRelationList=areaMap.get("groupList"); - areaIpRegionList=areaMap.get("dstList"); - //maatCfg.setAreaEffectiveIds(StringUtils.isBlank(cfg.getAreaEffectiveIds())?"0":cfg.getAreaEffectiveIds()); + } else if (maatType == Constants.MAAT_TYPE) { + Map map = cfgConvert(ipRegionList, beans, 1, cfg, groupRelationList); + ipRegionList = map.get("dstList"); + groupRelationList = map.get("groupList"); + numRegionList = map.get("numRegionList") == null ? new ArrayList<>() : map.get("numRegionList"); + Map areaMap = cfgConvert(areaIpRegionList, beans1, 1, cfg, groupRelationList); + groupRelationList = areaMap.get("groupList"); + areaIpRegionList = areaMap.get("dstList"); + // maatCfg.setAreaEffectiveIds(StringUtils.isBlank(cfg.getAreaEffectiveIds())?"0":cfg.getAreaEffectiveIds()); maatCfg.setAction(cfg.getAction()); maatCfg.setAuditTime(cfg.getAuditTime()); maatCfg.setIpRegionList(ipRegionList); @@ -450,33 +456,35 @@ public class IpCfgService extends CrudService { maatCfg.setGroupRelationList(groupRelationList); maatCfg.setGroupNum(groupRelationList.size()); maatCfg.setAreaIpRegionList(areaIpRegionList); - if(Constants.SERVICE_IP_MULITIPLEX==cfg.getServiceId().intValue()){ - String region=Constants.USERREGION_IR_STRATEGY+"="+cfg.getDnsStrategyId()+Constants.USER_REGION_SPLIT - +Constants.USERREGION_IR_TYPE+"="+cfg.getIrType(); + if (Constants.SERVICE_IP_MULITIPLEX == cfg.getServiceId().intValue()) { + String region = Constants.USERREGION_IR_STRATEGY + "=" + cfg.getDnsStrategyId() + + Constants.USER_REGION_SPLIT + Constants.USERREGION_IR_TYPE + "=" + cfg.getIrType(); maatCfg.setUserRegion(region); - }else if(Constants.SERVICE_IP_RATELIMIT==cfg.getServiceId().intValue()){ - maatCfg.setUserRegion(Constants.USERREGION_RATE_LIMIT+"="+cfg.getRatelimit()); + } else if (Constants.SERVICE_IP_RATELIMIT == cfg.getServiceId().intValue()) { + maatCfg.setUserRegion(Constants.USERREGION_RATE_LIMIT + "=" + cfg.getRatelimit()); } - //限速需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps - if(cfg.getAction().equals(Constants.RATELIMIT_ACTION)){ - if(cfg.getUserRegion1().equals("0")){//丢包率 - cfg.setUserRegion2(StringUtil.isEmpty(cfg.getUserRegion2()) ? "":cfg.getUserRegion2()); - maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+cfg.getUserRegion2()); - }else if(cfg.getUserRegion1().equals("1")){//带宽 - cfg.setUserRegion3(StringUtil.isEmpty(cfg.getUserRegion3()) ? "":cfg.getUserRegion3()); - maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+cfg.getUserRegion3()); + // 限速需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps + if (cfg.getAction().equals(Constants.RATELIMIT_ACTION)) { + if (cfg.getUserRegion1().equals("0")) {// 丢包率 + cfg.setUserRegion2(StringUtil.isEmpty(cfg.getUserRegion2()) ? "" : cfg.getUserRegion2()); + maatCfg.setUserRegion( + Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY + "=" + cfg.getUserRegion2()); + } else if (cfg.getUserRegion1().equals("1")) {// 带宽 + cfg.setUserRegion3(StringUtil.isEmpty(cfg.getUserRegion3()) ? "" : cfg.getUserRegion3()); + maatCfg.setUserRegion( + Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY + "=" + cfg.getUserRegion3()); } - }else { - if(!StringUtil.isEmpty(cfg.getUserRegion1())){ + } else { + if (!StringUtil.isEmpty(cfg.getUserRegion1())) { String userRegion = ""; - if(cfg.getUserRegion1().startsWith(Constants.REDIRECT_RESPONSE_CODE_STARTWITH)){ - userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+cfg.getUserRegion1()+ - Constants.USER_REGION_SPLIT+ - Constants.REDIRECT_URL_KEY+"="+cfg.getUserRegion2(); - }else{ - userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY+"="+cfg.getUserRegion1()+ - Constants.USER_REGION_SPLIT+ - Constants.REDIRECT_CONTENT_KEY+"="+cfg.getUserRegion2(); + if (cfg.getUserRegion1().startsWith(Constants.REDIRECT_RESPONSE_CODE_STARTWITH)) { + userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY + "=" + cfg.getUserRegion1() + + Constants.USER_REGION_SPLIT + Constants.REDIRECT_URL_KEY + "=" + + cfg.getUserRegion2(); + } else { + userRegion = Constants.REDIRECT_RESPONSE_CODE_KEY + "=" + cfg.getUserRegion1() + + Constants.USER_REGION_SPLIT + Constants.REDIRECT_CONTENT_KEY + "=" + + cfg.getUserRegion2(); } maatCfg.setUserRegion(userRegion); } @@ -487,76 +495,79 @@ public class IpCfgService extends CrudService { maatBean.setAuditTime(cfg.getAuditTime()); maatBean.setCreatorName(cfg.getCurrentUser().getName()); maatBean.setVersion(Constants.MAAT_VERSION); - //调用服务接口下发配置数据 - json=gsonToJson(maatBean); - logger.info("IP配置下发配置参数:"+json); - //调用服务接口下发配置 + // 调用服务接口下发配置数据 + json = gsonToJson(maatBean); + logger.info("IP配置下发配置参数:" + json); + // 调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); - if(result!=null){ - logger.info("IP配置配置下发响应信息:"+result.getMsg()); + if (result != null) { + logger.info("IP配置配置下发响应信息:" + result.getMsg()); } } catch (Exception e) { - logger.error("IP配置配置下发失败",e); + logger.error("IP配置配置下发失败", e); throw e; } - }else { - throw new MaatConvertException(":"+props.getProperty("unknown_cfg_type")); + } else { + throw new MaatConvertException( + ":" + props.getProperty("unknown_cfg_type")); } - }else if(cfg.getIsAudit()==Constants.AUDIT_NOT_YES){ - if(maatType==Constants.CALLBACK_TYPE){ - List ipList=new ArrayList<>(); - InlineIp ip=convertCallBackIp(cfg,null); + } else if (cfg.getIsAudit() == Constants.AUDIT_NOT_YES) { + if (maatType == Constants.CALLBACK_TYPE) { + List ipList = new ArrayList<>(); + InlineIp ip = convertCallBackIp(cfg, null); ipList.add(ip); - //调用服务接口取消配置 - json=gsonToJson(ipList); - logger.info("IP管控配置参数:"+json); - //调用服务接口取消配置 + // 调用服务接口取消配置 + json = gsonToJson(ipList); + logger.info("IP管控配置参数:" + json); + // 调用服务接口取消配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 2); - logger.info("IP配置取消配置响应信息:"+result.getMsg()); + logger.info("IP配置取消配置响应信息:" + result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("IP配置取消配置失败"); throw e; } - }else if(maatType==Constants.MAAT_TYPE){ + } else if (maatType == Constants.MAAT_TYPE) { maatCfg.setCompileId(cfg.getCompileId()); maatCfg.setServiceId(cfg.getServiceId()); - maatCfg.setIsValid(0);//无效 + maatCfg.setIsValid(0);// 无效 configCompileList.add(maatCfg); maatBean.setConfigCompileList(configCompileList); maatBean.setAuditTime(cfg.getAuditTime()); maatBean.setCreatorName(cfg.getCurrentUser().getName()); maatBean.setVersion(Constants.MAAT_VERSION); maatBean.setOpAction(Constants.UPDATE_ACTION); - //调用服务接口取消配置 - json=gsonToJson(maatBean); - logger.info("IP管控配置参数:"+json); - //调用服务接口取消配置 + // 调用服务接口取消配置 + json = gsonToJson(maatBean); + logger.info("IP管控配置参数:" + json); + // 调用服务接口取消配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 1); - logger.info("IP管控取消配置响应信息:"+result.getMsg()); + logger.info("IP管控取消配置响应信息:" + result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("IP管控取消配置失败"); throw e; } - }else { - throw new MaatConvertException(":"+props.getProperty("unknown_cfg_type")); + } else { + throw new MaatConvertException( + ":" + props.getProperty("unknown_cfg_type")); } } } - public void auditIpCfg(CfgIndexInfo entity,Integer isAudit,Integer opAction) throws MaatConvertException{ - Properties props=this.getMsgProp(); - //修改数据库审核状态信息 + + public void auditIpCfg(CfgIndexInfo entity, Integer isAudit, Integer opAction) throws MaatConvertException { + Properties props = this.getMsgProp(); + // 修改数据库审核状态信息 entity.setTableName(CfgIndexInfo.getTablename()); entity.setIsAudit(isAudit); entity.setAuditorId(UserUtils.getUser().getId()); entity.setAuditTime(new Date()); ipCfgDao.auditCfg(entity); - - ToMaatBean maatBean = new ToMaatBean(); + + ToMaatBean maatBean = new ToMaatBean(); MaatCfg maatCfg = new MaatCfg(); List configCompileList = new ArrayList(); List groupRelationList = new ArrayList(); @@ -565,116 +576,124 @@ public class IpCfgService extends CrudService { List numRegionList = new ArrayList(); List digestRegionList = new ArrayList(); List areaIpRegionList = new ArrayList(); - //获取region - List dictList = DictUtils.getFunctionRegionDictList(entity.getFunctionId()); - int maatType=0; - if(entity.getIpPortList()!=null && entity.getIpPortList().size()>0){ - //判断下发类型是走maat还是callback - String regionValue=entity.getIpPortList().get(0).getCfgType(); - if(regionValue!=null) { - for(FunctionRegionDict region:dictList) { - if(regionValue.equals(region.getConfigRegionValue())) { - maatType=region.getIsMaat(); + // 获取region + List dictList = DictUtils.getFunctionRegionDictList(entity.getFunctionId()); + int maatType = 0; + if (entity.getIpPortList() != null && entity.getIpPortList().size() > 0) { + // 判断下发类型是走maat还是callback + String regionValue = entity.getIpPortList().get(0).getCfgType(); + if (regionValue != null) { + for (FunctionRegionDict region : dictList) { + if (regionValue.equals(region.getConfigRegionValue())) { + maatType = region.getIsMaat(); break; } } } - for(IpPortCfg cfg:entity.getIpPortList()) { - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId","cfgType","userRegion1","userRegion2","userRegion3","userRegion4","userRegion5"}); + for (IpPortCfg cfg : entity.getIpPortList()) { + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId", "cfgType", "userRegion1", "userRegion2", + "userRegion3", "userRegion4", "userRegion5" }); cfg.setTableName(IpPortCfg.getTablename()); ipCfgDao.auditCfg(cfg); - /*BeanUtils.copyProperties(entity, cfg, new String[]{"userRegion1","userRegion2","userRegion3","userRegion4","userRegion5","ipType","direction", - "protocol","protocolId","areaEffectiveIds","cfgRegionCode", - "cfgType","ipPattern","srcIpAddress","portPattern","srcPort","destIpAddress","destPort"}); - cfg.setTableName(IpPortCfg.getTablename()); - ipCfgDao.auditCfg(cfg);*/ + /* + * BeanUtils.copyProperties(entity, cfg, new + * String[]{"userRegion1","userRegion2","userRegion3", + * "userRegion4","userRegion5","ipType","direction", + * "protocol","protocolId","areaEffectiveIds","cfgRegionCode", + * "cfgType","ipPattern","srcIpAddress","portPattern","srcPort", + * "destIpAddress","destPort"}); + * cfg.setTableName(IpPortCfg.getTablename()); + * ipCfgDao.auditCfg(cfg); + */ } - if(isAudit==1&&maatType==Constants.MAAT_TYPE){ - Map map = cfgConvert(ipRegionList,entity.getIpPortList(),1,entity,groupRelationList); - groupRelationList=map.get("groupList"); - ipRegionList=map.get("dstList"); - if(map.get("numRegionList")!=null){ + if (isAudit == 1 && maatType == Constants.MAAT_TYPE) { + Map map = cfgConvert(ipRegionList, entity.getIpPortList(), 1, entity, groupRelationList); + groupRelationList = map.get("groupList"); + ipRegionList = map.get("dstList"); + if (map.get("numRegionList") != null) { numRegionList.addAll(map.get("numRegionList")); } } } - if(entity.getNtcSubscribeIdCfgList()!=null && entity.getNtcSubscribeIdCfgList().size()>0){ + if (entity.getNtcSubscribeIdCfgList() != null && entity.getNtcSubscribeIdCfgList().size() > 0) { NtcSubscribeIdCfg cfg = new NtcSubscribeIdCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(NtcSubscribeIdCfg.getTablename()); ipCfgDao.auditCfg(cfg); - if(isAudit==1&&maatType==Constants.MAAT_TYPE){ - Map map = cfgConvert(strRegionList,entity.getNtcSubscribeIdCfgList(),2,entity,groupRelationList); - groupRelationList=map.get("groupList"); - strRegionList=map.get("dstList"); + if (isAudit == 1 && maatType == Constants.MAAT_TYPE) { + Map map = cfgConvert(strRegionList, entity.getNtcSubscribeIdCfgList(), 2, entity, + groupRelationList); + groupRelationList = map.get("groupList"); + strRegionList = map.get("dstList"); } } - if(entity.getAsnKeywords()!=null && entity.getAsnKeywords().size()>0){ - String regionValue=entity.getAsnKeywords().get(0).getCfgType(); - if(regionValue!=null) { - for(FunctionRegionDict region:dictList) { - if(regionValue.equals(region.getConfigRegionValue())) { - maatType=region.getIsMaat(); + if (entity.getAsnKeywords() != null && entity.getAsnKeywords().size() > 0) { + String regionValue = entity.getAsnKeywords().get(0).getCfgType(); + if (regionValue != null) { + for (FunctionRegionDict region : dictList) { + if (regionValue.equals(region.getConfigRegionValue())) { + maatType = region.getIsMaat(); break; } } } AsnKeywordCfg cfg = new AsnKeywordCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(AsnKeywordCfg.getTablename()); ipCfgDao.auditCfg(cfg); - if(isAudit==1&&maatType==Constants.MAAT_TYPE){ - Map map = cfgConvert(strRegionList,entity.getAsnKeywords(),2,entity,groupRelationList); - groupRelationList=map.get("groupList"); - strRegionList=map.get("dstList"); + if (isAudit == 1 && maatType == Constants.MAAT_TYPE) { + Map map = cfgConvert(strRegionList, entity.getAsnKeywords(), 2, entity, + groupRelationList); + groupRelationList = map.get("groupList"); + strRegionList = map.get("dstList"); } } - //保存区域IP信息 - List areaIpCfgList=areaIpCfgDao.getByCompileId(entity.getCompileId()); - if(!StringUtil.isEmpty(areaIpCfgList)){ + // 保存区域IP信息 + List areaIpCfgList = areaIpCfgDao.getByCompileId(entity.getCompileId()); + if (!StringUtil.isEmpty(areaIpCfgList)) { AreaIpCfg cfg = new AreaIpCfg(); - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); cfg.setTableName(AreaIpCfg.getTablename()); ipCfgDao.auditCfg(cfg); - if(isAudit==1&&maatType==Constants.MAAT_TYPE){ - Map map = cfgConvert(areaIpRegionList,areaIpCfgList,1,entity,groupRelationList); - groupRelationList=map.get("groupList"); - areaIpRegionList=map.get("dstList"); + if (isAudit == 1 && maatType == Constants.MAAT_TYPE) { + Map map = cfgConvert(areaIpRegionList, areaIpCfgList, 1, entity, groupRelationList); + groupRelationList = map.get("groupList"); + areaIpRegionList = map.get("dstList"); } } - - if(isAudit!=1) { - //处理定时任务【如果有定时任务则删除旧的,新增新的】 - handelScheduleCfg(entity, entity.getIndexTable()); + + if (isAudit != 1) { + // 处理定时任务【如果有定时任务则删除旧的,新增新的】 + handelScheduleCfg(entity, entity.getIndexTable(), entity); } - - //构造提交综合服务参数格式,一条配置提交一次综合服务 - if(isAudit==1){ - if(maatType==Constants.CALLBACK_TYPE){ - List ipList=new ArrayList<>(); - for(IpPortCfg cfg :entity.getIpPortList()) { - Integer ipsecProtocol=null; - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); - InlineIp ip=convertCallBackIp(cfg,null); - if(ipsecProtocol!=null) { + + // 构造提交综合服务参数格式,一条配置提交一次综合服务 + if (isAudit == 1) { + if (maatType == Constants.CALLBACK_TYPE) { + List ipList = new ArrayList<>(); + for (IpPortCfg cfg : entity.getIpPortList()) { + Integer ipsecProtocol = null; + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); + InlineIp ip = convertCallBackIp(cfg, null); + if (ipsecProtocol != null) { ip.setProtocol(ipsecProtocol); } ipList.add(ip); } - //调用服务接口下发配置数据 - String json=gsonToJson(ipList); - logger.info("IP配置下发配置参数:"+json); - //调用服务接口下发配置 + // 调用服务接口下发配置数据 + String json = gsonToJson(ipList); + logger.info("IP配置下发配置参数:" + json); + // 调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json); - if(result!=null){ - logger.info("IP配置配置下发响应信息:"+result.getMsg()); + if (result != null) { + logger.info("IP配置配置下发响应信息:" + result.getMsg()); } } catch (Exception e) { - logger.error("IP配置配置下发失败",e); + logger.error("IP配置配置下发失败", e); throw e; } - }else if(maatType==Constants.MAAT_TYPE){ + } else if (maatType == Constants.MAAT_TYPE) { maatCfg.initDefaultValue(); BeanUtils.copyProperties(entity, maatCfg); maatCfg.setAction(entity.getAction()); @@ -687,203 +706,213 @@ public class IpCfgService extends CrudService { maatCfg.setGroupNum(groupRelationList.size()); maatCfg.setAreaIpRegionList(areaIpRegionList); maatCfg.setIsValid(entity.getIsValid()); - + configCompileList.add(maatCfg); maatBean.setConfigCompileList(configCompileList); maatBean.setAuditTime(entity.getAuditTime()); maatBean.setCreatorName(entity.getCurrentUser().getName()); maatBean.setVersion(Constants.MAAT_VERSION); maatBean.setOpAction(opAction); - //限速需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps - if(entity.getAction().equals(Constants.RATELIMIT_ACTION)){ - if(entity.getUserRegion1().equals("0")){//丢包率 - entity.setUserRegion2(StringUtil.isEmpty(entity.getUserRegion2()) ? "":entity.getUserRegion2()); - maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY+"="+entity.getUserRegion2()); - }else if(entity.getUserRegion1().equals("1")){//带宽 - entity.setUserRegion3(StringUtil.isEmpty(entity.getUserRegion3()) ? "":entity.getUserRegion3()); - maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY+"="+entity.getUserRegion3()); + // 限速需要发Droprate=0.001 ,暂不支持Bandwidth=200kbps + if (entity.getAction().equals(Constants.RATELIMIT_ACTION)) { + if (entity.getUserRegion1().equals("0")) {// 丢包率 + entity.setUserRegion2( + StringUtil.isEmpty(entity.getUserRegion2()) ? "" : entity.getUserRegion2()); + maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_DROPRATE_USER_REGION_KEY + "=" + + entity.getUserRegion2()); + } else if (entity.getUserRegion1().equals("1")) {// 带宽 + entity.setUserRegion3( + StringUtil.isEmpty(entity.getUserRegion3()) ? "" : entity.getUserRegion3()); + maatCfg.setUserRegion(Constants.INTERCEPT_IP_RATELIMIT_BANDWITH_USER_REGION_KEY + "=" + + entity.getUserRegion3()); } } - //调用服务接口下发配置数据 - String json=gsonToJson(maatBean); - logger.info("ip配置下发配置参数:"+json); - //调用服务接口下发配置 + // 调用服务接口下发配置数据 + String json = gsonToJson(maatBean); + logger.info("ip配置下发配置参数:" + json); + // 调用服务接口下发配置 ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); - logger.info("ip配置下发响应信息:"+result.getMsg()); - }else { - throw new RuntimeException(":"+props.getProperty("unknown_cfg_type")); + logger.info("ip配置下发响应信息:" + result.getMsg()); + } else { + throw new RuntimeException( + ":" + props.getProperty("unknown_cfg_type")); } - }else if(isAudit==3 && entity.getIsValid()==1){ - if(maatType==Constants.CALLBACK_TYPE){ - List ipList=new ArrayList<>(); - for(IpPortCfg cfg :entity.getIpPortList()) { - Integer ipsecProtocol=null; - BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); - InlineIp ip=convertCallBackIp(cfg,null); - if(ipsecProtocol!=null) { + } else if (isAudit == 3 && entity.getIsValid() == 1) { + if (maatType == Constants.CALLBACK_TYPE) { + List ipList = new ArrayList<>(); + for (IpPortCfg cfg : entity.getIpPortList()) { + Integer ipsecProtocol = null; + BeanUtils.copyProperties(entity, cfg, new String[] { "cfgId" }); + InlineIp ip = convertCallBackIp(cfg, null); + if (ipsecProtocol != null) { ip.setProtocol(ipsecProtocol); } ipList.add(ip); } - //调用服务接口下发配置数据 - String json=gsonToJson(ipList); - logger.info("IP配置下发配置参数:"+json); - //调用服务接口下发配置 + // 调用服务接口下发配置数据 + String json = gsonToJson(ipList); + logger.info("IP配置下发配置参数:" + json); + // 调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 2); - if(result!=null){ - logger.info("IP配置配置下发响应信息:"+result.getMsg()); + if (result != null) { + logger.info("IP配置配置下发响应信息:" + result.getMsg()); } } catch (Exception e) { - logger.error("IP配置配置下发失败",e); + logger.error("IP配置配置下发失败", e); throw e; } - }else if(maatType==Constants.MAAT_TYPE){ + } else if (maatType == Constants.MAAT_TYPE) { maatCfg.setCompileId(entity.getCompileId()); maatCfg.setServiceId(entity.getServiceId()); - maatCfg.setIsValid(0);//无效 + maatCfg.setIsValid(0);// 无效 configCompileList.add(maatCfg); maatBean.setConfigCompileList(configCompileList); maatBean.setAuditTime(entity.getAuditTime()); maatBean.setCreatorName(entity.getCurrentUser().getName()); maatBean.setVersion(Constants.MAAT_VERSION); maatBean.setOpAction(Constants.UPDATE_ACTION); - //调用服务接口取消配置 - String json=gsonToJson(maatBean); - logger.info("ip配置下发配置参数:"+json); - //调用服务接口下发配置 - ToMaatResult result = ConfigServiceUtil.put(json,1); - logger.info("ip配置取消配置响应信息:"+result.getMsg()); - }else { - throw new RuntimeException(":"+props.getProperty("unknown_cfg_type")); + // 调用服务接口取消配置 + String json = gsonToJson(maatBean); + logger.info("ip配置下发配置参数:" + json); + // 调用服务接口下发配置 + ToMaatResult result = ConfigServiceUtil.put(json, 1); + logger.info("ip配置取消配置响应信息:" + result.getMsg()); + } else { + throw new RuntimeException( + ":" + props.getProperty("unknown_cfg_type")); } } } + /** * * @param isAudit * @param isValid - * @param ids cfgId + * @param ids + * cfgId * @param functionId */ - -// @Transactional(readOnly=false,rollbackFor=RuntimeException.class) -// @Deprecated -// public void auditAsnCfg(CfgIndexInfo entity,Integer isAudit){ -// entity.setTableName(CfgIndexInfo.getTablename()); -// entity.setIsAudit(isAudit); -// ipCfgDao.auditCfg(entity); -// ToMaatBean maatBean = new ToMaatBean(); -// -// List configCompileList = new ArrayList<>(); -// -// if(isAudit==Constants.AUDIT_YES) { -// List asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); -// if(asnKeywordCfgs!=null&&asnKeywordCfgs.size()>0) { -// MaatCfg maatCfg = new MaatCfg(); -// List groupRelationList = new ArrayList<>(); -// List ipRegionList = new ArrayList<>(); -// List strRegionList = new ArrayList<>(); -// List numRegionList = new ArrayList<>(); -// List digestRegionList = new ArrayList<>(); -// List areaIpRegionList = new ArrayList<>(); -// maatCfg.initDefaultValue(); -// BeanUtils.copyProperties(entity, maatCfg); -// maatCfg.setAction(entity.getAction()); -// maatCfg.setAuditTime(entity.getAuditTime()); -// -// maatCfg.setNumRegionList(numRegionList); -// maatCfg.setDigestRegionList(digestRegionList); -// maatCfg.setGroupRelationList(groupRelationList); -// maatCfg.setAreaIpRegionList(areaIpRegionList); -// maatCfg.setIsValid(entity.getIsValid()); -// //group -// List groupIds=ConfigServiceUtil.getId(2, 1); -// GroupCfg groupCfg=new GroupCfg(); -// groupCfg.setCompileId(entity.getCompileId()); -// //groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion4())); -// groupCfg.setGroupId(groupIds.get(0)); -// groupCfg.setIsValid(Constants.VALID_YES); -// groupCfg.setAuditTime(entity.getAuditTime()); -// groupRelationList.add(groupCfg); -// maatCfg.setGroupNum(groupRelationList.size()); -// maatCfg.setIpRegionList(ipRegionList); -// List regions=ConfigServiceUtil.getId(3, asnKeywordCfgs.size()); -// int index=0; -// List functionRegionDicts=DictUtils.getFunctionRegionDictList(entity.getFunctionId()); -// String cfgType=null; -// for(FunctionRegionDict dict:functionRegionDicts) { -// if("asn".equals(dict.getConfigServiceType())) { -// cfgType=dict.getCfgType(); -// } -// } -// for(AsnKeywordCfg keyword:asnKeywordCfgs) { -// StringCfg cfg=new StringCfg(); -// BeanUtils.copyProperties(keyword, cfg); -// cfg.setRegionId(index); -// //需要根据文档 -// //cfg.setCfgType(StringUtils.isBlank(cfgType)?"NTC_ASN_NUMBER":cfgType); -// cfg.setGroupId(groupIds.get(0)); -// cfg.setAuditTime(entity.getAuditTime()); -// cfg.setIsValid(entity.getIsValid()); -// cfg.setRegionId(regions.get(index)); -// //cfg.setGroupId(Integer.parseInt(entity.getUserRegion4())); -// strRegionList.add(cfg); -// index++; -// } -// maatCfg.setStrRegionList(strRegionList); -// configCompileList.add(maatCfg); -// maatBean.setConfigCompileList(configCompileList); -// maatBean.setAuditTime(entity.getAuditTime()); -// maatBean.setCreatorName(entity.getCurrentUser().getName()); -// maatBean.setVersion(Constants.MAAT_VERSION); -// maatBean.setOpAction(Constants.INSERT_ACTION); -// -// //调用服务接口下发配置数据 -// String json=gsonToJson(maatBean); -// logger.info("ipaddr asn配置下发配置参数:"+json); -// //调用服务接口下发配置 -// ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); -// logger.info("ipaddr asn配置下发响应信息:"+result.getMsg()); -//// } -// } -// -// }else if(isAudit==Constants.AUDIT_NOT_YES) {//取消审核通过 -// MaatCfg maatCfg = new MaatCfg(); -// maatCfg.setCompileId(entity.getCompileId()); -// maatCfg.setServiceId(entity.getServiceId()); -// maatCfg.setIsValid(0);//无效 -// configCompileList.add(maatCfg); -// maatBean.setConfigCompileList(configCompileList); -// maatBean.setAuditTime(entity.getAuditTime()); -// maatBean.setCreatorName(entity.getCurrentUser().getName()); -// maatBean.setVersion(Constants.MAAT_VERSION); -// maatBean.setOpAction(Constants.UPDATE_ACTION); -// //调用服务接口取消配置 -// String json=gsonToJson(maatBean); -// logger.info("ipaddr asn取消下发配置参数:"+json); -// //调用服务接口下发配置 -// ToMaatResult result = ConfigServiceUtil.put(json,1); -// logger.info("ipaddr asn取消配置响应信息:"+result.getMsg()); -// }else { -// throw new RuntimeException("unknown isAudit value "+isAudit); -// } -// -// } - @Transactional(readOnly=false,rollbackFor=RuntimeException.class) - public void deleteIp(String ids,String compileIds,int functionId){ - if(StringUtils.isNotBlank(compileIds)){ - for(String compileId:compileIds.split(",")){//强转数字,防止注入 + + // @Transactional(readOnly=false,rollbackFor=RuntimeException.class) + // @Deprecated + // public void auditAsnCfg(CfgIndexInfo entity,Integer isAudit){ + // entity.setTableName(CfgIndexInfo.getTablename()); + // entity.setIsAudit(isAudit); + // ipCfgDao.auditCfg(entity); + // ToMaatBean maatBean = new ToMaatBean(); + // + // List configCompileList = new ArrayList<>(); + // + // if(isAudit==Constants.AUDIT_YES) { + // List + // asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); + // if(asnKeywordCfgs!=null&&asnKeywordCfgs.size()>0) { + // MaatCfg maatCfg = new MaatCfg(); + // List groupRelationList = new ArrayList<>(); + // List ipRegionList = new ArrayList<>(); + // List strRegionList = new ArrayList<>(); + // List numRegionList = new ArrayList<>(); + // List digestRegionList = new ArrayList<>(); + // List areaIpRegionList = new ArrayList<>(); + // maatCfg.initDefaultValue(); + // BeanUtils.copyProperties(entity, maatCfg); + // maatCfg.setAction(entity.getAction()); + // maatCfg.setAuditTime(entity.getAuditTime()); + // + // maatCfg.setNumRegionList(numRegionList); + // maatCfg.setDigestRegionList(digestRegionList); + // maatCfg.setGroupRelationList(groupRelationList); + // maatCfg.setAreaIpRegionList(areaIpRegionList); + // maatCfg.setIsValid(entity.getIsValid()); + // //group + // List groupIds=ConfigServiceUtil.getId(2, 1); + // GroupCfg groupCfg=new GroupCfg(); + // groupCfg.setCompileId(entity.getCompileId()); + // //groupCfg.setGroupId(Integer.parseInt(entity.getUserRegion4())); + // groupCfg.setGroupId(groupIds.get(0)); + // groupCfg.setIsValid(Constants.VALID_YES); + // groupCfg.setAuditTime(entity.getAuditTime()); + // groupRelationList.add(groupCfg); + // maatCfg.setGroupNum(groupRelationList.size()); + // maatCfg.setIpRegionList(ipRegionList); + // List regions=ConfigServiceUtil.getId(3, asnKeywordCfgs.size()); + // int index=0; + // List + // functionRegionDicts=DictUtils.getFunctionRegionDictList(entity.getFunctionId()); + // String cfgType=null; + // for(FunctionRegionDict dict:functionRegionDicts) { + // if("asn".equals(dict.getConfigServiceType())) { + // cfgType=dict.getCfgType(); + // } + // } + // for(AsnKeywordCfg keyword:asnKeywordCfgs) { + // StringCfg cfg=new StringCfg(); + // BeanUtils.copyProperties(keyword, cfg); + // cfg.setRegionId(index); + // //需要根据文档 + // //cfg.setCfgType(StringUtils.isBlank(cfgType)?"NTC_ASN_NUMBER":cfgType); + // cfg.setGroupId(groupIds.get(0)); + // cfg.setAuditTime(entity.getAuditTime()); + // cfg.setIsValid(entity.getIsValid()); + // cfg.setRegionId(regions.get(index)); + // //cfg.setGroupId(Integer.parseInt(entity.getUserRegion4())); + // strRegionList.add(cfg); + // index++; + // } + // maatCfg.setStrRegionList(strRegionList); + // configCompileList.add(maatCfg); + // maatBean.setConfigCompileList(configCompileList); + // maatBean.setAuditTime(entity.getAuditTime()); + // maatBean.setCreatorName(entity.getCurrentUser().getName()); + // maatBean.setVersion(Constants.MAAT_VERSION); + // maatBean.setOpAction(Constants.INSERT_ACTION); + // + // //调用服务接口下发配置数据 + // String json=gsonToJson(maatBean); + // logger.info("ipaddr asn配置下发配置参数:"+json); + // //调用服务接口下发配置 + // ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); + // logger.info("ipaddr asn配置下发响应信息:"+result.getMsg()); + //// } + // } + // + // }else if(isAudit==Constants.AUDIT_NOT_YES) {//取消审核通过 + // MaatCfg maatCfg = new MaatCfg(); + // maatCfg.setCompileId(entity.getCompileId()); + // maatCfg.setServiceId(entity.getServiceId()); + // maatCfg.setIsValid(0);//无效 + // configCompileList.add(maatCfg); + // maatBean.setConfigCompileList(configCompileList); + // maatBean.setAuditTime(entity.getAuditTime()); + // maatBean.setCreatorName(entity.getCurrentUser().getName()); + // maatBean.setVersion(Constants.MAAT_VERSION); + // maatBean.setOpAction(Constants.UPDATE_ACTION); + // //调用服务接口取消配置 + // String json=gsonToJson(maatBean); + // logger.info("ipaddr asn取消下发配置参数:"+json); + // //调用服务接口下发配置 + // ToMaatResult result = ConfigServiceUtil.put(json,1); + // logger.info("ipaddr asn取消配置响应信息:"+result.getMsg()); + // }else { + // throw new RuntimeException("unknown isAudit value "+isAudit); + // } + // + // } + @Transactional(readOnly = false, rollbackFor = RuntimeException.class) + public void deleteIp(String ids, String compileIds, int functionId) { + if (StringUtils.isNotBlank(compileIds)) { + for (String compileId : compileIds.split(",")) {// 强转数字,防止注入 Integer.parseInt(compileId); } - ipCfgDao.deleteByCompileIds(new BaseIpCfg().getCurrentUser().getId(),AreaIpCfg.getTablename(),compileIds); + ipCfgDao.deleteByCompileIds(new BaseIpCfg().getCurrentUser().getId(), AreaIpCfg.getTablename(), compileIds); } - List ipCfgs=new ArrayList(); - Date date =new Date(); - if(StringUtils.isNotBlank(ids)){ - for(String idStr:ids.split(",")){ - if(StringUtils.isNotBlank(idStr)){ - BaseIpCfg cfg=new BaseIpCfg(); + List ipCfgs = new ArrayList(); + Date date = new Date(); + if (StringUtils.isNotBlank(ids)) { + for (String idStr : ids.split(",")) { + if (StringUtils.isNotBlank(idStr)) { + BaseIpCfg cfg = new BaseIpCfg(); cfg.setCfgId(Long.parseLong(idStr)); cfg.setTableName(IpPortCfg.getTablename()); cfg.setEditorId(cfg.getCurrentUser().getId()); @@ -894,132 +923,145 @@ public class IpCfgService extends CrudService { } } this.deleteBatch(ipCfgs, IpCfgDao.class); - } + } + /** * - * deleteIpCfg(删除IP类配置) - * (继承BaseIpCfg这个类方可使用) + * deleteIpCfg(删除IP类配置) (继承BaseIpCfg这个类方可使用) + * * @param baseIpCfg - * @return - *int - * @exception - * @since 1.0.0 + * @return int + * @exception @since + * 1.0.0 */ - @Transactional(readOnly=false,rollbackFor=RuntimeException.class) - public void deleteIpCfg(List baseIpCfg, List areaCfg){ - List cfgs=new ArrayList<>(); - if(areaCfg!=null&&areaCfg.size()>0){ + @Transactional(readOnly = false, rollbackFor = RuntimeException.class) + public void deleteIpCfg(List baseIpCfg, List areaCfg) { + List cfgs = new ArrayList<>(); + if (areaCfg != null && areaCfg.size() > 0) { cfgs.addAll(areaCfg); - this.deleteBatch(cfgs,IpCfgDao.class); + this.deleteBatch(cfgs, IpCfgDao.class); } - if(baseIpCfg!=null&&baseIpCfg.size()>0){ + if (baseIpCfg != null && baseIpCfg.size() > 0) { this.deleteBatch(baseIpCfg, IpCfgDao.class); } - - } + + } + /** * - * getIpCfg(根据IP与类名获取IP配置) - * (继承BaseIpCfg这个类方可使用) + * getIpCfg(根据IP与类名获取IP配置) (继承BaseIpCfg这个类方可使用) + * * @param clazz * @param id - * @return - *BaseIpCfg - * @exception - * @since 1.0.0 + * @return BaseIpCfg + * @exception @since + * 1.0.0 */ - public BaseIpCfg getIpCfgById(BaseIpCfg baseIpCfg){ + public BaseIpCfg getIpCfgById(BaseIpCfg baseIpCfg) { return ipCfgDao.getById(baseIpCfg.getTableName(), baseIpCfg.getCfgId()); } - public CfgIndexInfo getIpPortCfg(Long cfgId,Integer compileId){ - CfgIndexInfo entity = ipCfgDao.getCfgIndexInfo(cfgId,compileId); + + public CfgIndexInfo getIpPortCfg(Long cfgId, Integer compileId) { + CfgIndexInfo entity = ipCfgDao.getCfgIndexInfo(cfgId, compileId); List ipPortList = ipCfgDao.getIpPortList(entity); List subscribeIdList = stringCfgDao.findSubscribeIdCfgListByCfgIndexInfo(entity); entity.setIpPortList(ipPortList); entity.setNtcSubscribeIdCfgList(subscribeIdList); - if(StringUtils.isNotBlank(entity.getUserRegion4())) { - List asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); + if (StringUtils.isNotBlank(entity.getUserRegion4())) { + List asnKeywordCfgs = stringCfgDao.findAsnKeywordCfgList(entity); entity.setAsnKeywords(asnKeywordCfgs); } return entity; } - public CfgIndexInfo exportIpInfo(CfgIndexInfo entity){ + + public CfgIndexInfo exportIpInfo(CfgIndexInfo entity) { List ipPortList = ipCfgDao.getIpPortList(entity); entity.setIpPortList(ipPortList); - if(StringUtils.isNotBlank(entity.getUserRegion4())) { - List asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); + if (StringUtils.isNotBlank(entity.getUserRegion4())) { + List asnKeywordCfgs = stringCfgDao.findAsnKeywordCfgList(entity); entity.setAsnKeywords(asnKeywordCfgs); } return entity; } - public BaseIpCfg getIpCfgById(String tableName,long id){ + + public BaseIpCfg getIpCfgById(String tableName, long id) { return ipCfgDao.getById(tableName, id); } - public Integer getIsValid(BaseIpCfg baseIpCfg){ + + public Integer getIsValid(BaseIpCfg baseIpCfg) { return ipCfgDao.getIsValid(baseIpCfg); } - public Integer getIsValid(String tableName, long id){ - return ipCfgDao.getIsValid(tableName,id); + + public Integer getIsValid(String tableName, long id) { + return ipCfgDao.getIsValid(tableName, id); } - public Integer getIsAudit(BaseIpCfg baseIpCfg){ + + public Integer getIsAudit(BaseIpCfg baseIpCfg) { return ipCfgDao.getIsAudit(baseIpCfg); } - public Integer getIsAudit(String tableName, long id){ - return ipCfgDao.getIsAudit(tableName,id); + + public Integer getIsAudit(String tableName, long id) { + return ipCfgDao.getIsAudit(tableName, id); } - public List getAreaCfgByCompileId(/*int functionId,*/int compileId){ + + public List getAreaCfgByCompileId(/* int functionId, */int compileId) { return areaIpCfgDao.getByCompileId(compileId); } - public List getListByComileId(String tableName,int functionId,String ids){ - return ipCfgDao.getListByComileId(tableName,functionId,ids); + + public List getListByComileId(String tableName, int functionId, String ids) { + return ipCfgDao.getListByComileId(tableName, functionId, ids); } - public List getListByCfgId(String tableName,int functionId,String ids){ - return ipCfgDao.getListByCfgId(tableName,functionId,ids); + + public List getListByCfgId(String tableName, int functionId, String ids) { + return ipCfgDao.getListByCfgId(tableName, functionId, ids); } - public Integer getCompileId(){ - //调用服务接口获取compileId + + public Integer getCompileId() { + // 调用服务接口获取compileId Integer compileId = 0; try { - List compileIds = ConfigServiceUtil.getId(1,1); - if(!StringUtil.isEmpty(compileIds)){ + List compileIds = ConfigServiceUtil.getId(1, 1); + if (!StringUtil.isEmpty(compileIds)) { compileId = compileIds.get(0); } } catch (Exception e) { e.printStackTrace(); logger.info("获取编译ID出错"); - throw new MaatConvertException(":"+e.getMessage()); + throw new MaatConvertException(":" + e.getMessage()); } return compileId; } + /** - * getListByCfgIdWithName(这里用一句话描述这个方法的作用) - * (这里描述这个方法适用条件 – 可选) + * getListByCfgIdWithName(这里用一句话描述这个方法的作用) (这里描述这个方法适用条件 – 可选) + * * @param tablename * @param functionId * @param ids - * @return - *List - * @exception - * @since 1.0.0 - */ + * @return List + * @exception @since + * 1.0.0 + */ public List getListByCfgIdWithName(String tablename, Integer functionId, String ids) { // TODO Auto-generated method stub - return ipCfgDao.getListByCfgIdWithName(tablename,functionId,ids); + return ipCfgDao.getListByCfgIdWithName(tablename, functionId, ids); } + /** * 获取国际化配置文件 + * * @return */ - public Properties getMsgProp(){ + public Properties getMsgProp() { Properties msgProp = new Properties(); try { String language = LocaleContextHolder.getLocale().getLanguage(); if (language.equals("zh_cn") || language.equals("zh")) { - msgProp=Configurations.getMsgPropZh(); + msgProp = Configurations.getMsgPropZh(); } else if (language.equals("ru")) { - msgProp=Configurations.getMsgPropRu(); + msgProp = Configurations.getMsgPropRu(); } else { - msgProp=Configurations.getMsgPropEn(); + msgProp = Configurations.getMsgPropEn(); } } catch (Exception e) { @@ -1028,17 +1070,18 @@ public class IpCfgService extends CrudService { } return msgProp; } + public Page getIpCfgList(Page page, CfgIndexInfo entity) { - entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(),"a")); + entity.getSqlMap().put("dsf", configScopeFilter(entity.getCurrentUser(), "a")); entity.setPage(page); List list = ipCfgDao.getIpCfgList(entity); page.setList(list); return page; } - + public List getByIdsList(String ids) { List list = ipCfgDao.getByIdsList(ids); return list; } - + } diff --git a/src/main/resources/sql/20190417/extends_ip_port_pattern.sql b/src/main/resources/sql/20190417/extends_ip_port_pattern.sql new file mode 100644 index 000000000..63f182ef8 --- /dev/null +++ b/src/main/resources/sql/20190417/extends_ip_port_pattern.sql @@ -0,0 +1,104 @@ +#function_region_dict 对应ip_pattern,port_pattern的字段长度拓展一倍,使用分号分隔源/目的 +ALTER TABLE function_region_dict MODIFY config_ip_pattern VARCHAR(20) COMMENT "ip的格式 1:ip掩码;2:IP范围;3:IP;使用逗号分隔,源ip与目的IP使用;分隔"; +ALTER TABLE function_region_dict MODIFY config_port_pattern VARCHAR(20) COMMENT "端口的格式,1:port;2:port_mask;使用逗号分隔,源端口与目的端口使用;分隔"; +#各表修改ip_pattern,port_pattern +#app_ip_cfg +ALTER TABLE app_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE app_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE app_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE app_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#app_ip_range_cfg +ALTER TABLE app_ip_range_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE app_ip_range_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE app_ip_range_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE app_ip_range_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#area_ip_cfg +ALTER TABLE area_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE area_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE area_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE area_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#asn_ip_cfg +ALTER TABLE asn_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE asn_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE asn_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE asn_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#av_cont_ip_cfg +ALTER TABLE av_cont_ip_cfg change ip_pattern src_ip_pattern int COMMENT '源ip格式'; +ALTER TABLE av_cont_ip_cfg add dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE av_cont_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE av_cont_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#av_pic_ip_cfg +ALTER TABLE av_pic_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE av_pic_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE av_pic_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE av_pic_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#av_voip_ip_cfg +ALTER TABLE av_voip_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE av_voip_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE av_voip_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE av_voip_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#ddos_ip_cfg +ALTER TABLE ddos_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE ddos_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE ddos_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE ddos_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#dns_ip_cfg +ALTER TABLE dns_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE dns_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE dns_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE dns_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#ip_port_cfg +ALTER TABLE ip_port_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE ip_port_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE ip_port_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE ip_port_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#ip_reuse_ip_cfg +ALTER TABLE ip_reuse_ip_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE ip_reuse_ip_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +ALTER TABLE ip_reuse_ip_cfg CHANGE port_pattern src_port_pattern INT COMMENT '源端口格式'; +ALTER TABLE ip_reuse_ip_cfg ADD dest_port_pattern INT COMMENT '目的端口格式'; +#ip_reuse_policy_cfg +ALTER TABLE ip_reuse_policy_cfg CHANGE ip_pattern src_ip_pattern INT COMMENT '源ip格式'; +ALTER TABLE ip_reuse_policy_cfg ADD dest_ip_pattern INT COMMENT '目的ip格式'; +#修改字典的值 +UPDATE function_region_dict SET config_ip_pattern ="1,2,3;1,2,3" WHERE config_ip_pattern="1,2,3"; +UPDATE function_region_dict SET config_ip_pattern ="1;1" WHERE config_ip_pattern="1"; +UPDATE function_region_dict SET config_ip_pattern ="3;3" WHERE config_ip_pattern="3"; +UPDATE function_region_dict SET config_ip_pattern ="1,3;1,3" WHERE config_ip_pattern="1,3"; + +UPDATE function_region_dict SET config_port_pattern ="1;1" WHERE config_port_pattern="1"; +UPDATE function_region_dict SET config_port_pattern ="1,2;1,2" WHERE config_port_pattern="1,2"; +#Spoofing IP修改只显示目的IP +UPDATE function_region_dict SET config_ip_port_show=3 WHERE function_id=401; +#ASN IP修改只显示目的IP +UPDATE function_region_dict SET config_ip_port_show=3 WHERE function_id=600; +#sql 更新字段语句 +UPDATE app_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE app_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE app_ip_range_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE app_ip_range_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE area_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE area_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE asn_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE asn_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE av_cont_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE av_cont_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE av_pic_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE av_pic_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE av_voip_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE av_voip_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE ddos_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE ddos_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE dns_ip_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE dns_ip_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) + +UPDATE ip_port_cfg c SET c.dest_ip_pattern =(SELECT b.src_ip_pattern FROM ( SELECT a.src_ip_pattern,a.`cfg_id` FROM ip_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) +UPDATE ip_port_cfg c SET c.dest_port_pattern =(SELECT b.src_port_pattern FROM ( SELECT a.src_port_pattern,a.`cfg_id` FROM port_port_cfg a) b WHERE b.cfg_id=c.`cfg_id`) \ No newline at end of file