diff --git a/src/main/java/com/nis/web/controller/configuration/LogSearchController.java b/src/main/java/com/nis/web/controller/configuration/LogSearchController.java index 32ecb96fc..46075e331 100644 --- a/src/main/java/com/nis/web/controller/configuration/LogSearchController.java +++ b/src/main/java/com/nis/web/controller/configuration/LogSearchController.java @@ -1,14 +1,32 @@ package com.nis.web.controller.configuration; +import java.net.URISyntaxException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; - +import org.apache.http.client.utils.URIBuilder; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.mvc.support.RedirectAttributes; - +import com.beust.jcommander.internal.Maps; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; import com.nis.domain.log.BaseLogEntity; +import com.nis.util.Constants; +import com.nis.util.StringUtil; +import com.nis.util.httpclient.HttpClientUtil; import com.nis.web.controller.BaseController; +import net.sf.json.JSONObject; @Controller @RequestMapping("${adminPath}/toLogSearch") @@ -36,4 +54,95 @@ public class LogSearchController extends BaseController{ attr.addAttribute("isLogTotalSearch", entity.getIsLogTotalSearch()); return "redirect:"+adminPath+logUrl; } + + + @RequestMapping(value = {"logTrend",""}) + public String logTrend(Model model,BaseLogEntity entity,String cfgId,RedirectAttributes attr, HttpServletRequest request, + HttpServletResponse response) { + Calendar cal = Calendar. getInstance (); + cal.setTime(new Date()); + String now = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); + String oneHoursAgo = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); + model.addAttribute("beginDate", oneHoursAgo); + model.addAttribute("endDate", now); + model.addAttribute("cfgId", cfgId); + return "/cfg/logCfgTrendList"; + } + + @RequestMapping(value="actionLogTrend") + @ResponseBody + public List actionTrans(String cfgId,String beginDate,String endDate){ + Map fromJsonList = new HashMap(); + List resultList = new ArrayList(); + String url = Constants.LOG_BASE_URL+Constants.NTC_PZ_REPORT; + url=url+"?searchBusinessType=2&searchCfgId="+cfgId; + try { + //String url="http://192.168.10.204:9999/galaxy-service/service/log/v1/ntcPzReport?searchBusinessType=2&searchReportStartTime=2018-12-29%2000:00:00&searchReportEndTime=2018-12-30%2000:00:00"; + url = urlAddDate(url,beginDate,endDate); + //String json=ConfigServiceUtil.getReport(url.toString(), null); + String json = HttpClientUtil.get(url); + Gson gson = new GsonBuilder().create(); + fromJsonList = gson.fromJson(json, new TypeToken(){}.getType()); + fromJsonList=(Map) fromJsonList.get("data"); + logger.debug("日志趋势数据"+fromJsonList); + JSONObject obj=JSONObject.fromObject(json); + resultList =getList(fromJsonList); + + } catch (Exception e) { + e.printStackTrace(); + resultList.add(Maps.newHashMap("error","request_service_failed")); + } + return resultList; + } + + public List getList(Map dateList){ + List> resultList = new ArrayList>(); + try { + List> mapList=(List>) dateList.get("list"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + Map maps=new HashMap(); + List list=new ArrayList(); + Double total=0.0; + for (Map map : mapList) { + Double[] logs=new Double[2]; + Double sum=Double.valueOf(String.valueOf(map.get("sum"))); + Double date=Double.valueOf(sdf.parse(String.valueOf(map.get("reportTime"))).getTime()); + total+=sum; + logs[0]=date; + logs[1]=sum; + list.add(logs); + } + maps.put("sum",total); + maps.put("result", list); + resultList.add(maps); + } catch (Exception e) { + e.printStackTrace(); + } + return resultList; + } + + /** + * + * + * url路径时间参数格式化 + * @param url + * @param beginDate + * @param endDate + * @return + * @throws URISyntaxException + */ + public String urlAddDate(String url,String beginDate,String endDate) throws URISyntaxException{ + if(StringUtil.isBlank(beginDate)||StringUtil.isBlank(endDate)){ + Calendar cal = Calendar. getInstance (); + cal.setTime(new Date()); + endDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime());//获取到完整的时间 + cal.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY) - 1); + beginDate = new SimpleDateFormat( "yyyy-MM-dd HH:mm:00" ).format(cal.getTime()); + } + URIBuilder uriBuilder = new URIBuilder(url); + uriBuilder.addParameter("searchReportStartTime",beginDate); + uriBuilder.addParameter("searchReportEndTime",endDate); + return uriBuilder.toString(); + } } diff --git a/src/main/webapp/WEB-INF/views/cfg/logCfgTrendList.jsp b/src/main/webapp/WEB-INF/views/cfg/logCfgTrendList.jsp new file mode 100644 index 000000000..612c3d6bf --- /dev/null +++ b/src/main/webapp/WEB-INF/views/cfg/logCfgTrendList.jsp @@ -0,0 +1,408 @@ +<%@ page contentType="text/html;charset=UTF-8"%> +<%@ include file="/WEB-INF/include/taglib.jsp"%> + + + + <spring:message code="log"/><spring:message code="trend"/> + + + + + +
+ <%-- --%> + +
+
+ + +
+
+
+
+ +
+ +
+
+
+
+
+ +
+ +
+
+ +
+ + +
+
+ +
+
+
+
+ + <%-- --%> + + + + +
+ + +<%-- --%> + +<%-- --%> + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/home.jsp b/src/main/webapp/WEB-INF/views/home.jsp index 1df800b3a..28ceed752 100644 --- a/src/main/webapp/WEB-INF/views/home.jsp +++ b/src/main/webapp/WEB-INF/views/home.jsp @@ -343,6 +343,7 @@ background:#3d3d3d; +