|
@@ -1,23 +1,16 @@
|
|
package com.ym.mec.biz.event.listener;
|
|
package com.ym.mec.biz.event.listener;
|
|
|
|
|
|
-import com.ym.mec.biz.dal.dao.CourseScheduleStudentPaymentDao;
|
|
|
|
-import com.ym.mec.biz.dal.entity.CourseScheduleStudentPayment;
|
|
|
|
import com.ym.mec.biz.event.CourseStatusChangeEvent;
|
|
import com.ym.mec.biz.event.CourseStatusChangeEvent;
|
|
import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
|
|
import com.ym.mec.biz.service.CourseScheduleStudentPaymentService;
|
|
-import com.ym.mec.biz.service.StudentServeService;
|
|
|
|
-import com.ym.mec.common.redis.service.RedisCache;
|
|
|
|
-import org.slf4j.Logger;
|
|
|
|
-import org.slf4j.LoggerFactory;
|
|
|
|
|
|
+import org.apache.commons.collections.CollectionUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.context.event.EventListener;
|
|
import org.springframework.context.event.EventListener;
|
|
-import org.springframework.scheduling.annotation.Async;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
-import java.util.concurrent.TimeUnit;
|
|
|
|
-import java.util.stream.Collectors;
|
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
|
+import java.util.concurrent.Executors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Author qnc99
|
|
* @Author qnc99
|
|
@@ -26,64 +19,22 @@ import java.util.stream.Collectors;
|
|
@Component
|
|
@Component
|
|
public class CourseEventListener {
|
|
public class CourseEventListener {
|
|
|
|
|
|
- private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
-
|
|
|
|
- private final static String KEY = "updateCourseActualPrice";
|
|
|
|
-
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
|
|
private CourseScheduleStudentPaymentService courseScheduleStudentPaymentService;
|
|
- @Autowired
|
|
|
|
- private RedisCache<String, Object> redisCache;
|
|
|
|
- @Autowired
|
|
|
|
- private CourseScheduleStudentPaymentDao courseScheduleStudentPaymentDao;
|
|
|
|
- @Autowired
|
|
|
|
- private StudentServeService studentServeService;
|
|
|
|
|
|
|
|
- @Async
|
|
|
|
@EventListener
|
|
@EventListener
|
|
public void courseStatusChangeMonitor(CourseStatusChangeEvent courseStatusChangeEvent){
|
|
public void courseStatusChangeMonitor(CourseStatusChangeEvent courseStatusChangeEvent){
|
|
-// if(redisCache.getRedisTemplate().opsForValue().size(KEY)>0){
|
|
|
|
-// logger.info("课程状态变更(未执行,任务执行中):{}", courseStatusChangeEvent.getCourseIds());
|
|
|
|
-// return;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// Boolean success = redisCache.getRedisTemplate().opsForValue().setIfAbsent(KEY, Thread.currentThread().getId(), 1, TimeUnit.HOURS);
|
|
|
|
-// if(!success){
|
|
|
|
-// logger.info("课程状态变更(未执行,任务执行中):{}", courseStatusChangeEvent.getCourseIds());
|
|
|
|
-// return;
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// logger.info("课程状态变更(执行开始):{}", courseStatusChangeEvent.getCourseIds());
|
|
|
|
-
|
|
|
|
- try{
|
|
|
|
- courseScheduleStudentPaymentService.updateCourseActualPrice(null, null, null);
|
|
|
|
- } finally {
|
|
|
|
- redisCache.delete(KEY);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- @Async
|
|
|
|
- @EventListener
|
|
|
|
- public void courseStatusChangeMonitor2(CourseStatusChangeEvent courseStatusChangeEvent){
|
|
|
|
- if(redisCache.getRedisTemplate().opsForValue().size("exercisesSituationStatistics2")>0){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- Boolean success = redisCache.getRedisTemplate().opsForValue().setIfAbsent("exercisesSituationStatistics2", Thread.currentThread().getId(), 1, TimeUnit.HOURS);
|
|
|
|
- if(!success){
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- try{
|
|
|
|
-// List<CourseScheduleStudentPayment> cssps = courseScheduleStudentPaymentDao.findByCourseScheduleIds(new ArrayList<>(courseStatusChangeEvent.getCourseIds()));
|
|
|
|
-// if(CollectionUtils.isEmpty(cssps)){
|
|
|
|
-// return;
|
|
|
|
-// }
|
|
|
|
-// List<Integer> studentIds = cssps.stream().map(CourseScheduleStudentPayment::getUserId).collect(Collectors.toList());
|
|
|
|
-// studentServeService.exercisesSituationStatistics2(null,studentIds);
|
|
|
|
- } finally {
|
|
|
|
- redisCache.delete("exercisesSituationStatistics2");
|
|
|
|
|
|
+ List<Long> courseIds = courseStatusChangeEvent.getCourseIds();
|
|
|
|
+ if(CollectionUtils.isNotEmpty(courseIds)){
|
|
|
|
+ ExecutorService executor = Executors.newCachedThreadPool();
|
|
|
|
+ CompletableFuture.runAsync(()->{
|
|
|
|
+ try {
|
|
|
|
+ //更新课程营收
|
|
|
|
+ courseScheduleStudentPaymentService.updateCourseActualPrice(courseIds);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ },executor);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|