|
|
@@ -21,6 +21,7 @@ import com.fs.course.mapper.FsUserCourseVideoMapper;
|
|
|
import com.fs.course.service.IFsCourseLinkService;
|
|
|
import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
|
import com.fs.course.service.IFsCourseWatchLogService;
|
|
|
+import com.fs.feishu.service.FeiShuService;
|
|
|
import com.fs.his.domain.FsUser;
|
|
|
import com.fs.his.mapper.FsUserMapper;
|
|
|
import com.fs.his.utils.LinkUtil;
|
|
|
@@ -47,6 +48,7 @@ import com.fs.system.service.ISysConfigService;
|
|
|
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.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
@@ -57,6 +59,8 @@ import java.util.*;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
+import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Service
|
|
|
@AllArgsConstructor
|
|
|
@@ -84,9 +88,13 @@ public class IpadSendServer {
|
|
|
|
|
|
private final IFsCourseLinkService linkService;
|
|
|
|
|
|
+ private final FeiShuService feiShuService;
|
|
|
+
|
|
|
private static final List<String> PROJECT_NAMES = Arrays.asList("济南联志健康", "北京存在文化","宽益堂");
|
|
|
private final LiveWatchLogMapper liveWatchLogMapper;
|
|
|
|
|
|
+ private static final String FEISHU_MINIAPP_LINK = "/pages_course/video?course=";
|
|
|
+
|
|
|
private void sendMiniProgram(BaseVo vo, QwSopCourseFinishTempSetting.Setting content, Map<String, FsCoursePlaySourceConfig> miniMap, Long companyId) {
|
|
|
// 发送参数原本的appid
|
|
|
String appid = content.getMiniprogramAppid();
|
|
|
@@ -647,7 +655,7 @@ public class IpadSendServer {
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
- public void send(QwSopCourseFinishTempSetting.Setting content, QwUser qwUser, QwSopLogs qwSopLogs, Map<String, FsCoursePlaySourceConfig> miniMap, BaseVo parentVo) {
|
|
|
+ public void send(QwSopCourseFinishTempSetting.Setting content, QwUser qwUser, QwSopLogs qwSopLogs, Map<String, FsCoursePlaySourceConfig> miniMap, BaseVo parentVo, QwSopCourseFinishTempSetting finishSetting) {
|
|
|
BaseVo vo = new BaseVo();
|
|
|
vo.setId(Long.parseLong(qwSopLogs.getId()));
|
|
|
vo.setRoom(qwSopLogs.getSendType() == 6 || qwSopLogs.getSendType() == 21);
|
|
|
@@ -715,9 +723,15 @@ public class IpadSendServer {
|
|
|
sendMiniProgram(vo, content, miniMap);
|
|
|
break;
|
|
|
case "18":
|
|
|
-// // 发送直播卡片
|
|
|
-// sendLiveMiniProgram(vo, content, miniMap);
|
|
|
- // 链接
|
|
|
+ // 飞书看课链接:发送时生成,避免拖慢 qw-task 销售定时任务
|
|
|
+ if (StringUtils.isEmpty(content.getLinkUrl())) {
|
|
|
+ generateAndSetFeishuLink(content, qwUser, qwSopLogs, finishSetting);
|
|
|
+ }
|
|
|
+ if (StringUtils.isEmpty(content.getLinkUrl())) {
|
|
|
+ content.setSendStatus(2);
|
|
|
+ content.setSendRemarks("飞书链接生成失败");
|
|
|
+ break;
|
|
|
+ }
|
|
|
sendLink(vo, content);
|
|
|
break;
|
|
|
case "19":
|
|
|
@@ -867,6 +881,104 @@ public class IpadSendServer {
|
|
|
ipadSendUtils.loginOut(user.getUid(), user.getServerId());
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 发送时生成飞书看课链接(短链 + 飞书注册授权链接)
|
|
|
+ */
|
|
|
+ private void generateAndSetFeishuLink(QwSopCourseFinishTempSetting.Setting content, QwUser qwUser,
|
|
|
+ QwSopLogs qwSopLogs, QwSopCourseFinishTempSetting finishSetting) {
|
|
|
+ try {
|
|
|
+ Long courseId = content.getCourseId() != null ? content.getCourseId()
|
|
|
+ : (finishSetting != null && finishSetting.getCourseId() != null ? finishSetting.getCourseId().longValue() : null);
|
|
|
+ Long videoId = content.getVideoId() != null ? content.getVideoId()
|
|
|
+ : (finishSetting != null && finishSetting.getVideoId() != null ? finishSetting.getVideoId().longValue() : null);
|
|
|
+ if (courseId == null || videoId == null) {
|
|
|
+ log.error("飞书链接生成失败:课程或课节为空, sopLogId={}, courseId={}, videoId={}",
|
|
|
+ qwSopLogs.getId(), courseId, videoId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (qwUser.getCompanyId() == null || qwUser.getCompanyUserId() == null) {
|
|
|
+ log.error("飞书链接生成失败:公司或销售为空, sopLogId={}, companyId={}, companyUserId={}",
|
|
|
+ qwSopLogs.getId(), qwUser.getCompanyId(), qwUser.getCompanyUserId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (qwSopLogs.getExternalId() == null) {
|
|
|
+ log.error("飞书链接生成失败:外部联系人为空, sopLogId={}", qwSopLogs.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
+ if (config == null) {
|
|
|
+ log.error("飞书链接生成失败:course.config 未配置, sopLogId={}", qwSopLogs.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Date sendTime = new Date();
|
|
|
+
|
|
|
+ Map<String, String> feiShuLinkMap = createFeiShuLinkByMiniApp(content, qwSopLogs.getCorpId(), sendTime,
|
|
|
+ courseId, videoId, qwUser.getId(), qwUser.getCompanyUserId(), qwUser.getCompanyId(),
|
|
|
+ qwSopLogs.getExternalId(), config);
|
|
|
+ String shortLink = feiShuLinkMap.get("link");
|
|
|
+ if (StringUtils.isEmpty(shortLink)) {
|
|
|
+ log.error("飞书课程短链生成失败, sopLogId={}", qwSopLogs.getId());
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ String feishuLink = feiShuService.getFeishuRegisterLink(videoId, qwUser.getCompanyId(), courseId,
|
|
|
+ qwUser.getCompanyUserId(), shortLink);
|
|
|
+ if (StringUtils.isNotEmpty(feishuLink)) {
|
|
|
+ content.setLinkUrl(feishuLink);
|
|
|
+ content.setIsBindUrl("0");
|
|
|
+ } else {
|
|
|
+ log.error("飞书注册授权链接生成失败, sopLogId={}, videoId={}, courseId={}",
|
|
|
+ qwSopLogs.getId(), videoId, courseId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("飞书链接生成异常, sopLogId={}", qwSopLogs.getId(), e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成飞书课程短链
|
|
|
+ */
|
|
|
+ private Map<String, String> createFeiShuLinkByMiniApp(QwSopCourseFinishTempSetting.Setting setting, String corpId,
|
|
|
+ Date sendTime, Long courseId, Long videoId, Long qwUserId,
|
|
|
+ Long companyUserId, Long companyId, Long externalId,
|
|
|
+ CourseConfig config) {
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(companyId);
|
|
|
+ link.setQwUserId(qwUserId);
|
|
|
+ link.setCompanyUserId(companyUserId);
|
|
|
+ link.setVideoId(videoId);
|
|
|
+ link.setCorpId(corpId);
|
|
|
+ link.setCourseId(courseId);
|
|
|
+ link.setQwExternalId(externalId);
|
|
|
+ link.setLinkType(3);
|
|
|
+
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
+ if (StringUtils.isEmpty(randomString)) {
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ } else {
|
|
|
+ link.setLink(randomString);
|
|
|
+ }
|
|
|
+ link.setCreateTime(sendTime);
|
|
|
+
|
|
|
+ FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
|
+ BeanUtils.copyProperties(link, courseMap);
|
|
|
+ String courseJson = JSON.toJSONString(courseMap);
|
|
|
+ String realLinkFull = FEISHU_MINIAPP_LINK + courseJson;
|
|
|
+ if (config != null && StringUtils.isNotEmpty(config.getRealLinkGjDomainName())) {
|
|
|
+ realLinkFull = config.getRealLinkGjDomainName() + realLinkFull;
|
|
|
+ }
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+ link.setUpdateTime(createUpdateTime(setting, sendTime, config));
|
|
|
+ linkService.insertFsCourseLink(link);
|
|
|
+
|
|
|
+ Map<String, String> result = new HashMap<>();
|
|
|
+ result.put("url", link.getRealLink());
|
|
|
+ result.put("link", link.getLink());
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @Description: 生成福袋记录
|
|
|
* @Param:
|