package com.nis.web.service.configuration; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.nis.domain.FunctionRegionDict; import com.nis.domain.Page; import com.nis.domain.basics.AsnGroupInfo; import com.nis.domain.callback.InlineIp; import com.nis.domain.configuration.AreaIpCfg; import com.nis.domain.configuration.AsnKeywordCfg; import com.nis.domain.configuration.BaseIpCfg; import com.nis.domain.configuration.BaseStringCfg; import com.nis.domain.configuration.CfgIndexInfo; import com.nis.domain.configuration.IpPortCfg; import com.nis.domain.configuration.NtcSubscribeIdCfg; import com.nis.domain.maat.MaatCfg; import com.nis.domain.maat.MaatCfg.DigestCfg; import com.nis.domain.maat.MaatCfg.GroupCfg; import com.nis.domain.maat.MaatCfg.IpCfg; import com.nis.domain.maat.MaatCfg.NumBoundaryCfg; import com.nis.domain.maat.MaatCfg.StringCfg; import com.nis.domain.maat.ToMaatBean; import com.nis.domain.maat.ToMaatResult; import com.nis.exceptions.MaatConvertException; import com.nis.util.ConfigServiceUtil; import com.nis.util.Configurations; import com.nis.util.Constants; import com.nis.util.DictUtils; import com.nis.util.StringUtil; import com.nis.web.dao.basics.AsnGroupInfoDao; import com.nis.web.dao.basics.AsnIpCfgDao; import com.nis.web.dao.configuration.AreaIpCfgDao; import com.nis.web.dao.configuration.IpCfgDao; import com.nis.web.dao.configuration.StringCfgDao; import com.nis.web.dao.specific.ConfigGroupInfoDao; import com.nis.web.security.UserUtils; import com.nis.web.service.CrudService; /** * IP相关配置事务类 * @author dell * */ @Service public class IpCfgService extends CrudService { @Autowired protected IpCfgDao ipCfgDao; @Autowired protected StringCfgDao stringCfgDao; @Autowired protected AreaIpCfgDao areaIpCfgDao; @Autowired //protected SpecificServiceCfgDao specificServiceCfgDao; protected AsnGroupInfoDao asnGroupInfoDao; @Autowired protected ConfigGroupInfoDao configGroupInfoDao; @Autowired protected AsnIpCfgDao asnIpCfgDao; /** * * addIpCfg(新增IP类配置) * (继承BaseIpCfg这个类方可使用) * @param baseIpCfg * @return *int * @exception * @since 1.0.0 */ @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)){ compileId = compileIds.get(0); } } catch (MaatConvertException e) { e.printStackTrace(); logger.info("获取编译ID出错"); throw new MaatConvertException(":"+e.getMessage()); } if(compileId!=0){ cfg.setCompileId(compileId); setAreaEffectiveIds(cfg); 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", "cfgType","ipPattern","srcIpAddress","portPattern","srcPort","destIpAddress","destPort"}); c.setTableName(AreaIpCfg.getTablename()); } this.saveIpBatch(cfg.getAreaCfg()); } ipCfgDao.insert(cfg); }else{ throw new MaatConvertException(": compileId is 0"); } } @Transactional(readOnly=false,rollbackFor=RuntimeException.class) public void saveIpCfg(CfgIndexInfo entity){ //设置区域运营商信息 setAreaEffectiveIds(entity); entity.setIsValid(0); entity.setIsAudit(0); if(entity.getCfgId()==null){ Integer compileId = 0; try { List idList = ConfigServiceUtil.getId(1, 1); if(idList!=null && idList.size()>0){ compileId = idList.get(0); } } catch (MaatConvertException e) { logger.info("获取编译ID出错"); throw new MaatConvertException(""); } entity.setCompileId(compileId); entity.setCreateTime(new Date()); entity.setCreatorId(entity.getCurrentUser().getId()); //保存asn组织信息 字符串域信息 handleAsn(entity.getAsnKeywords(), entity); ipCfgDao.saveCfgIndex(entity); 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"}); stringCfgDao.saveSubscribeIdCfg(cfg); } } } //保存区域IP信息 if(entity.getAreaCfg()!=null){ for(AreaIpCfg cfg:entity.getAreaCfg()){ cfg.initDefaultValue(); BeanUtils.copyProperties(entity, cfg,new String[]{"cfgRegionCode","cfgType"}); areaIpCfgDao.saveAreaIpCfg(cfg); } } }else{ entity.setEditTime(new Date()); entity.setEditorId(entity.getCurrentUser().getId()); //保存asn组织信息 字符串域信息 handleAsn(entity.getAsnKeywords(), entity); ipCfgDao.updateCfgIndex(entity); entity.setCreateTime(new Date()); entity.setCreatorId(entity.getCurrentUser().getId()); //无效子配置后,再新增子配置 ipCfgDao.deleteIpCfg(entity); stringCfgDao.deleteSubscribeIdCfgByCfgIndexInfo(entity); AreaIpCfg area = new AreaIpCfg(); area.setCompileId(entity.getCompileId()); area.setFunctionId(entity.getFunctionId()); areaIpCfgDao.deleteAreaIpCfg(area); 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"}); stringCfgDao.saveSubscribeIdCfg(cfg); } } } //保存区域IP信息 if(entity.getAreaCfg()!=null){ for(AreaIpCfg cfg:entity.getAreaCfg()){ cfg.initDefaultValue(); BeanUtils.copyProperties(entity, cfg,new String[]{"cfgDesc","cfgRegionCode","cfgType"}); areaIpCfgDao.saveAreaIpCfg(cfg); } } handleAsn(entity.getAsnKeywords(), entity); //保存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 String org=entity.getUserRegion4(); stringCfgDao.deleteAsnKeyword(entity); List asnGroupInfos=asnGroupInfoDao.getValidConfigGroupInfoByName(org); for(AsnGroupInfo info:asnGroupInfos) { 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.setExprType(0); asnKeywordCfg.setMatchMethod(3); asnKeywordCfg.setExType("0"); asnKeywordCfg.setIsHexbin(0); asnKeywordCfg.setCfgRegionCode(regionDict.getConfigRegionCode()); asnKeywordCfg.setCfgType(regionDict.getConfigRegionValue()); asnKeywordCfg.setCreateTime(entity.getCreateTime()); asnKeywordCfg.setCreatorId(UserUtils.getUser().getId()); asnKeywordCfg.setFunctionId(regionDict.getFunctionId()); asnKeywordCfg.setEditorId(entity.getEditorId()); asnKeywordCfg.setEditTime(entity.getEditTime()); asnKeywordCfg.setCompileId(entity.getCompileId()); stringCfgDao.saveStringCfgBatch(asnKeywordCfg); } } }*/ } } public void updateIpCfgValid(Integer isValid,String ids,Integer functionId){ String[] idArray = ids.split(","); for(String id :idArray){ CfgIndexInfo entity = new CfgIndexInfo(); entity.setCfgId(Long.parseLong(id)); entity.setIsValid(isValid); entity.setEditorId(UserUtils.getUser().getId()); entity.setEditTime(new Date()); 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){ IpPortCfg cfg = new IpPortCfg(); BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); cfg.setTableName(IpPortCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } if(entity.getNtcSubscribeIdCfgList()!=null && entity.getNtcSubscribeIdCfgList().size()>0) { NtcSubscribeIdCfg cfg = new NtcSubscribeIdCfg(); BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); cfg.setTableName(NtcSubscribeIdCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } if(entity.getAsnKeywords()!=null && entity.getAsnKeywords().size()>0) { AsnKeywordCfg cfg = new AsnKeywordCfg(); BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); cfg.setTableName(AsnKeywordCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } //保存区域IP信息 if(entity.getAreaCfg()!=null && entity.getAreaCfg().size()>0){ AreaIpCfg cfg = new AreaIpCfg(); BeanUtils.copyProperties(entity, cfg, new String[]{"cfgId"}); cfg.setTableName(AreaIpCfg.getTablename()); ipCfgDao.updateCfgValid(cfg); } } } /** * * updateIpCfg(更新IP类配置) * (继承BaseIpCfg这个类方可使用) * @param baseIpCfg * @return *int * @exception * @since 1.0.0 */ @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设置 setAreaEffectiveIds(cfg); 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", "cfgType","ipPattern","srcIpAddress","portPattern","srcPort","destIpAddress","destPort"}); c.setTableName(AreaIpCfg.getTablename()); c.setCreatorId(cfg.getCurrentUser().getId()); c.setCreateTime(date); } this.saveIpBatch(cfg.getAreaCfg()); } ipCfgDao.update(cfg); } @Deprecated public void audit(BaseIpCfg cfg) throws Exception{ //更新IP配置与区域IP的状态 List beans=new ArrayList<>(); beans.add(cfg); ipCfgDao.audit(cfg); List beans1=new ArrayList<>(); List areaIpCfgList=areaIpCfgDao.getByCompileId(cfg.getCompileId()); for(AreaIpCfg area:areaIpCfgList){ BeanUtils.copyProperties(cfg,area ,new String[]{"cfgRegionCode" ,"cfgType" ,"cfgId" ,"ipType" ,"ipPattern" ,"srcIpAddress" ,"portPattern" ,"srcPort" ,"destPort" ,"protocol" ,"direction" ,"protocolId" }); beans1.add(area); } this.auditIpBatch(beans1); List configCompileList = new ArrayList<>(); List groupRelationList = new ArrayList<>(); List ipRegionList = new ArrayList<>(); List strRegionList = new ArrayList<>(); List numRegionList = new ArrayList<>(); List digestRegionList = new ArrayList<>(); List areaIpRegionList = new ArrayList<>(); 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(); 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); ipList.add(ip); //调用服务接口下发配置数据 json=gsonToJson(ipList); logger.info("IP配置下发配置参数:"+json); //调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json); if(result!=null){ logger.info("IP配置配置下发响应信息:"+result.getMsg()); } } catch (Exception 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()); maatCfg.setAction(cfg.getAction()); maatCfg.setAuditTime(cfg.getAuditTime()); maatCfg.setIpRegionList(ipRegionList); maatCfg.setStrRegionList(strRegionList); maatCfg.setNumRegionList(numRegionList); maatCfg.setAreaIpRegionList(areaIpRegionList); maatCfg.setDigestRegionList(digestRegionList); 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(); maatCfg.setUserRegion(region); }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()); } }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(); } maatCfg.setUserRegion(userRegion); } } configCompileList.add(maatCfg); maatBean.setOpAction(Constants.INSERT_ACTION); maatBean.setConfigCompileList(configCompileList); maatBean.setAuditTime(cfg.getAuditTime()); maatBean.setCreatorName(cfg.getCurrentUser().getName()); maatBean.setVersion(Constants.MAAT_VERSION); //调用服务接口下发配置数据 json=gsonToJson(maatBean); logger.info("IP配置下发配置参数:"+json); //调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); if(result!=null){ logger.info("IP配置配置下发响应信息:"+result.getMsg()); } } catch (Exception e) { logger.error("IP配置配置下发失败",e); throw e; } }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); ipList.add(ip); //调用服务接口取消配置 json=gsonToJson(ipList); logger.info("IP管控配置参数:"+json); //调用服务接口取消配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 2); logger.info("IP配置取消配置响应信息:"+result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("IP配置取消配置失败"); throw e; } }else if(maatType==Constants.MAAT_TYPE){ maatCfg.setCompileId(cfg.getCompileId()); maatCfg.setServiceId(cfg.getServiceId()); 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); //调用服务接口取消配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 1); logger.info("IP管控取消配置响应信息:"+result.getMsg()); } catch (Exception e) { e.printStackTrace(); logger.info("IP管控取消配置失败"); throw e; } }else { throw new MaatConvertException(":"+props.getProperty("unknown_cfg_type")); } } } public void auditIpCfg(CfgIndexInfo entity,Integer isAudit) throws MaatConvertException{ Properties props=this.getMsgProp(); //修改数据库审核状态信息 entity.setTableName(CfgIndexInfo.getTablename()); entity.setIsAudit(isAudit); ipCfgDao.auditCfg(entity); ToMaatBean maatBean = new ToMaatBean(); MaatCfg maatCfg = new MaatCfg(); List configCompileList = new ArrayList(); List groupRelationList = new ArrayList(); List ipRegionList = new ArrayList(); List strRegionList = new ArrayList(); List numRegionList = new ArrayList(); List digestRegionList = new ArrayList(); List areaIpRegionList = new ArrayList(); //获取region List dictList = DictUtils.getFunctionRegionDictList(entity.getFunctionId()); int maatType=0; //查询子配置并修改审核状态 entity = this.getIpPortCfg(entity.getCfgId(),entity.getCompileId()); 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"}); 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){ numRegionList.addAll(map.get("numRegionList")); } } }else{ maatType=1; } if(entity.getNtcSubscribeIdCfgList()!=null && entity.getNtcSubscribeIdCfgList().size()>0){ NtcSubscribeIdCfg cfg = new NtcSubscribeIdCfg(); 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"); } } //asn配置下发 auditAsnCfgForIpAddr(groupRelationList,strRegionList,entity,entity.getAsnKeywords()); //保存区域IP信息 List areaIpCfgList=areaIpCfgDao.getByCompileId(entity.getCompileId()); if(!StringUtil.isEmpty(areaIpCfgList)){ AreaIpCfg cfg = new AreaIpCfg(); 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){ 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); //调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.postCallbackCfg(json); if(result!=null){ logger.info("IP配置配置下发响应信息:"+result.getMsg()); } } catch (Exception e) { logger.error("IP配置配置下发失败",e); throw e; } }else if(maatType==Constants.MAAT_TYPE){ maatCfg.initDefaultValue(); BeanUtils.copyProperties(entity, maatCfg); maatCfg.setAction(entity.getAction()); maatCfg.setAuditTime(entity.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()); 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); //限速需要发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); //调用服务接口下发配置 ToMaatResult result = ConfigServiceUtil.postMaatCfg(json); logger.info("ip配置下发响应信息:"+result.getMsg()); }else { throw new RuntimeException(":"+props.getProperty("unknown_cfg_type")); } }else if(isAudit==3){ 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); //调用服务接口下发配置 try { ToMaatResult result = ConfigServiceUtil.put(json, 2); if(result!=null){ logger.info("IP配置配置下发响应信息:"+result.getMsg()); } } catch (Exception e) { logger.error("IP配置配置下发失败",e); throw e; } }else if(maatType==Constants.MAAT_TYPE){ maatCfg.setCompileId(entity.getCompileId()); maatCfg.setServiceId(entity.getServiceId()); maatCfg.setIsValid(0);//无效 configCompileList.add(addKeepGroupList(maatCfg,entity)); 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")); } } } /** * * @param isAudit * @param isValid * @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(",")){//强转数字,防止注入 Integer.parseInt(compileId); } 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(); cfg.setCfgId(Long.parseLong(idStr)); cfg.setTableName(IpPortCfg.getTablename()); cfg.setEditorId(cfg.getCurrentUser().getId()); cfg.setEditTime(date); cfg.setIsValid(Constants.VALID_DEL); ipCfgs.add(cfg); } } } this.deleteBatch(ipCfgs, IpCfgDao.class); } /** * * deleteIpCfg(删除IP类配置) * (继承BaseIpCfg这个类方可使用) * @param baseIpCfg * @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){ cfgs.addAll(areaCfg); this.deleteBatch(cfgs,IpCfgDao.class); } if(baseIpCfg!=null&&baseIpCfg.size()>0){ this.deleteBatch(baseIpCfg, IpCfgDao.class); } } /** * * getIpCfg(根据IP与类名获取IP配置) * (继承BaseIpCfg这个类方可使用) * @param clazz * @param id * @return *BaseIpCfg * @exception * @since 1.0.0 */ 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); List ipPortList = ipCfgDao.getIpPortList(entity); List subscribeIdList = stringCfgDao.findSubscribeIdCfgListByCfgIndexInfo(entity); entity.setIpPortList(ipPortList); entity.setNtcSubscribeIdCfgList(subscribeIdList); List asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); entity.setAsnKeywords(asnKeywordCfgs); return entity; } public CfgIndexInfo exportIpInfo(CfgIndexInfo entity){ List ipPortList = ipCfgDao.getIpPortList(entity); entity.setIpPortList(ipPortList); List asnKeywordCfgs=stringCfgDao.findAsnKeywordCfgList(entity); entity.setAsnKeywords(asnKeywordCfgs); return entity; } public BaseIpCfg getIpCfgById(String tableName,long id){ return ipCfgDao.getById(tableName, id); } public Integer getIsValid(BaseIpCfg baseIpCfg){ return ipCfgDao.getIsValid(baseIpCfg); } public Integer getIsValid(String tableName, long id){ return ipCfgDao.getIsValid(tableName,id); } public Integer getIsAudit(BaseIpCfg baseIpCfg){ return ipCfgDao.getIsAudit(baseIpCfg); } public Integer getIsAudit(String tableName, long id){ return ipCfgDao.getIsAudit(tableName,id); } 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 getListByCfgId(String tableName,int functionId,String ids){ return ipCfgDao.getListByCfgId(tableName,functionId,ids); } public Integer getCompileId(){ //调用服务接口获取compileId Integer compileId = 0; try { 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()); } return compileId; } /** * getListByCfgIdWithName(这里用一句话描述这个方法的作用) * (这里描述这个方法适用条件 – 可选) * @param tablename * @param functionId * @param ids * @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 */ public Properties getMsgProp(){ Properties msgProp = new Properties(); try { String language = LocaleContextHolder.getLocale().getLanguage(); if (language.equals("zh_cn") || language.equals("zh")) { msgProp=Configurations.getMsgPropZh(); } else if (language.equals("ru")) { msgProp=Configurations.getMsgPropRu(); } else { msgProp=Configurations.getMsgPropEn(); } } catch (Exception e) { msgProp = null; logger.error("未知i18n消息配置文件,请确定文件是否存在!", e); } return msgProp; } public Page getIpCfgList(Page page, CfgIndexInfo entity) { 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; } }