Commit d1570b53 by 章家宝

feat:代码优化

1 parent 2e94c9b5
......@@ -46,10 +46,10 @@ public class CouponAccountController {
@Operation(summary = "获取我的优惠券列表", description = "查询当前登录用户的优惠券列表,支持按状态筛选")
@GetMapping("/list")
public BaseResp<List<CouponAccountRespVO>> getMyCoupons(
public BaseResp<List<CouponAccountRespVO>> list(
@Parameter(description = "状态 (1:待使用;2:已核销;3:已过期)", example = "1")
@RequestParam(name = "status", required = false) Integer status,
@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】获取我的优惠券列表,status={}", status);
try {
Integer accountId = account.getAccountId();
......@@ -69,7 +69,7 @@ public class CouponAccountController {
public BaseResp<CouponAccountRespVO> getCouponDetail(
@Parameter(description = "优惠券实例 ID", required = true)
@PathVariable("couponId") String couponId,
@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】获取优惠券详情,couponId={}", couponId);
try {
CouponAccountRespVO result = couponAccountService.getCouponDetail(couponId);
......@@ -85,7 +85,7 @@ public class CouponAccountController {
@Operation(summary = "获取待展示弹窗", description = "查询当前用户有待展示的优惠券弹窗(用于首页弹窗)")
@GetMapping("/popup")
public BaseResp<CouponPopupRespVO> getPendingPopup(@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
public BaseResp<CouponPopupRespVO> getPendingPopup(@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】获取待展示弹窗");
try {
Integer accountId = account.getAccountId();
......@@ -102,7 +102,7 @@ public class CouponAccountController {
@Operation(summary = "统计各状态优惠券数量", description = "统计用户待使用、已核销、已过期优惠券数量")
@GetMapping("/count")
public BaseResp<CouponCountRespVO> countCoupons(@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
public BaseResp<CouponCountRespVO> countCoupons(@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】统计各状态优惠券数量");
try {
Integer accountId = account.getAccountId();
......@@ -120,7 +120,7 @@ public class CouponAccountController {
@Operation(summary = "核销优惠券", description = "订单支付时使用优惠券进行核销")
@PostMapping("/verify")
public BaseResp<CouponVerifyRespVO> verifyCoupon(
@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account,
@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account,
@Valid @RequestBody CouponVerifyReqVO reqVO) {
log.info("【接口请求】核销优惠券,accountId={}, orderId={}, couponId={}",
account.getAccountId(), reqVO.getOrderId(), reqVO.getCouponId());
......@@ -157,7 +157,7 @@ public class CouponAccountController {
public BaseResp<List<OrderCouponRespVO>> getOrderCoupons(
@Parameter(description = "订单 ID", required = true, example = "123")
@PathVariable("orderId") Integer orderId,
@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】获取订单可用优惠券列表,orderId={}", orderId);
try {
Integer accountId = account.getAccountId();
......@@ -213,7 +213,7 @@ public class CouponAccountController {
@Operation(summary = "查询红点状态", description = "查询当前用户是否有待通知的优惠券弹窗(用于前端展示红点)")
@GetMapping("/red-dot")
public BaseResp<CouponRedDotRespVO> checkRedDotStatus(@RequestAttribute(value = LOGIN_ACCOUNT, required = false) Account account) {
public BaseResp<CouponRedDotRespVO> checkRedDotStatus(@RequestAttribute(value = LOGIN_ACCOUNT, required = true) Account account) {
log.info("【接口请求】查询红点状态");
try {
Integer accountId = account.getAccountId();
......
......@@ -1077,7 +1077,7 @@ public class CouponActivityService {
try {
for (int i = 0; i < quantity; i++) {
distributeCoupon(activity, template, accountId, mobile,
CouponDistributionTypeEnum.DIRECT_ACTIVITY.getCode(), opId, opName, now);
CouponDistributionTypeEnum.DIRECT_ACTIVITY.getCode(), opId, opName, now, activity.getSendNotification() == 1);
}
distributedAccountIds.add(accountId);
} catch (Exception e) {
......@@ -1228,7 +1228,7 @@ public class CouponActivityService {
try {
for (int i = 0; i < activity.getDistributionQuantity(); i++) {
distributeCoupon(activity, template, target.getAccountId(), target.getAccountMobile(),
CouponDistributionTypeEnum.DIRECT_ACTIVITY.getCode(), 0, "系统定时任务", now);
CouponDistributionTypeEnum.DIRECT_ACTIVITY.getCode(), 0, "系统定时任务", now, activity.getSendNotification() == 1);
}
// 更新发放状态
target.setIsDistributed(1);
......@@ -1251,7 +1251,7 @@ public class CouponActivityService {
@Transactional(rollbackFor = Exception.class)
public void distributeCoupon(CouponActivity activity, CouponTemplate template,
Integer accountId, String mobile, Integer distributionType,
Integer opId, String opName, LocalDateTime now) {
Integer opId, String opName, LocalDateTime now, boolean sendNotification) {
// 计算有效期
LocalDateTime validStartTime = now;
......@@ -1327,14 +1327,17 @@ public class CouponActivityService {
distributionRecordRepository.save(record);
// 保存活动发放弹窗通知记录
couponPopupNotificationService.saveNotification(
accountId,
CouponPopupTypeEnum.ACTIVITY_DISTRIBUTION.getCode(),
CouponNotificationSourceTypeEnum.ACTIVITY.getCode(),
activity != null ? activity.getActivityId() : record.getRecordId(),
couponId,
now,
opName);
if (sendNotification) {
couponPopupNotificationService.saveNotification(
accountId,
CouponPopupTypeEnum.ACTIVITY_DISTRIBUTION.getCode(),
CouponNotificationSourceTypeEnum.ACTIVITY.getCode(),
activity != null ? activity.getActivityId() : record.getRecordId(),
couponId,
now,
opName);
}
log.info("优惠券发放成功:accountId={}, couponId={}, templateId={}", accountId, couponId, template.getId());
} catch (Exception e) {
......@@ -1664,7 +1667,8 @@ public class CouponActivityService {
CouponDistributionTypeEnum.AUTO_TRIGGER.getCode(),
null,
"系统自动发放",
now
now,
activity.getSendNotification() == 1
);
log.info("自动发放优惠券成功:accountId={}, activityId={}, templateId={}, transactionPrice={}",
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!