fix:修复凭证打印机bug

This commit is contained in:
石崇礼 2025-03-18 19:21:33 +08:00
parent f029719a42
commit d3e775b720
2 changed files with 6 additions and 16 deletions

View File

@ -1,7 +1,6 @@
package com.dpkj.modules.print.service.impl; package com.dpkj.modules.print.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dpkj.common.constant.ErrorCodeConstants;
import com.dpkj.common.dto.LexMarkDTO; import com.dpkj.common.dto.LexMarkDTO;
import com.dpkj.common.dto.LexMarkResultDTO; import com.dpkj.common.dto.LexMarkResultDTO;
import com.dpkj.common.exception.RRException; import com.dpkj.common.exception.RRException;
@ -33,8 +32,6 @@ public class MS439PrintServiceImpl implements MS439PrintService {
@Override @Override
public LexMarkResultDTO<?> printImage(MS439Request request) { public LexMarkResultDTO<?> printImage(MS439Request request) {
LexMarkResultDTO<PrinterStatus> status = this.getStatus(request.getPagesource()); LexMarkResultDTO<PrinterStatus> status = this.getStatus(request.getPagesource());
thirdService.open("HtmPrinter", 0);
PrinterStatus ms439 = status.getData(); PrinterStatus ms439 = status.getData();
// 如果是要盖章校验盖章机器是否正常 // 如果是要盖章校验盖章机器是否正常
@ -55,7 +52,6 @@ public class MS439PrintServiceImpl implements MS439PrintService {
} }
} }
LexMarkDTO lexMarkDTO = new LexMarkDTO(); LexMarkDTO lexMarkDTO = new LexMarkDTO();
lexMarkDTO.setActionName("PrintText"); lexMarkDTO.setActionName("PrintText");
lexMarkDTO.setCallID(19283); lexMarkDTO.setCallID(19283);
@ -88,8 +84,6 @@ public class MS439PrintServiceImpl implements MS439PrintService {
@Override @Override
public LexMarkResultDTO<PrinterStatus> getStatus(String papersource) { public LexMarkResultDTO<PrinterStatus> getStatus(String papersource) {
thirdService.open("HtmPrinter", 0);
LexMarkDTO lexMarkDTO = new LexMarkDTO(); LexMarkDTO lexMarkDTO = new LexMarkDTO();
lexMarkDTO.setActionName("GetStatus"); lexMarkDTO.setActionName("GetStatus");
lexMarkDTO.setCallID(19283); lexMarkDTO.setCallID(19283);
@ -98,7 +92,8 @@ public class MS439PrintServiceImpl implements MS439PrintService {
LexMarkResultDTO<PrinterStatus> status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class); LexMarkResultDTO<PrinterStatus> status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
if ( status.getResult() != 0){ if ( status.getResult() != 0){
throw new RRException(ErrorCodeConstants.MS439_PRINT_ERROR_CODE.get(status.getResult())); thirdService.open("HtmPrinter", 0);
status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
} }
String stPaperEx = status.getData().getStPaperEx(); String stPaperEx = status.getData().getStPaperEx();
@ -144,7 +139,6 @@ public class MS439PrintServiceImpl implements MS439PrintService {
throw new RRException(500, ms439.getStInk()); throw new RRException(500, ms439.getStInk());
} }
thirdService.close("HtmPrinter");
return status; return status;
} }

View File

@ -2,7 +2,6 @@ package com.dpkj.modules.print.service.impl;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.dpkj.common.constant.ErrorCodeConstants;
import com.dpkj.common.dto.LexMarkDTO; import com.dpkj.common.dto.LexMarkDTO;
import com.dpkj.common.dto.LexMarkResultDTO; import com.dpkj.common.dto.LexMarkResultDTO;
import com.dpkj.common.exception.RRException; import com.dpkj.common.exception.RRException;
@ -34,8 +33,7 @@ public class RegisterServiceImpl implements PrintService {
@Override @Override
public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) { public LexMarkResultDTO<LexMarkResultDTO.Param> printImage(JSONObject data, String template, int width, int height, String saveDir) {
thirdService.open("ReceiptPrinter", 1); this.getStatus();
StringBuilder filePath = new StringBuilder(saveDir); StringBuilder filePath = new StringBuilder(saveDir);
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了 // 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
if ( !StringUtils.isEmpty(template) && !StringUtils.isEmpty(saveDir)){ if ( !StringUtils.isEmpty(template) && !StringUtils.isEmpty(saveDir)){
@ -61,7 +59,7 @@ public class RegisterServiceImpl implements PrintService {
lexMarkDTO.setParam(param.toJSONString()); lexMarkDTO.setParam(param.toJSONString());
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class); LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
// 切纸 // 切纸
this.thirdService.cutPaper("ReceiptPrinter", "ControlMedia", 4); // this.thirdService.cutPaper("ReceiptPrinter", "ControlMedia", 4);
File file = new File(filePath.toString()); File file = new File(filePath.toString());
// 检查文件是否存在 // 检查文件是否存在
@ -82,8 +80,6 @@ public class RegisterServiceImpl implements PrintService {
@Override @Override
public LexMarkResultDTO<PrinterStatus> getStatus() { public LexMarkResultDTO<PrinterStatus> getStatus() {
thirdService.open("ReceiptPrinter", 1);
LexMarkDTO lexMarkDTO = new LexMarkDTO(); LexMarkDTO lexMarkDTO = new LexMarkDTO();
lexMarkDTO.setActionName("GetStatus"); lexMarkDTO.setActionName("GetStatus");
lexMarkDTO.setCallID(11225); lexMarkDTO.setCallID(11225);
@ -92,7 +88,8 @@ public class RegisterServiceImpl implements PrintService {
// lexMarkDTO.setMethodType(0); // lexMarkDTO.setMethodType(0);
LexMarkResultDTO<PrinterStatus> status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class); LexMarkResultDTO<PrinterStatus> status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
if ( status.getResult() != 0){ if ( status.getResult() != 0){
throw new RRException(ErrorCodeConstants.MS439_PRINT_ERROR_CODE.get(status.getResult())); thirdService.open("ReceiptPrinter", 1);
status = thirdService.callDevice(lexMarkDTO, PrinterStatus.class);
} }
PrinterStatus ms439 = status.getData(); PrinterStatus ms439 = status.getData();
@ -131,7 +128,6 @@ public class RegisterServiceImpl implements PrintService {
throw new RRException(500, ms439.getStInk()); throw new RRException(500, ms439.getStInk());
} }
this.thirdService.close("ReceiptPrinter");
return status; return status;
} }