| | |
| | | |
| | | @Scheduled(cron = "0 0/1 * * * *") |
| | | public void taskOrder1() { |
| | | List<XpActivity> list = xpActicityService.list(new QueryWrapper<XpActivity>().in("status", Arrays.asList(1, 2)).eq("is_deleted", 0)); |
| | | for (XpActivity xpActivity : list) { |
| | | Integer status = xpActivity.getStatus(); |
| | | if(1 == status && LocalDateTime.now().isAfter(xpActivity.getStartTime()) && LocalDateTime.now().isBefore(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(2); |
| | | //发放优惠券-发放一次的优惠券 |
| | | List<XpActicityStrategy> list1 = xpActicityStrategyService.list(new QueryWrapper<XpActicityStrategy>().eq("actitcity_id", xpActivity.getId()) |
| | | .eq("distribution_rules", 2)); |
| | | for (XpActicityStrategy xpActicityStrategy : list1) { |
| | | List<XpActicityCoupon> acticityCoupons = xpActicityCouponService.list(new QueryWrapper<XpActicityCoupon>().eq("actitcity_strategy_id", xpActicityStrategy.getId())); |
| | | List<XpCoupon> xpCoupons = xpCouponService.listByIds(acticityCoupons.stream().map(XpActicityCoupon::getCouponId).collect(Collectors.toList())); |
| | | |
| | | List<XpActicityUser> list2 = xpActicityUserService.list(new QueryWrapper<XpActicityUser>().eq("actitcity_stratege_id", xpActicityStrategy.getId())); |
| | | for (XpActicityUser xpActicityUser : list2) { |
| | | Integer userType = xpActicityUser.getUserType(); |
| | | //全部白名单用户 |
| | | if(1 == userType){ |
| | | List<XpWhitelist> list3 = xpWhitelistService.list(new QueryWrapper<XpWhitelist>().eq("is_deleted", 0).eq("status", 1)); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (XpWhitelist xpWhitelist : list3) { |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(xpWhitelist.getAppUserId()); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(xpWhitelist.getAccount()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | } |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | xpAppUserCouponClient.saveBatch(xpAppUserCoupons); |
| | | } |
| | | } |
| | | //老用户 |
| | | if(2 == userType || 3 == userType || 4 == userType){ |
| | | List<Long> longList = xpOrderClient.getUserTypeIdList(userType).getData(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Long userId : longList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | } |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | xpAppUserCouponClient.saveBatch(xpAppUserCoupons); |
| | | } |
| | | } |
| | | //指定用户 |
| | | if(5 == userType){ |
| | | List<Long> userList = xpActicityUser.getUserList(); |
| | | List<XpAppUserCoupon> xpAppUserCoupons = new ArrayList<>(); |
| | | for (Long userId : userList) { |
| | | UcUserInfo baseUserByUid = userResourcesClient.getBaseUserByUid(userId.toString()); |
| | | for (XpActicityCoupon acticityCoupon : acticityCoupons) { |
| | | XpCoupon xpCoupon = xpCoupons.stream().filter(s -> s.getId().equals(acticityCoupon.getCouponId())).findFirst().orElse(null); |
| | | if(null != xpCoupon){ |
| | | XpAppUserCoupon xpAppUserCoupon = new XpAppUserCoupon(); |
| | | xpAppUserCoupon.setFullMoney(xpCoupon.getConditionalAmount()); |
| | | xpAppUserCoupon.setMoney(xpCoupon.getAmount()); |
| | | |
| | | Integer expireRules = xpActicityStrategy.getExpireRules(); |
| | | //次日0点失效 |
| | | if(1 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | LocalDateTime localDateTime = now.plusDays(1); |
| | | LocalDateTime localDateTime1 = localDateTime.withHour(0).withMinute(0).withSecond(0); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime1); |
| | | } |
| | | //指定有效天数 |
| | | if(2 == expireRules){ |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | xpAppUserCoupon.setExpirationTime(now.plusDays(xpActicityStrategy.getExpireDays())); |
| | | } |
| | | //指定日期失效 |
| | | if(3 == expireRules){ |
| | | String format = xpActicityStrategy.getExpireDate().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); |
| | | LocalDateTime localDateTime = LocalDateTime.parse(format + " 23:59:59", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")); |
| | | xpAppUserCoupon.setExpirationTime(localDateTime); |
| | | } |
| | | |
| | | xpAppUserCoupon.setCouponId(acticityCoupon.getCouponId()); |
| | | xpAppUserCoupon.setAppUserId(userId); |
| | | xpAppUserCoupon.setStatus(1); |
| | | xpAppUserCoupon.setActivityId(xpActivity.getId()); |
| | | xpAppUserCoupon.setCouponName(xpCoupon.getCouponName()); |
| | | xpAppUserCoupon.setDeleted(false); |
| | | xpAppUserCoupon.setCreateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setUpdateTime(LocalDateTime.now()); |
| | | xpAppUserCoupon.setPhone(baseUserByUid.getMobile()); |
| | | xpAppUserCoupon.setTimeJson(JSON.toJSONString(xpActicityStrategy.getUsagePeriod())); |
| | | xpAppUserCoupons.add(xpAppUserCoupon); |
| | | } |
| | | } |
| | | } |
| | | if(!xpAppUserCoupons.isEmpty()){ |
| | | xpAppUserCouponClient.saveBatch(xpAppUserCoupons); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | }else if(2 == status & LocalDateTime.now().isAfter(xpActivity.getEndTime())){ |
| | | xpActivity.setStatus(3); |
| | | } |
| | | xpActicityService.updateById(xpActivity); |
| | | } |
| | | xpActicityService.updateStatus(); |
| | | } |
| | | |
| | | |