Bläddra i källkod

优化飞书获取课程链接的错误回显

cgp 1 vecka sedan
förälder
incheckning
901e7e79ec

+ 2 - 2
fs-admin/src/main/java/com/fs/his/task/Task.java

@@ -3419,7 +3419,7 @@ public class Task {
                 Client client = buildClient(account);
                 try {
                     String docId = docApiService.createDocument(client, video.getTitle() + "-注册");
-                    redisCache.setCacheObject("fei_shu_client:" + docId, account,30,TimeUnit.DAYS);
+                    redisCache.setCacheObject("fei_shu_client:" + docId, account);
                     return docId;
 
                 } catch (CustomException e) {
@@ -3454,7 +3454,7 @@ public class Task {
             FeishuAccount account = wrapper.getAccount();
             try {
                 String docId = docApiService.createDocument(client, video.getTitle() + "-注册");
-                redisCache.setCacheObject("fei_shu_client:" + docId, account,30,TimeUnit.DAYS);
+                redisCache.setCacheObject("fei_shu_client:" + docId, account);
                 return docId;
 
             } catch (CustomException e) {

+ 16 - 15
fs-service/src/main/java/com/fs/feishu/service/FeiShuService.java

@@ -136,10 +136,10 @@ public class FeiShuService {
                         //有视频短链+外部联系人id,需要缓存docId和account
                         if (fsCourseLink.getQwExternalId()!=null){
                             String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + videoId;
-                            redisCache.setCacheObject(docIdKey, docId,30,TimeUnit.DAYS);
+                            redisCache.setCacheObject(docIdKey, docId);
                             String accountKey = FEISHU_CLIENT+docId;
                             account.setDocumentIdFillFlag(Boolean.TRUE);//这里要记录一下文档内容已填充
-                            redisCache.setCacheObject(accountKey, account,30,TimeUnit.DAYS);
+                            redisCache.setCacheObject(accountKey, account);
                         }
                     }
                     return "https://www.feishu.cn/docx/" + docId;
@@ -184,10 +184,10 @@ public class FeiShuService {
                     if (fsCourseLink.getQwExternalId()!=null){
                         String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + videoId;
                         log.error("公共账号池 外部联系人id不为空,缓存飞书docId,key:{}",docIdKey);
-                        redisCache.setCacheObject(docIdKey, docId,30,TimeUnit.DAYS);
+                        redisCache.setCacheObject(docIdKey, docId);
                         String accountKey = FEISHU_CLIENT+docId;
                         account.setDocumentIdFillFlag(Boolean.TRUE);//这里要记录一下文档内容已填充
-                        redisCache.setCacheObject(accountKey, account,30,TimeUnit.DAYS);
+                        redisCache.setCacheObject(accountKey, account);
                     }
                 }
                 return "https://www.feishu.cn/docx/" + docId;
@@ -251,10 +251,10 @@ public class FeiShuService {
                     //有视频短链+外部联系人id,需要缓存docId和account
                     if (fsCourseLink.getQwExternalId()!=null){
                         String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + param.getVideoId();
-                        redisCache.setCacheObject(docIdKey, docId,30,TimeUnit.DAYS);//30天过期
+                        redisCache.setCacheObject(docIdKey, docId);//30天过期
                         String accountKey = FEISHU_CLIENT+docId;
                         account.setCourseFillFlag(Boolean.TRUE);//这里要记录一下课程内容已填充
-                        redisCache.setCacheObject(accountKey, account,30,TimeUnit.DAYS);;//30天过期
+                        redisCache.setCacheObject(accountKey, account);;//30天过期
                     }
                     String result = "https://www.feishu.cn/docx/" + docId;
                     redisCache.setCacheObject(courseLinkKey, result, 72, TimeUnit.HOURS);
@@ -300,10 +300,10 @@ public class FeiShuService {
                 FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(param.getLink());
                 if (fsCourseLink.getQwExternalId()!=null){
                     String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + param.getVideoId();
-                    redisCache.setCacheObject(docIdKey, docId,30,TimeUnit.DAYS);
+                    redisCache.setCacheObject(docIdKey, docId);
                     String accountKey = FEISHU_CLIENT+docId;
                     account.setCourseFillFlag(Boolean.TRUE);//这里要记录一下课程内容已填充
-                    redisCache.setCacheObject(accountKey, account,30,TimeUnit.DAYS);
+                    redisCache.setCacheObject(accountKey, account);
                 }
                 String result = "https://www.feishu.cn/docx/" + docId;
                 redisCache.setCacheObject(courseLinkKey, result, 72, TimeUnit.HOURS);
@@ -376,7 +376,7 @@ public class FeiShuService {
                     if (code == null) {
                         recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                                 param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                        return null;
+                        throw new CustomException(e.getMessage());
                     }
                     if (FeishuErrorCode.isAccountDisable(code)) {
                         disablePersonalAccount(account, e.getMessage());
@@ -386,12 +386,12 @@ public class FeiShuService {
                     } else {
                         recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                                 param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                        return null;
+                        throw new CustomException(e.getMessage());
                     }
                 } catch (Exception e) {
                     recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                             param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                    return null;
+                    throw new CustomException(e.getMessage());
                 }
             }
             log.warn("所有个人账号失败,降级到公共账号池");
@@ -417,7 +417,7 @@ public class FeiShuService {
                 if (code == null) {
                     recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                             param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                    return null;
+                    throw new CustomException(e.getMessage());
                 }
                 if (FeishuErrorCode.isAccountDisable(code)) {
                     clientPool.disableAccount(account, e.getMessage());
@@ -427,17 +427,18 @@ public class FeiShuService {
                 } else {
                     recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                             param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                    return null;
+                    throw new CustomException(e.getMessage());
                 }
             } catch (Exception e) {
                 recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                         param.getCompanyUserId(), param.getLink(), e.getMessage(), 2);
-                return null;
+                throw new CustomException(e.getMessage());
             }
         }
         recordLinkError(param.getVideoId(), param.getCompanyId(), param.getCourseId(),
                 param.getCompanyUserId(), param.getLink(), "所有公共账号不可用", 2);
-        return null;
+        log.error("所有飞书账号创建文档失败");
+        throw new CustomException("课程不存在或已过期,请联系管理员");
     }
 
     // ==================== 辅助方法 ====================