diff --git a/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatistic.java b/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatistic.java index 1969988..ad51c3e 100644 --- a/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatistic.java +++ b/src/main/java/com/nis/domain/restful/dashboard/TrafficTransStatistic.java @@ -1,8 +1,13 @@ package com.nis.domain.restful.dashboard; +import java.io.Serializable; import java.util.Date; -public class TrafficTransStatistic { +public class TrafficTransStatistic implements Serializable{ + /** + * + */ + private static final long serialVersionUID = 1L; private Integer statId ; private String addrType ; private Integer transType ; @@ -15,19 +20,19 @@ public class TrafficTransStatistic { private Date statTime ; private String time; - private Long pps; - private Long gbps; + private String pps; + private String gbps; - public Long getPps() { + public String getPps() { return pps; } - public void setPps(Long pps) { + public void setPps(String pps) { this.pps = pps; } - public Long getGbps() { + public String getGbps() { return gbps; } - public void setGbps(Long gbps) { + public void setGbps(String gbps) { this.gbps = gbps; } public String getTime() { diff --git a/src/main/java/com/nis/web/controller/restful/MaatTestController.java b/src/main/java/com/nis/web/controller/restful/MaatTestController.java index 5d288b3..86129d5 100644 --- a/src/main/java/com/nis/web/controller/restful/MaatTestController.java +++ b/src/main/java/com/nis/web/controller/restful/MaatTestController.java @@ -109,7 +109,7 @@ public class MaatTestController { // } // } try { - if (!configRedisService.delMaatConfig(compileMap)) { + if (!configRedisService.delMaatConfig(compileMap,false)) { FileUtils.addStrToFile( sdf.format(new Date()) + "\t" + "error:删除业务类型" + serviceType + "下的maat配置" + configId + "失败\n", Configurations.getStringProperty("maatTestLogPath", ""), true); diff --git a/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java index 1182231..7cf94d5 100644 --- a/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java +++ b/src/main/java/com/nis/web/controller/restful/TrafficeReportController.java @@ -51,7 +51,7 @@ import com.zdjizhi.utils.StringUtil; * */ @RestController -@RequestMapping("${servicePath}/ckLog/v1") +@RequestMapping("${servicePath}/log/v2") @Api(value = "TrafficeReportController", description = "流量统计查询报表controller") public class TrafficeReportController extends BaseRestController { diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.java b/src/main/java/com/nis/web/dao/TrafficReportDao.java index 2e62d79..939ee7b 100644 --- a/src/main/java/com/nis/web/dao/TrafficReportDao.java +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.java @@ -62,10 +62,6 @@ public interface TrafficReportDao extends CrudDao { - - - - NtcTotalReport getMaxReportTime(); Map getMaxStatTime(); List getTotalReportList(@Param("reportTime") Date reportTime); diff --git a/src/main/java/com/nis/web/dao/TrafficReportDao.xml b/src/main/java/com/nis/web/dao/TrafficReportDao.xml index b213b69..f0dd786 100644 --- a/src/main/java/com/nis/web/dao/TrafficReportDao.xml +++ b/src/main/java/com/nis/web/dao/TrafficReportDao.xml @@ -170,11 +170,11 @@ - STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]> + = STR_TO_DATE(#{searchReportStartTime},'%Y-%m-%d %H:%i:%s')]]> - + @@ -913,17 +913,19 @@ - - - - - - - - - - - + + + + + + + + + + + + + select sum(sum) sum,report_time time from ntc_entrance_report r where - =#{beginDate}]]> + =#{beginDate}]]> and entrance_id=#{entranceId} group by report_time order by report_time diff --git a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java index 9ef7063..b238c24 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java +++ b/src/main/java/com/nis/web/service/restful/ConfigJedisServiceimpl.java @@ -1011,11 +1011,11 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { list.add(i); } serviceConfigMap.put(129, list); - delMaatConfig(serviceConfigMap); + delMaatConfig(serviceConfigMap,false); } @Override - public boolean delMaatConfig(Map> serviceConfigMap) { + public boolean delMaatConfig(Map> serviceConfigMap,boolean isStart) { if (serviceConfigMap != null && serviceConfigMap.size() > 0) { Jedis resource = JedisUtils.getResource(0); Transaction transaction = resource.multi(); @@ -1036,82 +1036,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 按序号选择Redis数据库 transaction.select(redisDb); removeConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb, - idRelaRedisDBIndex); - } - } else { - throw new ServiceRuntimeException("删除配置时,未发现对应的配置id信息,请检查配置参数是否正确", - RestBusinessCode.ConfigSourceIsNull.getValue()); - } - transaction.incrBy("MAAT_VERSION", 1l); - logger.info("向{}号redis数据库更新了MAAT_VERSION,更新后版本是{}", redisDb, - Integer.valueOf(maatVersionStr) + 1); - } else { - throw new ServiceRuntimeException("从" + redisDb - + "号redis库中获取MAAT_VERSION的值为null,redis中不存在该值,请联系开发人员检查删除逻辑是否正确或redis数据是否出现了异常", - RestBusinessCode.GetMaatVersionFailure.getValue()); - } - } - } - } else { - throw new ServiceRuntimeException("删除maat类配置时,未发现对应的配置信息,请检查配置参数是否正确", - RestBusinessCode.ConfigSourceIsNull.getValue()); - } - if (removeMaatRelation(serviceConfigMap, transaction, null) - && removeStatisticsReal(serviceConfigMap, transaction, null)) { - transaction.exec(); - return true; - } else { - transaction.discard(); - } - - } catch (JedisConnectionException e) { - String error = "连接redis异常,删除maat配置失败," + e.getMessage(); - logger.error(error + " " + ExceptionUtil.getExceptionMsg(e)); - throw new ServiceRuntimeException(error, RestBusinessCode.CannotConnectionRedis.getValue()); - - } catch (Exception e) { - - int businessCode = RestBusinessCode.service_runtime_error.getValue(); - if (e instanceof ServiceRuntimeException) { - businessCode = ((ServiceRuntimeException) e).getErrorCode(); - } - logger.error("删除maat配置发生了异常" + ExceptionUtil.getExceptionMsg(e)); - transaction.discard(); - throw new ServiceRuntimeException("删除maat配置发生了异常," + e.getMessage(), businessCode); - } finally { - // 释放连接到连接池 - JedisUtils.returnResource(resource); - } - } else - - { - throw new ServiceRuntimeException("Map参数信息不能为空,请检查!", RestBusinessCode.ConfigInfoMapIsNull.getValue()); - } - return false; - } - - public boolean startStopMaatConfig(Map> serviceConfigMap, boolean isStart) { - if (serviceConfigMap != null && serviceConfigMap.size() > 0) { - Jedis resource = JedisUtils.getResource(0); - Transaction transaction = resource.multi(); - try { - int idRelaRedisDBIndex = Configurations.getIntProperty("idRelaRedisDBIndex", 15); - if (serviceConfigMap != null && serviceConfigMap.size() > 0) { - for (Integer service : serviceConfigMap.keySet()) { - Map> compileIdAndDBReal = getCompileIdAndDBReal( - serviceConfigMap.get(service), service, idRelaRedisDBIndex); - for (Integer redisDb : compileIdAndDBReal.keySet()) { - String maatVersionStr = JedisUtils.get("MAAT_VERSION", redisDb); - if (maatVersionStr != null) { - Double maatVersion = Double.valueOf(maatVersionStr) + 1D; - MaatXmlConfig maatXmlConfig = ReadMaatXmlUtil.getMaatConfigByService(service); - Set list = compileIdAndDBReal.get(redisDb); - if (list != null && list.size() > 0) { - for (Long id : list) { - // 按序号选择Redis数据库 - transaction.select(redisDb); - startStopConfig(id, maatXmlConfig, maatVersion, service, transaction, redisDb, - idRelaRedisDBIndex, isStart); + idRelaRedisDBIndex,isStart); } } else { throw new ServiceRuntimeException("删除配置时,未发现对应的配置id信息,请检查配置参数是否正确", @@ -1165,6 +1090,8 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { return false; } + + /** * 获取关联关系中每个关系中的-前部分 * @@ -1188,120 +1115,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { * @param service 业务类型 * @param redisTemplate * @param maatRelation id对应关系对象 + * @param isStart 是否将配置置为生效 */ private void removeConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service, - Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex) { - if (maatXmlConfig != null) { - Map keyMap = new HashMap<>(); - - // 删除(重命名)编译配置 - removeCompileAndGroupConfig(maatXmlConfig, id + "", 10, maatVersion, service, transaction, redisDBIndex, - null, null);// 10代表是编译配置 - // 拼接编译与分组关系的Redis Key - String compileStr = "COMPILEGROUP:" + id; - // 获取当前编译配置与分组配置的关联关系 - String compileStrVal = JedisUtils.get(compileStr, idRelaRedisDBIndex);// 根据编译id获取该编译下的分组关系 - if (compileStrVal != null && !compileStrVal.trim().equals("")) { - String[] compileGroupStrArr = org.apache.commons.lang.StringUtils.split(compileStrVal, ";"); - for (String compileGroup : compileGroupStrArr) { - if (compileGroup != null && !compileGroup.trim().equals("")) { - String groupCompileStrs = getRegionInfo(compileGroup);// 获取编译对应的分组信息,去除后面的redisdb信息 - if (groupCompileStrs != null && !groupCompileStrs.trim().equals("")) {// 遍历编译和分组的信息 - String[] split = org.apache.commons.lang.StringUtils.split(groupCompileStrs, ";"); - - for (String groupId : split) {// GROUPCOMPILE:groupid-redisdb - if (groupId != null && !groupId.trim().equals("")) { - String groupCompileAndDBStrs = null; - if (!keyMap.containsKey(groupId)) { - groupCompileAndDBStrs = JedisUtils.get(groupId, idRelaRedisDBIndex); - keyMap.put(groupId, groupCompileAndDBStrs); - } else { - groupCompileAndDBStrs = keyMap.get(groupId); - } - - String[] compileGroupArr = org.apache.commons.lang.StringUtils - .split(groupCompileAndDBStrs, ";");// 获取组对应的编译id - - for (String groupAndCompileStr : compileGroupArr) { - if (groupAndCompileStr != null && !groupAndCompileStr.trim().equals("")) { - String compileId = getRegionInfo(groupAndCompileStr); - if (compileId != null && !compileId.trim().equals("")) { - // 被分组复用的业务,不能将域置为失效 - if (!ServiceAndRDBIndexReal.serviceIsReuse(service)) {// 如果当前业务不允许被分组复用(普通的maat类配置),则可以将域置为失效,否则不将域置为失效 - // 如果只有一个编译id且与上面的编译id相同则说明未被分组复用,可以将其下的所有域置失效,否则不处理域配置,只把编译,分组关系置为无效 - if (compileId.equals(compileStr)) {// - String groupRegionKey = groupId.replace("GROUPCOMPILE", - "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION - String regionStrs = null; - if (!keyMap.containsKey(groupRegionKey)) { - regionStrs = JedisUtils.get(groupRegionKey, - idRelaRedisDBIndex); - keyMap.put(groupRegionKey, regionStrs); - } else { - regionStrs = keyMap.get(groupRegionKey); - } - if (regionStrs != null && !regionStrs.trim().equals("")) { - String[] regionStrArr = regionStrs.split(";"); - for (String str : regionStrArr) { - if (str != null && !str.trim().equals("")) { - - String regionStr = getRegionInfo(str); - if (regionStr != null - && !regionStr.trim().equals("")) { - String[] regionKeyArr = regionStr.split(";"); - if (regionKeyArr != null - && regionKeyArr.length > 0) { - // 根据分组与域关联关系找到对应域配置然后删除(重命名) - removeRegionConfig(maatXmlConfig, - regionKeyArr, maatVersion, service, - transaction, redisDBIndex, null); - } - } else { - throw new ServiceRuntimeException("从" - + idRelaRedisDBIndex - + "号redis库中无法获取MAAT配置分组与域的关联关系,key为" - + groupRegionKey, - RestBusinessCode.KeyNotExistsInRedis - .getValue()); - } - } - } - } - } - } - // 根据分组与编译关联关系找到对应分组配置然后删除(重命名) - removeCompileAndGroupConfig(maatXmlConfig, - groupId.replace("GROUPCOMPILE:", ""), 11, maatVersion, service, - transaction, redisDBIndex, id + "", null);// 11代表是分组配置 - - } else { - throw new ServiceRuntimeException( - "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置分组与编译的关联关系,key为" - + groupId, - RestBusinessCode.KeyNotExistsInRedis.getValue()); - } - } - } - } - } - } else { - throw new ServiceRuntimeException( - "从" + idRelaRedisDBIndex + "号redis库中无法获取MAAT配置编译与分组关联关系,key为" + compileStr, - RestBusinessCode.KeyNotExistsInRedis.getValue()); - } - } - } - } - } else - - { - throw new ServiceRuntimeException( - "无法从applicationConfig-maatRedis.xml配置文件中获取service为" + service + "对应的规则,请检查业务类型是否正确", - RestBusinessCode.NotFoundRedisRule.getValue()); - } - } - - private void startStopConfig(Long id, MaatXmlConfig maatXmlConfig, Double maatVersion, int service, Transaction transaction, int redisDBIndex, int idRelaRedisDBIndex, boolean isStart) { if (maatXmlConfig != null) { Map keyMap = new HashMap<>(); @@ -1457,9 +1273,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { } if (isStart == null) {// 置为失效 maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); - } else if (isStart == true) {// 将失效置为生效 + } else if (isStart) {// 将失效置为生效 maatKey = oldKey; - oldKey=oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); + oldKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); } else {// 将生效变为失效 maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); } @@ -1505,7 +1321,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (oldKey != null && !oldKey.trim().equals("")) { if (isStart == null) {// 置为失效 maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); - } else if (isStart == true) {// 将失效置为生效 + } else if (isStart) {// 将失效置为生效 maatKey = oldKey.replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); } else {// 将生效变为失效 maatKey = oldKey.replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); @@ -1552,14 +1368,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { if (idList != null && idList.size() > 0) { for (Long compileId : idList) { String effectiveRuleKey = "EFFECTIVE_RULE:" + maatTableName + "," + compileId; - transaction.rename(effectiveRuleKey.toUpperCase(), - effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE")); + if (isStart) { + transaction.rename( + effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE"), + effectiveRuleKey.toUpperCase()); + } else { + transaction.rename(effectiveRuleKey.toUpperCase(), + effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE")); + } logger.info("向{}号redis数据库修改了一条配置,修改前key是{},修改后key是:{}", redisStatisticsRealDBIndex, effectiveRuleKey.toUpperCase(), effectiveRuleKey.toUpperCase().replace("EFFECTIVE_RULE", "OBSOLETE_RULE")); String zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "DEL,"); if (isStart == null || isStart == false) { - } else if (isStart == true) { + } else if (isStart) { zset = effectiveRuleKey.replace("EFFECTIVE_RULE:", "ADD,"); } transaction.zadd("MAAT_UPDATE_STATUS", maatVersion, zset); @@ -1640,23 +1462,63 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { String groupRegion = groupCompile.replace("GROUPCOMPILE", "GROUPREGION");// groupregion里面value是region的信息,key是group的信息,所以可以直接将GROUPCOMPILE替换为GROUPREGION + String groupRegionVal = JedisUtils.get(groupRegion, + idRelaRedisDBIndex); + try { // 为了提高效率,不判断了,如果报错直接捕捉异常处理 // 删除分组与域的关联关系 if (isStart == null) {// 删除 transaction.del(groupRegion); - } else if (isStart == true) {// 将失效置为生效 - String groupRegionVal = JedisUtils.get(groupRegion, - idRelaRedisDBIndex); + } else if (isStart) {// 将失效置为生效 + groupRegionVal = groupRegionVal .replace("OBSOLETE_RULE", "EFFECTIVE_RULE"); - transaction.set(groupRegion, groupRegionVal); + String[] split = org.apache.commons.lang.StringUtils + .split(groupRegionVal, ";"); + if (split.length > 1) { + Set set = new HashSet<>(); + for (String regionKeyStr : split) { + if (regionKeyStr != null && !regionKeyStr + .trim().equals("")) { + set.add(regionKeyStr); + } + } + StringBuffer sb = new StringBuffer(); + for (String regionKeyStr : set) { + sb.append(";"); + sb.append(regionKeyStr); + } + transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key + } else { + transaction.set(groupRegion.toUpperCase(), + groupRegionVal); + } } else {// 将生效变为失效 - String groupRegionVal = JedisUtils.get(groupRegion, - idRelaRedisDBIndex); groupRegionVal = groupRegionVal .replace("EFFECTIVE_RULE", "OBSOLETE_RULE"); - transaction.set(groupRegion, groupRegionVal); + String[] split = org.apache.commons.lang.StringUtils + .split(groupRegionVal, ";"); + if (split.length > 1) { + Set set = new HashSet<>(); + + for (String regionKeyStr : split) { + if (regionKeyStr != null && !regionKeyStr + .trim().equals("")) { + set.add(regionKeyStr); + } + } + StringBuffer sb = new StringBuffer(); + for (String regionKeyStr : set) { + sb.append(";"); + sb.append(regionKeyStr); + } + transaction.set(groupRegion, sb.toString());// 避免有多个重复的region-key + + } else { + transaction.set(groupRegion.toUpperCase(), + groupRegionVal); + } } } catch (Exception e) { @@ -1676,9 +1538,9 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { // 删除分组与编译的关联关系 if (groupCompileStrVal != null && !groupCompileStrVal.trim().equals("")) { - StringBuffer sb = new StringBuffer(); String[] split = org.apache.commons.lang.StringUtils .split(groupCompileStrVal, ";"); + Set set = new HashSet<>(); for (String groupCompileAndDBStr : split) { if (groupCompileAndDBStr != null && !groupCompileAndDBStr.trim().equals("")) { @@ -1689,25 +1551,68 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { try { // 为了提高效率,不判断了,如果报错直接捕捉异常处理 // 删除当前组所对应的编译 - + String groupRegionVal = JedisUtils.get( + groupCompile.toUpperCase(), + idRelaRedisDBIndex); if (isStart == null) {// 删除 transaction.del(groupCompile.toUpperCase());// 删除编译与分组的关联关系 - } else if (isStart == true) {// 将失效置为生效 - String groupRegionVal = JedisUtils.get( - groupCompile.toUpperCase(), - idRelaRedisDBIndex); + } else if (isStart) {// 将失效置为生效 groupRegionVal = groupRegionVal.replace( "OBSOLETE_RULE", "EFFECTIVE_RULE"); - transaction.set(groupCompile.toUpperCase(), - groupRegionVal); + String[] split2 = org.apache.commons.lang.StringUtils + .split(groupRegionVal, ";"); + if (split2.length > 1) { + Set set1 = new HashSet<>(); + for (String regionKeyStr : split2) { + if (regionKeyStr != null + && !regionKeyStr.trim() + .equals("")) { + set1.add(regionKeyStr); + } + } + StringBuffer sb = new StringBuffer(); + for (String regionKeyStr : set1) { + sb.append(";"); + sb.append(regionKeyStr); + } + transaction.set( + groupCompile.toUpperCase(), + sb.toString()); + + } else { + transaction.set( + groupCompile.toUpperCase(), + groupRegionVal); + } } else {// 将生效变为失效 - String groupRegionVal = JedisUtils.get( - groupCompile.toUpperCase(), - idRelaRedisDBIndex); groupRegionVal = groupRegionVal.replace( "EFFECTIVE_RULE", "OBSOLETE_RULE"); - transaction.set(groupCompile.toUpperCase(), - groupRegionVal); + + String[] split2 = org.apache.commons.lang.StringUtils + .split(groupRegionVal, ";"); + if (split2.length > 1) { + + Set set2 = new HashSet<>(); + for (String regionKeyStr : split2) { + if (regionKeyStr != null + && !regionKeyStr.trim() + .equals("")) { + set2.add(regionKeyStr); + } + } + StringBuffer sb = new StringBuffer(); + for (String regionKeyStr : set2) { + sb.append(";"); + sb.append(regionKeyStr); + } + transaction.set( + groupCompile.toUpperCase(), + sb.toString()); + } else { + transaction.set( + groupCompile.toUpperCase(), + groupRegionVal); + } } } catch (Exception e) { throw new ServiceRuntimeException("从" @@ -1718,15 +1623,20 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { .getValue()); } - } else if (!groupCompileAndDBStr - .contains(compileStr.toUpperCase())) { - sb.append(groupCompileAndDBStr + ";"); +// } else if (!groupCompileAndDBStr +// .contains(compileStr.toUpperCase())) { + } else { + set.add(groupCompileAndDBStr); } } } - if (sb.length() > 0) { - transaction.set(groupCompile.toUpperCase(), - sb.substring(0, sb.length() - 1));// 重新设置分组与编译 + if (set.size() > 0) { + StringBuffer sb = new StringBuffer(); + for (String regionKeyStr : set) { + sb.append(";"); + sb.append(regionKeyStr); + } + transaction.set(groupCompile.toUpperCase(), sb.toString());// 重新设置分组与编译 } } else { @@ -1750,7 +1660,7 @@ public class ConfigJedisServiceimpl implements ConfigRedisService { try { if (isStart == null) {// 删除 transaction.del(compileStr.toUpperCase());// 删除编译与分组的关联关系 - } else if (isStart == true) {// 将失效置为生效 + } else if (isStart) {// 将失效置为生效 String groupRegionVal = JedisUtils.get(compileStr.toUpperCase(), idRelaRedisDBIndex); groupRegionVal = groupRegionVal.replace("OBSOLETE_RULE", diff --git a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java index 7f7ec3e..46244c6 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigRedisService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigRedisService.java @@ -76,17 +76,10 @@ public interface ConfigRedisService { * 删除maat类配置,key是业务类型,value是配置id集合 * * @param serviceConfigMap + * @param isStart 是否置为生效, * @return 成功返回true,失败返回false或抛出异常 */ - public boolean delMaatConfig(Map> serviceConfigMap); - /** - * 停启用maat类配置,key是业务类型,value是配置id集合 - * - * @param serviceConfigMap - * @param isStart 是否置位生效, - * @return 成功返回true,失败返回false或抛出异常 - */ - public boolean startStopMaatConfig(Map> serviceConfigMap, boolean isStart); + public boolean delMaatConfig(Map> serviceConfigMap,boolean isStart); /** * 删除分组复用的域配置 diff --git a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java index 1c6357d..6730f4e 100644 --- a/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java +++ b/src/main/java/com/nis/web/service/restful/ConfigSourcesService.java @@ -370,7 +370,7 @@ public class ConfigSourcesService extends BaseService { if (!isConfigStartStop) { // 所有的都删除成功返回true - if (!configRedisService.delMaatConfig(compileMap)) { + if (!configRedisService.delMaatConfig(compileMap,false)) { throw new ServiceRuntimeException("取消MAAT配置时出现异常,具体原因不详,请联系管理员", RestBusinessCode.service_runtime_error.getValue()); } @@ -380,7 +380,7 @@ public class ConfigSourcesService extends BaseService { if (isValid == 0) { isStart = false;// 置为失效 } - if (!configRedisService.startStopMaatConfig(compileMap, isStart)) { + if (!configRedisService.delMaatConfig(compileMap, isStart)) { throw new ServiceRuntimeException("停启用MAAT配置时出现异常,具体原因不详,请联系管理员", RestBusinessCode.service_runtime_error.getValue()); } diff --git a/src/main/java/com/nis/web/service/restful/DashboardService.java b/src/main/java/com/nis/web/service/restful/DashboardService.java index 5dd72a6..84d9531 100644 --- a/src/main/java/com/nis/web/service/restful/DashboardService.java +++ b/src/main/java/com/nis/web/service/restful/DashboardService.java @@ -102,6 +102,7 @@ public class DashboardService extends BaseService { * @param transType * @return */ + @Deprecated public List getBandwidthTrans(String addrType, Integer transType, String beginDate, String endDate) { ArrayList listMap = new ArrayList(); @@ -121,6 +122,7 @@ public class DashboardService extends BaseService { * @param transType * @return */ + @Deprecated public List getBandwidthTrans2(String addrType, Integer transType, String beginDate, String endDate) { ArrayList listMap = new ArrayList(); @@ -143,6 +145,7 @@ public class DashboardService extends BaseService { * @param entranceId * @return */ + @Deprecated public HashMap getBandwidthTransEntrance(String addrType, Integer transType, String beginDate, String endDate, Integer entranceId) { long start = System.currentTimeMillis(); @@ -177,8 +180,8 @@ public class DashboardService extends BaseService { if (t >= pointTime && t < pointTime + inter) { // 范围之内分到此pointTime组 sumL = sumL + tt.getLinkNum(); - sumP = sumP + tt.getPps(); - sumG = sumG + tt.getGbps(); + sumP = sumP + Long.parseLong(tt.getPps().substring(0, tt.getPps().lastIndexOf("."))); + sumG = sumG + Long.parseLong(tt.getGbps().substring(0, tt.getGbps().lastIndexOf("."))); } } // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 @@ -220,6 +223,7 @@ public class DashboardService extends BaseService { * @param li * @return */ + @Deprecated public static List formatDateData(String begin, String end, List li) { List resList = new ArrayList(); Map m = new HashMap(); @@ -260,6 +264,7 @@ public class DashboardService extends BaseService { * @param format 如:yyyy-MM-dd HH:mm:ss * @return */ + @Deprecated public static Long dateToStamp(String date_str) { try { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -277,6 +282,7 @@ public class DashboardService extends BaseService { * @param format 如:yyyy-MM-dd HH:mm:ss * @return */ + @Deprecated public static String stampToDate(long timeStamp) { SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm");// 这个是你要转成后的时间的格式 String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间 @@ -286,100 +292,49 @@ public class DashboardService extends BaseService { /** * 根据service 动作查询近五分钟变化趋势 entrance 默认为1,2 */ -/* - public List getActionTrans(String begin, String end, String serviceType) { - String sql = ""; - String sqlBlock = "((service>=16 and service<=40) or (service>=258 and service<=273) or (service=576))"; // 阻断 - String sqlMonitor = "((service>=128 and service<=152) or (service>=384 and service<=513) or (service=592) or (service>=848 and service<=1030) or (service=1152))"; // 监测 - String sqlDrop = "((service>=1040 and service<=1042) or (service=3) or (service=5) or (service=25) or (service=28) or (service=274))"; // 丢弃 - String sqlLoop = "((service=4) or (service>=832 and service<=834))"; // 回流 - // 区分动作 - if (StringUtils.isNotBlank(serviceType)) { - if (serviceType.equalsIgnoreCase("block")) { - sql = sqlBlock; - } - if (serviceType.equalsIgnoreCase("monitor")) { - sql = sqlMonitor; - } - if (serviceType.equalsIgnoreCase("drop")) { - sql = sqlDrop; - } - if (serviceType.equalsIgnoreCase("loop")) { - sql = sqlLoop; - } - } - ArrayList listMap = new ArrayList(); - List entrance1 = new ArrayList(); - List entrance2 = new ArrayList(); - HashMap m1 = new HashMap(); - HashMap m2 = new HashMap(); - entrance1 = ntcTotalReportDao.getActionTrans(begin, end, 1, sql); - entrance2 = ntcTotalReportDao.getActionTrans(begin, end, 2, sql); - List timeList = new ArrayList(); - List sumList1 = new ArrayList(); - List sumList2 = new ArrayList(); - - Map m = new HashMap(); - int inter = 1000 * 60 * 5;// 间隔时间为五分钟 - // 开始时间,结束时间 时间戳 - Long b = dateToStamp(begin); - Long e = dateToStamp(end); - int num = 0; - Long pointTime = b; - while (pointTime < e) { - Map rm = new HashMap(); - Long sum1 = 0l; - Long sum2 = 0l; - if (pointTime >= e) { - break; // 停止 - } - for (NtcEntranceReport e1 : entrance1) { - // 实际时间 - String time = e1.getTime(); - Long t = dateToStamp(time); - if (t >= pointTime && t < pointTime + inter) { - // 范围之内分到此pointTime组 - sum1 = sum1 + e1.getSum(); - } - } - for (NtcEntranceReport e2 : entrance2) { - // 实际时间 - String time = e2.getTime(); - Long t = dateToStamp(time); - if (t >= pointTime && t < pointTime + inter) { - // 范围之内分到此pointTime组 - sum2 = sum2 + e2.getSum(); - } - } - // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 - if (pointTime >= e - inter && sum1 > 0) { - sumList1.add(sum1); - } - if (pointTime >= e - inter && sum2 > 0) { - sumList2.add(sum2); - } - if (pointTime >= e - inter && (sum1 > 0 || sum2 > 0)) { - timeList.add(stampToDate(pointTime)); - } - if (pointTime < e - inter) { - sumList1.add(sum1); - sumList2.add(sum2); - timeList.add(stampToDate(pointTime)); - } - num = num + 1; - pointTime = b + inter * num; - } - m1.put("count", sumList1); - m1.put("statTime", timeList); - m1.put("entranceId", 1); - m2.put("count", sumList2);// - m2.put("statTime", timeList); - m2.put("entranceId", 2); - listMap.add(m1); - listMap.add(m2); - return listMap; - } - */ + /* + * public List getActionTrans(String begin, String end, String + * serviceType) { String sql = ""; String sqlBlock = + * "((service>=16 and service<=40) or (service>=258 and service<=273) or (service=576))" + * ; // 阻断 String sqlMonitor = + * "((service>=128 and service<=152) or (service>=384 and service<=513) or (service=592) or (service>=848 and service<=1030) or (service=1152))" + * ; // 监测 String sqlDrop = + * "((service>=1040 and service<=1042) or (service=3) or (service=5) or (service=25) or (service=28) or (service=274))" + * ; // 丢弃 String sqlLoop = "((service=4) or (service>=832 and service<=834))"; + * // 回流 // 区分动作 if (StringUtils.isNotBlank(serviceType)) { if + * (serviceType.equalsIgnoreCase("block")) { sql = sqlBlock; } if + * (serviceType.equalsIgnoreCase("monitor")) { sql = sqlMonitor; } if + * (serviceType.equalsIgnoreCase("drop")) { sql = sqlDrop; } if + * (serviceType.equalsIgnoreCase("loop")) { sql = sqlLoop; } } + * ArrayList listMap = new ArrayList(); + * List entrance1 = new ArrayList(); + * List entrance2 = new ArrayList(); + * HashMap m1 = new HashMap(); HashMap m2 = new HashMap(); entrance1 = + * ntcTotalReportDao.getActionTrans(begin, end, 1, sql); entrance2 = + * ntcTotalReportDao.getActionTrans(begin, end, 2, sql); List timeList = new + * ArrayList(); List sumList1 = new ArrayList(); List sumList2 = new + * ArrayList(); + * + * Map m = new HashMap(); int inter = + * 1000 * 60 * 5;// 间隔时间为五分钟 // 开始时间,结束时间 时间戳 Long b = dateToStamp(begin); Long + * e = dateToStamp(end); int num = 0; Long pointTime = b; while (pointTime < e) + * { Map rm = new HashMap(); Long sum1 = 0l; Long sum2 = 0l; if (pointTime >= e) + * { break; // 停止 } for (NtcEntranceReport e1 : entrance1) { // 实际时间 String time + * = e1.getTime(); Long t = dateToStamp(time); if (t >= pointTime && t < + * pointTime + inter) { // 范围之内分到此pointTime组 sum1 = sum1 + e1.getSum(); } } for + * (NtcEntranceReport e2 : entrance2) { // 实际时间 String time = e2.getTime(); Long + * t = dateToStamp(time); if (t >= pointTime && t < pointTime + inter) { // + * 范围之内分到此pointTime组 sum2 = sum2 + e2.getSum(); } } // + * 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 if (pointTime >= e - inter && sum1 > 0) { + * sumList1.add(sum1); } if (pointTime >= e - inter && sum2 > 0) { + * sumList2.add(sum2); } if (pointTime >= e - inter && (sum1 > 0 || sum2 > 0)) { + * timeList.add(stampToDate(pointTime)); } if (pointTime < e - inter) { + * sumList1.add(sum1); sumList2.add(sum2); timeList.add(stampToDate(pointTime)); + * } num = num + 1; pointTime = b + inter * num; } m1.put("count", sumList1); + * m1.put("statTime", timeList); m1.put("entranceId", 1); m2.put("count", + * sumList2);// m2.put("statTime", timeList); m2.put("entranceId", 2); + * listMap.add(m1); listMap.add(m2); return listMap; } + */ /** * 根据service 动作查询近五分钟变化趋势 entrance 默认为1,2 */ @@ -411,66 +366,68 @@ public class DashboardService extends BaseService { HashMap m2 = new HashMap(); entrance1 = ntcTotalReportDao.getActionTrans(begin, end, 1, sql); entrance2 = ntcTotalReportDao.getActionTrans(begin, end, 2, sql); - + Map m = new HashMap(); Date beginDate = DateUtils.parseDate(begin); Date endDate = DateUtils.parseDate(end); - - List dateRangeList = new ArrayList(); - List strDateRangeList = new ArrayList(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(beginDate); - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); - while (calendar.getTime().compareTo(endDate)<=0) { - dateRangeList.add(calendar.getTime()); - strDateRangeList.add(sdf.format(calendar.getTime())); - calendar.add(Calendar.MINUTE, 5); - } - //存放每个时间点的总数 - Map> ipCountListMap = new HashMap>(); - int index=0; - List sumList1 =new ArrayList(); - List sumList2 =new ArrayList(); - for (int i = 0; i < dateRangeList.size(); i++) { - //存放一个时间点中总数 - Map ipCountMap = new HashMap(); - Date date = dateRangeList.get(i); - Long num1 = 0L; - Long num2 = 0L; - for (int j = index; j < entrance1.size(); j++) { - NtcEntranceReport ipInfo = entrance1.get(j); - if (ipInfo.getReportTime()!=null){ - if(ipInfo.getReportTime().compareTo(date)>=0&&(i+1 dateRangeList = new ArrayList(); + List strDateRangeList = new ArrayList(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(beginDate); + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); + while (calendar.getTime().compareTo(endDate) <= 0) { + dateRangeList.add(calendar.getTime()); + strDateRangeList.add(sdf.format(calendar.getTime())); + calendar.add(Calendar.MINUTE, 5); + } + // 存放每个时间点的总数 + Map> ipCountListMap = new HashMap>(); + int index = 0; + List sumList1 = new ArrayList(); + List sumList2 = new ArrayList(); + for (int i = 0; i < dateRangeList.size(); i++) { + // 存放一个时间点中总数 + Map ipCountMap = new HashMap(); + Date date = dateRangeList.get(i); + Long num1 = 0L; + Long num2 = 0L; + for (int j = index; j < entrance1.size(); j++) { + NtcEntranceReport ipInfo = entrance1.get(j); + if (ipInfo.getReportTime() != null) { + if (ipInfo.getReportTime().compareTo(date) >= 0 && (i + 1 < dateRangeList.size() + && ipInfo.getReportTime().compareTo(dateRangeList.get(i + 1)) < 0)) { + num1 = num1 + ipInfo.getSum(); + } else { + index = j; + break; } } - sumList1.add(num1); - for (int j = index; j < entrance2.size(); j++) { - NtcEntranceReport ipInfo = entrance2.get(j); - if (ipInfo.getReportTime()!=null){ - if(ipInfo.getReportTime().compareTo(date)>=0&&(i+1= 0 && (i + 1 < dateRangeList.size() + && ipInfo.getReportTime().compareTo(dateRangeList.get(i + 1)) < 0)) { + num2 = num2 + ipInfo.getSum(); + } else { + index = j; + break; } } - sumList2.add(num2); } - //整合 count time - m1.put("count", sumList1); - m1.put("statTime", strDateRangeList); - m1.put("entranceId", 1); - m2.put("count", sumList2);// - m2.put("statTime", strDateRangeList); - m2.put("entranceId", 2); - listMap.add(m1); - listMap.add(m2); + sumList2.add(num2); + } + // 整合 count time + m1.put("count", sumList1); + m1.put("statTime", strDateRangeList); + m1.put("entranceId", 1); + m2.put("count", sumList2);// + m2.put("statTime", strDateRangeList); + m2.put("entranceId", 2); + listMap.add(m1); + listMap.add(m2); return listMap; } @@ -545,43 +502,44 @@ public class DashboardService extends BaseService { if (ipListTop10 != null && ipListTop10.size() > 0) { StringBuilder ipStr = new StringBuilder(); for (LinkedHashMap map : ipListTop10) { - ipStr.append("'"+(String) map.get("ipAddr")+"',"); + ipStr.append("'" + (String) map.get("ipAddr") + "',"); } - if (!StringUtil.isEmpty(ipStr)&&ipStr.indexOf(",")>0) { + if (!StringUtil.isEmpty(ipStr) && ipStr.indexOf(",") > 0) { ipStr.deleteCharAt(ipStr.lastIndexOf(",")); } - //如果所有IP在最后一个时间点的count都为0,则移除最后一个点 - //开始划分时间段,间隔5分钟 + // 如果所有IP在最后一个时间点的count都为0,则移除最后一个点 + // 开始划分时间段,间隔5分钟 List dateRangeList = new ArrayList(); List strDateRangeList = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(beginDate); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); - while (calendar.getTime().compareTo(endDate)<=0) { + while (calendar.getTime().compareTo(endDate) <= 0) { dateRangeList.add(calendar.getTime()); strDateRangeList.add(sdf.format(calendar.getTime())); calendar.add(Calendar.MINUTE, 5); } - - ArrayList ipInfoList = trafficIpActiveStatisticDao.ipActiveFiveMinute(ipStr.toString(), - beginDate, endDate); - //存放每个IP,每个时间点的总数 - Map> ipCountListMap = new HashMap>(); - int index=0; + + ArrayList ipInfoList = trafficIpActiveStatisticDao + .ipActiveFiveMinute(ipStr.toString(), beginDate, endDate); + // 存放每个IP,每个时间点的总数 + Map> ipCountListMap = new HashMap>(); + int index = 0; for (int i = 0; i < dateRangeList.size(); i++) { - //存放一个时间点中每个IP的总数 + // 存放一个时间点中每个IP的总数 Map ipCountMap = new HashMap(); Date date = dateRangeList.get(i); for (int j = index; j < ipInfoList.size(); j++) { TrafficIpActiveStatistic ipInfo = ipInfoList.get(j); - if (ipInfo.getStatTime()!=null){ - if(ipInfo.getStatTime().compareTo(date)>=0&&(i+1= 0 && (i + 1 < dateRangeList.size() + && ipInfo.getStatTime().compareTo(dateRangeList.get(i + 1)) < 0)) { Long num = ipInfo.getCount(); if (ipCountMap.containsKey(ipInfo.getIpAddr())) { - num=num+ipCountMap.get(ipInfo.getIpAddr()); + num = num + ipCountMap.get(ipInfo.getIpAddr()); } ipCountMap.put(ipInfo.getIpAddr(), num); - }else{ + } else { index = j; break; } @@ -591,21 +549,21 @@ public class DashboardService extends BaseService { String ip = (String) map.get("ipAddr"); Long sum = 0l; if (ipCountMap.containsKey(ip)) { - sum=ipCountMap.get(ip); + sum = ipCountMap.get(ip); } if (ipCountListMap.containsKey(ip)) { ipCountListMap.get(ip).add(sum); - }else{ + } else { List list = new ArrayList(); list.add(sum); ipCountListMap.put(ip, list); } } } - //整合IP count time + // 整合IP count time Iterator iterator = ipCountListMap.keySet().iterator(); while (iterator.hasNext()) { - String ip = iterator.next()+""; + String ip = iterator.next() + ""; Map ipTrafficMap = new HashMap(); ipTrafficMap.put("ipAddr", ip); ipTrafficMap.put("linkNum", ipCountListMap.get(ip)); @@ -622,23 +580,23 @@ public class DashboardService extends BaseService { * @return */ public List ipActiveOneHour(Date beginDate, Date endDate) { - TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); +// TrafficIpActiveStatistic maxStatTime = trafficIpActiveStatisticDao.getMaxStatTime(); ArrayList listMap = new ArrayList(); - if (maxStatTime != null && maxStatTime.getStatTime() != null) { - Date statTime = maxStatTime.getStatTime(); - ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(beginDate, endDate); - if (list != null && list.size() > 0) { - for (LinkedHashMap map : list) { - if (map.get("ipAddr") != null) { - String ipAddr = (String) map.get("ipAddr"); - HashMap resMap = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr, beginDate,endDate); - if(resMap!=null){ - listMap.add(resMap); - } +// if (maxStatTime != null && maxStatTime.getStatTime() != null) { +// Date statTime = maxStatTime.getStatTime(); + ArrayList list = trafficIpActiveStatisticDao.ipActiveChart(beginDate, endDate); + if (list != null && list.size() > 0) { + for (LinkedHashMap map : list) { + if (map.get("ipAddr") != null) { + String ipAddr = (String) map.get("ipAddr"); + HashMap resMap = trafficIpActiveStatisticDao.ipActiveOneHour(ipAddr, beginDate, endDate); + if (resMap != null) { + listMap.add(resMap); } } } } +// } return listMap; } @@ -696,12 +654,12 @@ public class DashboardService extends BaseService { * * @return */ - public List getProtocolList(String startTime, String endTime,Integer[] protoType) { + public List getProtocolList(String startTime, String endTime, Integer[] protoType) { // TrafficProtocolStatistic maxStatTime = trafficProtocolStatisticDao.getMaxStatTime(); List list = new ArrayList(); // if (maxStatTime != null && maxStatTime.getStatTime() != null) { // Date statTime = maxStatTime.getStatTime(); - list = trafficProtocolStatisticDao.getProtocolList(startTime, endTime,protoType); + list = trafficProtocolStatisticDao.getProtocolList(startTime, endTime, protoType); // } return list; } @@ -1101,8 +1059,8 @@ public class DashboardService extends BaseService { // String linkNumStr = String.valueOf(webIdAndCountMap.get("linkNum")); // String packetsStr = String.valueOf(webIdAndCountMap.get("pktCount")); if (countStr != null) { - Long pl = (Long.parseLong(countStr))/(1024*1024*1024); - if(pl>0) { + Long pl = (Long.parseLong(countStr)) / (1024 * 1024 * 1024); + if (pl > 0) { count += Long.parseLong(countStr);// 将count累加 转换单位小于0的不加 } } @@ -1121,21 +1079,21 @@ public class DashboardService extends BaseService { Collections.sort(list, new Comparator() { @Override public int compare(Object o1, Object o2) { - if(o1==null&&o2!=null){ + if (o1 == null && o2 != null) { return 1; } - if(o1!=null&&o2==null){ + if (o1 != null && o2 == null) { return -1; } - if(o1==o2&&o1==null){ + if (o1 == o2 && o1 == null) { return 0; } - Map m1=(Map)o1; - Map m2=(Map)o2; + Map m1 = (Map) o1; + Map m2 = (Map) o2; Object ob1 = m1.get("byteCount"); Object ob2 = m2.get("byteCount"); - Long b1=Long.parseLong(ob1.toString()); - Long b2=Long.parseLong(ob2.toString()); + Long b1 = Long.parseLong(ob1.toString()); + Long b2 = Long.parseLong(ob2.toString()); return -(b1).compareTo(b2); } }); @@ -1164,11 +1122,6 @@ public class DashboardService extends BaseService { return dataList; } - - - - - public List getTopicAndDomainList(Date beginDate, Date endDate, String top) { Map> topicIdAndIdMap = new HashMap<>();// 存储topicid和id的对应关系,一个topicid有多个id @@ -1243,24 +1196,7 @@ public class DashboardService extends BaseService { } return dataList; } - - - - - - - - - - - - - - - - - - + public String[] getFiledTypeByName(String fieldName) { if (fieldName == null) { return null; @@ -1286,8 +1222,9 @@ public class DashboardService extends BaseService { bandwidthListIPvx = ntcTotalReportDao.getBandwidthTransIPVx(beginDate, endDate); bandwidthListProtocol = ntcTotalReportDao.getBandwidthTransProtocol(beginDate, endDate); Map trafficMap = new HashMap(); - if((!StringUtil.isEmpty(bandwidthListIPvx)&&bandwidthListIPvx.size()>0)||(!StringUtil.isEmpty(bandwidthListProtocol)&&bandwidthListProtocol.size()>0)){ - //划分时间段 + if ((!StringUtil.isEmpty(bandwidthListIPvx) && bandwidthListIPvx.size() > 0) + || (!StringUtil.isEmpty(bandwidthListProtocol) && bandwidthListProtocol.size() > 0)) { + // 划分时间段 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date startTime = sdf.parse(beginDate); Date endTime = sdf.parse(endDate); @@ -1295,8 +1232,8 @@ public class DashboardService extends BaseService { List strDateRangeList = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(startTime); - - while (calendar.getTime().compareTo(endTime)<=0) { + + while (calendar.getTime().compareTo(endTime) <= 0) { dateRangeList.add(calendar.getTime()); strDateRangeList.add(sdf.format(calendar.getTime())); calendar.add(Calendar.MINUTE, 5); @@ -1304,9 +1241,10 @@ public class DashboardService extends BaseService { String[] addrTypes = getFiledTypeByName("addr_type"); String[] transTypes = getFiledTypeByName("trans_type"); String[] entranceIds = getFiledTypeByName("entrance_id"); - if(bandwidthListIPvx!=null&&bandwidthListIPvx.size()>0&&bandwidthListProtocol!=null&&bandwidthListProtocol.size()>0&&addrTypes!=null&&addrTypes.length>0&&transTypes!=null&&transTypes.length>0 - &&entranceIds!=null&&entranceIds.length>0){ - //按区域和类型构建Map + if (bandwidthListIPvx != null && bandwidthListIPvx.size() > 0 && bandwidthListProtocol != null + && bandwidthListProtocol.size() > 0 && addrTypes != null && addrTypes.length > 0 + && transTypes != null && transTypes.length > 0 && entranceIds != null && entranceIds.length > 0) { + // 按区域和类型构建Map for (String entranceId : entranceIds) { for (String addrType : addrTypes) { listMap.put("ipv" + addrType + "Type" + entranceId, new ArrayList()); @@ -1317,10 +1255,10 @@ public class DashboardService extends BaseService { listMap.put("trans" + transType + "Type" + entranceId, new ArrayList()); } } - //按区域和类型提取数据到列表中 + // 按区域和类型提取数据到列表中 for (TrafficTransStatistic tts : bandwidthListIPvx) { String addrType = tts.getAddrType(); - + Integer entranceId = tts.getEntranceId(); Integer transType = tts.getTransType(); String key = "ipv" + addrType + "Type" + entranceId; @@ -1338,7 +1276,7 @@ public class DashboardService extends BaseService { String key = entry.getKey(); String entranceId = key.substring(key.length() - 1); ArrayList value = entry.getValue(); - resultMap.put(key, getNewData(dateRangeList,strDateRangeList,value)); + resultMap.put(key, getNewData(dateRangeList, strDateRangeList, value)); } return resultMap; } @@ -1346,8 +1284,8 @@ public class DashboardService extends BaseService { return null; } - private Map getNewData(List dateRangeList,List timeList, List bandwidthList) { - Map resulMap = new HashMap(); + private Map getNewData(List dateRangeList, List timeList, List bandwidthList) { + Map resulMap = new HashMap(); int index = 0; for (int i = 0; i < dateRangeList.size(); i++) { Date date = dateRangeList.get(i); @@ -1357,12 +1295,14 @@ public class DashboardService extends BaseService { Long gbpsNum = 0L; for (int j = index; j < bandwidthList.size(); j++) { TrafficTransStatistic info = bandwidthList.get(j); - if (info.getStatTime()!=null){ - if(info.getStatTime().compareTo(date)>=0&&(i+1= 0 && (i + 1 < dateRangeList.size() + && info.getStatTime().compareTo(dateRangeList.get(i + 1)) < 0)) { + linkNum = info.getLinkNum() + linkNum; + ppsNum = Long.parseLong(info.getPps().substring(0, info.getPps().lastIndexOf("."))) + ppsNum; + gbpsNum = Long.parseLong(info.getGbps().substring(0, info.getGbps().lastIndexOf("."))) + + gbpsNum; + } else { index = j; break; } @@ -1373,10 +1313,10 @@ public class DashboardService extends BaseService { countMap.put("gbps", gbpsNum); Iterator iterator = countMap.keySet().iterator(); while (iterator.hasNext()) { - String key = iterator.next()+""; + String key = iterator.next() + ""; if (resulMap.containsKey(key)) { resulMap.get(key).add(countMap.get(key)); - }else { + } else { List list = new ArrayList(); list.add(countMap.get(key)); resulMap.put(key, list); @@ -1396,31 +1336,31 @@ public class DashboardService extends BaseService { * @return */ /* - * public List getDomainTrans(String beginDate, String endDate, - * Integer domain, Integer entranceId) { List listMap = new + * public List getDomainTrans(String beginDate, String endDate, Integer + * domain, Integer entranceId) { List listMap = new * ArrayList(); HashMap resulMap = new HashMap(); * List domainList = new * ArrayList(); domainList = * trafficHttpStatisticDao.getDomainTrans(entranceId, beginDate, endDate, - * domain); List timeList = new ArrayList(); List countList = new - * ArrayList(); if (domainList != null && domainList.size() > 0) { - * Map m = new HashMap(); int inter - * = 1000 * 60 * 30;// 间隔时间为30分钟 // 开始时间,结束时间 时间戳 Long b = - * dateToStamp(beginDate); Long e = dateToStamp(endDate); int num = 0; Long - * pointTime = b; while (pointTime < e) { Map rm = new HashMap(); Long sumL - * = 0l; if (pointTime >= e) { break; // 停止 } for (TrafficHttpFocusStatistic - * tt : domainList) { // 实际时间 String time = tt.getTime(); Long t = - * dateToStamp(time); if (t >= pointTime && t < pointTime + inter) { // - * 范围之内分到此pointTime组 sumL = sumL + tt.getCount(); } } // + * domain); List timeList = new ArrayList(); List countList = new ArrayList(); + * if (domainList != null && domainList.size() > 0) { Map m + * = new HashMap(); int inter = 1000 * 60 * 30;// 间隔时间为30分钟 + * // 开始时间,结束时间 时间戳 Long b = dateToStamp(beginDate); Long e = + * dateToStamp(endDate); int num = 0; Long pointTime = b; while (pointTime < e) + * { Map rm = new HashMap(); Long sumL = 0l; if (pointTime >= e) { break; // 停止 + * } for (TrafficHttpFocusStatistic tt : domainList) { // 实际时间 String time = + * tt.getTime(); Long t = dateToStamp(time); if (t >= pointTime && t < pointTime + * + inter) { // 范围之内分到此pointTime组 sumL = sumL + tt.getCount(); } } // * 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 if (pointTime >= e - inter && sumL > 0) { - * countList.add(sumL); timeList.add(stampToDate(pointTime)); } if - * (pointTime < e - inter) { timeList.add(stampToDate(pointTime)); - * countList.add(sumL); } num = num + 1; pointTime = b + inter * num; } - * resulMap.put("count", countList); resulMap.put("statTime", timeList); - * listMap.add(resulMap); } return listMap; } + * countList.add(sumL); timeList.add(stampToDate(pointTime)); } if (pointTime < + * e - inter) { timeList.add(stampToDate(pointTime)); countList.add(sumL); } num + * = num + 1; pointTime = b + inter * num; } resulMap.put("count", countList); + * resulMap.put("statTime", timeList); listMap.add(resulMap); } return listMap; + * } */ /** * 优化后的网站详情域名趋势查询 + * * @param beginDate * @param endDate * @param domain @@ -1433,134 +1373,139 @@ public class DashboardService extends BaseService { Date beginDate = DateUtils.parseDate(begin); Date endDate = DateUtils.parseDate(end); List listMap = new ArrayList(); - List dateRangeList = new ArrayList(); - List strDateRangeList = new ArrayList(); - Calendar calendar = Calendar.getInstance(); - calendar.setTime(beginDate); - SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); - while (calendar.getTime().compareTo(endDate)<=0) { - dateRangeList.add(calendar.getTime()); - strDateRangeList.add(sdf.format(calendar.getTime())); - calendar.add(Calendar.MINUTE, 5); - } - //存放每个时间点的总数 - Map> ipCountListMap = new HashMap>(); - int index=0; - List countList =new ArrayList(); - for (int i = 0; i < dateRangeList.size(); i++) { - //存放一个时间点中总数 - Map ipCountMap = new HashMap(); - Date date = dateRangeList.get(i); - Long num = 0L; - for (int j = index; j < domainList.size(); j++) { - TrafficHttpFocusStatistic ipInfo = domainList.get(j); - if (ipInfo.getStatTime()!=null){ - if(ipInfo.getStatTime().compareTo(date)>=0&&(i+1 dateRangeList = new ArrayList(); + List strDateRangeList = new ArrayList(); + Calendar calendar = Calendar.getInstance(); + calendar.setTime(beginDate); + SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); + while (calendar.getTime().compareTo(endDate) <= 0) { + dateRangeList.add(calendar.getTime()); + strDateRangeList.add(sdf.format(calendar.getTime())); + calendar.add(Calendar.MINUTE, 5); + } + // 存放每个时间点的总数 + Map> ipCountListMap = new HashMap>(); + int index = 0; + List countList = new ArrayList(); + for (int i = 0; i < dateRangeList.size(); i++) { + // 存放一个时间点中总数 + Map ipCountMap = new HashMap(); + Date date = dateRangeList.get(i); + Long num = 0L; + for (int j = index; j < domainList.size(); j++) { + TrafficHttpFocusStatistic ipInfo = domainList.get(j); + if (ipInfo.getStatTime() != null) { + if (ipInfo.getStatTime().compareTo(date) >= 0 && (i + 1 < dateRangeList.size() + && ipInfo.getStatTime().compareTo(dateRangeList.get(i + 1)) < 0)) { + num = num + ipInfo.getCount(); + } else { + index = j; + break; } } - countList.add(num); } - //整合 count time - HashMap ipTrafficMap = new HashMap(); - ipTrafficMap.put("count", countList); - ipTrafficMap.put("statTime", strDateRangeList); - listMap.add(ipTrafficMap); + countList.add(num); + } + // 整合 count time + HashMap ipTrafficMap = new HashMap(); + ipTrafficMap.put("count", countList); + ipTrafficMap.put("statTime", strDateRangeList); + listMap.add(ipTrafficMap); return listMap; } /** * 获取活跃Port top10 的趋势图 - * @throws ParseException + * + * @throws ParseException */ - public List findTrafficPortActive(String beginDate, String endDate, Integer[] portArray) throws ParseException { + public List findTrafficPortActive(String beginDate, String endDate, Integer[] portArray) + throws ParseException { List listMap = new ArrayList(); StringBuilder portStr = new StringBuilder(); - List portListTop10 = null; - if(portArray!=null && portArray.length>0){//如果有传人参数,获取传人参数 - for(int pi=0;pi portListTop10 = null; + if (portArray != null && portArray.length > 0) {// 如果有传人参数,获取传人参数 + for (int pi = 0; pi < portArray.length; pi++) { + portStr.append("'" + portArray[pi] + "',"); } - }else{//否则获取TOP10 + } else {// 否则获取TOP10 portListTop10 = trafficPortActiveStatisticDao.findTrafficPortActiveTopN(beginDate, endDate); for (LinkedHashMap map : portListTop10) { - portStr.append("'"+map.get("port")+"',"); + portStr.append("'" + map.get("port") + "',"); } } - if (!StringUtil.isEmpty(portStr)&&portStr.indexOf(",")>0) { + if (!StringUtil.isEmpty(portStr) && portStr.indexOf(",") > 0) { portStr.deleteCharAt(portStr.lastIndexOf(",")); } Date beginDate1 = DateUtils.strToDate(beginDate, "yyyy-MM-dd HH:mm:ss"); Date endDate1 = DateUtils.strToDate(endDate, "yyyy-MM-dd HH:mm:ss"); - //if (portListTop10 != null && portListTop10.size() > 0) { - //StringBuilder portStr = new StringBuilder(); - if(!StringUtil.isEmpty(portStr)){ - //如果所有IP在最后一个时间点的count都为0,则移除最后一个点 - //开始划分时间段,间隔5分钟 + // if (portListTop10 != null && portListTop10.size() > 0) { + // StringBuilder portStr = new StringBuilder(); + if (!StringUtil.isEmpty(portStr)) { + // 如果所有IP在最后一个时间点的count都为0,则移除最后一个点 + // 开始划分时间段,间隔5分钟 List dateRangeList = new ArrayList(); List strDateRangeList = new ArrayList(); Calendar calendar = Calendar.getInstance(); calendar.setTime(beginDate1); SimpleDateFormat sdf = new SimpleDateFormat("MM-dd HH:mm"); - while (calendar.getTime().compareTo(endDate1)<=0) { + while (calendar.getTime().compareTo(endDate1) <= 0) { dateRangeList.add(calendar.getTime()); strDateRangeList.add(sdf.format(calendar.getTime())); calendar.add(Calendar.MINUTE, 5); } - - ArrayList portInfoList = trafficPortActiveStatisticDao.findTrafficPortActive(beginDate, endDate, portStr.toString()); - //存放每个IP,每个时间点的总数 - Map> portCountListMap = new HashMap>(); - int index=0; + + ArrayList portInfoList = trafficPortActiveStatisticDao + .findTrafficPortActive(beginDate, endDate, portStr.toString()); + // 存放每个IP,每个时间点的总数 + Map> portCountListMap = new HashMap>(); + int index = 0; for (int i = 0; i < dateRangeList.size(); i++) { - //存放一个时间点中每个IP的总数 + // 存放一个时间点中每个IP的总数 Map portCountMap = new HashMap(); Date date = dateRangeList.get(i); for (int j = index; j < portInfoList.size(); j++) { TrafficPortActiveStatistic portInfo = portInfoList.get(j); - if (portInfo.getStatTime()!=null){ - if(portInfo.getStatTime().compareTo(date)>=0&&(i+1= 0 && (i + 1 < dateRangeList.size() + && portInfo.getStatTime().compareTo(dateRangeList.get(i + 1)) < 0)) { Long num = portInfo.getSum(); if (portCountMap.containsKey(portInfo.getPort())) { - num=num+portCountMap.get(portInfo.getPort()); + num = num + portCountMap.get(portInfo.getPort()); } portCountMap.put(portInfo.getPort().toString(), num); - }else{ + } else { index = j; break; } } } - if(portArray!=null && portArray.length>0){//如果有传人参数,获取传人参数 - for(int m=0;m 0) {// 如果有传人参数,获取传人参数 + for (int m = 0; m < portArray.length; m++) { String port = portArray[m].toString(); Long sum = 0l; if (portCountMap.containsKey(port)) { - sum=portCountMap.get(port); + sum = portCountMap.get(port); } if (portCountListMap.containsKey(port)) { portCountListMap.get(port).add(sum); - }else{ + } else { List list = new ArrayList(); list.add(sum); portCountListMap.put(port, list); } } - - }else if(portListTop10!=null){ + + } else if (portListTop10 != null) { for (LinkedHashMap map : portListTop10) { String port = map.get("port").toString(); Long sum = 0l; if (portCountMap.containsKey(port)) { - sum=portCountMap.get(port); + sum = portCountMap.get(port); } if (portCountListMap.containsKey(port)) { portCountListMap.get(port).add(sum); - }else{ + } else { List list = new ArrayList(); list.add(sum); portCountListMap.put(port, list); @@ -1568,10 +1513,10 @@ public class DashboardService extends BaseService { } } } - //整合port sum time + // 整合port sum time Iterator iterator = portCountListMap.keySet().iterator(); while (iterator.hasNext()) { - String ip = iterator.next()+""; + String ip = iterator.next() + ""; Map trafficPortActiveMap = new HashMap(); trafficPortActiveMap.put("port", ip); trafficPortActiveMap.put("sum", portCountListMap.get(ip)); diff --git a/src/main/java/com/nis/web/service/restful/TrafficReportService.java b/src/main/java/com/nis/web/service/restful/TrafficReportService.java index fe6295a..437a320 100644 --- a/src/main/java/com/nis/web/service/restful/TrafficReportService.java +++ b/src/main/java/com/nis/web/service/restful/TrafficReportService.java @@ -21,12 +21,11 @@ import com.nis.web.service.BaseLogService; @Service public class TrafficReportService extends BaseLogService { - + @Autowired protected TrafficReportDao trafficReportDao; - - public Page findNtcRadiusReport(Page page,NtcRadiusReport entity) throws Exception { + public Page findNtcRadiusReport(Page page, NtcRadiusReport entity) throws Exception { entity.setPage(page); List resultList = null; if ("1".equals(entity.getSearchBusinessType())) { @@ -69,11 +68,7 @@ public class TrafficReportService extends BaseLogService { return page; } - - - - - + /** * 根据ip46,协议tcp,udp查询带宽 * @@ -92,7 +87,6 @@ public class TrafficReportService extends BaseLogService { return listMap; } - /** * 根据ip46,协议tcp,udp查询带宽 @@ -112,8 +106,16 @@ public class TrafficReportService extends BaseLogService { return listMap; } - - + + public static void main(String[] args) { +// long a = Long.parseLong("123.3"); + Long.valueOf("123.3"); + +// long b = Long.parseLong("123.3",1); + + long c = Long.valueOf("123.3").longValue(); + } + /** * 查询单个局点流量的数据信息 * @@ -158,8 +160,11 @@ public class TrafficReportService extends BaseLogService { if (t >= pointTime && t < pointTime + inter) { // 范围之内分到此pointTime组 sumL = sumL + tt.getLinkNum(); - sumP = sumP + tt.getPps(); - sumG = sumG + tt.getGbps(); + sumP = sumP +Long.parseLong( + tt.getPps().substring(0,tt.getPps().lastIndexOf("."))); + sumG = sumG + + Long.parseLong( + tt.getGbps().substring(0,tt.getGbps().lastIndexOf("."))); } } // 在结束时间只有当值大于0时才记录数据,防止折线降为0引起误会 @@ -192,8 +197,7 @@ public class TrafficReportService extends BaseLogService { } return resulMap; } - - + /** * 时间戳 换成日期格式字符串转 * @@ -206,8 +210,7 @@ public class TrafficReportService extends BaseLogService { String sd = sdf.format(new Date(timeStamp)); // 时间戳转换成时间 return sd; } - - + /** * 日期格式字符串转换成时间戳 * diff --git a/src/main/resources/spring-mvc.xml b/src/main/resources/spring-mvc.xml index cf31f60..b260e78 100644 --- a/src/main/resources/spring-mvc.xml +++ b/src/main/resources/spring-mvc.xml @@ -217,14 +217,14 @@ - + - +