Browse Source

Merge branch 'master' of http://git.dayaedu.com/yonge/mec

# Conflicts:
#	mec-biz/src/main/java/com/ym/mec/biz/dal/dao/MusicGroupPaymentCalenderDao.java
#	mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderMapper.xml
yonge 5 years ago
parent
commit
af20dfe7a6

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

@@ -44,6 +44,13 @@ public interface MusicGroupPaymentCalenderDao extends BaseDAO<Long, MusicGroupPa
 	 * @return
 	 */
 	List<MusicGroupPaymentCalender> queryByPaymentStatus(List<PaymentStatusEnum> status);
+	
+	/**
+	 * 获取缴费信息锁
+	 * @param id
+	 * @return
+	 */
+	MusicGroupPaymentCalender getForLock(@Param("id") Long id);
 
 	/**
 	 * 根据指定乐团的缴费日期查询交集

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

@@ -52,4 +52,13 @@ public interface MusicGroupPaymentCalenderDetailDao extends BaseDAO<Long, MusicG
 	 * @return
 	 */
 	BigDecimal sumActualAmount(@Param("id") Long id);
+
+	/**
+	 * 获取学生最后一期续费记录
+	 * @param musicGroupId
+	 * @param userId
+	 * @return
+	 */
+	MusicGroupPaymentCalenderDetail getUserLastCalenderDetail(@Param("musicGroupId") String musicGroupId, @Param("userId") Integer userId);
+
 }

+ 8 - 8
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderDetail.java

@@ -51,6 +51,10 @@ public class MusicGroupPaymentCalenderDetail {
 	/**  */
 	private java.util.Date createTime;
 
+	private SysUser sysUser = new SysUser();
+
+	private StudentRegistration studentRegistration = new StudentRegistration();
+
 	public Date getStartPaymentDate() {
 		return startPaymentDate;
 	}
@@ -75,16 +79,12 @@ public class MusicGroupPaymentCalenderDetail {
 		this.open = open;
 	}
 
-	private SysUser sysUser = new SysUser();
-
-	private Student student = new Student();
-
-	public Student getStudent() {
-		return student;
+	public StudentRegistration getStudentRegistration() {
+		return studentRegistration;
 	}
 
-	public void setStudent(Student student) {
-		this.student = student;
+	public void setStudentRegistration(StudentRegistration studentRegistration) {
+		this.studentRegistration = studentRegistration;
 	}
 
 	public SysUser getSysUser() {

+ 23 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -148,6 +148,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     private GoodsService goodsService;
     @Autowired
     private ClassGroupStudentMapperService classGroupStudentMapperService;
+    @Autowired
+    private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
 
     @Autowired
     private ImFeignService imFeignService;
@@ -1658,8 +1660,10 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public boolean renewForCallback(StudentPaymentOrder studentPaymentOrder) throws IOException {
 
-        studentPaymentOrderService.update(studentPaymentOrder);
-
+        int updateNum = studentPaymentOrderService.update(studentPaymentOrder);
+        if(updateNum <= 0){
+            throw new BizException("订单更新失败");
+        }
         Integer userId = studentPaymentOrder.getUserId();
         String musicGroupId = studentPaymentOrder.getMusicGroupId();
 
@@ -1683,6 +1687,23 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 //            musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId, musicGroupStudentFee.getNextPaymentDate(), musicGroupStudentFee));
             musicGroupStudentFeeDao.update(musicGroupStudentFee);
 
+            MusicGroupPaymentCalenderDetail userLastCalenderDetail = musicGroupPaymentCalenderDetailDao.getUserLastCalenderDetail(musicGroupId, userId);
+            if(userLastCalenderDetail == null){
+                throw new BizException("学生没有续费中的记录");
+            }
+            //更新学生的缴费记录状态
+            userLastCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+            userLastCalenderDetail.setActualAmount(userLastCalenderDetail.getExpectAmount());
+            userLastCalenderDetail.setPayTime(date);
+            userLastCalenderDetail.setUpdateTime(date);
+            musicGroupPaymentCalenderDetailDao.update(userLastCalenderDetail);
+
+            //更新实际缴费人数
+            MusicGroupPaymentCalender musicGroupPaymentCalender = musicGroupPaymentCalenderDao.getForLock(userLastCalenderDetail.getMusicGroupPaymentCalenderId());
+            musicGroupPaymentCalender.setActualNum(musicGroupPaymentCalender.getActualNum()+1);
+            musicGroupPaymentCalender.setUpdateTime(date);
+            musicGroupPaymentCalenderDao.update(musicGroupPaymentCalender);
+
             //插入交易明细
             SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
             BigDecimal amount = studentPaymentOrder.getActualAmount();

+ 15 - 8
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderDetailMapper.xml

@@ -21,8 +21,8 @@
 		<association property="sysUser" javaType="com.ym.mec.auth.api.entity.SysUser">
 			<result column="username_" property="username" />
 		</association>
-		<association property="student" javaType="com.ym.mec.biz.dal.entity.Student">
-			<result column="subject_names_" property="subjectNames" />
+		<association property="studentRegistration" javaType="com.ym.mec.biz.dal.entity.StudentRegistration">
+			<result column="subject_names_" property="subjectName" />
 		</association>
 	</resultMap>
 
@@ -147,8 +147,8 @@
 		SELECT mgpc.*,su.username_,st.name_ subject_names_
 		FROM music_group_payment_calender_detail mgpc
 		LEFT JOIN sys_user su ON su.id_ = mgpc.user_id_
-		LEFT JOIN student s ON s.user_id_ = mgpc.user_id_
-		LEFT JOIN `subject` st ON FIND_IN_SET(st.id_,s.subject_id_list_)
+		LEFT JOIN student_registration sr ON sr.user_id_ = mgpc.user_id_
+		LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
 		<where>
 			<if test="userId != null">
 				AND mgpc.user_id_ = #{userId}
@@ -160,7 +160,7 @@
 				AND mgpc.payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
 			</if>
 			<if test="subjectId != null">
-				AND FIND_IN_SET(#{subjectId},s.subject_id_list_)
+				AND #{subjectId} = sr.actual_subject_id_
 			</if>
 		</where>
 		ORDER BY mgpc.create_time_
@@ -170,8 +170,8 @@
 	<!-- 查询当前表的总记录数 -->
 	<select id="queryCount" resultType="int">
 		SELECT COUNT(mgpc.id_) FROM music_group_payment_calender_detail mgpc
-		LEFT JOIN student s ON s.user_id_ = mgpc.user_id_
-		LEFT JOIN `subject` st ON FIND_IN_SET(st.id_,s.subject_id_list_)
+		LEFT JOIN student_registration sr ON sr.user_id_ = mgpc.user_id_
+		LEFT JOIN `subject` st ON st.id_ = sr.actual_subject_id_
 		<where>
 			<if test="userId != null">
 				AND mgpc.user_id_ = #{userId}
@@ -180,7 +180,7 @@
 				AND mgpc.music_group_payment_calender_id_ = #{id}
 			</if>
 			<if test="subjectId != null">
-				AND FIND_IN_SET(#{subjectId},s.subject_id_list_)
+				AND #{subjectId} = sr.actual_subject_id_
 			</if>
 			<if test="paymentStatus != null">
 				AND mgpc.payment_status_ = #{paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
@@ -211,4 +211,11 @@
 		SELECT SUM(mgpcd.actual_amount_) FROM music_group_payment_calender_detail mgpcd
 		WHERE mgpcd.music_group_payment_calender_id_ = #{id} AND mgpcd.payment_status_ = "PAID_COMPLETED"
 	</select>
+
+	<select id="getUserLastCalenderDetail" resultMap="MusicGroupPaymentCalenderDetail">
+		SELECT * FROM music_group_payment_calender_detail mgpcd
+		LEFT JOIN music_group_payment_calender mgpc ON mgpcd.music_group_payment_calender_id_ = mgpc.id_
+		WHERE mgpc.music_group_id_=#{musicGroupId} AND mgpcd.user_id_=#{userId} AND mgpcd.payment_status_ = 'PROCESSING'
+		ORDER BY mgpc.start_payment_date_ DESC
+	</select>
 </mapper>

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

@@ -165,6 +165,10 @@
         	</if>
         </where>
     </select>
+
+    <select id="getForLock" resultMap="MusicGroupPaymentCalender">
+        SELECT * FROM music_group_payment_calender WHERE id_ = #{id} FOR UPDATE
+    </select>
 	
     <select id="queryIntersectionByPaymentDate" resultType="int" parameterType="map">
         SELECT count(*) FROM music_group_payment_calender mgpc