| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.xiaopeng.api.model.operation.XpActicityStrategy; |
| | | import com.xiaopeng.api.model.operation.XpActicityUser; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.operation.service.IXpActicityService; |
| | | import com.xiaopeng.operation.service.IXpActicityStrategyService; |
| | | import com.xiaopeng.operation.service.IXpActicityUserService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.scheduling.annotation.Scheduled; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.List; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | | @Component |
| | |
| | | @Resource |
| | | private IXpActicityService xpActicityService; |
| | | |
| | | @Resource |
| | | private IXpActicityUserService xpActicityUserService; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 凌晨执行的定时任务 |
| | | */ |
| | | @Scheduled(cron = "0 0 0 * * *") |
| | | @Scheduled(cron = "0 0/1 * * * *") |
| | | public void taskOrder() { |
| | | xpActicityService.updateStatus(); |
| | | //循环发放的活动 |
| | | pusCoupon(); |
| | | } |
| | | |
| | |
| | | /** |
| | | * 每日发放券的活动 |
| | | */ |
| | | public void pusCoupon(){ |
| | | public void pusCoupon() { |
| | | List<XpActivity> activities = xpActicityService.list(new QueryWrapper<XpActivity>().eq("status", 2) |
| | | .eq("is_deleted", 0).last(" and now() between start_time and end_time")); |
| | | if(activities.isEmpty()){ |
| | | if (activities.isEmpty()) { |
| | | return; |
| | | } |
| | | List<Long> activityIds = activities.stream().map(XpActivity::getId).collect(Collectors.toList()); |
| | | //获取发放人 |
| | | List<XpActicityUser> xpActicityUsers = xpActicityUserService.list(new QueryWrapper<XpActicityUser>().eq("is_deleted", 0) |
| | | .in("actitcity_id", activityIds)); |
| | | List<XpActicityStrategy> list = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>() |
| | | .eq("distribution_rules", 1) |
| | | .eq("is_deleted", 0) |
| | | .in("actitcity_id", activityIds)); |
| | | for (XpActicityStrategy xpActicityStrategy : list) { |
| | | //发放人 |
| | | List<XpActicityUser> collect = xpActicityUsers.stream().filter(s -> s.getActitcityStrategeId().equals(xpActicityStrategy.getId())).collect(Collectors.toList()); |
| | | |
| | | |
| | | |
| | | |
| | | for (XpActivity activity : activities) { |
| | | List<XpActicityStrategy> list = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>() |
| | | .eq("distribution_rules", 1) |
| | | .eq("is_deleted", 0) |
| | | .eq("actitcity_id", activity.getId())); |
| | | for (XpActicityStrategy xpActicityStrategy : list) { |
| | | String distributionTime = xpActicityStrategy.getDistributionTime(); |
| | | String format = LocalDateTime.now().format(DateTimeFormatter.ofPattern("HH:mm")); |
| | | if (distributionTime.equals(format)) { |
| | | xpActicityService.pushCoupon(activity, xpActicityStrategy); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |