| | |
| | | import com.xinquan.user.service.AppUserService; |
| | | import com.xinquan.user.service.AppUserTreeService; |
| | | import com.xinquan.user.service.NoticeRecordService; |
| | | import org.springframework.scheduling.annotation.EnableScheduling; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | |
| | | private AppUserTreeService appUserTreeService; |
| | | @Resource |
| | | private NoticeRecordService noticeRecordService; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 每天凌晨12点执行的定时任务 |
| | |
| | | @Scheduled(cron = "0 0 0 * * ?") |
| | | public void taskLastDay() { |
| | | try { |
| | | System.err.println("每天晚上凌晨执行的任务"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | List<AppUserTree> list1 = appUserTreeService.lambdaQuery().eq(AppUserTree::getSowAgain, 2) |
| | | .list(); |
| | |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | LocalDate localDate = LocalDateTime.now().toLocalDate(); |
| | | System.err.println(localDate); |
| | | |
| | | } |
| | | // 每天早上7点执行的定时任务 |
| | | |
| | | @Scheduled(cron = "0 0 7 * * ?") |
| | | public void taskSivenDay() { |
| | | try { |
| | | System.err.println("每天晚上早上7点执行的任务"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | List<AppUser> list = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3).list(); |
| | | for (AppUser appUser : list) { |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | // 每天晚上9点执行的定时任务 |
| | | @Scheduled(cron = "0 0 21 * * ?") |
| | | public void taskNineDay() { |
| | | try { |
| | | System.err.println("执行每天晚上9点的定时任务"); |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | List<AppUser> list = appUserService.lambdaQuery().ne(AppUser::getUserStatus, 3).list(); |
| | | for (AppUser appUser : list) { |
| | |
| | | noticeRecord.setContent("你今天还未签到,及时签到可获得能量值奖励,快去签到吧!"); |
| | | noticeRecordService.save(noticeRecord); |
| | | } |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |