浏览代码

feat:12月活动

Joburgess 4 年之前
父节点
当前提交
bf35f60b41

+ 39 - 22
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -17,6 +17,7 @@ import com.ym.mec.common.constant.CommonConstants;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
+import com.ym.mec.common.redis.service.RedisCache;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.collection.MapUtil;
@@ -70,6 +71,8 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	private MusicGroupStudentClassAdjustDao musicGroupStudentClassAdjustDao;
 	@Autowired
 	private SysConfigDao sysConfigDao;
+	@Autowired
+	private RedisCache<String, Object> redisCache;
 
 	@Override
 	public BaseDAO<Long, CourseScheduleStudentPayment> getDAO() {
@@ -663,33 +666,47 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 	@Override
 	@Transactional(rollbackFor = Exception.class)
 	public void updateCourseActualPrice() {
-		List<CourseScheduleStudentPaymentDto> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findNeedUpdateActualPriceStudentCourses();
-		if(CollectionUtils.isEmpty(courseScheduleStudentPayments)){
+
+		String key = "updateCourseActualPrice";
+
+		if(redisCache.exists(key)){
 			return;
 		}
-		List<CourseScheduleStudentPayment> needUpdates = new ArrayList<>();
-		Map<CourseStatusEnum, List<CourseScheduleStudentPaymentDto>> statusCoursesMap = courseScheduleStudentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPaymentDto::getCourseStatus));
-		if(statusCoursesMap.containsKey(CourseStatusEnum.NOT_START)){
-			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.NOT_START);
-			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
-				studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getActualPrice(), StringUtils.join("课程状态变更到未开始,退还缴费:", notStartCourse.getCourseScheduleId()), null);
-				notStartCourse.setActualPrice(BigDecimal.ZERO);
-				needUpdates.add(notStartCourse);
+
+		redisCache.expire(key, 7200);
+
+		try {
+			List<CourseScheduleStudentPaymentDto> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findNeedUpdateActualPriceStudentCourses();
+			if(CollectionUtils.isEmpty(courseScheduleStudentPayments)){
+				redisCache.delete(key);
+				return;
+			}
+			List<CourseScheduleStudentPayment> needUpdates = new ArrayList<>();
+			Map<CourseStatusEnum, List<CourseScheduleStudentPaymentDto>> statusCoursesMap = courseScheduleStudentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPaymentDto::getCourseStatus));
+			if(statusCoursesMap.containsKey(CourseStatusEnum.NOT_START)){
+				List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.NOT_START);
+				for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+					studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), notStartCourse.getActualPrice(), StringUtils.join("课程状态变更到未开始,退还缴费:", notStartCourse.getCourseScheduleId()), null);
+					notStartCourse.setActualPrice(BigDecimal.ZERO);
+					needUpdates.add(notStartCourse);
+				}
 			}
-		}
 
-		if(statusCoursesMap.containsKey(CourseStatusEnum.OVER)){
-			List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.OVER);
-			notStartCourses.sort(Comparator.comparing(CourseScheduleStudentPaymentDto::getCourseStartTime));
-			for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
-				BigDecimal actualPrice = Objects.isNull(notStartCourse.getActualPrice())?BigDecimal.ZERO:notStartCourse.getActualPrice();
-				BigDecimal deductAmount = studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), (notStartCourse.getExpectPrice().subtract(actualPrice)).negate(), StringUtils.join("课程结束,扣除课程费用:", notStartCourse.getCourseScheduleId()), null);
-				notStartCourse.setActualPrice(actualPrice.add(deductAmount.abs()));
-				needUpdates.add(notStartCourse);
+			if(statusCoursesMap.containsKey(CourseStatusEnum.OVER)){
+				List<CourseScheduleStudentPaymentDto> notStartCourses = statusCoursesMap.get(CourseStatusEnum.OVER);
+				notStartCourses.sort(Comparator.comparing(CourseScheduleStudentPaymentDto::getCourseStartTime));
+				for (CourseScheduleStudentPaymentDto notStartCourse : notStartCourses) {
+					BigDecimal actualPrice = Objects.isNull(notStartCourse.getActualPrice())?BigDecimal.ZERO:notStartCourse.getActualPrice();
+					BigDecimal deductAmount = studentRegistrationService.updateUserSurplusCourseFee(notStartCourse.getUserId(), notStartCourse.getMusicGroupId(), (notStartCourse.getExpectPrice().subtract(actualPrice)).negate(), StringUtils.join("课程结束,扣除课程费用:", notStartCourse.getCourseScheduleId()), null);
+					notStartCourse.setActualPrice(actualPrice.add(deductAmount.abs()));
+					needUpdates.add(notStartCourse);
+				}
 			}
-		}
-		if(!CollectionUtils.isEmpty(needUpdates)){
-			courseScheduleStudentPaymentDao.batchUpdate(needUpdates);
+			if(!CollectionUtils.isEmpty(needUpdates)){
+				courseScheduleStudentPaymentDao.batchUpdate(needUpdates);
+			}
+		} finally {
+			redisCache.delete(key);
 		}
 	}
 }