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