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);
currentTime.set(System.currentTimeMillis());
result = joinPoint.proceed();
SysLog log = new SysLog("INFO", System.currentTimeMillis() - currentTime.get());
// SysLog log = new SysLog("INFO", System.currentTimeMillis() - currentTime.get());
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) {
StringBuffer errorStack = new StringBuffer();
errorStack.append("<br/>【异常堆栈:");

View File

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

View File

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