|
@@ -1,12 +1,14 @@
|
|
|
package com.qmth.teachcloud.common.aspect;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
|
import com.qmth.teachcloud.common.bean.dto.LogArgsDto;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
import com.qmth.teachcloud.common.entity.BasicOperationLog;
|
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
import com.qmth.teachcloud.common.service.BasicOperationLogService;
|
|
|
+import com.qmth.teachcloud.common.util.ResultUtil;
|
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
import org.aspectj.lang.JoinPoint;
|
|
|
import org.aspectj.lang.ProceedingJoinPoint;
|
|
@@ -55,20 +57,33 @@ public class LogAspect {
|
|
|
@Around(value = "operationLog()")
|
|
|
public Object aroundOperationLogPoint(ProceedingJoinPoint joinPoint) throws Throwable {
|
|
|
Object res = null;
|
|
|
- long time = System.currentTimeMillis();
|
|
|
+ long beginTime = System.currentTimeMillis();
|
|
|
+ long endTime = 0;
|
|
|
+ String runStatus = "成功";
|
|
|
try {
|
|
|
res = joinPoint.proceed();
|
|
|
- time = System.currentTimeMillis() - time;
|
|
|
+ endTime = System.currentTimeMillis();
|
|
|
return res;
|
|
|
+ } catch (Exception e) {
|
|
|
+ endTime = System.currentTimeMillis();
|
|
|
+ res = "Exception: " + e.getMessage();
|
|
|
+ runStatus = "失败";
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
+ if (e instanceof ApiException) {
|
|
|
+ return ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
+ } else {
|
|
|
+ return ResultUtil.error(e.getMessage());
|
|
|
+ }
|
|
|
} finally {
|
|
|
try {
|
|
|
//方法执行完成后增加日志
|
|
|
- addOperationLog(joinPoint, res, time);
|
|
|
+ addOperationLog(joinPoint, res, endTime - beginTime,runStatus);
|
|
|
} catch (Exception e) {
|
|
|
System.out.println("LogAspect 操作失败:" + e.getMessage());
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -77,8 +92,9 @@ public class LogAspect {
|
|
|
* @param joinPoint joinPoint
|
|
|
* @param res 返回值
|
|
|
* @param time 方法执行时间
|
|
|
+ * @param runStatus 方法执行状态
|
|
|
*/
|
|
|
- private void addOperationLog(JoinPoint joinPoint, Object res, long time) {
|
|
|
+ private void addOperationLog(JoinPoint joinPoint, Object res, long time,String runStatus) {
|
|
|
SysUser requestUser = (SysUser) ServletUtil.getRequestUser();
|
|
|
String userName = requestUser.getRealName();
|
|
|
HttpServletRequest request = ServletUtil.getRequest();
|
|
@@ -97,6 +113,7 @@ public class LogAspect {
|
|
|
operationLog.setMethod(methodName);
|
|
|
operationLog.setArgs(this.getTranslateArgs(paramsName, args));
|
|
|
operationLog.setRunTime(time);
|
|
|
+ operationLog.setRunStatus(runStatus);
|
|
|
operationLog.setReturnValue(JSON.toJSONString(res));
|
|
|
operationLog.setUserId(requestUser.getId());
|
|
|
operationLog.setUserName(userName);
|
|
@@ -122,7 +139,7 @@ public class LogAspect {
|
|
|
continue;
|
|
|
}
|
|
|
LogArgsDto logArgsDto = new LogArgsDto();
|
|
|
- logArgsDto.setArg(String.valueOf(args[i]));
|
|
|
+ logArgsDto.setArg(args[i]);
|
|
|
logArgsDto.setParamName(paramsName[i]);
|
|
|
logArgsDtoList.add(logArgsDto);
|
|
|
}
|
|
@@ -142,6 +159,9 @@ public class LogAspect {
|
|
|
|
|
|
Map<Object, Object> map = new HashMap<>();
|
|
|
for (int i = 0; i < argNames.length; i++) {
|
|
|
+ if (Objects.nonNull(args[i]) && (args[i] instanceof HttpServletRequest || args[i] instanceof HttpServletResponse || args[i] instanceof CommonsMultipartFile || args[i] instanceof MultipartFile || args[i] instanceof BeanPropertyBindingResult)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
map.put(argNames[i], args[i]);
|
|
|
}
|
|
|
|