|
@@ -420,134 +420,141 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
public void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds) {
|
|
|
- Map<CourseSchedule.CourseScheduleType, Map<Integer, Integer>> courseTypeCourseDurationMap = new HashMap<>();
|
|
|
- Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
|
|
|
-
|
|
|
- List<CourseScheduleStudentPayment> css = courseScheduleStudentPaymentDao.getWithGroup(musicGroupId, GroupType.MUSIC, studentIds);
|
|
|
- Map<Integer, Set<Long>> studentCourseIdsMap = new HashMap<>();
|
|
|
- if(!CollectionUtils.isEmpty(css)){
|
|
|
- studentCourseIdsMap = css.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getUserId, Collectors.mapping(CourseScheduleStudentPayment::getCourseScheduleId, Collectors.toSet())));
|
|
|
- }
|
|
|
-
|
|
|
- for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCoursesEntry : typeCourseMap.entrySet()) {
|
|
|
- Map<Integer, Integer> sdMap = new HashMap<>();
|
|
|
- for (Integer studentId : studentIds) {
|
|
|
- int totalCourseDuration = 0;
|
|
|
- for (CourseSchedule courseSchedule : typeCoursesEntry.getValue()) {
|
|
|
- if(courseSchedule.getMemberFlag() == 1){
|
|
|
- continue;
|
|
|
+ Map<Integer, List<CourseSchedule>> memberCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getMemberFlag));
|
|
|
+ for (Integer memberFlag : memberCourseMap.keySet()) {
|
|
|
+ List<CourseSchedule> courseScheduleList = memberCourseMap.get(memberFlag);
|
|
|
+ if(courseScheduleList != null && courseScheduleList.size() > 0){
|
|
|
+ if(memberFlag == 1){
|
|
|
+ createForMemberMusicGroup(musicGroupId,courseScheduleList,studentIds);
|
|
|
+ }else {
|
|
|
+ Map<CourseSchedule.CourseScheduleType, Map<Integer, Integer>> courseTypeCourseDurationMap = new HashMap<>();
|
|
|
+ Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCourseMap = courseScheduleList.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
|
|
|
+
|
|
|
+ List<CourseScheduleStudentPayment> css = courseScheduleStudentPaymentDao.getWithGroup(musicGroupId, GroupType.MUSIC, studentIds);
|
|
|
+ Map<Integer, Set<Long>> studentCourseIdsMap = new HashMap<>();
|
|
|
+ if(!CollectionUtils.isEmpty(css)){
|
|
|
+ studentCourseIdsMap = css.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getUserId, Collectors.mapping(CourseScheduleStudentPayment::getCourseScheduleId, Collectors.toSet())));
|
|
|
}
|
|
|
- //课程时长
|
|
|
- int courseDuration = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
|
|
|
- totalCourseDuration += courseDuration;
|
|
|
- }
|
|
|
- sdMap.put(studentId, totalCourseDuration);
|
|
|
- }
|
|
|
- courseTypeCourseDurationMap.put(typeCoursesEntry.getKey(), sdMap);
|
|
|
- }
|
|
|
|
|
|
- List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
-
|
|
|
- List<String> allBatchNos = new ArrayList<>();
|
|
|
-
|
|
|
- for (Integer studentId : studentIds) {
|
|
|
- Set<Long> existCourseIds = new HashSet<>();
|
|
|
- if(studentCourseIdsMap.containsKey(studentId)){
|
|
|
- existCourseIds = studentCourseIdsMap.get(studentId);
|
|
|
- }
|
|
|
- for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseScheduleTypeListEntry : typeCourseMap.entrySet()) {
|
|
|
- //当前课程类型总课程时长
|
|
|
- Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey()).get(studentId);
|
|
|
+ for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCoursesEntry : typeCourseMap.entrySet()) {
|
|
|
+ Map<Integer, Integer> sdMap = new HashMap<>();
|
|
|
+ for (Integer studentId : studentIds) {
|
|
|
+ int totalCourseDuration = 0;
|
|
|
+ for (CourseSchedule courseSchedule : typeCoursesEntry.getValue()) {
|
|
|
+ if(courseSchedule.getMemberFlag() == 1){
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //课程时长
|
|
|
+ int courseDuration = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
|
|
|
+ totalCourseDuration += courseDuration;
|
|
|
+ }
|
|
|
+ sdMap.put(studentId, totalCourseDuration);
|
|
|
+ }
|
|
|
+ courseTypeCourseDurationMap.put(typeCoursesEntry.getKey(), sdMap);
|
|
|
+ }
|
|
|
|
|
|
- String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey(),null);
|
|
|
+ List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
|
|
|
- List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(batchNo, studentId, courseScheduleTypeListEntry.getKey());
|
|
|
- int totalCourseMinutes = musicGroupPaymentStudentCourseDetails.stream().mapToInt(MusicGroupPaymentStudentCourseDetail::getTotalCourseMinutes).reduce(0, Integer::sum);
|
|
|
- if(CollectionUtils.isEmpty(musicGroupPaymentStudentCourseDetails) || totalCourseMinutes < typeCourseDuration){
|
|
|
- SysUser user = teacherDao.getUser(studentId);
|
|
|
- throw new BizException("{}在{}课程类型上的课程时长不足", user.getUsername(), courseScheduleTypeListEntry.getKey().getMsg());
|
|
|
- }
|
|
|
+ List<String> allBatchNos = new ArrayList<>();
|
|
|
|
|
|
- Set<Long> calenderIds = musicGroupPaymentStudentCourseDetails.stream().map(MusicGroupPaymentStudentCourseDetail::getMusicGroupPaymentCalenderId).collect(Collectors.toSet());
|
|
|
+ for (Integer studentId : studentIds) {
|
|
|
+ Set<Long> existCourseIds = new HashSet<>();
|
|
|
+ if(studentCourseIdsMap.containsKey(studentId)){
|
|
|
+ existCourseIds = studentCourseIdsMap.get(studentId);
|
|
|
+ }
|
|
|
+ for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseScheduleTypeListEntry : typeCourseMap.entrySet()) {
|
|
|
+ //当前课程类型总课程时长
|
|
|
+ Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey()).get(studentId);
|
|
|
|
|
|
- List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.queryByIds(calenderIds);
|
|
|
- if(CollectionUtils.isEmpty(musicGroupPaymentCalenders)||musicGroupPaymentCalenders.size()!=calenderIds.size()){
|
|
|
- throw new BizException("缴费设置异常");
|
|
|
- }
|
|
|
+ String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey(),null);
|
|
|
|
|
|
- List<MusicGroupPaymentCalenderCourseSettings> musicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalendersAndCourseType(calenderIds, courseScheduleTypeListEntry.getKey());
|
|
|
- int originalCourseTotalMinutes = musicGroupPaymentCalenderCourseSettings.stream().mapToInt(MusicGroupPaymentCalenderCourseSettings::getCourseTotalMinuties).reduce(0, Integer::sum);
|
|
|
- if(Objects.isNull(musicGroupPaymentCalenderCourseSettings)||originalCourseTotalMinutes!=totalCourseMinutes){
|
|
|
- throw new BizException("缴费设置异常");
|
|
|
- }
|
|
|
+ List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(batchNo, studentId, courseScheduleTypeListEntry.getKey());
|
|
|
+ int totalCourseMinutes = musicGroupPaymentStudentCourseDetails.stream().mapToInt(MusicGroupPaymentStudentCourseDetail::getTotalCourseMinutes).reduce(0, Integer::sum);
|
|
|
+ if(CollectionUtils.isEmpty(musicGroupPaymentStudentCourseDetails) || totalCourseMinutes < typeCourseDuration){
|
|
|
+ SysUser user = teacherDao.getUser(studentId);
|
|
|
+ throw new BizException("{}在{}课程类型上的课程时长不足", user.getUsername(), courseScheduleTypeListEntry.getKey().getMsg());
|
|
|
+ }
|
|
|
|
|
|
- allBatchNos.add(batchNo);
|
|
|
+ Set<Long> calenderIds = musicGroupPaymentStudentCourseDetails.stream().map(MusicGroupPaymentStudentCourseDetail::getMusicGroupPaymentCalenderId).collect(Collectors.toSet());
|
|
|
|
|
|
- BigDecimal totalCourseOriginalPrice = musicGroupPaymentCalenderCourseSettings.stream().map(MusicGroupPaymentCalenderCourseSettings::getCourseOriginalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
- BigDecimal totalCourseCurrentPrice = musicGroupPaymentCalenderCourseSettings.stream().map(MusicGroupPaymentCalenderCourseSettings::getCourseCurrentPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.queryByIds(calenderIds);
|
|
|
+ if(CollectionUtils.isEmpty(musicGroupPaymentCalenders)||musicGroupPaymentCalenders.size()!=calenderIds.size()){
|
|
|
+ throw new BizException("缴费设置异常");
|
|
|
+ }
|
|
|
|
|
|
- //课程每分钟原价
|
|
|
- BigDecimal unitMinuteOriginalPrice = totalCourseOriginalPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
- //课程每分钟现价
|
|
|
- BigDecimal unitMinuteCurrentPrice = totalCourseCurrentPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ List<MusicGroupPaymentCalenderCourseSettings> musicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalendersAndCourseType(calenderIds, courseScheduleTypeListEntry.getKey());
|
|
|
+ int originalCourseTotalMinutes = musicGroupPaymentCalenderCourseSettings.stream().mapToInt(MusicGroupPaymentCalenderCourseSettings::getCourseTotalMinuties).reduce(0, Integer::sum);
|
|
|
+ if(Objects.isNull(musicGroupPaymentCalenderCourseSettings)||originalCourseTotalMinutes!=totalCourseMinutes){
|
|
|
+ throw new BizException("缴费设置异常");
|
|
|
+ }
|
|
|
|
|
|
- if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(musicGroupPaymentCalenders.get(0).getPayUserType())){
|
|
|
- unitMinuteCurrentPrice = new BigDecimal("0");
|
|
|
- }
|
|
|
+ allBatchNos.add(batchNo);
|
|
|
|
|
|
- List<CourseScheduleStudentPayment> typeCourseStudentPayments = new ArrayList<>();
|
|
|
- courseScheduleTypeListEntry.getValue().sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
- BigDecimal typeCourseTotalOriginalPrice = new BigDecimal("0"), typeCourseTotalCurrentPrice = new BigDecimal("0");
|
|
|
- for (CourseSchedule courseSchedule : courseScheduleTypeListEntry.getValue()) {
|
|
|
- if(existCourseIds.contains(courseSchedule.getId())){
|
|
|
- throw new BizException("该学员已在此班级{}课程中", courseSchedule.getId());
|
|
|
- }
|
|
|
- //课程时长
|
|
|
- int courseDuration = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
|
|
|
+ BigDecimal totalCourseOriginalPrice = musicGroupPaymentCalenderCourseSettings.stream().map(MusicGroupPaymentCalenderCourseSettings::getCourseOriginalPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal totalCourseCurrentPrice = musicGroupPaymentCalenderCourseSettings.stream().map(MusicGroupPaymentCalenderCourseSettings::getCourseCurrentPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
|
|
|
- //课程原价
|
|
|
- BigDecimal courseOriginalPrice = unitMinuteOriginalPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
- typeCourseTotalOriginalPrice = typeCourseTotalOriginalPrice.add(courseOriginalPrice);
|
|
|
+ //课程每分钟原价
|
|
|
+ BigDecimal unitMinuteOriginalPrice = totalCourseOriginalPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ //课程每分钟现价
|
|
|
+ BigDecimal unitMinuteCurrentPrice = totalCourseCurrentPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
- //课程现价
|
|
|
- BigDecimal courseCurrentPrice = unitMinuteCurrentPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
- typeCourseTotalCurrentPrice = typeCourseTotalCurrentPrice.add(courseCurrentPrice);
|
|
|
+ if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(musicGroupPaymentCalenders.get(0).getPayUserType())){
|
|
|
+ unitMinuteCurrentPrice = new BigDecimal("0");
|
|
|
+ }
|
|
|
|
|
|
- CourseScheduleStudentPayment cssp = new CourseScheduleStudentPayment();
|
|
|
- cssp.setGroupType(courseSchedule.getGroupType());
|
|
|
- cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
|
|
|
- cssp.setCourseScheduleId(courseSchedule.getId());
|
|
|
- cssp.setClassGroupId(courseSchedule.getClassGroupId());
|
|
|
- cssp.setBatchNo(batchNo);
|
|
|
- cssp.setUserId(studentId);
|
|
|
- cssp.setOriginalPrice(courseOriginalPrice);
|
|
|
- cssp.setExpectPrice(courseCurrentPrice);
|
|
|
- cssp.setActualPrice(BigDecimal.ZERO);
|
|
|
- cssp.setBeMerged(false);
|
|
|
- typeCourseStudentPayments.add(cssp);
|
|
|
- }
|
|
|
+ List<CourseScheduleStudentPayment> typeCourseStudentPayments = new ArrayList<>();
|
|
|
+ courseScheduleTypeListEntry.getValue().sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
+ BigDecimal typeCourseTotalOriginalPrice = new BigDecimal("0"), typeCourseTotalCurrentPrice = new BigDecimal("0");
|
|
|
+ for (CourseSchedule courseSchedule : courseScheduleTypeListEntry.getValue()) {
|
|
|
+ if(existCourseIds.contains(courseSchedule.getId())){
|
|
|
+ throw new BizException("该学员已在此班级{}课程中", courseSchedule.getId());
|
|
|
+ }
|
|
|
+ //课程时长
|
|
|
+ int courseDuration = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
|
|
|
+
|
|
|
+ //课程原价
|
|
|
+ BigDecimal courseOriginalPrice = unitMinuteOriginalPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ typeCourseTotalOriginalPrice = typeCourseTotalOriginalPrice.add(courseOriginalPrice);
|
|
|
+
|
|
|
+ //课程现价
|
|
|
+ BigDecimal courseCurrentPrice = unitMinuteCurrentPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ typeCourseTotalCurrentPrice = typeCourseTotalCurrentPrice.add(courseCurrentPrice);
|
|
|
+
|
|
|
+ CourseScheduleStudentPayment cssp = new CourseScheduleStudentPayment();
|
|
|
+ cssp.setGroupType(courseSchedule.getGroupType());
|
|
|
+ cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
|
|
|
+ cssp.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ cssp.setClassGroupId(courseSchedule.getClassGroupId());
|
|
|
+ cssp.setBatchNo(batchNo);
|
|
|
+ cssp.setUserId(studentId);
|
|
|
+ cssp.setOriginalPrice(courseOriginalPrice);
|
|
|
+ cssp.setExpectPrice(courseCurrentPrice);
|
|
|
+ cssp.setActualPrice(BigDecimal.ZERO);
|
|
|
+ cssp.setBeMerged(false);
|
|
|
+ typeCourseStudentPayments.add(cssp);
|
|
|
+ }
|
|
|
|
|
|
- typeCourseStudentPayments.get(0).setOriginalPrice(typeCourseStudentPayments.get(0).getOriginalPrice().add(totalCourseOriginalPrice.subtract(typeCourseTotalOriginalPrice)));
|
|
|
- if(MusicGroupPaymentCalender.PayUserType.STUDENT.equals(musicGroupPaymentCalenders.get(0).getPayUserType())) {
|
|
|
- typeCourseStudentPayments.get(0).setExpectPrice(typeCourseStudentPayments.get(0).getExpectPrice().add(totalCourseCurrentPrice.subtract(typeCourseTotalCurrentPrice)));
|
|
|
- }
|
|
|
- courseScheduleStudentPayments.addAll(typeCourseStudentPayments);
|
|
|
- for (MusicGroupPaymentStudentCourseDetail musicGroupPaymentStudentCourseDetail : musicGroupPaymentStudentCourseDetails) {
|
|
|
- if(typeCourseDuration>musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes()){
|
|
|
- musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes());
|
|
|
- typeCourseDuration = typeCourseDuration-musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes();
|
|
|
- }else{
|
|
|
- musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(typeCourseDuration);
|
|
|
- typeCourseDuration = 0;
|
|
|
+ typeCourseStudentPayments.get(0).setOriginalPrice(typeCourseStudentPayments.get(0).getOriginalPrice().add(totalCourseOriginalPrice.subtract(typeCourseTotalOriginalPrice)));
|
|
|
+ if(MusicGroupPaymentCalender.PayUserType.STUDENT.equals(musicGroupPaymentCalenders.get(0).getPayUserType())) {
|
|
|
+ typeCourseStudentPayments.get(0).setExpectPrice(typeCourseStudentPayments.get(0).getExpectPrice().add(totalCourseCurrentPrice.subtract(typeCourseTotalCurrentPrice)));
|
|
|
+ }
|
|
|
+ courseScheduleStudentPayments.addAll(typeCourseStudentPayments);
|
|
|
+ for (MusicGroupPaymentStudentCourseDetail musicGroupPaymentStudentCourseDetail : musicGroupPaymentStudentCourseDetails) {
|
|
|
+ if(typeCourseDuration>musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes()){
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes());
|
|
|
+ typeCourseDuration = typeCourseDuration-musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes();
|
|
|
+ }else{
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(typeCourseDuration);
|
|
|
+ typeCourseDuration = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ musicGroupPaymentStudentCourseDetailDao.batchUpdate(musicGroupPaymentStudentCourseDetails);
|
|
|
+ }
|
|
|
}
|
|
|
+ courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|
|
|
}
|
|
|
- musicGroupPaymentStudentCourseDetailDao.batchUpdate(musicGroupPaymentStudentCourseDetails);
|
|
|
}
|
|
|
}
|
|
|
- courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|
|
|
-// for (String batchNo : allBatchNos) {
|
|
|
-// updateForMusicGroupWithPaymentCalender(batchNo);
|
|
|
-// }
|
|
|
}
|
|
|
|
|
|
@Override
|