|
@@ -1,13 +1,19 @@
|
|
package com.qmth.teachcloud.common.aspect;
|
|
package com.qmth.teachcloud.common.aspect;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
import com.qmth.teachcloud.common.annotation.OperationLogDetail;
|
|
import com.qmth.teachcloud.common.bean.dto.LogArgsDto;
|
|
import com.qmth.teachcloud.common.bean.dto.LogArgsDto;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
import com.qmth.teachcloud.common.entity.BasicOperationLog;
|
|
import com.qmth.teachcloud.common.entity.BasicOperationLog;
|
|
|
|
+import com.qmth.teachcloud.common.entity.SysPrivilege;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
import com.qmth.teachcloud.common.entity.SysUser;
|
|
|
|
+import com.qmth.teachcloud.common.enums.PrivilegeEnum;
|
|
|
|
+import com.qmth.teachcloud.common.enums.log.CustomizedOperationTypeEnum;
|
|
|
|
+import com.qmth.teachcloud.common.enums.log.OperationTypeEnum;
|
|
import com.qmth.teachcloud.common.service.BasicOperationLogService;
|
|
import com.qmth.teachcloud.common.service.BasicOperationLogService;
|
|
|
|
+import com.qmth.teachcloud.common.service.SysPrivilegeService;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ResultUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import com.qmth.teachcloud.common.util.ServletUtil;
|
|
import org.aspectj.lang.JoinPoint;
|
|
import org.aspectj.lang.JoinPoint;
|
|
@@ -36,6 +42,8 @@ import java.util.*;
|
|
public class LogAspect {
|
|
public class LogAspect {
|
|
@Resource
|
|
@Resource
|
|
private BasicOperationLogService basicOperationLogService;
|
|
private BasicOperationLogService basicOperationLogService;
|
|
|
|
+ @Resource
|
|
|
|
+ private SysPrivilegeService sysPrivilegeService;
|
|
|
|
|
|
private final static Logger log = LoggerFactory.getLogger(LogAspect.class);
|
|
private final static Logger log = LoggerFactory.getLogger(LogAspect.class);
|
|
|
|
|
|
@@ -124,10 +132,20 @@ public class LogAspect {
|
|
// 注解中的信息
|
|
// 注解中的信息
|
|
OperationLogDetail annotation = signature.getMethod().getAnnotation(OperationLogDetail.class);
|
|
OperationLogDetail annotation = signature.getMethod().getAnnotation(OperationLogDetail.class);
|
|
if (annotation != null) {
|
|
if (annotation != null) {
|
|
- operationLog.setDetail(getDetail(((MethodSignature) joinPoint.getSignature()).getParameterNames(), joinPoint.getArgs(), annotation));
|
|
|
|
|
|
+ String detail = annotation.detail();
|
|
|
|
+ if (SystemConstant.strNotNull(detail)) {
|
|
|
|
+ operationLog.setDetail(getDetail(((MethodSignature) joinPoint.getSignature()).getParameterNames(), joinPoint.getArgs(), annotation));
|
|
|
|
+ } else {
|
|
|
|
+ operationLog.setDetail(autoCreateOperationLogDetailByUrl(request.getServletPath()));
|
|
|
|
+ }
|
|
operationLog.setLevel(annotation.level());
|
|
operationLog.setLevel(annotation.level());
|
|
- operationLog.setCustomizedOperationType(annotation.customizedOperationType());
|
|
|
|
- operationLog.setOperationType(annotation.operationType());
|
|
|
|
|
|
+ CustomizedOperationTypeEnum customizedOperationType = annotation.customizedOperationType();
|
|
|
|
+ operationLog.setCustomizedOperationType(customizedOperationType);
|
|
|
|
+ OperationTypeEnum operationType = annotation.operationType();
|
|
|
|
+ if (OperationTypeEnum.UN_KNOW.equals(operationType)) {
|
|
|
|
+ operationType = customizedOperationType.getOperationType();
|
|
|
|
+ }
|
|
|
|
+ operationLog.setOperationType(operationType);
|
|
operationLog.setOperationUnit(annotation.operationUnit());
|
|
operationLog.setOperationUnit(annotation.operationUnit());
|
|
operationLog.setSystemType(annotation.system());
|
|
operationLog.setSystemType(annotation.system());
|
|
}
|
|
}
|
|
@@ -182,6 +200,34 @@ public class LogAspect {
|
|
return detail;
|
|
return detail;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * 根据权限url自动创建操作日志详情
|
|
|
|
+ *
|
|
|
|
+ * @param url url
|
|
|
|
+ * @return 操作日志详情
|
|
|
|
+ */
|
|
|
|
+ private String autoCreateOperationLogDetailByUrl(String url) {
|
|
|
|
+ String detail = "";
|
|
|
|
+ List<SysPrivilege> sysPrivilegeList = sysPrivilegeService.list(new QueryWrapper<SysPrivilege>()
|
|
|
|
+ .lambda()
|
|
|
|
+ .eq(SysPrivilege::getUrl, url)
|
|
|
|
+ .eq(SysPrivilege::getType, PrivilegeEnum.URL)
|
|
|
|
+ .orderByAsc(SysPrivilege::getId));
|
|
|
|
+ if (sysPrivilegeList.size() > 0) {
|
|
|
|
+ SysPrivilege sysPrivilege = sysPrivilegeList.get(0);
|
|
|
|
+ Long parentId = sysPrivilege.getParentId();
|
|
|
|
+ String operationName = sysPrivilege.getName();
|
|
|
|
+ String path = sysPrivilegeService.findPrivilegeUrlCatalog(parentId);
|
|
|
|
+ if (SystemConstant.strNotNull(path)) {
|
|
|
|
+ path = path.substring(0, path.length() - SystemConstant.CATALOG_LINK.length());
|
|
|
|
+ detail = path + SystemConstant.OPERATE_LINK + operationName;
|
|
|
|
+ } else {
|
|
|
|
+ detail = operationName;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return detail;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Before(value = "operationLog()")
|
|
@Before(value = "operationLog()")
|
|
public void doBeforeAdvice(JoinPoint joinPoint) {
|
|
public void doBeforeAdvice(JoinPoint joinPoint) {
|
|
System.out.println("进入方法前执行.....");
|
|
System.out.println("进入方法前执行.....");
|