|
@@ -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("操作失败:课程学员有变更");
|
|
|
}
|
|
|
}
|