|
@@ -76,6 +76,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 miniappRealLink = "/pages/index/index?course=";
|
|
|
|
|
|
private static final String QWSOP_KEY_PREFIX = "qwsop:";
|
|
@@ -1968,7 +1969,8 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
if (settings == null) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+ //完课后若是小程序发送另外一堂课
|
|
|
+ saveWacthLogOfCourseLink(settings,sopLogs,newTimeString,finishLog,finishTemp);
|
|
|
// 处理音频内容
|
|
|
// for (QwSopCourseFinishTempSetting.Setting st : settings) {
|
|
|
// if (st.getContentType().equals("7")) {
|
|
@@ -1987,6 +1989,233 @@ public class SopLogsTaskServiceImpl implements SopLogsTaskService {
|
|
|
return sopLogs;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 判定小程序的话新增创建看课记录,以及fsCourseLink
|
|
|
+ *
|
|
|
+ * @param settings
|
|
|
+ */
|
|
|
+ public void saveWacthLogOfCourseLink(List<QwSopCourseFinishTempSetting.Setting> settings, QwSopLogs sopLogs, String newTimeString, FsCourseWatchLog finishLog, FsCourseFinishTemp finishTemp){
|
|
|
+ String json = configService.selectConfigByKey("course.config");
|
|
|
+ CourseConfig config = JSON.parseObject(json, CourseConfig.class);
|
|
|
+ Date dataTime = new Date();
|
|
|
+ List<CompanyMiniapp> miniList = companyMiniappService.list(new QueryWrapper<CompanyMiniapp>().orderByAsc("sort_num"));
|
|
|
+ Map<Long, Map<Integer, List<CompanyMiniapp>>> miniMap = miniList.stream().collect(Collectors.groupingBy(CompanyMiniapp::getCompanyId, Collectors.groupingBy(CompanyMiniapp::getType)));
|
|
|
+
|
|
|
+ QwCompany qwCompany = iQwCompanyService.getQwCompanyByRedis(sopLogs.getCorpId());
|
|
|
+ QwUser qwUser = qwExternalContactService.getQwUserByRedis(sopLogs.getCorpId(), sopLogs.getQwUserid());
|
|
|
+ if (qwUser == null){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (QwSopCourseFinishTempSetting.Setting st : settings) {
|
|
|
+ switch (st.getContentType()) {
|
|
|
+ //小程序单独
|
|
|
+ case "4":
|
|
|
+ addWatchLogIfNeeded(sopLogs.getSopId(), st.getVideoId().intValue(), st.getCourseId().intValue(), sopLogs.getFsUserId(), String.valueOf(qwUser.getId()),qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(),
|
|
|
+ sopLogs.getExternalId(), newTimeString.substring(0, 10), dataTime);
|
|
|
+
|
|
|
+ String linkByMiniApp = createLinkByMiniApp(st, sopLogs.getCorpId(), dataTime, finishTemp.getCourseId().intValue(), Integer.valueOf(st.getVideoId().toString()),
|
|
|
+ String.valueOf(qwUser.getId()), qwUser.getCompanyUserId().toString(), qwUser.getCompanyId().toString(), sopLogs.getExternalId(), config);
|
|
|
+
|
|
|
+
|
|
|
+ String miniAppId = null;
|
|
|
+ if (!miniMap.isEmpty() && qwUser.getSendMsgType() == 1) {
|
|
|
+ Map<Integer, List<CompanyMiniapp>> integerListMap = miniMap.get(Long.valueOf(qwUser.getCompanyId()));
|
|
|
+ if (integerListMap != null) {
|
|
|
+ int listIndex = 0;
|
|
|
+ List<CompanyMiniapp> miniapps = integerListMap.get(listIndex);
|
|
|
+
|
|
|
+ if (miniapps != null && !miniapps.isEmpty()) {
|
|
|
+ CompanyMiniapp companyMiniapp = miniapps.get(0);
|
|
|
+ if (companyMiniapp != null && !StringUtil.strIsNullOrEmpty(companyMiniapp.getAppId())) {
|
|
|
+ miniAppId = companyMiniapp.getAppId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtil.strIsNullOrEmpty(miniAppId) && !StringUtil.strIsNullOrEmpty(qwCompany.getMiniAppId())) {
|
|
|
+ miniAppId = qwCompany.getMiniAppId();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!StringUtil.strIsNullOrEmpty(miniAppId)) {
|
|
|
+ st.setMiniprogramAppid(miniAppId);
|
|
|
+ } else {
|
|
|
+ log.error("企业未配置小程序-" + sopLogs.getCorpId());
|
|
|
+ }
|
|
|
+
|
|
|
+ String miniprogramTitle = st.getMiniprogramTitle();
|
|
|
+ int maxLength = 17;
|
|
|
+ st.setMiniprogramTitle(miniprogramTitle.length() > maxLength ? miniprogramTitle.substring(0, maxLength)+"..." : miniprogramTitle);
|
|
|
+ st.setMiniprogramPage(linkByMiniApp);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private Date processDate(String sendTimeParam) {
|
|
|
+ // 1. 获取当前日期(年月日)
|
|
|
+ LocalDate currentDate = LocalDate.now();
|
|
|
+
|
|
|
+ // 2. 解析传入的时分(支持 "HH:mm" 或 "H:mm")
|
|
|
+ LocalTime sendTime = LocalTime.parse(sendTimeParam);
|
|
|
+
|
|
|
+ // 3. 合并为 LocalDateTime
|
|
|
+ LocalDateTime dateTime = LocalDateTime.of(currentDate, sendTime);
|
|
|
+
|
|
|
+ // 4. 转换为 Date(需通过 Instant 和系统默认时区)
|
|
|
+ Date date = Date.from(dateTime.atZone(ZoneId.systemDefault()).toInstant());
|
|
|
+
|
|
|
+ return date;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新增courseLink
|
|
|
+ *
|
|
|
+ * @param setting
|
|
|
+ * @param corpId
|
|
|
+ * @param sendTime
|
|
|
+ * @param courseId
|
|
|
+ * @param videoId
|
|
|
+ * @param qwUserId
|
|
|
+ * @param companyUserId
|
|
|
+ * @param companyId
|
|
|
+ * @param externalId
|
|
|
+ * @param config
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private String createLinkByMiniApp(QwSopCourseFinishTempSetting.Setting setting, String corpId, Date sendTime,
|
|
|
+ Integer courseId, Integer videoId, String 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 = miniappRealLink + courseJson;
|
|
|
+ link.setRealLink(realLinkFull);
|
|
|
+
|
|
|
+ Date updateTime = createUpdateTime(setting, sendTime, config);
|
|
|
+
|
|
|
+ link.setUpdateTime(updateTime);
|
|
|
+ //存短链-
|
|
|
+ fsCourseLinkMapper.insertFsCourseLink(link);
|
|
|
+ return link.getRealLink();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建courselink
|
|
|
+ * @param corpId
|
|
|
+ * @param sendTime
|
|
|
+ * @param courseId
|
|
|
+ * @param videoId
|
|
|
+ * @param qwUserId
|
|
|
+ * @param companyUserId
|
|
|
+ * @param companyId
|
|
|
+ * @param externalId
|
|
|
+ * @param type
|
|
|
+ * @param chatId
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public FsCourseLink createFsCourseLink(String corpId, Date sendTime, Integer courseId, Integer videoId, String 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(Long.valueOf(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);
|
|
|
+
|
|
|
+ return link;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算过期时间
|
|
|
+ * @param setting
|
|
|
+ * @param sendTime
|
|
|
+ * @param config
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 增加看课记录
|
|
|
+ *
|
|
|
+ * @param sopId
|
|
|
+ * @param videoId
|
|
|
+ * @param courseId
|
|
|
+ * @param fsUserId
|
|
|
+ * @param qwUserId
|
|
|
+ * @param companyUserId
|
|
|
+ * @param companyId
|
|
|
+ * @param externalId
|
|
|
+ * @param startTime
|
|
|
+ * @param createTime
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ private Long addWatchLogIfNeeded(String sopId, Integer videoId, Integer courseId,
|
|
|
+ Long fsUserId, String qwUserId, String companyUserId,
|
|
|
+ String companyId, Long externalId, String startTime, Date createTime) {
|
|
|
+
|
|
|
+ try {
|
|
|
+ FsCourseWatchLog watchLog = new FsCourseWatchLog();
|
|
|
+ watchLog.setVideoId(videoId != null ? videoId.longValue() : null);
|
|
|
+ watchLog.setQwExternalContactId(externalId);
|
|
|
+ watchLog.setSendType(2);
|
|
|
+ watchLog.setQwUserId(Long.valueOf(qwUserId));
|
|
|
+ watchLog.setSopId(sopId);
|
|
|
+ watchLog.setDuration(0L);
|
|
|
+ watchLog.setCourseId(courseId != null ? courseId.longValue() : null);
|
|
|
+ watchLog.setCompanyUserId(companyUserId != null ? Long.valueOf(companyUserId) : null);
|
|
|
+ watchLog.setCompanyId(companyId != null ? Long.valueOf(companyId) : null);
|
|
|
+ watchLog.setCreateTime(createTime);
|
|
|
+ watchLog.setUpdateTime(createTime);
|
|
|
+ watchLog.setLogType(3);
|
|
|
+ watchLog.setUserId(fsUserId);
|
|
|
+ watchLog.setCampPeriodTime(convertStringToDate(startTime, "yyyy-MM-dd"));
|
|
|
+
|
|
|
+ //存看课记录
|
|
|
+ int i = fsCourseWatchLogMapper.insertOrUpdateFsCourseWatchLog(watchLog);
|
|
|
+ return watchLog.getLogId();
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("插入观看记录失败:" + e.getMessage());
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 解析模板设置
|
|
|
*/
|