Commit e8142515 by 章家宝

feat:【优惠券需求】小程序优惠券获取或者获取弹窗通知,将所有的弹窗置为已读

1 parent e3aa5617
...@@ -91,26 +91,6 @@ public class CouponAccountController { ...@@ -91,26 +91,6 @@ public class CouponAccountController {
} }
} }
@Operation(summary = "确认弹窗已读", description = "用户点击弹窗后,标记为已确认")
@PostMapping("/popup/confirm")
public BaseResp<Void> confirmPopup(
@Parameter(description = "通知 ID", required = true)
@RequestParam("notificationId") String notificationId,
@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
log.info("【接口请求】确认弹窗已读,notificationId={}", notificationId);
try {
Integer accountId = account.getAccountId();
couponAccountService.confirmPopup(accountId, notificationId);
return BaseResp.success();
} catch (BusinessCodeException be) {
log.error("【接口响应】确认弹窗失败,notificationId={}", notificationId, be);
return BaseResp.fail(be.getCode().toString(), be.getMessage());
} catch (Exception e) {
log.error("【接口响应】确认弹窗异常,notificationId={}", notificationId, e);
return BaseResp.fail("系统异常:确认弹窗失败");
}
}
@Operation(summary = "统计各状态优惠券数量", description = "统计用户待使用、已核销、已过期优惠券数量") @Operation(summary = "统计各状态优惠券数量", description = "统计用户待使用、已核销、已过期优惠券数量")
@GetMapping("/count") @GetMapping("/count")
public BaseResp<CouponAccountRespVO.CouponCountVO> countCoupons(@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) { public BaseResp<CouponAccountRespVO.CouponCountVO> countCoupons(@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
......
...@@ -2,6 +2,7 @@ package com.glsx.usedcar.module.coupon.dao; ...@@ -2,6 +2,7 @@ package com.glsx.usedcar.module.coupon.dao;
import com.glsx.usedcar.module.coupon.entity.CouponPopupNotification; import com.glsx.usedcar.module.coupon.entity.CouponPopupNotification;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
...@@ -61,4 +62,25 @@ public interface CouponPopupNotificationRepository extends JpaRepository<CouponP ...@@ -61,4 +62,25 @@ public interface CouponPopupNotificationRepository extends JpaRepository<CouponP
* @return 弹窗通知列表 * @return 弹窗通知列表
*/ */
List<CouponPopupNotification> findBySourceTypeAndSourceIdAndDeleteFlag(String sourceType, String sourceId, String deleteFlag); List<CouponPopupNotification> findBySourceTypeAndSourceIdAndDeleteFlag(String sourceType, String sourceId, String deleteFlag);
/**
* 批量更新用户弹窗通知状态为已确认
*
* @param accountId 用户 ID
* @param oldStatus 原状态
* @param newStatus 新状态
* @param deleteFlag 删除标识
* @param confirmTime 确认时间
* @return 更新的记录数
*/
@Modifying
@Query("UPDATE CouponPopupNotification n SET n.status = :newStatus, n.confirmTime = :confirmTime " +
"WHERE n.accountId = :accountId AND n.status = :oldStatus AND n.deleteFlag = :deleteFlag")
int batchUpdateStatusByAccountId(
@Param("accountId") Integer accountId,
@Param("oldStatus") Integer oldStatus,
@Param("newStatus") Integer newStatus,
@Param("deleteFlag") String deleteFlag,
@Param("confirmTime") LocalDateTime confirmTime
);
} }
...@@ -37,7 +37,11 @@ public class CouponAccountService { ...@@ -37,7 +37,11 @@ public class CouponAccountService {
/** /**
* 获取我的优惠券列表 * 获取我的优惠券列表
*/ */
@Transactional(rollbackFor = Exception.class)
public List<CouponAccountRespVO> getMyCoupons(Integer accountId, Integer status) { public List<CouponAccountRespVO> getMyCoupons(Integer accountId, Integer status) {
// 将该用户下所有弹窗通知置为已读
markAllPopupsAsRead(accountId);
List<CouponAccount> coupons; List<CouponAccount> coupons;
if (status == null) { if (status == null) {
coupons = couponAccountRepository.findByAccountIdAndDeleteFlag(accountId, "N"); coupons = couponAccountRepository.findByAccountIdAndDeleteFlag(accountId, "N");
...@@ -62,6 +66,7 @@ public class CouponAccountService { ...@@ -62,6 +66,7 @@ public class CouponAccountService {
/** /**
* 获取待展示弹窗 * 获取待展示弹窗
*/ */
@Transactional(rollbackFor = Exception.class)
public CouponPopupRespVO getPendingPopup(Integer accountId) { public CouponPopupRespVO getPendingPopup(Integer accountId) {
LocalDateTime now = LocalDateTime.now(); LocalDateTime now = LocalDateTime.now();
...@@ -73,6 +78,9 @@ public class CouponAccountService { ...@@ -73,6 +78,9 @@ public class CouponAccountService {
return null; return null;
} }
// 将该用户下所有弹窗通知置为已读
markAllPopupsAsRead(accountId);
// 构建弹窗响应 // 构建弹窗响应
CouponPopupRespVO popupVO = new CouponPopupRespVO(); CouponPopupRespVO popupVO = new CouponPopupRespVO();
popupVO.setPopupType(determinePopupType(pendingCoupons)); popupVO.setPopupType(determinePopupType(pendingCoupons));
...@@ -84,6 +92,23 @@ public class CouponAccountService { ...@@ -84,6 +92,23 @@ public class CouponAccountService {
} }
/** /**
* 将用户所有弹窗通知置为已读
*
* @param accountId 用户 ID
*/
private void markAllPopupsAsRead(Integer accountId) {
LocalDateTime now = LocalDateTime.now();
// 批量更新状态为 0(待通知) 或 1(已展示) 的弹窗通知为 2(已确认)
int updatedCount = popupNotificationRepository.batchUpdateStatusByAccountId(
accountId, 0, 2, DeleteFlag.NOT_DELETED.getCode(), now);
updatedCount += popupNotificationRepository.batchUpdateStatusByAccountId(
accountId, 1, 2, DeleteFlag.NOT_DELETED.getCode(), now);
if (updatedCount > 0) {
log.info("批量标记弹窗已读成功:accountId={}, updatedCount={}", accountId, updatedCount);
}
}
/**
* 确认弹窗已读 * 确认弹窗已读
*/ */
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!