Browse Source

feat:乐团费用改造

Joburgess 5 years ago
parent
commit
338ca790e7

+ 12 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentCalenderCourseSettingsDao.java

@@ -2,8 +2,19 @@ package com.ym.mec.biz.dal.dao;
 
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings;
 import com.ym.mec.common.dal.BaseDAO;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
 
 public interface MusicGroupPaymentCalenderCourseSettingsDao extends BaseDAO<Integer, MusicGroupPaymentCalenderCourseSettings> {
 
+    /**
+     * @describe 获取指定缴费日历的课程价格设置
+     * @author Joburgess
+     * @date 2020.10.27
+     * @param calenderId:
+     * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderCourseSettings>
+     */
+    List<MusicGroupPaymentCalenderCourseSettings> getWithPaymentCalender(@Param("calenderId") Long calenderId);
 	
-}
+}

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

@@ -129,4 +129,13 @@ public interface MusicGroupPaymentCalenderDao extends BaseDAO<Long, MusicGroupPa
      * @return com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender
      */
     MusicGroupPaymentCalender getMusicGroupUnusedFirstPaymentCalender(@Param("musicGroupId") String musicGroupId);
+
+    /**
+     * @describe 获取指定缴费日历中下未使用的最早的缴费记录
+     * @author Joburgess
+     * @date 2020.10.27
+     * @param calenderIds:
+     * @return com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender
+     */
+    MusicGroupPaymentCalender getUnusedFirstPaymentCalenderWithCalenders(@Param("calenderIds") List<Long> calenderIds);
 }

+ 12 - 3
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentCalenderDetailDao.java

@@ -136,12 +136,21 @@ public interface MusicGroupPaymentCalenderDetailDao extends BaseDAO<Long, MusicG
 	 */
     Integer countOpenPayment(@Param("musicGroupId") String musicGroupId, @Param("userId") Integer userId);
 
+	/**
+	 * @describe 获取指定缴费日历的详情
+	 * @author Joburgess
+	 * @date 2020.10.27
+	 * @param calenderId:
+	 * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail>
+	 */
+	List<MusicGroupPaymentCalenderDetail> getCalenderDetailWithCalender(@Param("calenderId") Long calenderId);
+
     /**
-     * @describe 获取指定缴费日历的详情
+     * @describe 获取乐团下未使用的缴费日历记录
      * @author Joburgess
      * @date 2020.10.27
-     * @param calenderId:
+     * @param musicGroupId:
      * @return java.util.List<com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail>
      */
-    List<MusicGroupPaymentCalenderDetail> getCalenderDetailWithCalender(@Param("calenderId") Long calenderId);
+    List<MusicGroupPaymentCalenderDetail> getUnusedPaymentCalenderWithMusicGroup(@Param("musicGroupId") String musicGroupId);
 }

+ 14 - 14
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderCourseSettings.java

@@ -14,10 +14,10 @@ public class MusicGroupPaymentCalenderCourseSettings {
 	private Integer musicGroupPaymentCalenderId;
 	
 	/** 课程类型 */
-	private String courseType;
+	private CourseSchedule.CourseScheduleType courseType;
 	
 	/** 课程总时间 */
-	private String courseTotalMinuties;
+	private Integer courseTotalMinuties;
 	
 	/** 单价 */
 	private java.math.BigDecimal unitPrice;
@@ -52,23 +52,23 @@ public class MusicGroupPaymentCalenderCourseSettings {
 	public Integer getMusicGroupPaymentCalenderId(){
 		return this.musicGroupPaymentCalenderId;
 	}
-			
-	public void setCourseType(String courseType){
+
+	public CourseSchedule.CourseScheduleType getCourseType() {
+		return courseType;
+	}
+
+	public void setCourseType(CourseSchedule.CourseScheduleType courseType) {
 		this.courseType = courseType;
 	}
-	
-	public String getCourseType(){
-		return this.courseType;
+
+	public Integer getCourseTotalMinuties() {
+		return courseTotalMinuties;
 	}
-			
-	public void setCourseTotalMinuties(String courseTotalMinuties){
+
+	public void setCourseTotalMinuties(Integer courseTotalMinuties) {
 		this.courseTotalMinuties = courseTotalMinuties;
 	}
-	
-	public String getCourseTotalMinuties(){
-		return this.courseTotalMinuties;
-	}
-			
+
 	public void setUnitPrice(java.math.BigDecimal unitPrice){
 		this.unitPrice = unitPrice;
 	}

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

@@ -38,6 +38,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
 	@Autowired
 	private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
+	@Autowired
+	private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -271,7 +273,27 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 
 	@Override
 	public void createForMusicGroup(String musicGroupId, List<CourseSchedule> courseSchedules, List<Integer> studentIds) {
-		MusicGroupPaymentCalender musicGroupUnusedFirstPaymentCalender = musicGroupPaymentCalenderDao.getMusicGroupUnusedFirstPaymentCalender(musicGroupId);
+		List<MusicGroupPaymentCalenderDetail> AllUnusedPaymentCalender = musicGroupPaymentCalenderDetailDao.getUnusedPaymentCalenderWithMusicGroup(musicGroupId);
+		if(CollectionUtils.isEmpty(AllUnusedPaymentCalender)){
+			throw new BizException("当前乐团无学员缴费信息");
+		}
+
+		Map<Long, Long> calenderStudentNumMap = AllUnusedPaymentCalender.stream().collect(Collectors.groupingBy(MusicGroupPaymentCalenderDetail::getMusicGroupPaymentCalenderId, Collectors.counting()));
+
+		//所有学员公共可用缴费日历编号
+		List<Long> calenderIds = new ArrayList<>();
+
+		for (Map.Entry<Long, Long> calenderIdStudentNumEntry : calenderStudentNumMap.entrySet()) {
+			if(calenderIdStudentNumEntry.getValue().intValue()==studentIds.size()){
+				calenderIds.add(calenderIdStudentNumEntry.getKey());
+			}
+		}
+
+		if(CollectionUtils.isEmpty(calenderIds)){
+			throw new BizException("部分学员无缴费信息");
+		}
+
+		MusicGroupPaymentCalender musicGroupUnusedFirstPaymentCalender = musicGroupPaymentCalenderDao.getUnusedFirstPaymentCalenderWithCalenders(calenderIds);
 		if(Objects.isNull(musicGroupUnusedFirstPaymentCalender)){
 			throw new BizException("当前乐团无未使用缴费记录");
 		}
@@ -281,6 +303,23 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 			throw new BizException("当前乐团无学员缴费信息");
 		}
 		Map<Integer, List<MusicGroupPaymentCalenderDetail>> studentPaymentCalenderMap = unusedPaymentCalender.stream().collect(Collectors.groupingBy(MusicGroupPaymentCalenderDetail::getUserId));
+
+		List<MusicGroupPaymentCalenderCourseSettings> calenderCourseSettings = musicGroupPaymentCalenderCourseSettingsDao.getWithPaymentCalender(musicGroupUnusedFirstPaymentCalender.getId());
+		if(CollectionUtils.isEmpty(calenderCourseSettings)){
+			throw new BizException("课程收费标准设置异常");
+		}
+		Map<CourseSchedule.CourseScheduleType, MusicGroupPaymentCalenderCourseSettings> courseTypeCourseSettingMap = calenderCourseSettings.stream().collect(Collectors.toMap(MusicGroupPaymentCalenderCourseSettings::getCourseType, cs -> cs, (c1, c2) -> c1));
+
+		Map<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseTypeCourseMap = courseSchedules.stream().collect(Collectors.groupingBy(CourseSchedule::getType));
+		for (Map.Entry<CourseSchedule.CourseScheduleType, List<CourseSchedule>> courseScheduleTypeListEntry : courseTypeCourseMap.entrySet()) {
+			CourseSchedule.CourseScheduleType courseType = courseScheduleTypeListEntry.getKey();
+			MusicGroupPaymentCalenderCourseSettings musicGroupPaymentCalenderCourseSettings = courseTypeCourseSettingMap.get(courseType);
+			if(musicGroupPaymentCalenderCourseSettings.isIsStudentOptional()){
+				//如果学生可选,则必须缴费才能排课
+			}
+
+		}
+
 		for (Integer studentId : studentIds) {
 			List<MusicGroupPaymentCalenderDetail> musicGroupPaymentCalenderDetails = studentPaymentCalenderMap.get(studentId);
 			if(CollectionUtils.isEmpty(musicGroupPaymentCalenderDetails)){
@@ -290,7 +329,9 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 			if(!musicGroupPaymentCalenderDetail.getMusicGroupPaymentCalenderId().equals(musicGroupUnusedFirstPaymentCalender.getId())){
 				throw new BizException("缴费信息异常");
 			}
+			for (CourseSchedule courseSchedule : courseSchedules) {
 
+			}
 		}
 	}
 }

+ 9 - 10
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderCourseSettingsMapper.xml

@@ -9,7 +9,7 @@
 		id="MusicGroupPaymentCalenderCourseSettings">
 		<result column="id_" property="id" />
 		<result column="music_group_payment_calender_id_" property="musicGroupPaymentCalenderId" />
-		<result column="course_type_" property="courseType" />
+		<result column="course_type_" property="courseType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler"/>
 		<result column="course_total_minuties_" property="courseTotalMinuties" />
 		<result column="unit_price_" property="unitPrice" />
 		<result column="course_original_price_" property="courseOriginalPrice" />
@@ -36,8 +36,8 @@
 		<!-- <selectKey resultClass="int" keyProperty="id" > SELECT SEQ_WSDEFINITION_ID.nextval 
 			AS ID FROM DUAL </selectKey> -->
 		INSERT INTO music_group_payment_calender_course_settings
-		(id_,music_group_payment_calender_id_,course_type_,course_total_minuties_,unit_price_,course_original_price_,course_current_price_,is_student_optional_,create_time_,update_time_)
-		VALUES(#{id},#{musicGroupPaymentCalenderId},#{courseType},#{courseTotalMinuties},#{unitPrice},#{courseOriginalPrice},#{courseCurrentPrice},#{isStudentOptional},#{createTime},#{updateTime})
+		(music_group_payment_calender_id_,course_type_,course_total_minuties_,unit_price_,course_original_price_,course_current_price_,is_student_optional_,create_time_,update_time_)
+		VALUES(#{musicGroupPaymentCalenderId},#{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{courseTotalMinuties},#{unitPrice},#{courseOriginalPrice},#{courseCurrentPrice},#{isStudentOptional},NOW(),NOW())
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->
@@ -54,9 +54,6 @@
 			<if test="unitPrice != null">
 				unit_price_ = #{unitPrice},
 			</if>
-			<if test="updateTime != null">
-				update_time_ = #{updateTime},
-			</if>
 			<if test="courseCurrentPrice != null">
 				course_current_price_ = #{courseCurrentPrice},
 			</if>
@@ -64,7 +61,7 @@
 				music_group_payment_calender_id_ = #{musicGroupPaymentCalenderId},
 			</if>
 			<if test="courseType != null">
-				course_type_ = #{courseType},
+				course_type_ = #{courseType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},
 			</if>
 			<if test="courseOriginalPrice != null">
 				course_original_price_ = #{courseOriginalPrice},
@@ -72,9 +69,7 @@
 			<if test="courseTotalMinuties != null">
 				course_total_minuties_ = #{courseTotalMinuties},
 			</if>
-			<if test="createTime != null">
-				create_time_ = #{createTime},
-			</if>
+				update_time_ = NOW()
 		</set>
 		WHERE id_ = #{id}
 	</update>
@@ -95,4 +90,8 @@
 	<select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM music_group_payment_calender_course_settings
 	</select>
+
+    <select id="getWithPaymentCalender" resultMap="MusicGroupPaymentCalenderCourseSettings">
+		SELECT * FROM music_group_payment_calender_course_settings WHERE music_group_payment_calender_id_=#{calenderId}
+	</select>
 </mapper>

+ 12 - 0
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderDetailMapper.xml

@@ -300,6 +300,7 @@
 		WHERE mgpcd.user_id_ = #{userId} AND mgpc.music_group_id_ = #{musicGroupId} AND (mgpc.payment_status_ = 1 OR mgpcd.open_ = 1)
 		AND mgpcd.payment_status_ != 'PAID_COMPLETED'
 	</select>
+
 	<select id="getCalenderDetailWithCalender" resultMap="MusicGroupPaymentCalenderDetail">
 		SELECT
 			mgpcd.*
@@ -308,4 +309,15 @@
 		WHERE
 			mgpc.music_group_payment_calender_id_ = #{calenderId}
 	</select>
+
+	<select id="getUnusedPaymentCalenderWithMusicGroup" resultMap="MusicGroupPaymentCalenderDetail">
+		SELECT
+			mgpcd.*
+		FROM
+			music_group_payment_calender_detail mgpcd
+			LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
+		WHERE
+			mgpc.music_group_id_ = #{musicGroupId}
+			AND NOT EXISTS ( SELECT id_ FROM course_schedule_student_payment WHERE batch_no_ = mgpcd.music_group_payment_calender_id_ AND music_group_id_ = #{musicGroupId} )
+	</select>
 </mapper>

+ 8 - 0
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderMapper.xml

@@ -292,4 +292,12 @@
         AND NOT EXISTS ( SELECT id_ FROM course_schedule WHERE batch_no_ = mgpc.id_ AND music_group_id_ = #{musicGroupId} )
         ORDER BY create_time_ LIMIT 1;
     </select>
+    <select id="getUnusedFirstPaymentCalenderWithCalenders" resultMap="MusicGroupPaymentCalender">
+        SELECT * FROM music_group_payment_calender mgpc
+        WHERE id_ IN
+        <foreach collection="calenderIds" item="calenderId" open="(" close=")" separator=",">
+            #{calenderId}
+        </foreach>
+        ORDER BY create_time_ LIMIT 1;
+    </select>
 </mapper>