Merge branch 'develop_no_common_group' of https://git.mesalab.cn/K18_NTCS_WEB/NTC.git into develop_no_common_group

This commit is contained in:
duandongmei
2019-04-08 21:03:30 +08:00
11 changed files with 245 additions and 49 deletions

View File

@@ -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<Integer,Map<String,Long>> asnNumerMap=new HashMap<>();
List<Object[]> 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<Object[]> asnIpList,Map<Integer,Map<String,Long>> 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<String, Long> 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<String, Long> 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<Integer,Map<String,Long>> 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<Integer,Map<String,Long>> 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)+"/毫秒)。。。。。。。。。。。。。。");
}
}

View File

@@ -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");

View File

@@ -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<String> list = effective.get(map1.get("id"));
SysUserWarn sysUserWarn=new SysUserWarn();

View File

@@ -49,7 +49,7 @@ public class SysUserWarnController extends BaseController{
return findServiceSum;
}
public static void main(String[] args) {
/* public static void main(String[] args) {
List<Map<String, Object>> 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"));
}
}
}*/
}

View File

@@ -19,4 +19,8 @@ public interface SysUserWarnDao extends CrudDao<SysUserWarn>{
public int insert(List<SysUserWarn> list);
//删除所有的数据
public int deleteAllData();
//查询ASN IP 页面配置总量
public Integer getASNIPTotal();
//查询APP IP 页面配置总量
public Integer getAPPIPTotal();
}

View File

@@ -51,12 +51,14 @@
<select id="getCfgCount" parameterType="com.nis.domain.SysUserWarn" resultType="java.lang.Integer">
select count(cfg_id) cfgTotal from ${tableName}
SELECT COUNT(a.compile_id) cfgTotal from (
select compile_id from ${tableName}
<where>
service_id = #{id}
and is_valid=1
</where>
GROUP BY compile_id)a
</select>
@@ -87,5 +89,22 @@
delete from sys_user_warn
</delete>
<!-- 查询ASN IP 页面配置总量 -->
<select id="getASNIPTotal" resultType="java.lang.Integer">
select count(compile_id) cfgTotal from asn_group_info
where is_valid=1
</select>
<!-- 查询APP IP 页面配置总量 -->
<select id="getAPPIPTotal" resultType="java.lang.Integer">
select count(compile_id) cfgTotal from config_group_info
where is_issued=1
and group_type=1
</select>
</mapper>

View File

@@ -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();
}
}

View File

@@ -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">
<!-- 配置加载 任务执行类 -->
<!-- 配置加载 (正常任务)任务执行类 -->
<bean id="scheduleCfgJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.nis.quartz.ScheduleCfgJob"/>
<property name="name" value="scheduleCfgJobDetail" />
@@ -35,7 +35,7 @@
</bean>
<!-- 配置加载 任务执行类 -->
<!-- 配置加载 (全量同步未执行任务)任务执行类 -->
<bean id="scheduleSyncCfgJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.nis.quartz.ScheduleSyncCfgJob"/>
<property name="name" value="scheduleSyncCfgJobDetail" />
@@ -53,6 +53,20 @@
</bean>
<!-- ASN IP统计 start-->
<bean id="scheduleStatisticASNIPNumJobDetail" class="org.springframework.scheduling.quartz.JobDetailFactoryBean">
<property name="jobClass" value="com.nis.quartz.ScheduleStatisticASNIPNumJob"/>
<property name="name" value="scheduleStatisticASNIPNumJobDetail" />
<property name="group" value="statisticASNIPNum" />
</bean>
<bean id="scheduleStatisticASNIPNumSimpleTrigger" class="org.springframework.scheduling.quartz.CronTriggerFactoryBean">
<property name="jobDetail">
<ref bean="scheduleStatisticASNIPNumJobDetail" />
</property>
<!-- 每天零点执行一次-->
<property name="cronExpression" value="0 0 0 * * ?"/>
</bean>
<!-- 定时任务 -->
<bean id="NTCScheduler" class="org.springframework.scheduling.quartz.SchedulerFactoryBean" >
<property name="dataSource" ref="ProductDataSource" /><!-- 配置数据源 -->
@@ -64,6 +78,7 @@
<list>
<ref bean="scheduleCfgSimpleTrigger" />
<ref bean="scheduleSyncCfgSimpleTrigger" />
<ref bean="scheduleStatisticASNIPNumSimpleTrigger" />
</list>
</property>
</bean>

View File

@@ -104,10 +104,6 @@
<context:component-scan base-package="com.nis.web"></context:component-scan>
<context:component-scan base-package="com.nis.restful"></context:component-scan>
<bean id="asnIpIask" class="com.nis.web.task.StatisticASNIpNumer"></bean>
<task:scheduled-tasks>
<task:scheduled ref="asnIpIask" method="calculateASNIp" cron=" 0 0 0 * * ?" />
</task:scheduled-tasks>
<!-- 定时任务配置 end -->
<!-- 统计页面配置总量和服务配置总量的定时任务配置 -->
<!-- <bean id="sysUserWarnTask" class="com.nis.web.controller.sys.StatisticSysUserWarnNumber"></bean>

View File

@@ -72,12 +72,13 @@
$(this).val("");
});
//定时查询界面配置总量和服务配置总量 是否一致
t2 = window.setInterval("getServiceSum()",5*60*1000);
/** 20190404后台逻辑需要再修改暂时不开放此功能
t2 = window.setInterval("getServiceSum()",5*60*1000); */
//去掉定时器的方法
//window.clearInterval(t2);
});
var t2;
/* var t2; */
//获取界面总量和服务总量
function getServiceSum(){
$.ajax({

View File

@@ -452,12 +452,15 @@ $(function(){
$(this).prev("input[name$='cfgKeywords']").val(keywordValue);*/
exprTypeChecked(objNamePrefix,size,options);
if(size == 1){
var tagObj = $(this);
for(var key in protectionData){
if(tagObj.hasClass(key)){
protectedListWarn(tagObj,key);
}
}
}
},
onRemoveTag:function(tag,size){
$(this).parent(".col-md-6").next("div").html("");
@@ -469,6 +472,7 @@ $(function(){
$(this).prev("input[name$='cfgKeywords']").val(keywordValue);*/
exprTypeChecked(objNamePrefix,size,options);
if(size == 1){
var tagObj = $(this);
for(var key in protectionData){
if(tagObj.hasClass(key)){
@@ -476,6 +480,7 @@ $(function(){
}
}
}
}
});
$(".tagsinput").popover({
animation:true,