Browse Source

飞书代码2

cgp 1 day ago
parent
commit
d2b0608d9c

+ 46 - 34
fs-company/src/main/java/com/fs/company/controller/course/FeiShuCourseController.java

@@ -2,12 +2,12 @@ package com.fs.company.controller.course;
 
 
 import com.fs.common.core.controller.BaseController;
-import com.fs.common.core.domain.R;
+import com.fs.common.core.domain.AjaxResult;
 import com.fs.common.exception.CustomException;
-import com.fs.common.utils.StringUtils;
-import com.fs.feishu.model.FeishuLinkParam;
+import com.fs.company.domain.CompanyUser;
 import com.fs.feishu.service.FeiShuService;
-import com.fs.system.service.ISysConfigService;
+import com.fs.framework.security.LoginUser;
+import com.fs.framework.security.SecurityUtils;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -23,42 +23,54 @@ public class FeiShuCourseController extends BaseController {
 
     @Autowired
     private FeiShuService feiShuService;
-
-    @Autowired
-    private ISysConfigService configService;
     @ApiOperation("生成飞书看课链接")
     @GetMapping("/getFeiShuCourseLink")
-    public R getFeiShuCourseLink(@RequestParam Long companyUserId,
-                                 @RequestParam Long videoId,
-                                 @RequestParam(required = false) Long companyId,
-                                 @RequestParam(required = false) Long courseId,
-                                 @RequestParam(required = false) Long projectId,
-                                 @RequestParam(required = false) Long id) {
-        // 读取配置判断是否启用飞书新跳转
-        Boolean enableFeishuNewLink = null;
+    public AjaxResult getFeiShuCourseLink(
+            @RequestParam(value = "videoId", required = true) Long videoId,
+            @RequestParam(value = "courseId", required = false) Long courseId,
+            @RequestParam(value = "projectId", required = false) Long projectId,
+            @RequestParam(value = "id", required = false) Long id) {
+
+        // 1. 强制必填参数校验
+        if (videoId == null) {
+            return AjaxResult.error("视频ID不能为空");
+        }
+
+        // 2. 获取当前登录企业用户信息
+        CompanyUser companyUser;
         try {
-            String json = configService.selectConfigByKey("course.config");
-            if (StringUtils.isNotBlank(json)) {
-                com.fs.course.config.CourseConfig config = cn.hutool.json.JSONUtil.toBean(json, com.fs.course.config.CourseConfig.class);
-                enableFeishuNewLink = config.getEnableFeishuNewLink();
-            }
+            companyUser = getCurrentCompanyUser();
+        } catch (CustomException e) {
+            log.warn("获取登录用户信息失败:{}", e.getMessage());
+            return AjaxResult.error(e.getMessage());
+        }
+
+        // 3. 组装用户参数
+        Long companyUserId = companyUser.getUserId();
+        Long companyId = companyUser.getCompanyId();
+
+        // 4. 调用业务层生成链接
+        try {
+            String feishuLink = feiShuService.generateRegisterLink(videoId, companyId, courseId, companyUserId, projectId, id);
+            return AjaxResult.success(feishuLink);
+        } catch (CustomException e) {
+            log.error("生成飞书看课链接业务异常:{}", e.getMessage());
+            return AjaxResult.error(e.getMessage());
         } catch (Exception e) {
-            log.warn("读取飞书跳转配置失败", e);
-            throw new CustomException("读取飞书看课配置失败");
+            log.error("生成飞书看课链接系统异常", e);
+            return AjaxResult.error("生成飞书课程链接失败,请稍后重试");
         }
+    }
 
-        if (Boolean.TRUE.equals(enableFeishuNewLink)) {
-            FeishuLinkParam param = new FeishuLinkParam();
-            param.setCompanyId(companyId);
-            param.setCompanyUserId(companyUserId);
-            param.setCourseId(courseId);
-            param.setVideoId(videoId);
-            param.setProjectId(projectId);
-            param.setId(id);
-            String link = feiShuService.getFeishuRegisterLink(param);
-            log.info("链接{}", link);
-            return R.ok().put("data", link);
+    /**
+     * 获取当前登录企业用户
+     * @return CompanyUser
+     */
+    public static CompanyUser getCurrentCompanyUser() {
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        if (loginUser == null || loginUser.getUser() == null) {
+            throw new CustomException("登录信息已过期,请重新登录");
         }
-        return R.error("未开启飞书看课,生成链接失败!");
+        return loginUser.getUser();
     }
 }

+ 2 - 2
fs-service/src/main/java/com/fs/course/service/IFsUserCourseVideoService.java

@@ -233,10 +233,10 @@ public interface IFsUserCourseVideoService
     /**
      * 更新飞书看课时长
      */
-    void feiShuUpdateWatchDurationWx(Long companyUserId, Long videoId, Long periodId, Long identifier, Long duration);
+    void feiShuUpdateWatchDurationWx(Long companyUserId, Long videoId, Long identifier, Long duration);
 
     /**
      * 飞书看课流量统计
      */
-    void getFeiShuInternetTraffic(Long identifier, Long companyUserId, Long videoId, Long periodId, String uuid, BigDecimal bufferRate);
+    void getFeiShuInternetTraffic(Long identifier, Long companyUserId, Long videoId, String uuid, BigDecimal bufferRate);
 }

+ 2 - 3
fs-service/src/main/java/com/fs/course/service/impl/FsUserCourseVideoServiceImpl.java

@@ -3649,7 +3649,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
      * 更新飞书看课时长
      */
     @Override
-    public void feiShuUpdateWatchDurationWx(Long companyUserId, Long videoId, Long periodId, Long identifier, Long duration) {
+    public void feiShuUpdateWatchDurationWx(Long companyUserId, Long videoId, Long identifier, Long duration) {
         // 获取视频总时长
         Long videoDuration = getAutoLookVideoDuration(videoId);
         if (duration > videoDuration + 10) {
@@ -3676,7 +3676,7 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public void getFeiShuInternetTraffic(Long identifier, Long companyUserId, Long videoId, Long periodId, String uuid, BigDecimal bufferRate) {
+    public void getFeiShuInternetTraffic(Long identifier, Long companyUserId, Long videoId, String uuid, BigDecimal bufferRate) {
         if (StringUtils.isBlank(uuid)) {
             return;
         }
@@ -3688,7 +3688,6 @@ public class FsUserCourseVideoServiceImpl implements IFsUserCourseVideoService
         trafficLog.setUserId(identifier);
         trafficLog.setVideoId(videoId);
         trafficLog.setCompanyUserId(companyUserId);
-        trafficLog.setPeriodId(periodId);
 
         FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
         if (video == null) {

+ 25 - 7
fs-service/src/main/java/com/fs/feishu/service/FeiShuService.java

@@ -19,6 +19,7 @@ import com.lark.oapi.service.drive.v1.model.ListFileResp;
 import com.lark.oapi.service.drive.v2.model.PatchPermissionPublicReq;
 import com.lark.oapi.service.drive.v2.model.PermissionPublic;
 import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import javax.annotation.PostConstruct;
 import java.io.UnsupportedEncodingException;
@@ -97,7 +98,7 @@ public class FeiShuService {
             String documentId = createDocument(userCourseVideo.getTitle());
 
             // 拼接新看课url
-            String url = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(), param.getCourseId(), param.getVideoId(), param.getPeriodId(), param.getProjectId(),param.getUserId(),param.getId());
+            String url = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(), param.getCourseId(), param.getVideoId(), param.getProjectId(),param.getUserId(),param.getId());
 
             // 创建iframe块
             createIframeBlock(documentId, url);
@@ -112,15 +113,33 @@ public class FeiShuService {
         }
     }
 
+    public String generateRegisterLink(Long videoId, Long companyId, Long courseId,Long companyUserId, Long projectId, Long id) {
+        // 读取配置判断是否启用飞书新跳转
+        String json = configService.selectConfigByKey("course.config");
+        if (StringUtils.isBlank(json)) {
+            throw new CustomException("飞书看课配置为空");
+        }
+        CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
+        Boolean enableFeishuNewLink = config.getEnableFeishuNewLink();
+        if (!Boolean.TRUE.equals(enableFeishuNewLink)) {
+            throw new CustomException("未开启飞书看课");
+        }
 
+        // 构建参数
+        FeishuLinkParam param = new FeishuLinkParam();
+        param.setCompanyId(companyId);
+        param.setCompanyUserId(companyUserId);
+        param.setCourseId(courseId);
+        param.setVideoId(videoId);
+        param.setProjectId(projectId);
+        param.setId(id);
+        // 调用原有方法
+        return getFeishuRegisterLink(param);
+    }
     /**
      * 复制飞书注册链接
      */
     public String getFeishuRegisterLink(FeishuLinkParam param) {
-        if (param == null || param.getCompanyUserId() == null || param.getCompanyId() == null) {
-            throw new CustomException("参数不能为空");
-        }
-
         FsUserCourseVideo userCourseVideo = videoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
         if (userCourseVideo == null) {
             throw new CustomException("视频不存在: " + param.getVideoId());
@@ -177,13 +196,12 @@ public class FeiShuService {
     /**
      * 拼接看课url(课程参数JSON方式,适配飞书iframe,双重URL编码)
      */
-    private String buildCourseNewLink(Long companyId, Long companyUserId, Long courseId, Long videoId, Long periodId, Long projectId,Long userId,Long id) {
+    private String buildCourseNewLink(Long companyId, Long companyUserId, Long courseId, Long videoId, Long projectId,Long userId,Long id) {
         String json = configService.selectConfigByKey("course.config");
         CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
 
         // 构造课程参数 JSON
         Map<String, Object> courseParam = new LinkedHashMap<>();
-        courseParam.put("periodId", periodId);
         courseParam.put("companyUserId", companyUserId);
         courseParam.put("videoId", videoId);
         courseParam.put("projectId", projectId);

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

@@ -17,6 +17,8 @@ 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;
@@ -51,6 +53,9 @@ public class CourseFsUserController extends AppBaseController {
     @Autowired
     private IFsCourseQuestionBankService questionBankService;
 
+    @Autowired
+    private FeiShuService feiShuService;
+
 
     @Login
     @ApiOperation("判断是否添加客服(是否关联销售)")
@@ -171,5 +176,11 @@ public class CourseFsUserController extends AppBaseController {
         return courseLinkService.getLinkInfo(param.getLogId());
     }
 
+    @ApiOperation("获取飞书看课新链接")
+    @PostMapping("/getFeiShuCourseNewLink")
+    public R getFeiShuCourseNewLink(@RequestBody FeishuLinkParam param) {
+        return R.ok().put("data", feiShuService.getFeishuCourseNewLink(param));
+    }
+
 
 }

+ 3 - 5
fs-user-app/src/main/java/com/fs/app/controller/course/FeiShuCourseController.java

@@ -20,7 +20,7 @@ import java.util.Map;
 
 @Api("会员-飞书看课接口")
 @RestController
-@RequestMapping("/feishu/course/h5")
+@RequestMapping("/app/course/feishu")
 public class FeiShuCourseController {
 
     @Autowired
@@ -64,12 +64,11 @@ public class FeiShuCourseController {
         Map<String, Object> params = accessCourse(param.getToken());
         Long companyUserId = (Long) params.get("companyUserId");
         Long videoId = (Long) params.get("videoId");
-        Long periodId = (Long) params.get("periodId");
         if (StringUtils.isNull(identifier)) {
             return;
         }
 
-        courseVideoService.feiShuUpdateWatchDurationWx(companyUserId, videoId, periodId, identifier, param.getDuration());
+        courseVideoService.feiShuUpdateWatchDurationWx(companyUserId, videoId, identifier, param.getDuration());
     }
 
     @ApiOperation("获取缓冲流量")
@@ -79,11 +78,10 @@ public class FeiShuCourseController {
         Map<String, Object> params = accessCourse(param.getToken());
         Long companyUserId = (Long) params.get("companyUserId");
         Long videoId = (Long) params.get("videoId");
-        Long periodId = (Long) params.get("periodId");
         if (StringUtils.isNull(identifier)) {
             return;
         }
-        courseVideoService.getFeiShuInternetTraffic(identifier, companyUserId, videoId, periodId, param.getUuId(), param.getBufferRate());
+        courseVideoService.getFeiShuInternetTraffic(identifier, companyUserId, videoId, param.getUuId(), param.getBufferRate());
     }
 
     /**