|
@@ -28,6 +28,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
import com.ym.mec.util.collection.MapUtil;
|
|
import com.ym.mec.util.excel.POIUtil;
|
|
import com.ym.mec.util.excel.POIUtil;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -92,49 +93,32 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
public Boolean saveCourseShare(CourseShareDto courseShareDto) {
|
|
public Boolean saveCourseShare(CourseShareDto courseShareDto) {
|
|
CourseSchedule courseSchedule = getCourseScheduleById(courseShareDto.getCourseId());
|
|
CourseSchedule courseSchedule = getCourseScheduleById(courseShareDto.getCourseId());
|
|
|
|
|
|
- HashMap<String, Object> params = new HashMap<>();
|
|
|
|
- MapUtil.populateMap(params, courseShareDto);
|
|
|
|
- List<Integer> userIds = courseShareDto.getUserIds();
|
|
|
|
- if (params.keySet().isEmpty() && CollectionUtils.isEmpty(userIds)) {
|
|
|
|
|
|
+ List<Integer> userIdList = courseShareDto.getUserIds();
|
|
|
|
+ if (CollectionUtils.isEmpty(userIdList)) {
|
|
|
|
+ throw new BizException("未选择学员");
|
|
|
|
+ }
|
|
|
|
+ saveCourseShareStudent(courseShareDto.getCourseId(), courseSchedule.getTenantId(), userIdList);
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public Boolean saveCourseShareByOne(CourseShareDto courseShareDto) {
|
|
|
|
+ CourseSchedule courseSchedule = getCourseScheduleById(courseShareDto.getCourseId());
|
|
|
|
+
|
|
|
|
+ if (StringUtils.isEmpty(courseShareDto.getSearch()) &&
|
|
|
|
+ StringUtils.isEmpty(courseShareDto.getSubjectId()) &&
|
|
|
|
+ StringUtils.isEmpty(courseShareDto.getOrganIds()) &&
|
|
|
|
+ StringUtils.isEmpty(courseShareDto.getGroupIds()) &&
|
|
|
|
+ StringUtils.isEmpty(courseShareDto.getSchoolIds())) {
|
|
throw new BizException("未选择搜索条件");
|
|
throw new BizException("未选择搜索条件");
|
|
}
|
|
}
|
|
|
|
+ HashMap<String, Object> params = new HashMap<>();
|
|
|
|
+ MapUtil.populateMap(params, courseShareDto);
|
|
List<StudentManageListDto> studentList = courseShareDao.selectStudentByParam(params);
|
|
List<StudentManageListDto> studentList = courseShareDao.selectStudentByParam(params);
|
|
List<Integer> userIdList = studentList.stream()
|
|
List<Integer> userIdList = studentList.stream()
|
|
.map(StudentManageListDto::getUserId).distinct().collect(Collectors.toList());
|
|
.map(StudentManageListDto::getUserId).distinct().collect(Collectors.toList());
|
|
- if (CollectionUtils.isNotEmpty(userIds)) {
|
|
|
|
- userIds.forEach(next -> {
|
|
|
|
- if (!userIdList.contains(next)) {
|
|
|
|
- userIdList.add(next);
|
|
|
|
- }
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
// 处理已经分享过的数据
|
|
// 处理已经分享过的数据
|
|
- List<CourseShare> existShares = courseShareDao.selectByCourseId(courseShareDto.getCourseId());
|
|
|
|
- if (CollectionUtils.isNotEmpty(existShares)) {
|
|
|
|
- List<Integer> sharedHistoryRecords = existShares.stream()
|
|
|
|
- .map(CourseShare::getUserId)
|
|
|
|
- .collect(Collectors.toList());
|
|
|
|
- // 已经存在的数据不需要重复录入
|
|
|
|
- userIdList.removeIf(sharedHistoryRecords::contains);
|
|
|
|
- }
|
|
|
|
- if (CollectionUtils.isEmpty(userIdList)) {
|
|
|
|
- // 没有新加入的数据
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Integer userId = userService.getUserId();
|
|
|
|
- List<CourseShare> courseShares = userIdList.stream().map(next -> {
|
|
|
|
- CourseShare courseShare = new CourseShare();
|
|
|
|
- courseShare.setCourseId(courseShareDto.getCourseId());
|
|
|
|
- courseShare.setTenantId(courseSchedule.getTenantId());
|
|
|
|
- courseShare.setUserId(next);
|
|
|
|
- courseShare.setCreateTime(new Date());
|
|
|
|
- courseShare.setCreateBy(userId);
|
|
|
|
- return courseShare;
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
-
|
|
|
|
- // 数据入库
|
|
|
|
- batchInsert(courseShares);
|
|
|
|
|
|
+ saveCourseShareStudent(courseShareDto.getCourseId(), courseSchedule.getTenantId(), userIdList);
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -364,6 +348,43 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
+ * // 保存课程分享的学生
|
|
|
|
+ *
|
|
|
|
+ * @param courseId 课程ID
|
|
|
|
+ * @param tenantId 租户ID
|
|
|
|
+ * @param userIdList 用户ID列表
|
|
|
|
+ */
|
|
|
|
+ private void saveCourseShareStudent(Long courseId, Integer tenantId, List<Integer> userIdList) {
|
|
|
|
+ // 处理已经分享过的数据
|
|
|
|
+ List<CourseShare> existShares = courseShareDao.selectByCourseId(courseId);
|
|
|
|
+ if (CollectionUtils.isNotEmpty(existShares)) {
|
|
|
|
+ List<Integer> sharedHistoryRecords = existShares.stream()
|
|
|
|
+ .map(CourseShare::getUserId)
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ // 已经存在的数据不需要重复录入
|
|
|
|
+ userIdList.removeIf(sharedHistoryRecords::contains);
|
|
|
|
+ }
|
|
|
|
+ if (CollectionUtils.isEmpty(userIdList)) {
|
|
|
|
+ // 没有新加入的数据
|
|
|
|
+ throw new BizException("学员已经在分享名单中");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Integer userId = userService.getUserId();
|
|
|
|
+ List<CourseShare> courseShares = userIdList.stream().map(next -> {
|
|
|
|
+ CourseShare courseShare = new CourseShare();
|
|
|
|
+ courseShare.setCourseId(courseId);
|
|
|
|
+ courseShare.setTenantId(tenantId);
|
|
|
|
+ courseShare.setUserId(next);
|
|
|
|
+ courseShare.setCreateTime(new Date());
|
|
|
|
+ courseShare.setCreateBy(userId);
|
|
|
|
+ return courseShare;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ // 数据入库
|
|
|
|
+ batchInsert(courseShares);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
* 根据用户id和课程id查询是否已经私有分享当前课程
|
|
* 根据用户id和课程id查询是否已经私有分享当前课程
|
|
*
|
|
*
|
|
* @param studentId 用户id
|
|
* @param studentId 用户id
|