| | |
| | | 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); |
| | | LocalDateTime localDateTime = LocalDateTime.now().minusDays(7); |
| | | long between = ChronoUnit.DAYS.between(LocalDateTime.now(),localDateTime); |
| | | System.err.println(between); |
| | | } |
| | | // 每天早上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) { |
| | | if (appUser.getVipExpireTime()!=null && appUser.getVipExpireTime().isAfter(now)){ |
| | | // 计算两个now和time的天数差 |
| | | long between = ChronoUnit.DAYS.between(appUser.getVipExpireTime(), now); |
| | | if (between<=7){ |
| | | long between = ChronoUnit.DAYS.between(now,appUser.getVipExpireTime()); |
| | | if (between<=7 &&between>=0){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(appUser.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("【会员临期通知】"); |
| | | noticeRecord.setContent("尊敬的心泉疗愈会员你好,你的会员即将在" |
| | | noticeRecord.setContent("尊敬的泉疗愈会员你好,你的会员即将在" |
| | | +appUser.getVipExpireTime().toLocalDate()+"到期,到期后将不再享受会员权益,请及时续费"); |
| | | noticeRecordService.save(noticeRecord); |
| | | } |
| | | |
| | | } |
| | | AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, appUser.getId()) |
| | | .eq(AppUserTree::getSowAgain, 2).one(); |
| | | if(one!=null&&(one.getTaskOne()==2||one.getTaskTwo()==2)){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(appUser.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("【冥想通知】"); |
| | | noticeRecord.setContent("你今天的冥想任务还未完成,完成冥想后可获得能量值奖励,快去冥想吧!"); |
| | | noticeRecordService.save(noticeRecord); |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | 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) { |
| | | AppUserTree one = appUserTreeService.lambdaQuery().eq(AppUserTree::getAppUserId, appUser.getId()) |
| | | .eq(AppUserTree::getSowAgain, 2).one(); |
| | | if(one!=null && (one.getTaskOne()==2||one.getTaskTwo()==2)){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(appUser.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("【冥想通知】"); |
| | | noticeRecord.setContent("你今天的冥想任务还未完成,完成冥想后可获得能量值奖励,快去冥想吧!"); |
| | | noticeRecordService.save(noticeRecord); |
| | | } |
| | | if (appUser.getSignTime()==null){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(appUser.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("【签到通知】"); |
| | | noticeRecord.setContent("你今天还未签到,及时签到可获得能量值奖励,快去签到吧!"); |
| | | noticeRecordService.save(noticeRecord); |
| | | }else if (!appUser.getSignTime().toLocalDate().equals(LocalDateTime.now().toLocalDate())){ |
| | | NoticeRecord noticeRecord = new NoticeRecord(); |
| | | noticeRecord.setAppUserId(appUser.getId()); |
| | | noticeRecord.setReadStatus(1); |
| | | noticeRecord.setNoticeType(1); |
| | | noticeRecord.setTitle("【签到通知】"); |
| | | noticeRecord.setContent("你今天还未签到,及时签到可获得能量值奖励,快去签到吧!"); |
| | | noticeRecordService.save(noticeRecord); |
| | | } |
| | | } |
| | | } catch (Exception e) { |