(1)境内源IP报表加入对界面时间字段的处理

(2)时间字段的处理放到baseController中
(3)界面ajax函数缩减为1个公用的函数
This commit is contained in:
wangxin
2018-07-10 13:33:28 +08:00
parent 86fa5f0000
commit 0e05e2a0e4
6 changed files with 255 additions and 142 deletions

View File

@@ -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<SearchReport>{
private String reportBusinessType;
private String searchBusinessType;
private String searchReportStartTime;
private Date reportStartTime;
private String searchReportEndTime;
private Date reportEndTime;
private String searchService;
private HashMap<String,Object> searchCondition;
public static final String searchConditionSplitor=",";
@@ -47,6 +50,34 @@ public class SearchReport extends BaseEntity<SearchReport>{
//界面查询的时间
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

View File

@@ -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

View File

@@ -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<String> getDateTitiles(SearchReport bean){
SimpleDateFormat sdf=new SimpleDateFormat(Constants.SEARCH_DATEFORMAT);
List<String> titles=new ArrayList<String>();
Calendar cal=Calendar.getInstance();
cal.setTime(bean.getReportStartTime());
while(cal.getTimeInMillis()<bean.getReportEndTime().getTime()){//构造标题
//报表时间单位加一
if(bean.getReportType()==Constants.REPORT_TYPE_HOUR){
titles.add(sdf.format(cal.getTime()).substring(0,13));
cal.add(Calendar.HOUR_OF_DAY, 1);
}else if(bean.getReportType()==Constants.REPORT_TYPE_DAY){
titles.add(sdf.format(cal.getTime()).substring(0,10));
cal.add(Calendar.DAY_OF_MONTH, 1);
}else if(bean.getReportType()==Constants.REPORT_TYPE_MONTH){
titles.add(sdf.format(cal.getTime()).substring(0,7));
cal.add(Calendar.MONTH, 1);
}
}
return titles;
}
public Date getReportTime(String reportTime) throws ParseException{
Pattern datePattern=Pattern.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}$");
Pattern monthPattern=Pattern.compile("^[0-9]{4}-[0-9]{2}$");
Pattern yearPattern=Pattern.compile("^[0-9]{4}$");
Matcher matcher=datePattern.matcher(reportTime);
if(matcher.matches()){
return new SimpleDateFormat("yyyy-MM-dd").parse(reportTime);
}else{
matcher=monthPattern.matcher(reportTime);
if(matcher.matches()){
return new SimpleDateFormat("yyyy-MM").parse(reportTime);
}else{
matcher=yearPattern.matcher(reportTime);
if(matcher.matches()){
return new SimpleDateFormat("yyyy").parse(reportTime);
}
}
}
return null;
}
}

View File

@@ -1,5 +1,6 @@
package com.nis.web.controller.report;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
@@ -11,6 +12,7 @@ import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
@@ -19,7 +21,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import com.nis.domain.FunctionServiceDict;
import com.nis.domain.Page;
import com.nis.domain.basics.ServiceDictInfo;
import com.nis.domain.configuration.RequestInfo;
import com.nis.domain.log.SearchReport;
import com.nis.domain.report.NtcSrcipDomesticReport;
import com.nis.domain.report.ReportResult;
@@ -50,47 +51,19 @@ public class NtcSrcipDomesticReportController extends BaseController {
}
bean.setSearchService(serviceId.toString());
}
String reportTime=bean.getReportTime();
bean.setSearchBusinessType("1");
ReportResult<NtcSrcipDomesticReport> 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<String> titles=new ArrayList<String>();
while(cal.getTime().getTime()<date.getTime()){//构造标题
//报表时间单位加一
if(bean.getReportType()==Constants.REPORT_TYPE_HOUR){
titles.add(sdf.format(cal.getTime()).substring(0,13));
cal.add(Calendar.HOUR_OF_DAY, 1);
}else if(bean.getReportType()==Constants.REPORT_TYPE_DAY){
titles.add(sdf.format(cal.getTime()).substring(0,10));
cal.add(Calendar.DAY_OF_MONTH, 1);
}else if(bean.getReportType()==Constants.REPORT_TYPE_MONTH){
titles.add(sdf.format(cal.getTime()).substring(0,7));
cal.add(Calendar.MONTH, 1);
}
try {
this.setReportSearchTime(bean);
} catch (ParseException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
List<String> titles=this.getDateTitiles(bean);
model.addAttribute("titles", titles);
// try {
// result=result.getReport(url.toString(), bean);

View File

@@ -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<FunctionServiceDict> serviceList = DictUtils.getFunctionServiceDictList(bean.getFunctionId());
List<ServiceDictInfo> labels=serviceDictInfoService.findAllLableDict();
model.addAttribute("labels", labels);

View File

@@ -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('<spring:message code="onloading"/>');
$.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('<spring:message code="onloading"/>');
$.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('<spring:message code="onloading"/>');
$.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('<spring:message code="onloading"/>');
$.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('<spring:message code="onloading"/>');
$.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('<spring:message code="onloading"/>');
$.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();
}
});