You've already forked FrameTour-BE
feat(printer):优化订单打印纸张尺寸获取逻辑
- 引入Redis缓存存储打印纸张尺寸信息 - 优先从Redis中获取纸张尺寸,减少数据库查询 - 在创建订单时将打印机偏好纸张存入Redis,有效期60秒 - 修复打印机对象作用域问题,避免空指针异常 - 统一打印机状态校验逻辑,提高代码可读性
This commit is contained in:
@@ -483,6 +483,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
|
||||
@Override
|
||||
public Map<String, Object> createOrder(Long memberId, Long scenicId, Integer printerId, Long faceId) {
|
||||
PrinterEntity printer = null;
|
||||
if (printerId == null) {
|
||||
List<PrinterResp> printerList = printerMapper.listByScenicId(scenicId);
|
||||
if (printerList.size() != 1) {
|
||||
@@ -491,16 +492,16 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
printerId = printerList.getFirst().getId();
|
||||
}
|
||||
} else {
|
||||
PrinterEntity printer = printerMapper.getById(printerId);
|
||||
if (printer == null) {
|
||||
throw new BaseException("打印机不存在");
|
||||
}
|
||||
if (printer.getStatus() != 1) {
|
||||
throw new BaseException("打印机已停用");
|
||||
}
|
||||
if (!printer.getScenicId().equals(scenicId)) {
|
||||
throw new BaseException("打印机不属于该景区");
|
||||
}
|
||||
printer = printerMapper.getById(printerId);
|
||||
}
|
||||
if (printer == null) {
|
||||
throw new BaseException("打印机不存在");
|
||||
}
|
||||
if (printer.getStatus() != 1) {
|
||||
throw new BaseException("打印机已停用");
|
||||
}
|
||||
if (!printer.getScenicId().equals(scenicId)) {
|
||||
throw new BaseException("打印机不属于该景区");
|
||||
}
|
||||
// 验证照片数量
|
||||
List<MemberPrintResp> userPhotoList = getUserPhotoList(memberId, scenicId, faceId);
|
||||
@@ -511,6 +512,7 @@ public class PrinterServiceImpl implements PrinterService {
|
||||
|
||||
OrderEntity order = new OrderEntity();
|
||||
Long orderId = SnowFlakeUtil.getLongId();
|
||||
redisTemplate.opsForValue().set("printer_size:"+orderId, printer.getPreferPaper(), 60, TimeUnit.SECONDS);
|
||||
order.setId(orderId);
|
||||
order.setMemberId(memberId);
|
||||
order.setFaceId(faceId);
|
||||
|
||||
Reference in New Issue
Block a user