Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
xm committed Sep 30, 2021
1 parent 436ac99 commit af3b7c4
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -31,7 +30,6 @@
*
* @author xiaomalover <xiaomalover@gmail.com>
*/
@SuppressWarnings("SpringJavaAutowiredFieldsWarningInspection")
@Aspect
@Component
@Slf4j
Expand All @@ -43,14 +41,17 @@ public class SystemLogAspect {
*/
private static final ThreadLocal<Date> 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层切点,注解方式
Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down Expand Up @@ -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();

Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,4 @@ public interface IStorage {
* @return 返回url地址
*/
Result<Object> upload(MultipartFile file, String folder);

/**
* 获取文件url
* @param path 文件路径
* @return 返回url
*/
String getUrl(String path);
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,4 @@ public Result<Object> upload(MultipartFile file, String folder) {
return new ResultUtil<>().error(e.toString());
}
}

@Override
public String getUrl(String path) {
return imageDomain + path;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ public Result<Object> upload(MultipartFile file, String folder) {
}
}

@Override
public String getUrl(String path) {
return path;
}

/**
* 上传到OSS服务器 如果同名文件会覆盖服务器上的
*
Expand Down

0 comments on commit af3b7c4

Please sign in to comment.