瀏覽代碼

课程转换

zouxuan 2 年之前
父節點
當前提交
209d1495ba

+ 2 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CloudTeacherFreeCourseDao.java

@@ -9,4 +9,6 @@ import java.util.List;
 public interface CloudTeacherFreeCourseDao extends BaseDAO<Long, CloudTeacherFreeCourse> {
 
     void batchInsert(@Param("scheduleIdList") String scheduleIdList, @Param("calenderId") Long calenderId);
+
+    void deleteByCourseIds(@Param("courseIdList") List<Long> courseIdList);
 }

+ 0 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -617,6 +617,4 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      * @return
      */
     List<StudentOrganDto> queryRemainCourseStudent(@Param("organIds") List<Integer> organIds);
-
-    Integer countByCourseIdAndUserId(@Param("newCourseIds") String newCourseIds, @Param("studentIds") String studentIds);
 }

+ 20 - 44
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleConvertServiceImpl.java

@@ -78,8 +78,12 @@ public class CourseScheduleConvertServiceImpl implements CourseScheduleConvertSe
     @Override
     @Transactional(rollbackFor = Exception.class)
     public HttpResponseResult action(List<ClassGroupDto> classGroups) {
+        ClassGroupDto classGroupDto = classGroups.get(0);
         //校验课程是否可以进行转换
-        this.checkConvertCourseIds(classGroups.get(0).getCourseIds());
+        this.checkConvertCourseIds(classGroupDto.getCourseIds());
+        if(!classGroupDto.getConfirmGenerate()){
+            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+        }
         //校验主教助教是否冲突
         classGroups.stream().forEach(e->classGroupTeacherMapperService.checkTeachingBishop(e.getClassGroupTeacherMapperList()));
         int classNum = classGroups.size();
@@ -116,7 +120,6 @@ public class CourseScheduleConvertServiceImpl implements CourseScheduleConvertSe
                     courseScheduleTeacherSalaryList.addAll(groupDto.getCourseScheduleTeacherSalaryList());
                     courseScheduleStudentPayments.addAll(groupDto.getCourseScheduleStudentPayments());
                 }else {
-                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     return result;
                 }
             }
@@ -153,55 +156,23 @@ public class CourseScheduleConvertServiceImpl implements CourseScheduleConvertSe
         List<Integer> userIdList = Arrays.stream(courseConvertLog.getStudentIds().split(",")).map(e -> Integer.parseInt(e)).collect(Collectors.toList());
         List<CourseSchedule> courseSchedules = JSONArray.parseArray(courseConvertLog.getOldCourseJson(), CourseSchedule.class);
         courseScheduleService.getDao().batchAddCourseSchedules(courseSchedules);
-        Map<Long, CourseSchedule> courseMap = courseSchedules.stream().collect(Collectors.groupingBy(e -> e.getId(),Collectors.collectingAndThen(Collectors.toList(),v->v.get(0))));
 
         String studentMapperJson = courseConvertLog.getOldCourseStudentMapperJson();
         List<CourseScheduleStudentPayment> studentPayments = JSONArray.parseArray(studentMapperJson, CourseScheduleStudentPayment.class);
-
-        courseScheduleStudentPaymentService.getDao().batchInsert(studentPayments);
         //获取学员课程价值
         List<CourseScheduleStudentPayment> paymentList = courseScheduleStudentPaymentService.getDao().findByCourseScheduleIds(newCourseIdList);
         //获取现有所有学员列表
-        Map<Integer, BigDecimal> userExpectMap = paymentList.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getUserId,
-                Collectors.collectingAndThen(Collectors.toList(), v -> v.stream().map(e -> e.getExpectPrice()).reduce(BigDecimal.ZERO, BigDecimal::add))));
-        Map<Integer, BigDecimal> userOriginalMap = paymentList.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getUserId,
-                Collectors.collectingAndThen(Collectors.toList(), v -> v.stream().map(e -> e.getOriginalPrice()).reduce(BigDecimal.ZERO, BigDecimal::add))));
-        CourseScheduleStudentPayment payment = paymentList.get(0);
-        //生成新的courseScheduleStudentPayment
-        List<Long> oldCourseIdList = Arrays.stream(courseConvertLog.getOldCourseIds().split(",")).map(e -> Long.parseLong(e)).collect(Collectors.toList());
-
-        for (Integer userId : userExpectMap.keySet()) {
-            BigDecimal expectAmount = userExpectMap.get(userId);
-            BigDecimal originalAmount = userOriginalMap.get(userId);
-            BigDecimal subExpectAmount = expectAmount;
-            BigDecimal subOriginalAmount = originalAmount;
-            int courseSize = oldCourseIdList.size();
-            BigDecimal ratioExpect = expectAmount.divide(new BigDecimal(courseSize), 2, RoundingMode.HALF_UP);
-            BigDecimal ratioOriginal = subOriginalAmount.divide(new BigDecimal(courseSize), 2, RoundingMode.HALF_UP);
-            for (int i = 0; i < courseSize; i++) {
-                CourseSchedule courseSchedule = courseMap.get(oldCourseIdList.get(i));
-                CourseScheduleStudentPayment studentPayment = new CourseScheduleStudentPayment();
-                studentPayment.setCourseScheduleId(courseSchedule.getId());
-                studentPayment.setMusicGroupId(courseSchedule.getMusicGroupId());
-                studentPayment.setUserId(userId);
-                studentPayment.setOriginalPrice(ratioOriginal);
-                studentPayment.setExpectPrice(ratioExpect);
-                subExpectAmount = subExpectAmount.subtract(ratioExpect);
-                subOriginalAmount = subOriginalAmount.subtract(ratioOriginal);
-                if(i == courseSize - 1){
-                    studentPayment.setOriginalPrice(studentPayment.getOriginalPrice().add(subOriginalAmount));
-                    studentPayment.setExpectPrice(studentPayment.getExpectPrice().add(subExpectAmount));
-                }
-                studentPayment.setActualPrice(BigDecimal.ZERO);
-                studentPayment.setTenantId(courseSchedule.getTenantId());
-                studentPayment.setClassGroupId(courseSchedule.getClassGroupId());
-            }
+        List<Integer> currentUserIdList = paymentList.stream().map(e -> e.getUserId()).distinct().collect(Collectors.toList());
+        userIdList.removeAll(currentUserIdList);
+        if(!CollectionUtils.isEmpty(userIdList)){
+            studentPayments = studentPayments.stream().filter(e->!userIdList.contains(e.getUserId())).collect(Collectors.toList());
         }
+        courseScheduleStudentPaymentService.getDao().batchInsert(studentPayments);
 
-
-
+        //保存老师课酬
         String teacherSalaryJson = courseConvertLog.getOldCourseTeacherSalaryJson();
         courseScheduleTeacherSalaryService.getDao().batchInsert(JSONArray.parseArray(teacherSalaryJson,CourseScheduleTeacherSalary.class));
+        //保存考勤
         String teacherAttendanceJson = courseConvertLog.getOldTeacherAttendanceJson();
         teacherAttendanceDao.batchInsert(JSONArray.parseArray(teacherAttendanceJson,TeacherAttendance.class));
 
@@ -219,6 +190,8 @@ public class CourseScheduleConvertServiceImpl implements CourseScheduleConvertSe
         courseScheduleTeacherSalaryService.getDao().batchDeleteByCourseScheduleIds(newCourseIdList);
         //删除学员课程价值
         courseScheduleStudentPaymentService.getDao().deleteByCourseSchedule(newCourseIdList);
+        //删除课程成本
+        cloudTeacherFreeCourseService.getDao().deleteByCourseIds(newCourseIdList);
     }
 
     private void checkConvertRevoke(CourseConvertLog courseConvertLog) {
@@ -245,10 +218,13 @@ public class CourseScheduleConvertServiceImpl implements CourseScheduleConvertSe
         if(courseSchedules.stream().anyMatch(e->e.getStatus() == CourseStatusEnum.OVER)){
             throw new BizException("操作失败:有已结束课程");
         }
-        String studentIds = courseConvertLog.getStudentIds();
         //学员课表是否变动
-        Integer userNum = courseScheduleStudentPaymentService.getDao().countByCourseIdAndUserId(newCourseIds,studentIds);
-        if(userNum == null || userNum < studentIds.split(",").length){
+        List<CourseScheduleStudentPayment> studentPayments = courseScheduleStudentPaymentService.getDao().findByCourseScheduleIds(courseIdList);
+        if(CollectionUtils.isEmpty(studentPayments)){
+            throw new BizException("操作失败:没有可操作的学员");
+        }
+        long count = studentPayments.stream().map(e -> e.getCreateTime()).distinct().count();
+        if(count > 1){
             throw new BizException("操作失败:课程学员有变更");
         }
     }

+ 3 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleServiceImpl.java

@@ -5989,6 +5989,9 @@ public class CourseScheduleServiceImpl extends BaseServiceImpl<Long, CourseSched
 			now = now.plusDays(1);
 		}
 		this.checkNewCourseSchedules(courseScheduleList, false, false);
+		if(!groupDto.getConfirmGenerate()){
+			return BaseController.succeed(courseScheduleList);
+		}
 
 		classGroupService.updateTotalClassTimes(classGroupId, courseScheduleList.size());
 

+ 8 - 2
mec-biz/src/main/resources/config/mybatis/CloudTeacherFreeCourseMapper.xml

@@ -58,8 +58,14 @@
 	<delete id="delete" >
 		DELETE FROM cloud_teacher_free_course WHERE id_ = #{id} 
 	</delete>
-	
-	<!-- 分页查询 -->
+    <delete id="deleteByCourseIds">
+		DELETE FROM cloud_teacher_free_course WHERE course_id_ IN
+		<foreach collection="courseIdList" separator="," item="id" open="(" close=")">
+			#{id}
+		</foreach>
+	</delete>
+
+    <!-- 分页查询 -->
 	<select id="queryPage" resultMap="CloudTeacherFreeCourse" parameterType="map">
 		SELECT * FROM cloud_teacher_free_course ORDER BY id_ <include refid="global.limit"/>
 	</select>

+ 0 - 4
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -1094,8 +1094,4 @@
         </foreach>
         group by cssp.user_id_ , u.organ_id_
 	</select>
-    <select id="countByCourseIdAndUserId" resultType="java.lang.Integer">
-		select COUNT(distinct user_id_) from course_schedule_student_payment cssp
-		where FIND_IN_SET(cssp.user_id_,#{studentIds}) and FIND_IN_SET(cssp.course_schedule_id_,#{newCourseIds})
-	</select>
 </mapper>