|
@@ -135,6 +135,11 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
studentCourseFeeDetail.setOperator(userId);
|
|
|
studentCourseFeeDetailDao.insert(studentCourseFeeDetail);
|
|
|
}
|
|
|
+ List<MusicGroupPaymentStudentCourseDetail> courseDetails = musicGroupPaymentStudentCourseDetailDao.findByCalenderAndUserId(musicGroupPaymentCalender.getId().toString(), userId);
|
|
|
+ if(CollectionUtils.isNotEmpty(courseDetails)){
|
|
|
+ distributeTotalAmount(courseDetails,musicalFee);
|
|
|
+ musicGroupPaymentStudentCourseDetailDao.batchUpdate(courseDetails);
|
|
|
+ }
|
|
|
}
|
|
|
for (MusicGroupPaymentCalenderCourseSettings courseSetting : courseSettingsList) {
|
|
|
if (musicGroupPaymentCalender.getPayUserType().equals(MusicGroupPaymentCalender.PayUserType.STUDENT)
|
|
@@ -170,6 +175,28 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ public static void distributeTotalAmount(List<MusicGroupPaymentStudentCourseDetail> courseDetails, BigDecimal totalAmount) {
|
|
|
+ if(CollectionUtils.isEmpty(courseDetails) || BigDecimal.ZERO.compareTo(totalAmount) == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ BigDecimal remainingAmount = totalAmount;
|
|
|
+ int lastIndex = courseDetails.size() - 1;
|
|
|
+ BigDecimal totalUnitPrice = courseDetails.stream().map(e -> e.getCourseOriginalPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+
|
|
|
+ // 分摊总金额
|
|
|
+ for (int i = 0; i < lastIndex; i++) {
|
|
|
+ MusicGroupPaymentStudentCourseDetail courseDetail = courseDetails.get(i);
|
|
|
+ BigDecimal ratio = courseDetail.getCourseOriginalPrice().divide(totalUnitPrice, 10, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal itemAmount = totalAmount.multiply(ratio).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ courseDetail.setCourseCurrentPrice(itemAmount.add(courseDetail.getCourseCurrentPrice()));
|
|
|
+ remainingAmount = remainingAmount.subtract(itemAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将剩余的金额放在最后一个Item对象中
|
|
|
+ MusicGroupPaymentStudentCourseDetail lastItem = courseDetails.get(lastIndex);
|
|
|
+ lastItem.setCourseCurrentPrice(lastItem.getCourseCurrentPrice().add(remainingAmount));
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<MusicGroupPaymentStudentCourseDetail> queryByMusicGroupPaymentStudentCourseDetailId(List<Long> musicGroupPaymentCalenderDetailIdList) {
|
|
|
return musicGroupPaymentStudentCourseDetailDao.queryByMusicGroupPaymentStudentCourseDetailId(musicGroupPaymentCalenderDetailIdList);
|