فهرست منبع

notion提前生成缓存链接

wjj 3 روز پیش
والد
کامیت
9cd0124f93

+ 1 - 1
fs-qw-task/src/main/java/com/fs/app/task/qwTask.java

@@ -117,7 +117,7 @@ public class qwTask {
         sopLogsTaskService.selectSopUserLogsListByTime(currentTime);
     }
 
-    @Scheduled(cron = "0 5 * * * ?") // 每小时的第5分钟触发
+    @Scheduled(cron = "0 5 18 * * ?") // 每小时的第5分钟触发
     @Async
     public void selectSopUserLogsListByTimeNew() throws Exception {
         // 获取当前时间的第二天

+ 80 - 3
fs-qw-task/src/main/java/com/fs/app/taskService/impl/SopLogsTaskServiceImpl.java

@@ -37,6 +37,9 @@ import com.fs.feishu.service.FeishuDocApiService;
 import com.fs.feishu.util.FeishuErrorCode;
 import com.fs.his.domain.FsCourseReissueConfig;
 import com.fs.his.service.IFsCourseReissueConfigService;
+import com.fs.notion.dto.NotionPageRequest;
+import com.fs.notion.dto.NotionPageResponse;
+import com.fs.notion.service.INotionService;
 import com.fs.qw.domain.*;
 import com.fs.qw.mapper.QwExternalContactMapper;
 import com.fs.qw.mapper.QwUserMapper;
@@ -103,6 +106,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
     private static final String miniappRealLink = "/pages_course/video.html?course=";
     private static final String appRealLink = "/pages/courseAnswer/index?link=";
     private static final String appLink = "https://jump.ylrztop.com/jumpapp/pages/index/index?link=";
+    private static final String notionLink = "https://notion.hcdyfa.top/pages_course/videoDetail?logId=";
 //    private static final String miniappRealLink = "/pages/index/index?course=";
 
     private static final String QWSOP_KEY_PREFIX = "qwsop:";
@@ -247,6 +251,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
     private FeishuClientPool clientPool;
     @Autowired
     private FsUserCourseVideoMapper fsUserCourseVideoMapper;
+    @Autowired
+    private INotionService notionService;
 
 
     @PostConstruct
@@ -1653,6 +1659,25 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                     setting.setMiniprogramPage(phoneLinkBy);
                     setting.setContentType("17");
                     break;
+                case "19" :
+                    Long notionWatchLogId = addNotionWatchLog(sopLogs.getSopId(), videoId, courseId,
+                            sopLogs.getFsUserId(), qwUserId, companyUserId, companyId,
+                            Long.valueOf(externalId), sopLogs.getSendTime(), logVo.getStartTime());
+                    createNotionH5Link(setting, sopLogs.getCorpId(), new Date(), courseId, videoId, qwUserId, companyUserId, companyId, Long.valueOf(externalId), config);
+                    String url = redisCache.getCacheObject("notion_course:" + videoId + "_" + externalId + "_" + qwUserId);
+                    if (StringUtils.isNotEmpty(url)) {
+                        log.info("notion缓存命中");
+                    }
+                    if (StringUtils.isEmpty(url)) {
+                        log.info("未命中notion缓存");
+                        NotionPageRequest request = new NotionPageRequest();
+                        request.setTitle(setting.getLinkDescribe());
+                        request.setIframeUrl(notionLink + notionWatchLogId);
+                        NotionPageResponse page = notionService.createPage(request);
+                        url = page.getPublicUrl();
+                    }
+                    setting.setLinkUrl(url);
+                    break;
 
                 case "18" :
                 case "20" :
@@ -1750,7 +1775,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
             log.error("Cloned content settings are empty, skipping.");
             return;
         }
-        FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
+
 
         // 顺序处理每个 Setting,避免过多的并行导致线程开销
         for (QwSopTempSetting.Content.Setting setting : settings) {
@@ -1762,6 +1787,7 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
             switch (setting.getContentType()) {
 
                 case "18" :
+                    FsUserCourseVideo video = fsUserCourseVideoMapper.selectFsUserCourseVideoByVideoId(videoId);
                     //飞书看课链接
                     Long companyIdLong = Long.parseLong(companyId);
                     Long companyUserIdLong = Long.parseLong(companyUserId);
@@ -1778,8 +1804,14 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
                     }
                     break;
                 case "19" :
-                    sopLogs.setContentJson(JSON.toJSONString(clonedContent));
-                    enqueueQwSopLogs(sopLogs);
+                    Long notionWatchLogId = addNotionWatchLog(sopLogs.getSopId(), videoId, courseId,
+                            sopLogs.getFsUserId(), qwUserId, companyUserId, companyId,
+                            Long.valueOf(externalId), sopLogs.getSendTime(), logVo.getStartTime());
+                    NotionPageRequest request = new NotionPageRequest();
+                    request.setTitle(setting.getLinkDescribe());
+                    request.setIframeUrl(notionLink + notionWatchLogId);
+                    NotionPageResponse page = notionService.createPage(request);
+                    redisCache.setCacheObject("notion_course:"+videoId+"_"+externalId+"_"+qwUserId,page.getPublicUrl(),3,TimeUnit.DAYS);
                     break;
                 default:
                     break;
@@ -3157,6 +3189,51 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
         return link.getRealLink();
     }
 
+    private void createNotionH5Link(QwSopTempSetting.Content.Setting setting, String corpId, Date sendTime,
+                                    Long courseId, Long videoId, String qwUserId,
+                                    String companyUserId, String companyId, Long externalId, CourseConfig config){
+        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 = REAL_LINK_PREFIX + courseJson;
+
+        link.setRealLink(realLinkFull);
+        link.setUpdateTime(createUpdateTime(setting, sendTime, config));
+        fsCourseLinkMapper.insertFsCourseLink(link);
+    }
+
+    private Long addNotionWatchLog(String sopId, Long videoId, Long courseId,
+                                   Long fsUserId, String qwUserId, String companyUserId,
+                                   String companyId, Long externalId, String startTime,String createTime) {
+        try {
+            FsCourseWatchLog watchLog = new FsCourseWatchLog();
+            watchLog.setVideoId(videoId);
+            watchLog.setQwExternalContactId(externalId);
+            watchLog.setSendType(2);
+            watchLog.setQwUserId(Long.valueOf(qwUserId));
+            watchLog.setSopId(sopId);
+            watchLog.setDuration(0L);
+            watchLog.setCourseId(courseId);
+            watchLog.setCompanyUserId(companyUserId != null ? Long.valueOf(companyUserId) : null);
+            watchLog.setCompanyId(companyId != null ? Long.valueOf(companyId) : null);
+            watchLog.setCreateTime(convertStringToDate(startTime,"yyyy-MM-dd HH:mm:ss"));
+            watchLog.setUpdateTime(new Date());
+            watchLog.setLogType(3);
+            watchLog.setUserId(fsUserId);
+            watchLog.setCampPeriodTime(convertStringToDate(createTime,"yyyy-MM-dd HH:mm:ss"));
+
+            //存看课记录
+            fsCourseWatchLogMapper.insertOrUpdateFsCourseWatchLog(watchLog);
+            return watchLog.getLogId();
+        }catch (Exception e){
+            log.error("一键群发失败-插入观看记录失败:"+e.getMessage());
+        }
+        return null;
+    }
+
     public String createShareMaterialLinkByMiniApp(QwSopTempSetting.Content.Setting st, QwSopLogs sopLogs, String corpId, Date sendTime, Long courseId, Long videoId, String qwUserId, String companyUserId, String companyId, CourseConfig config, String chatId) {
         FsCourseLink activityByLink = createActivityByLink(corpId, sendTime, courseId, videoId, qwUserId.toString()
                 , companyUserId, companyId, null, 3);