解决最近时间段显示为0问题,动作详情时间趋势转为后台运算时间分组

This commit is contained in:
zhanghongqing
2018-12-13 19:17:52 +08:00
parent 76008c23f9
commit 0b1d9d8783
4 changed files with 100 additions and 46 deletions

View File

@@ -70,13 +70,20 @@ public class DashboardServiceController extends BaseRestController {
*/
@RequestMapping(value = "ntcActionEntranceReport", method = RequestMethod.GET)
@ApiOperation(value = "根据不同动作统计总量汇聚", httpMethod = "GET", notes = "对应流量统计info滚动条动作类型详情数据显示")
public Map<String,?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response,String searchAction) {
public Map<String,?> ntcTotalReport(Model model, HttpServletRequest request, HttpServletResponse response,String searchAction,String beginDate,String endDate) {
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<HashMap> resultList = dashboardService.getActionTrans(searchAction);
if(StringUtils.isEmpty(beginDate)||StringUtils.isEmpty(endDate)) {
Calendar cal = Calendar. getInstance ();
cal.setTime(new Date());
endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());//获取到完整的时间
cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1);
beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ).format(cal.getTime());
}
List<HashMap> resultList = dashboardService.getActionTrans(beginDate,endDate,searchAction);
if (resultList!=null&&resultList.size() > 0) {
list = resultList;
}
@@ -206,12 +213,12 @@ public class DashboardServiceController extends BaseRestController {
*/
@RequestMapping(value="trafficProtocolList", method = RequestMethod.GET)
@ApiOperation(value = "协议统计占比与报表", httpMethod = "GET", notes = "对应协议统计详情占比与报表")
public Map<String,?> trafficProtocolList(String searchFoundStartTime,String searchFoundEndTime,Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String,?> trafficProtocolList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> ipActiveList = dashboardService.getProtocolList(searchFoundStartTime,searchFoundEndTime);
List<Map> ipActiveList = dashboardService.getProtocolList(beginDate,endDate);
if (ipActiveList!=null&&ipActiveList.size() > 0) {
String jsonString = JsonMapper.toJsonString(ipActiveList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);
@@ -329,12 +336,12 @@ public class DashboardServiceController extends BaseRestController {
*/
@RequestMapping(value="trafficAppList", method = RequestMethod.GET)
@ApiOperation(value = "App统计占比与报表", httpMethod = "GET", notes = "对应App统计详情占比与报表")
public Map<String,?> trafficAppList(String searchFoundStartTime,String searchFoundEndTime,Model model, HttpServletRequest request, HttpServletResponse response){
public Map<String,?> trafficAppList(String beginDate,String endDate,Model model, HttpServletRequest request, HttpServletResponse response){
long start = System.currentTimeMillis();
AuditLogThread auditLogThread = super.saveRequestLog(servicesRequestLogService, Constants.OPACTION_GET, request, null);
List<HashMap> list = new ArrayList<HashMap>();
try {
List<Map> appList = dashboardService.getAppList(searchFoundStartTime,searchFoundEndTime);
List<Map> appList = dashboardService.getAppList(beginDate,endDate);
if (appList!=null&&appList.size() > 0) {
String jsonString = JsonMapper.toJsonString(appList);
list = (java.util.List<HashMap>) JsonMapper.fromJsonList(jsonString,HashMap.class);

View File

@@ -19,5 +19,5 @@ public interface NtcTotalReportDao {
List<TrafficTransStatistic> getBandwidthTrans(@Param("entranceId") Integer entranceId,@Param("beginDate") String beginDate,@Param("endDate") String endDate,@Param("addrType") String addrType,@Param("transType") Integer transType);
Map getEntranceMaxReportTime();
List<NtcEntranceReport> getActionTrans(@Param("reportTime") Date reportTime,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
List<NtcEntranceReport> getActionTrans(@Param("beginDate") String beginDate,@Param("endDate") String endDate ,@Param("entranceId") Integer entranceId,@Param("serviceSql") String serviceSql);
}

View File

@@ -89,7 +89,7 @@
SELECT report_time reportTime FROM ntc_entrance_report order by report_time desc limit 1
</select>
<!-- entrance 1,2 ,动作为阻断,近五分钟数据 -->
<select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
<!-- <select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
select IFNULL(p.sumNum,0) sum, date_format(a.min5,'%Y-%m-%d %H:%i') time from
(select date_sub(#{reportTime},interval @mycnt :=@mycnt + 5 MINUTE) min5
from (SELECT @mycnt:=-5) m, ntc_entrance_report limit 12) a
@@ -103,5 +103,12 @@
) p
on date_format(p.timestamp,'%Y-%m-%d %H:%i')=date_format(a.min5,'%Y-%m-%d %H:%i')
ORDER by time
</select> -->
<!-- entrance 1,2 ,动作为阻断,近一小时 间隔5分钟数据 -->
<select id="getActionTrans" resultType="com.nis.domain.restful.NtcEntranceReport">
select sum(sum) sum,report_time time from ntc_entrance_report r where
<![CDATA[${serviceSql} and report_time<=#{endDate} and report_time>=#{beginDate}]]>
and entrance_id=#{entranceId}
group by report_time order by report_time
</select>
</mapper>

View File

@@ -169,16 +169,16 @@ public class DashboardService extends BaseService {
Map<String, Comparable> m= new HashMap<String, Comparable>();
int inter=1000*60*5;// 间隔时间为五分钟
// 开始时间,结束时间 时间戳
Long b = dateToStamp(endDate);
Long e = dateToStamp(beginDate);
Long b = dateToStamp(beginDate);
Long e = dateToStamp(endDate);
int num=0;
Long pointTime=b;
while(pointTime>e){
while(pointTime<e){
Map rm=new HashMap();
Long sumL=0l;
Long sumP=0l;
Long sumG=0l;
if(pointTime<e){
if(pointTime>=e){
break; //停止
}
for (TrafficTransStatistic tt : bandwidthList) {
@@ -192,17 +192,29 @@ public class DashboardService extends BaseService {
sumG=sumG+ tt.getGbps();
}
}
// 在结束时间只有当值大于0时才记录数据防止折线降为0引起误会
if(pointTime>=e-inter&&sumL>0) {
linkList.add(sumL);
}
if(pointTime>=e-inter&&sumP>0) {
ppsList.add(sumP);
}
if(pointTime>=e-inter&&sumG>0) {
gbpsList.add(sumG);
}
if(pointTime>=e-inter&&(sumL>0||sumG>0||sumP>0)) {
timeList.add(stampToDate(pointTime));
}
if(pointTime<e-inter) {
timeList.add(stampToDate(pointTime));
linkList.add(sumL);
gbpsList.add(sumG);
ppsList.add(sumP);
num=num+1;
pointTime =b-inter*num;
}
Collections.reverse(linkList);
Collections.reverse(gbpsList);
Collections.reverse(ppsList);
Collections.reverse(timeList);
num=num+1;
pointTime =b+inter*num;
}
resulMap.put("linkNum", linkList);
resulMap.put("gbps", gbpsList);
resulMap.put("pps", ppsList);
@@ -227,10 +239,10 @@ public class DashboardService extends BaseService {
Long e = dateToStamp(end);
int num=0;
Long pointTime=b;
while(pointTime>e){
while(pointTime<e){
Map rm=new HashMap();
Long sum=0l;
if(pointTime<e){
if(pointTime>=e){
break; //停止
}
for (Map<?, ?> map : li) {
@@ -245,7 +257,7 @@ public class DashboardService extends BaseService {
rm.put("time", stampToDate(pointTime));
rm.put("sum", sum);
num=num+1;
pointTime =b-inter*num;
pointTime =b+inter*num;
resList.add(rm);
}
return resList;
@@ -281,7 +293,7 @@ public class DashboardService extends BaseService {
/**
* 根据service 动作查询近五分钟变化趋势 entrance 默认为1,2
*/
public List<HashMap> getActionTrans(String serviceType) {
public List<HashMap> 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))"; // 监测
@@ -297,36 +309,65 @@ public class DashboardService extends BaseService {
ArrayList<HashMap> listMap = new ArrayList<HashMap>();
List<NtcEntranceReport> entrance1 = new ArrayList<NtcEntranceReport>();
List<NtcEntranceReport> entrance2 = new ArrayList<NtcEntranceReport>();
Map maxReportTime = ntcTotalReportDao.getEntranceMaxReportTime();
if (maxReportTime != null && maxReportTime.get("reportTime") != null) {
Date reportTime = (Date) maxReportTime.get("reportTime");
HashMap m1 = new HashMap();
HashMap m2 = new HashMap();
entrance1 = ntcTotalReportDao.getActionTrans(reportTime, 1, sql);
entrance2 = ntcTotalReportDao.getActionTrans(reportTime, 2, sql);
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();
// entrance 为1的趋势
if (entrance1 != null && entrance1.size() > 0) {
for (NtcEntranceReport tt : entrance1) {
if (tt.getTime() != null && tt.getSum() != null) {
timeList.add(tt.getTime());
sumList1.add(tt.getSum());
Map<String, Comparable> m= new HashMap<String, Comparable>();
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();
}
}
}
// entrance 为2的趋势
if (entrance2 != null && entrance2.size() > 0) {
for (NtcEntranceReport tt : entrance2) {
if (tt.getTime() != null && tt.getSum() != null) {
// timeList.add(tt.getTime());
sumList2.add(tt.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);
}
m1.put("count", sumList1);// [{time:[],link:[],link2:[]}]
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);// [{link1:[],time:[],entrance:"1"},]
@@ -334,7 +375,6 @@ public class DashboardService extends BaseService {
m2.put("entranceId", 2);
listMap.add(m1);
listMap.add(m2);
}
return listMap;
}