Browse Source

Merge remote-tracking branch 'origin/saas' into saas

# Conflicts:
#	mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
zouxuan 3 years ago
parent
commit
55b7ed9e06

+ 41 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CouponPayParam.java

@@ -0,0 +1,41 @@
+package com.ym.mec.biz.dal.entity;
+
+import java.math.BigDecimal;
+import java.util.Map;
+
+/**
+ * @author hgw
+ * Created by 2022-01-04
+ */
+public class CouponPayParam {
+    //本次使用的优惠券类型信息
+    private Map<String, CouponPayTypeInfo> couponTypeInfo;
+    //本次减免的全额
+    private BigDecimal couponRemitTotal;
+    //订单数据
+    private StudentPaymentOrder studentPaymentOrder;
+
+    public Map<String, CouponPayTypeInfo> getCouponTypeInfo() {
+        return couponTypeInfo;
+    }
+
+    public void setCouponTypeInfo(Map<String, CouponPayTypeInfo> couponTypeInfo) {
+        this.couponTypeInfo = couponTypeInfo;
+    }
+
+    public BigDecimal getCouponRemitTotal() {
+        return couponRemitTotal;
+    }
+
+    public void setCouponRemitTotal(BigDecimal couponRemitTotal) {
+        this.couponRemitTotal = couponRemitTotal;
+    }
+
+    public StudentPaymentOrder getStudentPaymentOrder() {
+        return studentPaymentOrder;
+    }
+
+    public void setStudentPaymentOrder(StudentPaymentOrder studentPaymentOrder) {
+        this.studentPaymentOrder = studentPaymentOrder;
+    }
+}

+ 42 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/CouponPayTypeInfo.java

@@ -0,0 +1,42 @@
+package com.ym.mec.biz.dal.entity;
+
+import java.math.BigDecimal;
+
+/**
+ * 这笔支付订单中使用的优惠券信息
+ * @author hgw
+ * Created by 2022-01-04
+ */
+public class CouponPayTypeInfo {
+
+    //优惠券类型
+    private String typeDetail;
+    //多个同类型优惠券 总共可以优惠的钱
+    private BigDecimal faceValue = BigDecimal.ZERO;
+    //多个同类型优惠券 总共“满多少”
+    private BigDecimal couponAmount = BigDecimal.ZERO;
+
+    public String getTypeDetail() {
+        return typeDetail;
+    }
+
+    public void setTypeDetail(String typeDetail) {
+        this.typeDetail = typeDetail;
+    }
+
+    public BigDecimal getCouponAmount() {
+        return couponAmount;
+    }
+
+    public void setCouponAmount(BigDecimal couponAmount) {
+        this.couponAmount = couponAmount;
+    }
+
+    public BigDecimal getFaceValue() {
+        return faceValue;
+    }
+
+    public void setFaceValue(BigDecimal faceValue) {
+        this.faceValue = faceValue;
+    }
+}

+ 29 - 2
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/CouponDetailTypeEnum.java

@@ -1,5 +1,8 @@
 package com.ym.mec.biz.dal.enums;
 
+import java.util.Arrays;
+import java.util.Objects;
+
 /**
  * 优惠券明细类型
  *
@@ -26,8 +29,8 @@ public enum CouponDetailTypeEnum {
     MIX("MIX", "合奏课"),
     //VIP = vip课 VIP +乐理课 THEORY_COURSE
     VIP("VIP", "VIP"),
-    //会员开通,团练宝
-    MEMBER("MEMBER","团练宝"),
+    //会员开通,团练宝   CLOUD_TEACHER  CLOUD_TEACHER_PLUS
+    MEMBER("MEMBER", "团练宝"),
     //全类都可以使用
     FULLCOUPON("FULLCOUPON", "全类券");
 
@@ -56,5 +59,29 @@ public enum CouponDetailTypeEnum {
         this.msg = msg;
     }
 
+    //根据传入code找到对应的券类型,默认全类型
+    public static String of(String code) {
+        CouponDetailTypeEnum detailTypeEnum = Arrays.stream(CouponDetailTypeEnum.values())
+                .filter(e -> e.code.equalsIgnoreCase(code))
+                .findFirst()
+                .orElse(null);
+        if (Objects.nonNull(detailTypeEnum)) {
+            return detailTypeEnum.getCode();
+        }
+        switch (code) {
+            case "TRAINING_SINGLE":
+                return SINGLE.getCode();
+            case "THEORY_COURSE":
+                return VIP.getCode();
+            case "TRAINING_MIX":
+                return MIX.getCode();
+            case "CLOUD_TEACHER":
+            case "CLOUD_TEACHER_PLUS":
+                return MEMBER.getCode();
+            default:
+                return FULLCOUPON.getCode();
+        }
+
+    }
 
 }

+ 449 - 387
mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupService.java

@@ -1,11 +1,5 @@
 package com.ym.mec.biz.service;
 
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.MusicGroupQueryInfo;
@@ -15,395 +9,463 @@ import com.ym.mec.common.entity.ImGroupMember;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicInteger;
+
 public interface MusicGroupService extends BaseService<String, MusicGroup> {
-	/**
-	 * 建团申请数据提交
-	 * @param subFeeSettingDto
-	 * @Author superzou
-	 */
-	String createGroup(SubFeeSettingDto subFeeSettingDto) throws Exception;
-	
-	/**
-	 * 预报名
-	 * @param studentPreRegistration
-	 * @return
-	 */
-	boolean preRegister(StudentPreRegistration studentPreRegistration);
-	
-	/**
-	 * 结束预报名
-	 * @param musicGroupId
-	 * @param isCheckStudentNum
-	 * @return
-	 */
-	boolean finishPreApply(String musicGroupId,boolean isCheckStudentNum);
-
-	/**
-	 * 发送家长会通知
-	 * @param userId
-	 * @param musicGroupId
-	 * @param meetingDate
-	 * @param address
-	 * @return
-	 */
-	boolean sendParentMeetingNotice(Integer userId, String musicGroupId, Date meetingDate, String address);
-
-	/**
-	 * 零星缴费
-	 * @param sporadicPayDto
-	 * @return
-	 */
-	Map sporadicPay(SporadicPayDto sporadicPayDto) throws Exception;
-
-	/**
-	 * 缴费
-	 * @param registerPayDto
-	 * @return
-	 */
-	HttpResponseResult pay(RegisterPayDto registerPayDto) throws Exception;
-
-	/**
-	 * 继续缴费
-	 * @param registerPayDto
-	 * @return
-	 */
+    /**
+     * 建团申请数据提交
+     *
+     * @param subFeeSettingDto
+     * @Author superzou
+     */
+    String createGroup(SubFeeSettingDto subFeeSettingDto) throws Exception;
+
+    /**
+     * 预报名
+     *
+     * @param studentPreRegistration
+     * @return
+     */
+    boolean preRegister(StudentPreRegistration studentPreRegistration);
+
+    /**
+     * 结束预报名
+     *
+     * @param musicGroupId
+     * @param isCheckStudentNum
+     * @return
+     */
+    boolean finishPreApply(String musicGroupId, boolean isCheckStudentNum);
+
+    /**
+     * 发送家长会通知
+     *
+     * @param userId
+     * @param musicGroupId
+     * @param meetingDate
+     * @param address
+     * @return
+     */
+    boolean sendParentMeetingNotice(Integer userId, String musicGroupId, Date meetingDate, String address);
+
+    /**
+     * 零星缴费
+     *
+     * @param sporadicPayDto
+     * @return
+     */
+    Map sporadicPay(SporadicPayDto sporadicPayDto) throws Exception;
+
+    /**
+     * 缴费
+     *
+     * @param registerPayDto
+     * @return
+     */
+    HttpResponseResult pay(RegisterPayDto registerPayDto) throws Exception;
+
+    /**
+     * 获取优惠券相关参数-校验优惠券和传入的支付金额是否合法
+     *
+     * @param couponIdList 优惠券集合
+     * @param total        本次订单所有商品的总数量
+     * @param payAmount    页面传入的本次支付的金额
+     */
+    CouponPayParam getCouponPayParam(List<Integer> couponIdList, AtomicInteger total, BigDecimal payAmount);
+
+    /**
+     * 继续缴费
+     * @param registerPayDto
+     * @return
+     */
 //	Map rePay(RegisterPayDto registerPayDto) throws Exception;
 
-	/**
-	 * 获取学生所在乐团详情
-	 * @return
-	 */
-	List<MusicCardDto> queryUserMusicGroups(Integer userId);
-
-	/**
-	 * 获取个人中心乐团数据
-	 * @param id
-	 * @return
-	 */
-	MusicCardDto queryPersonalMusicGroups(Integer id);
-
-	/**
-	 * 根据学员编号获取相关老师列表
-	 * @param studentId
-	 * @return
-	 */
-	List<BasicUserDto> findTeachersByStuId(Integer studentId,String search);
-
-	/**
-	 * 取消乐团
-	 * @param musicGroupId 乐团编号
-	 */
-	boolean cancelMusicGroup(String musicGroupId);
-
-	/**
-	 * 删除乐团
-	 * @param musicGroupId 乐团编号
-	 * @return
-	 */
-	boolean deleteMusicGroup(String musicGroupId);
-
-	/**
-	 * 暂停乐团
-	 * @param musicGroupId 乐团编号
-	 */
-	boolean pauseMusicGroup(String musicGroupId);
-
-	/**
-	 * 恢复乐团
-	 * @param musicGroupId 乐团编号
-	 */
-	boolean resumeMusicGroup(String musicGroupId);
-
-	/**
-	 * 延长缴费时间
-	 * @param musicGroupId 乐团编号
-	 * @param expireDate 延长缴费的截止日期
-	 * @return
-	 */
-	boolean extensionPaymentExpireDate(String musicGroupId, Date expireDate);
-
-	/**
-	 * 延长缴费
-	 * @param musicGroupId 乐团编号
-	 * @param expireDate 延长缴费的截止日期
-	 * @return
-	 */
-	boolean extensionApplyExpireDate(String musicGroupId, Date expireDate);
-
-	/**
-	 * 延长预报名时间
-	 * @param musicGroupId 乐团编号
-	 * @param expireDate 预报名的截止日期
-	 * @return
-	 */
-	boolean extensionPreApplyExpireDate(String musicGroupId, Date expireDate);
-
-		/**
-	 * 申请退团
-	 * @param reqMusicGroupQuit 
-	 * @param operatorId
-	 * @return
-	 */
-	boolean applyQuitMusicGroup(List<Integer> currentOperatorRoleIds, MusicGroupQuit reqMusicGroupQuit, Integer operatorId);
-
-
-	/**
-	 * 取消退团
-	 * @param userId
-	 * @param musicGroupId
-	 * @param reason
-	 * @return
-	 */
-	boolean cancelQuitMusicGroup(Integer userId, String musicGroupId, String reason);
-
-	/**
-	 * 审批退团
-	 * @param currentOperatorRoleIds
-	 * @param reqMusicGroupQuit
-	 * @return
-	 */
-	boolean approveQuitMusicGroup(List<Integer> currentOperatorRoleIds, MusicGroupQuit reqMusicGroupQuit);
-
-	/**
-	 * 一键退团
-	 * @param musicGroupId
-	 * @param userId
-	 * @param reason
-	 * @param isRefundCourseFee 是否退还课程费用
-	 * @param isRefundInstrumentFee 是否退还乐器费用
-	 * @param isRefundTeachingAssistantsFee 是否退还教辅费用
-	 * @param maintenanceFee
-	 * @param cloudTeacherAmount
-	 * @return
-	 */
-	boolean directQuitMusicGroup(String musicGroupId, Integer userId, String reason, boolean isRefundCourseFee, boolean isRefundInstrumentFee,
-								 boolean isRefundTeachingAssistantsFee,boolean isRefundMemberFee, BigDecimal maintenanceFee, BigDecimal cloudTeacherAmount);
-	/**
-	 * 处理oa审批退团逻辑
-	 * @param musicGroupId
-	 * @param userId
-	 * @param reason
-	 * @param isRefundInstrumentFee 是否退还乐器费用
-	 * @param isRefundTeachingAssistantsFee 是否退还教辅费用
-	 * @param maintenanceFee
-	 * @return
-	 */
-	void directQuitMusicGroupOa(String musicGroupId, Integer userId, String reason, boolean isRefundInstrumentFee,
-								   boolean isRefundTeachingAssistantsFee, boolean maintenanceFee,BigDecimal amount);
-
-	/**
-	 * 检测oa退团参数
-	 * @param musicGroupId
-	 * @param userId
-	 * @return
-	 */
-	void checkDirectQuitMusicGroupOa(String musicGroupId, Integer userId);
-
-	/**
-	 *  续费
-	 * @return
-	 */
-	HttpResponseResult renew(RegisterPayDto renewParamDto) throws Exception;
-
-	/**
-	 * 学生支付订单
-	 * @param studentPaymentOrder
-	 * @return
-	 */
-	boolean renewForCallback(StudentPaymentOrder studentPaymentOrder) throws IOException;
-
-	/**
-	 * 课酬调整
-	 * @param courseScheduleId 课程编号
-	 * @param teacherId 老师编号
-	 * @param salary 老师薪水
-	 * @param subsidy 老师补贴
-	 * @param scope 范围(one,all)
-	 * @return
-	 */
-	boolean updateTeacherCoursesSalary(Long courseScheduleId, Integer teacherId, BigDecimal salary, BigDecimal subsidy, String scope);
-
-	/**
-	 * 获取乐团列表
-	 * @param queryInfo
-	 * @return
-	 */
-	PageInfo<MusicGroup> queryMusicGroupPage(MusicGroupQueryInfo queryInfo);
-
-	/**
-	 * 获取乐团列表
-	 * @param queryInfo
-	 * @return
-	 */
-	PageInfo<MusicGroup> findEduTeacherMusicGroups(MusicGroupQueryInfo queryInfo);
-
-	/**
-	 * 修改乐团基本信息
-	 * @param subFeeSettingDto
-	 */
-	void updateBaseInfo(SubFeeSettingDto subFeeSettingDto) throws Exception;
-
-	/**
-	 * 获取修改乐团时的基本信息数据
-	 * @param musicGroupId
-	 * @return
-	 */
-	SubFeeSettingDto findMusicGroupBasicInfo(String musicGroupId);
-
-	/**
-	 * 获取乐团列表
-	 * @param musicGroupIds
-	 * @return
-	 */
-	List<MusicGroup> queryListByIds(Set<String> musicGroupIds);
-
-	/**
-	 * 乐团详情--课酬调整--课程教师列表
-	 * @param courseScheduleId
-	 * @return
-	 */
-	List<CourseScheduleTeachersDto> queryTeacherSalary(Long courseScheduleId,Integer teacherId);
-
-	/**
-	 * 开启缴费(报名中 -->  缴费中)
-	 * @param musicGroupId
-	 * @return
-	 */
-	MusicGroup openPay(String musicGroupId, String expireDate) throws Exception;
-
-	/**
-	 * 获取乐团详情
-	 * @param musicGroupId
-	 * @return
-	 */
-	MusicGroup getMusicGroupDetail(String musicGroupId);
-
-	/**
-	 * 获取乐团老师列表
-	 * @param musicGroupId
-	 * @return
-	 */
-	List<ImGroupMember> queryMusicGroupTeachers(String musicGroupId);
-
-	/**
-	 * 乐团确认成立
-	 * @param musicGroupId
-	 */
-	void musicGroupFound(String musicGroupId) throws Exception;
-
-	/**
-	 * 乐团修改,获取乐团声部信息数据
-	 * @param musicGroupId
-	 * @return
-	 */
-	SubFeeSettingDto findMusicGroupSubjectInfo(String musicGroupId);
-
-	/**
-	 * 修改乐团声部、商品组信息
-	 * @param subFeeSettingDto
-	 */
-	void updateSubjectInfo(SubFeeSettingDto subFeeSettingDto) throws Exception;
-
-	/**
-	 * 修改乐团计划招生人数
-	 * @param updateExpectedNumDtos
-	 * @return
-	 */
-	void updateExpectedStudentNum(List<UpdateExpectedNumDto> updateExpectedNumDtos);
-
-	/**
-	 * 开启乐团(筹备中 -->  进行中)
-	 * @param musicGroupId
-	 */
-	void musicGroupAction(String musicGroupId) throws Exception;
-
-	/**
-	 * 提交审核(草稿 -> 审核中)
-	 * @param musicGroupId
-	 */
-	void musicGroupAudit(String musicGroupId) throws Exception;
-
-	/**
-	 * 审核失败(审核中 -> 审核失败)
-	 * @param musicGroupId
-	 */
-	void musicGroupAuditFailed(String musicGroupId, String memo) throws Exception;
-
-	/**
-	 * 审核通过(审核中 -> 预报名)
-	 * @param musicGroupId
-	 */
-	void musicGroupAuditSuccess(String musicGroupId) throws Exception;
-
-	/**
-	 * 乐团筹备结束后,3.0乐团推送小班课缴费信息
-	 * @param musicGroupId
-	 */
-	int pushMessage(String musicGroupId, String classGroupIds) throws IOException;
-
-	/**
-	 * @describe 获取分部乐团列表名称
-	 * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
-	 * @author zouxuan
-	 * @date 2020/9/7
-	 * @time 14:28
-	 * @param :
-	 * @return java.util.List<com.ym.mec.biz.dal.dto.MusicCardDto>
-	 */
-	List<MusicCardDto> queryOrganMusicInfos(Integer organId);
-
-	/**
-	 * 补全musicGroupStudentFee表数据
-	 * @param musicGroupIds
-	 */
+    /**
+     * 获取学生所在乐团详情
+     *
+     * @return
+     */
+    List<MusicCardDto> queryUserMusicGroups(Integer userId);
+
+    /**
+     * 获取个人中心乐团数据
+     *
+     * @param id
+     * @return
+     */
+    MusicCardDto queryPersonalMusicGroups(Integer id);
+
+    /**
+     * 根据学员编号获取相关老师列表
+     *
+     * @param studentId
+     * @return
+     */
+    List<BasicUserDto> findTeachersByStuId(Integer studentId, String search);
+
+    /**
+     * 取消乐团
+     *
+     * @param musicGroupId 乐团编号
+     */
+    boolean cancelMusicGroup(String musicGroupId);
+
+    /**
+     * 删除乐团
+     *
+     * @param musicGroupId 乐团编号
+     * @return
+     */
+    boolean deleteMusicGroup(String musicGroupId);
+
+    /**
+     * 暂停乐团
+     *
+     * @param musicGroupId 乐团编号
+     */
+    boolean pauseMusicGroup(String musicGroupId);
+
+    /**
+     * 恢复乐团
+     *
+     * @param musicGroupId 乐团编号
+     */
+    boolean resumeMusicGroup(String musicGroupId);
+
+    /**
+     * 延长缴费时间
+     *
+     * @param musicGroupId 乐团编号
+     * @param expireDate   延长缴费的截止日期
+     * @return
+     */
+    boolean extensionPaymentExpireDate(String musicGroupId, Date expireDate);
+
+    /**
+     * 延长缴费
+     *
+     * @param musicGroupId 乐团编号
+     * @param expireDate   延长缴费的截止日期
+     * @return
+     */
+    boolean extensionApplyExpireDate(String musicGroupId, Date expireDate);
+
+    /**
+     * 延长预报名时间
+     *
+     * @param musicGroupId 乐团编号
+     * @param expireDate   预报名的截止日期
+     * @return
+     */
+    boolean extensionPreApplyExpireDate(String musicGroupId, Date expireDate);
+
+    /**
+     * 申请退团
+     *
+     * @param reqMusicGroupQuit
+     * @param operatorId
+     * @return
+     */
+    boolean applyQuitMusicGroup(List<Integer> currentOperatorRoleIds, MusicGroupQuit reqMusicGroupQuit, Integer operatorId);
+
+
+    /**
+     * 取消退团
+     *
+     * @param userId
+     * @param musicGroupId
+     * @param reason
+     * @return
+     */
+    boolean cancelQuitMusicGroup(Integer userId, String musicGroupId, String reason);
+
+    /**
+     * 审批退团
+     *
+     * @param currentOperatorRoleIds
+     * @param reqMusicGroupQuit
+     * @return
+     */
+    boolean approveQuitMusicGroup(List<Integer> currentOperatorRoleIds, MusicGroupQuit reqMusicGroupQuit);
+
+    /**
+     * 一键退团
+     *
+     * @param musicGroupId
+     * @param userId
+     * @param reason
+     * @param isRefundCourseFee             是否退还课程费用
+     * @param isRefundInstrumentFee         是否退还乐器费用
+     * @param isRefundTeachingAssistantsFee 是否退还教辅费用
+     * @param maintenanceFee
+     * @param cloudTeacherAmount
+     * @return
+     */
+    boolean directQuitMusicGroup(String musicGroupId, Integer userId, String reason, boolean isRefundCourseFee, boolean isRefundInstrumentFee,
+                                 boolean isRefundTeachingAssistantsFee, boolean isRefundMemberFee, BigDecimal maintenanceFee, BigDecimal cloudTeacherAmount);
+
+    /**
+     * 处理oa审批退团逻辑
+     *
+     * @param musicGroupId
+     * @param userId
+     * @param reason
+     * @param isRefundInstrumentFee         是否退还乐器费用
+     * @param isRefundTeachingAssistantsFee 是否退还教辅费用
+     * @param maintenanceFee
+     * @return
+     */
+    void directQuitMusicGroupOa(String musicGroupId, Integer userId, String reason, boolean isRefundInstrumentFee,
+                                boolean isRefundTeachingAssistantsFee, boolean maintenanceFee, BigDecimal amount);
+
+    /**
+     * 检测oa退团参数
+     *
+     * @param musicGroupId
+     * @param userId
+     * @return
+     */
+    void checkDirectQuitMusicGroupOa(String musicGroupId, Integer userId);
+
+    /**
+     * 续费
+     *
+     * @return
+     */
+    HttpResponseResult renew(RegisterPayDto renewParamDto) throws Exception;
+
+    /**
+     * 学生支付订单
+     *
+     * @param studentPaymentOrder
+     * @return
+     */
+    boolean renewForCallback(StudentPaymentOrder studentPaymentOrder) throws IOException;
+
+    /**
+     * 课酬调整
+     *
+     * @param courseScheduleId 课程编号
+     * @param teacherId        老师编号
+     * @param salary           老师薪水
+     * @param subsidy          老师补贴
+     * @param scope            范围(one,all)
+     * @return
+     */
+    boolean updateTeacherCoursesSalary(Long courseScheduleId, Integer teacherId, BigDecimal salary, BigDecimal subsidy, String scope);
+
+    /**
+     * 获取乐团列表
+     *
+     * @param queryInfo
+     * @return
+     */
+    PageInfo<MusicGroup> queryMusicGroupPage(MusicGroupQueryInfo queryInfo);
+
+    /**
+     * 获取乐团列表
+     *
+     * @param queryInfo
+     * @return
+     */
+    PageInfo<MusicGroup> findEduTeacherMusicGroups(MusicGroupQueryInfo queryInfo);
+
+    /**
+     * 修改乐团基本信息
+     *
+     * @param subFeeSettingDto
+     */
+    void updateBaseInfo(SubFeeSettingDto subFeeSettingDto) throws Exception;
+
+    /**
+     * 获取修改乐团时的基本信息数据
+     *
+     * @param musicGroupId
+     * @return
+     */
+    SubFeeSettingDto findMusicGroupBasicInfo(String musicGroupId);
+
+    /**
+     * 获取乐团列表
+     *
+     * @param musicGroupIds
+     * @return
+     */
+    List<MusicGroup> queryListByIds(Set<String> musicGroupIds);
+
+    /**
+     * 乐团详情--课酬调整--课程教师列表
+     *
+     * @param courseScheduleId
+     * @return
+     */
+    List<CourseScheduleTeachersDto> queryTeacherSalary(Long courseScheduleId, Integer teacherId);
+
+    /**
+     * 开启缴费(报名中 -->  缴费中)
+     *
+     * @param musicGroupId
+     * @return
+     */
+    MusicGroup openPay(String musicGroupId, String expireDate) throws Exception;
+
+    /**
+     * 获取乐团详情
+     *
+     * @param musicGroupId
+     * @return
+     */
+    MusicGroup getMusicGroupDetail(String musicGroupId);
+
+    /**
+     * 获取乐团老师列表
+     *
+     * @param musicGroupId
+     * @return
+     */
+    List<ImGroupMember> queryMusicGroupTeachers(String musicGroupId);
+
+    /**
+     * 乐团确认成立
+     *
+     * @param musicGroupId
+     */
+    void musicGroupFound(String musicGroupId) throws Exception;
+
+    /**
+     * 乐团修改,获取乐团声部信息数据
+     *
+     * @param musicGroupId
+     * @return
+     */
+    SubFeeSettingDto findMusicGroupSubjectInfo(String musicGroupId);
+
+    /**
+     * 修改乐团声部、商品组信息
+     *
+     * @param subFeeSettingDto
+     */
+    void updateSubjectInfo(SubFeeSettingDto subFeeSettingDto) throws Exception;
+
+    /**
+     * 修改乐团计划招生人数
+     *
+     * @param updateExpectedNumDtos
+     * @return
+     */
+    void updateExpectedStudentNum(List<UpdateExpectedNumDto> updateExpectedNumDtos);
+
+    /**
+     * 开启乐团(筹备中 -->  进行中)
+     *
+     * @param musicGroupId
+     */
+    void musicGroupAction(String musicGroupId) throws Exception;
+
+    /**
+     * 提交审核(草稿 -> 审核中)
+     *
+     * @param musicGroupId
+     */
+    void musicGroupAudit(String musicGroupId) throws Exception;
+
+    /**
+     * 审核失败(审核中 -> 审核失败)
+     *
+     * @param musicGroupId
+     */
+    void musicGroupAuditFailed(String musicGroupId, String memo) throws Exception;
+
+    /**
+     * 审核通过(审核中 -> 预报名)
+     *
+     * @param musicGroupId
+     */
+    void musicGroupAuditSuccess(String musicGroupId) throws Exception;
+
+    /**
+     * 乐团筹备结束后,3.0乐团推送小班课缴费信息
+     *
+     * @param musicGroupId
+     */
+    int pushMessage(String musicGroupId, String classGroupIds) throws IOException;
+
+    /**
+     * @param :
+     * @return java.util.List<com.ym.mec.biz.dal.dto.MusicCardDto>
+     * @describe 获取分部乐团列表名称
+     * @apiNote 时光荏苒,认真工作的时间总是过得很快,而我、享受这一刻!
+     * @author zouxuan
+     * @date 2020/9/7
+     * @time 14:28
+     */
+    List<MusicCardDto> queryOrganMusicInfos(Integer organId);
+
+    /**
+     * 补全musicGroupStudentFee表数据
+     * @param musicGroupIds
+     */
 //	void musicGroupStudentFeePatch(List<String> musicGroupIds);
 
-	/**
-	 * 给乐团添加报名学生
-	 * @param musicGroupId 乐团id
-	 * @param registerIds 学员注册id
-	 * @return 添加学员记录
-	 */
-	HttpResponseResult addMusicGroupRegs(String musicGroupId,List<Long> registerIds) throws Exception;
-
-
-	/**
-	 * 关闭乐团
-	 * @param closeMusicGroupDto 乐团关闭信息
-	 * @return 关闭结果
-	 */
-	Boolean closeMusicGroup(CloseMusicGroupDto closeMusicGroupDto);
-
-	/**
-	 * 根据合作单位获取所有乐团列表
-	 * @param cooperationId
-	 * @return
-	 */
-	List<MusicGroup> findByCooperationId(Integer cooperationId);
-
-	/**
-	 * 获取乐团已经过期或者即将过期的学员列表
-	 * @param musicMemberQueryInfo
-	 * @return
-	 */
-	PageInfo<MusicMemberDto> queryMusicMemberList(MusicMemberQueryInfo musicMemberQueryInfo);
-	
-	/**
-	 * 查询乐团基本信息
-	 * @param id
-	 * @return
-	 */
-	MusicGroupBasicDto queryBasicInfo(String id);
-
-	/**
-	 * 获取学员退团页面详情
-	 * @param musicGroupId
-	 * @return
-	 */
+    /**
+     * 给乐团添加报名学生
+     *
+     * @param musicGroupId 乐团id
+     * @param registerIds  学员注册id
+     * @return 添加学员记录
+     */
+    HttpResponseResult addMusicGroupRegs(String musicGroupId, List<Long> registerIds) throws Exception;
+
+
+    /**
+     * 关闭乐团
+     *
+     * @param closeMusicGroupDto 乐团关闭信息
+     * @return 关闭结果
+     */
+    Boolean closeMusicGroup(CloseMusicGroupDto closeMusicGroupDto);
+
+    /**
+     * 根据合作单位获取所有乐团列表
+     *
+     * @param cooperationId
+     * @return
+     */
+    List<MusicGroup> findByCooperationId(Integer cooperationId);
+
+    /**
+     * 获取乐团已经过期或者即将过期的学员列表
+     *
+     * @param musicMemberQueryInfo
+     * @return
+     */
+    PageInfo<MusicMemberDto> queryMusicMemberList(MusicMemberQueryInfo musicMemberQueryInfo);
+
+    /**
+     * 查询乐团基本信息
+     *
+     * @param id
+     * @return
+     */
+    MusicGroupBasicDto queryBasicInfo(String id);
+
+    /**
+     * 获取学员退团页面详情
+     *
+     * @param musicGroupId
+     * @return
+     */
     Object getQuitGroupDetail(String musicGroupId);
-    
+
     /**
      * 乐保生效
+     *
      * @param musicGroupId
      * @return
      */

+ 41 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderDetailService.java

@@ -15,13 +15,29 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
     /**
      * 批量添加订单
      *
-     * @param studentPaymentOrderDetailList
-     * @return
+     * @param studentPaymentOrderDetailList 订单详情
+     */
+    int batchAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList);
+
+    /**
+     * 按比例分摊优惠券减免金额-并且批量添加订单
+     *
+     * @param studentPaymentOrderDetailList 订单详情
+     * @param couponRemitFee                总优惠金额
      */
-    int batchAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee);
+    int allocateAndAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee);
+
+    /**
+     * 按比例分摊优惠券减免金额
+     *
+     * @param studentPaymentOrderDetailList 订单详情
+     * @param couponRemitFee                总优惠金额
+     */
+    List<StudentPaymentOrderDetail> allocateAmount(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee);
 
     /**
      * 查询注册支付的订单详情
+     *
      * @param musicGroupId
      * @param status
      * @return
@@ -30,6 +46,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取乐器的采购清单
+     *
      * @param musicGroupId
      * @return
      */
@@ -37,6 +54,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 确认采购清单
+     *
      * @param musicGroupId
      * @return
      */
@@ -44,6 +62,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 查询订单商品
+     *
      * @param orderId
      * @return
      */
@@ -51,21 +70,24 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取订单详情
+     *
      * @param userId
      * @param status
      * @return
      */
-    List<StudentPaymentOrderDetail>findUserApplyOrder(Integer userId,String musicGroupId,DealStatusEnum status);
+    List<StudentPaymentOrderDetail> findUserApplyOrder(Integer userId, String musicGroupId, DealStatusEnum status);
 
     /**
      * 乐器采购清单明细
+     *
      * @param musicGroupId
      * @return
      */
-    List<MusicalListDetailDto> getMusicalListDetail(String musicGroupId,Integer studentId);
+    List<MusicalListDetailDto> getMusicalListDetail(String musicGroupId, Integer studentId);
 
     /**
      * 获取订单的乐器信息
+     *
      * @param orderId
      * @return
      */
@@ -74,6 +96,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取订单详细
+     *
      * @param orderId
      * @return
      */
@@ -82,6 +105,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取订单详细
+     *
      * @param orderIdList
      * @return
      */
@@ -89,6 +113,7 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取订单类型的详情
+     *
      * @param orderId
      * @return
      */
@@ -97,28 +122,29 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
 
     /**
      * 获取订单商品详细
+     *
      * @param orderId
      * @return
      */
     List<StudentPaymentOrderDetail> getOrderGoodsDetail(Long orderId);
 
     /**
-    * @description: 获取订单详情列表
      * @param orderId
-    * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail>
-    * @author zx
-    * @date 2021/12/30 15:13
-    */
+     * @return java.util.List<com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail>
+     * @description: 获取订单详情列表
+     * @author zx
+     * @date 2021/12/30 15:13
+     */
     List<StudentPaymentOrderDetail> queryOrderDetail(Long orderId);
 
     /**
-    * @description: 处理乐团缴费完成后,课程、会员、乐保等数据的录入
      * @param studentPaymentOrder
      * @param musicGroup
-    * @return void
-    * @author zx
-    * @date 2021/12/30 17:00
-    */
+     * @return void
+     * @description: 处理乐团缴费完成后,课程、会员、乐保等数据的录入
+     * @author zx
+     * @date 2021/12/30 17:00
+     */
     void addOrderDetailTo(StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup, StudentRegistration studentRegistration);
 
     List<StudentPaymentOrderDetail> findByOrderId(Long paymentOrderId);

+ 42 - 35
mec-biz/src/main/java/com/ym/mec/biz/service/StudentRegistrationService.java

@@ -1,10 +1,5 @@
 package com.ym.mec.biz.service;
 
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.List;
-import java.util.Map;
-
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
@@ -13,6 +8,11 @@ import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.List;
+import java.util.Map;
+
 public interface StudentRegistrationService extends BaseService<Long, StudentRegistration> {
 
     /**
@@ -93,23 +93,15 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 学生注册缴费订单
+     *
      * @param studentRegistration
-     * @param amount
-     * @param orderNo
-     * @param paymentChannel
-     * @param goodsGroups
-     * @param remitFee
-     * @param courseRemitFee
-     * @param newCourses
-     * @param buyMaintenance
-     * @param buyCloudTeacher
-     * @param buyCloudTeacherPlus
-     * @param couponIdList
-     * @return
-     * @throws Exception
+     * @param studentPaymentOrder
+     * @param goodsDto
+     * @param registerPayDto
+     * @param couponPayParam
      */
     StudentPaymentOrder addOrder(StudentRegistration studentRegistration,
-                                 StudentPaymentOrder studentPaymentOrder,MusicGroupApplyGoodsDto goodsDto,RegisterPayDto registerPayDto) throws Exception;
+                                 StudentPaymentOrder studentPaymentOrder, MusicGroupApplyGoodsDto goodsDto, RegisterPayDto registerPayDto, CouponPayParam couponPayParam) throws Exception;
 
     /**
      * 查询用户指定乐团的报名信息
@@ -139,12 +131,13 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 跨团合班进行中加学员
-     * @param studentIds 学员列表
+     *
+     * @param studentIds      学员列表
      * @param oldMusicGroupId 原乐团
      * @param newMusicGroupId 主乐团
      * @return
      */
-    void insertStudent(String studentIds,String oldMusicGroupId,String newMusicGroupId,Map<Integer, List<MusicGroupPaymentCalenderStudentDetail>> collect);
+    void insertStudent(String studentIds, String oldMusicGroupId, String newMusicGroupId, Map<Integer, List<MusicGroupPaymentCalenderStudentDetail>> collect);
 
     /**
      * 获取班级学生
@@ -304,33 +297,36 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 获取班级未上课程的价值
+     *
      * @param classGroupIds
      * @return
      */
     BigDecimal getClassGroupCourseExpectPrice(List<Integer> classGroupIds);
 
     /**
-     * @describe 更新学生乐团可用课程余额
-     * @author qnc99
-     * @date 2020/12/2 0002
      * @param userId:
      * @param amount:
      * @param memo:
      * @param operatorId:
      * @return boolean
+     * @describe 更新学生乐团可用课程余额
+     * @author qnc99
+     * @date 2020/12/2 0002
      */
     BigDecimal updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId);
 
     /**
      * 查询指定学生的乐团信息
+     *
      * @param userId
      * @return
      */
-    List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId,String musicGroupId);
+    List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId, String musicGroupId);
 
 
     /**
      * 删除学生报名
+     *
      * @param id
      * @return
      */
@@ -339,14 +335,16 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 批量删除报名的学生
+     *
      * @param userIds
      * @return
      */
-    Boolean batchDelRegs(String musicGroupId,List<Integer> userIds);
+    Boolean batchDelRegs(String musicGroupId, List<Integer> userIds);
 
 
     /**
      * 获取乐团学员剩余课程金额
+     *
      * @param musicGroupId
      * @return
      */
@@ -355,27 +353,30 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 检查乐团是否能报名或缴费
+     *
      * @return
      */
     String checkRegOrPayStatus(String musicGroupId);
 
     /**
      * 检查多乐团是否能报名或缴费
+     *
      * @return
      */
-    Map<String,Boolean> checkMusicGroupsRegOrPayStatus(List<String> ids);
+    Map<String, Boolean> checkMusicGroupsRegOrPayStatus(List<String> ids);
 
     /**
+     * @param queryInfo:
+     * @return com.ym.mec.common.page.PageInfo<com.ym.mec.biz.dal.dto.NoClassMusicStudentDto>
      * @describe 查询乐团中未加入班级学员信息
      * @author Joburgess
      * @date 2021/3/25 0025
-     * @param queryInfo:
-     * @return com.ym.mec.common.page.PageInfo<com.ym.mec.biz.dal.dto.NoClassMusicStudentDto>
      */
     PageInfo<NoClassMusicStudentDto> queryNoClassMusicStudentInfo(NoClassMusicStudentQueryInfo queryInfo);
 
     /**
      * 退团所有的学生
+     *
      * @param musicGroupId
      * @param remark
      * @return
@@ -384,6 +385,7 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 获取乐团在读学员数
+     *
      * @param musicGroupIds
      * @return
      */
@@ -392,6 +394,7 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 获取预报名或者报名列表
+     *
      * @param queryInfo
      * @return
      */
@@ -400,6 +403,7 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 设置不需要云教练
+     *
      * @param id
      * @return
      */
@@ -407,6 +411,7 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 已付费解除审核增加缴费人数和0元缴费人数
+     *
      * @param id
      * @return
      */
@@ -415,6 +420,7 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
 
     /**
      * 获取学生乐团的注册信息
+     *
      * @param musicGroupId
      * @param studentId
      * @return
@@ -422,20 +428,21 @@ public interface StudentRegistrationService extends BaseService<Long, StudentReg
     StudentRegistration getStudentRegister(String musicGroupId, Integer studentId);
 
     PageInfo<StudentRegisterInstrumentsDetailDto> queryStudentRegisterInstrumentsDetailList(MusicGroupRecordStudentQueryInfo queryInfo);
-	
+
     /**
      * 云教练收费:审核中的记录审核失败
+     *
      * @param studentRegistration
      * @return
      */
     Boolean setCloudTeacherToFailed(StudentRegistration studentRegistration);
 
     /**
-    * @description: 获取乐团在读学员乐保信息
      * @param queryInfo
-    * @return com.ym.mec.common.page.PageInfo<com.ym.mec.biz.dal.entity.StudentRegistration>
-    * @author zx
-    * @date 2021/11/9 10:27
-    */
+     * @return com.ym.mec.common.page.PageInfo<com.ym.mec.biz.dal.entity.StudentRegistration>
+     * @description: 获取乐团在读学员乐保信息
+     * @author zx
+     * @date 2021/11/9 10:27
+     */
     PageInfo<StudentInstrument> queryMusicStudentInstrument(StudentPreRegistrationQueryInfo queryInfo);
 }

+ 5 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/SysCouponCodeService.java

@@ -24,7 +24,7 @@ public interface SysCouponCodeService extends BaseService<Long, SysCouponCode> {
      * @author Joburgess
      * @date 2021/9/8 0008
      */
-    boolean exchangeCoupon(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum, int type,Integer issueId);
+    boolean exchangeCoupon(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum, int type, Integer issueId);
 
     boolean exchangeCouponTest(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum);
 
@@ -46,15 +46,6 @@ public interface SysCouponCodeService extends BaseService<Long, SysCouponCode> {
     PageInfo<HorseRaceLampDto> queryHorseRaceLampDtoList(QueryInfo queryInfo);
 
     /**
-     * 获取用户优惠券列表
-     *
-     * @param amount
-     * @param userId
-     * @return
-     */
-    List<SysCouponCode> queryCouponPage(BigDecimal amount, Integer userId);
-
-    /**
      * 使用优惠券
      *
      * @param couponIdList
@@ -64,8 +55,12 @@ public interface SysCouponCodeService extends BaseService<Long, SysCouponCode> {
      */
     StudentPaymentOrder use(List<Integer> couponIdList, BigDecimal amount, Boolean useFlag);
 
+    List<SysCouponCodeDto> checkCoupon(List<Integer> couponIdList);
+
     List<SysCouponCodeDto> findByIdList(List<Integer> couponIdList);
 
+    void useCoupon(List<Integer> couponIdList);
+
     /**
      * 退优惠券
      *

File diff suppressed because it is too large
+ 411 - 313
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java


+ 266 - 236
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -10,13 +10,17 @@ import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
 import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
+import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -65,39 +69,64 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         return studentPaymentOrderDetailDao;
     }
 
+    @Transactional(rollbackFor = Exception.class)
     @Override
-    public int batchAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee) {
-        if(studentPaymentOrderDetailList == null || studentPaymentOrderDetailList.size() == 0){
-            return 0;
-        }
+    public int batchAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList) {
+        return Optional.ofNullable(studentPaymentOrderDetailList)
+                .filter(CollectionUtils::isNotEmpty)
+                .map(studentPaymentOrderDetailDao::batchAdd)
+                .orElse(0);
+    }
+
+    @Transactional(rollbackFor = Exception.class)
+    @Override
+    public int allocateAndAdd(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee) {
+        return Optional.ofNullable(studentPaymentOrderDetailList)
+                .filter(CollectionUtils::isNotEmpty)
+                .map(l -> allocateAmount(l, couponRemitFee))
+                .map(studentPaymentOrderDetailDao::batchAdd)
+                .orElse(0);
+    }
+
+    /**
+     * 按比例分摊优惠券减免金额
+     *
+     * @param studentPaymentOrderDetailList 订单详情
+     * @param couponRemitFee                总优惠金额
+     */
+    @Override
+    public List<StudentPaymentOrderDetail> allocateAmount(List<StudentPaymentOrderDetail> studentPaymentOrderDetailList, BigDecimal couponRemitFee) {
         //按比例分摊优惠券减免金额
-        if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
+        if (couponRemitFee.compareTo(BigDecimal.ZERO) > 0) {
             //待分配减免
             BigDecimal waitRemitFee = couponRemitFee;
             //已使用减免金额
             BigDecimal useRemitFee = BigDecimal.ZERO;
             List<StudentPaymentOrderDetail> collect = studentPaymentOrderDetailList.stream().filter(e -> e.getPrice().compareTo(BigDecimal.ZERO) > 0).collect(Collectors.toList());
-            if(collect.size() == 0){
+            if (collect.size() == 0) {
                 throw new BizException("订单金额异常");
             }
-            BigDecimal totalAmount = collect.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
+            BigDecimal totalAmount = WrapperUtil.sumList(collect, StudentPaymentOrderDetail::getPrice);
             for (int i = 0; i < collect.size(); i++) {
                 StudentPaymentOrderDetail orderDetail = collect.get(i);
                 //如果是最后一件商品
                 if (i == collect.size() - 1) {
                     orderDetail.setPrice(orderDetail.getPrice().subtract(waitRemitFee));
+                    orderDetail.setRemitFee(orderDetail.getRemitFee().add(waitRemitFee));
                 } else {
                     //获取比例
-                    BigDecimal ratioAmount = orderDetail.getPrice().divide(totalAmount, 6, BigDecimal.ROUND_HALF_UP);
+                    BigDecimal ratioAmount = orderDetail.getPrice().divide(totalAmount, 6, RoundingMode.HALF_UP);
                     //获取分配的减免金额
-                    BigDecimal multiply = ratioAmount.multiply(couponRemitFee).setScale(2, BigDecimal.ROUND_HALF_UP);
+                    BigDecimal multiply = ratioAmount.multiply(couponRemitFee).setScale(2, RoundingMode.HALF_UP);
                     waitRemitFee = waitRemitFee.subtract(multiply);
                     useRemitFee = useRemitFee.add(multiply);
                     orderDetail.setPrice(orderDetail.getPrice().subtract(multiply));
+                    orderDetail.setRemitFee(orderDetail.getRemitFee().add(multiply));
                 }
             }
+            return collect;
         }
-        return studentPaymentOrderDetailDao.batchAdd(studentPaymentOrderDetailList);
+        return studentPaymentOrderDetailList;
     }
 
     @Override
@@ -286,191 +315,192 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     public List<MusicalListDetailDto> getMusicalListDetail(String musicGroupId, Integer studentId) {
 
         List<MusicalListDetailDto> musicalListDetailDtos = new ArrayList<MusicalListDetailDto>();
-        
-    	List<String> musicGroupIdList = new ArrayList<String>();
-    	musicGroupIdList.add(musicGroupId);
-    	
-    	List<StudentRegistration> studentRegistrationList = studentRegistrationDao.findByMusicGroupIds(musicGroupIdList,StudentMusicGroupStatusEnum.NORMAL);
-    	
-    	if(studentRegistrationList == null || studentRegistrationList.size() == 0){
-    		return musicalListDetailDtos;
-    	}
+
+        List<String> musicGroupIdList = new ArrayList<String>();
+        musicGroupIdList.add(musicGroupId);
+
+        List<StudentRegistration> studentRegistrationList = studentRegistrationDao.findByMusicGroupIds(musicGroupIdList, StudentMusicGroupStatusEnum.NORMAL);
+
+        if (studentRegistrationList == null || studentRegistrationList.size() == 0) {
+            return musicalListDetailDtos;
+        }
 
         List<Integer> userIds = studentRegistrationList.stream().distinct().map(StudentRegistration::getUserId).collect(Collectors.toList());
-        
+
         List<SubjectChange> subjectChangeList = subjectChangeDao.getStudentGoods(musicGroupId);
-        Map<Integer,SubjectChange> subjectChangeMap = subjectChangeList.stream().collect(Collectors.toMap(SubjectChange :: getStudentId, t -> t));
-        
+        Map<Integer, SubjectChange> subjectChangeMap = subjectChangeList.stream().collect(Collectors.toMap(SubjectChange::getStudentId, t -> t));
+
         SubjectChange subjectChange = null;
-        
+
         MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
         Organization organization = organizationDao.get(musicGroup.getOrganId());
         Map<Integer, String> usernameMap = MapUtil.convertIntegerMap(teacherDao.queryUsernameByIds(userIds));
         Map<Integer, String> userSubjectMap = subjectDao.getRegisterSubject(musicGroupId, userIds).stream().collect(Collectors.toMap(StudentRegistration::getUserId, StudentRegistration::getSubjectName));
         Integer userId = null;
-        
-        for(StudentRegistration studentRegistration : studentRegistrationList){
-        	
-        	MusicalListDetailDto dto = new MusicalListDetailDto();
-        	
-        	userId = studentRegistration.getUserId();
-        	
-        	List<StudentPaymentOrder> studentPaymentOrderList = new ArrayList<StudentPaymentOrder>();
-
-			if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
-				studentPaymentOrderList = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
-			} else {
-				studentPaymentOrderList = studentPaymentOrderService.queryByBatchNo(userId, studentRegistration.getMusicGroupPaymentCalenderId() + "",
-						DealStatusEnum.SUCCESS);
-			}
-
-			List<Long> paymentOrderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
-			
-			subjectChange = subjectChangeMap.get(studentRegistration.getUserId());
-			
-			if((paymentOrderIdList == null || paymentOrderIdList.size() == 0) && subjectChange == null){
-				continue;
-			}
-			
-			List<StudentPaymentOrderDetail> orderDetailList = new ArrayList<StudentPaymentOrderDetail>();
-			
-			if(paymentOrderIdList != null && paymentOrderIdList.size() > 0) {
-				orderDetailList = studentPaymentOrderDetailDao.getWithIds(paymentOrderIdList);
-			}
-			
-			Map<OrderDetailTypeEnum,BigDecimal> userOrderTypeMap = new HashMap<OrderDetailTypeEnum, BigDecimal>();;
-			
-			BigDecimal amount = BigDecimal.ZERO;
-			KitGroupPurchaseTypeEnum kitGroupPurchaseType = null;
-			String musicalId = null;
-			StringBuffer accessoriesId = new StringBuffer();
-			BigDecimal orderTotalAmount = BigDecimal.ZERO;
-			
-			boolean isCalculatedOfAccessories = false;
-			boolean isChangeMusical = false;
-			boolean isChangeAccessories = false;
-			
-			for(StudentPaymentOrderDetail spod : orderDetailList) {
-				
-				if (spod.getType() == OrderDetailTypeEnum.COURSE || spod.getType() == OrderDetailTypeEnum.HIGH_ONLINE_COURSE
-						|| spod.getType() == OrderDetailTypeEnum.SINGLE || spod.getType() == OrderDetailTypeEnum.VIP
-						|| spod.getType() == OrderDetailTypeEnum.HIGH || spod.getType() == OrderDetailTypeEnum.MIX
-						|| spod.getType() == OrderDetailTypeEnum.DEMO || spod.getType() == OrderDetailTypeEnum.COMPREHENSIVE
-						|| spod.getType() == OrderDetailTypeEnum.ENLIGHTENMENT || spod.getType() == OrderDetailTypeEnum.TRAINING_SINGLE
-						|| spod.getType() == OrderDetailTypeEnum.TRAINING_MIX || spod.getType() == OrderDetailTypeEnum.HIGH_ONLINE
-						|| spod.getType() == OrderDetailTypeEnum.MUSIC_NETWORK || spod.getType() == OrderDetailTypeEnum.CLASSROOM || spod.getType() == OrderDetailTypeEnum.THEORY_COURSE) {
-					spod.setType(OrderDetailTypeEnum.COURSE);
-					//courseAmount = courseAmount.add(spod.getPrice().subtract(spod.getRemitFee()));
-				}else if(spod.getType() == OrderDetailTypeEnum.MUSICAL){
-					if(subjectChange != null && spod.getPaymentOrderId() <= subjectChange.getOriginalOrderId()) {
-						if(subjectChange.getChangeMusical() == null){
-							continue;
-						}
-						kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
-						musicalId = subjectChange.getChangeMusical() + "";
-						spod.setPrice(subjectChange.getChangeMusicalPrice());
-						spod.setRemitFee(BigDecimal.ZERO);
-						isChangeMusical = true;
-		        	} else {
-						kitGroupPurchaseType = spod.getKitGroupPurchaseType();
-						musicalId = spod.getGoodsIdList();
-						//musicalAmount = musicalAmount.add(spod.getPrice());
-		        	}
-				}else if(spod.getType() == OrderDetailTypeEnum.ACCESSORIES){
-					if(subjectChange != null && (subjectChange.getOriginalOrderId() != null && spod.getPaymentOrderId() <= subjectChange.getOriginalOrderId())) {
-						if(StringUtils.isBlank(subjectChange.getChangeAccessories()) || isCalculatedOfAccessories == true){
-							continue;
-						}
-						isCalculatedOfAccessories = true;
-						accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
-						//accessoriesAmount = accessoriesAmount.add(subjectChange.getChangeAccessoriesPrice());
-						spod.setPrice(subjectChange.getChangeAccessoriesPrice());
-						spod.setRemitFee(BigDecimal.ZERO);
-						isChangeAccessories = true;
-		        	}else{
-						accessoriesId = accessoriesId.append(spod.getGoodsIdList()).append(",");
-						//accessoriesAmount = accessoriesAmount.add(spod.getPrice());
-		        	}
-				}
-				
-				amount = userOrderTypeMap.get(spod.getType());
-				if(amount != null){
-					amount = amount.add(spod.getPrice().subtract(spod.getRemitFee()));
-				}else{
-					amount = spod.getPrice().subtract(spod.getRemitFee());
-				}
-				userOrderTypeMap.put(spod.getType(), amount);
-				
-				orderTotalAmount = orderTotalAmount.add(spod.getPrice().subtract(spod.getRemitFee()));
-			}
-			
-			if(orderDetailList.size() == 0) {
-				if(subjectChange != null){
-					if(subjectChange.getChangeMusical() != null){
-						kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
-						musicalId = subjectChange.getChangeMusical() + "";
-						userOrderTypeMap.put(OrderDetailTypeEnum.MUSICAL, subjectChange.getChangeMusicalPrice());
-						orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeMusicalPrice());
-					}
-					if(StringUtils.isNotBlank(subjectChange.getChangeAccessories())) {
-						accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
-						userOrderTypeMap.put(OrderDetailTypeEnum.ACCESSORIES, subjectChange.getChangeAccessoriesPrice());
-						orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeAccessoriesPrice());
-		        	}
-				}
-			}else if(isChangeAccessories == false || isChangeMusical == false){
-				if(subjectChange != null){
-					if(subjectChange.getChangeMusical() != null && isChangeMusical == false){
-						kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
-						musicalId = subjectChange.getChangeMusical() + "";
-						userOrderTypeMap.put(OrderDetailTypeEnum.MUSICAL, subjectChange.getChangeMusicalPrice());
-						orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeMusicalPrice());
-					}
-					if(StringUtils.isNotBlank(subjectChange.getChangeAccessories()) && isChangeAccessories == false) {
-						accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
-						userOrderTypeMap.put(OrderDetailTypeEnum.ACCESSORIES, subjectChange.getChangeAccessoriesPrice());
-						orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeAccessoriesPrice());
-		        	}
-				}
-			}
-        	
-        	dto.setAccessoriesAmount(userOrderTypeMap.get(OrderDetailTypeEnum.ACCESSORIES));
-			dto.setCourseAmount(userOrderTypeMap.get(OrderDetailTypeEnum.COURSE));
-    		dto.setMusicalAmount(userOrderTypeMap.get(OrderDetailTypeEnum.MUSICAL));
-    		dto.setMaintenanceAmount(userOrderTypeMap.get(OrderDetailTypeEnum.MAINTENANCE));
-			dto.setCloudTeacherAmount(userOrderTypeMap.get(OrderDetailTypeEnum.CLOUD_TEACHER) == null ? userOrderTypeMap
-					.get(OrderDetailTypeEnum.CLOUD_TEACHER_PLUS) : userOrderTypeMap.get(OrderDetailTypeEnum.CLOUD_TEACHER));
-			
-			if (StringUtils.isNoneBlank(accessoriesId.toString())) {
-				String accessoriesIdList = StringUtils.removeEnd(accessoriesId.toString(), ",");
-				Map<Integer, Goods> goodsMap = goodsService.findGoodsByIds(accessoriesIdList).stream().collect(Collectors.toMap(Goods::getId, Goods -> Goods));
-
-				String[] accessoriesIds = StringUtils.split(accessoriesIdList, ',');
-
-				StringBuffer sb = new StringBuffer();
-				for (String s : accessoriesIds) {
-					if(StringUtils.isBlank(s)){
-						continue;
-					}
-					sb.append(goodsMap.get(Integer.parseInt(s)).getName()).append(",");
-				}
-				dto.setAccessoriesName(StringUtils.removeEnd(sb.toString(), ","));
-			}
-			
-    		if(StringUtils.isNoneBlank(musicalId)){
-    			dto.setMusicalName(goodsService.findGoodsByIds(musicalId).stream().map(Goods::getName).collect(Collectors.joining(",")));
-    		}
-    		dto.setKitGroupPurchaseTypeEnum(kitGroupPurchaseType);
-    		dto.setMusicGroupName(musicGroup.getName());
-    		dto.setOrganName(organization.getName());
-    		dto.setOrderAmount(orderTotalAmount);
-    		dto.setUserId(userId);
-    		dto.setSubjectName(userSubjectMap.get(userId));
-    		dto.setUsername(usernameMap.get(userId));
-    		
-        	musicalListDetailDtos.add(dto);
+
+        for (StudentRegistration studentRegistration : studentRegistrationList) {
+
+            MusicalListDetailDto dto = new MusicalListDetailDto();
+
+            userId = studentRegistration.getUserId();
+
+            List<StudentPaymentOrder> studentPaymentOrderList = new ArrayList<StudentPaymentOrder>();
+
+            if (studentRegistration.getMusicGroupPaymentCalenderId() == null) {
+                studentPaymentOrderList = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, musicGroupId, SUCCESS);
+            } else {
+                studentPaymentOrderList = studentPaymentOrderService.queryByBatchNo(userId, studentRegistration.getMusicGroupPaymentCalenderId() + "",
+                        DealStatusEnum.SUCCESS);
+            }
+
+            List<Long> paymentOrderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
+
+            subjectChange = subjectChangeMap.get(studentRegistration.getUserId());
+
+            if ((paymentOrderIdList == null || paymentOrderIdList.size() == 0) && subjectChange == null) {
+                continue;
+            }
+
+            List<StudentPaymentOrderDetail> orderDetailList = new ArrayList<StudentPaymentOrderDetail>();
+
+            if (paymentOrderIdList != null && paymentOrderIdList.size() > 0) {
+                orderDetailList = studentPaymentOrderDetailDao.getWithIds(paymentOrderIdList);
+            }
+
+            Map<OrderDetailTypeEnum, BigDecimal> userOrderTypeMap = new HashMap<OrderDetailTypeEnum, BigDecimal>();
+            ;
+
+            BigDecimal amount = BigDecimal.ZERO;
+            KitGroupPurchaseTypeEnum kitGroupPurchaseType = null;
+            String musicalId = null;
+            StringBuffer accessoriesId = new StringBuffer();
+            BigDecimal orderTotalAmount = BigDecimal.ZERO;
+
+            boolean isCalculatedOfAccessories = false;
+            boolean isChangeMusical = false;
+            boolean isChangeAccessories = false;
+
+            for (StudentPaymentOrderDetail spod : orderDetailList) {
+
+                if (spod.getType() == OrderDetailTypeEnum.COURSE || spod.getType() == OrderDetailTypeEnum.HIGH_ONLINE_COURSE
+                        || spod.getType() == OrderDetailTypeEnum.SINGLE || spod.getType() == OrderDetailTypeEnum.VIP
+                        || spod.getType() == OrderDetailTypeEnum.HIGH || spod.getType() == OrderDetailTypeEnum.MIX
+                        || spod.getType() == OrderDetailTypeEnum.DEMO || spod.getType() == OrderDetailTypeEnum.COMPREHENSIVE
+                        || spod.getType() == OrderDetailTypeEnum.ENLIGHTENMENT || spod.getType() == OrderDetailTypeEnum.TRAINING_SINGLE
+                        || spod.getType() == OrderDetailTypeEnum.TRAINING_MIX || spod.getType() == OrderDetailTypeEnum.HIGH_ONLINE
+                        || spod.getType() == OrderDetailTypeEnum.MUSIC_NETWORK || spod.getType() == OrderDetailTypeEnum.CLASSROOM || spod.getType() == OrderDetailTypeEnum.THEORY_COURSE) {
+                    spod.setType(OrderDetailTypeEnum.COURSE);
+                    //courseAmount = courseAmount.add(spod.getPrice().subtract(spod.getRemitFee()));
+                } else if (spod.getType() == OrderDetailTypeEnum.MUSICAL) {
+                    if (subjectChange != null && spod.getPaymentOrderId() <= subjectChange.getOriginalOrderId()) {
+                        if (subjectChange.getChangeMusical() == null) {
+                            continue;
+                        }
+                        kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
+                        musicalId = subjectChange.getChangeMusical() + "";
+                        spod.setPrice(subjectChange.getChangeMusicalPrice());
+                        spod.setRemitFee(BigDecimal.ZERO);
+                        isChangeMusical = true;
+                    } else {
+                        kitGroupPurchaseType = spod.getKitGroupPurchaseType();
+                        musicalId = spod.getGoodsIdList();
+                        //musicalAmount = musicalAmount.add(spod.getPrice());
+                    }
+                } else if (spod.getType() == OrderDetailTypeEnum.ACCESSORIES) {
+                    if (subjectChange != null && (subjectChange.getOriginalOrderId() != null && spod.getPaymentOrderId() <= subjectChange.getOriginalOrderId())) {
+                        if (StringUtils.isBlank(subjectChange.getChangeAccessories()) || isCalculatedOfAccessories == true) {
+                            continue;
+                        }
+                        isCalculatedOfAccessories = true;
+                        accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
+                        //accessoriesAmount = accessoriesAmount.add(subjectChange.getChangeAccessoriesPrice());
+                        spod.setPrice(subjectChange.getChangeAccessoriesPrice());
+                        spod.setRemitFee(BigDecimal.ZERO);
+                        isChangeAccessories = true;
+                    } else {
+                        accessoriesId = accessoriesId.append(spod.getGoodsIdList()).append(",");
+                        //accessoriesAmount = accessoriesAmount.add(spod.getPrice());
+                    }
+                }
+
+                amount = userOrderTypeMap.get(spod.getType());
+                if (amount != null) {
+                    amount = amount.add(spod.getPrice().subtract(spod.getRemitFee()));
+                } else {
+                    amount = spod.getPrice().subtract(spod.getRemitFee());
+                }
+                userOrderTypeMap.put(spod.getType(), amount);
+
+                orderTotalAmount = orderTotalAmount.add(spod.getPrice().subtract(spod.getRemitFee()));
+            }
+
+            if (orderDetailList.size() == 0) {
+                if (subjectChange != null) {
+                    if (subjectChange.getChangeMusical() != null) {
+                        kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
+                        musicalId = subjectChange.getChangeMusical() + "";
+                        userOrderTypeMap.put(OrderDetailTypeEnum.MUSICAL, subjectChange.getChangeMusicalPrice());
+                        orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeMusicalPrice());
+                    }
+                    if (StringUtils.isNotBlank(subjectChange.getChangeAccessories())) {
+                        accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
+                        userOrderTypeMap.put(OrderDetailTypeEnum.ACCESSORIES, subjectChange.getChangeAccessoriesPrice());
+                        orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeAccessoriesPrice());
+                    }
+                }
+            } else if (isChangeAccessories == false || isChangeMusical == false) {
+                if (subjectChange != null) {
+                    if (subjectChange.getChangeMusical() != null && isChangeMusical == false) {
+                        kitGroupPurchaseType = subjectChange.getKitGroupPurchaseType();
+                        musicalId = subjectChange.getChangeMusical() + "";
+                        userOrderTypeMap.put(OrderDetailTypeEnum.MUSICAL, subjectChange.getChangeMusicalPrice());
+                        orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeMusicalPrice());
+                    }
+                    if (StringUtils.isNotBlank(subjectChange.getChangeAccessories()) && isChangeAccessories == false) {
+                        accessoriesId = accessoriesId.append(subjectChange.getChangeAccessories()).append(",");
+                        userOrderTypeMap.put(OrderDetailTypeEnum.ACCESSORIES, subjectChange.getChangeAccessoriesPrice());
+                        orderTotalAmount = orderTotalAmount.add(subjectChange.getChangeAccessoriesPrice());
+                    }
+                }
+            }
+
+            dto.setAccessoriesAmount(userOrderTypeMap.get(OrderDetailTypeEnum.ACCESSORIES));
+            dto.setCourseAmount(userOrderTypeMap.get(OrderDetailTypeEnum.COURSE));
+            dto.setMusicalAmount(userOrderTypeMap.get(OrderDetailTypeEnum.MUSICAL));
+            dto.setMaintenanceAmount(userOrderTypeMap.get(OrderDetailTypeEnum.MAINTENANCE));
+            dto.setCloudTeacherAmount(userOrderTypeMap.get(OrderDetailTypeEnum.CLOUD_TEACHER) == null ? userOrderTypeMap
+                    .get(OrderDetailTypeEnum.CLOUD_TEACHER_PLUS) : userOrderTypeMap.get(OrderDetailTypeEnum.CLOUD_TEACHER));
+
+            if (StringUtils.isNoneBlank(accessoriesId.toString())) {
+                String accessoriesIdList = StringUtils.removeEnd(accessoriesId.toString(), ",");
+                Map<Integer, Goods> goodsMap = goodsService.findGoodsByIds(accessoriesIdList).stream().collect(Collectors.toMap(Goods::getId, Goods -> Goods));
+
+                String[] accessoriesIds = StringUtils.split(accessoriesIdList, ',');
+
+                StringBuffer sb = new StringBuffer();
+                for (String s : accessoriesIds) {
+                    if (StringUtils.isBlank(s)) {
+                        continue;
+                    }
+                    sb.append(goodsMap.get(Integer.parseInt(s)).getName()).append(",");
+                }
+                dto.setAccessoriesName(StringUtils.removeEnd(sb.toString(), ","));
+            }
+
+            if (StringUtils.isNoneBlank(musicalId)) {
+                dto.setMusicalName(goodsService.findGoodsByIds(musicalId).stream().map(Goods::getName).collect(Collectors.joining(",")));
+            }
+            dto.setKitGroupPurchaseTypeEnum(kitGroupPurchaseType);
+            dto.setMusicGroupName(musicGroup.getName());
+            dto.setOrganName(organization.getName());
+            dto.setOrderAmount(orderTotalAmount);
+            dto.setUserId(userId);
+            dto.setSubjectName(userSubjectMap.get(userId));
+            dto.setUsername(usernameMap.get(userId));
+
+            musicalListDetailDtos.add(dto);
         }
-    	
+
         return musicalListDetailDtos;
     }
 
@@ -480,36 +510,36 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     }
 
     @Override
-	public List<StudentPaymentOrderDetail> getOrderDetail(Long orderId) {
-    	
-    	if(orderId == null){
-    		return new ArrayList<StudentPaymentOrderDetail>();
-    	}
-		
-    	List<Long> orderIdList = new ArrayList<Long>();
-    	orderIdList.add(orderId);
-    		
-    	return getOrderDetail(orderIdList);
-	}
+    public List<StudentPaymentOrderDetail> getOrderDetail(Long orderId) {
+
+        if (orderId == null) {
+            return new ArrayList<StudentPaymentOrderDetail>();
+        }
+
+        List<Long> orderIdList = new ArrayList<Long>();
+        orderIdList.add(orderId);
+
+        return getOrderDetail(orderIdList);
+    }
+
+    @Override
+    public List<StudentPaymentOrderDetail> getOrderDetail(List<Long> orderIdList) {
+        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailDao.getOrderDetailByOrderId(orderIdList);
+
+        for (StudentPaymentOrderDetail spod : studentPaymentOrderDetailList) {
+            if (spod.getType() == OrderDetailTypeEnum.ACCESSORIES || spod.getType() == OrderDetailTypeEnum.MUSICAL
+                    || spod.getType() == OrderDetailTypeEnum.TEACHING) {
+                List<Goods> goods = goodsService.findGoodsByIds(spod.getGoodsIdList());
+                if (goods != null && goods.size() > 0) {
+                    spod.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
+                }
+            }
+        }
+
+        return studentPaymentOrderDetailList;
+    }
 
     @Override
-	public List<StudentPaymentOrderDetail> getOrderDetail(List<Long> orderIdList) {
-    	List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailDao.getOrderDetailByOrderId(orderIdList);
-
-		for (StudentPaymentOrderDetail spod : studentPaymentOrderDetailList) {
-			if (spod.getType() == OrderDetailTypeEnum.ACCESSORIES || spod.getType() == OrderDetailTypeEnum.MUSICAL
-					|| spod.getType() == OrderDetailTypeEnum.TEACHING) {
-				List<Goods> goods = goodsService.findGoodsByIds(spod.getGoodsIdList());
-				if (goods != null && goods.size() > 0) {
-					spod.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
-				}
-			}
-		}
-
-		return studentPaymentOrderDetailList;
-	}
-
-	@Override
     public List<String> getOrderDetailType(Long orderId) {
         return studentPaymentOrderDetailDao.getOrderDetailType(orderId);
     }
@@ -524,16 +554,16 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         return studentPaymentOrderDetailDao.findApplyOrderGoods(orderId);
     }
 
-    public void addOrderDetailTo(StudentPaymentOrder studentPaymentOrder,MusicGroup musicGroup,StudentRegistration studentRegistration){
+    public void addOrderDetailTo(StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup, StudentRegistration studentRegistration) {
         //SurplusCourseFee
         List<StudentPaymentOrderDetail> allDetails = this.findByOrderId(studentPaymentOrder.getId());
         BigDecimal courseFee = allDetails.stream().filter(o -> !(o.getType() == MUSICAL)
-                && !(o.getType() == VIP)
-                && !(o.getType() == PRACTICE)
-                && !(o.getType() == MAINTENANCE)
-                && !(o.getType() == CLOUD_TEACHER)
-                && !(o.getType() == CLOUD_TEACHER_PLUS)
-                && !(o.getType() == ACCESSORIES))
+                        && !(o.getType() == VIP)
+                        && !(o.getType() == PRACTICE)
+                        && !(o.getType() == MAINTENANCE)
+                        && !(o.getType() == CLOUD_TEACHER)
+                        && !(o.getType() == CLOUD_TEACHER_PLUS)
+                        && !(o.getType() == ACCESSORIES))
                 .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
         if (studentRegistration.getTemporaryCourseFee() != null) {
@@ -544,7 +574,7 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
         if (studentPaymentOrder.getClassGroupId() == null || !studentPaymentOrder.getClassGroupId().equals(206)) {
             studentRegistration.setPayingStatus(0);
         }
-        if(courseFee.compareTo(BigDecimal.ZERO) > 0){
+        if (courseFee.compareTo(BigDecimal.ZERO) > 0) {
             //累加充值金额
             studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(courseFee));
             //添加日志
@@ -564,11 +594,11 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
 
         List<OrderDetailTypeEnum> detailTypeEnums = allDetails.stream().map(e -> e.getType()).collect(Collectors.toList());
         //销售订单详情
-        if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) ||detailTypeEnums.contains(ACCESSORIES) ||detailTypeEnums.contains(TEACHING))) {
+        if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) || detailTypeEnums.contains(ACCESSORIES) || detailTypeEnums.contains(TEACHING))) {
             BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
-                BigDecimal musicFee = allDetails.stream().filter(o -> o.getType()==MUSICAL
-                        || o.getType()==ACCESSORIES || o.getType()==TEACHING)
+            if (couponRemitFee.compareTo(BigDecimal.ZERO) > 0) {
+                BigDecimal musicFee = allDetails.stream().filter(o -> o.getType() == MUSICAL
+                                || o.getType() == ACCESSORIES || o.getType() == TEACHING)
                         .map(o -> o.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
                 BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
                 //获取比例
@@ -576,32 +606,32 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
                 //获取分配的减免金额
                 couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
             }
-            sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup,couponRemitFee);
+            sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup, couponRemitFee);
         }
 
         //活动小课包处理
-        List<StudentPaymentOrderDetail> activity = allDetails.stream().filter(o -> o.getType()==PRACTICE || o.getType() == VIP).collect(Collectors.toList());
-        if(activity != null && activity.size() > 0){
-            activityUserMapperService.addOrderDetail2Activity(studentPaymentOrder,activity);
+        List<StudentPaymentOrderDetail> activity = allDetails.stream().filter(o -> o.getType() == PRACTICE || o.getType() == VIP).collect(Collectors.toList());
+        if (activity != null && activity.size() > 0) {
+            activityUserMapperService.addOrderDetail2Activity(studentPaymentOrder, activity);
         }
 
         //学生乐器与月保处理
-        if(detailTypeEnums.contains(MUSICAL)){
-            StudentPaymentOrderDetail musical = allDetails.stream().filter(o -> o.getType()==MUSICAL).findFirst().get();
+        if (detailTypeEnums.contains(MUSICAL)) {
+            StudentPaymentOrderDetail musical = allDetails.stream().filter(o -> o.getType() == MUSICAL).findFirst().get();
             Long studentInstrumentId = studentInstrumentService.addOrderDetail2Instrument(studentPaymentOrder, Integer.valueOf(musical.getGoodsIdList()));
-            if(detailTypeEnums.contains(MAINTENANCE)){
-                StudentPaymentOrderDetail repair = allDetails.stream().filter(o -> o.getType()==MAINTENANCE).findFirst().get();
+            if (detailTypeEnums.contains(MAINTENANCE)) {
+                StudentPaymentOrderDetail repair = allDetails.stream().filter(o -> o.getType() == MAINTENANCE).findFirst().get();
                 repair.setStudentInstrumentId(studentInstrumentId);
                 studentPaymentOrderDetailDao.update(repair);
             }
         }
 
         //学生云教练处理
-        if(detailTypeEnums.contains(CLOUD_TEACHER)){
-            BigDecimal cloudTeacherFee = allDetails.stream() .filter(o -> o.getType()==CLOUD_TEACHER)
+        if (detailTypeEnums.contains(CLOUD_TEACHER)) {
+            BigDecimal cloudTeacherFee = allDetails.stream().filter(o -> o.getType() == CLOUD_TEACHER)
                     .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
-            cloudTeacherOrderService.addOrderDetail2CloudTeacher(studentPaymentOrder,cloudTeacherFee);
+            cloudTeacherOrderService.addOrderDetail2CloudTeacher(studentPaymentOrder, cloudTeacherFee);
         }
     }
 

+ 127 - 127
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -109,70 +109,70 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private final static Logger LOGGER = LoggerFactory.getLogger(StudentPaymentOrderServiceImpl.class);
 
     @Override
-    public StudentPaymentOrder findByUserAndActive(Integer userId, Integer activeRemark, String remark,String status) {
-        return studentPaymentOrderDao.findByUserAndActive(userId,activeRemark,remark,status);
+    public StudentPaymentOrder findByUserAndActive(Integer userId, Integer activeRemark, String remark, String status) {
+        return studentPaymentOrderDao.findByUserAndActive(userId, activeRemark, remark, status);
     }
 
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
-	public Map createOrder(StudentPaymentOrder studentPaymentOrder, List<StudentPaymentOrderDetail> details, String payReceiver) throws Exception {
+    public Map createOrder(StudentPaymentOrder studentPaymentOrder, List<StudentPaymentOrderDetail> details, String payReceiver) throws Exception {
 
-    	BigDecimal cashAmount = studentPaymentOrder.getActualAmount();
-    	BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-    	BigDecimal balance = studentPaymentOrder.getBalancePaymentAmount();
+        BigDecimal cashAmount = studentPaymentOrder.getActualAmount();
+        BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
+        BigDecimal balance = studentPaymentOrder.getBalancePaymentAmount();
 
-		if (cashAmount.add(balance).compareTo(expectAmount) != 0) {
-			throw new BizException("支付金额不正确,请重试");
-		}
+        if (cashAmount.add(balance).compareTo(expectAmount) != 0) {
+            throw new BizException("支付金额不正确,请重试");
+        }
 
-		Date date = new Date();
-		studentPaymentOrder.setUpdateTime(date);
+        Date date = new Date();
+        studentPaymentOrder.setUpdateTime(date);
 
-		StudentPaymentOrder orignStudentPaymentOrder = get(studentPaymentOrder.getId());
-		if(orignStudentPaymentOrder == null){
+        StudentPaymentOrder orignStudentPaymentOrder = get(studentPaymentOrder.getId());
+        if (orignStudentPaymentOrder == null) {
 
-			String orderNo = idGeneratorService.generatorId("payment") + "";
-			studentPaymentOrder.setOrderNo(orderNo);
-			studentPaymentOrder.setCreateTime(date);
-			studentPaymentOrder.setUpdateTime(date);
-			studentPaymentOrder.setVersion(0);
-			insert(studentPaymentOrder);
-		}
+            String orderNo = idGeneratorService.generatorId("payment") + "";
+            studentPaymentOrder.setOrderNo(orderNo);
+            studentPaymentOrder.setCreateTime(date);
+            studentPaymentOrder.setUpdateTime(date);
+            studentPaymentOrder.setVersion(0);
+            insert(studentPaymentOrder);
+        }
 
-		if(details != null && details.size() > 0){
-			for(StudentPaymentOrderDetail spod : details){
-				spod.setPaymentOrderId(studentPaymentOrder.getId());
-				spod.setCreateTime(date);
-				spod.setUpdateTime(date);
-			}
+        if (details != null && details.size() > 0) {
+            for (StudentPaymentOrderDetail spod : details) {
+                spod.setPaymentOrderId(studentPaymentOrder.getId());
+                spod.setCreateTime(date);
+                spod.setUpdateTime(date);
+            }
 
-			studentPaymentOrderDetailService.batchAdd(details,studentPaymentOrder.getCouponRemitFee());
-		}
+            studentPaymentOrderDetailService.allocateAndAdd(details, studentPaymentOrder.getCouponRemitFee());
+        }
 
-		String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
+        String baseApiUrl = sysConfigDao.findConfigValue("base_api_url");
 
-		if (cashAmount.compareTo(BigDecimal.ZERO) == 0) {
+        if (cashAmount.compareTo(BigDecimal.ZERO) == 0) {
 
-			studentPaymentRouteOrderService.addRouteOrder(studentPaymentOrder.getOrderNo(), studentPaymentOrder.getOrganId(), balance);
+            studentPaymentRouteOrderService.addRouteOrder(studentPaymentOrder.getOrderNo(), studentPaymentOrder.getOrganId(), balance);
 
-			Map<String, String> notifyMap = new HashMap<>(4);
-			notifyMap.put("tradeState", "1");
-			notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
-			notifyMap.put("channelType", "");
-			notifyMap.put("orderNo", "");
-			updateOrder(notifyMap);
-			return notifyMap;
-		}
+            Map<String, String> notifyMap = new HashMap<>(4);
+            notifyMap.put("tradeState", "1");
+            notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
+            notifyMap.put("channelType", "");
+            notifyMap.put("orderNo", "");
+            updateOrder(notifyMap);
+            return notifyMap;
+        }
 
-		Map<String, Object> payMap = payService.getPayMap(cashAmount, balance, studentPaymentOrder.getOrderNo(), baseApiUrl + "/api-student/studentOrder/notify", baseApiUrl
-				+ "/api-student/studentOrder/paymentResult?orderNo=" + studentPaymentOrder.getOrderNo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getOrganId(), payReceiver);
+        Map<String, Object> payMap = payService.getPayMap(cashAmount, balance, studentPaymentOrder.getOrderNo(), baseApiUrl + "/api-student/studentOrder/notify", baseApiUrl
+                + "/api-student/studentOrder/paymentResult?orderNo=" + studentPaymentOrder.getOrderNo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getMemo(), studentPaymentOrder.getOrganId(), payReceiver);
 
-		studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
-		studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
-		studentPaymentOrder.setUpdateTime(date);
-		update(studentPaymentOrder);
-		return payMap;
-	}
+        studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrder.setUpdateTime(date);
+        update(studentPaymentOrder);
+        return payMap;
+    }
 
     @Override
     public List<StudentPaymentOrder> queryByCondition(GroupType groupType, String musicGroupId, Integer userId, DealStatusEnum status, OrderTypeEnum type) {
@@ -190,9 +190,9 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-	public List<StudentPaymentOrder> queryByBatchNo(Integer userId, String batchNo, DealStatusEnum status) {
-		return studentPaymentOrderDao.queryByBatchNo(userId, batchNo, status);
-	}
+    public List<StudentPaymentOrder> queryByBatchNo(Integer userId, String batchNo, DealStatusEnum status) {
+        return studentPaymentOrderDao.queryByBatchNo(userId, batchNo, status);
+    }
 
     @Override
     public List<StudentPaymentOrder> findOrdersByStatus(DealStatusEnum status, String paymentChannel) {
@@ -261,9 +261,9 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         if (payingOrders == null) {
             payingOrders = findOrdersByStatus(DealStatusEnum.ING, "ADAPAY");
         }
-        
+
         Date date = new Date();
-        
+
         if (payingOrders.size() == 0) {
             return;
         }
@@ -279,12 +279,12 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 continue;
             }
             //查询支付超过10分钟的
-            if(DateUtil.minutesBetween(payingOrder.getCreateTime(), date) < 10){
-            	continue;
+            if (DateUtil.minutesBetween(payingOrder.getCreateTime(), date) < 10) {
+                continue;
             }
             Map<String, Object> payment = Payment.queryPayment(payingOrder.getTransNo());
             LOGGER.info("订单[{}]交易主动查询接口返回:{}", payingOrder.getTransNo(), payment);
-            
+
             Map<String, String> rpMap = new HashMap<>();
             rpMap.put("merOrderNo", payingOrder.getOrderNo());
             rpMap.put("orderNo", payingOrder.getTransNo());
@@ -295,7 +295,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             }
             if (status.equals("succeeded")) {
                 rpMap.put("tradeState", "1");
-            }else if (status.equals("failed") || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2), date) > 0)) {
+            } else if (status.equals("failed") || (DateUtil.minutesBetween(DateUtil.addHours(payingOrder.getUpdateTime(), 2), date) > 0)) {
                 rpMap.put("tradeState", "0");
             }
 
@@ -370,7 +370,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     private Boolean confirmOrder(StudentPaymentOrder order) {
-    	Date date = new Date();
+        Date date = new Date();
         List<StudentPaymentRouteOrder> routeOrders = studentPaymentRouteOrderDao.getRouteOrders(order.getOrderNo());
         for (StudentPaymentRouteOrder routeOrder : routeOrders) {
             Map<String, Object> divMember = new HashMap<>();
@@ -390,7 +390,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             confirm.put("div_members", divMembers);
             try {
                 Map<String, Object> map = Payment.createConfirm(confirm);
-                LOGGER.info("分账信息返回:{}",map);
+                LOGGER.info("分账信息返回:{}", map);
                 routeOrder.setServiceFee(new BigDecimal(map.get("fee_amt").toString()));
                 routeOrder.setUpdateTime(date);
                 studentPaymentRouteOrderDao.update(routeOrder);
@@ -463,13 +463,13 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             studentInstrumentService.orderCallback(order);
         } else if (order.getType().equals(OrderTypeEnum.REPLACEMENT)) {
             replacementInstrumentActivityService.orderCallback(order);
-        }else if (order.getType().equals(OrderTypeEnum.DEGREE)) {
+        } else if (order.getType().equals(OrderTypeEnum.DEGREE)) {
             childrenDayReserveService.orderCallback(order);
-        }else if (order.getType().equals(OrderTypeEnum.MEMBER)) {
-        	memberRankSettingService.orderCallback(order);
-        }else if (order.getType().equals(OrderTypeEnum.ACTIVITY)) {
+        } else if (order.getType().equals(OrderTypeEnum.MEMBER)) {
+            memberRankSettingService.orderCallback(order);
+        } else if (order.getType().equals(OrderTypeEnum.ACTIVITY)) {
             practiceGroupService.activityOrderCallback(order);
-        }else if (order.getType().equals(OrderTypeEnum.DOUBLE_ELEVEN2021)) {
+        } else if (order.getType().equals(OrderTypeEnum.DOUBLE_ELEVEN2021)) {
             practiceGroupService.doubleEleven2021OrderCallback(order);
         }
     }
@@ -608,8 +608,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         List<StudentPaymentOrderExportDto> orders = studentPaymentOrderDao.getUserApplyOrders(studentId, musicGroupId);
         StudentRegistration studentRegister = studentRegistrationService.getStudentRegister(musicGroupId, studentId);
         for (StudentPaymentOrderExportDto order : orders) {
-            if((DealStatusEnum.ING.equals(order.getStatus())||DealStatusEnum.SUCCESS.equals(order.getStatus())) &&
-                studentRegister.getPayingStatus().equals(2)){
+            if ((DealStatusEnum.ING.equals(order.getStatus()) || DealStatusEnum.SUCCESS.equals(order.getStatus())) &&
+                    studentRegister.getPayingStatus().equals(2)) {
                 order.setPayingStatus(2);
             }
             if (order.getOrderDetailList() == null) continue;
@@ -625,8 +625,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                 if (StringUtils.isNotBlank(childGoodIds)) {
                     studentPaymentOrderDetail.setChildGoodsList(goodsDao.findGoodsByIds(childGoodIds));
                 }
-                if(studentPaymentOrderDetail.getType() == OrderDetailTypeEnum.CLOUD_TEACHER ||studentPaymentOrderDetail.getType() == OrderDetailTypeEnum.CLOUD_TEACHER_PLUS){
-                	studentPaymentOrderDetail.setCloudTeacherOrderDto(cloudTeacherOrderService.queryOrderInfoByOrderId(studentPaymentOrderDetail.getPaymentOrderId()));
+                if (studentPaymentOrderDetail.getType() == OrderDetailTypeEnum.CLOUD_TEACHER || studentPaymentOrderDetail.getType() == OrderDetailTypeEnum.CLOUD_TEACHER_PLUS) {
+                    studentPaymentOrderDetail.setCloudTeacherOrderDto(cloudTeacherOrderService.queryOrderInfoByOrderId(studentPaymentOrderDetail.getPaymentOrderId()));
                 }
             }
         }
@@ -638,65 +638,65 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
         return studentPaymentOrderDao.getUserReplacementIngOrder(userId, replacementId);
     }
 
-	@Override
-	public int batchUpdate(List<StudentPaymentOrder> studentPaymentOrderList) {
-		return studentPaymentOrderDao.batchUpdate(studentPaymentOrderList);
-	}
-
-	@Override
-	public PayStatus queryPayStatus(String paymentChannel, String orderNo, String transNo) throws Exception {
-		if (StringUtils.isBlank(transNo)) {
-			return PayStatus.FAILED;
-		}
-		if (StringUtils.equals(paymentChannel, "ADAPAY")) {
-			Map<String, Object> payment = Payment.queryPayment(transNo);
-			String status = (String) payment.get("status");
-			if (status.equals("succeeded")) {
-				return PayStatus.SUCCESSED;
-			} else if (status.equals("failed")) {
-				return PayStatus.FAILED;
-			} else {
-				return PayStatus.PAYING;
-			}
-		} else if (StringUtils.equals(paymentChannel, "YQPAY")) {
-			String notifyUrl = ""; // 回调地址
-			Map<String, Object> resultMap = new LinkedHashMap<>();
-			resultMap.put("merOrderNoList", orderNo);
-			Map<String, Object> requestMap = YqPayUtil.getRequestMap(notifyUrl, resultMap);
-
-			RsqMsg rsqMsg = new RsqMsg(requestMap);
-
-			Msg queryRs = yqPayFeignService.orderQuery(rsqMsg);
-
-			if (queryRs.getCode().equals("88")) {
-				// 更新订单状态
-				String responseParameters = queryRs.getResponseParameters();
-				List<Map<String, String>> responseList = JSON.parseObject(responseParameters, List.class);
-				for (Map<String, String> response : responseList) {
-
-					if (StringUtils.equals(response.get("tradeState"), "1")) {
-						return PayStatus.SUCCESSED;
-					} else if (StringUtils.equals(response.get("tradeState"), "0") || StringUtils.equals(response.get("tradeState"), "7")) {
-						return PayStatus.FAILED;
-					} else {
-						return PayStatus.PAYING;
-					}
-				}
-			}
-		}
-		throw new BizException("支付渠道错误");
-	}
+    @Override
+    public int batchUpdate(List<StudentPaymentOrder> studentPaymentOrderList) {
+        return studentPaymentOrderDao.batchUpdate(studentPaymentOrderList);
+    }
+
+    @Override
+    public PayStatus queryPayStatus(String paymentChannel, String orderNo, String transNo) throws Exception {
+        if (StringUtils.isBlank(transNo)) {
+            return PayStatus.FAILED;
+        }
+        if (StringUtils.equals(paymentChannel, "ADAPAY")) {
+            Map<String, Object> payment = Payment.queryPayment(transNo);
+            String status = (String) payment.get("status");
+            if (status.equals("succeeded")) {
+                return PayStatus.SUCCESSED;
+            } else if (status.equals("failed")) {
+                return PayStatus.FAILED;
+            } else {
+                return PayStatus.PAYING;
+            }
+        } else if (StringUtils.equals(paymentChannel, "YQPAY")) {
+            String notifyUrl = ""; // 回调地址
+            Map<String, Object> resultMap = new LinkedHashMap<>();
+            resultMap.put("merOrderNoList", orderNo);
+            Map<String, Object> requestMap = YqPayUtil.getRequestMap(notifyUrl, resultMap);
+
+            RsqMsg rsqMsg = new RsqMsg(requestMap);
+
+            Msg queryRs = yqPayFeignService.orderQuery(rsqMsg);
+
+            if (queryRs.getCode().equals("88")) {
+                // 更新订单状态
+                String responseParameters = queryRs.getResponseParameters();
+                List<Map<String, String>> responseList = JSON.parseObject(responseParameters, List.class);
+                for (Map<String, String> response : responseList) {
+
+                    if (StringUtils.equals(response.get("tradeState"), "1")) {
+                        return PayStatus.SUCCESSED;
+                    } else if (StringUtils.equals(response.get("tradeState"), "0") || StringUtils.equals(response.get("tradeState"), "7")) {
+                        return PayStatus.FAILED;
+                    } else {
+                        return PayStatus.PAYING;
+                    }
+                }
+            }
+        }
+        throw new BizException("支付渠道错误");
+    }
 
     @Override
     public Integer getOrderIdByMusical(String musicGroupId, Integer studentId) {
-        return studentPaymentOrderDao.getOrderIdByMusical(musicGroupId,studentId);
+        return studentPaymentOrderDao.getOrderIdByMusical(musicGroupId, studentId);
     }
 
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Integer activityGive(Integer vipGroupActivityId, StudentPaymentOrder studentPaymentOrder, Long vipGroupId, Long practiceGroupId, Integer teacherId) {
         Integer activityUserMapperId = null;
-        if(vipGroupActivityId != null){
+        if (vipGroupActivityId != null) {
             ActivityUserMapper activityUserMapper = new ActivityUserMapper();
             activityUserMapper.setVipGroupId(vipGroupId);
             activityUserMapper.setPracticeGroupId(practiceGroupId);
@@ -705,27 +705,27 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
             activityUserMapper.setActivityId(vipGroupActivityId);
             activityUserMapper.setTeacherId(teacherId);
             activityUserMapper.setActualPrice(studentPaymentOrder.getExpectAmount());
-            if(vipGroupId != null){
+            if (vipGroupId != null) {
                 activityUserMapper.setVipFlag(2);
-            }else {
+            } else {
                 activityUserMapper.setPracticeFlag(2);
             }
             //是否达到满赠标准
             VipGroupActivity activity = vipGroupActivityDao.get(vipGroupActivityId);
-            if(activity.getFullMinusCourseTimes() == -1 || studentPaymentOrder.getActivityBuyNum() < activity.getFullMinusCourseTimes()){
+            if (activity.getFullMinusCourseTimes() == -1 || studentPaymentOrder.getActivityBuyNum() < activity.getFullMinusCourseTimes()) {
                 activityUserMapperDao.insert(activityUserMapper);
                 return activityUserMapper.getId();
             }
             //是否赠送课程
-            if(activity.getGiveCourseNum() > 0){
-                if(activity.getGiveCourseType().equals("VIP")){
+            if (activity.getGiveCourseNum() > 0) {
+                if (activity.getGiveCourseType().equals("VIP")) {
                     activityUserMapper.setGiveVipFlag(1);
-                }else {
+                } else {
                     activityUserMapper.setGivePracticeFlag(1);
                 }
             }
             //是否赠送会员(会员立即生效)
-            if(activity.getGiveMemberTime() > 0){
+            if (activity.getGiveMemberTime() > 0) {
                 Date now = new Date();
                 // 查询会员订单信息
                 CloudTeacherOrder cloudTeacherOrder = new CloudTeacherOrder();
@@ -747,7 +747,7 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
                     cloudTeacherOrder.setStartTime(DateUtil.addDays(student.getMembershipEndTime(), 1));
                     startDate = student.getMembershipEndTime();
                 }
-                cloudTeacherOrder.setEndTime(studentService.getMembershipEndTime(activity.getGivePeriodEnum(),startDate,activity.getGiveMemberTime()));
+                cloudTeacherOrder.setEndTime(studentService.getMembershipEndTime(activity.getGivePeriodEnum(), startDate, activity.getGiveMemberTime()));
                 cloudTeacherOrder.setTime(activity.getGiveMemberTime());
                 cloudTeacherOrderService.insert(cloudTeacherOrder);
                 // 添加会员有效时长
@@ -765,10 +765,10 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     public HttpResponseResult checkRepeatPay(StudentPaymentOrder order, Boolean repeatPay) throws Exception {
         // 查询订单状态
         PayStatus payStatus = this.queryPayStatus(order.getPaymentChannel(), order.getOrderNo(), order.getTransNo());
-        if(payStatus == PayStatus.SUCCESSED){
+        if (payStatus == PayStatus.SUCCESSED) {
             throw new BizException("订单已支付成功,请勿重复支付");
         }
-        if(!repeatPay){
+        if (!repeatPay) {
             return BaseController.failed(HttpStatus.CONTINUE, "您有待支付的订单,是否继续支付");
         }
         //处理关闭订单

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

@@ -18,13 +18,14 @@ import com.ym.mec.common.entity.ImResult;
 import com.ym.mec.common.entity.ImUserModel;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.page.WrapperUtil;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
-import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.im.ImFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,6 @@ import org.springframework.http.HttpStatus;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Propagation;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.io.IOException;
@@ -192,11 +192,11 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                 }
                 if (studentCloudTeacherMap.containsKey(e.getStudentId())) {
                     List<CloudTeacherOrder> cloudTeacherOrders = studentCloudTeacherMap.get(e.getStudentId());
-                    if(cloudTeacherOrders != null && cloudTeacherOrders.size() > 0){
+                    if (cloudTeacherOrders != null && cloudTeacherOrders.size() > 0) {
                         BigDecimal cloudAmount = BigDecimal.ZERO;
                         for (CloudTeacherOrder cloudTeacherOrder : cloudTeacherOrders) {
-                            if (cloudTeacherOrder.getEndTime() == null || DateUtil.stringToDate(DateUtil.format(cloudTeacherOrder.getEndTime(),DateUtil.ISO_EXPANDED_DATE_FORMAT),DateUtil.ISO_EXPANDED_DATE_FORMAT).compareTo(
-                                    DateUtil.stringToDate(DateUtil.format(nowDate,DateUtil.ISO_EXPANDED_DATE_FORMAT),DateUtil.ISO_EXPANDED_DATE_FORMAT)) >= 0) {
+                            if (cloudTeacherOrder.getEndTime() == null || DateUtil.stringToDate(DateUtil.format(cloudTeacherOrder.getEndTime(), DateUtil.ISO_EXPANDED_DATE_FORMAT), DateUtil.ISO_EXPANDED_DATE_FORMAT).compareTo(
+                                    DateUtil.stringToDate(DateUtil.format(nowDate, DateUtil.ISO_EXPANDED_DATE_FORMAT), DateUtil.ISO_EXPANDED_DATE_FORMAT)) >= 0) {
                                 cloudAmount = cloudAmount.add(cloudTeacherOrder.getAmount());
                             }
                         }
@@ -230,154 +230,153 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             musicGroupSubjectPlanService.addApplyStudentNum(musicGroupId, subId, 1);
             MusicGroup musicGroup = musicGroupDao.get(musicGroupId);
 
-            sendSeoMessageSource.sendSeoMessage(musicGroup.getOrganId(),new SysUserRoleEnum[]{SECTION_MANAGER},
-                    null,musicGroup.getEducationalTeacherId(),MessageTypeEnum.BACKSTAGE_STUDENT_SUBJECT_CHANGE, musicGroup.getName());
+            sendSeoMessageSource.sendSeoMessage(musicGroup.getOrganId(), new SysUserRoleEnum[]{SECTION_MANAGER},
+                    null, musicGroup.getEducationalTeacherId(), MessageTypeEnum.BACKSTAGE_STUDENT_SUBJECT_CHANGE, musicGroup.getName());
         }
         return i;
     }
 
     @Override
-	public List<StudentPaymentOrderDetail> queryFeeDetail(Integer studentId, String musicGroupId) {
+    public List<StudentPaymentOrderDetail> queryFeeDetail(Integer studentId, String musicGroupId) {
 
-		List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, musicGroupId, studentId,
-				DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
+        List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, musicGroupId, studentId,
+                DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
 
-		List<Long> orderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
+        List<Long> orderIdList = studentPaymentOrderList.stream().map(t -> t.getId()).collect(Collectors.toList());
 
-		List<StudentPaymentOrderDetail> studentPaymentOrderDetailList =new ArrayList<StudentPaymentOrderDetail>();
-		if(orderIdList != null && orderIdList.size() > 0){
-			studentPaymentOrderDetailList = studentPaymentOrderDetailService.getOrderDetail(orderIdList);
-		}
+        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<StudentPaymentOrderDetail>();
+        if (orderIdList != null && orderIdList.size() > 0) {
+            studentPaymentOrderDetailList = studentPaymentOrderDetailService.getOrderDetail(orderIdList);
+        }
 
-		SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
+        SubjectChange studentLastChange = subjectChangeDao.getStudentLastChange(studentId, musicGroupId);
 
-		if (studentLastChange != null) {
-			Iterator<StudentPaymentOrderDetail> iterator = studentPaymentOrderDetailList.iterator();
-			StudentPaymentOrderDetail spod = null;
-			while (iterator.hasNext()) {
-				spod = iterator.next();
-				if ((spod.getType() == OrderDetailTypeEnum.ACCESSORIES || spod.getType() == OrderDetailTypeEnum.MUSICAL) && (studentLastChange.getOriginalOrderId() != null && spod.getPaymentOrderId() <= studentLastChange.getOriginalOrderId())) {
-					iterator.remove();
-				}
-			}
+        if (studentLastChange != null) {
+            Iterator<StudentPaymentOrderDetail> iterator = studentPaymentOrderDetailList.iterator();
+            StudentPaymentOrderDetail spod = null;
+            while (iterator.hasNext()) {
+                spod = iterator.next();
+                if ((spod.getType() == OrderDetailTypeEnum.ACCESSORIES || spod.getType() == OrderDetailTypeEnum.MUSICAL) && (studentLastChange.getOriginalOrderId() != null && spod.getPaymentOrderId() <= studentLastChange.getOriginalOrderId())) {
+                    iterator.remove();
+                }
+            }
 
-			if (StringUtils.isNoneBlank(studentLastChange.getChangeAccessories())) {
-				StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
-				detail.setGoodsIdList(studentLastChange.getChangeAccessories());
-				List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
-				if (goods != null && goods.size() > 0) {
-					detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
-				}
-				if(studentLastChange.getOriginalOrderId() != null){
-					detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
-				}
-				detail.setPrice(studentLastChange.getChangeAccessoriesPrice());
-				detail.setType(OrderDetailTypeEnum.ACCESSORIES);
-				detail.setCreateTime(studentLastChange.getCreateTime());
+            if (StringUtils.isNoneBlank(studentLastChange.getChangeAccessories())) {
+                StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
+                detail.setGoodsIdList(studentLastChange.getChangeAccessories());
+                List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
+                if (goods != null && goods.size() > 0) {
+                    detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
+                }
+                if (studentLastChange.getOriginalOrderId() != null) {
+                    detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
+                }
+                detail.setPrice(studentLastChange.getChangeAccessoriesPrice());
+                detail.setType(OrderDetailTypeEnum.ACCESSORIES);
+                detail.setCreateTime(studentLastChange.getCreateTime());
 
-				studentPaymentOrderDetailList.add(detail);
-			}
-			if (studentLastChange.getChangeMusical() != null) {
-				StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
-				detail.setGoodsIdList(studentLastChange.getChangeMusical() + "");
-				List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
-				if (goods != null && goods.size() > 0) {
-					detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
-				}
-				if(studentLastChange.getOriginalOrderId() != null){
-					detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
-				}
-				detail.setPrice(studentLastChange.getChangeMusicalPrice());
-				detail.setType(OrderDetailTypeEnum.MUSICAL);
-				detail.setCreateTime(studentLastChange.getCreateTime());
+                studentPaymentOrderDetailList.add(detail);
+            }
+            if (studentLastChange.getChangeMusical() != null) {
+                StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
+                detail.setGoodsIdList(studentLastChange.getChangeMusical() + "");
+                List<Goods> goods = goodsDao.findGoodsByIds(detail.getGoodsIdList());
+                if (goods != null && goods.size() > 0) {
+                    detail.setName(goods.stream().map(t -> t.getName()).collect(Collectors.joining(",")));
+                }
+                if (studentLastChange.getOriginalOrderId() != null) {
+                    detail.setPaymentOrderId((long) studentLastChange.getOriginalOrderId());
+                }
+                detail.setPrice(studentLastChange.getChangeMusicalPrice());
+                detail.setType(OrderDetailTypeEnum.MUSICAL);
+                detail.setCreateTime(studentLastChange.getCreateTime());
 
-				studentPaymentOrderDetailList.add(detail);
-			}
-		}
+                studentPaymentOrderDetailList.add(detail);
+            }
+        }
 
-		return studentPaymentOrderDetailList;
-	}
+        return studentPaymentOrderDetailList;
+    }
 
     @Override
-	public Map<String, BigDecimal> queryRefundsDetail(Integer studentId, String musicGroupId) {
+    public Map<String, BigDecimal> queryRefundsDetail(Integer studentId, String musicGroupId) {
 
-		List<StudentPaymentOrderDetail> detailList = queryFeeDetail(studentId, musicGroupId);
+        List<StudentPaymentOrderDetail> detailList = queryFeeDetail(studentId, musicGroupId);
 
-		Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> detailMap = detailList.stream().collect(
-				Collectors.groupingBy(StudentPaymentOrderDetail::getType));
+        Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> detailMap = detailList.stream().collect(
+                Collectors.groupingBy(StudentPaymentOrderDetail::getType));
 
-		Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
+        Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
 
         if (detailMap.containsKey(OrderDetailTypeEnum.MUSICAL)) {
-			detailList = detailMap.get(OrderDetailTypeEnum.MUSICAL);
-			if (detailList == null) {
-				detailList = new ArrayList<StudentPaymentOrderDetail>();
-			}
+            detailList = detailMap.get(OrderDetailTypeEnum.MUSICAL);
+            if (detailList == null) {
+                detailList = new ArrayList<StudentPaymentOrderDetail>();
+            }
             BigDecimal reduce = detailList.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
 
-            map.put(OrderDetailTypeEnum.MUSICAL.getCode(),sysUserCashAccountLogService.musicReturnFeeCharges(reduce,0));
-		} else {
-			map.put(OrderDetailTypeEnum.MUSICAL.getCode(), BigDecimal.ZERO);
-		}
+            map.put(OrderDetailTypeEnum.MUSICAL.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(reduce, 0));
+        } else {
+            map.put(OrderDetailTypeEnum.MUSICAL.getCode(), BigDecimal.ZERO);
+        }
 
-		if (detailMap.containsKey(MAINTENANCE)) {
+        if (detailMap.containsKey(MAINTENANCE)) {
 
-			BigDecimal totalAmount = BigDecimal.ZERO;
+            BigDecimal totalAmount = BigDecimal.ZERO;
 
-			Date date = new Date();
+            Date date = new Date();
 
-			// 查询当前乐团报名订单中购买了乐保的订单
-			List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailDao.findUserApplyOrder(studentId, musicGroupId,
-					DealStatusEnum.SUCCESS);
+            // 查询当前乐团报名订单中购买了乐保的订单
+            List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = studentPaymentOrderDetailDao.findUserApplyOrder(studentId, musicGroupId,
+                    DealStatusEnum.SUCCESS);
 
-			if (studentPaymentOrderDetailList != null && studentPaymentOrderDetailList.size() > 0) {
+            if (studentPaymentOrderDetailList != null && studentPaymentOrderDetailList.size() > 0) {
 
-				Map<Long, StudentPaymentOrderDetail> maintenanceMap = studentPaymentOrderDetailList.stream()
-						.filter(t -> (t.getType() == MAINTENANCE))
-						.collect(Collectors.toMap(t -> t.getStudentInstrumentId(), StudentPaymentOrderDetail -> StudentPaymentOrderDetail));
+                Map<Long, StudentPaymentOrderDetail> maintenanceMap = studentPaymentOrderDetailList.stream()
+                        .filter(t -> (t.getType() == MAINTENANCE))
+                        .collect(Collectors.toMap(t -> t.getStudentInstrumentId(), StudentPaymentOrderDetail -> StudentPaymentOrderDetail));
 
-				List<Long> instrumentIdList = new ArrayList<Long>(maintenanceMap.keySet());
-				if (instrumentIdList != null && instrumentIdList.size() > 0) {
-					List<StudentInstrument> studentInstrumentList = studentInstrumentDao.queryById(instrumentIdList);
+                List<Long> instrumentIdList = new ArrayList<Long>(maintenanceMap.keySet());
+                if (instrumentIdList != null && instrumentIdList.size() > 0) {
+                    List<StudentInstrument> studentInstrumentList = studentInstrumentDao.queryById(instrumentIdList);
 
-					for (StudentInstrument si : studentInstrumentList) {
-						if (si.getDelFlag() == 1) {
-							continue;
-						}
+                    for (StudentInstrument si : studentInstrumentList) {
+                        if (si.getDelFlag() == 1) {
+                            continue;
+                        }
 
-						if ((si.getStatus() == 0 && si.getStartTime() == null) || si.getEndTime().after(date)) {
-							totalAmount = totalAmount.add(maintenanceMap.get(si.getId()).getPrice());
-						}
-					}
-				}
-			}
-			map.put(MAINTENANCE.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(totalAmount,0));
-		} else {
-			map.put(MAINTENANCE.getCode(), BigDecimal.ZERO);
-		}
+                        if ((si.getStatus() == 0 && si.getStartTime() == null) || si.getEndTime().after(date)) {
+                            totalAmount = totalAmount.add(maintenanceMap.get(si.getId()).getPrice());
+                        }
+                    }
+                }
+            }
+            map.put(MAINTENANCE.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(totalAmount, 0));
+        } else {
+            map.put(MAINTENANCE.getCode(), BigDecimal.ZERO);
+        }
 
-		if (detailMap.containsKey(OrderDetailTypeEnum.ACCESSORIES)) {
-			detailList = detailMap.get(OrderDetailTypeEnum.ACCESSORIES);
-			if (detailList == null) {
-				detailList = new ArrayList<StudentPaymentOrderDetail>();
-			}
+        if (detailMap.containsKey(OrderDetailTypeEnum.ACCESSORIES)) {
+            detailList = detailMap.get(OrderDetailTypeEnum.ACCESSORIES);
+            if (detailList == null) {
+                detailList = new ArrayList<StudentPaymentOrderDetail>();
+            }
             BigDecimal reduce = detailList.stream().map(StudentPaymentOrderDetail::getPrice).reduce(BigDecimal.ZERO, BigDecimal::add);
-            map.put(OrderDetailTypeEnum.ACCESSORIES.getCode(),sysUserCashAccountLogService.musicReturnFeeCharges(reduce,0));
-		} else {
-			map.put(OrderDetailTypeEnum.ACCESSORIES.getCode(), BigDecimal.ZERO);
-		}
+            map.put(OrderDetailTypeEnum.ACCESSORIES.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(reduce, 0));
+        } else {
+            map.put(OrderDetailTypeEnum.ACCESSORIES.getCode(), BigDecimal.ZERO);
+        }
 
-		StudentRegistration studentRegistration = studentRegistrationDao.getStudentRegister(musicGroupId, studentId);
-		if (studentRegistration == null) {
-			throw new BizException("学生报名信息查询失败");
-		}
-		//未上课*0995手续费、以上课*0.8
+        StudentRegistration studentRegistration = studentRegistrationDao.getStudentRegister(musicGroupId, studentId);
+        if (studentRegistration == null) {
+            throw new BizException("学生报名信息查询失败");
+        }
+        //未上课*0995手续费、以上课*0.8
         List<StudentCourseInfoDto> history = courseScheduleDao.findUserCourseInfos(GroupType.MUSIC, musicGroupId, studentId, "history");
-        map.put(OrderDetailTypeEnum.COURSE.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(studentRegistration.getSurplusCourseFee(),history.size()));
-
+        map.put(OrderDetailTypeEnum.COURSE.getCode(), sysUserCashAccountLogService.musicReturnFeeCharges(studentRegistration.getSurplusCourseFee(), history.size()));
 
 
-		// 查询云教练订单
+        // 查询云教练订单
 		/*BigDecimal cloudAmount = BigDecimal.ZERO;
 		List<Integer> studentIds = new ArrayList<Integer>();
 		studentIds.add(studentId);
@@ -396,10 +395,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
 		map.put(OrderDetailTypeEnum.CLOUD_TEACHER.getCode(), cloudAmount);*/
 
-		return map;
-	}
+        return map;
+    }
 
-	@Override
+    @Override
     public List<Map<String, Object>> getNoClassStuBySubjectId(String musicGroupId, String actualSubjectId) {
         List<StudentRegistration> students = studentRegistrationDao.getNoClassStuBySubjectId(musicGroupId, actualSubjectId);
         List<Map<String, Object>> mapArrayList = new ArrayList<>();
@@ -524,43 +523,45 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration, StudentPaymentOrder studentPaymentOrder,
-                                        MusicGroupApplyGoodsDto goodsDto,RegisterPayDto registerPayDto) {
+    public StudentPaymentOrder addOrder(StudentRegistration studentRegistration,
+                                        StudentPaymentOrder studentPaymentOrder,
+                                        MusicGroupApplyGoodsDto goodsDto,
+                                        RegisterPayDto registerPayDto,
+                                        CouponPayParam couponPayParam) throws Exception {
         Date date = new Date();
-        ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
+        List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
         //乐器及打包辅件
         String maintenanceGoodsId = "";
         List<MusicGroupSubjectGoodsGroup> goodsGroups = goodsDto.getGoodsGroups();
         List<MusicGroupPaymentCalenderCourseSettings> newCourses = goodsDto.getNewCourses();
         BigDecimal remitFee = goodsDto.getRemitFee();
-        if (goodsGroups != null && goodsGroups.size() > 0) {
+        if (CollectionUtils.isNotEmpty(goodsGroups)) {
             for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
                 StudentPaymentOrderDetail studentPaymentOrderDetail4goodsGroup = new StudentPaymentOrderDetail();
                 studentPaymentOrderDetail4goodsGroup.setRemitFee(BigDecimal.ZERO);
                 OrderDetailTypeEnum type = null;
                 if (goodsGroup.getType().equals(GoodsType.INSTRUMENT)) {
-                    type = OrderDetailTypeEnum.MUSICAL;
+                    type = OrderDetailTypeEnum.MUSICAL;//todo  乐器
                     goodsGroup.setPrice(goodsGroup.getPrice().subtract(remitFee));
                     studentPaymentOrderDetail4goodsGroup.setRemitFee(remitFee);
                 } else if (goodsGroup.getType().equals(GoodsType.ACCESSORIES)) {
-                    type = OrderDetailTypeEnum.ACCESSORIES;
+                    type = OrderDetailTypeEnum.ACCESSORIES;//todo 辅件
                 } else if (goodsGroup.getType().equals(GoodsType.OTHER)) {
-                    type = OrderDetailTypeEnum.TEACHING;
+                    type = OrderDetailTypeEnum.TEACHING;//todo 教谱
                 }
                 studentPaymentOrderDetail4goodsGroup.setType(type);
-                
+
                 BigDecimal goodsPrice = new BigDecimal(0);
-                
-                if(studentRegistration.getOrganId() == 55 && (newCourses == null || newCourses.size() == 0) && !registerPayDto.getBuyCloudTeacher()){
-                	//取商品零售价
+                if (studentRegistration.getOrganId() == 55 && (newCourses == null || newCourses.size() == 0) && !registerPayDto.getBuyCloudTeacher()) {
+                    //取商品零售价
                     if (StringUtils.isNotBlank(goodsGroup.getGoodsIdList())) {
-                    	List<Goods> goodsList = goodsDao.findGoodsByIds(goodsGroup.getGoodsIdList());
-                    	for(Goods goods : goodsList){
-                    		goodsPrice = goodsPrice.add(goods.getDiscountPrice());
-                    	}
+                        List<Goods> goodsList = goodsDao.findGoodsByIds(goodsGroup.getGoodsIdList());
+                        for (Goods goods : goodsList) {
+                            goodsPrice = goodsPrice.add(goods.getDiscountPrice());
+                        }
                     }
-                }else{
-                	goodsPrice = goodsGroup.getPrice();
+                } else {
+                    goodsPrice = goodsGroup.getPrice();
                 }
                 studentPaymentOrderDetail4goodsGroup.setPrice(goodsPrice);
                 studentPaymentOrderDetail4goodsGroup.setGoodsIdList(goodsGroup.getGoodsIdList());
@@ -575,8 +576,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             }
         }
 
-        //新的课程形态
-        if (newCourses != null && newCourses.size() > 0) {
+        //新的课程形态  todo  合奏课  单技课
+        if (CollectionUtils.isNotEmpty(newCourses)) {
             BigDecimal courseRemitFee = goodsDto.getCourseRemitFee();
             for (MusicGroupPaymentCalenderCourseSettings newCourse : newCourses) {
                 StudentPaymentOrderDetail studentPaymentOrderDetailCourse = new StudentPaymentOrderDetail();
@@ -597,7 +598,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
         //合班缴费
         List<MusicGroupPaymentCalenderStudentDetail> studentDetails = musicGroupPaymentCalenderStudentDetailDao.findByBatchNoAndUserId(registerPayDto.getBatchNo(), studentPaymentOrder.getUserId());
-        if(studentDetails != null && studentDetails.size() > 0){
+        if (CollectionUtils.isNotEmpty(studentDetails)) {
             for (MusicGroupPaymentCalenderStudentDetail studentDetail : studentDetails) {
                 StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
                 studentPaymentOrderDetail.setType(OrderDetailTypeEnum.valueOf(studentDetail.getCourseType()));
@@ -609,7 +610,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             }
         }
 
-        //乐保
+        //乐保 todo  乐保
         if (registerPayDto.getBuyMaintenance()) {
             if (StringUtils.isEmpty(maintenanceGoodsId)) {
                 throw new BizException("有乐器才能购买乐保,请核查");
@@ -625,13 +626,14 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             maintenanceOrderDetail.setIsRenew(0);
             studentPaymentOrderDetailList.add(maintenanceOrderDetail);
         }
-        //活动
+
+        //活动 todo  VIP 或 网管课
         List<Long> buyCalenderActivityId = registerPayDto.getBuyCalenderActivityId();
-        if (buyCalenderActivityId != null && buyCalenderActivityId.size() > 0) {
+        if (CollectionUtils.isNotEmpty(buyCalenderActivityId)) {
             List<MusicGroupPaymentCalenderActivity> calenderActivities = musicGroupPaymentCalenderActivityService.findByIds(buyCalenderActivityId);
             for (MusicGroupPaymentCalenderActivity calenderActivity : calenderActivities) {
                 StudentPaymentOrderDetail maintenanceOrderDetail = new StudentPaymentOrderDetail();
-                maintenanceOrderDetail.setType("网管课".equals(calenderActivity.getCategoryName())?PRACTICE:VIP);
+                maintenanceOrderDetail.setType("网管课".equals(calenderActivity.getCategoryName()) ? PRACTICE : VIP);
                 maintenanceOrderDetail.setPrice(calenderActivity.getActualAmount());
                 maintenanceOrderDetail.setRemitFee(BigDecimal.ZERO);
                 maintenanceOrderDetail.setCreateTime(date);
@@ -644,13 +646,12 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             }
         }
         MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
-        
-        //云教练/云教练+
+
+        //云教练/云教练+  todo  团练宝
         if (registerPayDto.getBuyCloudTeacher()) {
             MusicGroupPaymentCalenderMember calenderMember = musicGroupPaymentCalenderMemberService.findByCalenderId(studentPaymentOrder.getCalenderId());
-            OrderDetailTypeEnum orderDetailTypeEnum = OrderDetailTypeEnum.CLOUD_TEACHER;
             StudentPaymentOrderDetail cloudTeacherOrderDetail = new StudentPaymentOrderDetail();
-            cloudTeacherOrderDetail.setType(orderDetailTypeEnum);
+            cloudTeacherOrderDetail.setType(OrderDetailTypeEnum.CLOUD_TEACHER);
             cloudTeacherOrderDetail.setPrice(calenderMember.getActualAmount());
             cloudTeacherOrderDetail.setRemitFee(BigDecimal.ZERO);
             cloudTeacherOrderDetail.setCreateTime(date);
@@ -659,42 +660,57 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             cloudTeacherOrderDetail.setIsRenew(0);
             studentPaymentOrderDetailList.add(cloudTeacherOrderDetail);
         }
-        studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList,studentPaymentOrder.getCouponRemitFee());
+
+        //开始计算商品的优惠券
+        if (Objects.nonNull(couponPayParam) && Objects.nonNull(couponPayParam.getCouponTypeInfo())) {
+            //按OrderDetailTypeEnum类型 进行聚合分组
+            Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> orderDetailGroupList =
+                    WrapperUtil.groupList(studentPaymentOrderDetailList, StudentPaymentOrderDetail::getType);
+            //获取本次交易中各优惠券的使用信息
+            Map<String, CouponPayTypeInfo> couponParam = couponPayParam.getCouponTypeInfo();
+            //计算使用优惠券后的对应的商品应该均摊的金额
+            calculateCoupon(couponParam, orderDetailGroupList);
+            //获取使用了优惠券之后的总金额
+            BigDecimal useCouponAmount = WrapperUtil.sumList(studentPaymentOrderDetailList, StudentPaymentOrderDetail::getRemitFee);
+            studentPaymentOrder.setCouponRemitFee(useCouponAmount);
+        }
+        //添加订单明细
+        studentPaymentOrderDetailService.batchAdd(studentPaymentOrderDetailList);
 
         //增加缴费学生数,0元订单不增加报名人数(没买云教练/云教练+的)
         boolean paidZeroFlag = false;
 
         MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
-        
-		if (studentRegistration.getMusicGroupStatus() != StudentMusicGroupStatusEnum.NORMAL) {
-			// 判断之前是否已有订单
-			List<StudentPaymentOrder> oldStudentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC,
-					studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
-
-			int paidNum = musicOneSubjectClassPlan.getPaidStudentNum() == null ? 0 : musicOneSubjectClassPlan.getPaidStudentNum();
-			int paidZeroNum = musicOneSubjectClassPlan.getPaidZeroNum() == null ? 0 : musicOneSubjectClassPlan.getPaidZeroNum();
-			if ((musicGroup.getCourseViewType().equals(CourseViewTypeEnum.MEMBER_FEE) && !registerPayDto.getBuyCloudTeacher() && StringUtils.isBlank(maintenanceGoodsId))) {
-				if (studentRegistration.getPaymentStatus() != YES) {
-					paidZeroFlag = true;
-				}
-				if (studentRegistration.getNoneNeedCloudTeacher().equals(1) && (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0)) {
-					musicOneSubjectClassPlan.setPaidZeroNum(paidZeroNum + 1);
-					musicOneSubjectClassPlan.setPaidStudentNum(paidNum + 1);
-				}
-			} else {
-				if (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0) {
-					musicOneSubjectClassPlan.setPaidStudentNum(paidNum + 1);
-				}
-			}
-			if (musicOneSubjectClassPlan.getPaidStudentNum() > musicOneSubjectClassPlan.getExpectedStudentNum()) {
-				throw new BizException("乐团该声部人数暂时已满,请稍后再试");
-			}
 
-			int count = musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
-			if (count <= 0) {
-				throw new BizException("排队人数过多,请重试");
-			}
-		}
+        if (studentRegistration.getMusicGroupStatus() != StudentMusicGroupStatusEnum.NORMAL) {
+            // 判断之前是否已有订单
+            List<StudentPaymentOrder> oldStudentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC,
+                    studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.SUCCESS, OrderTypeEnum.APPLY);
+
+            int paidNum = musicOneSubjectClassPlan.getPaidStudentNum() == null ? 0 : musicOneSubjectClassPlan.getPaidStudentNum();
+            int paidZeroNum = musicOneSubjectClassPlan.getPaidZeroNum() == null ? 0 : musicOneSubjectClassPlan.getPaidZeroNum();
+            if ((musicGroup.getCourseViewType().equals(CourseViewTypeEnum.MEMBER_FEE) && !registerPayDto.getBuyCloudTeacher() && StringUtils.isBlank(maintenanceGoodsId))) {
+                if (studentRegistration.getPaymentStatus() != YES) {
+                    paidZeroFlag = true;
+                }
+                if (studentRegistration.getNoneNeedCloudTeacher().equals(1) && (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0)) {
+                    musicOneSubjectClassPlan.setPaidZeroNum(paidZeroNum + 1);
+                    musicOneSubjectClassPlan.setPaidStudentNum(paidNum + 1);
+                }
+            } else {
+                if (oldStudentPaymentOrderList == null || oldStudentPaymentOrderList.size() == 0) {
+                    musicOneSubjectClassPlan.setPaidStudentNum(paidNum + 1);
+                }
+            }
+            if (musicOneSubjectClassPlan.getPaidStudentNum() > musicOneSubjectClassPlan.getExpectedStudentNum()) {
+                throw new BizException("乐团该声部人数暂时已满,请稍后再试");
+            }
+
+            int count = musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
+            if (count <= 0) {
+                throw new BizException("排队人数过多,请重试");
+            }
+        }
         if (paidZeroFlag) {
             studentPaymentOrder.setVersion(0);
             String code = studentRegistration.getNoneNeedCloudTeacher().equals(1) ? "200" : "205";
@@ -707,6 +723,53 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         return studentPaymentOrder;
     }
 
+    /**
+     * 计算使用优惠券后的每个明细均摊的金额
+     *
+     * @param couponParam          优惠券的信息
+     * @param orderDetailGroupList 订单信息
+     */
+    private void calculateCoupon(Map<String, CouponPayTypeInfo> couponParam,
+                                 Map<OrderDetailTypeEnum, List<StudentPaymentOrderDetail>> orderDetailGroupList) {
+        List<StudentPaymentOrderDetail> singleTypeList = new ArrayList<>();
+        List<StudentPaymentOrderDetail> allTypeList = new ArrayList<>();
+        //先处理”非全类型券“的数据
+        orderDetailGroupList.forEach((e, list) -> {
+            //根据OrderDetailTypeEnum类型找到对应的券类型,默认全类型
+            String couponDetailCode = CouponDetailTypeEnum.of(e.getCode());
+            //获取本次支付中该类型优惠券的详情,如果该商品没有找到本次支付时选择的优惠券则当作全类型
+            CouponPayTypeInfo couponPayTypeInfo = couponParam.get(couponDetailCode);
+            //全类型券数据后面处理
+            if (Objects.isNull(couponPayTypeInfo) || couponDetailCode.equals(CouponDetailTypeEnum.FULLCOUPON.getCode())) {
+                allTypeList.addAll(list);
+                return;
+            }
+            analyzeAmount(couponPayTypeInfo, singleTypeList, list);
+        });
+        List<StudentPaymentOrderDetail> allList = new ArrayList<>();
+        //再处理全类型优惠券数据
+        if (CollectionUtils.isNotEmpty(allTypeList)) {
+            allTypeList.addAll(singleTypeList);
+            analyzeAmount(couponParam.get(CouponDetailTypeEnum.FULLCOUPON.getCode()), allList, allTypeList);
+        }
+    }
+
+    /**
+     * 计算分配优惠券金额
+     */
+    private void analyzeAmount(CouponPayTypeInfo couponPayTypeInfo, List<StudentPaymentOrderDetail> resultList,
+                               List<StudentPaymentOrderDetail> list) {
+        //获取该优惠券对应的商品的总金额
+        BigDecimal totalAmount = WrapperUtil.sumList(list, StudentPaymentOrderDetail::getPrice);
+        //校验本次优惠券的 ”满额“ 是否大于 该类型的总金额
+        if (couponPayTypeInfo.getCouponAmount().compareTo(totalAmount) <= 0) {
+            List<StudentPaymentOrderDetail> details = studentPaymentOrderDetailService.allocateAmount(list, couponPayTypeInfo.getFaceValue());
+            resultList.addAll(details);
+        } else {
+            throw new BizException("交易失败,请重新选择优惠券!");
+        }
+    }
+
     @Override
     @Transactional(rollbackFor = Exception.class)
     public StudentRegistration queryByUserIdAndMusicGroupId(Integer userId, String musicGroupId) {
@@ -775,10 +838,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             sysUser.setImToken(register.getToken());
             teacherDao.updateUser(sysUser);
         } else {
-            if(musicGroup.getCourseViewType() == CourseViewTypeEnum.MEMBER_FEE){
+            if (musicGroup.getCourseViewType() == CourseViewTypeEnum.MEMBER_FEE) {
                 //该学员是否在其他的会员团
-                boolean hasMemberGroup = studentRegistrationDao.checkHasMemberGroup(musicGroupId,sysUser.getId());
-                if(hasMemberGroup){
+                boolean hasMemberGroup = studentRegistrationDao.checkHasMemberGroup(musicGroupId, sysUser.getId());
+                if (hasMemberGroup) {
                     throw new BizException("操作失败:该学员已在其他系统收费乐团中,不可报名该乐团请联系教务老师");
                 }
             }
@@ -826,7 +889,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         studentRegistration.setMusicGroupStatus(StudentMusicGroupStatusEnum.APPLY);
         studentRegistration.setTemporaryCourseFee(studentAddDto.getTemporaryCourseFee());
         studentRegistration.setMusicGroupPaymentCalenderId(null);
-        
+
         //增加报名学生数
         musicGroupSubjectPlanService.addApplyStudentNum(musicGroupId, studentRegistration.getSubjectId(), 1);
         //汇总金额
@@ -853,10 +916,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         studentDao.update(student);
         //studentRegistrationDao.updateCurrentClass(studentRegistration);
         imFeignService.update(new ImUserModel(userId.toString(), sysUser.getUsername(), sysUser.getAvatar()));
-        
+
         //学生报名表
-        sendSeoMessageSource.sendSeoMessage(musicGroup.getOrganId(),new SysUserRoleEnum[]{SECTION_MANAGER},
-                null,musicGroup.getEducationalTeacherId(),MessageTypeEnum.BACKSTAGE_MUSIC_GROUP_ADD_STUDENT, musicGroup.getName(), studentRegistration.getName());
+        sendSeoMessageSource.sendSeoMessage(musicGroup.getOrganId(), new SysUserRoleEnum[]{SECTION_MANAGER},
+                null, musicGroup.getEducationalTeacherId(), MessageTypeEnum.BACKSTAGE_MUSIC_GROUP_ADD_STUDENT, musicGroup.getName(), studentRegistration.getName());
         return userId;
     }
 
@@ -1056,7 +1119,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         if (studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)) {
             MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
             //支付成功后处理课程、云教练、活动等数据
-            studentPaymentOrderDetailService.addOrderDetailTo(studentPaymentOrder,musicGroup,studentRegistration);
+            studentPaymentOrderDetailService.addOrderDetailTo(studentPaymentOrder, musicGroup, studentRegistration);
 
             //插入交易明细
             BigDecimal amount = studentPaymentOrder.getActualAmount();
@@ -1169,7 +1232,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
         return studentPaymentOrder;
     }
 
-
     @Override
     public List<StudentRegistration> findMusicGroupNoClassGroupStudent(String musicGroupId, Integer actualSubjectId) {
         //获取所有声部
@@ -1417,19 +1479,19 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             if (originalPaidNum > 0) {
                 originalSubjectPlan.setPaidStudentNum(originalPaidNum - 1);
                 //是否是0元入团
-                if(studentRegistration.getNoneNeedCloudTeacher() != null && studentRegistration.getNoneNeedCloudTeacher() == 1){
-                	originalSubjectPlan.setPaidZeroNum(originalZeroPaidNum - 1);
+                if (studentRegistration.getNoneNeedCloudTeacher() != null && studentRegistration.getNoneNeedCloudTeacher() == 1) {
+                    originalSubjectPlan.setPaidZeroNum(originalZeroPaidNum - 1);
                 }
                 originalPaidCount = musicGroupSubjectPlanService.update(originalSubjectPlan);
             }
             MusicGroupSubjectPlan changeSubjectPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(musicGroupId, changeSubjectId);
             int changelPaidNum = changeSubjectPlan.getPaidStudentNum() == null ? 0 : changeSubjectPlan.getPaidStudentNum();
             changeSubjectPlan.setPaidStudentNum(changelPaidNum + 1);
-            if(studentRegistration.getNoneNeedCloudTeacher() != null && studentRegistration.getNoneNeedCloudTeacher() == 1){
-            	if(changeSubjectPlan.getPaidZeroNum() != null && changeSubjectPlan.getPaidZeroNum() > 0){
-            		throw new BizException("声部更换失败,当前用户是0元入团,且当前声部已有0元入团学生");
-            	}
-            	changeSubjectPlan.setPaidZeroNum(1);
+            if (studentRegistration.getNoneNeedCloudTeacher() != null && studentRegistration.getNoneNeedCloudTeacher() == 1) {
+                if (changeSubjectPlan.getPaidZeroNum() != null && changeSubjectPlan.getPaidZeroNum() > 0) {
+                    throw new BizException("声部更换失败,当前用户是0元入团,且当前声部已有0元入团学生");
+                }
+                changeSubjectPlan.setPaidZeroNum(1);
             }
             int changePaidCount = musicGroupSubjectPlanService.update(changeSubjectPlan);
             if (originalPaidCount > 0 && changePaidCount > 0) {
@@ -1481,8 +1543,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    public List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId,String musicGroupId) {
-        return studentRegistrationDao.queryStudentMusicGroupInfo(userId,musicGroupId);
+    public List<StudentMusicGroupDto> queryStudentMusicGroupInfo(Integer userId, String musicGroupId) {
+        return studentRegistrationDao.queryStudentMusicGroupInfo(userId, musicGroupId);
     }
 
     @Override
@@ -1716,28 +1778,28 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             throw new BizException("该学生已设置");
         }
         MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
-        if(musicGroup == null){
+        if (musicGroup == null) {
             throw new BizException("乐团信息不存在");
         }
-        if(musicGroup.getTenantId() == null){
+        if (musicGroup.getTenantId() == null) {
             throw new BizException("乐团机构信息异常,请联系管理员");
         }
 
         MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
         int paidNum = musicOneSubjectClassPlan.getPaidStudentNum() == null ? 0 : musicOneSubjectClassPlan.getPaidStudentNum();
         int paidZeroNum = musicOneSubjectClassPlan.getPaidZeroNum() == null ? 0 : musicOneSubjectClassPlan.getPaidZeroNum();
-        String configValue = sysTenantConfigService.getTenantConfigValue(SysConfigService.MEMBER_GROUP_FEE_STUDENT_NUM,musicGroup.getTenantId());
-        if(StringUtils.isNotEmpty(configValue)){
-            if(paidZeroNum >= Integer.parseInt(configValue)){
-                throw new BizException("每个声部只能有{}个免费入团名额",configValue);
+        String configValue = sysTenantConfigService.getTenantConfigValue(SysConfigService.MEMBER_GROUP_FEE_STUDENT_NUM, musicGroup.getTenantId());
+        if (StringUtils.isNotEmpty(configValue)) {
+            if (paidZeroNum >= Integer.parseInt(configValue)) {
+                throw new BizException("每个声部只能有{}个免费入团名额", configValue);
             }
         }
-        if(!isContinue){
-        	if (musicOneSubjectClassPlan.getPaidStudentNum() >= musicOneSubjectClassPlan.getExpectedStudentNum()) {
+        if (!isContinue) {
+            if (musicOneSubjectClassPlan.getPaidStudentNum() >= musicOneSubjectClassPlan.getExpectedStudentNum()) {
                 return new HttpResponseResult<Boolean>(true, HttpStatus.CONTINUE, null, "乐团该声部招生人数已满,是否继续操作?");
             }
         }
-        
+
         studentRegistration.setPayingStatus(0);
         studentRegistration.setNoneNeedCloudTeacher(1);
         studentRegistration.setPaymentStatus(YES);
@@ -1750,25 +1812,25 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 				throw new BizException("订单处理失败,请重试");
 			}
 		}*/
-        
-		List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.ING, OrderTypeEnum.APPLY);
-		
-		List<StudentPaymentOrder> updateList = new ArrayList<StudentPaymentOrder>();
-		
-		if(studentPaymentOrderList != null && studentPaymentOrderList.size() > 0){
-			for(StudentPaymentOrder studentPaymentOrder : studentPaymentOrderList){
-				if(StringUtils.equals("205", studentPaymentOrder.getPaymentAccountNo())){
-					studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
-					studentPaymentOrder.setMemo("用户未支付");
-					updateList.add(studentPaymentOrder);
-				}
-			}
-		}
-		
-		if(updateList.size() > 0){
-			studentPaymentOrderService.batchUpdate(updateList);
-		}
-        
+
+        List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.ING, OrderTypeEnum.APPLY);
+
+        List<StudentPaymentOrder> updateList = new ArrayList<StudentPaymentOrder>();
+
+        if (studentPaymentOrderList != null && studentPaymentOrderList.size() > 0) {
+            for (StudentPaymentOrder studentPaymentOrder : studentPaymentOrderList) {
+                if (StringUtils.equals("205", studentPaymentOrder.getPaymentAccountNo())) {
+                    studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
+                    studentPaymentOrder.setMemo("用户未支付");
+                    updateList.add(studentPaymentOrder);
+                }
+            }
+        }
+
+        if (updateList.size() > 0) {
+            studentPaymentOrderService.batchUpdate(updateList);
+        }
+
         musicOneSubjectClassPlan.setPaidZeroNum(paidZeroNum + 1);
         musicOneSubjectClassPlan.setPaidStudentNum(paidNum + 1);
         int count = musicGroupSubjectPlanService.update(musicOneSubjectClassPlan);
@@ -1780,43 +1842,43 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
     @Override
     public StudentRegistration getStudentRegister(String musicGroupId, Integer studentId) {
-        return studentRegistrationDao.getStudentRegister(musicGroupId,studentId);
+        return studentRegistrationDao.getStudentRegister(musicGroupId, studentId);
     }
 
-	@Override
+    @Override
     @Transactional(rollbackFor = Exception.class)
-	public Boolean setCloudTeacherToFailed(StudentRegistration studentRegistration) {
-        
-        if(studentRegistration.getPayingStatus() != 2){
-        	throw new BizException("只有'审核中'的记录才能取消审核");
-        }
-		
-		Date date = new Date();
-		
-		studentRegistration.setPayingStatus(0);
-		studentRegistration.setUpdateTime(date);
-		update(studentRegistration);
-		
-		List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.ING, OrderTypeEnum.APPLY);
-		
-		List<StudentPaymentOrder> updateList = new ArrayList<StudentPaymentOrder>();
-		
-		if(studentPaymentOrderList != null && studentPaymentOrderList.size() > 0){
-			for(StudentPaymentOrder studentPaymentOrder : studentPaymentOrderList){
-				if(StringUtils.equals("205", studentPaymentOrder.getPaymentAccountNo())){
-					studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
-					studentPaymentOrder.setMemo("云教练审核拒绝");
-					updateList.add(studentPaymentOrder);
-				}
-			}
-		}
-		
-		if(updateList.size() > 0){
-			studentPaymentOrderService.batchUpdate(updateList);
-		}
-		
-		return true;
-	}
+    public Boolean setCloudTeacherToFailed(StudentRegistration studentRegistration) {
+
+        if (studentRegistration.getPayingStatus() != 2) {
+            throw new BizException("只有'审核中'的记录才能取消审核");
+        }
+
+        Date date = new Date();
+
+        studentRegistration.setPayingStatus(0);
+        studentRegistration.setUpdateTime(date);
+        update(studentRegistration);
+
+        List<StudentPaymentOrder> studentPaymentOrderList = studentPaymentOrderService.queryByCondition(GroupType.MUSIC, studentRegistration.getMusicGroupId(), studentRegistration.getUserId(), DealStatusEnum.ING, OrderTypeEnum.APPLY);
+
+        List<StudentPaymentOrder> updateList = new ArrayList<StudentPaymentOrder>();
+
+        if (studentPaymentOrderList != null && studentPaymentOrderList.size() > 0) {
+            for (StudentPaymentOrder studentPaymentOrder : studentPaymentOrderList) {
+                if (StringUtils.equals("205", studentPaymentOrder.getPaymentAccountNo())) {
+                    studentPaymentOrder.setStatus(DealStatusEnum.CLOSE);
+                    studentPaymentOrder.setMemo("云教练审核拒绝");
+                    updateList.add(studentPaymentOrder);
+                }
+            }
+        }
+
+        if (updateList.size() > 0) {
+            studentPaymentOrderService.batchUpdate(updateList);
+        }
+
+        return true;
+    }
 
     @Override
     public PageInfo<StudentInstrument> queryMusicStudentInstrument(StudentPreRegistrationQueryInfo queryInfo) {
@@ -1839,22 +1901,22 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-	public PageInfo<StudentRegisterInstrumentsDetailDto> queryStudentRegisterInstrumentsDetailList(MusicGroupRecordStudentQueryInfo queryInfo) {
-		PageInfo<StudentRegisterInstrumentsDetailDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
-		Map<String, Object> params = new HashMap<>();
-		MapUtil.populateMap(params, queryInfo);
-
-		List<StudentRegisterInstrumentsDetailDto> dataList = null;
-		int count = studentRegistrationDao.queryStudentRegisterInstrumentsDetailCount(params);
-		if (count > 0) {
-			pageInfo.setTotal(count);
-			params.put("offset", pageInfo.getOffset());
-			dataList = studentRegistrationDao.queryStudentRegisterInstrumentsDetailList(params);
-		}
-		if (count == 0) {
-			dataList = new ArrayList<>();
-		}
-		pageInfo.setRows(dataList);
-		return pageInfo;
-	}
+    public PageInfo<StudentRegisterInstrumentsDetailDto> queryStudentRegisterInstrumentsDetailList(MusicGroupRecordStudentQueryInfo queryInfo) {
+        PageInfo<StudentRegisterInstrumentsDetailDto> pageInfo = new PageInfo<>(queryInfo.getPage(), queryInfo.getRows());
+        Map<String, Object> params = new HashMap<>();
+        MapUtil.populateMap(params, queryInfo);
+
+        List<StudentRegisterInstrumentsDetailDto> dataList = null;
+        int count = studentRegistrationDao.queryStudentRegisterInstrumentsDetailCount(params);
+        if (count > 0) {
+            pageInfo.setTotal(count);
+            params.put("offset", pageInfo.getOffset());
+            dataList = studentRegistrationDao.queryStudentRegisterInstrumentsDetailList(params);
+        }
+        if (count == 0) {
+            dataList = new ArrayList<>();
+        }
+        pageInfo.setRows(dataList);
+        return pageInfo;
+    }
 }

+ 36 - 22
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponCodeServiceImpl.java

@@ -22,6 +22,7 @@ import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -209,34 +210,16 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
     }
 
     @Override
-    public List<SysCouponCode> queryCouponPage(BigDecimal amount, Integer userId) {
-
-        return null;
-    }
-
-    @Override
     @Transactional(rollbackFor = Exception.class)
     public StudentPaymentOrder use(List<Integer> couponIdList, BigDecimal amount, Boolean useFlag) {
         StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
-        if (couponIdList != null && couponIdList.size() > 0) {
-            Date date = new Date();
-            List<SysCouponCodeDto> couponCodeDtoList = sysCouponCodeDao.findByIdList(couponIdList);
-            if (couponIdList.size() != couponCodeDtoList.size()) {
-                throw new BizException("操作失败:优惠券数据异常");
-            }
+        if (CollectionUtils.isNotEmpty(couponIdList)) {
             BigDecimal fullAmount = BigDecimal.ZERO;
             BigDecimal faceAmount = BigDecimal.ZERO;
+            //校验优惠券
+            List<SysCouponCodeDto> couponCodeDtoList = checkCoupon(couponIdList);
 
             for (SysCouponCodeDto sysCouponCodeDto : couponCodeDtoList) {
-                if (sysCouponCodeDto.getUsageStatus() == 1) {
-                    throw new BizException("操作失败:优惠券已使用");
-                }
-                if (sysCouponCodeDto.getUseStartDate().after(date)) {
-                    throw new BizException("操作失败:不在优惠券使用期限");
-                }
-                if (date.after(sysCouponCodeDto.getUseDeadlineDate())) {
-                    throw new BizException("操作失败:优惠券已过期");
-                }
                 CouponTypeEnum couponType = sysCouponCodeDto.getCouponType();
                 switch (couponType) {
                     case DISCOUNT:
@@ -249,6 +232,7 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
                         throw new BizException("操作失败:错误的优惠券类型");
                 }
             }
+
             if (amount.compareTo(fullAmount) < 0) {
                 throw new BizException("操作失败:当前消费金额不满足优惠券满减条件");
             }
@@ -258,7 +242,7 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
             }
             //使用优惠券
             if (useFlag) {
-                sysCouponCodeDao.use(couponIdList);
+                useCoupon(couponIdList);
             }
             studentPaymentOrder.setCouponCodeId(StringUtils.join(couponIdList, ","));
             studentPaymentOrder.setCouponRemitFee(faceAmount);
@@ -269,11 +253,41 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
     }
 
     @Override
+    public List<SysCouponCodeDto> checkCoupon(List<Integer> couponIdList) {
+        Date date = new Date();
+        List<SysCouponCodeDto> couponCodeDtoList = findByIdList(couponIdList);
+        if (couponIdList.size() != couponCodeDtoList.size()) {
+            throw new BizException("操作失败:优惠券数据异常");
+        }
+
+        for (SysCouponCodeDto sysCouponCodeDto : couponCodeDtoList) {
+            if (sysCouponCodeDto.getUsageStatus() == 1) {
+                throw new BizException("操作失败:优惠券已使用");
+            }
+            if (sysCouponCodeDto.getUseStartDate().after(date)) {
+                throw new BizException("操作失败:不在优惠券使用期限");
+            }
+            if (date.after(sysCouponCodeDto.getUseDeadlineDate())) {
+                throw new BizException("操作失败:优惠券已过期");
+            }
+        }
+
+        return couponCodeDtoList;
+    }
+
+    @Override
     public List<SysCouponCodeDto> findByIdList(List<Integer> couponIdList) {
         return sysCouponCodeDao.findByIdList(couponIdList);
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void useCoupon(List<Integer> couponIdList) {
+        sysCouponCodeDao.use(couponIdList);
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
     public void quit(String couponCodeId) {
         if (StringUtils.isEmpty(couponCodeId)) {
             return;

+ 2 - 1
mec-biz/src/main/resources/config/mybatis/SysCouponCodeMapper.xml

@@ -260,7 +260,8 @@
 		scc.use_start_date_,
 		scc.use_deadline_date_,
 		scc.used_time_,
-		 scc.type_ as issueType,
+		scc.type_ as issueType,
+        sc.type_detail_ as typeDetail,
 		IF(scc.usage_status_ = 0 AND scc.use_deadline_date_ &lt; NOW(),2,scc.usage_status_) usage_status_
 		FROM sys_coupon_code scc
 		LEFT JOIN sys_coupon sc ON scc.coupon_id_=sc.id_

+ 34 - 8
mec-common/common-core/src/main/java/com/ym/mec/common/page/WrapperUtil.java

@@ -5,7 +5,9 @@ import com.ym.mec.common.exception.BizException;
 import org.apache.commons.collections.CollectionUtils;
 import org.apache.commons.lang3.StringUtils;
 
+import java.math.BigDecimal;
 import java.util.*;
+import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
@@ -15,13 +17,13 @@ import java.util.stream.Collectors;
  */
 public class WrapperUtil<T> {
 
-    private final QueryWrapper<T> queryWrapper;
+    public static final Predicate<? super Object> ObjPredicate = (Predicate<Object>) Objects::nonNull;
 
-    private final Predicate<? super Object> ObjPredicate = (Predicate<Object>) Objects::nonNull;
+    public static final Predicate<? super String> StrPredicate = (Predicate<String>) StringUtils::isNotBlank;
 
-    private final Predicate<? super String> StrPredicate = (Predicate<String>) StringUtils::isNotBlank;
+    public static final Predicate<? super Collection<?>> ListPredicate = (Predicate<Collection<?>>) CollectionUtils::isNotEmpty;
 
-    private final Predicate<? super Collection<?>> ListPredicate = (Predicate<Collection<?>>) CollectionUtils::isNotEmpty;
+    private final QueryWrapper<T> queryWrapper;
 
     public WrapperUtil() {
         this.queryWrapper = new QueryWrapper<>();
@@ -112,7 +114,7 @@ public class WrapperUtil<T> {
         return optional
                 .filter(s -> s instanceof String)
                 .map(String::valueOf)
-                .filter(StringUtils::isNotBlank);
+                .filter(StrPredicate);
     }
 
     public static List<String> toList(String key) {
@@ -136,14 +138,14 @@ public class WrapperUtil<T> {
 
     public static Optional<List<String>> toListOptional(String key, String symbol) {
         return Optional.ofNullable(key)
-                .filter(StringUtils::isNotBlank)
+                .filter(StrPredicate)
                 .map(b -> b.split(symbol))
                 .map(WrapperUtil::collectToList)
-                .filter(CollectionUtils::isNotEmpty);
+                .filter(ListPredicate);
     }
 
     public static List<String> collectToList(String[] b) {
-        return Arrays.stream(b).filter(StringUtils::isNotBlank).collect(Collectors.toList());
+        return Arrays.stream(b).filter(StrPredicate).collect(Collectors.toList());
     }
 
     /**
@@ -155,4 +157,28 @@ public class WrapperUtil<T> {
         return Arrays.stream(obj).noneMatch(Objects::isNull);
     }
 
+    /**
+     * 根据分组groupVal进行聚合分组
+     *
+     * @param list     待聚合的集合
+     * @param groupVal 分组value
+     */
+    public static <S, L> Map<S, List<L>> groupList(List<L> list, Function<? super L, ? extends S> groupVal) {
+        return list.stream()
+                .filter(ObjPredicate)
+                .collect(Collectors.groupingBy(groupVal));
+    }
+
+    /**
+     * 根据groupVal进行聚合累加
+     *
+     * @param list   待聚合的集合
+     * @param sumVal 需要聚合操作的字段
+     */
+    public static <L> BigDecimal sumList(List<L> list, Function<? super L, BigDecimal> sumVal) {
+        return list.stream()
+                .map(sumVal)
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+    }
+
 }

+ 34 - 34
mec-web/src/main/java/com/ym/mec/web/WebApplication.java

@@ -1,9 +1,9 @@
 package com.ym.mec.web;
 
-import javax.servlet.Filter;
-
 import com.huifu.adapay.model.MerConfig;
+import com.spring4all.swagger.EnableSwagger2Doc;
 import com.ym.mec.biz.service.NotifyCallback;
+import com.ym.mec.common.filters.EmojiEncodingFilter;
 import com.ym.mec.thirdparty.adapay.ConfigInit;
 import org.mybatis.spring.annotation.MapperScan;
 import org.springframework.boot.SpringApplication;
@@ -18,8 +18,7 @@ import org.springframework.context.annotation.Configuration;
 import org.springframework.scheduling.annotation.EnableAsync;
 import org.springframework.web.client.RestTemplate;
 
-import com.spring4all.swagger.EnableSwagger2Doc;
-import com.ym.mec.common.filters.EmojiEncodingFilter;
+import javax.servlet.Filter;
 
 @SpringBootApplication
 @EnableDiscoveryClient
@@ -31,37 +30,38 @@ import com.ym.mec.common.filters.EmojiEncodingFilter;
 @EnableAsync
 public class WebApplication {
 
-	public static void main(String[] args) {
-		SpringApplication.run(WebApplication.class, args);
-	}
+    public static void main(String[] args) {
+        SpringApplication.run(WebApplication.class, args);
+    }
 
-	@Bean
-	@LoadBalanced
-	public RestTemplate restTemplate() {
-		return new RestTemplate();
-	}
+    @Bean
+    @LoadBalanced
+    public RestTemplate restTemplate() {
+        return new RestTemplate();
+    }
 
-	/**
-	 * 注册filter
-	 * @return
-	 */
-	@Bean
-	public FilterRegistrationBean<Filter> filterRegistrationBean() {
-		FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<Filter>();
-		// 注入过滤器
-		registration.setFilter(new EmojiEncodingFilter());
-		// 过滤器名称
-		registration.setName("emojiEncodingFilter");
-		// 拦截规则
-		registration.addUrlPatterns("/*");
-		// 过滤器顺序(值越小,优先级越高)
-		registration.setOrder(1);
-		return registration;
-	}
+    /**
+     * 注册filter
+     *
+     * @return
+     */
+    @Bean
+    public FilterRegistrationBean<Filter> filterRegistrationBean() {
+        FilterRegistrationBean<Filter> registration = new FilterRegistrationBean<Filter>();
+        // 注入过滤器
+        registration.setFilter(new EmojiEncodingFilter());
+        // 过滤器名称
+        registration.setName("emojiEncodingFilter");
+        // 拦截规则
+        registration.addUrlPatterns("/*");
+        // 过滤器顺序(值越小,优先级越高)
+        registration.setOrder(1);
+        return registration;
+    }
 
-	@Bean
-	public static void startMqtt() {
-		MerConfig merConfig = ConfigInit.merConfig;
-		new NotifyCallback();
-	}
+    @Bean
+    public static void startMqtt() {
+        MerConfig merConfig = ConfigInit.merConfig;
+        new NotifyCallback();
+    }
 }

Some files were not shown because too many files changed in this diff