|
|
@@ -17,6 +17,7 @@ import com.fs.company.service.ICompanyMiniappService;
|
|
|
import com.fs.course.config.CourseConfig;
|
|
|
import com.fs.course.domain.FsCourseLink;
|
|
|
import com.fs.course.domain.FsCoursePlaySourceConfig;
|
|
|
+import com.fs.course.domain.FsCourseRealLink;
|
|
|
import com.fs.course.domain.FsCourseWatchLog;
|
|
|
import com.fs.course.mapper.FsCourseLinkMapper;
|
|
|
import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
@@ -49,10 +50,12 @@ import com.fs.sop.domain.QwSopLogs;
|
|
|
import com.fs.sop.service.IQwSopLogsService;
|
|
|
import com.fs.sop.service.impl.QwSopLogsServiceImpl;
|
|
|
import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.voice.utils.StringUtil;
|
|
|
import com.lark.oapi.Client;
|
|
|
import com.fs.wxwork.dto.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
@@ -61,18 +64,19 @@ import java.net.URI;
|
|
|
import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.ZoneId;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
+import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
public class IpadSendServer {
|
|
|
private static final String notionLink = "https://notion.hcdyfa.top/pages_course/videoDetail?logId=";
|
|
|
+ private static final String feiShuMiniAppLink = "/pages_course/video?course=";
|
|
|
private static final Pattern LINK_PATTERN = Pattern.compile("link=([^&]+)");
|
|
|
private final QwUserMapper qwUserMapper;
|
|
|
private final IQwUserService qwUserService;
|
|
|
@@ -335,16 +339,16 @@ public class IpadSendServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void sendLink(BaseVo vo, QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs, Long externalId,Long qwUserId) {
|
|
|
+ public void sendLink(BaseVo vo, QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs, Long externalId,QwUser qwUser) {
|
|
|
if ("18".equals(content.getContentType())){
|
|
|
// 完善content里面的飞书注册链接
|
|
|
//completeFeishuRegisterLink(vo, content,qwSopLogs, externalId,qwUserId);
|
|
|
- completeFeishuCourseLink(vo, content,qwSopLogs, externalId,qwUserId);
|
|
|
+ completeFeishuCourseLink(vo, content,qwSopLogs, externalId,qwUser.getId());
|
|
|
}else if ("20".equals(content.getContentType())){
|
|
|
// 新飞书逻辑
|
|
|
- completeFeishuCourseLink(vo, content,qwSopLogs, externalId,qwUserId);
|
|
|
+ completeFeishuCourseLink(vo, content,qwSopLogs, externalId,qwUser.getId());
|
|
|
} else if ("19".equals(content.getContentType())){
|
|
|
- completeNotionCourseLink(vo, content,qwSopLogs, externalId,qwUserId);
|
|
|
+ completeNotionCourseLink(vo, content,qwSopLogs, externalId,qwUser);
|
|
|
}
|
|
|
|
|
|
// ---- 如果链接获取失败,则不发送 ----
|
|
|
@@ -374,25 +378,98 @@ public class IpadSendServer {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public void completeNotionCourseLink(BaseVo vo, QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs,Long externalId,Long qwUserId) {
|
|
|
+ public void completeNotionCourseLink(BaseVo vo, QwSopCourseFinishTempSetting.Setting content,QwSopLogs qwSopLogs,Long externalId,QwUser qwUser) {
|
|
|
String linkUrl = content.getLinkUrl();
|
|
|
if (StringUtils.isEmpty(linkUrl)) {
|
|
|
- Long logId = fsCourseWatchLogMapper.selectFsCourseWatchLogIdByVideoIdAndExternalIdAndQwUserId(content.getVideoId(), externalId, String.valueOf(qwUserId));
|
|
|
+ Long logId = fsCourseWatchLogMapper.selectFsCourseWatchLogIdByVideoIdAndExternalIdAndQwUserId(content.getVideoId(), externalId, String.valueOf(qwUser.getId()));
|
|
|
NotionPageRequest request = new NotionPageRequest();
|
|
|
request.setTitle(content.getLinkDescribe());
|
|
|
request.setIframeUrl(notionLink + logId);
|
|
|
NotionPageResponse page = notionService.createPage(request);
|
|
|
if (!page.isSuccess() || page.getPublicUrl() == null) {
|
|
|
- content.setSendStatus(2);
|
|
|
- content.setSendRemarks("获取Notion文档链接异常:" + page.getError());
|
|
|
- return;
|
|
|
+// content.setSendStatus(2);
|
|
|
+// content.setSendRemarks("获取Notion文档链接异常:" + page.getError());
|
|
|
+// return;
|
|
|
+ //发送失败发送飞书
|
|
|
+ //2.创建课程短链
|
|
|
+ Map<String, String> notionLinkByMiniApp = createNotionLinkByMiniApp(qwSopLogs.getCorpId(), new Date(), content.getCourseId(), content.getVideoId(),
|
|
|
+ String.valueOf(qwUser.getId()), String.valueOf(qwUser.getCompanyUserId()), String.valueOf(qwUser.getCompanyId()), externalId);
|
|
|
+ content.setLinkUrl("https://www.feishu.cn/docx/" + notionLinkByMiniApp.get("link"));
|
|
|
+ completeFeishuCourseLink(vo, content,qwSopLogs, externalId,qwUser.getId());
|
|
|
+ } else {
|
|
|
+ content.setLinkUrl(page.getPublicUrl());
|
|
|
+ redisCache.setCacheObject("notion_course:"+content.getVideoId()+"_"+externalId+"_"+qwUser.getId(),content.getLinkUrl(),3,TimeUnit.DAYS);
|
|
|
+ qwSopLogsService.updateLinkUrlInContentJson(qwSopLogs, page.getPublicUrl());
|
|
|
}
|
|
|
- content.setLinkUrl(page.getPublicUrl());
|
|
|
- redisCache.setCacheObject("notion_course:"+content.getVideoId()+"_"+externalId+"_"+qwUserId,content.getLinkUrl(),3,TimeUnit.DAYS);
|
|
|
- qwSopLogsService.updateLinkUrlInContentJson(qwSopLogs, page.getPublicUrl());
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ private Map<String, String> createNotionLinkByMiniApp(String corpId, Date sendTime,
|
|
|
+ Long courseId, Long videoId, String qwUserId,
|
|
|
+ String companyUserId, String companyId, Long externalId) {
|
|
|
+
|
|
|
+ FsCourseLink link = createFsCourseLink(corpId, sendTime, courseId, videoId, qwUserId,
|
|
|
+ companyUserId, companyId, externalId.toString(), 3);
|
|
|
+
|
|
|
+ FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
|
+ BeanUtils.copyProperties(link, courseMap);
|
|
|
+
|
|
|
+ String courseJson = JSON.toJSONString(courseMap);
|
|
|
+
|
|
|
+ String realLinkFull = feiShuMiniAppLink + courseJson;
|
|
|
+
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+
|
|
|
+ Date updateTime = createUpdateTime1(sendTime);
|
|
|
+
|
|
|
+ link.setUpdateTime(updateTime);
|
|
|
+ //存短链-
|
|
|
+ courseLinkMapper.insertFsCourseLink(link);
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
+ result.put("url", link.getRealLink());
|
|
|
+ result.put("link", link.getLink());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public FsCourseLink createFsCourseLink(String corpId, Date sendTime,Long courseId,Long videoId, String qwUserId,
|
|
|
+ String companyUserId, String companyId,String externalId,Integer type){
|
|
|
+ // 手动创建 FsCourseLink 对象,避免使用 BeanUtils.copyProperties
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(Long.parseLong(companyId));
|
|
|
+ link.setQwUserId(Long.parseLong(qwUserId));
|
|
|
+ link.setCompanyUserId(Long.parseLong(companyUserId));
|
|
|
+ link.setVideoId(videoId);
|
|
|
+ link.setCorpId(corpId);
|
|
|
+ link.setCourseId(courseId);
|
|
|
+ link.setQwExternalId(Long.parseLong(externalId));
|
|
|
+ link.setLinkType(type); //小程序
|
|
|
+
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(randomString)){
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ }else {
|
|
|
+ link.setLink(randomString);
|
|
|
+ }
|
|
|
+
|
|
|
+ link.setCreateTime(sendTime);
|
|
|
+
|
|
|
+ return link;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date createUpdateTime1(Date sendTime){
|
|
|
+
|
|
|
+ int expireDays = 3;
|
|
|
+
|
|
|
+// 使用 Java 8 时间 API 计算过期时间
|
|
|
+ LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(expireDays-1);
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
+
|
|
|
+ return Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 完善飞书课程链接
|
|
|
* */
|
|
|
@@ -757,7 +834,7 @@ public class IpadSendServer {
|
|
|
break;
|
|
|
case "3":
|
|
|
// 链接
|
|
|
- sendLink(vo, content, qwSopLogs,externalUserId,qwUser.getId());
|
|
|
+ sendLink(vo, content, qwSopLogs,externalUserId,qwUser);
|
|
|
break;
|
|
|
case "4":
|
|
|
case "10":
|
|
|
@@ -851,11 +928,11 @@ public class IpadSendServer {
|
|
|
case "18":
|
|
|
case "20":
|
|
|
// 链接
|
|
|
- sendLink(vo, content,qwSopLogs,externalUserId,qwUser.getId());
|
|
|
+ sendLink(vo, content,qwSopLogs,externalUserId,qwUser);
|
|
|
break;
|
|
|
case "19":
|
|
|
// 文档2
|
|
|
- sendLink(vo, content,qwSopLogs,externalUserId,qwUser.getId());
|
|
|
+ sendLink(vo, content,qwSopLogs,externalUserId,qwUser);
|
|
|
break;
|
|
|
case "21":
|
|
|
content.setSendStatus(0);
|