| | |
| | | import com.ruoyi.account.api.model.TAppUserVipDetail; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.account.service.TAppUserVipDetailService; |
| | | import org.intellij.lang.annotations.RegExp; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDate; |
| | | import java.time.LocalDateTime; |
| | | import java.util.List; |
| | | |
| | | |
| | |
| | | */ |
| | | @Component |
| | | public class TaskUtil { |
| | | |
| | | @Resource |
| | | private TAppUserVipDetailService tAppUserVipDetailService; |
| | | |
| | | @Resource |
| | | private TAppUserService appUserService; |
| | | |
| | | |
| | | /** |
| | | * 每隔一分钟去处理的定时任务 |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void sendVipCoupon(){ |
| | | try { |
| | | //首先获取当前的月份,用int类型标识 |
| | | LocalDate currentDate = LocalDate.now(); |
| | | int monthNum = currentDate.getMonthValue(); |
| | | //获取在当前时间内生效的vipDetail |
| | | List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery() |
| | | .ge(TAppUserVipDetail::getStartTime, currentDate) |
| | | .le(TAppUserVipDetail::getEndTime, currentDate) |
| | | .orderByDesc(TAppUserVipDetail::getStartTime).list(); |
| | | //判断sendNum是否包括当前月份 |
| | | for (TAppUserVipDetail recentDetail : recentDetails) { |
| | | |
| | | //赠送优惠卷 |
| | | tAppUserVipDetailService.giveVipCoupun(recentDetail.getAppUserId(), recentDetail.getVipId(),recentDetail.getId(),monthNum); |
| | | |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | } |
| | | |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void changeVipId(){ |
| | | LocalDate currentDate = LocalDate.now(); |
| | | List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery() |
| | | .le(TAppUserVipDetail::getStartTime, currentDate) |
| | | .ge(TAppUserVipDetail::getEndTime, currentDate) |
| | | .orderByDesc(TAppUserVipDetail::getStartTime).list(); |
| | | for (TAppUserVipDetail recentDetail : recentDetails) { |
| | | TAppUser byId = appUserService.getById(recentDetail.getAppUserId()); |
| | | if (byId!=null) { |
| | | byId.setVipId(recentDetail.getVipId()); |
| | | appUserService.updateById(byId); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @Resource |
| | | private TAppUserVipDetailService tAppUserVipDetailService; |
| | | |
| | | @Resource |
| | | private TAppUserService appUserService; |
| | | |
| | | |
| | | /** |
| | | * 每隔一分钟去处理的定时任务 |
| | | */ |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void sendVipCoupon() { |
| | | try { |
| | | //会员优惠次数使用完后重新续次数 |
| | | LocalDateTime currentDate = LocalDateTime.now(); |
| | | List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery() |
| | | .le(TAppUserVipDetail::getStartTime, currentDate) |
| | | .ge(TAppUserVipDetail::getEndTime, currentDate) |
| | | .eq(TAppUserVipDetail::getChargeNum, 0) |
| | | .le(TAppUserVipDetail::getMonthEndTime, currentDate) |
| | | .orderByDesc(TAppUserVipDetail::getStartTime).list(); |
| | | for (TAppUserVipDetail recentDetail : recentDetails) { |
| | | tAppUserVipDetailService.giveVipCoupun(recentDetail); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void changeVipId() { |
| | | LocalDateTime currentDate = LocalDateTime.now(); |
| | | List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery() |
| | | .le(TAppUserVipDetail::getStartTime, currentDate) |
| | | .ge(TAppUserVipDetail::getEndTime, currentDate) |
| | | .orderByDesc(TAppUserVipDetail::getStartTime).list(); |
| | | for (TAppUserVipDetail recentDetail : recentDetails) { |
| | | TAppUser byId = appUserService.getById(recentDetail.getAppUserId()); |
| | | if (byId != null) { |
| | | byId.setVipId(recentDetail.getVipId()); |
| | | appUserService.updateById(byId); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |