Forráskód Böngészése

分享人员也生成考勤

liujc 2 éve
szülő
commit
be2d9dc5a7

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseShareService.java

@@ -12,6 +12,8 @@ public interface CourseShareService extends BaseService<Integer, CourseShare> {
 
     Boolean saveCourseShare(CourseShareDto courseShareDto);
 
+    Boolean saveCourseShareByOne(CourseShareDto courseShareDto);
+
     PageInfo<StudentManageListDto> queryCourseSharedStudent(CourseShareQueryInfo shareQueryInfo);
 
     boolean createPaymentRecord(Long courseId, Integer userId);

+ 58 - 37
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseShareServiceImpl.java

@@ -28,6 +28,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.excel.POIUtil;
 import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -92,49 +93,32 @@ public class CourseShareServiceImpl extends BaseServiceImpl<Integer, CourseShare
     public Boolean saveCourseShare(CourseShareDto courseShareDto) {
         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("未选择搜索条件");
         }
+        HashMap<String, Object> params = new HashMap<>();
+        MapUtil.populateMap(params, courseShareDto);
         List<StudentManageListDto> studentList = courseShareDao.selectStudentByParam(params);
         List<Integer> userIdList = studentList.stream()
                 .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;
     }
 
@@ -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查询是否已经私有分享当前课程
      *
      * @param studentId        用户id

+ 8 - 0
mec-web/src/main/java/com/ym/mec/web/controller/CourseShareController.java

@@ -45,6 +45,14 @@ public class CourseShareController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation(value = "一键添加保存分享列表")
+    @PostMapping("/saveCourseShareByOne")
+    @PreAuthorize("@pcs.hasPermissions('courseShare/saveCourseShareByOne')")
+    public HttpResponseResult<List<CourseShare>> saveCourseShareByOne(@Validated @RequestBody CourseShareDto courseShareDto) {
+        courseShareService.saveCourseShareByOne(courseShareDto);
+        return succeed();
+    }
+
     @ApiOperation(value = "查询已经分享过的学生")
     @GetMapping("/queryCourseSharedStudent")
     @PreAuthorize("@pcs.hasPermissions('courseShare/queryCourseSharedStudent')")