解决文件预览失败的日志记录。
This commit is contained in:
parent
228a8d5142
commit
ff32992c8d
|
|
@ -0,0 +1,47 @@
|
|||
package com.electromagnetic.industry.software.manage.aop;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class AopUtil {
|
||||
|
||||
public static String getReqArgs(Object[] args, String[] argNames) {
|
||||
String paramInfo = "";
|
||||
if (args != null && args.length > 0) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String name = argNames[i];
|
||||
Object value = args[i];
|
||||
if (value instanceof ServletRequest) {
|
||||
log.info("参数中有request");
|
||||
map.put(name, "request");
|
||||
} else if (value instanceof ServletResponse) {
|
||||
log.info("参数中有response");
|
||||
map.put(name, "response");
|
||||
} else if (value instanceof MultipartFile) {
|
||||
MultipartFile file = (MultipartFile) value;
|
||||
Map<String, Object> pars = new HashMap<>();
|
||||
pars.put("fileName", file.getOriginalFilename());
|
||||
pars.put("fileSize", file.getSize());
|
||||
map.put("file", pars);
|
||||
} else {
|
||||
map.put(name, value);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("切面异常--->{}", e.getMessage(), e);
|
||||
} finally {
|
||||
paramInfo = JSONUtil.toJsonStr(map);
|
||||
}
|
||||
}
|
||||
return paramInfo;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,12 +12,15 @@ import com.electromagnetic.industry.software.manage.service.PermissionService;
|
|||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Order(1)
|
||||
public class FilePermissionCheckAspect {
|
||||
|
||||
@Resource
|
||||
|
|
@ -28,7 +31,9 @@ public class FilePermissionCheckAspect {
|
|||
@Around("@annotation(requiredPermission)")
|
||||
public Object requirePermission(ProceedingJoinPoint joinPoint, RequiredPermission requiredPermission) throws Throwable {
|
||||
Object[] args = joinPoint.getArgs();
|
||||
|
||||
String[] argNames = ((MethodSignature) joinPoint.getSignature()).getParameterNames();
|
||||
String paramInfo = AopUtil.getReqArgs(args, argNames);
|
||||
UserThreadLocal.setReqArgs(paramInfo);
|
||||
if (args.length == 0) {
|
||||
return joinPoint.proceed();
|
||||
}
|
||||
|
|
@ -36,7 +41,6 @@ public class FilePermissionCheckAspect {
|
|||
FilePermission filePermission = requiredPermission.value();
|
||||
String userId = UserThreadLocal.getUserId();
|
||||
String id = extractId(args[0]); // 提取ID逻辑封装成方法,减少冗余代码
|
||||
|
||||
// 特殊处理 FileInfoQueryDTO
|
||||
if (args[0] instanceof FileInfoQueryDTO) {
|
||||
if (id.length() > ElectromagneticConstants.PRJ_ID_LENGTH) {
|
||||
|
|
|
|||
|
|
@ -10,20 +10,17 @@ import org.aspectj.lang.ProceedingJoinPoint;
|
|||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.aspectj.lang.reflect.MethodSignature;
|
||||
import org.junit.jupiter.api.Order;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
@Slf4j
|
||||
@Order(0)
|
||||
public class ServiceAspect {
|
||||
|
||||
/**
|
||||
|
|
@ -35,35 +32,7 @@ public class ServiceAspect {
|
|||
+ jp.getSignature().getName();
|
||||
Object[] args = jp.getArgs();
|
||||
String[] argNames = ((MethodSignature) jp.getSignature()).getParameterNames();
|
||||
String paramInfo = "";
|
||||
if (args != null && args.length > 0) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
try {
|
||||
for (int i = 0; i < args.length; i++) {
|
||||
String name = argNames[i];
|
||||
Object value = args[i];
|
||||
if (value instanceof ServletRequest) {
|
||||
log.info("参数中有request");
|
||||
map.put(name, "request");
|
||||
} else if (value instanceof ServletResponse) {
|
||||
log.info("参数中有response");
|
||||
map.put(name, "response");
|
||||
} else if (value instanceof MultipartFile) {
|
||||
MultipartFile file = (MultipartFile) value;
|
||||
Map<String, Object> pars = new HashMap<>();
|
||||
pars.put("fileName", file.getOriginalFilename());
|
||||
pars.put("fileSize", file.getSize());
|
||||
map.put("file", pars);
|
||||
} else {
|
||||
map.put(name, value);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("切面异常--->{}", e.getMessage(), e);
|
||||
} finally {
|
||||
paramInfo = JSONUtil.toJsonStr(map);
|
||||
}
|
||||
}
|
||||
String paramInfo = AopUtil.getReqArgs(args, argNames);
|
||||
log.info("请求接口开始:{},参数:{}", methodInfo, paramInfo);
|
||||
long startTime = System.currentTimeMillis();
|
||||
StopWatch stopwatch = new StopWatch();
|
||||
|
|
@ -73,15 +42,12 @@ public class ServiceAspect {
|
|||
UserThreadLocal.set(userLoginInfo);
|
||||
}
|
||||
UserThreadLocal.setReqArgs(paramInfo);
|
||||
|
||||
Object rvt = jp.proceed();
|
||||
|
||||
if (rvt instanceof ResponseEntity) {
|
||||
UserThreadLocal.setRes(ElectromagneticResultUtil.success(""));
|
||||
return rvt;
|
||||
}
|
||||
UserThreadLocal.setRes((ElectromagneticResult) rvt);
|
||||
|
||||
String returnInfo = JSONUtil.toJsonStr(rvt);
|
||||
log.info("请求接口结束:{},返回参数:{},接口耗时:{}", methodInfo, returnInfo, (System.currentTimeMillis() - startTime) + "毫秒");
|
||||
stopwatch.stop();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.electromagnetic.industry.software.manage.config;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.date.SystemClock;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
|
|
@ -137,6 +138,39 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
|
||||
UserLoginInfo user = Optional.of(UserThreadLocal.getUser()).orElse(new UserLoginInfo());
|
||||
List<AccessSuccessInfo> successInfoList = user.getSuccessInfoList();
|
||||
|
||||
if (CollUtil.isEmpty(successInfoList)) {
|
||||
ElectromagneticResult res = user.getResult();
|
||||
UserAccessLog userAccessLog = new UserAccessLog()
|
||||
.setId(IdWorker.getSnowFlakeIdString())
|
||||
.setUserId(user.getUserId())
|
||||
.setAccessStartTime(DateUtil.date(accessStartTime))
|
||||
.setAccessEndTime(DateUtil.date(accessEndTime))
|
||||
.setAccessDuration(accessEndTime - accessStartTime)
|
||||
.setAction(userOperation.value())
|
||||
.setRequestUrl(request.getRequestURL().toString())
|
||||
.setRequestIp(parseIpFromUrl(request.getRequestURL().toString()))
|
||||
.setReqArgs(reqArgs)
|
||||
.setRemoteAddr(getRealIp(request))
|
||||
.setAccessSuccess(true)
|
||||
.setCreateTime(new Date())
|
||||
.setOperationModule(userOperation.modelName().key)
|
||||
.setOperationMsg(res.getErrorMessage())
|
||||
.setDataId("")
|
||||
.setParentId("");
|
||||
|
||||
if (res != null) {
|
||||
userAccessLog.setResponse(JSONUtil.toJsonStr(res));
|
||||
if (!res.getSuccess()) {
|
||||
userAccessLog.setAccessSuccess(false);
|
||||
userAccessLog.setOperationMsg(res.getErrorMessage());
|
||||
userAccessLog.setExceptionDetail(UserThreadLocal.getUser().getExceptionDetail());
|
||||
}
|
||||
} else { // 返回为ResponseEntity,且状态为失败。
|
||||
userAccessLog.setAccessSuccess(false);
|
||||
}
|
||||
userAccessLogMapper.insert(userAccessLog);
|
||||
} else {
|
||||
for (AccessSuccessInfo accessSuccessInfo : successInfoList) {
|
||||
UserAccessLog userAccessLog = new UserAccessLog()
|
||||
.setId(IdWorker.getSnowFlakeIdString())
|
||||
|
|
@ -169,6 +203,7 @@ public class LoginInterceptor implements HandlerInterceptor {
|
|||
}
|
||||
userAccessLogMapper.insert(userAccessLog);
|
||||
}
|
||||
}
|
||||
|
||||
UserThreadLocal.remove();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1077,6 +1077,7 @@ public class EdFileInfoServiceImpl extends ServiceImpl<EdFileInfoMapper, EdFileI
|
|||
User singleUser = userMapper.getSingleUser(fileInfo.getCreatedBy());
|
||||
fileInfo.setCreatedBy(singleUser.getUserName());
|
||||
FileInfoVO fileInfoVO = BeanUtil.copyProperties(fileInfo, FileInfoVO.class);
|
||||
fileInfoVO.setFileSizeShow(EleCommonUtil.convertFileSize(fileInfoVO.getFileSize()));
|
||||
fileInfoVO.setLabels(fileTagRelationService.getFileTags(fileInfo.getFileId()));
|
||||
UserThreadLocal.setSuccessInfo(fileInfo.getParentId(), id, "查询了文件的详细信息");
|
||||
return ElectromagneticResultUtil.success(fileInfoVO);
|
||||
|
|
|
|||
Loading…
Reference in New Issue