opt:关闭日志及设备反馈

This commit is contained in:
zhangzq
2025-02-09 19:09:14 +08:00
parent 1f02e53d11
commit 41c2671829
4 changed files with 188 additions and 187 deletions

View File

@@ -105,9 +105,9 @@ public class LogAspect {
log.info("[--request--][请求接口:{}][请求参数:{}]", url, params); log.info("[--request--][请求接口:{}][请求参数:{}]", url, params);
currentTime.set(System.currentTimeMillis()); currentTime.set(System.currentTimeMillis());
result = joinPoint.proceed(); result = joinPoint.proceed();
SysLog log = new SysLog("INFO", System.currentTimeMillis() - currentTime.get()); // SysLog log = new SysLog("INFO", System.currentTimeMillis() - currentTime.get());
currentTime.remove(); currentTime.remove();
logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log); // logServsice.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), joinPoint, log);
}catch (Throwable ex) { }catch (Throwable ex) {
StringBuffer errorStack = new StringBuffer(); StringBuffer errorStack = new StringBuffer();
errorStack.append("<br/>【异常堆栈:"); errorStack.append("<br/>【异常堆栈:");

View File

@@ -1,133 +1,133 @@
package org.nl.modules.logging.aspect; //package org.nl.modules.logging.aspect;
//
import cn.hutool.core.util.ObjectUtil; //import cn.hutool.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil; //import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j; //import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint; //import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint; //import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*; //import org.aspectj.lang.annotation.*;
import org.aspectj.lang.reflect.MethodSignature; //import org.aspectj.lang.reflect.MethodSignature;
import org.nl.common.utils.SecurityUtils; //import org.nl.common.utils.SecurityUtils;
import org.nl.modules.common.utils.RequestHolder; //import org.nl.modules.common.utils.RequestHolder;
import org.nl.modules.common.utils.StringUtils; //import org.nl.modules.common.utils.StringUtils;
import org.nl.modules.common.utils.ThrowableUtil; //import org.nl.modules.common.utils.ThrowableUtil;
import org.nl.modules.logging.properties.LoggingProperties; //import org.nl.modules.logging.properties.LoggingProperties;
import org.nl.system.service.logging.ISysInterfaceLogService; //import org.nl.system.service.logging.ISysInterfaceLogService;
import org.nl.system.service.logging.dao.SysInterfaceLog; //import org.nl.system.service.logging.dao.SysInterfaceLog;
import org.nl.system.service.logging.dao.SysLog; //import org.nl.system.service.logging.dao.SysLog;
import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async; //import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; //import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher; //import org.springframework.util.AntPathMatcher;
import org.springframework.web.context.request.RequestContextHolder; //import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes; //import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.support.MultipartFilter; //import org.springframework.web.multipart.support.MultipartFilter;
//
import javax.servlet.http.HttpServletRequest; //import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; //import javax.servlet.http.HttpServletResponse;
import java.lang.reflect.Method; //import java.lang.reflect.Method;
import java.util.Arrays; //import java.util.Arrays;
import java.util.List; //import java.util.List;
import java.util.Objects; //import java.util.Objects;
import java.util.stream.Collectors; //import java.util.stream.Collectors;
//
/** ///**
* @author by: zz // * @author by: zz
* @ClassName: WhiteListLogAspect // * @ClassName: WhiteListLogAspect
* @Description: 外部接口日志切面插入日志表 // * @Description: 外部接口日志切面插入日志表
* @Date: 2024/7/25 15:06 // * @Date: 2024/7/25 15:06
*/ // */
@Slf4j ////@Slf4j
@Aspect ////@Aspect
@Component ////@Component
public class WhiteListLogAspect { //public class WhiteListLogAspect {
//
@Autowired //// @Autowired
private LoggingProperties loggingProperties; // private LoggingProperties loggingProperties;
//
@Autowired // @Autowired
private ISysInterfaceLogService interfaceLogService; // private ISysInterfaceLogService interfaceLogService;
//
private AntPathMatcher pathMatcher = new AntPathMatcher(); // private AntPathMatcher pathMatcher = new AntPathMatcher();
//
@Pointcut("execution(* org.nl.wms.ext..*Service.*(..)) || @annotation(org.nl.modules.logging.annotation.InterfaceLog)") // @Pointcut("execution(* org.nl.wms.ext..*Service.*(..)) || @annotation(org.nl.modules.logging.annotation.InterfaceLog)")
public void logPointcut() { // public void logPointcut() {
// 该方法无方法体,主要为了让同类中其他方法使用此切入点 // // 该方法无方法体,主要为了让同类中其他方法使用此切入点
} // }
//
@Around("logPointcut()") // @Around("logPointcut()")
public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable { // public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
Object[] args = joinPoint.getArgs(); // Object[] args = joinPoint.getArgs();
long startTime = System.currentTimeMillis(); // long startTime = System.currentTimeMillis();
try { // try {
Object result = joinPoint.proceed(args); // Object result = joinPoint.proceed(args);
long endTime = System.currentTimeMillis(); // long endTime = System.currentTimeMillis();
long time = endTime - startTime; // long time = endTime - startTime;
MethodSignature signature = (MethodSignature) joinPoint.getSignature(); // MethodSignature signature = (MethodSignature) joinPoint.getSignature();
//黑名单接口不打印日志 // //黑名单接口不打印日志
if (!shouldLog(signature.getName())){ // if (!shouldLog(signature.getName())){
addLog(joinPoint, JSONUtil.toJsonStr(result), time); // addLog(joinPoint, JSONUtil.toJsonStr(result), time);
} // }
return result; // return result;
} catch (Exception e) { // } catch (Exception e) {
log.error("doAround日志记录异常异常信息为:", e); // log.error("doAround日志记录异常异常信息为:", e);
throw e; // throw e;
} // }
//
} // }
//
/** // /**
* 日志记录操作 // * 日志记录操作
*/ // */
public void addLog(ProceedingJoinPoint joinPoint, String outParams, long time) { // public void addLog(ProceedingJoinPoint joinPoint, String outParams, long time) {
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); // ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = null; // HttpServletRequest request = null;
if (ObjectUtil.isNotEmpty(attributes)) { // if (ObjectUtil.isNotEmpty(attributes)) {
request = attributes.getRequest(); // request = attributes.getRequest();
} // }
// 方法路径 // // 方法路径
SysInterfaceLog log = new SysInterfaceLog("INFO", time); // SysInterfaceLog log = new SysInterfaceLog("INFO", time);
String borwser = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getBrowser(request) : "定时器"; // String borwser = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getBrowser(request) : "定时器";
String ip = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getIp(request) : "定时器"; // String ip = ObjectUtil.isNotEmpty(attributes) ? StringUtils.getIp(request) : "定时器";
interfaceLogService.save(getUsername(), outParams, borwser, ip, joinPoint, log); // interfaceLogService.save(getUsername(), outParams, borwser, ip, joinPoint, log);
} // }
//
public String getUsername() { // public String getUsername() {
try { // try {
return SecurityUtils.getCurrentUsername(); // return SecurityUtils.getCurrentUsername();
} catch (Exception e) { // } catch (Exception e) {
return ""; // return "";
} // }
} // }
//
@AfterThrowing(pointcut = "logPointcut()", throwing = "e") // @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { // public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
try { // try {
SysInterfaceLog log = new SysInterfaceLog("ERROR", 0L); // SysInterfaceLog log = new SysInterfaceLog("ERROR", 0L);
log.setException_detail(ThrowableUtil.getStackTrace(e).getBytes()); // log.setException_detail(ThrowableUtil.getStackTrace(e).getBytes());
HttpServletRequest request = RequestHolder.getHttpServletRequest(); // HttpServletRequest request = RequestHolder.getHttpServletRequest();
interfaceLogService.save(getUsername(), e.toString(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); // interfaceLogService.save(getUsername(), e.toString(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log);
}catch (Exception ex){ // }catch (Exception ex){
log.error("doAround日志记录异常异常信息为:", ex); // log.error("doAround日志记录异常异常信息为:", ex);
} // }
//
} // }
//
/** // /**
* 过滤参数 // * 过滤参数
* // *
* @param args // * @param args
* @return // * @return
*/ // */
private List<Object> filterArgs(Object[] args) { // private List<Object> filterArgs(Object[] args) {
return Arrays.stream(args).filter(object -> !(object instanceof MultipartFilter) // return Arrays.stream(args).filter(object -> !(object instanceof MultipartFilter)
&& !(object instanceof HttpServletRequest) // && !(object instanceof HttpServletRequest)
&& !(object instanceof HttpServletResponse) // && !(object instanceof HttpServletResponse)
).collect(Collectors.toList()); // ).collect(Collectors.toList());
} // }
//
private boolean shouldLog(String requestURI) { // private boolean shouldLog(String requestURI) {
return loggingProperties.getIncludePaths().stream().anyMatch(pattern -> pathMatcher.match(pattern, requestURI)); // return loggingProperties.getIncludePaths().stream().anyMatch(pattern -> pathMatcher.match(pattern, requestURI));
} // }
} //}
//

View File

@@ -71,8 +71,8 @@ public class InterfaceLogServiceImpl implements InterfaceLogService {
map.put("log_dtl_info", whereJson.get("log_dtl_info")); map.put("log_dtl_info", whereJson.get("log_dtl_info"));
map.put("log_type", whereJson.get("log_type")); map.put("log_type", whereJson.get("log_type"));
map.put("method", whereJson.get("method")); map.put("method", whereJson.get("method"));
JSONObject json = WQL.getWO("QSCH_INTERFACE_LOGS").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc"); // JSONObject json = WQL.getWO("QSCH_INTERFACE_LOGS").addParamMap(map).pageQuery(WqlUtil.getHttpContext(pageable), "create_time desc");
return json; return new HashMap<>();
} }
@Override @Override

View File

@@ -1018,56 +1018,57 @@ public class AcsToWmsServiceImpl implements AcsToWmsService {
@Override @Override
public JSONObject sendDeviceStatus(JSONObject whereJson) { public JSONObject sendDeviceStatus(JSONObject whereJson) {
log.info("sendDeviceStatus--------------输入为:" + whereJson.toString());
WQLObject wo = WQLObject.getWQLObject("em_bi_devicestatus"); // log.info("sendDeviceStatus--------------输入为:" + whereJson.toString());
String device_code = whereJson.getString("device_code"); // WQLObject wo = WQLObject.getWQLObject("em_bi_devicestatus");
String device_name = whereJson.getString("device_name"); // String device_code = whereJson.getString("device_code");
String product_area = whereJson.getString("product_area"); // String device_name = whereJson.getString("device_name");
String device_type = whereJson.getString("device_type"); // String product_area = whereJson.getString("product_area");
if (StrUtil.isEmpty(device_code)) { // String device_type = whereJson.getString("device_type");
log.info("未传入设备号,输入参数为:" + whereJson.toString()); // if (StrUtil.isEmpty(device_code)) {
JSONObject result = new JSONObject(); // log.info("未传入设备号,输入参数为:" + whereJson.toString());
result.put("status", HttpStatus.OK.value()); // JSONObject result = new JSONObject();
result.put("message", "反馈成功!"); // result.put("status", HttpStatus.OK.value());
return result; // result.put("message", "反馈成功!");
} else { // return result;
JSONObject device = wo.query("device_code = '" + device_code + "'").uniqueResult(0); // } else {
if (ObjectUtil.isEmpty(device)) { // JSONObject device = wo.query("device_code = '" + device_code + "'").uniqueResult(0);
JSONObject jo = new JSONObject(); // if (ObjectUtil.isEmpty(device)) {
jo.put("device_code", device_code); // JSONObject jo = new JSONObject();
jo.put("device_name", device_name); // jo.put("device_code", device_code);
jo.put("product_area", product_area); // jo.put("device_name", device_name);
jo.put("device_type", device_type); // jo.put("product_area", product_area);
jo.put("plan", "1"); // jo.put("device_type", device_type);
jo.put("upload_flag", "1"); // jo.put("plan", "1");
if (whereJson.containsKey("mode")) { // jo.put("upload_flag", "1");
jo.put("mode", whereJson.getString("mode")); // if (whereJson.containsKey("mode")) {
jo.put("mode_update_time", DateUtil.now()); // jo.put("mode", whereJson.getString("mode"));
} // jo.put("mode_update_time", DateUtil.now());
if (whereJson.containsKey("error")) { // }
jo.put("error", whereJson.getString("error")); // if (whereJson.containsKey("error")) {
jo.put("error_msg", whereJson.getString("error_msg")); // jo.put("error", whereJson.getString("error"));
jo.put("error_update_time", DateUtil.now()); // jo.put("error_msg", whereJson.getString("error_msg"));
} // jo.put("error_update_time", DateUtil.now());
wo.insert(jo); // }
} else { // wo.insert(jo);
HashMap<String, String> map = new HashMap<>(); // } else {
if (whereJson.containsKey("mode")) { // HashMap<String, String> map = new HashMap<>();
map.put("mode", whereJson.getString("mode")); // if (whereJson.containsKey("mode")) {
map.put("mode_update_time", DateUtil.now()); // map.put("mode", whereJson.getString("mode"));
} // map.put("mode_update_time", DateUtil.now());
if (whereJson.containsKey("error")) { // }
map.put("error", whereJson.getString("error")); // if (whereJson.containsKey("error")) {
map.put("error_msg", whereJson.getString("error_msg")); // map.put("error", whereJson.getString("error"));
map.put("error_update_time", DateUtil.now()); // map.put("error_msg", whereJson.getString("error_msg"));
if ("0".equals(whereJson.getString("error"))) { // map.put("error_update_time", DateUtil.now());
map.put("is_upload", "0"); // if ("0".equals(whereJson.getString("error"))) {
map.put("upload_time", DateUtil.now()); // map.put("is_upload", "0");
} // map.put("upload_time", DateUtil.now());
} // }
wo.update(map, "device_code = '" + device_code + "'"); // }
} // wo.update(map, "device_code = '" + device_code + "'");
} // }
// }
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("status", HttpStatus.OK.value()); result.put("status", HttpStatus.OK.value());
result.put("message", "反馈成功!"); result.put("message", "反馈成功!");