|
@@ -1,11 +1,10 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderCourseSettingsDao;
|
|
|
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentStudentCourseDetailDao;
|
|
|
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings;
|
|
|
-import com.ym.mec.biz.dal.entity.MusicGroupPaymentStudentCourseDetail;
|
|
|
+import com.ym.mec.biz.dal.dao.*;
|
|
|
+import com.ym.mec.biz.dal.dto.StudentApplyInstrumentDto;
|
|
|
+import com.ym.mec.biz.dal.entity.*;
|
|
|
+import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
|
|
|
+import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
|
|
|
import com.ym.mec.biz.service.MusicGroupPaymentStudentCourseDetailService;
|
|
|
import com.ym.mec.biz.service.StudentMusicCourseFeeService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
@@ -16,13 +15,11 @@ import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.Set;
|
|
|
+import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import static com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PayUserType.SCHOOL;
|
|
|
+import static com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PayUserType.STUDENT;
|
|
|
|
|
|
@Service
|
|
|
public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseServiceImpl<Long, MusicGroupPaymentStudentCourseDetail> implements MusicGroupPaymentStudentCourseDetailService {
|
|
@@ -35,6 +32,14 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
private StudentMusicCourseFeeService studentMusicCourseFeeService;
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupDao musicGroupDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentRegistrationDao studentRegistrationDao;
|
|
|
+ @Autowired
|
|
|
+ private ChargeTypeSubjectMapperDao chargeTypeSubjectMapperDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentCourseFeeDetailDao studentCourseFeeDetailDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, MusicGroupPaymentStudentCourseDetail> getDAO() {
|
|
@@ -83,10 +88,10 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
musicGroupPaymentStudentCourseDetailList.add(musicGroupPaymentStudentCourseDetail);
|
|
|
reduce = reduce.add(musicGroupPaymentStudentCourseDetail.getCourseCurrentPrice());
|
|
|
}
|
|
|
- if(reduce.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+// if(reduce.compareTo(BigDecimal.ZERO) > 0){
|
|
|
//汇总学员乐团课费,如果有溢出的乐器费用、云教练费用,也一并汇总,用于计算经营报表
|
|
|
- studentMusicCourseFeeService.addExpectPrice(studentId,musicGroupId,reduce);
|
|
|
- }
|
|
|
+// studentMusicCourseFeeService.addExpectPrice(studentId,musicGroupId,reduce);
|
|
|
+// }
|
|
|
}
|
|
|
if (musicGroupPaymentStudentCourseDetailList.size() > 0) {
|
|
|
musicGroupPaymentStudentCourseDetailDao.batchInsert(musicGroupPaymentStudentCourseDetailList);
|
|
@@ -104,7 +109,40 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
List<MusicGroupPaymentCalenderCourseSettings> courseSettingsList = musicGroupPaymentCalenderCourseSettingsDao
|
|
|
.getWithPaymentCalender(musicGroupPaymentCalender.getId());
|
|
|
Boolean cloudTeacherPaymentFlag = musicGroupPaymentCalender.getCloudTeacherPaymentFlag();
|
|
|
- BigDecimal reduce = BigDecimal.ZERO;
|
|
|
+ String musicGroupId = musicGroupPaymentCalender.getMusicGroupId();
|
|
|
+ MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
|
|
|
+ //免费团,并且购买乐器
|
|
|
+ BigDecimal musicalFee = BigDecimal.ZERO;
|
|
|
+ if(musicGroup.getCourseViewType() == CourseViewTypeEnum.FREE){
|
|
|
+ StudentPaymentOrderDetail orderMusical = studentPaymentOrderDetailDao.findApplyOrderMusical(paymentOrderId);
|
|
|
+ if(Objects.nonNull(orderMusical)){
|
|
|
+ //如果是免费团,那么要处理乐器溢出的课程费用
|
|
|
+ CourseViewTypeEnum courseViewType = musicGroup.getCourseViewType();
|
|
|
+ StudentRegistration studentRegistration = studentRegistrationDao.queryByUserIdAndMusicGroupId(userId, musicGroupId);
|
|
|
+ Integer subjectId = studentRegistration.getActualSubjectId();
|
|
|
+ ChargeTypeSubjectMapper chargeType = chargeTypeSubjectMapperDao.findByViewTypeANdSubject(courseViewType,subjectId,musicGroup.getTenantId());
|
|
|
+ if(Objects.nonNull(chargeType) && chargeType.getFee() != null && orderMusical.getPrice().compareTo(BigDecimal.ZERO) > 0
|
|
|
+ && chargeType.getFee().compareTo(orderMusical.getPrice()) < 0){
|
|
|
+ musicalFee = orderMusical.getPrice().subtract(chargeType.getFee());
|
|
|
+ //累加充值金额
|
|
|
+ studentRegistrationDao.updateCourseFee(studentRegistration.getId(),musicalFee);
|
|
|
+ //添加日志
|
|
|
+ StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
|
|
|
+ studentCourseFeeDetail.setTenantId(musicGroup.getTenantId());
|
|
|
+ studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
|
|
|
+ studentCourseFeeDetail.setAmount(musicalFee);
|
|
|
+ studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(musicalFee));
|
|
|
+ studentCourseFeeDetail.setMemo("免费团,购买乐器赠送课费");
|
|
|
+ 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)
|
|
|
&& !orderDetailTypes.contains(courseSetting.getCourseType().getCode())) {
|
|
@@ -122,9 +160,9 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
musicGroupPaymentStudentCourseDetail.setTotalCourseMinutes(courseSetting.getCourseTotalMinuties());
|
|
|
musicGroupPaymentStudentCourseDetail.setSubCourseMinutes(courseSetting.getCourseTotalMinuties());
|
|
|
musicGroupPaymentStudentCourseDetail.setCourseOriginalPrice(courseSetting.getCourseOriginalPrice());
|
|
|
- musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(courseSetting.getOverflowCoursePrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(courseSetting.getOverflowCoursePrice().add(musicalFee));
|
|
|
musicGroupPaymentStudentCourseDetail.setSubCourseOriginalPrice(courseSetting.getCourseOriginalPrice());
|
|
|
- musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(courseSetting.getOverflowCoursePrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(courseSetting.getOverflowCoursePrice().add(musicalFee));
|
|
|
if(musicGroupPaymentCalender.getPayUserType() == SCHOOL){
|
|
|
musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(BigDecimal.ZERO);
|
|
@@ -133,16 +171,53 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
musicGroupPaymentStudentCourseDetail.setCloudTeacherPaymentFlag(cloudTeacherPaymentFlag);
|
|
|
musicGroupPaymentStudentCourseDetails.add(musicGroupPaymentStudentCourseDetail);
|
|
|
}
|
|
|
- if(reduce.compareTo(BigDecimal.ZERO) > 0){
|
|
|
- //汇总学员乐团课费,如果有溢出的乐器费用、云教练费用,也一并汇总,用于计算经营报表
|
|
|
- studentMusicCourseFeeService.addExpectPrice(userId,musicGroupPaymentCalender.getMusicGroupId(),reduce);
|
|
|
- }
|
|
|
if (musicGroupPaymentStudentCourseDetails.size() > 0) {
|
|
|
+ if(musicGroupPaymentCalender.getPayUserType() == STUDENT && musicGroup.getCourseViewType() == CourseViewTypeEnum.FREE) {
|
|
|
+ List<StudentPaymentOrderDetail> instrumentDtos = studentPaymentOrderDetailDao.getWithUserAndOrderType(userId, musicGroupId, OrderDetailTypeEnum.MUSICAL);
|
|
|
+ //是否买过乐器
|
|
|
+ if(CollectionUtils.isNotEmpty(instrumentDtos)){
|
|
|
+ StudentPaymentOrderDetail orderMusical = instrumentDtos.get(0);
|
|
|
+ //如果是免费团,那么要处理乐器溢出的课程费用
|
|
|
+ CourseViewTypeEnum courseViewType = musicGroup.getCourseViewType();
|
|
|
+ StudentRegistration studentRegistration = studentRegistrationDao.queryByUserIdAndMusicGroupId(userId, musicGroupId);
|
|
|
+ Integer subjectId = studentRegistration.getActualSubjectId();
|
|
|
+ ChargeTypeSubjectMapper chargeType = chargeTypeSubjectMapperDao.findByViewTypeANdSubject(courseViewType,subjectId,musicGroup.getTenantId());
|
|
|
+ if(Objects.nonNull(chargeType) && chargeType.getFee() != null && orderMusical.getPrice().compareTo(BigDecimal.ZERO) > 0
|
|
|
+ && chargeType.getFee().compareTo(orderMusical.getPrice()) < 0){
|
|
|
+ musicalFee = orderMusical.getPrice().subtract(chargeType.getFee());
|
|
|
+ distributeTotalAmount(musicGroupPaymentStudentCourseDetails,musicalFee);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
musicGroupPaymentStudentCourseDetailDao.batchInsert(musicGroupPaymentStudentCourseDetails);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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()));
|
|
|
+ courseDetail.setSubCourseCurrentPrice(courseDetail.getCourseCurrentPrice());
|
|
|
+ remainingAmount = remainingAmount.subtract(itemAmount);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将剩余的金额放在最后一个Item对象中
|
|
|
+ MusicGroupPaymentStudentCourseDetail lastItem = courseDetails.get(lastIndex);
|
|
|
+ lastItem.setCourseCurrentPrice(lastItem.getCourseCurrentPrice().add(remainingAmount));
|
|
|
+ lastItem.setSubCourseCurrentPrice(lastItem.getCourseCurrentPrice());
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public List<MusicGroupPaymentStudentCourseDetail> queryByMusicGroupPaymentStudentCourseDetailId(List<Long> musicGroupPaymentCalenderDetailIdList) {
|
|
|
return musicGroupPaymentStudentCourseDetailDao.queryByMusicGroupPaymentStudentCourseDetailId(musicGroupPaymentCalenderDetailIdList);
|
|
@@ -177,7 +252,7 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
List<Long> courseDetailIds = courseDetails.stream().map(e -> e.getId()).collect(Collectors.toList());
|
|
|
musicGroupPaymentStudentCourseDetailDao.delByIds(courseDetailIds);
|
|
|
//汇总学员乐团课费,如果有溢出的乐器费用、云教练费用,也一并汇总,用于计算经营报表
|
|
|
- courseDetails = courseDetails.stream().filter(e -> e.getCourseCurrentPrice().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
|
+ /*courseDetails = courseDetails.stream().filter(e -> e.getCourseCurrentPrice().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
|
|
|
if(CollectionUtils.isNotEmpty(courseDetails)){
|
|
|
Map<Integer, List<MusicGroupPaymentStudentCourseDetail>> userMap = courseDetails.stream().collect(Collectors.groupingBy(e -> e.getUserId()));
|
|
|
for (Integer userId : userMap.keySet()) {
|
|
@@ -188,7 +263,7 @@ public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseService
|
|
|
studentMusicCourseFeeService.cutExpectPrice(userId,musicGroupId,priceMap.get(musicGroupId));
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }*/
|
|
|
}
|
|
|
}
|
|
|
}
|