ソースを参照

优化飞书业务逻辑代码结构

cgp 1 週間 前
コミット
9dda55a13a

+ 0 - 77
fs-ipad-task/src/main/java/com/fs/app/service/IpadSendServer.java

@@ -462,83 +462,6 @@ public class IpadSendServer {
         return content;
     }
 
-    /**
-     * 完善飞书注册链接
-     * */
-    public QwSopCourseFinishTempSetting.Setting completeFeishuRegisterLink(BaseVo vo, QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs,Long externalId,Long qwUserId) {
-            //获取初始的虚拟飞书链接
-            String initUrl = content.getLinkUrl();
-        try {
-            // 1. 从虚拟飞书链接提取携带的课程短链
-            String shortLink = extractLastPathSegment(initUrl);
-            FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(shortLink);
-            Long companyId = fsCourseLink.getCompanyId();
-            Long companyUserId = fsCourseLink.getCompanyUserId();
-            Long courseId = fsCourseLink.getCourseId();
-            Long videoId = fsCourseLink.getVideoId();
-            //从缓存取出docId;account
-            String docIdKey=FEISHU_DOC_ID + externalId+ "_" + videoId;
-            String feiShuDocId = redisCache.getCacheObject(docIdKey);
-            if (StringUtils.isBlank(feiShuDocId)) {
-                log.error("未命中飞书缓存key:{}",docIdKey);
-                //如果缓存中的docId为空,则调用飞书API直接获取完整飞书链接
-                String feishuRegisterLink = feiShuService.getFeishuRegisterLink(videoId, companyId, courseId, companyUserId, shortLink);
-                content.setLinkUrl(feishuRegisterLink);
-                //更新qwSopLogs
-                qwSopLogsService.updateLinkUrlInContentJson(qwSopLogs, feishuRegisterLink);
-                return content;
-            }
-            log.error("命中飞书缓存key:{}",docIdKey);
-            //根据虚拟飞书链接组装真实飞书链接
-            String completeFeiShuLinkUrl = replaceShortLinkInUrl(initUrl, feiShuDocId);
-            String amountKey = FEISHU_CLIENT+feiShuDocId;
-            //从缓存取出account
-            FeishuAccount account = redisCache.getCacheObject(amountKey);
-
-            Client client = buildClient(account);
-
-            //更新qwSopLogs
-            qwSopLogsService.updateLinkUrlInContentJson(qwSopLogs, completeFeiShuLinkUrl);
-            content.setLinkUrl(completeFeiShuLinkUrl);
-            String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
-            // ============ 异步调用飞书API完善文档内容与文档权限 ============
-            //异步之前要做个判断,如果缓存中的文档填充标识为true,则不需要进行异步处理(因为已经填充过了)
-            if (!account.getDocumentIdFillFlag()){
-                //异步处理(同时异步更新缓存的文档填充标识为true)
-                asyncService.processFeishuDocAsync(
-                        client, feiShuDocId, authUrl,
-                        videoId, companyId, courseId,
-                        companyUserId, shortLink,
-                        account
-                );
-            }
-
-            return content;
-        }catch (Exception e){
-            log.error("ID:{}-完善飞书注册链接异常:{}", vo.getId(), e.getMessage());
-        }
-        return content;
-    }
-
-    //构造发送的飞书授权链接
-    private String buildAuthLink(Long companyId, Long companyUserId, Long courseId,
-                                 Long videoId, String shortLink) {
-        CourseConfig config = getCourseConfig();
-        Map<String, Object> authParam = new LinkedHashMap<>();
-        authParam.put("companyUserId", companyUserId);
-        authParam.put("videoId", videoId);
-        authParam.put("companyId", companyId);
-        authParam.put("courseId", courseId);
-        authParam.put("link", shortLink);
-        try {
-            String encodedJson = URLEncoder.encode(JSONUtil.toJsonStr(authParam), "UTF-8");
-            String fullUrl = config.getFeishuAuthDomain() +
-                    "/feishuAuth/pages/wxauth?course=" + encodedJson;
-            return URLEncoder.encode(fullUrl, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new CustomException("授权URL拼接失败", e);
-        }
-    }
 
     private String buildNewFeiSHuCourseLink(Long companyId, Long companyUserId, Long courseId,
                                       Long videoId, Long userId, FsCourseLink fsCourseLink,Long logId) {

+ 4 - 7
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -1678,8 +1678,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                 case "18" :
                 case "20" :
                     //飞书看课链接
-                    Long companyIdLong = Long.parseLong(companyId);
-                    Long companyUserIdLong = Long.parseLong(companyUserId);
+                    //Long companyIdLong = Long.parseLong(companyId);
+                    //Long companyUserIdLong = Long.parseLong(companyUserId);
                     Long externalIdLong = Long.parseLong(externalId);
 
                     //1.添加待看课记录
@@ -1691,12 +1691,9 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                     //课程短码
                     String shortLink = feiShuLinkMap.get("link");
 
-                    //3.调用生成飞书注册授权链接(这个是在ipad发送时取缓存的docId)
-//                    String feishuLink = feiShuService.getNewFeishuRegisterLink(videoId,companyIdLong,courseId,companyUserIdLong,shortLink);
+                    //3.组装生成飞书注册授权链接(这个是在ipad发送时取缓存的docId)
                     String feishuLink = "https://www.feishu.cn/docx/"+shortLink;
-//                    if (StringUtils.isNotEmpty(feishuLink)) {
-                        setting.setLinkUrl(feishuLink);
-//                    }
+                    setting.setLinkUrl(feishuLink);
                     break;
                 case "21"://短信看课
                     if (sopLogs.getFsUserId() != null && !Long.valueOf(0L).equals(sopLogs.getFsUserId())) {

+ 0 - 126
fs-service/src/main/java/com/fs/feishu/service/FeiShuService.java

@@ -98,113 +98,6 @@ public class FeiShuService {
         }
         return "https://www.feishu.cn/docx/"+shortLink;
     }
-    // ==================== 生成飞书注册链接 ====================
-
-    public String getFeishuRegisterLink(Long videoId, Long companyId, Long courseId,
-                                        Long companyUserId, String shortLink) {
-        CourseConfig config = getCourseConfig();
-        if (!Boolean.TRUE.equals(config.getEnableFeishuNewLink())) {
-            throw new CustomException("未开启飞书看课");
-        }
-        FsUserCourseVideo userCourseVideo = videoMapper.selectFsUserCourseVideoByVideoId(videoId);
-        if (userCourseVideo == null) {
-            throw new CustomException("视频不存在: " + videoId);
-        }
-        // 1. 尝试销售个人账号创建文档
-        List<FeishuAccount> personalAccounts = getFeishuAccountCompanyUser(companyId, companyUserId);
-        if (!personalAccounts.isEmpty()) {
-            for (FeishuAccount account : personalAccounts) {
-                if (account.getStatus() != 1) continue;
-                Client client = buildClient(account);
-                try {
-                    String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
-                    String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
-                    docApiService.createTextLinkBlock(client, docId, authUrl);
-                    docApiService.changeDocumentPermissions(client, docId);
-                    if (StringUtils.isNotBlank(shortLink)){
-                        FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(shortLink);
-                        //有视频短链+外部联系人id,需要缓存docId和account
-                        if (fsCourseLink.getQwExternalId()!=null){
-                            String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + videoId;
-                            redisCache.setCacheObject(docIdKey, docId);
-                            String accountKey = FEISHU_CLIENT+docId;
-                            account.setDocumentIdFillFlag(Boolean.TRUE);//这里要记录一下文档内容已填充
-                            redisCache.setCacheObject(accountKey, account);
-                        }
-                    }
-                    return "https://www.feishu.cn/docx/" + docId;
-                } catch (CustomException e) {
-                    Integer code = e.getCode();
-                    if (code == null) {
-                        recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                        return null;
-                    }
-                    if (FeishuErrorCode.isAccountDisable(code)) {
-                        disablePersonalAccount(account, e.getMessage());
-                        log.warn("个人账号[{}]被禁用,尝试下一个", account.getAppId());
-                    } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
-                        log.warn("个人账号[{}]可重试错误,切换下一个", account.getAppId());
-                    } else {
-                        // 业务错误或其他,记录失败并返回
-                        recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                        return null;
-                    }
-                } catch (Exception e) {
-                    recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                    return null;
-                }
-            }
-            log.warn("所有个人账号失败,降级到公共账号池");
-        }
-
-        // 2. 公共账号池
-        int retries = clientPool.getAvailableCount();
-        for (int i = 0; i < retries; i++) {
-            ClientWrapper wrapper = clientPool.getClientWrapper();
-            Client client = wrapper.getClient();
-            FeishuAccount account = wrapper.getAccount();
-            try {
-                String docId = docApiService.createDocument(client, userCourseVideo.getTitle() + "-注册");
-                String authUrl = buildAuthLink(companyId, companyUserId, courseId, videoId, shortLink);
-                docApiService.createTextLinkBlock(client, docId, authUrl);
-                docApiService.changeDocumentPermissions(client, docId);
-                if (StringUtils.isNotBlank(shortLink)){
-                    FsCourseLink fsCourseLink = courseLinkMapper.selectFsCourseLinkByLink(shortLink);
-                    //有视频短链+外部联系人id,需要缓存docId和account
-                    if (fsCourseLink.getQwExternalId()!=null){
-                        String docIdKey=FEISHU_DOC_ID + fsCourseLink.getQwExternalId()+ "_" + videoId;
-                        log.error("公共账号池 外部联系人id不为空,缓存飞书docId,key:{}",docIdKey);
-                        redisCache.setCacheObject(docIdKey, docId);
-                        String accountKey = FEISHU_CLIENT+docId;
-                        account.setDocumentIdFillFlag(Boolean.TRUE);//这里要记录一下文档内容已填充
-                        redisCache.setCacheObject(accountKey, account);
-                    }
-                }
-                return "https://www.feishu.cn/docx/" + docId;
-            } catch (CustomException e) {
-                Integer code = e.getCode();
-                if (code == null) {
-                    recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                    return null;
-                }
-                if (FeishuErrorCode.isAccountDisable(code)) {
-                    clientPool.disableAccount(account, e.getMessage());
-                    log.warn("公共账号被禁用,尝试下一个");
-                } else if (FeishuErrorCode.isRateLimit(code) || FeishuErrorCode.isInternalRetryable(code)) {
-                    log.warn("公共账号可重试错误,切换下一个");
-                } else {
-                    recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                    return null;
-                }
-            } catch (Exception e) {
-                recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, e.getMessage(), 1);
-                return null;
-            }
-        }
-        recordLinkError(videoId, companyId, courseId, companyUserId, shortLink, "所有公共账号不可用", 1);
-        return null;
-    }
-
 
 
     // ==================== 生成新版飞书课程链接(无授权流程,进入即是看课界面) ====================
@@ -520,23 +413,4 @@ public class FeiShuService {
             throw new CustomException("看课URL拼接失败", e);
         }
     }
-
-    private String buildAuthLink(Long companyId, Long companyUserId, Long courseId,
-                                 Long videoId, String shortLink) {
-        CourseConfig config = getCourseConfig();
-        Map<String, Object> authParam = new LinkedHashMap<>();
-        authParam.put("companyUserId", companyUserId);
-        authParam.put("videoId", videoId);
-        authParam.put("companyId", companyId);
-        authParam.put("courseId", courseId);
-        authParam.put("link", shortLink);
-        try {
-            String encodedJson = URLEncoder.encode(JSONUtil.toJsonStr(authParam), "UTF-8");
-            String fullUrl = config.getFeishuAuthDomain() +
-                    "/feishuAuth/pages/wxauth?course=" + encodedJson;
-            return URLEncoder.encode(fullUrl, "UTF-8");
-        } catch (UnsupportedEncodingException e) {
-            throw new CustomException("授权URL拼接失败", e);
-        }
-    }
 }

+ 1 - 1
fs-service/src/main/java/com/fs/sop/service/impl/QwSopLogsServiceImpl.java

@@ -2203,7 +2203,7 @@ public class QwSopLogsServiceImpl extends ServiceImpl<QwSopLogsMapper, QwSopLogs
                 if (setting.getContentType() != null && ("18".equals(setting.getContentType())||"20".equals(setting.getContentType()) || "19".equals(setting.getContentType()))) {
                     setting.setLinkUrl(newLinkUrl);
                     updated = true;
-                    // 不 break,更新全部飞书相关的LinkUrl
+                    //更新全部飞书相关的LinkUrl
                 }
             }
         }

+ 4 - 32
fs-service/src/main/java/com/fs/sop/service/impl/SopUserLogsInfoServiceImpl.java

@@ -204,9 +204,6 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
     @Autowired
     private ISysConfigService sysConfigService;
 
-    @Autowired
-    private FeiShuService feiShuService;
-
     @Autowired
     private INotionService notionService;
 
@@ -726,15 +723,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                                 //获取生成的课程短链码
                                 String shortCode = feishuH5Link.get("link");
 
-                                //3.调用生成飞书伪链接
-//                                String feishuLink = feiShuService.getNewFeishuRegisterLink(videoId.longValue(), companyIdLong, courseId.longValue(), companyUserIdLong,shortCode);
-//
-//                                if (StringUtils.isNotEmpty(feishuLink)) {
-//
-//                                    st.setLinkUrl(feishuLink);
-//                                } else {
-//                                    log.error("生成飞书注册链接失败,sopId={}", param.getSopId());
-//                                }
+                                //3.组装生成飞书伪链接
                                 String feishuLink = "https://www.feishu.cn/docx/"+shortCode;
                                 st.setLinkUrl(feishuLink);
                                 break;
@@ -909,15 +898,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                                 //获取生成的课程短链码
                                 String shortCode = feishuH5Link.get("link");
 
-                                //3.调用生成飞书伪链接
-//                                String feishuLink = feiShuService.getNewFeishuRegisterLink(videoId.longValue(), companyIdLong, courseId.longValue(), companyUserIdLong,shortCode);
-//
-//                                if (StringUtils.isNotEmpty(feishuLink)) {
-//
-//                                    st.setLinkUrl(feishuLink);
-//                                } else {
-//                                    log.error("生成飞书注册链接失败,sopId={}", param.getSopId());
-//                                }
+                                //3.组装生成飞书伪链接
                                 String feishuLink = "https://www.feishu.cn/docx/"+shortCode;
                                 st.setLinkUrl(feishuLink);
                                 break;
@@ -1276,15 +1257,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                             //获取生成的课程短链码
                             String shortCode = feishuH5Link.get("link");
 
-                            //3.调用生成飞书伪链接
-//                            String feishuLink = feiShuService.getNewFeishuRegisterLink(videoId.longValue(), companyIdLong, courseId.longValue(), companyUserIdLong,shortCode);
-//
-//                            if (StringUtils.isNotEmpty(feishuLink)) {
-//
-//                                st.setLinkUrl(feishuLink);
-//                            } else {
-//                                log.error("生成飞书注册链接失败,sopId={}", param.getSopId());
-//                            }
+                            //3.组装生成飞书伪链接
                             String feishuLink = "https://www.feishu.cn/docx/"+shortCode;
                             st.setLinkUrl(feishuLink);
                             break;
@@ -1983,8 +1956,7 @@ public class SopUserLogsInfoServiceImpl implements ISopUserLogsInfoService {
                     //获取生成的课程短链码
                     String shortLink = feishuH5Link.get("link");
                     log.info("课程短链接生成成功:{}", shortLink);
-                    //3.调用生成飞书伪链接
-                    //String feishuLink = feiShuService.getNewFeishuRegisterLink(videoId.longValue(), companyIdLong, courseId.longValue(), companyUserIdLong,shortLink);
+                    //3.组装生成飞书伪链接
                     String feishuLink = "https://www.feishu.cn/docx/"+shortLink;
                     if (StringUtils.isNotEmpty(feishuLink)) {
                         // 替换占位符

+ 0 - 7
fs-user-app/src/main/java/com/fs/app/controller/course/CourseFsUserController.java

@@ -2,15 +2,12 @@ package com.fs.app.controller.course;
 
 
 
-import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fs.app.annotation.UserOperationLog;
 import com.fs.app.controller.AppBaseController;
 import com.fs.common.annotation.RepeatSubmit;
 import com.fs.common.core.domain.R;
 import com.fs.common.core.domain.ResponseResult;
 import com.fs.app.annotation.Login;
-import com.fs.common.utils.StringUtils;
-import com.fs.course.dto.BatchSendCourseDTO;
 import com.fs.course.param.*;
 import com.fs.course.param.newfs.FsUserCourseAddCompanyUserParam;
 import com.fs.course.param.newfs.FsUserCourseVideoLinkParam;
@@ -18,17 +15,13 @@ import com.fs.course.param.newfs.FsUserCourseVideoUParam;
 import com.fs.course.service.*;
 import com.fs.course.vo.FsUserCourseVideoH5VO;
 import com.fs.course.vo.newfs.FsUserCourseVideoLinkDetailsVO;
-import com.fs.feishu.model.FeishuLinkParam;
 import com.fs.feishu.service.FeiShuService;
 import com.fs.his.domain.FsUser;
 import com.fs.his.enums.FsUserOperationEnum;
-import com.fs.im.dto.OpenImResponseDTO;
-import com.fs.im.service.OpenIMService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;