You've already forked FrameTour-BE
refactor(voucher): 重构凭证相关服务
- 移除VoucherClaimReq 中的 brokerId 字段 - 更新 VoucherCodeServiceImpl 中的逻辑,移除与推客相关的验证 - 在 VoucherPrintServiceImpl 中添加打印小票功能的实现 - 新增与微信小程序相关的配置和功能
This commit is contained in:
@@ -5,7 +5,6 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class VoucherClaimReq {
|
public class VoucherClaimReq {
|
||||||
private Long scenicId;
|
private Long scenicId;
|
||||||
private Long brokerId;
|
|
||||||
private Long faceId;
|
private Long faceId;
|
||||||
private String code;
|
private String code;
|
||||||
}
|
}
|
@@ -74,9 +74,6 @@ public class VoucherCodeServiceImpl implements VoucherCodeService {
|
|||||||
if (req.getScenicId() == null) {
|
if (req.getScenicId() == null) {
|
||||||
throw new BizException(400, "景区ID不能为空");
|
throw new BizException(400, "景区ID不能为空");
|
||||||
}
|
}
|
||||||
if (req.getBrokerId() == null) {
|
|
||||||
throw new BizException(400, "推客ID不能为空");
|
|
||||||
}
|
|
||||||
if (req.getFaceId() == null) {
|
if (req.getFaceId() == null) {
|
||||||
throw new BizException(400, "用户faceId不能为空");
|
throw new BizException(400, "用户faceId不能为空");
|
||||||
}
|
}
|
||||||
@@ -109,11 +106,6 @@ public class VoucherCodeServiceImpl implements VoucherCodeService {
|
|||||||
throw new BizException(400, "券码批次不存在");
|
throw new BizException(400, "券码批次不存在");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 验证批次是否可用于该推客
|
|
||||||
if (!Objects.equals(batch.getBrokerId(), req.getBrokerId())) {
|
|
||||||
throw new BizException(400, "券码不属于该推客");
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新券码状态
|
// 更新券码状态
|
||||||
voucherCode.setFaceId(req.getFaceId());
|
voucherCode.setFaceId(req.getFaceId());
|
||||||
voucherCode.setStatus(VoucherCodeStatus.CLAIMED_UNUSED.getCode());
|
voucherCode.setStatus(VoucherCodeStatus.CLAIMED_UNUSED.getCode());
|
||||||
|
@@ -3,6 +3,7 @@ package com.ycwl.basic.pricing.service.impl;
|
|||||||
import com.ycwl.basic.constant.BaseContextHandler;
|
import com.ycwl.basic.constant.BaseContextHandler;
|
||||||
import com.ycwl.basic.exception.BaseException;
|
import com.ycwl.basic.exception.BaseException;
|
||||||
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
import com.ycwl.basic.model.pc.face.entity.FaceEntity;
|
||||||
|
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||||
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
|
import com.ycwl.basic.pricing.dto.req.VoucherPrintReq;
|
||||||
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
|
import com.ycwl.basic.pricing.dto.resp.VoucherPrintResp;
|
||||||
import com.ycwl.basic.pricing.entity.PriceVoucherCode;
|
import com.ycwl.basic.pricing.entity.PriceVoucherCode;
|
||||||
@@ -10,7 +11,10 @@ import com.ycwl.basic.pricing.entity.VoucherPrintRecord;
|
|||||||
import com.ycwl.basic.pricing.mapper.PriceVoucherCodeMapper;
|
import com.ycwl.basic.pricing.mapper.PriceVoucherCodeMapper;
|
||||||
import com.ycwl.basic.pricing.mapper.VoucherPrintRecordMapper;
|
import com.ycwl.basic.pricing.mapper.VoucherPrintRecordMapper;
|
||||||
import com.ycwl.basic.pricing.service.VoucherPrintService;
|
import com.ycwl.basic.pricing.service.VoucherPrintService;
|
||||||
|
import com.ycwl.basic.printer.ticket.FeiETicketPrinter;
|
||||||
import com.ycwl.basic.repository.FaceRepository;
|
import com.ycwl.basic.repository.FaceRepository;
|
||||||
|
import com.ycwl.basic.repository.ScenicRepository;
|
||||||
|
import com.ycwl.basic.utils.WxMpUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -47,6 +51,8 @@ public class VoucherPrintServiceImpl implements VoucherPrintService {
|
|||||||
|
|
||||||
// 原子计数器,确保流水号唯一性
|
// 原子计数器,确保流水号唯一性
|
||||||
private static final AtomicLong counter = new AtomicLong(0);
|
private static final AtomicLong counter = new AtomicLong(0);
|
||||||
|
@Autowired
|
||||||
|
private ScenicRepository scenicRepository;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
@@ -113,14 +119,18 @@ public class VoucherPrintServiceImpl implements VoucherPrintService {
|
|||||||
|
|
||||||
voucherPrintRecordMapper.insert(printRecord);
|
voucherPrintRecordMapper.insert(printRecord);
|
||||||
|
|
||||||
// TODO: 调用打印机接口打印小票
|
try {
|
||||||
// printTicket(printRecord);
|
printTicket(printRecord);
|
||||||
|
|
||||||
// 暂时标记为打印成功状态(实际应该在打印成功回调中更新)
|
|
||||||
printRecord.setPrintStatus(1);
|
printRecord.setPrintStatus(1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("打印失败");
|
||||||
|
printRecord.setPrintStatus(2);
|
||||||
|
}
|
||||||
|
|
||||||
voucherPrintRecordMapper.updatePrintStatus(printRecord.getId(), 1, null);
|
voucherPrintRecordMapper.updatePrintStatus(printRecord.getId(), 1, null);
|
||||||
|
|
||||||
log.info("成功创建打印记录: {}, 券码: {}", code, availableVoucher.getCode());
|
log.info("成功创建打印记录: {}, 券码: {}", code, availableVoucher.getCode());
|
||||||
|
printRecord.setCode(printRecord.getVoucherCode());
|
||||||
return buildResponse(printRecord);
|
return buildResponse(printRecord);
|
||||||
|
|
||||||
} finally {
|
} finally {
|
||||||
@@ -198,8 +208,32 @@ public class VoucherPrintServiceImpl implements VoucherPrintService {
|
|||||||
/**
|
/**
|
||||||
* 调用打印机接口(待实现)
|
* 调用打印机接口(待实现)
|
||||||
*/
|
*/
|
||||||
private void printTicket(VoucherPrintRecord record) {
|
private void printTicket(VoucherPrintRecord record) throws Exception {
|
||||||
// TODO: 实现打印机接口调用逻辑
|
FaceEntity face = faceRepository.getFace(record.getFaceId());
|
||||||
log.info("TODO: 调用打印机打印小票,记录ID: {}, 券码: {}", record.getId(), record.getVoucherCode());
|
MpConfigEntity scenicMpConfig = scenicRepository.getScenicMpConfig(face.getScenicId());
|
||||||
|
String urlLink = WxMpUtil.generateUrlLink(scenicMpConfig.getAppId(), scenicMpConfig.getAppSecret(), "pages/videoSynthesis/index", "code=" + record.getVoucherCode() + "&faceId=" + face.getId());
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日");
|
||||||
|
SimpleDateFormat sdf2 = new SimpleDateFormat("MM月dd日");
|
||||||
|
log.info(" 调用打印机打印小票,记录ID: {}, 券码: {}", record.getId(), record.getVoucherCode());
|
||||||
|
String content;
|
||||||
|
content = "<BR><B>世界再大</B><BR>";
|
||||||
|
content += "<B>你永远是这段旅途</B><BR>";
|
||||||
|
content += "<B>的焦点</B><BR>";
|
||||||
|
content += "━━━━━━━━━━━━━━━━<BR>";
|
||||||
|
content += "正片主演:旅途中最靓的你<BR>";
|
||||||
|
content += "拍摄地点:剑门关滑道<BR>";
|
||||||
|
content += "拍摄日期:";
|
||||||
|
content += sdf.format(new Date());
|
||||||
|
content += "<BR>";
|
||||||
|
content += "大片内容:包含Vlog、打卡录像与<BR>";
|
||||||
|
content += " 精选照片<BR><BR>";
|
||||||
|
content += "<QR>"+urlLink+"</QR>";
|
||||||
|
content += "<CB>游后微信扫码领取</CB>";
|
||||||
|
content += "<C>精彩指数:★★★★★</C><BR>";
|
||||||
|
content += "━━━━━━━━━━━━━━━━<BR>";
|
||||||
|
content += "<CB>"+record.getVoucherCode()+"</CB>";
|
||||||
|
content += "<C>赠品码</C>";
|
||||||
|
content += "<C>有效期:"+sdf2.format(new Date())+"</C>";
|
||||||
|
FeiETicketPrinter.doPrint("550519002", content, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user