|
|
@@ -0,0 +1,531 @@
|
|
|
+package com.fs.his.service.impl;
|
|
|
+
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.ZoneId;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+import cn.binarywang.wx.miniapp.api.WxMaService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
+import com.fs.common.core.domain.R;
|
|
|
+import com.fs.common.core.redis.RedisCache;
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.DateUtils;
|
|
|
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
+import com.fs.config.cloud.CloudHostProper;
|
|
|
+import com.fs.core.config.WxMaConfiguration;
|
|
|
+import com.fs.course.config.CourseConfig;
|
|
|
+import com.fs.course.domain.*;
|
|
|
+import com.fs.course.mapper.FsCourseLinkMapper;
|
|
|
+import com.fs.course.mapper.FsCourseWatchLogMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoMapper;
|
|
|
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
|
|
|
+import com.fs.feishu.service.FeiShuService;
|
|
|
+import com.fs.qw.domain.QwCompany;
|
|
|
+import com.fs.qw.domain.QwExternalContact;
|
|
|
+import com.fs.qw.domain.QwUser;
|
|
|
+import com.fs.qw.service.IQwExternalContactService;
|
|
|
+import com.fs.qw.service.IQwUserService;
|
|
|
+import com.fs.qw.vo.QwSopCourseFinishTempSetting;
|
|
|
+import com.fs.sop.domain.QwSopLogs;
|
|
|
+import com.fs.sop.mapper.QwSopLogsMapper;
|
|
|
+import com.fs.system.service.ISysConfigService;
|
|
|
+import com.fs.voice.utils.StringUtil;
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+import com.fs.his.mapper.FsCourseReissueConfigMapper;
|
|
|
+import com.fs.his.domain.FsCourseReissueConfig;
|
|
|
+import com.fs.his.service.IFsCourseReissueConfigService;
|
|
|
+
|
|
|
+import static com.fs.course.utils.LinkUtil.generateRandomStringWithLock;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 补发SOP配置Service业务层处理
|
|
|
+ *
|
|
|
+ * @author fs
|
|
|
+ * @date 2026-07-16
|
|
|
+ */
|
|
|
+@Service
|
|
|
+public class FsCourseReissueConfigServiceImpl extends ServiceImpl<FsCourseReissueConfigMapper, FsCourseReissueConfig> implements IFsCourseReissueConfigService {
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(getClass());
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseReissueConfigMapper fsCourseReissueConfigMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseLinkMapper fsCourseLinkMapper;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private QwSopLogsMapper qwSopLogsMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsCourseWatchLogMapper watchLogMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwExternalContactService qwExternalContactService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IQwUserService qwUserService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseVideoMapper courseVideoMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FsUserCourseMapper userCourseMapper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CloudHostProper cloudHostProper;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private FeiShuService feiShuService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ RedisCache redisCache;
|
|
|
+
|
|
|
+
|
|
|
+ private static final String courseRealLink = "/pages_course/video.html?course=";
|
|
|
+ private static final String feiShuMiniAppLink = "/pages_course/video?course=";
|
|
|
+ /**
|
|
|
+ * 查询补发SOP配置
|
|
|
+ *
|
|
|
+ * @param id 补发SOP配置主键
|
|
|
+ * @return 补发SOP配置
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public FsCourseReissueConfig selectFsCourseReissueConfigById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsCourseReissueConfigById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FsCourseReissueConfig getInfo() {
|
|
|
+ List<FsCourseReissueConfig> fsCourseReissueConfigs = fsCourseReissueConfigMapper.selectFsCourseReissueConfigList(new FsCourseReissueConfig());
|
|
|
+ if (CollectionUtils.isEmpty(fsCourseReissueConfigs)) {
|
|
|
+ return new FsCourseReissueConfig();
|
|
|
+ } else {
|
|
|
+ return fsCourseReissueConfigs.get(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询补发SOP配置列表
|
|
|
+ *
|
|
|
+ * @param fsCourseReissueConfig 补发SOP配置
|
|
|
+ * @return 补发SOP配置
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public List<FsCourseReissueConfig> selectFsCourseReissueConfigList(FsCourseReissueConfig fsCourseReissueConfig)
|
|
|
+ {
|
|
|
+ return baseMapper.selectFsCourseReissueConfigList(fsCourseReissueConfig);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增补发SOP配置
|
|
|
+ *
|
|
|
+ * @param fsCourseReissueConfig 补发SOP配置
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int insertFsCourseReissueConfig(FsCourseReissueConfig fsCourseReissueConfig)
|
|
|
+ {
|
|
|
+ fsCourseReissueConfig.setCreateTime(DateUtils.getNowDate());
|
|
|
+ int i = baseMapper.insertFsCourseReissueConfig(fsCourseReissueConfig);
|
|
|
+ if (i > 0) {
|
|
|
+ redisCache.setCacheObject("fs_course_reissue_config:", fsCourseReissueConfig);
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改补发SOP配置
|
|
|
+ *
|
|
|
+ * @param fsCourseReissueConfig 补发SOP配置
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int updateFsCourseReissueConfig(FsCourseReissueConfig fsCourseReissueConfig)
|
|
|
+ {
|
|
|
+ fsCourseReissueConfig.setUpdateTime(DateUtils.getNowDate());
|
|
|
+ int i = baseMapper.updateFsCourseReissueConfig(fsCourseReissueConfig);
|
|
|
+ if (i > 0) {
|
|
|
+ redisCache.setCacheObject("fs_course_reissue_config:", fsCourseReissueConfig);
|
|
|
+ }
|
|
|
+ return i;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量删除补发SOP配置
|
|
|
+ *
|
|
|
+ * @param ids 需要删除的补发SOP配置主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsCourseReissueConfigByIds(Long[] ids)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsCourseReissueConfigByIds(ids);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除补发SOP配置信息
|
|
|
+ *
|
|
|
+ * @param id 补发SOP配置主键
|
|
|
+ * @return 结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public int deleteFsCourseReissueConfigById(Long id)
|
|
|
+ {
|
|
|
+ return baseMapper.deleteFsCourseReissueConfigById(id);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public R reissueCourseSop(Long configId) {
|
|
|
+ // 1.查询补发SOP配置
|
|
|
+ FsCourseReissueConfig fsCourseReissueConfig = fsCourseReissueConfigMapper.selectFsCourseReissueConfigById(configId);
|
|
|
+
|
|
|
+ if (fsCourseReissueConfig == null) {
|
|
|
+ return R.error("补发SOP配置不存在");
|
|
|
+ }
|
|
|
+ if (fsCourseReissueConfig.getStatus() == 2) {
|
|
|
+ return R.error("补发SOP配置已禁用");
|
|
|
+ }
|
|
|
+ if (fsCourseReissueConfig.getType() == 1) {
|
|
|
+ // 小程序
|
|
|
+ if ( fsCourseReissueConfig.getAppId() == null) {
|
|
|
+ return R.error("小程序APPID不能为空");
|
|
|
+ }
|
|
|
+ if (!checkAppId(fsCourseReissueConfig.getAppId())) {
|
|
|
+ return R.error("小程序已封禁");
|
|
|
+ }
|
|
|
+ //作废sopLos
|
|
|
+ qwSopLogsMapper.wasteQwSopLogs();
|
|
|
+ //小程序补发
|
|
|
+ List<FsCourseWatchLog> watchLogs = watchLogMapper.selectTodayWatchLogs(4);
|
|
|
+ if (CollectionUtils.isNotEmpty(watchLogs)) {
|
|
|
+ reissueCourse(fsCourseReissueConfig.getAppId(), fsCourseReissueConfig.getType(), watchLogs, null);
|
|
|
+ }
|
|
|
+ List<FsCourseWatchLog> waitWatchLogs = watchLogMapper.selectTodayWatchLogs(3);
|
|
|
+
|
|
|
+ if (CollectionUtils.isNotEmpty(waitWatchLogs)) {
|
|
|
+ reissueCourse(fsCourseReissueConfig.getAppId(), fsCourseReissueConfig.getType(), waitWatchLogs, null);
|
|
|
+ }
|
|
|
+ return R.ok("补发成功");
|
|
|
+ } else if (fsCourseReissueConfig.getType() == 2) {
|
|
|
+ // 飞书
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
+ List<FsCourseWatchLog> watchLogs = watchLogMapper.selectTodayWatchLogs(4);
|
|
|
+ if (CollectionUtils.isNotEmpty(watchLogs)) {
|
|
|
+ reissueCourse(null, fsCourseReissueConfig.getType(), watchLogs, config);
|
|
|
+ }
|
|
|
+ List<FsCourseWatchLog> waitWatchLogs = watchLogMapper.selectTodayWatchLogs(3);
|
|
|
+ if (CollectionUtils.isNotEmpty(waitWatchLogs)) {
|
|
|
+ reissueCourse(null, fsCourseReissueConfig.getType(), waitWatchLogs, config);
|
|
|
+ }
|
|
|
+ return R.ok("补发成功");
|
|
|
+ } else {
|
|
|
+ return R.error("补发SOP配置类型错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ //return R.error("补发失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public FsCourseReissueConfig getConfigInfoRedis() {
|
|
|
+ FsCourseReissueConfig config = redisCache.getCacheObject("fs_course_reissue_config:");
|
|
|
+ if (config != null) {
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+ config = fsCourseReissueConfigMapper.selectOne(Wrappers.<FsCourseReissueConfig>lambdaQuery().eq(FsCourseReissueConfig::getStatus, 1));
|
|
|
+ if (config != null) {
|
|
|
+ redisCache.setCacheObject("fs_course_reissue_config:", config);
|
|
|
+ return config;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private boolean checkAppId(String appId) {
|
|
|
+ boolean result = false;
|
|
|
+ final WxMaService wxMaService = WxMaConfiguration.getMaService(appId);
|
|
|
+ String scene="collectionId";
|
|
|
+ try {
|
|
|
+ wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(
|
|
|
+ scene,
|
|
|
+ "pages_course/customerStatistics",
|
|
|
+ true,
|
|
|
+ "release",//trial - 体验版 release - 正式版 develop - 开发版
|
|
|
+ 430,
|
|
|
+ true,
|
|
|
+ null,
|
|
|
+ false);
|
|
|
+ result = true;
|
|
|
+ } catch (WxErrorException e) {
|
|
|
+ int errorCode = e.getError().getErrorCode();
|
|
|
+ if (errorCode == 50002) {
|
|
|
+ logger.info("生成二维码失败,mainAppId: {}, 错误码: {}, 错误信息: {}", appId, errorCode, e.getMessage());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ result = true;
|
|
|
+ logger.info("生成二维码失败,mainAppId: {}, 错误信息: {}", appId, e.getMessage());
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ private String createCourseLinkByMiniApp(Date sendTime, Long courseId, Long videoId,
|
|
|
+ QwUser qwUser, Long externalId) {
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(qwUser.getCompanyId());
|
|
|
+ link.setQwUserId(qwUser.getId());
|
|
|
+ link.setCompanyUserId(qwUser.getCompanyUserId());
|
|
|
+ link.setVideoId(videoId);
|
|
|
+ link.setCorpId(qwUser.getCorpId());
|
|
|
+ link.setCourseId(courseId);
|
|
|
+ link.setQwExternalId(externalId);
|
|
|
+ link.setIsRoom(1);
|
|
|
+ link.setUNo(UUID.randomUUID().toString());
|
|
|
+ link.setLinkType(3);
|
|
|
+
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(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 = courseRealLink + courseJson;
|
|
|
+
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+
|
|
|
+
|
|
|
+ // 使用 Java 8 时间 API 计算过期时间
|
|
|
+ LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(0);
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
+ Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ link.setUpdateTime(updateTime);
|
|
|
+
|
|
|
+ //存短链-
|
|
|
+ fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
+
|
|
|
+
|
|
|
+ return link.getRealLink();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private void reissueCourse(String appId,Integer type,List<FsCourseWatchLog> watchLogs,CourseConfig config) {
|
|
|
+ List<QwSopLogs> sopLogsList = new ArrayList<>();
|
|
|
+ for (FsCourseWatchLog watchLog : watchLogs) {
|
|
|
+ try {
|
|
|
+ FsUserCourse userCourse = userCourseMapper.selectFsUserCourseByCourseId(watchLog.getCourseId());
|
|
|
+ if (userCourse==null) {
|
|
|
+ throw new CustomException("课程不存在,请检查");
|
|
|
+ }
|
|
|
+
|
|
|
+ FsUserCourseVideo courseVideo = courseVideoMapper.selectFsUserCourseVideoByVideoId(watchLog.getVideoId());
|
|
|
+ if (courseVideo==null) {
|
|
|
+ throw new CustomException("视频不存在,请检查");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwUser qwUser = qwUserService.selectQwUserById(watchLog.getQwUserId());
|
|
|
+ if (qwUser==null||qwUser.getCompanyId()==null||qwUser.getCompanyUserId()==null){
|
|
|
+ throw new CustomException("用户不存在,请检查");
|
|
|
+ }
|
|
|
+
|
|
|
+ QwExternalContact qwExternalContact = qwExternalContactService.selectQwExternalContactById(watchLog.getQwExternalContactId());
|
|
|
+ if (qwExternalContact==null) {
|
|
|
+ throw new CustomException("客户不存在");
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
+ if (type == 1) {
|
|
|
+ String linkByMiniApp = createCourseLinkByMiniApp(new Date(), watchLog.getCourseId(), watchLog.getVideoId(), qwUser, watchLog.getQwExternalContactId());
|
|
|
+
|
|
|
+ QwSopLogs sopLogs = new QwSopLogs();
|
|
|
+ sopLogs.setQwUserid(qwUser.getQwUserId());
|
|
|
+ sopLogs.setExternalUserId(qwExternalContact.getExternalUserId());
|
|
|
+ sopLogs.setExternalId(qwExternalContact.getId());
|
|
|
+ sopLogs.setLogType(2);
|
|
|
+ sopLogs.setSendStatus(3L);
|
|
|
+ sopLogs.setSendTime(sdf.format(new Date()));
|
|
|
+ sopLogs.setCompanyId(qwUser.getCompanyId());
|
|
|
+ sopLogs.setReceivingStatus(0L);
|
|
|
+ sopLogs.setSopId("miniSidebar");
|
|
|
+ sopLogs.setCorpId(qwUser.getCorpId());
|
|
|
+ sopLogs.setFsUserId(watchLog.getUserId());
|
|
|
+ sopLogs.setSort(99999999);
|
|
|
+ sopLogs.setSendType(3);
|
|
|
+ sopLogs.setExternalUserName(qwExternalContact.getName());
|
|
|
+ sopLogs.setQwUserKey(qwUser.getId());
|
|
|
+
|
|
|
+ QwSopCourseFinishTempSetting setting = new QwSopCourseFinishTempSetting();
|
|
|
+ List<QwSopCourseFinishTempSetting.Setting> list = new ArrayList<>();
|
|
|
+ QwSopCourseFinishTempSetting.Setting st = new QwSopCourseFinishTempSetting.Setting();
|
|
|
+ st.setContentType("4");
|
|
|
+ st.setVideoId(watchLog.getVideoId());
|
|
|
+ st.setMiniprogramAppid(appId);
|
|
|
+ st.setMiniprogramTitle(courseVideo.getTitle());
|
|
|
+ st.setMiniprogramPicUrl(userCourse.getImgUrl());
|
|
|
+ st.setMiniprogramPage(linkByMiniApp);
|
|
|
+
|
|
|
+ list.add(st);
|
|
|
+ setting.setSetting(list);
|
|
|
+ setting.setType(2);
|
|
|
+ setting.setCourseType(0);
|
|
|
+ setting.setCourseId(watchLog.getCourseId().intValue());
|
|
|
+ setting.setVideoId(watchLog.getVideoId().intValue());
|
|
|
+
|
|
|
+ sopLogs.setSendMiniAppId(appId);
|
|
|
+ sopLogs.setContentJson(JSON.toJSONString(setting));
|
|
|
+ sopLogsList.add(sopLogs);
|
|
|
+ } else if (type == 2) {
|
|
|
+ //创建课程短链
|
|
|
+ Map<String, String> feiShuH5Link = createFeiShuH5Link(qwUser.getCorpId(), new Date()
|
|
|
+ , watchLog.getCourseId().intValue(), watchLog.getVideoId().intValue()
|
|
|
+ , qwUser.getId(), String.valueOf(watchLog.getCompanyUserId())
|
|
|
+ , String.valueOf(watchLog.getCompanyId()), qwExternalContact.getId()
|
|
|
+ , config);
|
|
|
+ //获取生成的课程短链码
|
|
|
+ String shortCode = feiShuH5Link.get("link");
|
|
|
+ //调用生成飞书注册授权链接
|
|
|
+ String feiShuLink = feiShuService.getFeishuRegisterLink(watchLog.getVideoId(), watchLog.getCompanyId(), watchLog.getCourseId(), watchLog.getCompanyUserId(),shortCode);
|
|
|
+
|
|
|
+ QwSopLogs sopLogs = new QwSopLogs();
|
|
|
+ sopLogs.setQwUserid(qwUser.getQwUserId());
|
|
|
+ sopLogs.setExternalUserId(qwExternalContact.getExternalUserId());
|
|
|
+ sopLogs.setExternalId(qwExternalContact.getId());
|
|
|
+ sopLogs.setLogType(2);
|
|
|
+ sopLogs.setSendStatus(3L);
|
|
|
+ sopLogs.setSendTime(sdf.format(new Date()));
|
|
|
+ sopLogs.setCompanyId(qwUser.getCompanyId());
|
|
|
+ sopLogs.setReceivingStatus(0L);
|
|
|
+ sopLogs.setSopId("miniSidebar");
|
|
|
+ sopLogs.setCorpId(qwUser.getCorpId());
|
|
|
+ sopLogs.setFsUserId(watchLog.getUserId());
|
|
|
+ sopLogs.setSort(99999999);
|
|
|
+ sopLogs.setSendType(3);
|
|
|
+ sopLogs.setExternalUserName(qwExternalContact.getName());
|
|
|
+ sopLogs.setQwUserKey(qwUser.getId());
|
|
|
+
|
|
|
+ QwSopCourseFinishTempSetting setting = new QwSopCourseFinishTempSetting();
|
|
|
+ List<QwSopCourseFinishTempSetting.Setting> list = new ArrayList<>();
|
|
|
+ QwSopCourseFinishTempSetting.Setting st = new QwSopCourseFinishTempSetting.Setting();
|
|
|
+
|
|
|
+ st.setContentType("18");
|
|
|
+ st.setIsBindUrl("1");
|
|
|
+ st.setLinkDescribe(courseVideo.getTitle());
|
|
|
+ st.setLinkTitle(userCourse.getCourseName());
|
|
|
+ st.setLinkImageUrl(userCourse.getImgUrl());
|
|
|
+ st.setLinkUrl(feiShuLink);
|
|
|
+
|
|
|
+ list.add(st);
|
|
|
+ setting.setSetting(list);
|
|
|
+ setting.setType(2);
|
|
|
+ setting.setCourseType(0);
|
|
|
+ setting.setCourseId(watchLog.getCourseId().intValue());
|
|
|
+ setting.setVideoId(watchLog.getVideoId().intValue());
|
|
|
+
|
|
|
+ sopLogs.setContentJson(JSON.toJSONString(setting));
|
|
|
+ sopLogsList.add(sopLogs);
|
|
|
+ }
|
|
|
+ } catch (CustomException e) {
|
|
|
+ logger.error("生成SOP失败,原因:{}", e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (CollectionUtils.isNotEmpty(sopLogsList)) {
|
|
|
+ qwSopLogsMapper.batchInsertQwSopLogs(sopLogsList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成课程链接
|
|
|
+ * */
|
|
|
+ private Map<String, String> createFeiShuH5Link(String corpId, Date sendTime,
|
|
|
+ Integer courseId, Integer videoId, Long qwUserId,
|
|
|
+ String companyUserId, String companyId, Long externalId, CourseConfig config) {
|
|
|
+ FsCourseLink link = createFsCourseLink(corpId, sendTime, courseId, videoId, qwUserId,
|
|
|
+ companyUserId, companyId, externalId, 3, null);
|
|
|
+ FsCourseRealLink courseMap = new FsCourseRealLink();
|
|
|
+ BeanUtils.copyProperties(link, courseMap);
|
|
|
+ String courseJson = JSON.toJSONString(courseMap);
|
|
|
+ String realLinkFull = feiShuMiniAppLink + courseJson;
|
|
|
+ if (StringUtils.isNotEmpty(config.getRealLinkGjDomainName())) {
|
|
|
+ realLinkFull = config.getRealLinkGjDomainName() + realLinkFull;
|
|
|
+ }
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+ // 使用 Java 8 时间 API 计算过期时间
|
|
|
+ LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(0);
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
+ Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+ link.setUpdateTime(updateTime);
|
|
|
+ fsCourseLinkMapper.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, Integer courseId, Integer videoId, Long qwUserId,
|
|
|
+ String companyUserId, String companyId, Long externalId, Integer type, String chatId) {
|
|
|
+ // 手动创建 FsCourseLink 对象,避免使用 BeanUtils.copyProperties
|
|
|
+ FsCourseLink link = new FsCourseLink();
|
|
|
+ link.setCompanyId(Long.parseLong(companyId));
|
|
|
+ link.setQwUserId(qwUserId);
|
|
|
+ link.setCompanyUserId(Long.parseLong(companyUserId));
|
|
|
+ link.setVideoId(videoId.longValue());
|
|
|
+ link.setCorpId(corpId);
|
|
|
+ link.setCourseId(courseId.longValue());
|
|
|
+ link.setChatId(chatId);
|
|
|
+ link.setQwExternalId(externalId);
|
|
|
+ link.setLinkType(type); //小程序
|
|
|
+ link.setUNo(UUID.randomUUID().toString());
|
|
|
+ String randomString = generateRandomStringWithLock();
|
|
|
+ if (StringUtil.strIsNullOrEmpty(randomString)) {
|
|
|
+ link.setLink(UUID.randomUUID().toString().replace("-", ""));
|
|
|
+ } else {
|
|
|
+ link.setLink(randomString);
|
|
|
+ }
|
|
|
+
|
|
|
+ link.setCreateTime(sendTime);
|
|
|
+ link.setProjectCode(cloudHostProper.getProjectCode());
|
|
|
+
|
|
|
+ return link;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Date createUpdateTime(QwSopCourseFinishTempSetting.Setting setting,Date sendTime,CourseConfig config){
|
|
|
+
|
|
|
+ Integer expireDays = (setting.getExpiresDays() == null || setting.getExpiresDays() == 0)
|
|
|
+ ? config.getVideoLinkExpireDate()
|
|
|
+ : setting.getExpiresDays();
|
|
|
+
|
|
|
+// 使用 Java 8 时间 API 计算过期时间
|
|
|
+ LocalDateTime sendDateTime = sendTime.toInstant().atZone(ZoneId.systemDefault()).toLocalDateTime();
|
|
|
+ LocalDateTime expireDateTime = sendDateTime.plusDays(expireDays-1);
|
|
|
+ expireDateTime = expireDateTime.toLocalDate().atTime(23, 59, 59);
|
|
|
+ Date updateTime = Date.from(expireDateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ return updateTime;
|
|
|
+ }
|
|
|
+}
|