|
@@ -1,26 +1,28 @@
|
|
|
package com.fs.course.service.impl;
|
|
|
|
|
|
-import java.util.*;
|
|
|
-import java.util.function.Function;
|
|
|
-import java.util.stream.Collectors;
|
|
|
-
|
|
|
+import com.fs.common.exception.CustomException;
|
|
|
+import com.fs.common.utils.StringUtils;
|
|
|
import com.fs.course.domain.FsUserCoursePeriod;
|
|
|
import com.fs.course.domain.FsUserCoursePeriodDays;
|
|
|
+import com.fs.course.domain.FsUserCourseVideoRedPackage;
|
|
|
import com.fs.course.mapper.FsUserCoursePeriodDaysMapper;
|
|
|
import com.fs.course.mapper.FsUserCoursePeriodMapper;
|
|
|
+import com.fs.course.mapper.FsUserCourseVideoRedPackageMapper;
|
|
|
+import com.fs.course.param.BatchCompanyRedPackageParam;
|
|
|
import com.fs.course.param.FsBatchPeriodRedPackageParam;
|
|
|
+import com.fs.course.service.IFsUserCourseVideoRedPackageService;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.ibatis.session.ExecutorType;
|
|
|
import org.apache.ibatis.session.SqlSession;
|
|
|
import org.apache.ibatis.session.SqlSessionFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import com.fs.course.mapper.FsUserCourseVideoRedPackageMapper;
|
|
|
-import com.fs.course.domain.FsUserCourseVideoRedPackage;
|
|
|
-import com.fs.course.service.IFsUserCourseVideoRedPackageService;
|
|
|
-import org.springframework.test.annotation.Rollback;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
+import java.util.*;
|
|
|
+import java.util.function.Function;
|
|
|
+import java.util.stream.Collectors;
|
|
|
+
|
|
|
/**
|
|
|
* 课程公司红包Service业务层处理
|
|
|
*
|
|
@@ -244,5 +246,45 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
return fsUserCourseVideoRedPackageMapper.selectByRuleIds(ruleIds);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 按照公司批量设置红包
|
|
|
+ * @param param 入参
|
|
|
+ */
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public void batchRedPacketByCompany(BatchCompanyRedPackageParam param) {
|
|
|
+ FsUserCoursePeriod period = userCoursePeriodMapper.selectFsUserCoursePeriodById(param.getPeriodId());
|
|
|
+ if (Objects.isNull(period)) {
|
|
|
+ throw new CustomException("营期不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Set<Long> targetCompanyIds = new HashSet<>(param.getCompanyIds());
|
|
|
+ Set<Long> companyIds = Arrays.stream(period.getCompanyId().split(","))
|
|
|
+ .filter(StringUtils::isNotBlank)
|
|
|
+ .map(Long::valueOf)
|
|
|
+ .filter(targetCompanyIds::contains)
|
|
|
+ .collect(Collectors.toSet());
|
|
|
+
|
|
|
+ if (companyIds.isEmpty()) {
|
|
|
+ throw new CustomException("当前营期不包含所选公司");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FsUserCoursePeriodDays> periodVideos = userCoursePeriodDaysMapper.selectCourseVideoList(Collections.singleton(period.getPeriodId()));
|
|
|
+
|
|
|
+ List<FsUserCourseVideoRedPackage> fsRedPackageList = companyIds.stream()
|
|
|
+ .flatMap(companyId -> periodVideos.stream().map(video -> {
|
|
|
+ FsUserCourseVideoRedPackage redPkg = new FsUserCourseVideoRedPackage();
|
|
|
+ redPkg.setCompanyId(companyId);
|
|
|
+ redPkg.setVideoId(video.getVideoId());
|
|
|
+ redPkg.setRedPacketMoney(param.getRedPacketMoney());
|
|
|
+ redPkg.setPeriodId(period.getPeriodId());
|
|
|
+ redPkg.setDataType(2);
|
|
|
+ return redPkg;
|
|
|
+ }))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ this.batchSaveCompanyRedPackage(fsRedPackageList);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|