|
@@ -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;
|
|
|
}
|