定时任务超v过期
课程过期
This commit is contained in:
48
src/main/java/com/peanut/modules/job/task/CourseTask.java
Normal file
48
src/main/java/com/peanut/modules/job/task/CourseTask.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package com.peanut.modules.job.task;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.peanut.modules.common.dao.UserCourseBuyDao;
|
||||
import com.peanut.modules.common.entity.UserCourseBuyEntity;
|
||||
import org.apache.commons.lang.time.DateUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@Component("courseTask")
|
||||
public class CourseTask implements ITask{
|
||||
|
||||
@Autowired
|
||||
private UserCourseBuyDao userCourseBuyDao;
|
||||
|
||||
@Override
|
||||
public void run(String params) {
|
||||
LambdaQueryWrapper<UserCourseBuyEntity> wrapper = new LambdaQueryWrapper();
|
||||
wrapper.eq(UserCourseBuyEntity::getUserId,params);
|
||||
List<UserCourseBuyEntity> list = userCourseBuyDao.selectList(wrapper);
|
||||
if (list.size() > 0) {
|
||||
for (UserCourseBuyEntity userCourseBuyEntity : list) {
|
||||
if (userCourseBuyEntity.getStartTime()==null) {
|
||||
//未开始学习,超过一年自动开始
|
||||
if (DateUtils.addYears(userCourseBuyEntity.getCreateTime(),1).getTime()<=new Date().getTime()){
|
||||
userCourseBuyEntity.setStartTime(DateUtils.addYears(userCourseBuyEntity.getCreateTime(),1));
|
||||
userCourseBuyEntity.setEndTime(DateUtils.addDays(userCourseBuyEntity.getStartTime(),userCourseBuyEntity.getDays()));
|
||||
userCourseBuyDao.updateById(userCourseBuyEntity);
|
||||
}
|
||||
}else {
|
||||
//开始时间+有效天数,过期删除
|
||||
if (DateUtils.addDays(userCourseBuyEntity.getStartTime(),userCourseBuyEntity.getDays()).getTime() >= new Date().getTime()) {
|
||||
userCourseBuyDao.deleteById(userCourseBuyEntity.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println("课程过期更新完成");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user