Commit 0d0fec04 by 章家宝

feat:优惠券红点接口与获取弹窗通知保持一致

1 parent 2dcc8f46
...@@ -288,7 +288,7 @@ public class CouponAccountService { ...@@ -288,7 +288,7 @@ public class CouponAccountService {
/** /**
* 检查用户是否有待通知的弹窗(红点状态) * 检查用户是否有待通知的弹窗(红点状态)
* <p> * <p>
* 查询用户是否有状态为待通知(0)且未过期的弹窗通知 * 查询用户状态为待通知(0)且未过期的弹窗通知,并校验关联优惠券是否过期
* *
* @param accountId 用户 ID * @param accountId 用户 ID
* @return 红点状态响应 * @return 红点状态响应
...@@ -296,13 +296,39 @@ public class CouponAccountService { ...@@ -296,13 +296,39 @@ public class CouponAccountService {
public CouponRedDotRespVO checkRedDotStatus(Integer accountId) { public CouponRedDotRespVO checkRedDotStatus(Integer accountId) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
// 统计待通知且未过期的弹窗通知数量 // 查询待通知且未过期的弹窗通知
Long pendingCount = popupNotificationRepository.countPendingNotifications( List<CouponPopupNotification> pendingNotifications = popupNotificationRepository.findPendingNotifications(
accountId, 0, DeleteFlag.NOT_DELETED.getCode(), now); accountId, 0, DeleteFlag.NOT_DELETED.getCode(), now);
CouponRedDotRespVO respVO = new CouponRedDotRespVO(); CouponRedDotRespVO respVO = new CouponRedDotRespVO();
respVO.setHasRedDot(pendingCount != null && pendingCount > 0);
respVO.setPendingCount(pendingCount != null ? pendingCount : 0L); if (pendingNotifications.isEmpty()) {
respVO.setHasRedDot(false);
respVO.setPendingCount(0L);
return respVO;
}
// 提取所有优惠券 ID
List<String> couponIdList = new ArrayList<>();
for (CouponPopupNotification notification : pendingNotifications) {
JSONArray objects = JSON.parseArray(notification.getCouponIds());
couponIdList.addAll(objects.toJavaList(String.class));
}
if (couponIdList.isEmpty()) {
respVO.setHasRedDot(false);
respVO.setPendingCount(0L);
return respVO;
}
// 查询优惠券并过滤掉已过期的
List<CouponAccount> validCoupons = couponAccountRepository.findByCouponIdInAndDeleteFlag(couponIdList, DeleteFlag.NOT_DELETED.getCode())
.stream()
.filter(c -> c.getValidEndTime() != null && c.getValidEndTime().isAfter(now))
.toList();
long pendingCount = validCoupons.size();
respVO.setHasRedDot(pendingCount > 0);
respVO.setPendingCount(pendingCount);
return respVO; return respVO;
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!