49 lines
1.9 KiB
Java
49 lines
1.9 KiB
Java
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("课程过期更新完成");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|