|
@@ -1,21 +1,194 @@
|
|
|
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.service.MusicGroupPaymentStudentCourseDetailService;
|
|
|
+import com.ym.mec.biz.service.StudentMusicCourseFeeService;
|
|
|
import com.ym.mec.common.dal.BaseDAO;
|
|
|
import com.ym.mec.common.service.impl.BaseServiceImpl;
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
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.stream.Collectors;
|
|
|
+
|
|
|
+import static com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PayUserType.SCHOOL;
|
|
|
|
|
|
@Service
|
|
|
public class MusicGroupPaymentStudentCourseDetailServiceImpl extends BaseServiceImpl<Long, MusicGroupPaymentStudentCourseDetail> implements MusicGroupPaymentStudentCourseDetailService {
|
|
|
|
|
|
@Autowired
|
|
|
private MusicGroupPaymentStudentCourseDetailDao musicGroupPaymentStudentCourseDetailDao;
|
|
|
+ @Autowired
|
|
|
+ private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentMusicCourseFeeService studentMusicCourseFeeService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, MusicGroupPaymentStudentCourseDetail> getDAO() {
|
|
|
return musicGroupPaymentStudentCourseDetailDao;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void batchInsert(Set<Integer> userIdList,
|
|
|
+ MusicGroupPaymentCalender calender,
|
|
|
+ Map<Integer, Long> userCalenderDetailMap) {
|
|
|
+ List<MusicGroupPaymentCalenderCourseSettings> courseSettingsList = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalender(calender.getId());
|
|
|
+ //创建学生课排课分钟数
|
|
|
+ if (courseSettingsList != null && courseSettingsList.size() > 0) {
|
|
|
+ List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetailList = new ArrayList<>();
|
|
|
+ MusicGroupPaymentStudentCourseDetail musicGroupPaymentStudentCourseDetail = null;
|
|
|
+ Long calenderId = calender.getId();
|
|
|
+ String musicGroupId = calender.getMusicGroupId();
|
|
|
+ MusicGroupPaymentCalender.PayUserType payUserType = calender.getPayUserType();
|
|
|
+ Boolean cloudTeacherPaymentFlag = calender.getCloudTeacherPaymentFlag();
|
|
|
+ for (Integer studentId : userIdList) {
|
|
|
+ BigDecimal reduce = BigDecimal.ZERO;
|
|
|
+
|
|
|
+ for (MusicGroupPaymentCalenderCourseSettings courseSettings : courseSettingsList) {
|
|
|
+ if (courseSettings.getCourseTotalMinuties() == null || courseSettings.getCourseTotalMinuties() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ musicGroupPaymentStudentCourseDetail = new MusicGroupPaymentStudentCourseDetail();
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupId(musicGroupId);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseType(courseSettings.getCourseType());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupPaymentCalenderId(calenderId);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupPaymentCalenderDetailId(userCalenderDetailMap.get(studentId));
|
|
|
+ musicGroupPaymentStudentCourseDetail.setTotalCourseMinutes(courseSettings.getCourseTotalMinuties());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseMinutes(courseSettings.getCourseTotalMinuties());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseOriginalPrice(courseSettings.getCourseOriginalPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(courseSettings.getCourseCurrentPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseOriginalPrice(courseSettings.getCourseOriginalPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(courseSettings.getCourseCurrentPrice());
|
|
|
+ if(payUserType == SCHOOL){
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(0);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUserId(studentId);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCloudTeacherPaymentFlag(cloudTeacherPaymentFlag);
|
|
|
+ musicGroupPaymentStudentCourseDetailList.add(musicGroupPaymentStudentCourseDetail);
|
|
|
+ reduce = reduce.add(musicGroupPaymentStudentCourseDetail.getCourseCurrentPrice());
|
|
|
+ }
|
|
|
+ if(reduce.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ //汇总学员乐团课费,如果有溢出的乐器费用、云教练费用,也一并汇总,用于计算经营报表
|
|
|
+ studentMusicCourseFeeService.addExpectPrice(studentId,musicGroupId,reduce);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (musicGroupPaymentStudentCourseDetailList.size() > 0) {
|
|
|
+ musicGroupPaymentStudentCourseDetailDao.batchInsert(musicGroupPaymentStudentCourseDetailList);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void batchInsert(Integer userId, MusicGroupPaymentCalender musicGroupPaymentCalender, Long calenderDetailId, Long paymentOrderId) {
|
|
|
+ //续费项目加学员时就生成了课程时长,报名项目在缴费成功后才需要添加课程时长
|
|
|
+ if (musicGroupPaymentCalender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.MUSIC_APPLY) {
|
|
|
+ List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = new ArrayList<>();
|
|
|
+ List<String> orderDetailTypes = studentPaymentOrderDetailDao.getOrderDetailType(paymentOrderId);
|
|
|
+ List<MusicGroupPaymentCalenderCourseSettings> courseSettingsList = musicGroupPaymentCalenderCourseSettingsDao
|
|
|
+ .getWithPaymentCalender(musicGroupPaymentCalender.getId());
|
|
|
+ Boolean cloudTeacherPaymentFlag = musicGroupPaymentCalender.getCloudTeacherPaymentFlag();
|
|
|
+ BigDecimal reduce = BigDecimal.ZERO;
|
|
|
+ for (MusicGroupPaymentCalenderCourseSettings courseSetting : courseSettingsList) {
|
|
|
+ if (musicGroupPaymentCalender.getPayUserType().equals(MusicGroupPaymentCalender.PayUserType.STUDENT)
|
|
|
+ && !orderDetailTypes.contains(courseSetting.getCourseType().getCode())) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (courseSetting.getCourseTotalMinuties() == null || courseSetting.getCourseTotalMinuties() == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ MusicGroupPaymentStudentCourseDetail musicGroupPaymentStudentCourseDetail = new MusicGroupPaymentStudentCourseDetail();
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupId(musicGroupPaymentCalender.getMusicGroupId());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupPaymentCalenderId(musicGroupPaymentCalender.getId());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setMusicGroupPaymentCalenderDetailId(calenderDetailId);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUserId(userId);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseType(courseSetting.getCourseType());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setTotalCourseMinutes(courseSetting.getCourseTotalMinuties());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseMinutes(courseSetting.getCourseTotalMinuties());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseOriginalPrice(courseSetting.getCourseOriginalPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(courseSetting.getCourseCurrentPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseOriginalPrice(courseSetting.getCourseOriginalPrice());
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(courseSetting.getCourseCurrentPrice());
|
|
|
+ if(musicGroupPaymentCalender.getPayUserType() == SCHOOL){
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setSubCourseCurrentPrice(BigDecimal.ZERO);
|
|
|
+ }
|
|
|
+ musicGroupPaymentStudentCourseDetail.setUsedCourseMinutes(0);
|
|
|
+ musicGroupPaymentStudentCourseDetail.setCloudTeacherPaymentFlag(cloudTeacherPaymentFlag);
|
|
|
+ musicGroupPaymentStudentCourseDetails.add(musicGroupPaymentStudentCourseDetail);
|
|
|
+ }
|
|
|
+ if(reduce.compareTo(BigDecimal.ZERO) > 0){
|
|
|
+ //汇总学员乐团课费,如果有溢出的乐器费用、云教练费用,也一并汇总,用于计算经营报表
|
|
|
+ studentMusicCourseFeeService.addExpectPrice(userId,musicGroupPaymentCalender.getMusicGroupId(),reduce);
|
|
|
+ }
|
|
|
+ if (musicGroupPaymentStudentCourseDetails.size() > 0) {
|
|
|
+ musicGroupPaymentStudentCourseDetailDao.batchInsert(musicGroupPaymentStudentCourseDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<MusicGroupPaymentStudentCourseDetail> queryByMusicGroupPaymentStudentCourseDetailId(List<Long> musicGroupPaymentCalenderDetailIdList) {
|
|
|
+ return musicGroupPaymentStudentCourseDetailDao.queryByMusicGroupPaymentStudentCourseDetailId(musicGroupPaymentCalenderDetailIdList);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteByMusicGroupPaymentCalenderDetailId(List<Long> musicGroupPaymentCalenderDetailIdList) {
|
|
|
+ this.delByDetails(musicGroupPaymentStudentCourseDetailDao.queryByMusicGroupPaymentStudentCourseDetailId(musicGroupPaymentCalenderDetailIdList));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteByMusicGroupPaymentCalenderId(String calenderId,Integer userId) {
|
|
|
+ this.delByDetails(musicGroupPaymentStudentCourseDetailDao.findByCalenderAndUserId(calenderId, userId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void deleteByUserIdAndMusicGroupId(Integer userId, String musicGroupId) {
|
|
|
+ this.delByDetails(musicGroupPaymentStudentCourseDetailDao.findByUserIdAndMusicGroupId(userId, musicGroupId));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void clearRemainCourseMinutesByMusicGroupId(String musicGroupId) {
|
|
|
+ musicGroupPaymentStudentCourseDetailDao.clearRemainCourseMinutesByMusicGroupId(musicGroupId);
|
|
|
+ }
|
|
|
+
|
|
|
+ void delByDetails(List<MusicGroupPaymentStudentCourseDetail> courseDetails){
|
|
|
+ if(CollectionUtils.isNotEmpty(courseDetails)){
|
|
|
+ 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());
|
|
|
+ if(CollectionUtils.isNotEmpty(courseDetails)){
|
|
|
+ Map<Integer, List<MusicGroupPaymentStudentCourseDetail>> userMap = courseDetails.stream().collect(Collectors.groupingBy(e -> e.getUserId()));
|
|
|
+ for (Integer userId : userMap.keySet()) {
|
|
|
+ List<MusicGroupPaymentStudentCourseDetail> studentCourseDetails = userMap.get(userId);
|
|
|
+ Map<String, BigDecimal> priceMap = studentCourseDetails.stream().collect(Collectors.groupingBy(e -> e.getMusicGroupId(),
|
|
|
+ Collectors.collectingAndThen(Collectors.toList(), v -> v.stream().map(e -> e.getCourseCurrentPrice()).reduce(BigDecimal.ZERO, BigDecimal::add))));
|
|
|
+ for (String musicGroupId : priceMap.keySet()) {
|
|
|
+ studentMusicCourseFeeService.cutExpectPrice(userId,musicGroupId,priceMap.get(musicGroupId));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|