|
|
@@ -32,7 +32,7 @@ import org.springframework.stereotype.Component;
|
|
|
@Slf4j
|
|
|
public class FeiShuService {
|
|
|
|
|
|
- private final String COURSE_PATH = "/feishu/pages_course/videovip?token=%s";
|
|
|
+ private final String COURSE_PATH = "/feishu/pages_course/video?token=%s";
|
|
|
|
|
|
@Autowired
|
|
|
private FeiShuConfig feishuConfig;
|
|
|
@@ -49,40 +49,56 @@ public class FeiShuService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 复制飞书看课链接
|
|
|
+ * 001 生成飞书初始链接
|
|
|
*/
|
|
|
- public String getFeishuCourseLink(Long companyUserId, Long videoId, Long periodId) {
|
|
|
- if (companyUserId == null || videoId == null) {
|
|
|
- throw new CustomException("用户ID和视频ID不能为空");
|
|
|
+ public String getFeishuRegisterLink(Long videoId, Long companyId, Long courseId,Long companyUserId) {
|
|
|
+ // 读取配置判断是否启用飞书新跳转
|
|
|
+ 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("未开启飞书看课");
|
|
|
}
|
|
|
|
|
|
- FsUserCourseVideo userCourseVideo = videoMapper.selectFsUserCourseVideoByVideoId(videoId);
|
|
|
+ // 构建参数
|
|
|
+ FeishuLinkParam param = new FeishuLinkParam();
|
|
|
+ param.setCompanyId(companyId);
|
|
|
+ param.setCompanyUserId(companyUserId);
|
|
|
+ param.setCourseId(courseId);
|
|
|
+ param.setVideoId(videoId);
|
|
|
+
|
|
|
+ FsUserCourseVideo userCourseVideo = videoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
if (userCourseVideo == null) {
|
|
|
- throw new CustomException("视频不存在: " + videoId);
|
|
|
+ throw new CustomException("视频不存在: " + param.getVideoId());
|
|
|
}
|
|
|
|
|
|
try {
|
|
|
// 创建云文档
|
|
|
- String documentId = createDocument(userCourseVideo.getTitle());
|
|
|
-
|
|
|
- // 拼接看课url
|
|
|
- String url = buildCourseLink(companyUserId, videoId, periodId);
|
|
|
+ String documentId = createDocument(userCourseVideo.getTitle() + "-注册");
|
|
|
|
|
|
- // 创建iframe块
|
|
|
- createIframeBlock(documentId, url);
|
|
|
+ // 拼接授权url
|
|
|
+ String authUrl = buildAuthLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
|
+ param.getCourseId(), param.getVideoId());
|
|
|
|
|
|
+ // 创建关注公众号 text + link block
|
|
|
+ createTextLinkBlock(documentId, authUrl);
|
|
|
// 更新文档权限
|
|
|
changeDocumentPermissions(documentId);
|
|
|
|
|
|
// 返回飞书看课链接
|
|
|
return "https://www.feishu.cn/docx/" + documentId;
|
|
|
} catch (Exception e) {
|
|
|
- throw new CustomException("创建飞书课程链接失败: " + e.getMessage(), e);
|
|
|
+ throw new CustomException("创建飞书注册链接失败: " + e.getMessage(), e);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
- * 复制飞书看课新链接
|
|
|
+ * 002生成飞书课程链接
|
|
|
*/
|
|
|
public String getFeishuCourseNewLink(FeishuLinkParam param) {
|
|
|
if (param == null || param.getCompanyUserId() == null || param.getCompanyId() == null) {
|
|
|
@@ -98,7 +114,7 @@ public class FeiShuService {
|
|
|
String documentId = createDocument(userCourseVideo.getTitle());
|
|
|
|
|
|
// 拼接新看课url
|
|
|
- String url = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(), param.getCourseId(), param.getVideoId(),param.getUserId(),param.getId());
|
|
|
+ String url = buildCourseNewLink(param.getCompanyId(), param.getCompanyUserId(), param.getCourseId(), param.getVideoId(),param.getUserId());
|
|
|
|
|
|
// 创建iframe块
|
|
|
createIframeBlock(documentId, url);
|
|
|
@@ -113,57 +129,6 @@ public class FeiShuService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public String generateRegisterLink(Long videoId, Long companyId, Long courseId,Long companyUserId, 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.setId(id);
|
|
|
- // 调用原有方法
|
|
|
- return getFeishuRegisterLink(param);
|
|
|
- }
|
|
|
- /**
|
|
|
- * 复制飞书注册链接
|
|
|
- */
|
|
|
- public String getFeishuRegisterLink(FeishuLinkParam param) {
|
|
|
- FsUserCourseVideo userCourseVideo = videoMapper.selectFsUserCourseVideoByVideoId(param.getVideoId());
|
|
|
- if (userCourseVideo == null) {
|
|
|
- throw new CustomException("视频不存在: " + param.getVideoId());
|
|
|
- }
|
|
|
-
|
|
|
- try {
|
|
|
- // 创建云文档
|
|
|
- String documentId = createDocument(userCourseVideo.getTitle() + "-注册");
|
|
|
-
|
|
|
- // 拼接授权url
|
|
|
- String authUrl = buildAuthLink(param.getCompanyId(), param.getCompanyUserId(),
|
|
|
- param.getCourseId(), param.getVideoId(),param.getId());
|
|
|
-
|
|
|
- // 创建关注公众号 text + link block
|
|
|
- createTextLinkBlock(documentId, authUrl);
|
|
|
- // 更新文档权限
|
|
|
- changeDocumentPermissions(documentId);
|
|
|
-
|
|
|
- // 返回飞书看课链接
|
|
|
- return "https://www.feishu.cn/docx/" + documentId;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new CustomException("创建飞书注册链接失败: " + e.getMessage(), e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 创建云文档
|
|
|
@@ -178,24 +143,11 @@ public class FeiShuService {
|
|
|
return data.getDocument().getDocumentId();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 拼接看课url
|
|
|
- */
|
|
|
- private String buildCourseLink(Long companyUserId, Long videoId, Long periodId) {
|
|
|
- String json = configService.selectConfigByKey("course.config");
|
|
|
- CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
-
|
|
|
- // 生成安全令牌
|
|
|
- Long timestamp = System.currentTimeMillis() / 1000;
|
|
|
- String token = SecureTokenUtil.generateToken(companyUserId, videoId, periodId, timestamp);
|
|
|
-
|
|
|
- return config.getFeishuLinkDomainName() + String.format(COURSE_PATH, token);
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 拼接看课url(课程参数JSON方式,适配飞书iframe,双重URL编码)
|
|
|
*/
|
|
|
- private String buildCourseNewLink(Long companyId, Long companyUserId, Long courseId, Long videoId,Long userId,Long id) {
|
|
|
+ private String buildCourseNewLink(Long companyId, Long companyUserId, Long courseId, Long videoId,Long userId) {
|
|
|
String json = configService.selectConfigByKey("course.config");
|
|
|
CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
|
@@ -205,14 +157,15 @@ public class FeiShuService {
|
|
|
courseParam.put("videoId", videoId);
|
|
|
courseParam.put("companyId", companyId);
|
|
|
courseParam.put("courseId", courseId);
|
|
|
- courseParam.put("id", id);
|
|
|
+ //TODO: 查询这个用户对应的sop课程短链
|
|
|
+ courseParam.put("link", courseId);
|
|
|
String courseJson = JSONUtil.toJsonStr(courseParam);
|
|
|
try {
|
|
|
// 第一次编码:对JSON进行URL编码
|
|
|
String encodedJson = URLEncoder.encode(courseJson, "UTF-8");
|
|
|
// 拼接完整URL(userId与course参数同级)
|
|
|
String baseUrl = config.getFeishuNewLinkDomainName();
|
|
|
- String fullUrl = baseUrl + "/feishuCourse/pages_course/videovip?course=" + encodedJson + "&userId=" +userId;
|
|
|
+ String fullUrl = baseUrl + "/feishuCourse/pages_course/video?course=" + encodedJson + "&userId=" +userId;
|
|
|
// 第二次编码:对整个URL进行URL编码(适配飞书iframe创建要求)
|
|
|
return URLEncoder.encode(fullUrl, "UTF-8");
|
|
|
} catch (UnsupportedEncodingException e) {
|
|
|
@@ -223,7 +176,7 @@ public class FeiShuService {
|
|
|
/**
|
|
|
* 拼接授权url(课程参数JSON方式,适配飞书iframe,双重URL编码)
|
|
|
*/
|
|
|
- private String buildAuthLink(Long companyId, Long companyUserId, Long courseId, Long videoId,Long id) {
|
|
|
+ private String buildAuthLink(Long companyId, Long companyUserId, Long courseId, Long videoId) {
|
|
|
String json = configService.selectConfigByKey("course.config");
|
|
|
CourseConfig config = JSONUtil.toBean(json, CourseConfig.class);
|
|
|
|
|
|
@@ -232,7 +185,6 @@ public class FeiShuService {
|
|
|
authParam.put("videoId", videoId);
|
|
|
authParam.put("companyId", companyId);
|
|
|
authParam.put("courseId", courseId);
|
|
|
- authParam.put("id", id);
|
|
|
String authJson = JSONUtil.toJsonStr(authParam);
|
|
|
|
|
|
try {
|