| | |
| | | package com.ruoyi.account.task; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONArray; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.ruoyi.account.api.model.TAppCoupon; |
| | | import com.ruoyi.account.api.model.TAppUser; |
| | | import com.ruoyi.account.api.model.TAppUserVipDetail; |
| | | import com.ruoyi.account.service.TAppCouponService; |
| | | import com.ruoyi.account.service.TAppUserService; |
| | | import com.ruoyi.account.service.TAppUserVipDetailService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.other.api.domain.TCoupon; |
| | | import com.ruoyi.other.api.feignClient.OtherClient; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.boot.web.context.WebServerInitializedEvent; |
| | | import org.springframework.context.ApplicationListener; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | |
| | | /** |
| | | * 定时任务工具类 |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | | public class TaskUtil implements ApplicationListener<WebServerInitializedEvent> { |
| | | |
| | |
| | | |
| | | @Resource |
| | | private TAppUserService appUserService; |
| | | |
| | | |
| | | @Resource |
| | | private OtherClient otherClient; |
| | | |
| | | @Resource |
| | | private TAppCouponService appCouponService; |
| | | |
| | | |
| | | private Integer port = null; |
| | | |
| | | |
| | |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | @Scheduled(cron = "0 5 0 1 * ?") |
| | | public void pushVipCoupon() { |
| | | if(null != port && port == 5200){ |
| | | log.info("发送季度会员和年度会员优惠券"); |
| | | try { |
| | | //季度会员和年度会员需要每月发送会员优惠券 |
| | | LocalDateTime currentDate = LocalDateTime.now(); |
| | | List<TAppUserVipDetail> recentDetails = tAppUserVipDetailService.lambdaQuery() |
| | | .le(TAppUserVipDetail::getStartTime, currentDate) |
| | | .ge(TAppUserVipDetail::getEndTime, currentDate) |
| | | .ne(TAppUserVipDetail::getVipType, 1).list(); |
| | | for (TAppUserVipDetail recentDetail : recentDetails) { |
| | | //[{"id":22,"number":5},{"id":21,"number":1}] |
| | | String couponIds = recentDetail.getCouponIds(); |
| | | JSONArray objects = JSON.parseArray(couponIds); |
| | | for (int i = 0; i < objects.size(); i++) { |
| | | JSONObject jsonObject = objects.getJSONObject(i); |
| | | Integer id = jsonObject.getInteger("id"); |
| | | Integer number = jsonObject.getInteger("number"); |
| | | R<TCoupon> couponById = otherClient.getCouponById(id); |
| | | TCoupon coupon = couponById.getData(); |
| | | |
| | | for (int j = 0; j < number; j++) { |
| | | //将该优惠卷添加到用户优惠卷中 |
| | | TAppCoupon tAppCoupon = new TAppCoupon(); |
| | | tAppCoupon.setAppUserId(recentDetail.getAppUserId()); |
| | | tAppCoupon.setCouponId(id); |
| | | if (coupon.getValidityPeriodMode() == 1) { |
| | | tAppCoupon.setEndTime(coupon.getEndTime()); |
| | | } else { |
| | | tAppCoupon.setEndTime(LocalDateTime.now().plusDays(coupon.getDays())); |
| | | } |
| | | tAppCoupon.setWaysToObtain(4); |
| | | tAppCoupon.setStatus(1); |
| | | tAppCoupon.setCouponJson(com.alibaba.fastjson2.JSON.toJSONString(coupon)); |
| | | tAppCoupon.setDetailId(recentDetail.getId()); |
| | | appCouponService.save(tAppCoupon); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | @Scheduled(fixedRate = 1000 * 60) |
| | | public void changeVipId() { |