zouxuan 4 vuotta sitten
vanhempi
commit
67b8336eaf

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/CourseScheduleStudentPaymentDao.java

@@ -401,4 +401,13 @@ public interface CourseScheduleStudentPaymentDao extends BaseDAO<Long, CourseSch
      * @return java.util.List<com.ym.mec.biz.dal.entity.CourseScheduleStudentPaymentDto>
      */
     List<CourseScheduleStudentPaymentDto> findNeedUpdateActualPriceStudentCourses();
+
+    /**
+     * 根据课程编号和,学员编号获取列表信息
+     * @author zouxuan
+     * @param courseIds
+     * @param studentId
+     * @return
+     */
+    List<CourseScheduleStudentPayment> queryCourseByIdsAndStudentId(@Param("courseIds") List<Long> courseIds, @Param("studentId") Integer studentId);
 }

+ 2 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentStudentCourseDetailDao.java

@@ -42,7 +42,8 @@ public interface MusicGroupPaymentStudentCourseDetailDao extends BaseDAO<Long, M
      */
     String getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(@Param("musicGroupId") String musicGroupId,
                                                                    @Param("studentId") Integer studentId,
-                                                                   @Param("courseType") CourseSchedule.CourseScheduleType courseType);
+                                                                   @Param("courseType") CourseSchedule.CourseScheduleType courseType,
+                                                                   @Param("batchNo") String batchNo);
 
     /**
      * @param studentIds:

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/ClassGroup4MixDto.java

@@ -57,6 +57,17 @@ public class ClassGroup4MixDto {
     @ApiModelProperty(value = "班级剩余时长,用于自动排课", required = true)
     private String classCourseMinute;
 
+    @ApiModelProperty(value = "批次号,用于自动排课", required = true)
+    private String batchNo;
+
+    public String getBatchNo() {
+        return batchNo;
+    }
+
+    public void setBatchNo(String batchNo) {
+        this.batchNo = batchNo;
+    }
+
     public String getClassCourseMinute() {
         return classCourseMinute;
     }

+ 14 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/MergeClassSplitClassAffirmDto.java

@@ -1,6 +1,10 @@
 package com.ym.mec.biz.dal.dto;
 
 
+import com.alibaba.fastjson.JSON;
+import org.json.JSONArray;
+import org.json.JSONObject;
+
 import java.util.List;
 
 public class MergeClassSplitClassAffirmDto {
@@ -12,6 +16,16 @@ public class MergeClassSplitClassAffirmDto {
 
     private List<Integer> studentIds;
 
+    private List<String> classGroupStudents;
+
+    public List<String> getClassGroupStudents() {
+        return classGroupStudents;
+    }
+
+    public void setClassGroupStudents(List<String> classGroupStudents) {
+        this.classGroupStudents = classGroupStudents;
+    }
+
     public List<Integer> getStudentIds() {
         return studentIds;
     }

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java

@@ -75,6 +75,17 @@ public interface CourseScheduleStudentPaymentService extends BaseService<Long, C
 	void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds);
 
 	/**
+	 * @describe 创建课程缴费记录-乐团-用于合班拆班自动排课
+	 * @author zouxuan
+	 * @date 2020.10.27
+	 * @param musicGroupId: 乐团编号
+	 * @param courseSchedules: 课程计划列表
+	 * @param studentIds: 课程学员列表
+	 * @return void
+	 */
+	void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds,String batchNo);
+
+	/**
 	 * @describe 根据缴费日历更新乐团课程学院课程价格
 	 * @author Joburgess
 	 * @date 2020.10.29

+ 20 - 14
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -34,6 +34,7 @@ import com.ym.mec.biz.service.*;
 import com.ym.mec.common.service.IdGeneratorService;
 import org.apache.commons.beanutils.BeanUtils;
 import org.apache.commons.lang3.StringUtils;
+import org.json.JSONArray;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
@@ -1672,14 +1673,17 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         if (classGroup4MixDtos.get(0).getCourseTimes().compareTo(0) <= 0) {
             throw new BizException("排课次数必须大于0");
         }
-        List<ClassGroup4MixDto> classGroup4MixDtosBackup = new ArrayList<>();
+        //准备自动排课数据
+        List<ClassGroup4MixDto> classGroup4MixDtosBackup = Arrays.asList(new ClassGroup4MixDto[classGroup4MixDtos.size()]);
+        String batchNo = classGroup4MixDtos.get(0).getBatchNo();
         if(StringUtils.isNotEmpty(classGroup4MixDtos.get(0).getClassCourseMinute())){
             try {
-                classGroup4MixDtosBackup = (List<ClassGroup4MixDto>)BeanUtils.cloneBean(classGroup4MixDtos);
+                Collections.copy(classGroup4MixDtosBackup,classGroup4MixDtos);
             } catch (Exception e) {
                 throw new BizException("拷贝课程信息异常");
             }
         }
+
         Date entryDate = DateUtil.stringToDate(sysConfigDao.findByParamName(SysConfigService.TEACHER_ENTRY_DATE).getParanValue(), "yyyy-MM-dd");
         Integer schoolId = musicGroup.getSchoolId();
 
@@ -1792,6 +1796,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         String classCourseMinute = null;
         for (ClassGroup4MixDto classGroup4MixDto : classGroup4MixDtos) {
             List<CourseSchedule> courseSchedules = new ArrayList<>();
+            courseSchedules.clear();
             if(classGroup4MixDto.getCourseTimeDtoList() == null || classGroup4MixDto.getCourseTimeDtoList().size() == 0){
                 break;
             }
@@ -1799,17 +1804,17 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             LocalDateTime now = LocalDate.parse(classGroup4MixDto.getStartDate(), DateTimeFormatter.ofPattern("yyyy-MM-dd")).atStartOfDay();
             //是否是合班后的自动排课
             classCourseMinute = classGroup4MixDto.getClassCourseMinute();
+            long courseDuration = Duration.between(LocalDateTime.parse(classGroup4MixDto.getStartDate() + " " + classGroup4MixDto.getCourseTimeDtoList().get(0).getStartClassTime() + ":00", formatter),
+                    LocalDateTime.parse(classGroup4MixDto.getStartDate() + " " + classGroup4MixDto.getCourseTimeDtoList().get(0).getEndClassTime() + ":00", formatter))
+                    .toMinutes();
             if(StringUtils.isNotEmpty(classCourseMinute)){
                 Map<String, Integer> classCourseMinuteMap = JSON.parseObject(classCourseMinute, Map.class);
-                classGroup4MixDto.setCourseTimes(classCourseMinuteMap.get(classGroup4MixDto.getCourseType().getCode()));
+                classGroup4MixDto.setCourseTimes(classCourseMinuteMap.get(classGroup4MixDto.getCourseType().getCode())/(int)courseDuration);
             }else {
                 if(!courseTypeMinutesMap.containsKey(classGroup4MixDto.getCourseType().getCode())){
                     throw new BizException("{}课程类型暂无剩余课程时长", classGroup4MixDto.getCourseType().getMsg());
                 }
                 Integer totalMinutes = courseTypeMinutesMap.get(classGroup4MixDto.getCourseType().getCode());
-                long courseDuration = Duration.between(LocalDateTime.parse(classGroup4MixDto.getStartDate() + " " + classGroup4MixDto.getCourseTimeDtoList().get(0).getStartClassTime() + ":00", formatter),
-                        LocalDateTime.parse(classGroup4MixDto.getStartDate() + " " + classGroup4MixDto.getCourseTimeDtoList().get(0).getEndClassTime() + ":00", formatter))
-                        .toMinutes();
                 classGroup4MixDto.setCourseTimes(totalMinutes/(int)courseDuration);
 
                 if(classGroup4MixDto.getCourseTimes()<=0){
@@ -1817,7 +1822,6 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 }
             }
 
-
             int times = 0;
 
             Set<String> holidayDays = new HashSet<>();
@@ -1985,8 +1989,6 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 try {
                     courseScheduleService.checkNewCourseSchedules(courseSchedules, false);
                 }catch (BizException e){
-                    e.printStackTrace();
-                }finally {
                     //如果出现冲突
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
                     //排课开始时间加一周
@@ -2010,7 +2012,11 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         }
         //学生结算表
         if (courseScheduleList.size() > 0) {
-            courseScheduleStudentPaymentService.createForMusicGroup(musicGroupId, courseScheduleList, studentIdList);
+            if(StringUtils.isEmpty(classCourseMinute)){
+                courseScheduleStudentPaymentService.createForMusicGroup(musicGroupId, courseScheduleList, studentIdList);
+            }else {
+                courseScheduleStudentPaymentService.createForMusicGroup(musicGroupId, courseScheduleList, studentIdList,batchNo);
+            }
         }
         return classGroup;
     }
@@ -3374,13 +3380,13 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         //记录申请信息
         MusicGroupStudentClassAdjust musicGroupStudentClassAdjust = new MusicGroupStudentClassAdjust();
         musicGroupStudentClassAdjust.setBatchNo(batchNo);
-        musicGroupStudentClassAdjust.setBatchNo(batchNo);
         musicGroupStudentClassAdjust.setCourseFlag(false);
         musicGroupStudentClassAdjust.setMusicGroupId(musicGroup.getId());
         musicGroupStudentClassAdjust.setOperatorId(sysUser.getId());
         musicGroupStudentClassAdjust.setNewClassGroupJson(JSON.toJSONString(classGroup4MixDtos));
         musicGroupStudentClassAdjust.setClassGroupIds(JSON.toJSONString(classGroupIds));
         musicGroupStudentClassAdjust.setStudentIds(JSON.toJSONString(studentIds));
+
         //获取需要冻结的课程
         List<Long> allLockCourseIds = courseScheduleDao.queryStudentNotStartByClassIdsAndStudentIds(classGroupIds,null);
         musicGroupStudentClassAdjust.setAllLockCourseIds(JSON.toJSONString(allLockCourseIds));
@@ -3390,7 +3396,6 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         //计算新增班级的可排课时长,总课次*默认时长  (用学员剩余的课程时长加上购买的时长,可能导致同一班级学员时长不一致)
         musicGroupStudentClassAdjust.setClassCourseMinute(JSON.toJSONString(findClassCourseMinuteMap(classGroupIds)));
 
-
         //如果需要审核,校验参数配置
         checkMergeClassSplitClassAffirmParam(classGroup4MixDtos);
         //如果缴费项目不需要审核,那么生成班级以及课表
@@ -3398,7 +3403,8 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
             ClassGroup4MixDto classGroup4MixDto = classGroup4MixDtos.get(0);
             classGroup4MixDto.setClassCourseMinute(musicGroupStudentClassAdjust.getClassCourseMinute());
             List<CourseTimeDto> courseTimeDtoList = classGroup4MixDto.getCourseTimeDtoList();
-            List<CourseTimeDto> courseTimeDtoListBackup = (List<CourseTimeDto>)BeanUtils.cloneBean(courseTimeDtoList);
+            List<CourseTimeDto> courseTimeDtoListBackup = Arrays.asList(new CourseTimeDto[courseTimeDtoList.size()]);
+            Collections.copy(courseTimeDtoListBackup,courseTimeDtoList);
             //每种课程类型单独排课
             for (CourseTimeDto courseTimeDto : courseTimeDtoListBackup) {
                 List<CourseTimeDto> courseTimeDtos = new ArrayList<>();
@@ -3417,7 +3423,6 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         }
         musicGroupStudentClassAdjustDao.insert(musicGroupStudentClassAdjust);
     }
-    //审核通过后排课,删除指定课程,并解冻当前班级课程
 
     private void checkMergeClassSplitClassAffirmParam(List<ClassGroup4MixDto> classGroup4MixDtos){
         if (classGroup4MixDtos.get(0).getCourseTimes().compareTo(0) <= 0) {
@@ -3431,6 +3436,7 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         if(noRepeatTeacherIds.size()!=classGroupTeacherMapperList.size()){
             throw new BizException("主教与助教存在冲突");
         }
+        //所选课程不能有未开始的临时合并课程
         List<Integer> allTeacherIds = classGroupTeacherMapperList.stream()
                 .map(ClassGroupTeacherMapper::getUserId)
                 .collect(Collectors.toList());

+ 37 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.CourseScheduleStudentListDto;
@@ -64,6 +65,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private SubjectDao subjectDao;
 	@Autowired
 	private StudentRegistrationService studentRegistrationService;
+	@Autowired
+	private MusicGroupStudentClassAdjustDao musicGroupStudentClassAdjustDao;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -305,6 +308,38 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 
 	@Override
 	@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);
+		//获取提交的合班申请
+		MusicGroupStudentClassAdjust classAdjust = musicGroupStudentClassAdjustDao.findByBatchNo(batchNo);
+		List<Long> courseIds = JSON.parseArray(classAdjust.getSubLockCourseIds(), Long.class);
+		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){
+
+					}
+				}
+				//如果合班时生成了缴费项目
+				if(byBatchNo != null){
+
+				}
+			}
+		}
+	}
+
+
+	@Override
+	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
 	public void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds) {
 		Map<CourseSchedule.CourseScheduleType, Integer> courseTypeCourseDurationMap = new HashMap<>();
 		Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> typeCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
@@ -327,11 +362,11 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 				//当前课程类型总课程时长
 				Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey());
 
-				String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey());
+				String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, studentId, courseScheduleTypeListEntry.getKey(),null);
 
 				List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(batchNo, studentId, courseScheduleTypeListEntry.getKey());
 				int totalCourseMinutes = musicGroupPaymentStudentCourseDetails.stream().mapToInt(MusicGroupPaymentStudentCourseDetail::getTotalCourseMinutes).reduce(0, Integer::sum);
-				if(CollectionUtils.isEmpty(musicGroupPaymentStudentCourseDetails)||totalCourseMinutes<typeCourseDuration){
+				if(CollectionUtils.isEmpty(musicGroupPaymentStudentCourseDetails) || totalCourseMinutes < typeCourseDuration){
 					SysUser user = teacherDao.getUser(studentId);
 					throw new BizException("{}在{}课程类型上的课程时长不足", user.getUsername(), courseScheduleTypeListEntry.getKey().getMsg());
 				}

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

@@ -147,7 +147,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 			throw new BizException("请登录");
 		}
 		// 所有缴费项目已完成排课才能创建下一个缴费项目
-		String orignBatchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, null, null);
+		String orignBatchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, null, null,null);
 		if (StringUtils.isNoneBlank(orignBatchNo)) {
 			if(StringUtils.isEmpty(musicGroupPaymentCalenderDto.getBatchNo()) || !musicGroupPaymentCalenderDto.getBatchNo().equals(orignBatchNo)){
 				throw new BizException("当前乐团存在未排课的缴费项目,请先完成排课再操作");
@@ -880,9 +880,9 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		ClassGroup4MixDto classGroup4MixDto = classGroup4MixDtos.get(0);
 		classGroup4MixDto.setClassCourseMinute(musicGroupStudentClassAdjust.getClassCourseMinute());
 		List<CourseTimeDto> courseTimeDtoList = classGroup4MixDto.getCourseTimeDtoList();
-		List<CourseTimeDto> courseTimeDtoListBackup = new ArrayList<>();
+		List<CourseTimeDto> courseTimeDtoListBackup = Arrays.asList(new CourseTimeDto[courseTimeDtoList.size()]);
 		try {
-			courseTimeDtoListBackup = (List<CourseTimeDto>)BeanUtils.cloneBean(courseTimeDtoList);
+			Collections.copy(courseTimeDtoListBackup,courseTimeDtoList);
 		} catch (Exception e) {
 			throw new BizException("拷贝课程信息异常");
 		}

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

@@ -1317,7 +1317,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 //当前课程类型总课程时长
                 Integer typeCourseDuration = courseTypeCourseDurationMap.get(courseScheduleTypeListEntry.getKey());
 
-                String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, student.getUserId(), courseScheduleTypeListEntry.getKey());
+                String batchNo = musicGroupPaymentStudentCourseDetailDao.getUnUseBatchNoWithStudentAndCourseTypeAndCourseMinutes(musicGroupId, student.getUserId(), courseScheduleTypeListEntry.getKey(),null);
 
                 List<MusicGroupPaymentStudentCourseDetail> musicGroupPaymentStudentCourseDetails = musicGroupPaymentStudentCourseDetailDao.getUnUseWithStudentAndCourseTypeAndCourseMinutes(batchNo, student.getUserId(), courseScheduleTypeListEntry.getKey());
                 int totalCourseMinutes = musicGroupPaymentStudentCourseDetails.stream().mapToInt(MusicGroupPaymentStudentCourseDetail::getTotalCourseMinutes).reduce(0, Integer::sum);

+ 7 - 0
mec-biz/src/main/resources/config/mybatis/CourseScheduleStudentPaymentMapper.xml

@@ -632,4 +632,11 @@
 			AND ((cs.status_ = 'OVER' AND (cssp.actual_price_ IS NULL OR cssp.actual_price_ &lt;= 0))
 			OR ( cs.status_ = 'NOT_START' AND (cssp.actual_price_ IS NOT NULL AND cssp.actual_price_ &gt; 0)))
 	</select>
+	<select id="queryCourseByIdsAndStudentId" resultMap="CourseScheduleStudentPayment">
+		SELECT * FROM course_schedule_student_payment WHERE course_schedule_id_ IN
+		<foreach collection="courseIds" open="(" item="item" close=")" separator=",">
+			#{item}
+		</foreach>
+		AND user_id_ = #{studentId}
+	</select>
 </mapper>

+ 3 - 0
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentStudentCourseDetailMapper.xml

@@ -156,6 +156,9 @@
             <if test="studentId != null">
             AND mgpscd.user_id_ = #{studentId}
             </if>
+            <if test="batchNo != null">
+            AND mgpc.batch_no_ = #{batchNo}
+            </if>
             <if test="courseType != null">
             AND mgpscd.course_type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
             </if>