|
@@ -606,57 +606,134 @@ public class LifeDiscountCouponStoreFriendServiceImpl extends ServiceImpl<LifeDi
|
|
|
return ruleVo;
|
|
return ruleVo;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 代金券类型常量
|
|
|
|
|
+ */
|
|
|
|
|
+ private static final Integer TYPE_VOUCHER = 4;
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
public List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(String storeUserId, String friendStoreUserId, String storeName, Integer type) {
|
|
public List<LifeDiscountCouponFriendRuleVo> getReceivedSendFriendCouponList(String storeUserId, String friendStoreUserId, String storeName, Integer type) {
|
|
|
- boolean voucherOnly = Integer.valueOf(4).equals(type);
|
|
|
|
|
|
|
+ // 参数校验:至少需要提供一个查询条件
|
|
|
|
|
+ if (StringUtils.isEmpty(storeUserId) && StringUtils.isEmpty(friendStoreUserId)) {
|
|
|
|
|
+ log.warn("getReceivedSendFriendCouponList 参数错误:storeUserId 和 friendStoreUserId 不能同时为空");
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 判断是否仅查询代金券
|
|
|
|
|
+ boolean voucherOnly = TYPE_VOUCHER.equals(type);
|
|
|
|
|
+
|
|
|
|
|
+ // 好友赠我场景
|
|
|
if (StringUtils.isNotEmpty(storeUserId)) {
|
|
if (StringUtils.isNotEmpty(storeUserId)) {
|
|
|
- // 好友赠我
|
|
|
|
|
- if (voucherOnly) {
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> q = new QueryWrapper<>();
|
|
|
|
|
- q.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) q.like("si.store_name", storeName);
|
|
|
|
|
- return lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(q);
|
|
|
|
|
- }
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> qCoupon = new QueryWrapper<>();
|
|
|
|
|
- qCoupon.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.coupon_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) qCoupon.like("si.store_name", storeName);
|
|
|
|
|
- List<LifeDiscountCouponFriendRuleVo> list = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponList(qCoupon);
|
|
|
|
|
- if (type != null) return list;
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> qVoucher = new QueryWrapper<>();
|
|
|
|
|
- qVoucher.eq("ldcsf.store_user_id", storeUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) qVoucher.like("si.store_name", storeName);
|
|
|
|
|
- List<LifeDiscountCouponFriendRuleVo> voucherList = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(qVoucher);
|
|
|
|
|
- list = new ArrayList<>(list);
|
|
|
|
|
- list.addAll(voucherList);
|
|
|
|
|
- list.sort((a, b) -> (b.getEndDate() != null && a.getEndDate() != null) ? b.getEndDate().compareTo(a.getEndDate()) : 0);
|
|
|
|
|
- return list;
|
|
|
|
|
|
|
+ return queryCouponList(true, storeUserId, storeName, type, voucherOnly);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ // 我赠好友场景
|
|
|
if (StringUtils.isNotEmpty(friendStoreUserId)) {
|
|
if (StringUtils.isNotEmpty(friendStoreUserId)) {
|
|
|
- // 我赠好友
|
|
|
|
|
- if (voucherOnly) {
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> q = new QueryWrapper<>();
|
|
|
|
|
- q.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) q.like("si.store_name", storeName);
|
|
|
|
|
- return lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(q);
|
|
|
|
|
- }
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> qCoupon = new QueryWrapper<>();
|
|
|
|
|
- qCoupon.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.coupon_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) qCoupon.like("si.store_name", storeName);
|
|
|
|
|
- List<LifeDiscountCouponFriendRuleVo> list = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhy(qCoupon);
|
|
|
|
|
- if (type != null) return list;
|
|
|
|
|
- QueryWrapper<LifeDiscountCouponFriendRuleVo> qVoucher = new QueryWrapper<>();
|
|
|
|
|
- qVoucher.eq("ldcsf.friend_store_user_id", friendStoreUserId).eq("ldcsf.delete_flag", 0).isNotNull("ldcsf.voucher_id");
|
|
|
|
|
- if (StringUtils.isNotEmpty(storeName)) qVoucher.like("si.store_name", storeName);
|
|
|
|
|
- List<LifeDiscountCouponFriendRuleVo> voucherList = lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(qVoucher);
|
|
|
|
|
- list = new ArrayList<>(list);
|
|
|
|
|
- list.addAll(voucherList);
|
|
|
|
|
- list.sort((a, b) -> (b.getEndDate() != null && a.getEndDate() != null) ? b.getEndDate().compareTo(a.getEndDate()) : 0);
|
|
|
|
|
- return list;
|
|
|
|
|
|
|
+ return queryCouponList(false, friendStoreUserId, storeName, type, voucherOnly);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
return new ArrayList<>();
|
|
return new ArrayList<>();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
|
|
+ * 查询赠券列表(抽取公共方法,减少代码重复)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param isReceivedByMe true=好友赠我,false=我赠好友
|
|
|
|
|
+ * @param userId 店铺用户ID(根据 isReceivedByMe 决定是 store_user_id 还是 friend_store_user_id)
|
|
|
|
|
+ * @param storeName 店铺名称(模糊查询)
|
|
|
|
|
+ * @param type 类型参数(4=代金券,其他=优惠券,null=全部)
|
|
|
|
|
+ * @param voucherOnly 是否仅查询代金券
|
|
|
|
|
+ * @return 赠券列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<LifeDiscountCouponFriendRuleVo> queryCouponList(boolean isReceivedByMe, String userId, String storeName, Integer type, boolean voucherOnly) {
|
|
|
|
|
+ // 仅查询代金券
|
|
|
|
|
+ if (voucherOnly) {
|
|
|
|
|
+ QueryWrapper<LifeDiscountCouponFriendRuleVo> queryWrapper = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
|
|
|
|
|
+ queryWrapper.isNotNull("ldcsf.voucher_id");
|
|
|
|
|
+ return isReceivedByMe
|
|
|
|
|
+ ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(queryWrapper)
|
|
|
|
|
+ : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(queryWrapper);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 查询优惠券
|
|
|
|
|
+ QueryWrapper<LifeDiscountCouponFriendRuleVo> couponQuery = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
|
|
|
|
|
+ couponQuery.isNotNull("ldcsf.coupon_id");
|
|
|
|
|
+ List<LifeDiscountCouponFriendRuleVo> couponList = isReceivedByMe
|
|
|
|
|
+ ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponList(couponQuery)
|
|
|
|
|
+ : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhy(couponQuery);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果 type 不为 null,说明只查询优惠券,直接返回
|
|
|
|
|
+ if (type != null) {
|
|
|
|
|
+ return sortByEndDate(couponList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // type 为 null,需要合并优惠券和代金券
|
|
|
|
|
+ QueryWrapper<LifeDiscountCouponFriendRuleVo> voucherQuery = buildBaseQueryWrapper(isReceivedByMe, userId, storeName);
|
|
|
|
|
+ voucherQuery.isNotNull("ldcsf.voucher_id");
|
|
|
|
|
+ List<LifeDiscountCouponFriendRuleVo> voucherList = isReceivedByMe
|
|
|
|
|
+ ? lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListVoucher(voucherQuery)
|
|
|
|
|
+ : lifeDiscountCouponStoreFriendMapper.getReceivedSendFriendCouponListwzhyVoucher(voucherQuery);
|
|
|
|
|
+
|
|
|
|
|
+ // 合并列表并排序
|
|
|
|
|
+ List<LifeDiscountCouponFriendRuleVo> result = new ArrayList<>(couponList);
|
|
|
|
|
+ result.addAll(voucherList);
|
|
|
|
|
+ return sortByEndDate(result);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 构建基础查询条件
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param isReceivedByMe true=好友赠我,false=我赠好友
|
|
|
|
|
+ * @param userId 店铺用户ID
|
|
|
|
|
+ * @param storeName 店铺名称(模糊查询)
|
|
|
|
|
+ * @return QueryWrapper
|
|
|
|
|
+ */
|
|
|
|
|
+ private QueryWrapper<LifeDiscountCouponFriendRuleVo> buildBaseQueryWrapper(boolean isReceivedByMe, String userId, String storeName) {
|
|
|
|
|
+ QueryWrapper<LifeDiscountCouponFriendRuleVo> queryWrapper = new QueryWrapper<>();
|
|
|
|
|
+ // 根据场景设置不同的用户ID字段
|
|
|
|
|
+ if (isReceivedByMe) {
|
|
|
|
|
+ queryWrapper.eq("ldcsf.store_user_id", userId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ queryWrapper.eq("ldcsf.friend_store_user_id", userId);
|
|
|
|
|
+ }
|
|
|
|
|
+ queryWrapper.eq("ldcsf.delete_flag", 0);
|
|
|
|
|
+ // 店铺名称模糊查询
|
|
|
|
|
+ if (StringUtils.isNotEmpty(storeName)) {
|
|
|
|
|
+ queryWrapper.like("si.store_name", storeName);
|
|
|
|
|
+ }
|
|
|
|
|
+ return queryWrapper;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 按结束时间降序排序(null 值排在最后)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param list 待排序列表
|
|
|
|
|
+ * @return 排序后的列表
|
|
|
|
|
+ */
|
|
|
|
|
+ private List<LifeDiscountCouponFriendRuleVo> sortByEndDate(List<LifeDiscountCouponFriendRuleVo> list) {
|
|
|
|
|
+ if (CollectionUtils.isEmpty(list)) {
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+ list.sort((a, b) -> {
|
|
|
|
|
+ Date dateA = a.getEndDate();
|
|
|
|
|
+ Date dateB = b.getEndDate();
|
|
|
|
|
+ // null 值排在最后
|
|
|
|
|
+ if (dateA == null && dateB == null) {
|
|
|
|
|
+ return 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dateA == null) {
|
|
|
|
|
+ return 1;
|
|
|
|
|
+ }
|
|
|
|
|
+ if (dateB == null) {
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ // 降序排序(最新的在前)
|
|
|
|
|
+ return dateB.compareTo(dateA);
|
|
|
|
|
+ });
|
|
|
|
|
+ return list;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
* 好评送券:用户好评且AI审核通过后,按运营活动配置的优惠券/代金券ID发放到用户券包,发放成功后扣减库存;按券类型发送对应通知。
|
|
* 好评送券:用户好评且AI审核通过后,按运营活动配置的优惠券/代金券ID发放到用户券包,发放成功后扣减库存;按券类型发送对应通知。
|
|
|
*
|
|
*
|
|
|
* @param userId 评价用户ID(life用户)
|
|
* @param userId 评价用户ID(life用户)
|