TRX 1 gadu atpakaļ
vecāks
revīzija
8bd69f9621

+ 0 - 1
FullCardServer/src/main/java/com/zhongshu/card/server/FullCardServerApplication.java

@@ -12,7 +12,6 @@ import org.springframework.scheduling.annotation.EnableAsync;
 @SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
 @EnableApplicationClient
 @ComponentScan("com.zhongshu.card.server.core")
-@EnableAsync
 public class FullCardServerApplication extends ApplicationBootSuper {
 
 	public static void main(String[] args) {

+ 14 - 19
FullCardServer/src/main/java/com/zhongshu/card/server/core/service/user/OperationLogsService.java

@@ -24,6 +24,7 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Service;
 
 import java.util.Date;
+import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -42,27 +43,21 @@ public class OperationLogsService extends SuperService {
     // 保存60天
     private static Long ttlTime = 60 * 24 * 60 * 60 * 1000L;
 
-    @Async
     public void addLog(OperationLogsAddParam param) {
-        try {
-            log.error("开始等待");
-            TimeUnit.SECONDS.sleep(5);
-            log.error("结束...............");
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-        OperationLogs logs = new OperationLogs();
-        BeanUtils.copyProperties(param, logs);
-        logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
-        logs.setTtl(new Date(System.currentTimeMillis() + ttlTime));
-        if (StringUtils.isNotEmpty(param.getUid())) {
-            UserAccount userAccount = userDao.findTopByUserId(param.getUid());
-            if (ObjectUtils.isNotEmpty(userAccount)) {
-                logs.setUserName(userAccount.getName());
-                logs.setLoginName(userAccount.getLoginName());
+        CompletableFuture.runAsync(() -> {
+            OperationLogs logs = new OperationLogs();
+            BeanUtils.copyProperties(param, logs);
+            logs.setTime(DateUtils.paresTime(System.currentTimeMillis(), DateUtils.FORMAT_LONG));
+            logs.setTtl(new Date(System.currentTimeMillis() + ttlTime));
+            if (StringUtils.isNotEmpty(param.getUid())) {
+                UserAccount userAccount = userDao.findTopByUserId(param.getUid());
+                if (ObjectUtils.isNotEmpty(userAccount)) {
+                    logs.setUserName(userAccount.getName());
+                    logs.setLoginName(userAccount.getLoginName());
+                }
             }
-        }
-        operationLogsDao.save(logs);
+            operationLogsDao.save(logs);
+        });
     }
 
     public ResultContent addLogs(String content, LogsLevel level) {