diff --git a/admin-server/src/main/java/com/xm/admin/common/aop/SystemLogAspect.java b/admin-server/src/main/java/com/xm/admin/common/aop/SystemLogAspect.java index 46445e8..df36f10 100644 --- a/admin-server/src/main/java/com/xm/admin/common/aop/SystemLogAspect.java +++ b/admin-server/src/main/java/com/xm/admin/common/aop/SystemLogAspect.java @@ -13,7 +13,6 @@ import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.NamedThreadLocal; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.userdetails.UserDetails; @@ -31,7 +30,6 @@ * * @author xiaomalover */ -@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection") @Aspect @Component @Slf4j @@ -43,14 +41,17 @@ public class SystemLogAspect { */ private static final ThreadLocal beginTimeThreadLocal = new NamedThreadLocal<>("ThreadLocal beginTime"); - @Autowired - private IAdminLogService logService; + private final IAdminLogService logService; - @Autowired(required = false) - private HttpServletRequest request; + private final HttpServletRequest request; - @Autowired - private IpInfoUtil ipInfoUtil; + private final IpInfoUtil ipInfoUtil; + + public SystemLogAspect(IAdminLogService logService, HttpServletRequest request, IpInfoUtil ipInfoUtil) { + this.logService = logService; + this.request = request; + this.ipInfoUtil = ipInfoUtil; + } /** * Controller层切点,注解方式 @@ -111,8 +112,8 @@ public void after(JoinPoint joinPoint) { long beginTime = beginTimeThreadLocal.get().getTime(); long endTime = System.currentTimeMillis(); //请求耗时 - Long logElapsedTime = endTime - beginTime; - log.setCostTime(logElapsedTime.intValue()); + long logElapsedTime = endTime - beginTime; + log.setCostTime((int) logElapsedTime); //调用线程保存至数据库 ThreadPoolUtil.getPool().execute(new SaveSystemLogThread(log, logService)); @@ -127,9 +128,9 @@ public void after(JoinPoint joinPoint) { */ private static class SaveSystemLogThread implements Runnable { - private AdminLog log; + private final AdminLog log; - private IAdminLogService logService; + private final IAdminLogService logService; SaveSystemLogThread(AdminLog log, IAdminLogService logService) { this.log = log; @@ -158,7 +159,7 @@ private static String getControllerMethodDescription(JoinPoint joinPoint) throws //获取相关参数 Object[] arguments = joinPoint.getArgs(); //生成类对象 - Class targetClass = Class.forName(targetName); + Class targetClass = Class.forName(targetName); //获取该类中的方法 Method[] methods = targetClass.getMethods(); @@ -168,7 +169,7 @@ private static String getControllerMethodDescription(JoinPoint joinPoint) throws if (!method.getName().equals(methodName)) { continue; } - Class[] clazzs = method.getParameterTypes(); + Class[] clazzs = method.getParameterTypes(); if (clazzs.length != arguments.length) { //比较方法中参数个数与从切点中获取的参数个数是否相同,原因是方法可以重载哦 continue; diff --git a/admin-server/src/main/java/com/xm/admin/common/utils/ImageUtil.java b/admin-server/src/main/java/com/xm/admin/common/utils/ImageUtil.java index 26ab593..dfe2223 100644 --- a/admin-server/src/main/java/com/xm/admin/common/utils/ImageUtil.java +++ b/admin-server/src/main/java/com/xm/admin/common/utils/ImageUtil.java @@ -47,7 +47,7 @@ public static void saveImageFromUrl(String imgUrl, String path) throws Exception public static boolean initDir(String dir) { File file = new File(dir); if (!file.exists() && !file.isDirectory()) { - return file.mkdir(); + return file.mkdirs(); } return true; } diff --git a/admin-server/src/main/java/com/xm/admin/module/storage/service/IStorage.java b/admin-server/src/main/java/com/xm/admin/module/storage/service/IStorage.java index c247910..1bb4bcc 100644 --- a/admin-server/src/main/java/com/xm/admin/module/storage/service/IStorage.java +++ b/admin-server/src/main/java/com/xm/admin/module/storage/service/IStorage.java @@ -12,11 +12,4 @@ public interface IStorage { * @return 返回url地址 */ Result upload(MultipartFile file, String folder); - - /** - * 获取文件url - * @param path 文件路径 - * @return 返回url - */ - String getUrl(String path); } diff --git a/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/LocalStorageImpl.java b/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/LocalStorageImpl.java index 5cba9b7..d312d5c 100644 --- a/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/LocalStorageImpl.java +++ b/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/LocalStorageImpl.java @@ -69,10 +69,4 @@ public Result upload(MultipartFile file, String folder) { return new ResultUtil<>().error(e.toString()); } } - - @Override - public String getUrl(String path) { - return imageDomain + path; - } - } diff --git a/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/aliOssStorageImpl.java b/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/aliOssStorageImpl.java index 72ff348..00c6f11 100644 --- a/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/aliOssStorageImpl.java +++ b/admin-server/src/main/java/com/xm/admin/module/storage/service/impl/aliOssStorageImpl.java @@ -69,11 +69,6 @@ public Result upload(MultipartFile file, String folder) { } } - @Override - public String getUrl(String path) { - return path; - } - /** * 上传到OSS服务器 如果同名文件会覆盖服务器上的 *