|
|
@@ -2,7 +2,10 @@ package com.fs.sop.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fs.common.annotation.DataSource;
|
|
|
import com.fs.common.enums.DataSourceType;
|
|
|
import com.fs.common.exception.base.BaseException;
|
|
|
@@ -46,7 +49,6 @@ import java.text.SimpleDateFormat;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.CountDownLatch;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.function.Consumer;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -425,6 +427,10 @@ public class QwSopTempServiceImpl implements IQwSopTempService {
|
|
|
temp.setProject(fsUserCourse.getProject());
|
|
|
qwSopTempMapper.updateQwSopTemp(temp);
|
|
|
List<FsUserCourseVideo> videoList = fsUserCourseVideoMapper.selectVideoByCourseId(fsUserCourse.getCourseId());
|
|
|
+ createSopTempRules(temp, videoList, fsUserCourse);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void createSopTempRules(QwSopTemp temp, List<FsUserCourseVideo> videoList, FsUserCourse fsUserCourse) {
|
|
|
AtomicInteger i = new AtomicInteger(1);
|
|
|
Integer gap = temp.getGap();
|
|
|
List<QwSopTempDay> collect = videoList.stream().map(e -> {
|
|
|
@@ -627,67 +633,76 @@ public class QwSopTempServiceImpl implements IQwSopTempService {
|
|
|
if (CollectionUtils.isEmpty(rulesList)) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
// 获取这些规则关联的模板ID集合
|
|
|
Set<String> tempIds = rulesList.stream()
|
|
|
.map(QwSopTempRules::getTempId)
|
|
|
.filter(Objects::nonNull)
|
|
|
.collect(Collectors.toSet());
|
|
|
|
|
|
- // 查询相关联的sop模板
|
|
|
- if (CollectionUtils.isEmpty(tempIds)) {
|
|
|
- return;
|
|
|
- }
|
|
|
- // 只弄课程模板的
|
|
|
+ FsUserCourse fsUserCourse = fsUserCourseMapper.selectFsUserCourseByCourseId(courseId);
|
|
|
+ List<FsUserCourseVideo> videoList = fsUserCourseVideoMapper.selectVideoByCourseId(fsUserCourse.getCourseId());
|
|
|
List<QwSopTemp> tempList = qwSopTempMapper.selectListByIds(tempIds);
|
|
|
- tempList = tempList.stream().filter(f -> Objects.equals(f.getStatus(), "1")).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isEmpty(tempList)) {
|
|
|
- return;
|
|
|
+ List<QwSopTempContent> contentList = qwSopTempContentService.listByTempIds(tempIds);
|
|
|
+ List<QwSopTempDay> dayList = qwSopTempDayService.listByTempIds(new LambdaQueryWrapper<QwSopTempDay>().in(QwSopTempDay::getTempId, tempIds));
|
|
|
+ List<Long> videoIdList = videoList.stream().map(FsUserCourseVideo::getVideoId).collect(Collectors.toList());
|
|
|
+ // videoList转Map key 为videoId value 为 courseSort
|
|
|
+ Map<Long, Long> videoSortMap = videoList.stream().collect(Collectors.toMap(FsUserCourseVideo::getVideoId, FsUserCourseVideo::getCourseSort));
|
|
|
+
|
|
|
+ // 将课程中已删除的视频在规则和日期中删除
|
|
|
+ Set<Long> dayIdList = rulesList.stream().filter(e -> !videoIdList.contains(e.getVideoId())).map(QwSopTempRules::getDayId).collect(Collectors.toSet());
|
|
|
+ if (CollectionUtils.isNotEmpty(dayIdList)) {
|
|
|
+ qwSopTempDayService.removeByWrapper(new LambdaQueryWrapper<QwSopTempDay>().in(QwSopTempDay::getId, dayIdList));
|
|
|
+ qwSopTempRulesService.removeByWrapper(new LambdaQueryWrapper<QwSopTempRules>().in(QwSopTempRules::getDayId, dayIdList));
|
|
|
+ qwSopTempContentService.removeByWrapper(new LambdaQueryWrapper<QwSopTempContent>().in(QwSopTempContent::getDayId, dayIdList));
|
|
|
}
|
|
|
|
|
|
- // 获取这些规则关联的模板ID集合
|
|
|
- Set<String> sopTempIds = tempList.stream()
|
|
|
- .map(QwSopTemp::getId)
|
|
|
- .filter(Objects::nonNull)
|
|
|
- .collect(Collectors.toSet());
|
|
|
+ // 需要添加的课程视频
|
|
|
+ List<FsUserCourseVideo> addVideoList = videoList.stream()
|
|
|
+ .filter(e -> rulesList.stream().noneMatch(f -> f.getVideoId().equals(e.getVideoId()))).collect(Collectors.toList());
|
|
|
|
|
|
- List<QwSopTempContent> contentList = qwSopTempContentService.listByTempIds(sopTempIds);
|
|
|
+ if (CollectionUtils.isNotEmpty(addVideoList)) {
|
|
|
+ for (QwSopTemp temp : tempList) {
|
|
|
+ // 通过历史中的第一课的数据来构建
|
|
|
+ Optional<QwSopTempDay> first = dayList.stream().filter(e -> e.getTempId().equals(temp.getId())).findFirst();
|
|
|
+ if (!first.isPresent()) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ QwSopTempDay qwSopTempDay = first.get();
|
|
|
+ // 构造timeList timeDesc time
|
|
|
+ temp.setTime(LocalTime.now());
|
|
|
+
|
|
|
+ temp.setTimeList(rulesList.stream()
|
|
|
+ .filter(e -> e.getTempId().equals(temp.getId()) && Objects.equals(e.getIsOfficial(), "0")
|
|
|
+ && Objects.equals(e.getDayId(), qwSopTempDay.getId())
|
|
|
+ ).map(QwSopTempRules::getTime)
|
|
|
+ .collect(Collectors.toList()));
|
|
|
|
|
|
- qwSopTempDayService.removeByTempIds(tempIds);
|
|
|
- qwSopTempRulesService.removeByTempIds(tempIds);
|
|
|
- qwSopTempContentService.removeByTempIds(tempIds);
|
|
|
- // 对每个模板执行同步操作
|
|
|
- for (QwSopTemp temp : tempList) {
|
|
|
- // 构造timeList timeDesc time
|
|
|
- rulesList.stream().filter(e -> e.getTempId().equals(temp.getId())).findFirst()
|
|
|
- .ifPresent(first -> temp.setTime(LocalTime.parse(first.getTime() + ":00")));
|
|
|
-
|
|
|
- temp.setTimeList(rulesList.stream()
|
|
|
- .filter(e -> e.getTempId().equals(temp.getId()) && Objects.equals(e.getIsOfficial(), "0")
|
|
|
- && Objects.equals(e.getName(), "第1天")).map(QwSopTempRules::getTime)
|
|
|
- .collect(Collectors.toList()));
|
|
|
- // 过滤并找到 dayId 最小的元素
|
|
|
- Optional<QwSopTempContent> minDayEntity = contentList.stream()
|
|
|
- // 1. 过滤条件:tempId匹配 + isBindUrl为null
|
|
|
- .filter(e -> e.getTempId().equals(temp.getId())
|
|
|
- && Objects.isNull(e.getIsBindUrl()))
|
|
|
- // 2. 按 dayId 升序排序,取第一个(最小)
|
|
|
- .min(Comparator.comparingLong(QwSopTempContent::getDayId)); // 若dayId是Long,用comparingLong
|
|
|
-
|
|
|
- if (minDayEntity.isPresent()) {
|
|
|
- QwSopTempContent qwSopTempContent = minDayEntity.get();
|
|
|
temp.setTimeDesc(contentList.stream().filter(e -> e.getTempId().equals(temp.getId())
|
|
|
&& Objects.isNull(e.getIsBindUrl())
|
|
|
- && Objects.equals(qwSopTempContent.getDayId(), e.getDayId())
|
|
|
+ && Objects.equals(qwSopTempDay.getId(), e.getDayId())
|
|
|
)
|
|
|
.map(m -> JSONObject.parseObject(m.getContent()).getString("value")).collect(Collectors.toList()));
|
|
|
+ temp.setProject(fsUserCourse.getProject());
|
|
|
+ temp.setCourseId(courseId);
|
|
|
+ temp.setOpenOfficial("1");
|
|
|
+ qwSopTempMapper.updateQwSopTemp(temp);
|
|
|
+ createSopTempRules(temp, addVideoList, fsUserCourse);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // 插入课程id
|
|
|
- temp.setCourseId(courseId);
|
|
|
- temp.setOpenOfficial("1");
|
|
|
- // 重新生成该模板的规则和内容
|
|
|
- threadPoolTaskExecutor.execute(() -> createSopTempRules(temp));
|
|
|
+ // 整理排序
|
|
|
+ List<QwSopTempRules> afterRuleList = qwSopTempRulesService.listByCourseId(courseId);
|
|
|
+ for (QwSopTemp temp : tempList) {
|
|
|
+ Long[] dayIdArray = afterRuleList.stream().filter(e -> e.getTempId().equals(temp.getId())).sorted(Comparator.comparing(a -> videoSortMap.get(a.getVideoId())))
|
|
|
+ .map(QwSopTempRules::getDayId).distinct().toArray(Long[]::new);
|
|
|
+ for (int i = 0; i < dayIdArray.length; i++) {
|
|
|
+ qwSopTempDayService.updateByWrapper(new UpdateWrapper<QwSopTempDay>()
|
|
|
+ .eq("id", dayIdArray[i])
|
|
|
+ .set("sorts", i + 1)
|
|
|
+ .set("name", "第" + (i + 1) + "天")
|
|
|
+ .set("day_num", i + 1)
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|