Sfoglia il codice sorgente

Merge remote-tracking branch 'origin/master'

Joburgess 4 anni fa
parent
commit
deaede1141

+ 2 - 3
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderStudentDetail.java

@@ -177,20 +177,19 @@ public class MusicGroupPaymentCalenderStudentDetail {
 	public String toString() {
 		return "MusicGroupPaymentCalenderStudentDetail{" +
 				"userId=" + userId +
-				", courseOriginalPrice=" + courseOriginalPrice +
 				", courseCurrentPrice=" + courseCurrentPrice +
 				", courseType='" + courseType + '\'' +
 				", classGroupId=" + classGroupId +
 				'}';
 	}
 
+
 	@Override
 	public boolean equals(Object o) {
 		if (this == o) return true;
 		if (o == null || getClass() != o.getClass()) return false;
 		MusicGroupPaymentCalenderStudentDetail that = (MusicGroupPaymentCalenderStudentDetail) o;
 		return userId.equals(that.userId) &&
-				courseOriginalPrice.doubleValue()==(that.courseOriginalPrice.doubleValue()) &&
 				courseCurrentPrice.doubleValue()==(that.courseCurrentPrice.doubleValue()) &&
 				courseType.equals(that.courseType) &&
 				classGroupId.equals(that.classGroupId);
@@ -198,6 +197,6 @@ public class MusicGroupPaymentCalenderStudentDetail {
 
 	@Override
 	public int hashCode() {
-		return Objects.hash(userId, courseOriginalPrice.doubleValue(), courseCurrentPrice.doubleValue(), courseType, classGroupId);
+		return Objects.hash(userId, courseCurrentPrice.doubleValue(), courseType, classGroupId);
 	}
 }

+ 75 - 79
mec-biz/src/main/java/com/ym/mec/biz/service/impl/ClassGroupServiceImpl.java

@@ -3672,104 +3672,69 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         Map<Integer, Integer> studentCLassMap = new HashMap<>();
         List<Map<Integer, BigDecimal>> surplusCourseFeeMapList = new ArrayList<>();
         List<Map<String,String>> classGroupStudents = (List<Map<String,String>>)JSON.parse(classGroupStudentMap);
-//        Map<Integer,Map<String, BigDecimal>> classGroupUnitPriceMap = new HashMap<>();
-//        Map<Integer,Map<String, BigDecimal>> classSubCoursePriceMap = new HashMap<>();
+        //学员剩余课程价值
+        Map<Integer,BigDecimal> classGroupTotalPrice = new HashMap<>();
+        //主班剩余课程价值
+        Map<String, BigDecimal> masterTotalPriceMap = getMasterTotalPriceMap(masterClassGroupId);
+        BigDecimal masterTotalPrice = getMasterTotalPrice(masterClassGroupId);
         for (Map<String, String> classGroupStudent : classGroupStudents) {
             for (String integer : classGroupStudent.keySet()) {
                 //获取学员剩余课程费用
                 surplusCourseFeeMapList.addAll(studentRegistrationDao.querySurplusCourseFeeByClassGroupId(Integer.parseInt(integer),classGroupStudent.get(integer)));
-                MusicGroup byClassId = musicGroupDao.findByClassId(Integer.parseInt(integer));
-                if (byClassId == null){
-                    throw new BizException("操作失败:班级所在乐团状态不支持");
-                }
-                //学员可能来自不同的分部,获取对应的课程单价
-//                classGroupUnitPriceMap.put(Integer.parseInt(integer),MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(byClassId.getChargeTypeId(), byClassId.getOrganId())));
-
-                //获取班级剩余课程时长
-//                classSubCoursePriceMap.put(Integer.parseInt(integer),MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(Integer.parseInt(integer))));
                 String[] s = classGroupStudent.get(integer).split(",");
                 for (String s1 : s) {
+                    classGroupTotalPrice.put(Integer.parseInt(s1),courseScheduleStudentPaymentDao.querySubCoursePriceMap(Integer.parseInt(s1),Integer.parseInt(integer),null));
                     studentCLassMap.put(Integer.parseInt(s1),Integer.parseInt(integer));
                 }
             }
         }
         //学员剩余课程费用
         Map<Integer, BigDecimal> surplusCourseFeeMap = MapUtil.convertIntegerMap(surplusCourseFeeMapList);
-        //获取分布默认的课程类型单价
-        MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
-        Map<String, BigDecimal> masterUnitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
-        Set<String> masterKeySet = masterMap.keySet();
-        //计算主班课程类型剩余价值
-//        Map<String, BigDecimal> masterTotalPriceMap = new HashMap<>(masterKeySet.size());
-        //计算从班课程类型剩余价值
-        Map<String,Map<Integer, BigDecimal>> studentTotalPriceMap = new HashMap<>();
-        //学员缴费项目列表
+        List<String> courseTypes = new ArrayList(masterMap.keySet());
         List<MusicGroupPaymentCalenderStudentDetail> musicGroupPaymentCalenderStudentDetails = new ArrayList<>();
-        for (String s : masterKeySet) {
-            BigDecimal masterUnitPrice = masterUnitPriceMap.get(s);
-            if (masterUnitPrice == null) {
-                throw new BizException("分部默认课程类型单价不存在,请设置");
-            }
-            BigDecimal masterCourseTime = masterMap.get(s);
-            //获取主班剩余课程价值,按分部默认单价计算
-            //总价四舍五入取整
-            BigDecimal masterTotalPrice = masterUnitPrice.multiply(masterCourseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
-//            masterTotalPriceMap.put(s,masterTotalPrice);
-            //获取学员剩余课程价值
-            Map<Integer, BigDecimal> totalPriceMap = new HashMap<>();
-            //课程余额转移
-            for (Integer studentId : studentCLassMap.keySet()) {
-                //学员剩余课程价值
-                BigDecimal totalPrice = courseScheduleStudentPaymentDao.querySubCoursePriceMap(studentId,studentCLassMap.get(studentId),s);
-                //学员剩余课程余额
-                BigDecimal bigDecimal = surplusCourseFeeMap.get(studentId);
-                //创建学员缴费项目
+        for (Integer studentId : studentCLassMap.keySet()) {
+            //学员剩余课程价值
+            BigDecimal totalPrice = classGroupTotalPrice.get(studentId);
+            if(totalPrice == null){
+                totalPrice = BigDecimal.ZERO;
+            }
+            //学员剩余课程余额
+            BigDecimal bigDecimal = surplusCourseFeeMap.get(studentId);
+            if(bigDecimal == null){
+                bigDecimal = BigDecimal.ZERO;
+            }
+            //学员可带走的价值
+            BigDecimal subCourseAmount;
+            if(masterTotalPrice.doubleValue() >= totalPrice.doubleValue()){
+                subCourseAmount = totalPrice;
+            }else {
+                subCourseAmount = masterTotalPrice;
+            }
+            if(subCourseAmount.doubleValue() >= bigDecimal.doubleValue()){
+                subCourseAmount = bigDecimal;
+            }
+            for (int i = 0; i < courseTypes.size(); i++) {
+                BigDecimal masterPrice = masterTotalPriceMap.get(courseTypes.get(i));
                 MusicGroupPaymentCalenderStudentDetail calenderDto = new MusicGroupPaymentCalenderStudentDetail();
                 calenderDto.setClassGroupId(studentCLassMap.get(studentId));
-                //学员班级剩余课程价值
-//                Map<String, BigDecimal> subCoursePriceMap = classSubCoursePriceMap.get(calenderDto.getClassGroupId());
-//                Map<String, BigDecimal> unitPriceMap = classGroupUnitPriceMap.get(calenderDto.getClassGroupId());
-//                BigDecimal courseTime = subCoursePriceMap.get(s);
-//                BigDecimal unitPrice = unitPriceMap.get(s);
-//                if (unitPrice == null) {
-//                    throw new BizException("分部默认课程类型单价不存在,请设置");
-//                }
-                if(totalPrice == null){
-                    totalPrice = BigDecimal.ZERO;
-                }
-//                BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
-                totalPriceMap.put(studentId,totalPrice);
-                calenderDto.setMasterSubCoursePrice(masterTotalPrice);
-                BigDecimal subCourseAmount = new BigDecimal(Math.min(Math.min(masterTotalPrice.doubleValue(), totalPrice.doubleValue()), bigDecimal.doubleValue()));
-                calenderDto.setSubCourseAmount(subCourseAmount);
-                //如果剩余课程余额小于等于0
-                if(subCourseAmount.doubleValue() <= 0d){
-                    calenderDto.setCourseCurrentPrice(masterTotalPrice);
-                    calenderDto.setCourseOriginalPrice(masterTotalPrice);
+                if(subCourseAmount.doubleValue() >= masterPrice.doubleValue()){
+                    calenderDto.setSubCourseAmount(masterPrice);
+                    calenderDto.setCutAmount(masterPrice);
+                    subCourseAmount = subCourseAmount.subtract(masterPrice);
                 }else {
-                    //如果剩余课程余额大于等于总价值,那么补交0元
-                    if(subCourseAmount.doubleValue() >= masterTotalPrice.doubleValue()){
-                        calenderDto.setCutAmount(masterTotalPrice);
-                        calenderDto.setCourseCurrentPrice(BigDecimal.ZERO);
-                        calenderDto.setCourseOriginalPrice(BigDecimal.ZERO);
-                    }else {
-                        calenderDto.setCourseCurrentPrice(masterTotalPrice.subtract(subCourseAmount));
-                        calenderDto.setCutAmount(subCourseAmount);
-                        calenderDto.setCourseOriginalPrice(masterTotalPrice.subtract(subCourseAmount));
-                    }
-                    //剩余课程余额减去主班对应课程类型总的课程价值,负数就是需要补交的金额
-//                    bigDecimal = bigDecimal.subtract(totalPrice);
-                    surplusCourseFeeMap.put(studentId,bigDecimal.subtract(masterTotalPrice));
-                }
-//                calenderDto.setCourseTime(courseTime.intValue());
-                calenderDto.setCourseType(s);
-
+                    calenderDto.setSubCourseAmount(subCourseAmount);
+                    calenderDto.setCutAmount(subCourseAmount);
+                    subCourseAmount = BigDecimal.ZERO;
+                }
+                calenderDto.setCourseTime(masterMap.get(courseTypes.get(i)).intValue());
+                calenderDto.setMasterSubCoursePrice(masterPrice);
+                calenderDto.setCourseCurrentPrice(masterPrice.subtract(calenderDto.getCutAmount()));
+                calenderDto.setCourseType(courseTypes.get(i));
                 calenderDto.setPhone(phoneMaps.get(studentId));
                 calenderDto.setUserId(studentId);
                 calenderDto.setUsername(userNames.get(studentId));
                 musicGroupPaymentCalenderStudentDetails.add(calenderDto);
             }
-            studentTotalPriceMap.put(s,totalPriceMap);
         }
         return musicGroupPaymentCalenderStudentDetails;
     }
@@ -3779,8 +3744,8 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
     public BigDecimal getMasterTotalPrice(Integer masterClassGroupId) {
         //获取主班剩余时长
         Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
-        if(masterMap.size() <= 0){
-            throw new BizException("所选主班没有剩余课程,请重新选择");
+        if(masterMap.size() == 0){
+            throw new BizException("操作失败:所选主班没有剩余时长");
         }
         //获取分布默认的课程类型单价
         MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
@@ -3794,6 +3759,9 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
                 throw new BizException("分部默认课程类型单价不存在,请设置");
             }
             BigDecimal courseTime = masterMap.get(s);
+            if(courseTime == null){
+                courseTime = BigDecimal.ZERO;
+            }
             //获取主班剩余课程价值,按分部默认单价计算
             //总价四舍五入取整
             BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
@@ -3802,6 +3770,34 @@ public class ClassGroupServiceImpl extends BaseServiceImpl<Integer, ClassGroup>
         return masterTotalPrice;
     }
 
+    public Map<String,BigDecimal> getMasterTotalPriceMap(Integer masterClassGroupId) {
+        //获取主班剩余时长
+        Map<String, BigDecimal> masterMap = MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseTimeMap(masterClassGroupId));
+        if(masterMap.size() == 0){
+            throw new BizException("操作失败:所选主班没有剩余时长");
+        }
+        Map<String,BigDecimal> resultMap = new HashMap<>();
+        //获取分布默认的课程类型单价
+        MusicGroup musicGroup = musicGroupDao.findByClassGroupId(masterClassGroupId);
+        Map<String, BigDecimal> unitPriceMap = MapUtil.convertIntegerMap(organizationCourseUnitPriceSettingsDao.queryMapByOrganIdAndChargeTypeId(musicGroup.getChargeTypeId(), musicGroup.getOrganId()));
+        Set<String> masterKeySet = masterMap.keySet();
+        //计算主班课程类型剩余价值
+        for (String s : masterKeySet) {
+            BigDecimal unitPrice = unitPriceMap.get(s);
+            if (unitPrice == null) {
+                throw new BizException("分部默认课程类型单价不存在,请设置");
+            }
+            BigDecimal courseTime = masterMap.get(s);
+            if(courseTime == null){
+                courseTime = BigDecimal.ZERO;
+            }
+            //获取主班剩余课程价值,按分部默认单价计算
+            BigDecimal totalPrice = unitPrice.multiply(courseTime).setScale(0, BigDecimal.ROUND_HALF_UP);
+            resultMap.put(s,totalPrice);
+        }
+        return resultMap;
+    }
+
     @Override
     public Map<String, Long> querySubCourseTime(Integer classGroupId) {
         return MapUtil.convertIntegerMap(courseScheduleDao.querySubCourseNumMap(classGroupId));

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

@@ -718,6 +718,8 @@
 		SELECT SUM(cssp.expect_price_) FROM course_schedule_student_payment cssp
 		LEFT JOIN course_schedule cs ON cs.id_ = cssp.course_schedule_id_
 		WHERE cssp.class_group_id_ = #{classGroupId} AND cssp.user_id_ = #{studentId} AND CONCAT(cs.class_date_,' ',cs.start_class_time_) > NOW()
-		AND cs.type_ = #{courseType}
+	  <if test="courseType != null">
+		  AND cs.type_ = #{courseType}
+	  </if>
 	</select>
 </mapper>

+ 8 - 4
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderStudentDetailMapper.xml

@@ -13,6 +13,7 @@
 		<result column="username_" property="username" />
 		<result column="course_original_price_" property="courseOriginalPrice" />
 		<result column="course_current_price_" property="courseCurrentPrice" />
+		<result column="master_sub_course_price_" property="masterSubCoursePrice" />
 		<result column="course_type_" property="courseType" />
 		<result column="course_time_" property="courseTime" />
 		<result column="class_group_id_" property="classGroupId" />
@@ -34,9 +35,9 @@
 	<!-- 向数据库增加一条记录 -->
 	<insert id="insert" parameterType="com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderStudentDetail" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
 		INSERT INTO music_group_payment_calender_student_detail (id_,user_id_,phone_,username_,course_original_price_,
-																 course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_)
+																 course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_,master_sub_course_price_)
 		VALUES(#{id},#{userId},#{phone},#{username},#{courseOriginalPrice},#{courseCurrentPrice},
-			   #{courseType},#{courseTime},#{classGroupId},#{batchNo},NOW(),NOW())
+			   #{courseType},#{courseTime},#{classGroupId},#{batchNo},NOW(),NOW(),#{masterSubCoursePrice})
 	</insert>
 	
 	<!-- 根据主键查询一条记录 -->
@@ -45,6 +46,9 @@
 		<if test="userId != null">
 		user_id_ = #{userId},
 		</if>
+		<if test="masterSubCoursePrice != null">
+			master_sub_course_price_ = #{masterSubCoursePrice},
+		</if>
 		<if test="classGroupId != null">
 		class_group_id_ = #{classGroupId},
 		</if>
@@ -89,11 +93,11 @@
 	</select>
 	<insert id="batchInsert">
 		INSERT INTO music_group_payment_calender_student_detail (user_id_,phone_,username_,course_original_price_,
-		course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_)
+		course_current_price_,course_type_,course_time_,class_group_id_,batch_no_,create_time_,update_time_,master_sub_course_price_)
 		VALUES
 		<foreach collection="musicGroupPaymentCalenderStudentDetails" item="item" index="index" separator=",">
 			(#{item.userId},#{item.phone},#{item.username},#{item.courseOriginalPrice},#{item.courseCurrentPrice},
-			#{item.courseType},#{item.courseTime},#{item.classGroupId},#{batchNo},NOW(),NOW())
+			#{item.courseType},#{item.courseTime},#{item.classGroupId},#{batchNo},NOW(),NOW(),#{item.masterSubCoursePrice})
 		</foreach>
 	</insert>