diff --git a/src/main/java/com/nis/domain/log/SearchReport.java b/src/main/java/com/nis/domain/log/SearchReport.java index fdb60bf07..c99242112 100644 --- a/src/main/java/com/nis/domain/log/SearchReport.java +++ b/src/main/java/com/nis/domain/log/SearchReport.java @@ -8,6 +8,7 @@ */ package com.nis.domain.log; +import java.util.Date; import java.util.HashMap; import com.nis.domain.BaseEntity; @@ -35,7 +36,9 @@ public class SearchReport extends BaseEntity{ private String reportBusinessType; private String searchBusinessType; private String searchReportStartTime; + private Date reportStartTime; private String searchReportEndTime; + private Date reportEndTime; private String searchService; private HashMap searchCondition; public static final String searchConditionSplitor=","; @@ -47,6 +50,34 @@ public class SearchReport extends BaseEntity{ //界面查询的时间 private String reportTime; + /** + * reportStartTime + * @return reportStartTime + */ + + public Date getReportStartTime() { + return reportStartTime; + } + /** + * @param reportStartTime the reportStartTime to set + */ + public void setReportStartTime(Date reportStartTime) { + this.reportStartTime = reportStartTime; + } + /** + * reportEndTime + * @return reportEndTime + */ + + public Date getReportEndTime() { + return reportEndTime; + } + /** + * @param reportEndTime the reportEndTime to set + */ + public void setReportEndTime(Date reportEndTime) { + this.reportEndTime = reportEndTime; + } /** * reportTime * @return reportTime diff --git a/src/main/java/com/nis/util/DateUtils.java b/src/main/java/com/nis/util/DateUtils.java index 0a331f4ba..011f1dd0a 100644 --- a/src/main/java/com/nis/util/DateUtils.java +++ b/src/main/java/com/nis/util/DateUtils.java @@ -243,6 +243,89 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils { SimpleDateFormat sdf = new SimpleDateFormat(format); return sdf.parse(date); } + /** + * + * isLeapYear(计算是否为闰年) + * (这里描述这个方法适用条件 – 可选) + * @param years + * @return + *boolean + * @exception + * @since 1.0.0 + */ + public static boolean isLeapYear(int years){ + Calendar calendar=Calendar.getInstance(); + calendar.set(years,Calendar.DECEMBER,31); + if(calendar.get(Calendar.DAY_OF_YEAR)==366){ + return true; + } + return false; + } + /** + * + * setLastDayOfMonth(设置天为月末最后一天) + * (这里描述这个方法适用条件 – 可选) + * @param cal + *void + * @exception + * @since 1.0.0 + */ + public static void setLastDayOfMonth(Calendar cal){ + switch(cal.get(Calendar.MONTH)){ + case 0:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 1:{ + if(DateUtils.isLeapYear(cal.get(Calendar.YEAR))){ + cal.set(Calendar.DAY_OF_MONTH, 29); + }else{ + cal.set(Calendar.DAY_OF_MONTH, 28); + } + break; + } + case 2:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 3:{ + cal.set(Calendar.DAY_OF_MONTH, 30); + break; + } + case 4:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 5:{ + cal.set(Calendar.DAY_OF_MONTH, 30); + break; + } + case 6:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 7:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 8:{ + cal.set(Calendar.DAY_OF_MONTH, 30); + break; + } + case 9:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + case 10:{ + cal.set(Calendar.DAY_OF_MONTH, 30); + break; + } + case 11:{ + cal.set(Calendar.DAY_OF_MONTH, 31); + break; + } + } + } /** * @param args * @throws ParseException diff --git a/src/main/java/com/nis/web/controller/BaseController.java b/src/main/java/com/nis/web/controller/BaseController.java index 359bf0282..21e4a574b 100644 --- a/src/main/java/com/nis/web/controller/BaseController.java +++ b/src/main/java/com/nis/web/controller/BaseController.java @@ -1,7 +1,10 @@ package com.nis.web.controller; import java.beans.PropertyEditorSupport; import java.io.IOException; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Calendar; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -45,6 +48,7 @@ import com.nis.exceptions.MaatConvertException; import com.nis.util.Configurations; //import com.nis.main.ConvertTool; import com.nis.util.Constants; +import com.nis.util.DateUtil; import com.nis.util.DateUtils; import com.nis.util.DictUtils; import com.nis.util.JsonMapper; @@ -1001,5 +1005,114 @@ public class BaseController { } return msg.toString(); } - + /** + * + * setReportSearchTime(报表查询设置开始时间与结束时间) + * (这里描述这个方法适用条件 – 可选) + * @param bean + * @throws ParseException + *void + * @exception + * @since 1.0.0 + */ + public void setReportSearchTime(SearchReport bean) throws ParseException{ + SimpleDateFormat sdf=new SimpleDateFormat(Constants.SEARCH_DATEFORMAT); + String reportTime=bean.getReportTime(); + if(StringUtils.isNotBlank(reportTime)){ + Calendar startCal=Calendar.getInstance(); + startCal.setTime(getReportTime(reportTime)); + startCal.set(Calendar.MINUTE, 0); + startCal.set(Calendar.SECOND, 0); + startCal.set(Calendar.MILLISECOND, 0); + Calendar endCal=Calendar.getInstance(); + endCal.setTime(getReportTime(reportTime)); + endCal.set(Calendar.MINUTE, 59); + endCal.set(Calendar.SECOND, 59); + endCal.set(Calendar.MILLISECOND, 0); + if(bean.getReportType()==Constants.REPORT_TYPE_HOUR){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + endCal.set(Calendar.HOUR_OF_DAY, 23); + }else if(bean.getReportType()==Constants.REPORT_TYPE_DAY){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + startCal.set(Calendar.DAY_OF_MONTH, 1); + endCal.set(Calendar.HOUR_OF_DAY, 23); + DateUtils.setLastDayOfMonth(endCal); + }else if(bean.getReportType()==Constants.REPORT_TYPE_MONTH){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + startCal.set(Calendar.DAY_OF_MONTH, 1); + startCal.set(Calendar.MONTH, 0); + endCal.set(Calendar.HOUR_OF_DAY, 23); + DateUtils.setLastDayOfMonth(endCal); + endCal.set(Calendar.MONTH, 11); + } + bean.setReportStartTime(startCal.getTime()); + bean.setReportEndTime(endCal.getTime()); + bean.setSearchReportStartTime(sdf.format(startCal.getTime())); + bean.setSearchReportEndTime(sdf.format(endCal.getTime())); + }else{ + Date date=new Date(); + bean.setReportEndTime(date); + bean.setSearchReportEndTime(sdf.format(date)); + Calendar startCal=Calendar.getInstance(); + startCal.setTime(date); + startCal.set(Calendar.MINUTE, 0); + startCal.set(Calendar.SECOND, 0); + startCal.set(Calendar.MILLISECOND, 0); + if(bean.getReportType()==Constants.REPORT_TYPE_HOUR){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + }else if(bean.getReportType()==Constants.REPORT_TYPE_DAY){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + startCal.set(Calendar.DAY_OF_MONTH, 1); + }else if(bean.getReportType()==Constants.REPORT_TYPE_MONTH){ + startCal.set(Calendar.HOUR_OF_DAY, 0); + startCal.set(Calendar.DAY_OF_MONTH, 1); + startCal.set(Calendar.MONTH, 0); + } + bean.setReportStartTime(startCal.getTime()); + bean.setSearchReportStartTime(sdf.format(startCal.getTime())); + + } + logger.info("search start time "+bean.getSearchReportStartTime()); + logger.info("search end time "+bean.getSearchReportEndTime()); + } + public List getDateTitiles(SearchReport bean){ + SimpleDateFormat sdf=new SimpleDateFormat(Constants.SEARCH_DATEFORMAT); + List titles=new ArrayList(); + Calendar cal=Calendar.getInstance(); + cal.setTime(bean.getReportStartTime()); + while(cal.getTimeInMillis() result=new ReportResult<>(); StringBuffer url=new StringBuffer(Constants.LOG_BASE_URL+Constants.NTC_SERVICE_REPORT+"?"); bean.setPageSize(-1); bean.setFields("srcProvince,srcCity,sum,reportTime"); - String format=Constants.SEARCH_DATEFORMAT; - SimpleDateFormat sdf=new SimpleDateFormat(format); - Date date=new Date(); - bean.setSearchReportEndTime(sdf.format(date)); - Calendar cal=Calendar.getInstance(); - cal.set(Calendar.MINUTE, 0); - cal.set(Calendar.SECOND, 0); - cal.set(Calendar.MILLISECOND, 0); - if(bean.getReportType()==Constants.REPORT_TYPE_HOUR){ - cal.set(Calendar.HOUR_OF_DAY, 0); - }else if(bean.getReportType()==Constants.REPORT_TYPE_DAY){ - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.DAY_OF_MONTH, 1); - }else if(bean.getReportType()==Constants.REPORT_TYPE_MONTH){ - cal.set(Calendar.HOUR_OF_DAY, 0); - cal.set(Calendar.DAY_OF_MONTH, 1); - cal.set(Calendar.MONTH, 0); - } - logger.info("search start time "+sdf.format(cal.getTime())); - logger.info("search end time "+sdf.format(date)); - bean.setSearchReportStartTime(sdf.format(cal.getTime())); - List titles=new ArrayList(); - while(cal.getTime().getTime() titles=this.getDateTitiles(bean); model.addAttribute("titles", titles); // try { // result=result.getReport(url.toString(), bean); diff --git a/src/main/java/com/nis/web/controller/report/NtcTagReportController.java b/src/main/java/com/nis/web/controller/report/NtcTagReportController.java index 35586024a..ac2a68260 100644 --- a/src/main/java/com/nis/web/controller/report/NtcTagReportController.java +++ b/src/main/java/com/nis/web/controller/report/NtcTagReportController.java @@ -32,9 +32,6 @@ import com.nis.web.controller.BaseController; public class NtcTagReportController extends BaseController { @RequestMapping("/ajaxNtcTagReport") public String list(@ModelAttribute("bean") SearchReport bean,Model model, HttpServletRequest request, HttpServletResponse response) { -// if (bean.getReportType() == null) { -// bean.setReportType(1); -// } List serviceList = DictUtils.getFunctionServiceDictList(bean.getFunctionId()); List labels=serviceDictInfoService.findAllLableDict(); model.addAttribute("labels", labels); diff --git a/src/main/webapp/WEB-INF/views/report/list.jsp b/src/main/webapp/WEB-INF/views/report/list.jsp index fe80ff8a8..0931f8cff 100644 --- a/src/main/webapp/WEB-INF/views/report/list.jsp +++ b/src/main/webapp/WEB-INF/views/report/list.jsp @@ -23,19 +23,19 @@ $("#searchForm")[0].reset(); }); if(!"${bean.reportBusinessType}"){ - ajaxGetLabelReport(); + ajaxReport("/report/ajaxNtcTagReport","#label"); }else if("${bean.reportBusinessType}"=="label_report"){ - ajaxGetLabelReport(); + ajaxReport("/report/ajaxNtcTagReport","#label"); }else if("${bean.reportBusinessType}"=="lwhh_report"){ - ajaxGetLwhhReport(); + ajaxReport("/report/ajaxNtcLwhhReport","#lwhh"); }else if("${bean.reportBusinessType}"=="src_ip_report"){ - ajaxGetSrcIpReport(); + ajaxReport("/report/ajaxNtcSrcipDomesticReport","#srcIp"); }else if("${bean.reportBusinessType}"=="attr_type_report"){ - ajaxGetXzReport(); + ajaxReport("/report/ajaxNtcXzReport","#attrType"); }else if("${bean.reportBusinessType}"=="dest_ip_report"){ - ajaxGetDestIpReport(); + ajaxReport("/report/ajaxNtcDestIpReport","#destIp"); }else if("${bean.reportBusinessType}"=="isp_report"){ - ajaxGetIspReport(); + ajaxReport("/report/ajaxNtcIspReport","#entranceId"); } $("[name='reportType']").each(function(){ var type='${bean.reportType}'; @@ -47,17 +47,17 @@ $("#reportBusinessType").val($(this).data("bussiness")); if(!$(this).parent("li").hasClass("active")){ if($(this).data("bussiness")=="label_report"){ - ajaxGetLabelReport(); + ajaxReport("/report/ajaxNtcTagReport","#label"); }else if($(this).data("bussiness")=="lwhh_report"){ - ajaxGetLwhhReport(); + ajaxReport("/report/ajaxNtcLwhhReport","#lwhh"); }else if($(this).data("bussiness")=="src_ip_report"){ - ajaxGetSrcIpReport(); + ajaxReport("/report/ajaxNtcSrcipDomesticReport","#srcIp"); }else if($(this).data("bussiness")=="attr_type_report"){ - ajaxGetXzReport(); + ajaxReport("/report/ajaxNtcXzReport","#attrType"); }else if($(this).data("bussiness")=="dest_ip_report"){ - ajaxGetDestIpReport(); + ajaxReport("/report/ajaxNtcDestIpReport","#destIp"); }else if($(this).data("bussiness")=="isp_report"){ - ajaxGetIspReport(); + ajaxReport("/report/ajaxNtcIspReport","#entranceId"); } } }); @@ -78,104 +78,20 @@ } } -var ajaxGetLabelReport=function(){ +var ajaxReport=function(url,target){ loading(''); $.ajax({ type:'post', async:false, - url:'${ctx}/report/ajaxNtcTagReport', + url:'${ctx}'+url,///report/ajaxNtcTagReport data:{ "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() + "reportType":$('[name="reportType"]').val(), + "reportTime":$('[name="reportTime"]').val() }, dataType:"html", success:function(data){ - $("#label").html(data); - closeTip(); - } - }); -} -var ajaxGetLwhhReport=function(){ - loading(''); - $.ajax({ - type:'post', - async:false, - url:'${ctx}/report/ajaxNtcLwhhReport', - data:{ - "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() - }, - dataType:"html", - success:function(data){ - $("#lwhh").html(data); - closeTip(); - } - }); -} -var ajaxGetSrcIpReport=function(){ - loading(''); - $.ajax({ - type:'post', - async:false, - url:'${ctx}/report/ajaxNtcSrcipDomesticReport', - data:{ - "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() - }, - dataType:"html", - success:function(data){ - $("#srcIp").html(data); - closeTip(); - } - }); -} -var ajaxGetXzReport=function(){ - loading(''); - $.ajax({ - type:'post', - async:false, - url:'${ctx}/report/ajaxNtcXzReport', - data:{ - "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() - }, - dataType:"html", - success:function(data){ - $("#attrType").html(data); - closeTip(); - } - }); -} -var ajaxGetDestIpReport=function(){ - loading(''); - $.ajax({ - type:'post', - async:false, - url:'${ctx}/report/ajaxNtcDestIpReport', - data:{ - "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() - }, - dataType:"html", - success:function(data){ - $("#destIp").html(data); - closeTip(); - } - }); -} -var ajaxGetIspReport=function(){ - loading(''); - $.ajax({ - type:'post', - async:false, - url:'${ctx}/report/ajaxNtcIspReport', - data:{ - "action":$('[name="action"]').val(), - "reportType":$('[name="reportType"]').val() - }, - dataType:"html", - success:function(data){ - $("#entranceId").html(data); + $(target).html(data);//#label closeTip(); } });