feat(voucher): 增加查询已打印凭证和自动领券功能

- 新增 queryPrintedVoucher 方法查询已打印的凭证
- 新增 claimVoucher 方法实现自动领取凭证
- 优化 printVoucherTicket 方法,移除冗余参数
- 更新相关 mapper 和 XML 文件以支持新功能
This commit is contained in:
2025-08-25 09:36:40 +08:00
parent ea9945b9e0
commit 6b20e700f0
5 changed files with 63 additions and 9 deletions

View File

@@ -14,4 +14,6 @@ public interface VoucherPrintService {
* @return 打印响应
*/
VoucherPrintResp printVoucherTicket(VoucherPrintReq request);
VoucherPrintResp queryPrintedVoucher(Long faceId);
}

View File

@@ -1,6 +1,5 @@
package com.ycwl.basic.pricing.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ycwl.basic.constant.BaseContextHandler;
import com.ycwl.basic.exception.BaseException;
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
@@ -77,13 +76,13 @@ public class VoucherPrintServiceImpl implements VoucherPrintService {
try {
// 尝试获取锁,超时时间30秒
Boolean lockAcquired = redisTemplate.opsForValue().setIfAbsent(lockKey, lockValue, 30, TimeUnit.SECONDS);
if (!lockAcquired) {
if (Boolean.FALSE.equals(lockAcquired)) {
throw new BaseException("请求处理中,请稍后再试");
}
// 检查是否已存在相同的打印记录
VoucherPrintRecord existingRecord = voucherPrintRecordMapper.selectByFaceBrokerScenic(
request.getFaceId(), request.getBrokerId(), request.getScenicId());
request.getFaceId(), request.getScenicId());
if (existingRecord != null) {
log.info("找到已存在的打印记录,返回该记录: {}", existingRecord.getId());
@@ -131,7 +130,28 @@ public class VoucherPrintServiceImpl implements VoucherPrintService {
}
}
}
@Override
public VoucherPrintResp queryPrintedVoucher(Long faceId) {
FaceEntity face = faceRepository.getFace(faceId);
if (face == null) {
throw new BaseException("请上传人脸");
}
Long currentUserId = Long.valueOf(BaseContextHandler.getUserId());
// 验证faceId是否属于当前用户
validateFaceOwnership(faceId, currentUserId);
// 检查是否已存在相同的打印记录
VoucherPrintRecord existingRecord = voucherPrintRecordMapper.selectByFaceBrokerScenic(
faceId, face.getScenicId());
if (existingRecord == null) {
return null;
}
return buildResponse(existingRecord);
}
/**
* 验证faceId是否属于当前用户
*/