|
@@ -4,10 +4,13 @@ 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.mapper.FsUserCoursePeriodDaysMapper;
|
|
|
import com.fs.course.mapper.FsUserCoursePeriodMapper;
|
|
|
+import com.fs.course.param.BatchCompanyRedPackageParam;
|
|
|
import com.fs.course.param.FsBatchPeriodRedPackageParam;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import org.apache.ibatis.annotations.Param;
|
|
@@ -23,12 +26,12 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
/**
|
|
|
* 课程公司红包Service业务层处理
|
|
|
- *
|
|
|
+ *
|
|
|
* @author fs
|
|
|
* @date 2024-10-25
|
|
|
*/
|
|
|
@Service
|
|
|
-public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVideoRedPackageService
|
|
|
+public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVideoRedPackageService
|
|
|
{
|
|
|
@Autowired
|
|
|
private FsUserCourseVideoRedPackageMapper fsUserCourseVideoRedPackageMapper;
|
|
@@ -44,7 +47,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 查询课程公司红包
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 课程公司红包主键
|
|
|
* @return 课程公司红包
|
|
|
*/
|
|
@@ -56,7 +59,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 查询课程公司红包列表
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserCourseVideoRedPackage 课程公司红包
|
|
|
* @return 课程公司红包
|
|
|
*/
|
|
@@ -68,7 +71,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 新增课程公司红包
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserCourseVideoRedPackage 课程公司红包
|
|
|
* @return 结果
|
|
|
*/
|
|
@@ -80,7 +83,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 修改课程公司红包
|
|
|
- *
|
|
|
+ *
|
|
|
* @param fsUserCourseVideoRedPackage 课程公司红包
|
|
|
* @return 结果
|
|
|
*/
|
|
@@ -92,7 +95,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 批量删除课程公司红包
|
|
|
- *
|
|
|
+ *
|
|
|
* @param ids 需要删除的课程公司红包主键
|
|
|
* @return 结果
|
|
|
*/
|
|
@@ -104,7 +107,7 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
|
|
|
/**
|
|
|
* 删除课程公司红包信息
|
|
|
- *
|
|
|
+ *
|
|
|
* @param id 课程公司红包主键
|
|
|
* @return 结果
|
|
|
*/
|
|
@@ -239,5 +242,44 @@ public class FsUserCourseVideoRedPackageServiceImpl implements IFsUserCourseVide
|
|
|
public void batchSaveFsUserCourseVideoRedPackage(List<FsUserCourseVideoRedPackage> redPackage) {
|
|
|
fsUserCourseVideoRedPackageMapper.batchSaveFsUserCourseVideoRedPackage(redPackage);
|
|
|
}
|
|
|
+ /**
|
|
|
+ * 按照公司批量设置红包
|
|
|
+ * @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);
|
|
|
+ }
|
|
|
|
|
|
}
|