|
@@ -1,5 +1,6 @@
|
|
package com.ym.mec.biz.service.impl;
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
|
|
+import com.sun.scenario.effect.Identity;
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
import com.ym.mec.biz.dal.dao.*;
|
|
import com.ym.mec.biz.dal.dto.CourseScheduleStudentListDto;
|
|
import com.ym.mec.biz.dal.dto.CourseScheduleStudentListDto;
|
|
@@ -31,6 +32,7 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.function.IntBinaryOperator;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -327,30 +329,40 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseScheduleTypeListEntry : typeCourseMap.entrySet()) {
|
|
for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseScheduleTypeListEntry : typeCourseMap.entrySet()) {
|
|
//当前课程类型总课程时长
|
|
//当前课程类型总课程时长
|
|
Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey());
|
|
Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey());
|
|
- MusicGroupPaymentStudentCourseDetail musicGroupPaymentStudentCourseDetail = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey(), typeCourseDuration);
|
|
|
|
- if(Objects.isNull(musicGroupPaymentStudentCourseDetail)||musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes().compareTo(typeCourseDuration)<0){
|
|
|
|
|
|
+
|
|
|
|
+ String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey());
|
|
|
|
+
|
|
|
|
+ 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);
|
|
SysUser user = teacherDao.getUser(studentId);
|
|
throw new BizException("{}在{}课程类型上的课程时长不足", user.getUsername(), courseScheduleTypeListEntry.getKey().getMsg());
|
|
throw new BizException("{}在{}课程类型上的课程时长不足", user.getUsername(), courseScheduleTypeListEntry.getKey().getMsg());
|
|
}
|
|
}
|
|
|
|
|
|
- MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.get(musicGroupPaymentStudentCourseDetail.getMusicGroupPaymentCalenderId());
|
|
|
|
- if(Objects.isNull(musicGroupPaymentCalender)||!musicGroupId.equals(musicGroupPaymentCalender.getMusicGroupId())){
|
|
|
|
|
|
+ Set<Long> calenderIds = musicGroupPaymentStudentCourseDetails.stream().map(MusicGroupPaymentStudentCourseDetail::getMusicGroupPaymentCalenderId).collect(Collectors.toSet());
|
|
|
|
+
|
|
|
|
+ List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.queryByIds(calenderIds);
|
|
|
|
+ if(CollectionUtils.isEmpty(musicGroupPaymentCalenders)||musicGroupPaymentCalenders.size()!=calenderIds.size()){
|
|
throw new BizException("缴费设置异常");
|
|
throw new BizException("缴费设置异常");
|
|
}
|
|
}
|
|
|
|
|
|
- MusicGroupPaymentCalenderCourseSettings musicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalenderAndCourseType(musicGroupPaymentStudentCourseDetail.getMusicGroupPaymentCalenderId(), courseScheduleTypeListEntry.getKey());
|
|
|
|
- if(Objects.isNull(musicGroupPaymentCalenderCourseSettings)||musicGroupPaymentCalenderCourseSettings.getCourseTotalMinuties().compareTo(musicGroupPaymentStudentCourseDetail.getTotalCourseMinutes())!=0){
|
|
|
|
|
|
+ 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("缴费设置异常");
|
|
throw new BizException("缴费设置异常");
|
|
}
|
|
}
|
|
|
|
|
|
- allBatchNos.add(musicGroupPaymentCalender.getBatchNo());
|
|
|
|
|
|
+ allBatchNos.add(batchNo);
|
|
|
|
+
|
|
|
|
+ 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 unitMinuteOriginalPrice = musicGroupPaymentCalenderCourseSettings.getCourseOriginalPrice().divide(new BigDecimal(musicGroupPaymentCalenderCourseSettings.getCourseTotalMinuties()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
+ BigDecimal unitMinuteOriginalPrice = totalCourseOriginalPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
//课程每分钟现价
|
|
//课程每分钟现价
|
|
- BigDecimal unitMinuteCurrentPrice = musicGroupPaymentCalenderCourseSettings.getCourseCurrentPrice().divide(new BigDecimal(musicGroupPaymentCalenderCourseSettings.getCourseTotalMinuties()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
+ BigDecimal unitMinuteCurrentPrice = totalCourseCurrentPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
|
|
|
- if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(musicGroupPaymentCalender.getPayUserType())){
|
|
|
|
|
|
+ if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(musicGroupPaymentCalenders.get(0).getPayUserType())){
|
|
unitMinuteCurrentPrice = new BigDecimal("0");
|
|
unitMinuteCurrentPrice = new BigDecimal("0");
|
|
}
|
|
}
|
|
|
|
|
|
@@ -374,7 +386,7 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
|
|
cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
|
|
cssp.setCourseScheduleId(courseSchedule.getId());
|
|
cssp.setCourseScheduleId(courseSchedule.getId());
|
|
cssp.setClassGroupId(courseSchedule.getClassGroupId());
|
|
cssp.setClassGroupId(courseSchedule.getClassGroupId());
|
|
- cssp.setBatchNo(musicGroupPaymentCalender.getBatchNo());
|
|
|
|
|
|
+ cssp.setBatchNo(batchNo);
|
|
cssp.setUserId(studentId);
|
|
cssp.setUserId(studentId);
|
|
cssp.setOriginalPrice(courseOriginalPrice);
|
|
cssp.setOriginalPrice(courseOriginalPrice);
|
|
cssp.setExpectPrice(courseCurrentPrice);
|
|
cssp.setExpectPrice(courseCurrentPrice);
|
|
@@ -382,13 +394,21 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
typeCourseStudentPayments.add(cssp);
|
|
typeCourseStudentPayments.add(cssp);
|
|
}
|
|
}
|
|
|
|
|
|
- typeCourseStudentPayments.get(0).setOriginalPrice(typeCourseStudentPayments.get(0).getOriginalPrice().add(musicGroupPaymentCalenderCourseSettings.getCourseOriginalPrice().subtract(typeCourseTotalOriginalPrice)));
|
|
|
|
- if(MusicGroupPaymentCalender.PayUserType.STUDENT.equals(musicGroupPaymentCalender.getPayUserType())) {
|
|
|
|
- typeCourseStudentPayments.get(0).setExpectPrice(typeCourseStudentPayments.get(0).getExpectPrice().add(musicGroupPaymentCalenderCourseSettings.getCourseCurrentPrice().subtract(typeCourseTotalCurrentPrice)));
|
|
|
|
|
|
+ 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);
|
|
courseScheduleStudentPayments.addAll(typeCourseStudentPayments);
|
|
- musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(typeCourseDuration);
|
|
|
|
- musicGroupPaymentStudentCourseDetailDao.update(musicGroupPaymentStudentCourseDetail);
|
|
|
|
|
|
+ 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);
|
|
courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|