| | |
| | | |
| | | import com.alibaba.fastjson2.JSON; |
| | | import com.alibaba.fastjson2.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.xiaopeng.account.constant.I18nKeyConstant; |
| | |
| | | /** |
| | | * 定时任务发送优惠券通知 |
| | | */ |
| | | @Scheduled(cron = "0 0/1 * * * *") |
| | | @Scheduled(fixedDelay = 30000) |
| | | public void taskOrder() { |
| | | List<XpActivity> activityList = acticityClient.getAllEffectiveActivity().getData(); |
| | | List<XpActivity> collect1 = activityList.stream().filter(xpActivity -> xpActivity.getWechatNotification() == 1).collect(Collectors.toList()); |
| | | List<XpActivity> collect1 = activityList.stream().filter(xpActivity -> null != xpActivity.getWechatNotification() && xpActivity.getWechatNotification() == 1).collect(Collectors.toList()); |
| | | pushWxCouponMessage(collect1); |
| | | List<XpActivity> collect2 = activityList.stream().filter(xpActivity -> xpActivity.getSmsNotification() == 1).collect(Collectors.toList()); |
| | | List<XpActivity> collect2 = activityList.stream().filter(xpActivity -> null != xpActivity.getSmsNotification() && xpActivity.getSmsNotification() == 1).collect(Collectors.toList()); |
| | | pushSmsCouponMessage(collect2); |
| | | List<XpActivity> collect3 = activityList.stream().filter(xpActivity -> xpActivity.getMiniProgramNotification() == 1).collect(Collectors.toList()); |
| | | List<XpActivity> collect3 = activityList.stream().filter(xpActivity -> null != xpActivity.getMiniProgramNotification() && xpActivity.getMiniProgramNotification() == 1).collect(Collectors.toList()); |
| | | pushMiniProgramCouponMessage(collect3); |
| | | editUserCouponStatus(); |
| | | } |
| | | |
| | | |
| | |
| | | for (XpActivity xpActivity : activityList) { |
| | | //微信通知活动开始提醒(0=否,1=是) |
| | | Integer wechatActicityStart = xpActivity.getWechatActicityStart(); |
| | | if(1 == wechatActicityStart){ |
| | | if(null != wechatActicityStart && 1 == wechatActicityStart){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //即将到期提前通知 |
| | | Integer wechatActicityStartMinutes = xpActivity.getWechatActicityStartMinutes(); |
| | | //获取满足微信通知的即将生效的优惠券 |
| | | long time = LocalDateTime.now().minusMinutes(wechatActicityStartMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusMinutes(wechatActicityStartMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(effective_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(effective_time) - 100")); |
| | |
| | | vo.setUserId(xpAppUserCoupon.getAppUserId()); |
| | | vo.setTemplateId(MessageTemplateEnum.C.getTemplateId()); |
| | | String json = MessageTemplateEnum.C.getRemarks(); |
| | | json = json.replace("优惠券名称", xpAppUserCoupon.getCouponName()); |
| | | json = json.replace("今日出行最高立减XXX元,点击领取", coupon.getCouponDescription()); |
| | | json = json.replace("活动名称", xpAppUserCoupon.getCouponName()); |
| | | json = json.replace("温馨提示", coupon.getCouponDescription()); |
| | | vo.setJson(json); |
| | | R<?> r = subscribeMessageClient.sendSubscribeMessage(vo); |
| | | } |
| | |
| | | |
| | | //微信通知即将过期提醒(0=否,1=是) |
| | | Integer wechatAboutExpireReminder = xpActivity.getWechatAboutExpireReminder(); |
| | | if(1 == wechatAboutExpireReminder){ |
| | | if(null != wechatAboutExpireReminder && 1 == wechatAboutExpireReminder){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //即将到期提前通知 |
| | | Integer wechatAboutExpireDays = xpActivity.getWechatAboutExpireDays(); |
| | | //微信通知即将过期天数 |
| | | long time = LocalDateTime.now().minusDays(wechatAboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusDays(wechatAboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(expiration_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(expiration_time) - 100")); |
| | |
| | | */ |
| | | private void pushSmsCouponMessage(List<XpActivity> activityList) { |
| | | log.info("开始执行优惠券短信提醒消息发送 {}", activityList.size()); |
| | | for (XpActivity xpActivity : activityList) { |
| | | aa: for (XpActivity xpActivity : activityList) { |
| | | Integer now = Integer.valueOf(LocalDateTime.now().format(DateTimeFormatter.ofPattern("HHmm"))); |
| | | Integer smsAboutExpireReminder = xpActivity.getSmsAboutExpireReminder(); |
| | | String[] smsStartBlockingTime = xpActivity.getSmsStartBlockingTime().split(","); |
| | | String[] smsEndBlockingTime = xpActivity.getSmsEndBlockingTime().split(","); |
| | | for (int i = 0; i < smsStartBlockingTime.length; i++) { |
| | | Integer start = Integer.valueOf(smsStartBlockingTime[i].replace(":", "")); |
| | | Integer end = Integer.valueOf(smsEndBlockingTime[i].replace(":", "")); |
| | | if(start <= now && now <= end){ |
| | | log.info("当前时间在短信发送时间区间内,不发送短信"); |
| | | return; |
| | | if(StringUtils.hasLength(xpActivity.getSmsStartBlockingTime())){ |
| | | String[] smsStartBlockingTime = xpActivity.getSmsStartBlockingTime().split(","); |
| | | String[] smsEndBlockingTime = xpActivity.getSmsEndBlockingTime().split(","); |
| | | for (int i = 0; i < smsStartBlockingTime.length; i++) { |
| | | Integer start = Integer.valueOf(smsStartBlockingTime[i].replace(":", "")); |
| | | Integer end = Integer.valueOf(smsEndBlockingTime[i].replace(":", "")); |
| | | if(start <= now && now <= end){ |
| | | log.info("当前时间在短信发送时间区间内,不发送短信"); |
| | | continue aa; |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | //微信通知活动开始提醒(0=否,1=是) |
| | | Integer smsActicityStart = xpActivity.getSmsActicityStart(); |
| | | if(1 == smsActicityStart){ |
| | | if(null != smsActicityStart && 1 == smsActicityStart){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //短信通知临近券生效前X分钟通知 |
| | | Integer smsActicityStartMinutes = xpActivity.getSmsActicityStartMinutes(); |
| | | //获取满足微信通知的即将生效的优惠券 |
| | | long time = LocalDateTime.now().minusMinutes(smsActicityStartMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusMinutes(smsActicityStartMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(effective_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(effective_time) - 100")); |
| | |
| | | } |
| | | |
| | | //短信通知即将过期提醒(0=否,1=是) |
| | | if(1 == smsAboutExpireReminder){ |
| | | if(null != smsAboutExpireReminder && 1 == smsAboutExpireReminder){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //即将到期提前通知 |
| | | Integer smsAboutExpireDays = xpActivity.getSmsAboutExpireDays(); |
| | | //微信通知即将过期天数 |
| | | long time = LocalDateTime.now().minusDays(smsAboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusDays(smsAboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(expiration_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(expiration_time) - 100")); |
| | |
| | | //小程序弹窗券到账提醒(0=否,1=是) |
| | | Integer miniProgramReceivedReminder = xpActivity.getMiniProgramReceivedReminder(); |
| | | String expireMinutesNotificationContent = xpActivity.getExpireMinutesNotificationContent(); |
| | | if(1 == miniProgramReceivedReminder){ |
| | | if(null != miniProgramReceivedReminder && 1 == miniProgramReceivedReminder){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //即将到期提前通知 |
| | | Integer miniProgramAboutExpireMinutes = xpActivity.getMiniProgramAboutExpireMinutes(); |
| | | //获取满足微信通知的即将生效的优惠券 |
| | | long time = LocalDateTime.now().minusMinutes(miniProgramAboutExpireMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusMinutes(miniProgramAboutExpireMinutes).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(effective_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(effective_time) - 100")); |
| | |
| | | //小程序弹窗即将过期提醒(0=否,1=是) |
| | | Integer miniProgramAboutExpireReminder = xpActivity.getMiniProgramAboutExpireReminder(); |
| | | String expireDaysNotificationContent = xpActivity.getExpireDaysNotificationContent(); |
| | | if(1 == miniProgramAboutExpireReminder){ |
| | | if(null != miniProgramAboutExpireReminder && 1 == miniProgramAboutExpireReminder){ |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | //即将到期提前通知 |
| | | Integer aboutExpireDays = xpActivity.getAboutExpireDays(); |
| | | //微信通知即将过期天数 |
| | | long time = LocalDateTime.now().minusDays(aboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | long time = LocalDateTime.now().plusDays(aboutExpireDays).toEpochSecond(ZoneOffset.of("+8")); |
| | | List<XpAppUserCoupon> list = xpAppUserCouponService.list(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .eq(XpAppUserCoupon::getActivityId, xpActivity.getId()).eq(XpAppUserCoupon::getStatus, 1) |
| | | .last(" and UNIX_TIMESTAMP(expiration_time) >= " + time + " and " + time + "> UNIX_TIMESTAMP(expiration_time) - 100")); |
| | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | private void editUserCouponStatus(){ |
| | | log.info("开始执行编辑用户优惠券状态"); |
| | | RETRY_EXECUTOR.execute(() -> { |
| | | xpAppUserCouponService.update(new LambdaUpdateWrapper<XpAppUserCoupon>() |
| | | .set(XpAppUserCoupon::getStatus, 3) |
| | | .eq(XpAppUserCoupon::getStatus, 1) |
| | | .le(XpAppUserCoupon::getExpirationTime, LocalDateTime.now())); |
| | | }); |
| | | } |
| | | } |