فهرست منبع

模板更新修改

xyx 1 هفته پیش
والد
کامیت
65efd47d52

+ 3 - 0
fs-service/src/main/java/com/fs/sop/service/IQwSopTempContentService.java

@@ -1,5 +1,6 @@
 package com.fs.sop.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.common.annotation.DataSource;
 import com.fs.common.enums.DataSourceType;
@@ -90,4 +91,6 @@ public interface IQwSopTempContentService extends IService<QwSopTempContent>{
     void removeByTempIds(Collection<String> tempIds);
 
     List<QwSopTempContent> listByTempIds(Collection<String> tempIds);
+
+    void removeByWrapper(LambdaQueryWrapper<QwSopTempContent> wrapper);
 }

+ 11 - 0
fs-service/src/main/java/com/fs/sop/service/IQwSopTempDayService.java

@@ -1,10 +1,15 @@
 package com.fs.sop.service;
 
+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.extension.service.IService;
 import com.fs.sop.domain.QwSopTempDay;
 
+import java.sql.Wrapper;
 import java.util.Collection;
 import java.util.List;
+import java.util.Set;
 
 /**
  * sop任务模板规则Service接口
@@ -35,4 +40,10 @@ public interface IQwSopTempDayService extends IService<QwSopTempDay> {
     int getDayNumByIdLimitOne(String tempId);
 
     void removeByTempIds(Collection<String> tempIds);
+
+    void removeByWrapper(LambdaQueryWrapper<QwSopTempDay> wrapper);
+
+    List<QwSopTempDay> listByTempIds(LambdaQueryWrapper<QwSopTempDay> wrapper);
+
+    void updateByWrapper(UpdateWrapper<QwSopTempDay> wrapper);
 }

+ 3 - 0
fs-service/src/main/java/com/fs/sop/service/IQwSopTempRulesService.java

@@ -1,5 +1,6 @@
 package com.fs.sop.service;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.fs.common.annotation.DataSource;
 import com.fs.common.enums.DataSourceType;
@@ -94,4 +95,6 @@ public interface IQwSopTempRulesService extends IService<QwSopTempRules>{
     List<QwSopTempRules> listByCourseId(Long courseId);
 
     void removeByTempIds(Collection<String> tempIds);
+
+    void removeByWrapper(LambdaQueryWrapper<QwSopTempRules> wrapper);
 }

+ 7 - 0
fs-service/src/main/java/com/fs/sop/service/impl/QwSopTempContentServiceImpl.java

@@ -1,5 +1,6 @@
 package com.fs.sop.service.impl;
 
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.annotation.DataSource;
@@ -163,4 +164,10 @@ public class QwSopTempContentServiceImpl extends ServiceImpl<QwSopTempContentMap
     public List<QwSopTempContent> listByTempIds(Collection<String> tempIds) {
         return baseMapper.selectList(new QueryWrapper<QwSopTempContent>().in("temp_id", tempIds));
     }
+
+    @Override
+    @DataSource(DataSourceType.SOP)
+    public void removeByWrapper(LambdaQueryWrapper<QwSopTempContent> wrapper) {
+        this.remove(wrapper);
+    }
 }

+ 23 - 0
fs-service/src/main/java/com/fs/sop/service/impl/QwSopTempDayServiceImpl.java

@@ -2,6 +2,7 @@ package com.fs.sop.service.impl;
 
 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.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.annotation.DataSource;
@@ -13,7 +14,9 @@ import lombok.AllArgsConstructor;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.sql.Wrapper;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -24,6 +27,7 @@ import java.util.List;
  */
 @Service
 @AllArgsConstructor
+@DataSource(DataSourceType.SOP)
 public class QwSopTempDayServiceImpl extends ServiceImpl<QwSopTempDayMapper, QwSopTempDay> implements IQwSopTempDayService {
 
 
@@ -92,4 +96,23 @@ public class QwSopTempDayServiceImpl extends ServiceImpl<QwSopTempDayMapper, QwS
     public void removeByTempIds(Collection<String> tempIds) {
         this.remove(new QueryWrapper<QwSopTempDay>().in("temp_id", tempIds));
     }
+
+    @Override
+    @DataSource(DataSourceType.SOP)
+    public void removeByWrapper(LambdaQueryWrapper<QwSopTempDay> wrapper) {
+        this.remove(wrapper);
+    }
+
+    @Override
+    @DataSource(DataSourceType.SOP)
+    public List<QwSopTempDay> listByTempIds(LambdaQueryWrapper<QwSopTempDay> wrapper) {
+        return this.list(wrapper);
+    }
+
+    @Override
+    @DataSource(DataSourceType.SOP)
+    public void updateByWrapper(UpdateWrapper<QwSopTempDay> wrapper) {
+        this.update(wrapper);
+    }
+
 }

+ 7 - 0
fs-service/src/main/java/com/fs/sop/service/impl/QwSopTempRulesServiceImpl.java

@@ -1,6 +1,7 @@
 package com.fs.sop.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.fs.common.annotation.DataSource;
@@ -252,4 +253,10 @@ public class QwSopTempRulesServiceImpl extends ServiceImpl<QwSopTempRulesMapper,
     public void removeByTempIds(Collection<String> tempIds) {
         this.remove(new QueryWrapper<QwSopTempRules>().in("temp_id", tempIds));
     }
+
+    @Override
+    @DataSource(DataSourceType.SOP)
+    public void removeByWrapper(LambdaQueryWrapper<QwSopTempRules> wrapper) {
+        this.remove(wrapper);
+    }
 }

+ 60 - 45
fs-service/src/main/java/com/fs/sop/service/impl/QwSopTempServiceImpl.java

@@ -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)
+                );
+            }
         }
     }
 

+ 3 - 0
fs-service/src/main/resources/application-dev.yml

@@ -178,6 +178,9 @@ headerImg:
 ipad:
     ipadUrl: http://admin.test.ylrztop.com/ipad
     aiApi: http://1.95.196.10:3000/api
+    voiceApi:
+    commonApi:
+    url:
 wx_miniapp_temp:
     pay_order_temp_id:
     inquiry_temp_id: