|
|
|
@@ -241,44 +241,37 @@ public class CouponSendSchedule { |
|
|
|
wxCUserBasicInfoDto.setTenantId(mall.getTenantId()); |
|
|
|
List<WxCUserBasicInfo> wxCUserBasicInfoList = wxCUserBasicInfoMapper.findBirthdayList(wxCUserBasicInfoDto); |
|
|
|
if (CollectionUtils.isEmpty(wxCUserBasicInfoList)) { |
|
|
|
logger.info("生日发券: {} 用户列表为空 wxCUserBasicInfoList = {}, 任务跳过不执行",mall.getName(),wxCUserBasicInfoList); |
|
|
|
logger.info("生日发券: {} 用户列表为空 wxCUserBasicInfoList = {}, 任务跳过不执行", mall.getName(), wxCUserBasicInfoList); |
|
|
|
return; |
|
|
|
} |
|
|
|
//每人可以发送几张生日券 |
|
|
|
final int sendCount = 1; |
|
|
|
// final int sendCount = 1; |
|
|
|
wxCUserBasicInfoList.forEach(cu -> { |
|
|
|
WxCouponSend wxCouponSend = new WxCouponSend(); |
|
|
|
wxCouponSend.setTenantId(cu.getTenantId()); |
|
|
|
wxCouponSend.setSendType(EnumCouponSendSendType.BIRTHDAY.getCode()); |
|
|
|
wxCouponSend.setStatus(EnumCouponSendStatus.VALID.getCode()); |
|
|
|
List<WxCouponSendVo> couponSendList = wxCouponSendMapper.findListVo(wxCouponSend); |
|
|
|
if(CollectionUtils.isEmpty(couponSendList)) { |
|
|
|
if (CollectionUtils.isEmpty(couponSendList)) { |
|
|
|
logger.info("生日发券: 会员生日券投放列表为空 couponSendList = {}, 任务跳过不执行", couponSendList); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(),cu.getTenantId()) ; |
|
|
|
if(Objects.isNull(config)||Objects.isNull(config.getConditions())) { |
|
|
|
WxCouponSend config = wxCouponSendService.getConfig(EnumCouponSendSendType.BIRTHDAY.getCode(), cu.getTenantId()); |
|
|
|
if (Objects.isNull(config) || Objects.isNull(config.getConditions())) { |
|
|
|
logger.info("生日发券: 会员生日券配置不存在 config = {}, 任务跳过不执行", config); |
|
|
|
return; |
|
|
|
} |
|
|
|
JSONObject configJo = JSONObject.parseObject(config.getConditions()) ; |
|
|
|
int beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); |
|
|
|
int remain = couponSendList.stream().map(cs -> { |
|
|
|
int count = cs.getRemainInventory(); |
|
|
|
logger.info("定时发券:给[" + cu.getNickName() + |
|
|
|
"]券[" + cs.getTitle() + "]还剩" + |
|
|
|
count + "张"); |
|
|
|
return count; |
|
|
|
}).reduce(Integer::sum).orElse(0); |
|
|
|
|
|
|
|
if (remain < sendCount) { |
|
|
|
logger.error("定时发券:库存不足[" + cu.getNickName() + "]应发" + sendCount + "张,总共剩" + remain + "张"); |
|
|
|
return; |
|
|
|
//默认生日当天发送 |
|
|
|
int beforeDays = 0; |
|
|
|
JSONObject configJo = JSONObject.parseObject(config.getConditions()); |
|
|
|
if (configJo.containsKey(WxCouponSend.KEY_BEFOREDAYS)) { |
|
|
|
beforeDays = configJo.getIntValue(WxCouponSend.KEY_BEFOREDAYS); |
|
|
|
} |
|
|
|
|
|
|
|
int sentCount = couponSendList.stream().map(cs -> { |
|
|
|
Map<String,Object> params = new HashMap<>(); |
|
|
|
for (WxCouponSendVo cs : couponSendList) { |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("tenantId", cs.getTenantId()); |
|
|
|
params.put("cUserId", cu.getId()); |
|
|
|
params.put("couponId", cs.getCouponId()); |
|
|
|
@@ -289,45 +282,36 @@ public class CouponSendSchedule { |
|
|
|
logger.info("生日发券:已经给[" + cu.getNickName() + |
|
|
|
"]券[" + cs.getTitle() + "] " + |
|
|
|
count + "张"); |
|
|
|
return count; |
|
|
|
}).reduce(Integer::sum).orElse(0); |
|
|
|
|
|
|
|
|
|
|
|
logger.info("生日发券:给[" + cu.getNickName() + |
|
|
|
"]总共已发送券" + sentCount + "张,还需发" + (sendCount - sentCount) + "张"); |
|
|
|
|
|
|
|
for (int count = 0; count < sendCount - sentCount; count++) { |
|
|
|
boolean sent = false; |
|
|
|
for (int couponIndex = 0; couponIndex < couponSendList.size(); couponIndex++) { |
|
|
|
WxCouponSendVo cs = couponSendList.get(couponIndex); |
|
|
|
//提前n天发送生日券,不满足跳过不执行 |
|
|
|
if(DateUtils.daysBetween(cu.getBirthdate(), new Date()) == beforeDays) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (cs.getRemainInventory() <= 0) |
|
|
|
continue; |
|
|
|
// 发放免费券 |
|
|
|
try { |
|
|
|
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); |
|
|
|
sendSMS(cu,mall); |
|
|
|
wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); |
|
|
|
logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("定时发券:商场[" + mall.getName() + |
|
|
|
"]会员生日[" + cu.getBirthdate().toInstant() + |
|
|
|
"]发送券[" + cs.getTitle() + |
|
|
|
"]给:" + cu.getNickName() + |
|
|
|
" 电话-" + cu.getPhone() + |
|
|
|
" id-" + cu.getId()); |
|
|
|
sent = true; |
|
|
|
break; |
|
|
|
if (count > 0) { |
|
|
|
logger.info("生日发券: 会员{}已经发送过生日券, 本次不再发送", cu.getNickName()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
//提前n天发送生日券,不满足跳过不执行 |
|
|
|
if (DateUtils.daysBetween(cu.getBirthdate(), new Date()) == beforeDays) { |
|
|
|
continue; |
|
|
|
} |
|
|
|
if (!sent) |
|
|
|
break; |
|
|
|
if (cs.getRemainInventory() <= 0) { |
|
|
|
logger.info("生日发券: [title={},id={}]卡券库存不足!", cs.getTitle(), cs.getCouponId()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
// 发放免费券 |
|
|
|
try { |
|
|
|
WxCouponOrder couponOrder = wxOrderService.sendFreeCouponToUser(cu.getId(), cs.getCouponId()); |
|
|
|
sendSMS(cu, mall); |
|
|
|
wxCouponActionLogService.addOne(cu.getTenantId(), cs.getCouponId(), couponOrder.getId(), cs.getSendType(), cs.getId()); |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); |
|
|
|
logger.info("定时发券:发券失败 levelId=" + cu.getId() + " couponId=" + cs.getCouponId() + " userId=" + cu.getId() + e.getMessage()); |
|
|
|
continue; |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("定时发券:商场[" + mall.getName() + |
|
|
|
"]会员生日[" + cu.getBirthdate().toInstant() + |
|
|
|
"]发送券[" + cs.getTitle() + |
|
|
|
"]给:" + cu.getNickName() + |
|
|
|
" 电话-" + cu.getPhone() + |
|
|
|
" id-" + cu.getId()); |
|
|
|
break; |
|
|
|
} |
|
|
|
}); |
|
|
|
}); |
|
|
|
|