diff --git a/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java b/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java index c3015a9cc..3e6437728 100644 --- a/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java +++ b/lms/nladmin-system/src/main/java/org/nl/modules/logging/aspect/LogAspect.java @@ -42,10 +42,7 @@ import org.springframework.web.bind.annotation.RequestParam; import javax.servlet.http.HttpServletRequest; import java.lang.reflect.Method; import java.lang.reflect.Parameter; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; /** * @author Zheng Jie @@ -79,6 +76,7 @@ public class LogAspect { */ @Around("logPointcut()") public Object logAround(ProceedingJoinPoint joinPoint) throws Throwable { + String trackId = UUID.randomUUID().toString(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); // 方法路径 @@ -89,54 +87,51 @@ public class LogAspect { //是否输出到日志文件 if (logInfo.isPrintToLogFile()) { - log.info("请求方法:{}", methodName); - log.info("请求方法参数:{}", params); + log.info("track_id:{},请求方法:{},请求方法参数:{}",trackId,methodName,params); } - - + HttpServletRequest request = RequestHolder.getHttpServletRequest(); + String requestIp = StringUtils.getIp(request); Object result; currentTime.set(System.currentTimeMillis()); - result = joinPoint.proceed(); - - HttpServletRequest request = RequestHolder.getHttpServletRequest(); - - String requestIp = StringUtils.getIp(request); - //是否把日志存到日志表 - if (logInfo.isAddLogTable()) { - Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get()); - currentTime.remove(); - - - logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log); - } - - - //保存到接口日志表 - if (logInfo.isInterfaceLog()) { - try { - System.out.println("日志存储到接口日志表!"); - WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log"); - JSONObject json = new JSONObject(); - json.put("log_id", IdUtil.getStringId()); - json.put("description", logInfo.value()); - json.put("log_type", logInfo.interfaceLogType().getDesc()); - json.put("log_level", "1"); - json.put("method", methodName); - json.put("params", getParameter(method, joinPoint.getArgs())); - json.put("request_ip", StringUtils.getIp(request)); - json.put("time", System.currentTimeMillis() - currentTime.get()); - json.put("username", getUsername()); - json.put("address", StringUtils.getCityInfo(requestIp)); - json.put("browser", StringUtils.getBrowser(request)); - json.put("exception_detail", IdUtil.getStringId()); - json.put("create_time", DateUtil.now()); - json.put("return_result", JSONObject.parse(result.toString())); - interfaceLog.insert(json); - } catch (Exception e) { - System.out.println("接口日志保存异常!"+e.getMessage()); + try { + result = joinPoint.proceed(); + //是否把日志存到日志表 + if (logInfo.isAddLogTable()) { + Log log = new Log("INFO", System.currentTimeMillis() - currentTime.get()); + currentTime.remove(); + logService.save(getUsername(), StringUtils.getBrowser(request), requestIp, joinPoint, log); } - } + if (logInfo.isInterfaceLog()) { + try { + WQLObject interfaceLog = WQLObject.getWQLObject("sys_interface_log"); + JSONObject json = new JSONObject(); + json.put("log_id", IdUtil.getStringId()); + json.put("description", logInfo.value()); + json.put("log_type", logInfo.interfaceLogType().getDesc()); + json.put("log_level", "1"); + json.put("method", methodName); + json.put("params", getParameter(method, joinPoint.getArgs())); + json.put("request_ip", StringUtils.getIp(request)); + json.put("time", System.currentTimeMillis() - currentTime.get()); + json.put("username", getUsername()); + json.put("address", StringUtils.getCityInfo(requestIp)); + json.put("browser", StringUtils.getBrowser(request)); + json.put("exception_detail", IdUtil.getStringId()); + json.put("create_time", DateUtil.now()); + json.put("return_result", JSONObject.parse(result.toString())); + interfaceLog.insert(json); + } catch (Exception e) { + } + } + }catch (Exception ex){ + log.error("track_id:{},error:{}",trackId,ex.getMessage()); + Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get()); + currentTime.remove(); + log.setExceptionDetail(ThrowableUtil.getStackTrace(ex).getBytes()); + logService.save(getUsername(), StringUtils.getBrowser(request), StringUtils.getIp(request), (ProceedingJoinPoint) joinPoint, log); + throw ex; + } return result; } @@ -176,7 +171,7 @@ public class LogAspect { * @param joinPoint join point for advice * @param e exception */ - @AfterThrowing(pointcut = "logPointcut()", throwing = "e") +// @AfterThrowing(pointcut = "logPointcut()", throwing = "e") public void logAfterThrowing(JoinPoint joinPoint, Throwable e) { Log log = new Log("ERROR", System.currentTimeMillis() - currentTime.get()); currentTime.remove(); diff --git a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/rest/AcsToWmsController.java b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/rest/AcsToWmsController.java index a0842abdf..3f1976b34 100644 --- a/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/rest/AcsToWmsController.java +++ b/lms/nladmin-system/src/main/java/org/nl/wms/ext/acs/rest/AcsToWmsController.java @@ -81,7 +81,7 @@ public class AcsToWmsController { } @PostMapping("/shipDeviceUpdate") - @Log(value = "输送线光电无货上报", isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) +// @Log(value = "输送线光电无货上报", isInterfaceLog = true,interfaceLogType= InterfaceLogType.ACS_TO_LMS) @ApiOperation("输送线光电无货上报") @SaIgnore public ResponseEntity shipDeviceUpdate(@RequestBody JSONObject jo) {