From 253e9b3735533c4d8c69cf5e6983d5fa1e984ae9 Mon Sep 17 00:00:00 2001
From: Junjie <DELL@qq.com>
Date: 星期五, 05 十二月 2025 12:34:41 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/common/config/AspectConfig.java | 130 ++++++++++++++++++++++++++
src/main/java/com/zy/asrs/controller/OpenController.java | 149 -----------------------------
2 files changed, 130 insertions(+), 149 deletions(-)
diff --git a/src/main/java/com/zy/asrs/controller/OpenController.java b/src/main/java/com/zy/asrs/controller/OpenController.java
index 4b2914a..730403a 100644
--- a/src/main/java/com/zy/asrs/controller/OpenController.java
+++ b/src/main/java/com/zy/asrs/controller/OpenController.java
@@ -63,22 +63,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean dispatchShuttle = shuttleDispatchUtils.dispatchShuttle(null, param.getLocNo(), param.getShuttleNo());
- apiLogService.insert(new ApiLog(
- null
- , "灏忚溅绉诲姩浠诲姟"
- , "/createMoveTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , dispatchShuttle ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (dispatchShuttle) {
return R.ok();
}
@@ -93,22 +77,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean result = commonService.createLocMoveTask(param);
- apiLogService.insert(new ApiLog(
- null
- , "绉诲簱浠诲姟"
- , "/createLocMoveTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , result ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (result) {
return R.ok();
}
@@ -123,22 +91,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean result = commonService.createInTask(param);
- apiLogService.insert(new ApiLog(
- null
- , "鍏ュ簱浠诲姟"
- , "/createInTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , result ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (result) {
return R.ok();
}
@@ -153,22 +105,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean result = commonService.createOutTask(param);
- apiLogService.insert(new ApiLog(
- null
- , "鍑哄簱浠诲姟"
- , "/createOutTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , result ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (result) {
return R.ok();
}
@@ -182,22 +118,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean completeTask = commonService.completeTask(param);
- apiLogService.insert(new ApiLog(
- null
- , "浠诲姟瀹屾垚"
- , "/completeTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , completeTask ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (completeTask) {
return R.ok();
}
@@ -211,22 +131,6 @@
return R.error("鍙傛暟涓嶈兘涓虹┖");
}
boolean completeTask = commonService.cancelTask(param);
- apiLogService.insert(new ApiLog(
- null
- , "浠诲姟鍙栨秷"
- , "/cancelTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , completeTask ? 1 : 0
- , 1
- , new Date()
- , null
- , null
- ));
if (completeTask) {
return R.ok();
}
@@ -355,24 +259,6 @@
@OpenApiLog(memo = "灏忚溅闆嗗悎")
public R shuttleGather(@RequestBody ShuttleGatherParam param) {
List<ShuttleGatherResult> shuttleGather = shuttleDispatchUtils.shuttleGather(param);
-
- apiLogService.insert(new ApiLog(
- null
- , "灏忚溅闆嗗悎"
- , "/shuttleGather"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , JSON.toJSONString(shuttleGather)
- , null
- , null
- , 1
- , new Date()
- , null
- , null
- ));
-
return R.ok().add(shuttleGather);
}
@@ -380,24 +266,6 @@
@OpenApiLog(memo = "灏忚溅婕旂ず")
public R shuttleDemo(@RequestBody ShuttleDemoParam param) {
shuttleDispatchUtils.shuttleDemo(param);
-
- apiLogService.insert(new ApiLog(
- null
- , "灏忚溅婕旂ず"
- , "/shuttleDemo"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , null
- , null
- , null
- , 1
- , new Date()
- , null
- , null
- ));
-
return R.ok();
}
@@ -417,23 +285,6 @@
wrapper.eq("io_type", ioType.id);
}
List<WrkMast> wrkMasts = wrkMastService.selectList(wrapper);
- apiLogService.insert(new ApiLog(
- null
- , "鏌ヨ浠诲姟"
- , "/queryTask"
- , null
- , null
- , null
- , JSON.toJSONString(param)
- , JSON.toJSONString(wrkMasts)
- , null
- , null
- , 1
- , new Date()
- , null
- , null
- ));
-
return R.ok().add(wrkMasts);
}
diff --git a/src/main/java/com/zy/common/config/AspectConfig.java b/src/main/java/com/zy/common/config/AspectConfig.java
new file mode 100644
index 0000000..3a72029
--- /dev/null
+++ b/src/main/java/com/zy/common/config/AspectConfig.java
@@ -0,0 +1,130 @@
+package com.zy.common.config;
+
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
+import com.core.common.Cools;
+import com.core.common.R;
+import com.core.exception.CoolException;
+import com.zy.asrs.entity.ApiLog;
+import com.zy.asrs.service.ApiLogService;
+import com.zy.common.annotations.OpenApiLog;
+import lombok.extern.slf4j.Slf4j;
+import org.aspectj.lang.ProceedingJoinPoint;
+import org.aspectj.lang.annotation.Around;
+import org.aspectj.lang.annotation.Aspect;
+import org.aspectj.lang.annotation.Pointcut;
+import org.aspectj.lang.reflect.MethodSignature;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.web.context.request.RequestContextHolder;
+import org.springframework.web.context.request.ServletRequestAttributes;
+import org.springframework.web.multipart.MultipartFile;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+@Component
+@Aspect
+@Slf4j
+public class AspectConfig {
+
+ @Autowired
+ private ApiLogService apiLogService;
+
+ @Pointcut("execution(* com.zy.asrs.controller.*(..))")
+ private void webLog() {
+ }
+
+ @Around("@within(org.springframework.web.bind.annotation.RestController)" +
+ "||@within(org.springframework.stereotype.Controller)")
+ public Object after(ProceedingJoinPoint joinPoint) throws Throwable {
+ ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
+ HttpServletRequest request = requestAttributes != null ? requestAttributes.getRequest() : null;
+ long start = System.currentTimeMillis();
+ MethodSignature signature = (MethodSignature) joinPoint.getSignature();
+ Method method = signature.getMethod();
+ OpenApiLog annotation = method.isAnnotationPresent(OpenApiLog.class) ? method.getAnnotation(OpenApiLog.class) : null;
+ Object result = null;
+ Object errorResponse = null;
+ try {
+ result = joinPoint.proceed(joinPoint.getArgs());
+ if (annotation != null && !Cools.isEmpty(annotation.memo())) {
+ saveLog(joinPoint, request, result, annotation.memo());
+ }
+ return result;
+ } catch (Throwable ex) {
+ errorResponse = buildErrorResponse(ex);
+ if (annotation != null && !Cools.isEmpty(annotation.memo())) {
+ saveErrLog(joinPoint, request, errorResponse, ex, annotation.memo());
+ }
+ throw ex;
+ } finally {
+ long end = System.currentTimeMillis();
+// log.info("璇锋眰鏃ュ織鐨勬墦鍗�");
+// log.info("璇锋眰鍦板潃:{}", request != null ? Optional.ofNullable(request.getRequestURI()).orElse(null) : null);
+// log.info("璇锋眰鏂瑰紡:{}", request != null ? request.getMethod() : null);
+// log.info("璇锋眰绫绘柟娉�:{}", joinPoint.getSignature());
+// log.info("璇锋眰绫绘柟娉曞弬鏁�:{}", JSONObject.toJSONString(filterArgs(joinPoint.getArgs())));
+// log.info("璇锋眰鍝嶅簲鍙傛暟{}", JSONObject.toJSONString(result != null ? result : errorResponse));
+// log.info("鎵ц鑰楁椂:{}", end - start);
+ }
+ }
+
+ private List<Object> filterArgs(Object[] objects) {
+ return Arrays.stream(objects).filter(obj -> !(obj instanceof MultipartFile)
+ && !(obj instanceof HttpServletResponse)
+ && !(obj instanceof HttpServletRequest)).collect(Collectors.toList());
+ }
+
+ private void saveLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object result, String memo) {
+ apiLogService.insert(new ApiLog(
+ null,
+ memo,
+ request != null ? Optional.ofNullable(String.valueOf(request.getRequestURI())).orElse(null) : null,
+ null,
+ null,
+ null,
+ JSONObject.toJSONString(filterArgs(joinPoint.getArgs())),
+ JSON.toJSONString(result),
+ null,
+ 1,
+ 1,
+ new Date(),
+ null,
+ null
+ ));
+ }
+
+ private void saveErrLog(ProceedingJoinPoint joinPoint, HttpServletRequest request, Object response, Throwable ex, String memo) {
+ apiLogService.insert(new ApiLog(
+ null,
+ memo,
+ request != null ? Optional.ofNullable(String.valueOf(request.getRequestURI())).orElse(null) : null,
+ null,
+ null,
+ null,
+ JSONObject.toJSONString(filterArgs(joinPoint.getArgs())),
+ JSON.toJSONString(response),
+ String.valueOf(ex),
+ 0,
+ 1,
+ new Date(),
+ null,
+ null
+ ));
+ }
+
+ private Object buildErrorResponse(Throwable ex) {
+ if (ex instanceof CoolException) {
+ return R.parse(ex.getMessage());
+ }
+ return R.error();
+ }
+
+}
--
Gitblit v1.9.1