package com.xiaopeng.operation.utils.task; import com.alibaba.fastjson.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.xiaopeng.api.dto.account.UcUserInfo; import com.xiaopeng.api.feignClient.account.UserResourcesClient; import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; import com.xiaopeng.api.feignClient.order.XpOrderClient; import com.xiaopeng.api.model.account.XpAppUserCoupon; import com.xiaopeng.api.model.operation.*; import com.xiaopeng.operation.service.*; 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.ArrayList; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; @Slf4j @Component public class ActivityTask { @Resource private IXpActicityStrategyService xpActicityStrategyService; @Resource private IXpActicityService xpActicityService; @Resource private IXpActicityUserService xpActicityUserService; @Resource private IXpWhitelistService xpWhitelistService; @Resource private IXpActicityCouponService xpActicityCouponService; @Resource private IXpCouponService xpCouponService; @Resource private XpAppUserCouponClient xpAppUserCouponClient; @Resource private XpOrderClient xpOrderClient; @Resource private UserResourcesClient userResourcesClient; @Scheduled(cron = "0 0/1 * * * *") public void taskOrder1() { xpActicityService.updateStatus(); } /** * 凌晨执行的定时任务 */ @Scheduled(cron = "0 0 0 * * *") public void taskOrder() { pusCoupon(); } /** * 每日发放券的活动 */ public void pusCoupon(){ List activities = xpActicityService.list(new QueryWrapper().eq("status", 2) .eq("is_deleted", 0).last(" and now() between start_time and end_time")); if(activities.isEmpty()){ return; } List activityIds = activities.stream().map(XpActivity::getId).collect(Collectors.toList()); //获取发放人 List xpActicityUsers = xpActicityUserService.list(new QueryWrapper().eq("is_deleted", 0) .in("actitcity_id", activityIds)); List list = xpActicityStrategyService.list(new QueryWrapper() .eq("distribution_rules", 1) .eq("is_deleted", 0) .in("actitcity_id", activityIds)); for (XpActicityStrategy xpActicityStrategy : list) { //发放人 List collect = xpActicityUsers.stream().filter(s -> s.getActitcityStrategeId().equals(xpActicityStrategy.getId())).collect(Collectors.toList()); } } }