|
@@ -73,6 +73,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
private MusicGroupStudentClassAdjustDao musicGroupStudentClassAdjustDao;
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderDao studentPaymentOrderDaop;
|
|
|
+ @Autowired
|
|
|
+ private OrganizationCourseUnitPriceSettingsDao organizationCourseUnitPriceSettingsDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
|
|
@@ -389,8 +391,7 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
public void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds) {
|
|
|
Map<Integer, List<CourseSchedule>> memberCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getMemberFlag));
|
|
|
- //课程是否需要标记为云教练赠送
|
|
|
- Boolean cloudTeacherPaymentFlag = false;
|
|
|
+ List<Long> operatingCourse = new ArrayList<>();
|
|
|
Long calenderId = null;
|
|
|
for (Integer memberFlag : memberCourseMap.keySet()) {
|
|
|
List<CourseSchedule> courseScheduleList = memberCourseMap.get(memberFlag);
|
|
@@ -426,8 +427,6 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
|
|
|
List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
|
|
|
|
|
|
- List<String> allBatchNos = new ArrayList<>();
|
|
|
-
|
|
|
for (Integer studentId : studentIds) {
|
|
|
Set<Long> existCourseIds = new HashSet<>();
|
|
|
if(studentCourseIdsMap.containsKey(studentId)){
|
|
@@ -437,8 +436,6 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
//当前课程类型总课程时长
|
|
|
Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey()).get(studentId);
|
|
|
|
|
|
- String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey(),null);
|
|
|
-
|
|
|
List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(studentId, courseScheduleTypeListEntry.getKey(),musicGroupId);
|
|
|
int subCourseMinutes = musicGroupPaymentStudentCourseDetails.stream().mapToInt(MusicGroupPaymentStudentCourseDetail::getSubCourseMinutes).reduce(0, Integer::sum);
|
|
|
if(CollectionUtils.isEmpty(musicGroupPaymentStudentCourseDetails) || subCourseMinutes < typeCourseDuration){
|
|
@@ -453,29 +450,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
throw new BizException("缴费设置异常");
|
|
|
}
|
|
|
|
|
|
- List<MusicGroupPaymentCalenderCourseSettings> musicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalendersAndCourseType(calenderIds, courseScheduleTypeListEntry.getKey());
|
|
|
- int originalCourseTotalMinutes = musicGroupPaymentCalenderCourseSettings.stream().mapToInt(MusicGroupPaymentCalenderCourseSettings::getCourseTotalMinuties).reduce(0, Integer::sum);
|
|
|
- if(Objects.isNull(musicGroupPaymentCalenderCourseSettings) || originalCourseTotalMinutes != subCourseMinutes){
|
|
|
- throw new BizException("缴费设置异常");
|
|
|
- }
|
|
|
-
|
|
|
- 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 = totalCourseOriginalPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
- //课程每分钟现价
|
|
|
- BigDecimal unitMinuteCurrentPrice = totalCourseCurrentPrice.divide(new BigDecimal(originalCourseTotalMinutes), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
-
|
|
|
- if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(musicGroupPaymentCalenders.get(0).getPayUserType())){
|
|
|
- unitMinuteCurrentPrice = new BigDecimal("0");
|
|
|
- }
|
|
|
-
|
|
|
List<CourseScheduleStudentPayment> typeCourseStudentPayments = new ArrayList<>();
|
|
|
courseScheduleTypeListEntry.getValue().sort(Comparator.comparing(CourseSchedule::getStartClassTime));
|
|
|
- BigDecimal typeCourseTotalOriginalPrice = new BigDecimal("0"), typeCourseTotalCurrentPrice = new BigDecimal("0");
|
|
|
List<CourseSchedule> scheduleList = courseScheduleTypeListEntry.getValue();
|
|
|
for (CourseSchedule courseSchedule : scheduleList) {
|
|
|
if(existCourseIds.contains(courseSchedule.getId())){
|
|
@@ -483,48 +459,16 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
}
|
|
|
//课程时长
|
|
|
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);
|
|
|
+ CourseScheduleStudentPayment cssp = this.init(courseSchedule);
|
|
|
cssp.setUserId(studentId);
|
|
|
- cssp.setOriginalPrice(courseOriginalPrice);
|
|
|
- cssp.setExpectPrice(courseCurrentPrice);
|
|
|
- cssp.setActualPrice(BigDecimal.ZERO);
|
|
|
- cssp.setBeMerged(false);
|
|
|
+ //扣除可排课时长
|
|
|
+ if(this.calcCourseMinutes(musicGroupPaymentStudentCourseDetails,courseDuration,cssp,musicGroupPaymentCalenders)){
|
|
|
+ //课程是否需要标记为云教练赠送
|
|
|
+ operatingCourse.add(courseSchedule.getId());
|
|
|
+ }
|
|
|
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 detail : musicGroupPaymentStudentCourseDetails) {
|
|
|
- if(typeCourseDuration>detail.getTotalCourseMinutes()){
|
|
|
- detail.setUsedCourseMinutes(detail.getTotalCourseMinutes());
|
|
|
- typeCourseDuration = typeCourseDuration-detail.getTotalCourseMinutes();
|
|
|
- }else{
|
|
|
- detail.setUsedCourseMinutes(typeCourseDuration);
|
|
|
- typeCourseDuration = 0;
|
|
|
- }
|
|
|
- //如果是免费的云教练课程
|
|
|
- if(detail.getCloudTeacherPaymentFlag() && !cloudTeacherPaymentFlag){
|
|
|
- cloudTeacherPaymentFlag = true;
|
|
|
- calenderId = detail.getMusicGroupPaymentCalenderId();
|
|
|
- }
|
|
|
- }
|
|
|
musicGroupPaymentStudentCourseDetailDao.batchUpdate(musicGroupPaymentStudentCourseDetails);
|
|
|
}
|
|
|
}
|
|
@@ -532,11 +476,61 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- if(cloudTeacherPaymentFlag){
|
|
|
- operatingReportCloudService.updateSet(calenderId,courseSchedules.stream().map(e->e.getId()).collect(Collectors.toList()));
|
|
|
+ if(!CollectionUtils.isEmpty(operatingCourse)){
|
|
|
+ operatingReportCloudService.updateSet(calenderId,operatingCourse);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Boolean calcCourseMinutes(List<MusicGroupPaymentStudentCourseDetail> courseDetails,
|
|
|
+ Integer courseDuration,
|
|
|
+ CourseScheduleStudentPayment studentPayment,
|
|
|
+ List<MusicGroupPaymentCalender> musicGroupPaymentCalenders){
|
|
|
+ Boolean result = true;
|
|
|
+ Integer courseMinutes = courseDuration;
|
|
|
+ Map<Long, List<MusicGroupPaymentCalender>> calenderMap = musicGroupPaymentCalenders.stream().collect(Collectors.groupingBy(MusicGroupPaymentCalender::getId));
|
|
|
+ for (int i = 0; i < courseDetails.size(); i++) {
|
|
|
+ MusicGroupPaymentStudentCourseDetail detail = courseDetails.get(i);
|
|
|
+ if(detail.getSubCourseMinutes() > 0){
|
|
|
+ if(!detail.getCloudTeacherPaymentFlag()){
|
|
|
+ result = false;
|
|
|
+ }
|
|
|
+ if(courseMinutes >= detail.getSubCourseMinutes()){
|
|
|
+ detail.setUsedCourseMinutes(detail.getUsedCourseMinutes() + detail.getSubCourseMinutes());
|
|
|
+ detail.setSubCourseMinutes(0);
|
|
|
+ courseMinutes = courseMinutes - detail.getSubCourseMinutes();
|
|
|
+ studentPayment.setOriginalPrice(detail.getSubCourseOriginalPrice());
|
|
|
+ studentPayment.setExpectPrice(detail.getSubCourseCurrentPrice());
|
|
|
+ detail.setSubCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
+ detail.setSubCourseOriginalPrice(BigDecimal.ZERO);
|
|
|
+ }else{
|
|
|
+ detail.setUsedCourseMinutes(detail.getUsedCourseMinutes() + courseDuration);
|
|
|
+ detail.setSubCourseMinutes(detail.getSubCourseMinutes() - courseDuration);
|
|
|
+ //课程每分钟现价
|
|
|
+ BigDecimal unitMinuteCurrentPrice = detail.getCourseCurrentPrice().divide(new BigDecimal(detail.getTotalCourseMinutes()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ BigDecimal unitMinuteOriginalPrice = detail.getCourseOriginalPrice().divide(new BigDecimal(detail.getTotalCourseMinutes()), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN);
|
|
|
+ BigDecimal originalPrice = unitMinuteOriginalPrice.multiply(new BigDecimal(courseMinutes)).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+ BigDecimal expectPrice = unitMinuteCurrentPrice.multiply(new BigDecimal(courseMinutes)).setScale(2, BigDecimal.ROUND_DOWN);
|
|
|
+ studentPayment.setOriginalPrice(originalPrice);
|
|
|
+ studentPayment.setExpectPrice(expectPrice);
|
|
|
+ detail.setSubCourseCurrentPrice(detail.getSubCourseOriginalPrice().subtract(originalPrice));
|
|
|
+ detail.setSubCourseOriginalPrice(detail.getSubCourseCurrentPrice().subtract(expectPrice));
|
|
|
+ courseMinutes = 0;
|
|
|
+ }
|
|
|
+ if(MusicGroupPaymentCalender.PayUserType.SCHOOL.equals(calenderMap.get(detail.getMusicGroupPaymentCalenderId()).get(0).getPayUserType())){
|
|
|
+ studentPayment.setExpectPrice(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ if(courseMinutes == 0){
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(i == courseDetails.size() - 1 && courseMinutes > 0){
|
|
|
+ throw new BizException("操作失败:学员可排课时长不足");
|
|
|
+ }
|
|
|
}
|
|
|
+ return result;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
|
|
|
public void createForMemberMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds) {
|
|
@@ -762,7 +756,19 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
|
|
|
courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
+ @Override
|
|
|
+ public CourseScheduleStudentPayment init(CourseSchedule courseSchedule) {
|
|
|
+ CourseScheduleStudentPayment cssp = new CourseScheduleStudentPayment();
|
|
|
+ cssp.setGroupType(courseSchedule.getGroupType());
|
|
|
+ cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
|
|
|
+ cssp.setCourseScheduleId(courseSchedule.getId());
|
|
|
+ cssp.setClassGroupId(courseSchedule.getClassGroupId());
|
|
|
+ cssp.setActualPrice(BigDecimal.ZERO);
|
|
|
+ cssp.setBeMerged(false);
|
|
|
+ return cssp;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void updateCourseActualPrice(List<String> groupIds, List<Integer> userIds, GroupType groupType) {
|
|
|
studentDao.lockUser(1);
|