Browse Source

刷新token增加多线程

yumeng 4 years ago
parent
commit
d2a43faed0

+ 11 - 15
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/TestController.java

@@ -82,8 +82,8 @@ public class TestController {
     private IMaterialParameterService parameterService;
     @Autowired
     private IMaterialAscriptionService ascriptionService;
-   /* @Autowired
-    private IMaterialTagService tagService;*/
+    /* @Autowired
+     private IMaterialTagService tagService;*/
     @Autowired
     private IMaterialImageInfoService iMaterialImageInfoService;
     @Autowired
@@ -138,6 +138,8 @@ public class TestController {
     private IMaterialUploadService materialUploadService;
     @Autowired
     private IKuaishouProgramCreativeService kuaishouProgramCreativeService;
+    @Autowired
+    private IRefreshTokenService refreshTokenService;
 
     @Value("${xxl-job.requestUrl}")
     private String jobUrl;
@@ -244,15 +246,6 @@ public class TestController {
         list.add(10299241L);
 
 
-
-
-
-
-
-
-
-
-
         for (int i = 0; i < list.size(); i++) {
             Long accountId = list.get(i);
             CtopOauthToken token = oauthTokenService.getTokenByAccountId(accountId);
@@ -481,6 +474,12 @@ public class TestController {
         }
     }
 
+    @GetMapping("/getKuaiShouRefresh")
+    public void getKuaiShouRefresh(Long projectId) {
+
+        refreshTokenService.getKuaiShouRefresh();
+    }
+
     @GetMapping("/uploadVideo")
     public String uploadVideo(Long projectId) {
 
@@ -1617,10 +1616,8 @@ public class TestController {
     }
 
 
-
-
     @GetMapping("getMaterialListDemo")
-    public void getMaterialList(){
+    public void getMaterialList() {
 
         CtopOauthToken token = new CtopOauthToken();
         token.setAccountId(1696831659659278L);
@@ -1630,5 +1627,4 @@ public class TestController {
     }
 
 
-
 }

+ 1 - 0
module-common/src/main/java/cn/com/ctop/common/module/mapper/xml/CtopOauthTokenMapper.xml

@@ -35,6 +35,7 @@
         from ctop_oauth_token
         where media_id = #{mediaId}
         group by account_id
+        order by create_time DESC
     </select>
 
 

+ 3 - 1
module-common/src/main/java/cn/com/ctop/common/module/service/impl/CtopOauthTokenServiceImpl.java

@@ -18,6 +18,8 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.*;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 /**
  * @Description: oauth授权码
@@ -142,7 +144,7 @@ public class CtopOauthTokenServiceImpl extends ServiceImpl<CtopOauthTokenMapper,
             XxlJobHelper.log("刷新token,入參:{},token:{}", param, headers);
             String result = HttpUtils.httpPostRequest(url, param, headers);
             JSONObject resultJson = JSONObject.parseObject(result);
-            log.info("快手刷新token返回结果:{}", refreshToken);
+            log.info("快手刷新token返回结果,accountId:{},返回结果:{}", accountId, resultJson);
             if (Check.isNull(resultJson)) {
                 log.error("快手刷新token返回结果为空,accountId:{}", accountId);
                 return;

+ 10 - 3
module-common/src/main/java/cn/com/ctop/common/module/service/impl/RefreshTokenServiceImpl.java

@@ -17,6 +17,8 @@ import org.springframework.stereotype.Service;
 
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 @Slf4j
 @Service
@@ -29,6 +31,7 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
     private IOauthAgentTokenService agentTokenService;
     @Autowired
     private IOauthConfigService configService;
+    private static ExecutorService kuaishouTokenExecutorService = Executors.newFixedThreadPool(4);
 
     /**
      * 获取所有token
@@ -37,8 +40,6 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
      */
     @Override
     public void getKuaiShouRefresh() {
-
-
         List<CtopOauthToken> oauthTokens = oauthTokenMapper.selectKuaiShouTokens(CtopAdConstant.PLATFORM_TYPE_KUAISHOU);
         if (!Check.isNull(oauthTokens)) {
             Map<Long, String> configMap = configService.getConfigMapByMediaId(CtopAdConstant.PLATFORM_TYPE_KUAISHOU_INT);
@@ -47,7 +48,13 @@ public class RefreshTokenServiceImpl implements IRefreshTokenService {
                 //快手
                 if (CtopAdConstant.PLATFORM_TYPE_KUAISHOU.equals(oauthToken.getMediaId().trim())) {
                     String secret = configMap.get(oauthToken.getAppId());
-                    oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getAccessToken(), oauthToken.getRefreshToken(), oauthToken.getAppId(), secret);
+                    kuaishouTokenExecutorService.submit(new Runnable() {
+                        @Override
+                        public void run() {
+                            oauthTokenService.getKuaiShouRefreshToken(oauthToken.getAccountId(), oauthToken.getAccessToken(), oauthToken.getRefreshToken(), oauthToken.getAppId(), secret);
+
+                        }
+                    });
                 }
             }
         } else {