You've already forked FrameTour-BE
feat(voucher): 增加查询已打印凭证和自动领券功能
- 新增 queryPrintedVoucher 方法查询已打印的凭证 - 新增 claimVoucher 方法实现自动领取凭证 - 优化 printVoucherTicket 方法,移除冗余参数 - 更新相关 mapper 和 XML 文件以支持新功能
This commit is contained in:
@@ -1,14 +1,23 @@
|
||||
package com.ycwl.basic.controller.mobile;
|
||||
|
||||
import com.ycwl.basic.constant.BaseContextHandler;
|
||||
import com.ycwl.basic.exception.BaseException;
|
||||
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherClaimReq;
|
||||
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherCodeResp;
|
||||
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
|
||||
import com.ycwl.basic.pricing.service.VoucherCodeService;
|
||||
import com.ycwl.basic.pricing.service.VoucherPrintService;
|
||||
import com.ycwl.basic.repository.FaceRepository;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
|
||||
@@ -19,7 +28,11 @@ public class AppVoucherController {
|
||||
|
||||
@Autowired
|
||||
private VoucherPrintService voucherPrintService;
|
||||
|
||||
@Autowired
|
||||
private VoucherCodeService voucherCodeService;
|
||||
@Autowired
|
||||
private FaceRepository faceRepository;
|
||||
|
||||
/**
|
||||
* 打印小票
|
||||
* @param request 打印请求
|
||||
@@ -37,4 +50,26 @@ public class AppVoucherController {
|
||||
|
||||
return ApiResponse.success(response);
|
||||
}
|
||||
|
||||
@GetMapping("/printed")
|
||||
public ApiResponse<VoucherPrintResp> queryPrintedVoucher(
|
||||
@RequestParam Long faceId
|
||||
) {
|
||||
return ApiResponse.success(voucherPrintService.queryPrintedVoucher(faceId));
|
||||
}
|
||||
|
||||
@PostMapping("/claim")
|
||||
public ApiResponse<VoucherCodeResp> claimVoucher(@RequestBody VoucherClaimReq req) {
|
||||
FaceEntity face = faceRepository.getFace(req.getFaceId());
|
||||
if (face == null) {
|
||||
throw new BaseException("请选择人脸");
|
||||
}
|
||||
if (!face.getMemberId().equals(Long.valueOf(BaseContextHandler.getUserId()))) {
|
||||
throw new BaseException("自动领取失败");
|
||||
}
|
||||
req.setScenicId(face.getScenicId());
|
||||
VoucherCodeResp result = voucherCodeService.claimVoucher(req);
|
||||
return ApiResponse.success(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -14,12 +14,10 @@ public interface VoucherPrintRecordMapper extends BaseMapper<VoucherPrintRecord>
|
||||
/**
|
||||
* 根据faceId、brokerId、scenicId查询已存在的打印记录
|
||||
* @param faceId 用户faceId
|
||||
* @param brokerId 经纪人ID
|
||||
* @param scenicId 景区ID
|
||||
* @return 打印记录
|
||||
*/
|
||||
VoucherPrintRecord selectByFaceBrokerScenic(@Param("faceId") Long faceId,
|
||||
@Param("brokerId") Long brokerId,
|
||||
VoucherPrintRecord selectByFaceBrokerScenic(@Param("faceId") Long faceId,
|
||||
@Param("scenicId") Long scenicId);
|
||||
|
||||
/**
|
||||
|
@@ -14,4 +14,6 @@ public interface VoucherPrintService {
|
||||
* @return 打印响应
|
||||
*/
|
||||
VoucherPrintResp printVoucherTicket(VoucherPrintReq request);
|
||||
|
||||
VoucherPrintResp queryPrintedVoucher(Long faceId);
|
||||
}
|
@@ -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是否属于当前用户
|
||||
*/
|
||||
|
Reference in New Issue
Block a user