浏览代码

合班拆班

zouxuan 4 年之前
父节点
当前提交
924ea98ae3

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CourseScheduleStudentPayment.java

@@ -53,6 +53,8 @@ public class CourseScheduleStudentPayment implements Comparable<CourseScheduleSt
 
 	private String openPlayMidi;
 
+	private String examSongDownloadJson;
+
 	public CourseScheduleStudentPayment() {
 	}
 
@@ -68,6 +70,14 @@ public class CourseScheduleStudentPayment implements Comparable<CourseScheduleSt
 		this.courseScheduleId = courseScheduleId;
 	}
 
+	public String getExamSongDownloadJson() {
+		return examSongDownloadJson;
+	}
+
+	public void setExamSongDownloadJson(String examSongDownloadJson) {
+		this.examSongDownloadJson = examSongDownloadJson;
+	}
+
 	public String getOpenPlayMidi() {
 		return openPlayMidi;
 	}

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupStudentClassAdjust.java

@@ -34,6 +34,9 @@ public class MusicGroupStudentClassAdjust {
 	@ApiModelProperty(value = "所选学员冻结的课程列表", required = false)
 	private String subLockCourseIds;
 
+	@ApiModelProperty(value = "学员对应的缴费项目", required = false)
+	private String studentCalenderIds;
+
 	@ApiModelProperty(value = "是否排课", required = false)
 	private boolean courseFlag;
 
@@ -43,6 +46,14 @@ public class MusicGroupStudentClassAdjust {
 
 	private Date updateTime;
 
+	public String getStudentCalenderIds() {
+		return studentCalenderIds;
+	}
+
+	public void setStudentCalenderIds(String studentCalenderIds) {
+		this.studentCalenderIds = studentCalenderIds;
+	}
+
 	public Integer getId() {
 		return id;
 	}

+ 7 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -3345,7 +3345,8 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         //生成缴费记录,同一个批次
         MusicGroupPaymentCalender.PaymentCalenderStatusEnum status = null;
         String batchNo = null;
-                List<MusicGroupPaymentCalenderDto> paymentCalenderDtos = mergeClassSplitClassAffirmDto.getMusicGroupPaymentCalenderDtos();
+        List<MusicGroupPaymentCalenderDto> paymentCalenderDtos = mergeClassSplitClassAffirmDto.getMusicGroupPaymentCalenderDtos();
+        List<Map<String,String>> studentCalenderIds = new ArrayList<>();
         if(paymentCalenderDtos != null && paymentCalenderDtos.size() > 0){
             batchNo = idGeneratorService.generatorId() + "";
             for (MusicGroupPaymentCalenderDto calenderDto : paymentCalenderDtos) {
@@ -3373,13 +3374,17 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 }
                 //指定批次
                 calenderDto.setBatchNo(batchNo);
-                musicGroupPaymentCalenderService.create(calenderDto);
+                String calenderIds = musicGroupPaymentCalenderService.create(calenderDto);
+                Map<String,String> studentCalenderIdMap = new HashMap<>(1);
+                studentCalenderIdMap.put(calenderDto.getStudentIds(),calenderIds);
+                studentCalenderIds.add(studentCalenderIdMap);
             }
         }
 
         //记录申请信息
         MusicGroupStudentClassAdjust musicGroupStudentClassAdjust = new MusicGroupStudentClassAdjust();
         musicGroupStudentClassAdjust.setBatchNo(batchNo);
+        musicGroupStudentClassAdjust.setStudentCalenderIds(JSON.toJSONString(studentCalenderIds));
         musicGroupStudentClassAdjust.setCourseFlag(false);
         musicGroupStudentClassAdjust.setMusicGroupId(musicGroup.getId());
         musicGroupStudentClassAdjust.setOperatorId(sysUser.getId());

+ 61 - 19
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -1,6 +1,7 @@
 package com.ym.mec.biz.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.CourseScheduleStudentListDto;
@@ -67,6 +68,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private StudentRegistrationService studentRegistrationService;
 	@Autowired
 	private MusicGroupStudentClassAdjustDao musicGroupStudentClassAdjustDao;
+	@Autowired
+	private SysConfigDao sysConfigDao;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -310,34 +313,73 @@ 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,String batchNo) {
 		//获取合班时的缴费项目
-		MusicGroupStudentClassAdjust byBatchNo = musicGroupStudentClassAdjustDao.findByBatchNo(batchNo);
+		List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByBatchNo(batchNo);
 		//获取提交的合班申请
 		MusicGroupStudentClassAdjust classAdjust = musicGroupStudentClassAdjustDao.findByBatchNo(batchNo);
 		List<CourseScheduleStudentPayment> courseScheduleStudentPayments = new ArrayList<>();
 		List<Long> courseIds = JSON.parseArray(classAdjust.getSubLockCourseIds(), Long.class);
+
+		Map<CourseSchedule.CourseScheduleType, Integer> courseTypeCourseDurationMap = new HashMap<>();
+		Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
+		for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCoursesEntry : typeCourseMap.entrySet()) {
+			int totalCourseDuration = 0;
+			for (CourseSchedule courseSchedule : typeCoursesEntry.getValue()) {
+				//课程时长
+				int courseDuration = DateUtil.minutesBetween(courseSchedule.getStartClassTime(), courseSchedule.getEndClassTime());
+				totalCourseDuration += courseDuration;
+			}
+			courseTypeCourseDurationMap.put(typeCoursesEntry.getKey(), totalCourseDuration);
+		}
+
+		//获取默认的排课时长
+		String courseDefaultMinutes = sysConfigDao.findConfigValue("music_course_default_minutes");
+		JSONObject jsonObject = JSON.parseObject(courseDefaultMinutes);
+
 		for (Integer studentId : studentIds) {
 			//优先处理之前剩余的课程
 			List<CourseScheduleStudentPayment> studentPayments = courseScheduleStudentPaymentDao.queryCourseByIdsAndStudentId(courseIds,studentId);
-			Map<Long, List<CourseScheduleStudentPayment>> collect = null;
-			if(studentPayments != null && studentPayments.size() >0 ){
-				collect = studentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getCourseScheduleId));
-			}
-			for (CourseSchedule courseSchedule : courseSchedules) {
-				//
-				if(studentPayments != null && studentPayments.size() >0 ){
-					List<CourseScheduleStudentPayment> payments = collect.get(courseSchedule.getId());
-					if(payments != null && payments.size() > 0){
-						//复制之前的数据
-						CourseScheduleStudentPayment scheduleStudentPayment = payments.get(0);
-						scheduleStudentPayment.setCourseScheduleId(courseSchedule.getId());
-						scheduleStudentPayment.setClassGroupId(courseSchedule.getClassGroupId());
-						scheduleStudentPayment.setOpenPlayMidi(null);
-
+			for (int i = 0; i < courseSchedules.size(); i++) {
+				CourseSchedule courseSchedule = courseSchedules.get(i);
+				//优先处理之前的剩余课程
+				if(studentPayments != null && studentPayments.size() > 0 && i < studentPayments.size()){
+					for (int j = 0; j < studentPayments.size(); j++) {
+						CourseScheduleStudentPayment studentPayment = studentPayments.get(i);
+						studentPayment.setCourseScheduleId(courseSchedule.getId());
+						studentPayment.setClassGroupId(courseSchedule.getClassGroupId());
+						studentPayment.setOpenPlayMidi(null);
+						studentPayment.setSettlementTime(null);
+						studentPayment.setExamSongDownloadJson(null);
+						courseScheduleStudentPayments.add(studentPayment);
+						break;
 					}
-				}
-				//如果合班时生成了缴费项目
-				if(byBatchNo != null){
+					Set<Long> calenderIds = musicGroupPaymentCalenders.stream().map(e -> e.getId()).collect(Collectors.toSet());
+					List<MusicGroupPaymentCalenderCourseSettings> musicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalendersAndCourseType(calenderIds, null);
+					Map<Long, List<MusicGroupPaymentCalenderCourseSettings>> collect = musicGroupPaymentCalenderCourseSettings.stream().collect(Collectors.groupingBy(MusicGroupPaymentCalenderCourseSettings::getMusicGroupPaymentCalenderId));
+					for (MusicGroupPaymentCalender musicGroupPaymentCalender : musicGroupPaymentCalenders) {
+						MusicGroupPaymentCalenderCourseSettings courseSetting = collect.get(musicGroupPaymentCalender.getId()).get(0);
+						//课程每分钟原价
+						BigDecimal unitMinuteOriginalPrice = courseSetting.getCourseOriginalPrice().divide(new BigDecimal(courseSetting.getCourseTotalMinuties()), CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+						//课程每分钟现价
+						BigDecimal unitMinuteCurrentPrice = courseSetting.getCourseCurrentPrice().divide(new BigDecimal(courseSetting.getCourseTotalMinuties()), CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+
+						//默认课程时长
+						int courseDuration = Integer.parseInt(jsonObject.get(courseSchedule.getType().getCode()).toString());
+						BigDecimal courseOriginalPrice = unitMinuteOriginalPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+						//课程现价
+						BigDecimal courseCurrentPrice = unitMinuteCurrentPrice.multiply(new BigDecimal(courseDuration)).setScale(CommonConstants.DECIMAL_FINAL_PLACE, BigDecimal.ROUND_DOWN);
+						CourseScheduleStudentPayment cssp = new CourseScheduleStudentPayment();
+						cssp.setGroupType(courseSchedule.getGroupType());
+						cssp.setMusicGroupId(courseSchedule.getMusicGroupId());
+						cssp.setCourseScheduleId(courseSchedule.getId());
+						cssp.setClassGroupId(courseSchedule.getClassGroupId());
+						cssp.setBatchNo(batchNo);
+						cssp.setUserId(studentId);
+						cssp.setOriginalPrice(courseOriginalPrice);
+						cssp.setExpectPrice(courseCurrentPrice);
+						cssp.setActualPrice(BigDecimal.ZERO);
+						courseScheduleStudentPayments.add(cssp);
 
+					}
 				}
 			}
 		}

+ 9 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -238,6 +238,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			}
 		});
 
+		//获取缴费项目编号列表
+		StringBuffer calenderIds = new StringBuffer();
 		for (int i = 0; i < musicGroupPaymentDateRangeList.size(); i++) {
 
 			MusicGroupPaymentDateRange musicGroupPaymentDateRange = musicGroupPaymentDateRangeList.get(i);
@@ -347,6 +349,10 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			// 设置批次号
 			musicGroupPaymentCalender.setBatchNo(batchNo);
 			musicGroupPaymentCalenderDao.insert(musicGroupPaymentCalender);
+			if(calenderIds.length() > 0){
+				calenderIds.append(",");
+			}
+			calenderIds.append(musicGroupPaymentCalender.getId());
 
 			List<MusicGroupPaymentCalenderCourseSettings> currentMusicGroupPaymentCalenderCourseSettings = musicGroupPaymentCalender
 					.getMusicGroupPaymentCalenderCourseSettingsList();
@@ -400,7 +406,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			sysMessageService.batchSeoMessage(musicGroupDao.queryUserIdByRoleId(roleIds, musicGroup.getOrganId()),
 					MessageTypeEnum.BACKSTAGE_PAYMENT_CALENDER_AUDIT, "", organization.getName(), musicGroup.getName());
 		}
-
+		if(StringUtils.isNotEmpty(musicGroupPaymentCalenderDto.getBatchNo())){
+			return calenderIds.toString();
+		}
 		return batchNo;
 	}
 

+ 3 - 1
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderCourseSettingsMapper.xml

@@ -119,7 +119,9 @@
 			<foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
 				#{calenderId}
 			</foreach>
-			AND course_type_=#{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+			<if test="courseType != null">
+				AND course_type_=#{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+			</if>
 	</select>
 
 	<delete id="deleteByMusicGroupPaymentCalenderId">