业务配置添加日志趋势图
js国际化添加日志趋势
This commit is contained in:
@@ -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<Object> 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<String, Object> fromJsonList = new HashMap<String, Object>();
|
||||
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<Map>(){}.getType());
|
||||
fromJsonList=(Map<String, Object>) 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<String, Object> dateList){
|
||||
List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
|
||||
try {
|
||||
List<Map<String, Object>> mapList=(List<Map<String, Object>>) dateList.get("list");
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
Map<String, Object> maps=new HashMap<String,Object>();
|
||||
List<Double[]> list=new ArrayList<Double[]>();
|
||||
Double total=0.0;
|
||||
for (Map<String, Object> 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user