package com.wgcloud.controller;
|
|
import cn.hutool.json.JSONObject;
|
import cn.hutool.json.JSONUtil;
|
import com.github.pagehelper.PageInfo;
|
import com.wgcloud.entity.LogInfo;
|
import com.wgcloud.service.LogInfoService;
|
import com.wgcloud.util.PageUtil;
|
import com.wgcloud.util.ResDataUtils;
|
import com.wgcloud.util.TokenUtils;
|
import com.wgcloud.util.staticvar.StaticKeys;
|
import org.apache.commons.lang3.StringUtils;
|
import org.slf4j.Logger;
|
import org.slf4j.LoggerFactory;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.ui.Model;
|
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* @version v3.3
|
* @ClassName:LogInfoController.java
|
* @author: http://www.wgstart.com
|
* @date: 2021年1月16日
|
* @Description: 系统生成的日志管理
|
* @Copyright: 2019-2021 wgcloud. All rights reserved.
|
*/
|
@Controller
|
@RequestMapping("/log")
|
public class LogInfoController {
|
|
|
private static final Logger logger = LoggerFactory.getLogger(LogInfoController.class);
|
|
@Resource
|
private LogInfoService logInfoService;
|
@Autowired
|
private TokenUtils tokenUtils;
|
|
/**
|
* agent获取系统日志信息列表
|
*
|
* @param model
|
* @param request
|
* @return
|
*/
|
@ResponseBody
|
@RequestMapping(value = "agentList")
|
public String agentList(@RequestBody String paramBean) {
|
JSONObject agentJsonObject = (JSONObject) JSONUtil.parse(paramBean);
|
if (!tokenUtils.checkAgentToken(agentJsonObject)) {
|
logger.error(StaticKeys.TOKEN_ERROR);
|
return ResDataUtils.resetErrorJson(StaticKeys.TOKEN_ERROR);
|
}
|
Map<String, Object> params = new HashMap<String, Object>();
|
try {
|
if (null != agentJsonObject.get("hostname") && !StringUtils.isEmpty(agentJsonObject.get("hostname").toString())) {
|
params.put("hostname", agentJsonObject.get("hostname").toString().trim());
|
}
|
if (null != agentJsonObject.get("startTime")) {
|
params.put("startTime", agentJsonObject.get("startTime").toString().trim());
|
}
|
if (null != agentJsonObject.get("endTime")) {
|
params.put("endTime", agentJsonObject.get("endTime").toString().trim());
|
}
|
if (null != agentJsonObject.get("state")) {
|
params.put("state", agentJsonObject.get("state").toString().trim());
|
}
|
PageInfo logInfoList = logInfoService.selectByParams(params, agentJsonObject.getInt("page"), agentJsonObject.getInt("pageSize"));
|
return ResDataUtils.resetSuccessJson(logInfoList);
|
} catch (Exception e) {
|
logger.error("agent获取系统日志信息列表错误", e);
|
logInfoService.save("agent获取系统日志信息列表错误", e.toString(), StaticKeys.LOG_XTCZ);
|
return ResDataUtils.resetErrorJson(e.toString());
|
}
|
}
|
|
/**
|
* 根据条件查询日志信息列表
|
*
|
* @param model
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = "list")
|
public String LogInfoList(LogInfo logInfo, Model model, HttpServletRequest request) {
|
Map<String, Object> params = new HashMap<String, Object>();
|
try {
|
StringBuffer url = new StringBuffer();
|
String startTime = request.getParameter("startTime");
|
String endTime = request.getParameter("endTime");
|
String hostname = null;
|
if (!StringUtils.isEmpty(logInfo.getHostname())) {
|
hostname = logInfo.getHostname();
|
params.put("hostname", hostname.trim());
|
url.append("&hostname=").append(hostname);
|
}
|
if (!StringUtils.isEmpty(startTime)) {
|
params.put("startTime", startTime + " 00:00:00");
|
url.append("&startTime=").append(startTime);
|
model.addAttribute("startTime", startTime);
|
}
|
if (!StringUtils.isEmpty(endTime)) {
|
params.put("endTime", endTime + " 23:59:59");
|
url.append("&endTime=").append(endTime);
|
model.addAttribute("endTime", endTime);
|
}
|
if (!StringUtils.isEmpty(logInfo.getState())) {
|
params.put("state", logInfo.getState());
|
url.append("&state=").append(logInfo.getState());
|
}
|
PageInfo pageInfo = logInfoService.selectByParams(params, logInfo.getPage(), logInfo.getPageSize());
|
PageUtil.initPageNumber(pageInfo, model);
|
|
model.addAttribute("pageUrl", "/log/list?1=1" + url.toString());
|
model.addAttribute("page", pageInfo);
|
model.addAttribute("logInfo", logInfo);
|
} catch (Exception e) {
|
logger.error("查询日志列表错误", e);
|
}
|
return "log/list";
|
}
|
|
/**
|
* 查看日志信息
|
*
|
* @param LogInfo
|
* @param model
|
* @param request
|
* @return
|
*/
|
@RequestMapping(value = "view")
|
public String viewLogInfo(Model model, HttpServletRequest request) {
|
String id = request.getParameter("id");
|
LogInfo logInfo;
|
try {
|
logInfo = logInfoService.selectById(id);
|
model.addAttribute("logInfo", logInfo);
|
} catch (Exception e) {
|
logger.error("查看日志信息错误", e);
|
}
|
return "log/view";
|
}
|
|
}
|