diff --git a/src/main/java/com/nis/quartz/ScheduleStatisticASNIPNumJob.java b/src/main/java/com/nis/quartz/ScheduleStatisticASNIPNumJob.java new file mode 100644 index 000000000..c28a67328 --- /dev/null +++ b/src/main/java/com/nis/quartz/ScheduleStatisticASNIPNumJob.java @@ -0,0 +1,137 @@ +package com.nis.quartz; + + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; +import org.apache.log4j.Logger; +import org.quartz.DisallowConcurrentExecution; +import org.quartz.Job; +import org.quartz.JobExecutionContext; +import org.quartz.JobExecutionException; +import org.quartz.PersistJobDataAfterExecution; + +import com.nis.util.IPUtil; +import com.nis.util.StringUtil; +import com.nis.web.dao.basics.AsnGroupInfoDao; +import com.nis.web.dao.basics.AsnIpCfgDao; +import com.nis.web.service.SpringContextHolder; + +/** + * 定时任务: 定时统计ASN 下IPv4和IPV6的个数 + * 1、每 n s 执行一次(两个小时执行一次) + * 2、单线程执行 + * @author ddm + * + */ +@DisallowConcurrentExecution +@PersistJobDataAfterExecution +public class ScheduleStatisticASNIPNumJob implements Job { + private static final Logger logger = Logger.getLogger(ScheduleStatisticASNIPNumJob.class); + + @Override + public void execute(JobExecutionContext context) throws JobExecutionException { + AsnIpCfgDao asnIpCfgDao = SpringContextHolder.getBean(AsnIpCfgDao.class); + logger.info("定时统计ASN IP个数开始。。。。。。。。。。。。。。"); + long start=System.currentTimeMillis(); + Map> asnNumerMap=new HashMap<>(); + List asnIpList=new ArrayList<>(); + asnIpList=asnIpCfgDao.findAllAsnIpCfgList(); + + getAllASNIPNumber(asnIpList, asnNumerMap); + + updateAllASNIPNumber(asnNumerMap); + + long end=System.currentTimeMillis(); + logger.info("定时统计ASN IP个数结束:耗时("+(end-start)+"/毫秒)。。。。。。。。。。。。。。"); + } + + public void getAllASNIPNumber(List asnIpList,Map> asnNumerMap){ + logger.info("计算ASN IP开始:asn ip size:"+asnIpList.size()+"。。。。。。。。。。。。。。"); + long start=System.currentTimeMillis(); + if(!StringUtil.isEmpty(asnIpList)){ + try { + for (Iterator iterator = asnIpList.iterator(); iterator.hasNext();) { + Map asnIpMap=(Map) iterator.next(); + //groupId + Integer asnGroupId = (Integer)asnIpMap.get("asn_ip_group"); + //ipType(4:v4,6:v6) + Integer ipType= (Integer)asnIpMap.get("ip_type"); + //(1:mask,2:range,3:ip) + //Integer ipPattern= (Integer)asnIpMap.get("ip_pattern"); + //dest_ip_address + String ipAddress= (String)asnIpMap.get("dest_ip_address"); + long IPNumber=0; + if(ipType.equals(4)){ + if(ipAddress.indexOf("/") > -1){ + Integer mask=Integer.parseInt(ipAddress.split("/")[1]); + ipAddress=ipAddress.split("/")[0]; + IPNumber=IPUtil.getIpNum(ipAddress, mask); + }else{ + IPNumber=1; + } + //判断组是否已经存在 + if(asnNumerMap.keySet().contains(asnGroupId)){ + asnNumerMap.get(asnGroupId).put("v4", asnNumerMap.get(asnGroupId).get("v4")+IPNumber); + asnNumerMap.put(asnGroupId, asnNumerMap.get(asnGroupId)); + }else{ + Map map=new HashMap<>(); + map.put("v4", IPNumber); + map.put("v6", 0l); + asnNumerMap.put(asnGroupId, map); + } + }else{ + IPNumber=1; + //判断组是否已经存在 + if(asnNumerMap.keySet().contains(asnGroupId)){ + asnNumerMap.get(asnGroupId).put("v6", asnNumerMap.get(asnGroupId).get("v6")+IPNumber); + asnNumerMap.put(asnGroupId, asnNumerMap.get(asnGroupId)); + }else{ + Map map=new HashMap<>(); + map.put("v4", 0l); + map.put("v6", IPNumber); + asnNumerMap.put(asnGroupId, map); + } + } + } + } catch (Exception e) { + logger.error("计算ASN IP个数失败",e); + } + } + + long end=System.currentTimeMillis(); + logger.info("计算ASN IP个数结束:耗时("+(end-start)+"/毫秒)。。。。。。。。。。。。。。"); + } + public void updateAllASNIPNumber(Map> asnNumerMap) { + logger.info("修改ASN IP个数开始:asn size:"+asnNumerMap.size()+"。。。。。。。。。。。。。。"); + long start=System.currentTimeMillis(); + if(!StringUtil.isEmpty(asnNumerMap)){ + int index=0; + SqlSessionFactory sqlSessionFactory=SpringContextHolder.getBean(SqlSessionFactory.class); + SqlSession batchSqlSession = null; + try { + batchSqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH, true); + for(Entry> e: asnNumerMap.entrySet()) { + ((AsnGroupInfoDao) batchSqlSession.getMapper(AsnGroupInfoDao.class)).updateIpNum(e.getValue().get("v4"),e.getValue().get("v6"),e.getKey()); + batchSqlSession.commit(); + index++; + } + }catch (Exception e) { + logger.error("修改ASN IP个数失败", e); + } finally { + if(batchSqlSession != null){ + batchSqlSession.close(); + } + } + } + long end=System.currentTimeMillis(); + logger.info("修改ASN IP个数结束:耗时("+(end-start)+"/毫秒)。。。。。。。。。。。。。。"); + } +} diff --git a/src/main/java/com/nis/web/controller/configuration/proxy/PxyObjKeyringController.java b/src/main/java/com/nis/web/controller/configuration/proxy/PxyObjKeyringController.java index 894f18edb..c5059b0d0 100644 --- a/src/main/java/com/nis/web/controller/configuration/proxy/PxyObjKeyringController.java +++ b/src/main/java/com/nis/web/controller/configuration/proxy/PxyObjKeyringController.java @@ -122,7 +122,7 @@ public class PxyObjKeyringController extends BaseController { logger.error("证书文件校验失败", e); if (e instanceof MaatConvertException) { addMessage(redirectAttributes, "error", "request_service_failed"); - } else if (e instanceof MaatConvertException) { + } else if (e instanceof MultiPartNewException) { addMessage(redirectAttributes, "error", e.getMessage()); } else { addMessage(redirectAttributes, "error", "save_failed"); diff --git a/src/main/java/com/nis/web/controller/sys/StatisticSysUserWarnNumber.java b/src/main/java/com/nis/web/controller/sys/StatisticSysUserWarnNumber.java index 6e4a5860b..76229d8a7 100644 --- a/src/main/java/com/nis/web/controller/sys/StatisticSysUserWarnNumber.java +++ b/src/main/java/com/nis/web/controller/sys/StatisticSysUserWarnNumber.java @@ -72,7 +72,15 @@ public class StatisticSysUserWarnNumber { entity.setId(Integer.parseInt(map1.get("id").toString())); entity.setTableName(map1.get("tableName").toString()); //根据serviceID和表名查询界面各个业务的配置数量 - Integer cfgCount = sysUserWarnService.getCfgCount(entity); + Integer cfgCount=0; + if(map1.get("id").toString().equals("400")){//ASN IP(特殊的业务,需单独查询) + cfgCount = sysUserWarnService.getASNIPTotal(); + }else if(map1.get("id").toString().equals("1028")){// APP IP + + cfgCount = sysUserWarnService.getAPPIPTotal(); + }else{ + cfgCount = sysUserWarnService.getCfgCount(entity); + } //查询服务端的各个业务的配置数量 List list = effective.get(map1.get("id")); SysUserWarn sysUserWarn=new SysUserWarn(); @@ -93,7 +101,7 @@ public class StatisticSysUserWarnNumber { } //判断表中是否有数据 Integer total = sysUserWarnService.getAllInfoCount(); - if(total !=null && total>0){//说明有数据 先删除 后添加 + if(total != null && total > 0){//说明有数据 先删除 后添加 sysUserWarnService.deleteAllData(); sysUserWarnService.insert(listTotal); }else{// 没有 直接 添加 diff --git a/src/main/java/com/nis/web/controller/sys/SysUserWarnController.java b/src/main/java/com/nis/web/controller/sys/SysUserWarnController.java index 4e811fcd0..b9a6034be 100644 --- a/src/main/java/com/nis/web/controller/sys/SysUserWarnController.java +++ b/src/main/java/com/nis/web/controller/sys/SysUserWarnController.java @@ -49,7 +49,7 @@ public class SysUserWarnController extends BaseController{ return findServiceSum; } - public static void main(String[] args) { +/* public static void main(String[] args) { List> serviceList = ServiceConfigTemplateUtil.getServiceList(); System.out.println(serviceList); @@ -57,5 +57,5 @@ public class SysUserWarnController extends BaseController{ System.out.println(map.get("id")); System.out.println(map.get("tableName")); } - } + }*/ } diff --git a/src/main/java/com/nis/web/dao/SysUserWarnDao.java b/src/main/java/com/nis/web/dao/SysUserWarnDao.java index 3978a7224..ee05181f8 100644 --- a/src/main/java/com/nis/web/dao/SysUserWarnDao.java +++ b/src/main/java/com/nis/web/dao/SysUserWarnDao.java @@ -19,4 +19,8 @@ public interface SysUserWarnDao extends CrudDao{ public int insert(List list); //删除所有的数据 public int deleteAllData(); + //查询ASN IP 页面配置总量 + public Integer getASNIPTotal(); + //查询APP IP 页面配置总量 + public Integer getAPPIPTotal(); } diff --git a/src/main/java/com/nis/web/dao/SysUserWarnDao.xml b/src/main/java/com/nis/web/dao/SysUserWarnDao.xml index d38d881d8..04cd4267a 100644 --- a/src/main/java/com/nis/web/dao/SysUserWarnDao.xml +++ b/src/main/java/com/nis/web/dao/SysUserWarnDao.xml @@ -50,13 +50,15 @@ @@ -87,5 +89,22 @@ delete from sys_user_warn + + + + + \ No newline at end of file diff --git a/src/main/java/com/nis/web/service/SysUserWarnService.java b/src/main/java/com/nis/web/service/SysUserWarnService.java index b66abd20c..6bb8fd506 100644 --- a/src/main/java/com/nis/web/service/SysUserWarnService.java +++ b/src/main/java/com/nis/web/service/SysUserWarnService.java @@ -39,7 +39,7 @@ public class SysUserWarnService extends BaseService{ page.setList(allList); return page; } - //根据serviceID和表名查询业务配置的数量 + //查询总的记录数 public Integer getAllInfoCount(){ return sysUserWarnDao.getAllInfoCount(); @@ -69,4 +69,15 @@ public class SysUserWarnService extends BaseService{ return allSum; } + //查询ASN IP 页面配置总量 + public Integer getASNIPTotal(){ + + return sysUserWarnDao.getASNIPTotal(); + } + //查询APP IP 页面配置总量 + public Integer getAPPIPTotal(){ + + return sysUserWarnDao.getAPPIPTotal(); + } + } diff --git a/src/main/resources/applicationContext-quartz.xml b/src/main/resources/applicationContext-quartz.xml index e597748a0..00485961a 100644 --- a/src/main/resources/applicationContext-quartz.xml +++ b/src/main/resources/applicationContext-quartz.xml @@ -16,7 +16,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd" default-lazy-init="true"> - + @@ -35,7 +35,7 @@ - + @@ -51,8 +51,22 @@ + - + + + + + + + + + + + + + + @@ -64,6 +78,7 @@ + diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index 83926c54b..8e1808b75 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -104,10 +104,6 @@ - - - -