zouxuan 5 年之前
父節點
當前提交
23dc8fafe7

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

@@ -6,6 +6,7 @@ import com.ym.mec.biz.service.MusicGroupPaymentCalenderService;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 
+import com.ym.mec.util.date.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -14,6 +15,7 @@ import java.util.Calendar;
 import java.util.Collections;
 import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
 
 @Service
 public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long, MusicGroupPaymentCalender> implements MusicGroupPaymentCalenderService {
@@ -41,17 +43,30 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 	public Date getNextPaymentDate(String musicGroupId) {
 		List<MusicGroupPaymentCalender> musicGroupPaymentCalenderList = musicGroupPaymentCalenderDao.findByMusicGroupId(musicGroupId);
 		if (musicGroupPaymentCalenderList != null && musicGroupPaymentCalenderList.size() > 0) {
-
-			Collections.sort(musicGroupPaymentCalenderList);
-
-			Calendar cale = Calendar.getInstance();
-			int month = cale.get(Calendar.MONTH) + 1;
-
-			for (MusicGroupPaymentCalender cal : musicGroupPaymentCalenderList) {
-				if (cal.getPaymentMonth() >= month) {
-					return cal.getStartPaymentDate();
+			Date date = new Date();
+			List<Integer> months = musicGroupPaymentCalenderList.stream().map(e -> e.getPaymentMonth()).collect(Collectors.toList());
+			//获取当前月份
+			int currentMonth = Integer.parseInt(DateUtil.getMonth(date));
+			int nextMonth = currentMonth;
+			for (int i = 0;i < months.size();i++){
+				if(i == months.size()-1 && months.get(i) <= currentMonth){
+					nextMonth = months.get(0);
+					break;
+				}else if(months.get(i) > currentMonth){
+					nextMonth = months.get(i);
+					break;
 				}
 			}
+			// 修改学员付费周期
+			Date nextPaymentDate = null;
+			if(nextMonth > currentMonth){
+				nextPaymentDate = DateUtil.addMonths(date, nextMonth - currentMonth);
+			}else if(nextMonth < currentMonth) {
+				nextPaymentDate = DateUtil.addMonths(date, 12 - currentMonth + nextMonth);
+			}else {
+				nextPaymentDate = DateUtil.addMonths(date, 12);
+			}
+			return nextPaymentDate;
 		}
 		return null;
 	}

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

@@ -101,8 +101,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private SysMessageService sysMessageService;
     @Autowired
-    private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
-    @Autowired
     private MusicGroupSubjectPlanDao musicGroupSubjectPlanDao;
     @Autowired
     private SubjectDao subjectDao;
@@ -585,9 +583,10 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
                     MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanDao.getMusicOneSubjectClassPlan(musicGroupId, studentRegistration.getActualSubjectId());
                     studentAddDto.setCourseFee(musicOneSubjectClassPlan.getFee());
                 }
+                Date nextPaymentDate = musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId);
                 musicGroupStudentFeeDao.insert(new MusicGroupStudentFee(musicGroupId,
                         userId, studentRegistration.getSubjectId(), studentAddDto.getCourseFee(),
-                        musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId), studentAddDto.getTemporaryCourseFee()));
+                        nextPaymentDate, studentAddDto.getTemporaryCourseFee()));
                 //生成订单
                 StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
                 studentPaymentOrder.setUserId(userId);

+ 1 - 0
mec-biz/src/main/resources/config/mybatis/StudentPaymentOrderMapper.xml

@@ -240,6 +240,7 @@
     <select id="findMusicGroupApplyOrderByStatus" resultMap="StudentPaymentOrder">
         SELECT * FROM student_payment_order WHERE music_group_id_= #{musicGroupId} AND user_id_=#{userId} AND type_ =
         'APPLY' AND status_ = #{status,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler}
+         ORDER BY id_ DESC LIMIT 1
     </select>
 
     <!-- 根据订单号查询订单 -->