生日有礼问题
This commit is contained in:
@@ -104,7 +104,8 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
||||
|
||||
@Override
|
||||
public Page<MkBirthdayGiftRecordVO> getRecord(Long shopId, String key, LocalDateTime dateTime) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().select()
|
||||
QueryWrapper queryWrapper = new MyQueryWrapper()
|
||||
.selectAll(MkBirthdayGiftRecord.class)
|
||||
.select(ShopUser::getNickName, ShopUser::getPhone)
|
||||
.eq(MkBirthdayGiftRecord::getMainShopId, shopId)
|
||||
.leftJoin(ShopUser.class).on(ShopUser::getId, MkBirthdayGiftRecord::getShopUserId);
|
||||
@@ -165,66 +166,64 @@ public class MkBirthdayGiftServiceImpl extends ServiceImpl<MkBirthdayGiftMapper,
|
||||
shopTemplate = null;
|
||||
}
|
||||
ShopInfo shopInfo = shopInfoService.getById(birthdayGift.getMainShopId());
|
||||
FunUtils.safeRunVoid(() -> {
|
||||
JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class).forEach(config -> {
|
||||
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
||||
if ("day".equals(config.getDeliverDate())) {
|
||||
if (config.getDeliverTime() != 1) {
|
||||
current = current.plusDays(config.getDeliverTime());
|
||||
}
|
||||
} else {
|
||||
// 获取当月第一天
|
||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
||||
FunUtils.safeRunVoid(() -> JSONArray.parseArray(birthdayGift.getConfigList()).toJavaList(MkBirthdayGiftConfig.class).forEach(config -> {
|
||||
LocalDate current = DateUtil.date().toLocalDateTime().toLocalDate();
|
||||
if ("day".equals(config.getDeliverDate())) {
|
||||
if (config.getDeliverTime() != 1) {
|
||||
current = current.plusDays(config.getDeliverTime());
|
||||
}
|
||||
List<ShopUser> shopUserList = shopUserService.selectBirthdayUser(current, birthdayGift.getMainShopId(), config.getUserType());
|
||||
log.info("符合用户, {}", shopUserList);
|
||||
for (ShopUser shopUser : shopUserList) {
|
||||
long count = birthdayGiftRecordService.count(new QueryWrapper().eq(MkBirthdayGiftRecord::getUserId, shopUser.getUserId())
|
||||
.eq(MkBirthdayGiftRecord::getYear, DateUtil.year(now)));
|
||||
if (count > 1) {
|
||||
log.info("用户{}已领取过生日礼包", shopUser.getUserId());
|
||||
continue;
|
||||
}
|
||||
// 发放记录
|
||||
MkBirthdayGiftRecord giftRecord = new MkBirthdayGiftRecord().setUserId(shopUser.getUserId()).setShopUserId(shopUser.getId())
|
||||
.setPushStatus(birthdayGift.getSendSms() == 1 ?
|
||||
TableValueConstant.BirthdayGiftRecord.PushStatus.WAIT_PUSH.getCode() : TableValueConstant.BirthdayGiftRecord.PushStatus.NO_PUSH.getCode())
|
||||
.setMainShopId(birthdayGift.getMainShopId()).setBirthday(DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate())
|
||||
.setPhone(shopUser.getPhone()).setTemplateId(shopTemplate == null ? null : shopTemplate.getId())
|
||||
.setYear(DateUtil.year(now)).setUserType(config.getUserType())
|
||||
.setSourceId(birthdayGift.getId()).setTemplateCode(shopTemplate == null ? null : shopTemplate.getTemplateCode()).setTemplateContent(JSONObject.toJSONString(Map.of(
|
||||
"用户昵称", shopUser.getNickName(),
|
||||
"店铺名称", shopInfo.getShopName(),
|
||||
"数量", config.getCouponInfoList() != null ? config.getCouponInfoList().stream().map(CouponInfoDTO::getNum).reduce(0, Integer::sum) : 0
|
||||
)));
|
||||
birthdayGiftRecordService.save(giftRecord);
|
||||
rabbitPublisher.sendBirthdayGiftSmsMsg(giftRecord.getId().toString());
|
||||
} else {
|
||||
// 获取当月第一天
|
||||
current = DateUtil.beginOfMonth(now).toLocalDateTime().toLocalDate();
|
||||
}
|
||||
List<ShopUser> shopUserList = shopUserService.selectBirthdayUser(current, birthdayGift.getMainShopId(), config.getUserType());
|
||||
log.info("符合用户, {}", shopUserList);
|
||||
for (ShopUser shopUser : shopUserList) {
|
||||
long count = birthdayGiftRecordService.count(new QueryWrapper().eq(MkBirthdayGiftRecord::getUserId, shopUser.getUserId())
|
||||
.eq(MkBirthdayGiftRecord::getYear, DateUtil.year(now)));
|
||||
if (count > 1) {
|
||||
log.info("用户{}已领取过生日礼包", shopUser.getUserId());
|
||||
continue;
|
||||
}
|
||||
// 发放记录
|
||||
MkBirthdayGiftRecord giftRecord = new MkBirthdayGiftRecord().setUserId(shopUser.getUserId()).setShopUserId(shopUser.getId())
|
||||
.setPushStatus(birthdayGift.getSendSms() == 1 ?
|
||||
TableValueConstant.BirthdayGiftRecord.PushStatus.WAIT_PUSH.getCode() : TableValueConstant.BirthdayGiftRecord.PushStatus.NO_PUSH.getCode())
|
||||
.setMainShopId(birthdayGift.getMainShopId()).setBirthday(DateUtil.parseDate(shopUser.getBirthDay()).toLocalDateTime().toLocalDate())
|
||||
.setPhone(shopUser.getPhone()).setTemplateId(shopTemplate == null ? null : shopTemplate.getId())
|
||||
.setYear(DateUtil.year(now)).setUserType(config.getUserType())
|
||||
.setSourceId(birthdayGift.getId()).setTemplateCode(shopTemplate == null ? null : shopTemplate.getTemplateCode()).setTemplateContent(JSONObject.toJSONString(Map.of(
|
||||
"用户昵称", shopUser.getNickName(),
|
||||
"店铺名称", shopInfo.getShopName(),
|
||||
"数量", config.getCouponInfoList() != null ? config.getCouponInfoList().stream().map(CouponInfoDTO::getNum).reduce(0, Integer::sum) : 0
|
||||
)));
|
||||
birthdayGiftRecordService.save(giftRecord);
|
||||
rabbitPublisher.sendBirthdayGiftSmsMsg(giftRecord.getId().toString());
|
||||
|
||||
// 优惠券信息
|
||||
if (config.getCouponInfoList() != null && !config.getCouponInfoList().isEmpty()) {
|
||||
Map<Long, ShopCoupon> couponMap = shopCouponService.list(new QueryWrapper().in(ShopCoupon::getId, config.getCouponInfoList()
|
||||
.stream().map(CouponInfoDTO::getId).toList())).stream().collect(Collectors.toMap(ShopCoupon::getId, item -> item));
|
||||
config.getCouponInfoList().forEach(couponInfo -> {
|
||||
ShopCoupon shopCoupon = couponMap.get(couponInfo.getId());
|
||||
if (shopCoupon == null) {
|
||||
log.warn("优惠券不存在, id: {}", couponInfo.getId());
|
||||
return;
|
||||
}
|
||||
FunUtils.safeRunVoid(() -> {
|
||||
shopCouponRecordService.grant(birthdayGift.getMainShopId(), new MkRewardCouponDTO().setCouponId(couponInfo.getId())
|
||||
.setNum(couponInfo.getNum())
|
||||
.setUserId(shopUser.getUserId())
|
||||
.setShopId(birthdayGift.getMainShopId()), "生日赠券");
|
||||
MkBirthdayGiftRecordCoupon recordCoupon = new MkBirthdayGiftRecordCoupon().setCouponName(shopCoupon.getTitle()).setNum(couponInfo.getNum())
|
||||
.setType(TableValueConstant.BirthdayGiftRecordCoupon.Type.GIVE.getCode())
|
||||
.setRecordId(giftRecord.getId()).setUserId(shopUser.getUserId()).setShopUserId(shopUser.getId());
|
||||
birthdayGiftRecordCouponService.save(recordCoupon);
|
||||
}, "优惠券发放失败");
|
||||
});
|
||||
}
|
||||
// 优惠券信息
|
||||
if (config.getCouponInfoList() != null && !config.getCouponInfoList().isEmpty()) {
|
||||
Map<Long, ShopCoupon> couponMap = shopCouponService.list(new QueryWrapper().in(ShopCoupon::getId, config.getCouponInfoList()
|
||||
.stream().map(CouponInfoDTO::getId).toList())).stream().collect(Collectors.toMap(ShopCoupon::getId, item -> item));
|
||||
config.getCouponInfoList().forEach(couponInfo -> {
|
||||
ShopCoupon shopCoupon = couponMap.get(couponInfo.getId());
|
||||
if (shopCoupon == null) {
|
||||
log.warn("优惠券不存在, id: {}", couponInfo.getId());
|
||||
return;
|
||||
}
|
||||
FunUtils.safeRunVoid(() -> {
|
||||
shopCouponRecordService.grant(birthdayGift.getMainShopId(), new MkRewardCouponDTO().setCouponId(couponInfo.getId())
|
||||
.setNum(couponInfo.getNum())
|
||||
.setUserId(shopUser.getUserId())
|
||||
.setShopId(birthdayGift.getMainShopId()), "生日赠券");
|
||||
MkBirthdayGiftRecordCoupon recordCoupon = new MkBirthdayGiftRecordCoupon().setCouponName(shopCoupon.getTitle()).setNum(couponInfo.getNum())
|
||||
.setType(TableValueConstant.BirthdayGiftRecordCoupon.Type.GIVE.getCode())
|
||||
.setRecordId(giftRecord.getId()).setUserId(shopUser.getUserId()).setShopUserId(shopUser.getId());
|
||||
birthdayGiftRecordCouponService.save(recordCoupon);
|
||||
}, "优惠券发放失败");
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user