|  | @@ -7,10 +7,14 @@ import com.fs.common.annotation.DataSource;
 | 
	
		
			
				|  |  |  import com.fs.common.enums.DataSourceType;
 | 
	
		
			
				|  |  |  import com.fs.common.exception.base.BaseException;
 | 
	
		
			
				|  |  |  import com.fs.common.utils.PubFun;
 | 
	
		
			
				|  |  | +import com.fs.course.config.CourseConfig;
 | 
	
		
			
				|  |  |  import com.fs.course.domain.FsUserCourse;
 | 
	
		
			
				|  |  |  import com.fs.course.domain.FsUserCourseVideo;
 | 
	
		
			
				|  |  | +import com.fs.course.domain.FsUserCourseVideoRedPackage;
 | 
	
		
			
				|  |  |  import com.fs.course.mapper.FsUserCourseMapper;
 | 
	
		
			
				|  |  |  import com.fs.course.mapper.FsUserCourseVideoMapper;
 | 
	
		
			
				|  |  | +import com.fs.course.service.IFsUserCourseVideoRedPackageService;
 | 
	
		
			
				|  |  | +import com.fs.course.vo.FsCourseRedPacketLogListPVO;
 | 
	
		
			
				|  |  |  import com.fs.fastGpt.domain.FastGptChatReplaceWords;
 | 
	
		
			
				|  |  |  import com.fs.fastGpt.mapper.FastGptChatReplaceWordsMapper;
 | 
	
		
			
				|  |  |  import com.fs.qw.vo.QwSopTempSetting2;
 | 
	
	
		
			
				|  | @@ -22,12 +26,16 @@ import com.fs.sop.domain.QwSopTempRules;
 | 
	
		
			
				|  |  |  import com.fs.sop.mapper.QwSopTempMapper;
 | 
	
		
			
				|  |  |  import com.fs.sop.params.QwSopShareTempParam;
 | 
	
		
			
				|  |  |  import com.fs.sop.service.*;
 | 
	
		
			
				|  |  | +import com.fs.sop.vo.QwSopTempRedPackageVo;
 | 
	
		
			
				|  |  |  import com.fs.sop.vo.VoiceVo;
 | 
	
		
			
				|  |  | +import com.fs.system.domain.SysConfig;
 | 
	
		
			
				|  |  | +import com.fs.system.service.ISysConfigService;
 | 
	
		
			
				|  |  |  import lombok.AllArgsConstructor;
 | 
	
		
			
				|  |  |  import org.apache.rocketmq.spring.core.RocketMQTemplate;
 | 
	
		
			
				|  |  |  import org.springframework.stereotype.Service;
 | 
	
		
			
				|  |  |  import org.springframework.transaction.annotation.Transactional;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import java.math.BigDecimal;
 | 
	
		
			
				|  |  |  import java.text.SimpleDateFormat;
 | 
	
		
			
				|  |  |  import java.time.LocalTime;
 | 
	
		
			
				|  |  |  import java.time.format.DateTimeFormatter;
 | 
	
	
		
			
				|  | @@ -55,6 +63,8 @@ public class QwSopTempServiceImpl implements IQwSopTempService
 | 
	
		
			
				|  |  |      private final RocketMQTemplate rocketMQTemplate;
 | 
	
		
			
				|  |  |      private final FsUserCourseMapper fsUserCourseMapper;
 | 
	
		
			
				|  |  |      private final FsUserCourseVideoMapper fsUserCourseVideoMapper;
 | 
	
		
			
				|  |  | +    private final IFsUserCourseVideoRedPackageService fsUserCourseVideoRedPackageService;
 | 
	
		
			
				|  |  | +    private final ISysConfigService sysConfigService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 查询sop模板
 | 
	
	
		
			
				|  | @@ -258,6 +268,72 @@ public class QwSopTempServiceImpl implements IQwSopTempService
 | 
	
		
			
				|  |  |              r.setRulesId(e.getId());
 | 
	
		
			
				|  |  |          })).collect(Collectors.toList());
 | 
	
		
			
				|  |  |          qwSopTempContentService.saveList(contentList);
 | 
	
		
			
				|  |  | +        SysConfig sysConfig = sysConfigService.selectConfigByConfigKey("course.config");
 | 
	
		
			
				|  |  | +        CourseConfig courseConfig = JSON.parseObject(sysConfig.getConfigValue(), CourseConfig.class);
 | 
	
		
			
				|  |  | +        List<Long> videoIdList = PubFun.listToNewList(ruleList, QwSopTempRules::getVideoId);
 | 
	
		
			
				|  |  | +        Map<Long, Optional<BigDecimal>> redMap;
 | 
	
		
			
				|  |  | +        if(!videoIdList.isEmpty()){
 | 
	
		
			
				|  |  | +            List<FsUserCourseVideoRedPackage> redPackageList = fsUserCourseVideoRedPackageService.listByCompanyIdAndVideoIds(temp.getCompanyId(), videoIdList);
 | 
	
		
			
				|  |  | +            redMap = redPackageList.stream().collect(Collectors.groupingBy(FsUserCourseVideoRedPackage::getVideoId, Collectors.mapping(FsUserCourseVideoRedPackage::getRedPacketMoney, Collectors.reducing((e1, e2) -> e1))));
 | 
	
		
			
				|  |  | +        }else{
 | 
	
		
			
				|  |  | +            redMap = new HashMap<>();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<FsUserCourseVideoRedPackage> redPackage = ruleList.stream().filter(e -> e.getVideoId() != null).map(e -> {
 | 
	
		
			
				|  |  | +            FsUserCourseVideoRedPackage red = new FsUserCourseVideoRedPackage();
 | 
	
		
			
				|  |  | +            red.setCompanyId(temp.getCompanyId());
 | 
	
		
			
				|  |  | +            red.setVideoId(e.getVideoId());
 | 
	
		
			
				|  |  | +            red.setRedPacketMoney(redMap.getOrDefault(e.getVideoId(), Optional.of(courseConfig.getRedPackageMoney())).orElse(BigDecimal.ZERO));
 | 
	
		
			
				|  |  | +            red.setRuleId(e.getId());
 | 
	
		
			
				|  |  | +            red.setDataType(3);
 | 
	
		
			
				|  |  | +            return red;
 | 
	
		
			
				|  |  | +        }).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        fsUserCourseVideoRedPackageService.batchSaveFsUserCourseVideoRedPackage(redPackage);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public List<QwSopTempRedPackageVo> redList(String id) {
 | 
	
		
			
				|  |  | +        List<QwSopTempDay> dayList = qwSopTempRulesService.listByTempIdAll(id);
 | 
	
		
			
				|  |  | +        if(dayList.isEmpty()){
 | 
	
		
			
				|  |  | +            return Collections.emptyList();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<QwSopTempRules> rules = dayList.stream().flatMap(e -> e.getList().stream()).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        if(rules.isEmpty()){
 | 
	
		
			
				|  |  | +            return Collections.emptyList();
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        List<FsUserCourseVideoRedPackage> redPackageList = fsUserCourseVideoRedPackageService.listByRuleIds(PubFun.listToNewList(rules, QwSopTempRules::getId));
 | 
	
		
			
				|  |  | +        Map<Long, FsUserCourseVideoRedPackage> redMap = PubFun.listToMapByGroupObject(redPackageList, FsUserCourseVideoRedPackage::getVideoId);
 | 
	
		
			
				|  |  | +        List<FsUserCourseVideo> videoList = fsUserCourseVideoMapper.selectVideoByCourseId(rules.get(0).getCourseId());
 | 
	
		
			
				|  |  | +        Map<Long, FsUserCourseVideo> videoMap = PubFun.listToMapByGroupObject(videoList, FsUserCourseVideo::getVideoId);
 | 
	
		
			
				|  |  | +        return rules.stream().filter(e -> redMap.containsKey(e.getVideoId()) && videoMap.containsKey(e.getVideoId())).map(e -> {
 | 
	
		
			
				|  |  | +            FsUserCourseVideoRedPackage red = redMap.get(e.getVideoId());
 | 
	
		
			
				|  |  | +            FsUserCourseVideo video = videoMap.get(e.getVideoId());
 | 
	
		
			
				|  |  | +            QwSopTempRedPackageVo vo = new QwSopTempRedPackageVo();
 | 
	
		
			
				|  |  | +            vo.setId(red.getId());
 | 
	
		
			
				|  |  | +            vo.setRuleId(e.getId());
 | 
	
		
			
				|  |  | +            vo.setName(e.getName());
 | 
	
		
			
				|  |  | +            vo.setVideoId(e.getVideoId());
 | 
	
		
			
				|  |  | +            vo.setVideoName(video.getTitle());
 | 
	
		
			
				|  |  | +            vo.setCompanyId(red.getCompanyId());
 | 
	
		
			
				|  |  | +            vo.setRedPacketMoney(red.getRedPacketMoney());
 | 
	
		
			
				|  |  | +            vo.setDataType(red.getDataType());
 | 
	
		
			
				|  |  | +            return vo;
 | 
	
		
			
				|  |  | +        }).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public void updateRedPackage(List<QwSopTempRedPackageVo> list) {
 | 
	
		
			
				|  |  | +        fsUserCourseVideoRedPackageService.deleteFsUserCourseVideoRedPackageByIds(list.stream().map(QwSopTempRedPackageVo::getId).toArray(Long[]::new));
 | 
	
		
			
				|  |  | +        List<FsUserCourseVideoRedPackage> redPackage = list.stream().map(e -> {
 | 
	
		
			
				|  |  | +            FsUserCourseVideoRedPackage red = new FsUserCourseVideoRedPackage();
 | 
	
		
			
				|  |  | +            red.setCompanyId(e.getCompanyId());
 | 
	
		
			
				|  |  | +            red.setVideoId(e.getVideoId());
 | 
	
		
			
				|  |  | +            red.setRedPacketMoney(e.getRedPacketMoney());
 | 
	
		
			
				|  |  | +            red.setRuleId(e.getRuleId());
 | 
	
		
			
				|  |  | +            red.setDataType(3);
 | 
	
		
			
				|  |  | +            return red;
 | 
	
		
			
				|  |  | +        }).collect(Collectors.toList());
 | 
	
		
			
				|  |  | +        fsUserCourseVideoRedPackageService.batchSaveFsUserCourseVideoRedPackage(redPackage);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
	
		
			
				|  | @@ -305,6 +381,7 @@ public class QwSopTempServiceImpl implements IQwSopTempService
 | 
	
		
			
				|  |  |          if(!voiceList.isEmpty()){
 | 
	
		
			
				|  |  |              rocketMQTemplate.syncSend("voice-generation", JSON.toJSONString(VoiceVo.builder().type(0).id(day.getId().toString()).build()));
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return map;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |