2018-08-29 21:58:56 +08:00
|
|
|
package com.nis.web.controller.configuration;
|
|
|
|
|
|
2019-01-15 18:49:28 +08:00
|
|
|
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;
|
2018-08-29 21:58:56 +08:00
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
2019-01-15 18:49:28 +08:00
|
|
|
import org.apache.http.client.utils.URIBuilder;
|
2018-08-29 21:58:56 +08:00
|
|
|
import org.springframework.stereotype.Controller;
|
2019-01-15 18:49:28 +08:00
|
|
|
import org.springframework.ui.Model;
|
2018-08-29 21:58:56 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
2019-01-15 18:49:28 +08:00
|
|
|
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
2018-08-29 21:58:56 +08:00
|
|
|
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
2019-01-15 18:49:28 +08:00
|
|
|
import com.beust.jcommander.internal.Maps;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.google.gson.GsonBuilder;
|
|
|
|
|
import com.google.gson.reflect.TypeToken;
|
2018-08-29 21:58:56 +08:00
|
|
|
import com.nis.domain.log.BaseLogEntity;
|
2019-01-15 18:49:28 +08:00
|
|
|
import com.nis.util.Constants;
|
2019-04-25 14:42:41 +08:00
|
|
|
import com.nis.util.LogUtils;
|
2019-01-15 18:49:28 +08:00
|
|
|
import com.nis.util.StringUtil;
|
|
|
|
|
import com.nis.util.httpclient.HttpClientUtil;
|
2018-08-29 21:58:56 +08:00
|
|
|
import com.nis.web.controller.BaseController;
|
2019-01-15 18:49:28 +08:00
|
|
|
import net.sf.json.JSONObject;
|
2018-08-29 21:58:56 +08:00
|
|
|
|
|
|
|
|
@Controller
|
|
|
|
|
@RequestMapping("${adminPath}/toLogSearch")
|
|
|
|
|
public class LogSearchController extends BaseController{
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = {"list",""})
|
2018-09-13 16:46:56 +08:00
|
|
|
public String LogSearch(BaseLogEntity<Object> entity, RedirectAttributes attr, HttpServletRequest request,
|
|
|
|
|
HttpServletResponse response) {
|
2018-08-29 21:58:56 +08:00
|
|
|
/**
|
|
|
|
|
* url: logUrl
|
|
|
|
|
* searchCfgId: compileId
|
|
|
|
|
* searchService: serviceId
|
|
|
|
|
*/
|
|
|
|
|
// 获取相应日志检索菜单URL
|
2018-12-14 11:53:41 +08:00
|
|
|
if(entity.getFunctionId()!=null && entity.getFunctionId().equals(635)){
|
|
|
|
|
entity.setFunctionId(8);//关键字配置的日志查询定位至http日志
|
|
|
|
|
}
|
2018-08-29 21:58:56 +08:00
|
|
|
String logUrl = menuService.getLogUrl(entity.getFunctionId());
|
2018-09-30 10:54:30 +08:00
|
|
|
// Integer serviceId = menuService.getServiceId(entity.getFunctionId(),entity.getAction());
|
2018-08-29 21:58:56 +08:00
|
|
|
|
2018-09-30 10:54:30 +08:00
|
|
|
attr.addAttribute("service", entity.getService().intValue());
|
2018-09-13 16:46:56 +08:00
|
|
|
attr.addAttribute("cfgId", entity.getCfgId());
|
2018-08-29 21:58:56 +08:00
|
|
|
attr.addAttribute("functionId", entity.getFunctionId());
|
2018-09-03 12:37:46 +08:00
|
|
|
attr.addAttribute("date", entity.getDate());
|
2018-09-13 16:46:56 +08:00
|
|
|
attr.addAttribute("isLogTotalSearch", entity.getIsLogTotalSearch());
|
2018-08-29 21:58:56 +08:00
|
|
|
return "redirect:"+adminPath+logUrl;
|
|
|
|
|
}
|
2019-01-15 18:49:28 +08:00
|
|
|
|
|
|
|
|
|
2019-01-15 19:11:10 +08:00
|
|
|
@RequestMapping(value = {"logTrend"})
|
2019-01-15 18:51:49 +08:00
|
|
|
public String logTrend(Model model,BaseLogEntity<Object> entity,String cfgId,String serviceId,RedirectAttributes attr, HttpServletRequest request,
|
2019-01-15 18:49:28 +08:00
|
|
|
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);
|
2019-01-15 18:51:49 +08:00
|
|
|
model.addAttribute("serviceId", serviceId);
|
2019-01-15 18:49:28 +08:00
|
|
|
return "/cfg/logCfgTrendList";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value="actionLogTrend")
|
|
|
|
|
@ResponseBody
|
2019-04-25 14:42:41 +08:00
|
|
|
public List actionTrans(String cfgId,String beginDate,String endDate,String serviceId,HttpServletRequest request){
|
2019-01-15 18:49:28 +08:00
|
|
|
Map<String, Object> fromJsonList = new HashMap<String, Object>();
|
|
|
|
|
List resultList = new ArrayList();
|
|
|
|
|
String url = Constants.LOG_BASE_URL+Constants.NTC_PZ_REPORT;
|
2019-01-16 18:21:22 +08:00
|
|
|
url=url+"?pageSize=-1&searchBusinessType=2&searchCfgId="+cfgId;
|
2019-01-15 18:51:49 +08:00
|
|
|
if(!StringUtil.isEmpty(serviceId)){
|
|
|
|
|
url=url+"&searchService="+serviceId;
|
|
|
|
|
}
|
2019-01-15 18:49:28 +08:00
|
|
|
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"));
|
2019-04-25 14:42:41 +08:00
|
|
|
LogUtils.saveLog(request, null, e, null);
|
2019-01-15 18:49:28 +08:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
}
|
2018-08-29 21:58:56 +08:00
|
|
|
}
|