fix:优化打印机逻辑
This commit is contained in:
parent
3f0d3e5026
commit
46810f941d
|
@ -16,6 +16,8 @@ import java.io.InputStreamReader;
|
||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,10 +36,17 @@ public class ThirdService {
|
||||||
@Value("${app.custom.lexMarkServicePort}")
|
@Value("${app.custom.lexMarkServicePort}")
|
||||||
private String lexMarkServicePort;
|
private String lexMarkServicePort;
|
||||||
|
|
||||||
|
private static final Map<String, String> devNameMap = new HashMap<>();
|
||||||
|
static {
|
||||||
|
devNameMap.put("HtmPrinter", "激光打印机");
|
||||||
|
devNameMap.put("ReceiptPrinter", "凭条打印机");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 利盟台式机-立体机 接口请求
|
* 利盟台式机-立体机 接口请求
|
||||||
*
|
*
|
||||||
* @param lexMarkDTO 请求DTO
|
* @param lexMarkDTO 请求DTO
|
||||||
|
* @param clazz 返回类型
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
public <T> LexMarkResultDTO<T> callDevice(LexMarkDTO lexMarkDTO, Class<T> clazz) {
|
public <T> LexMarkResultDTO<T> callDevice(LexMarkDTO lexMarkDTO, Class<T> clazz) {
|
||||||
|
@ -110,5 +119,87 @@ public class ThirdService {
|
||||||
return callDevice(lexMarkDTO, JSONObject.class);
|
return callDevice(lexMarkDTO, JSONObject.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 打开设备连接或者 链接+初始化
|
||||||
|
* @param devName 设备名称
|
||||||
|
* @param resterType 初始化类型,如果不设置,那么就不会进行初始化
|
||||||
|
*/
|
||||||
|
public void open(String devName, Integer resterType) {
|
||||||
|
// 优先自动连接对应的设备
|
||||||
|
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||||
|
lexMarkDTO.setActionName("OpenConnection");
|
||||||
|
lexMarkDTO.setCallID(19283);
|
||||||
|
lexMarkDTO.setDevName(devName);
|
||||||
|
lexMarkDTO.setPluginMethod("exec");
|
||||||
|
JSONObject param = new JSONObject();
|
||||||
|
param.put("", String.format("{\"ServiceName\":\"%s\",\"TimeOut\":90000}", devName));
|
||||||
|
lexMarkDTO.setParam(param.toString());
|
||||||
|
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||||
|
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||||
|
if (data != null) {
|
||||||
|
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||||
|
throw new RRException("设备: " + devNameMap.get(devName) + " 打开失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 打开后直接进行重置
|
||||||
|
if ( resterType != null && data != null) {
|
||||||
|
lexMarkDTO.setActionName("Reset");
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("", String.format("{\"ResetAction\":%d,\"binNumber\":0}", resterType));
|
||||||
|
lexMarkDTO.setParam(jsonObject.toString());
|
||||||
|
LexMarkResultDTO<JSONObject> resultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||||
|
JSONObject data1 = resultDTO.getData();
|
||||||
|
if (data1 != null) {
|
||||||
|
if (!String.valueOf(data1.get("result")).equals("0")) {
|
||||||
|
throw new RRException("设备: " + devNameMap.get(devName) + " _ " + resterType + " 初始化失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关闭设备练级
|
||||||
|
* @param devName 设备名称
|
||||||
|
*/
|
||||||
|
public void close(String devName) {
|
||||||
|
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||||
|
lexMarkDTO.setActionName("CloseConnection");
|
||||||
|
lexMarkDTO.setCallID(19283);
|
||||||
|
lexMarkDTO.setDevName(devName);
|
||||||
|
lexMarkDTO.setPluginMethod("exec");
|
||||||
|
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||||
|
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||||
|
if (data != null) {
|
||||||
|
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||||
|
throw new RRException("设备: " + devNameMap.get(devName) + " 关闭失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 切纸,但是目前凭条和ms439打印机都是可以自动切纸的
|
||||||
|
* @param devName 设备名称
|
||||||
|
* @param actionName action名称,实际的动作函数名称
|
||||||
|
* @param mediaType 媒介类型
|
||||||
|
*/
|
||||||
|
public void cutPaper(String devName, String actionName, Integer mediaType){
|
||||||
|
LexMarkDTO lexMarkDTO = new LexMarkDTO();
|
||||||
|
lexMarkDTO.setActionName(actionName);
|
||||||
|
lexMarkDTO.setCallID(19283);
|
||||||
|
lexMarkDTO.setDevName(devName);
|
||||||
|
lexMarkDTO.setPluginMethod("exec");
|
||||||
|
JSONObject param = new JSONObject();
|
||||||
|
param.put("", String.format("{\"mediaCtrol\":%d}", mediaType));
|
||||||
|
lexMarkDTO.setParam(param.toString());
|
||||||
|
|
||||||
|
LexMarkResultDTO<JSONObject> jsonObjectLexMarkResultDTO = this.callDevice(lexMarkDTO, JSONObject.class);
|
||||||
|
JSONObject data = jsonObjectLexMarkResultDTO.getData();
|
||||||
|
if (data != null) {
|
||||||
|
if (!String.valueOf(data.get("result")).equals("0")) {
|
||||||
|
throw new RRException("设备: " + devNameMap.get(devName) + " 切纸失败!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,8 @@ public class MS439Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/getStatus")
|
@PostMapping("/getStatus")
|
||||||
public Result<String> print(){
|
public Result<String> print(@RequestParam(defaultValue = "A4") String papersource){
|
||||||
this.ms439PrintService.getStatus();
|
this.ms439PrintService.getStatus(papersource);
|
||||||
return Result.ok();
|
return Result.ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,10 @@ package com.dpkj.modules.print.controller;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.dpkj.common.dto.LexMarkResultDTO;
|
import com.dpkj.common.dto.LexMarkResultDTO;
|
||||||
import com.dpkj.common.vo.Result;
|
import com.dpkj.common.vo.Result;
|
||||||
|
import com.dpkj.modules.print.request.ReceiptPrintRequest;
|
||||||
import com.dpkj.modules.print.service.PrintService;
|
import com.dpkj.modules.print.service.PrintService;
|
||||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||||
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
@ -36,9 +38,11 @@ public class RegisterController {
|
||||||
/**
|
/**
|
||||||
* 挂号,通过文件路径
|
* 挂号,通过文件路径
|
||||||
*/
|
*/
|
||||||
@PostMapping("/register")
|
@PostMapping("/print")
|
||||||
public Result<LexMarkResultDTO> registerByFilePath(@RequestParam(defaultValue = "D:\\images") String filePath){
|
public Result<LexMarkResultDTO> registerByFilePath(@RequestBody @Validated ReceiptPrintRequest request){
|
||||||
return Result.ok((LexMarkResultDTO)printService.printImage(null, null, 0, 0, filePath));
|
String testData = "{\"hospitalName\":\"澜沧县中医医院\",\"registeTerminalName\":\"中国农业银行自助终端\",\"registeType\":\"自助挂号\",\"name\":\"刘博雅\",\"gender\":\"男\",\"age\":28,\"birthDate\":\"1996-06-31\",\"cardNumber\":\"6221**********0731\",\"outpatientNumber\":\"2501150038\",\"department\":\"普外科门诊\",\"visitLevel\":\"普通号\",\"doctor\":\"普通门诊\",\"sequence\":\"1\",\"registerDate\":\"2025-01-15\",\"totalFee\":4.00,\"paymentMethod\":\"微信扫码支付\",\"orderNumber\":\"\",\"transactionNumber\":\"2025011513090412092794szztzzj\",\"qrCodeBase64_2base64Type_1_250_250\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
||||||
|
// String testData = "{\"hospitalName\":\"澜沧县中医医院\",\"registeTerminalName\":\"中国农业银行自助终端\",\"registeType\":\"自助挂号\",\"name\":\"刘博雅\",\"gender\":\"男\",\"age\":28,\"birthDate\":\"1996-06-31\",\"cardNumber\":\"6221**********0731\",\"outpatientNumber\":\"2501150038\",\"department\":\"普外科门诊\",\"visitLevel\":\"普通号\",\"doctor\":\"普通门诊\",\"sequence\":\"1\",\"registerDate\":\"2025-01-15\",\"totalFee\":4.00,\"paymentMethod\":\"微信扫码支付\",\"orderNumber\":\"\",\"transactionNumber\":\"2025011513090412092794szztzzj\",\"qrCodeBase64_2base64Type_2_500_160\":\"maby this is a Base64 code data if has\",\"terminalNumber\":\"12092794\",\"printTime\":\"2025-01-15 13:10:08\"}";
|
||||||
|
return Result.ok((LexMarkResultDTO)printService.printImage(JSONObject.parseObject(testData), request.getTemplateName(), request.getWidth(), request.getHeight(), request.getFileDir()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -5,6 +5,8 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.ToString;
|
import lombok.ToString;
|
||||||
|
|
||||||
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
@ -28,6 +30,7 @@ public class MS439Request implements Serializable {
|
||||||
/**
|
/**
|
||||||
* 份数,默认1
|
* 份数,默认1
|
||||||
*/
|
*/
|
||||||
|
@Min(value = 1, message = "份数最少要为一份")
|
||||||
private Integer copies = 1;
|
private Integer copies = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -9,5 +9,5 @@ public interface MS439PrintService {
|
||||||
|
|
||||||
LexMarkResultDTO<?> printImage(MS439Request request);
|
LexMarkResultDTO<?> printImage(MS439Request request);
|
||||||
|
|
||||||
LexMarkResultDTO<PrinterStatus> getStatus();
|
LexMarkResultDTO<PrinterStatus> getStatus(String papersource);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 利盟MS439打印机服务
|
* 利盟MS439打印机服务
|
||||||
|
@ -31,29 +32,10 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LexMarkResultDTO<?> printImage(MS439Request request) {
|
public LexMarkResultDTO<?> printImage(MS439Request request) {
|
||||||
LexMarkResultDTO<PrinterStatus> status = this.getStatus();
|
LexMarkResultDTO<PrinterStatus> status = this.getStatus(request.getPagesource());
|
||||||
|
thirdService.open("HtmPrinter", 0);
|
||||||
|
|
||||||
PrinterStatus ms439 = status.getData();
|
PrinterStatus ms439 = status.getData();
|
||||||
String stPaperEx = ms439.getStPaperEx();
|
|
||||||
if (stPaperEx == null || stPaperEx.equals("")) {
|
|
||||||
throw new RRException("获取打印机纸张状态出问题");
|
|
||||||
}
|
|
||||||
String[] papers = stPaperEx.split("\\|");
|
|
||||||
if ( papers.length < 2) {
|
|
||||||
throw new RRException("打印机纸盒数量不对");
|
|
||||||
}
|
|
||||||
String paperStatus = "";
|
|
||||||
// 如果是A4,当前是取第一层纸盒作为A4
|
|
||||||
if (request.getPagesource().equals("A4")) {
|
|
||||||
paperStatus = papers[0];
|
|
||||||
}
|
|
||||||
// 如果是A5,当前是取第二层纸盒只作为A5
|
|
||||||
if (request.getPagesource().equals("A5")) {
|
|
||||||
paperStatus = papers[1];
|
|
||||||
}
|
|
||||||
if ( !(paperStatus.equals(MS439PaperStatusEnum.PAPERFULL.getPrintCode()) || !paperStatus.equals(MS439PaperStatusEnum.PAPERLOW.getPrintCode()))){
|
|
||||||
throw new RRException(MS439PaperStatusEnum.getPCode(paperStatus), MS439PaperStatusEnum.getMessage(paperStatus));
|
|
||||||
}
|
|
||||||
|
|
||||||
// 如果是要盖章,校验盖章机器是否正常
|
// 如果是要盖章,校验盖章机器是否正常
|
||||||
if ( request.getStamp() == 1) {
|
if ( request.getStamp() == 1) {
|
||||||
|
@ -61,7 +43,7 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
if (deviceExStatus == null || deviceExStatus.equals("")) {
|
if (deviceExStatus == null || deviceExStatus.equals("")) {
|
||||||
throw new RRException("获取打印机设备状态出问题");
|
throw new RRException("获取打印机设备状态出问题");
|
||||||
}
|
}
|
||||||
String[] devices = stPaperEx.split("\\|");
|
String[] devices = deviceExStatus.split("\\|");
|
||||||
if (devices.length < 2) {
|
if (devices.length < 2) {
|
||||||
throw new RRException("打印机默认设备数量不对");
|
throw new RRException("打印机默认设备数量不对");
|
||||||
}
|
}
|
||||||
|
@ -81,15 +63,34 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
lexMarkDTO.setPluginMethod("exec");
|
lexMarkDTO.setPluginMethod("exec");
|
||||||
|
|
||||||
JSONObject param = new JSONObject();
|
JSONObject param = new JSONObject();
|
||||||
param.put("prtData", String.format("pagesource=%s;copies=%d;file[0]=%s;stamp=%d;duplex=%d;color=%d;direction=%d",
|
|
||||||
request.getPagesource(), request.getCopies(), request.getFileDir(), request.getStamp(),
|
|
||||||
request.getDuplex(), request.getColor(), request.getDirection()));
|
// printType 选择箱子
|
||||||
|
// param.put("prtData", String.format("PrintType=%d;pagesource=%s;copies=%d;file[0]=%s;stamp=%d;duplex=%d;color=%d;direction=%d",
|
||||||
|
// request.getPagesource(), request.getCopies(), request.getFileDir(), request.getStamp(),
|
||||||
|
// request.getDuplex(), request.getColor(), request.getDirection()));
|
||||||
|
param.put("prtData", String.format("PaperNum=%d;PrintType=%d;Stamp=%d;File[0]=%s;WaitNum=%d;copies=%d;stamp=%d;duplex=%d;color=%d;direction=%d",
|
||||||
|
request.getCopies(), // 盖章事件分数,和打印份数一致
|
||||||
|
Objects.equals(request.getPagesource(), "A4") ? 1 : 2, // 打印类型1-A4或者2-A5
|
||||||
|
request.getStamp(), // 是否盖章
|
||||||
|
request.getFileDir(), // 要打印的文件的路径
|
||||||
|
request.getCopies(), // 盖章事件分数,和打印份数一致
|
||||||
|
request.getCopies(), // 实际要打印的份数
|
||||||
|
request.getStamp(), // 是否盖章 0-不盖章 1-盖章
|
||||||
|
request.getDuplex(), // 单面还是双面打印 1-单面 2-双面
|
||||||
|
request.getColor(), // 打印的颜色0-黑色,1-彩色
|
||||||
|
request.getDirection()));
|
||||||
|
|
||||||
lexMarkDTO.setParam(param.toString());
|
lexMarkDTO.setParam(param.toString());
|
||||||
return thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
||||||
|
thirdService.close("HtmPrinter");
|
||||||
|
return paramLexMarkResultDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LexMarkResultDTO<PrinterStatus> getStatus() {
|
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);
|
||||||
|
@ -101,6 +102,27 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
throw new RRException(ErrorCodeConstants.MS439_PRINT_ERROR_CODE.get(status.getResult()));
|
throw new RRException(ErrorCodeConstants.MS439_PRINT_ERROR_CODE.get(status.getResult()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String stPaperEx = status.getData().getStPaperEx();
|
||||||
|
if (stPaperEx == null || stPaperEx.equals("")) {
|
||||||
|
throw new RRException("获取打印机纸张状态出问题");
|
||||||
|
}
|
||||||
|
String[] papers = stPaperEx.split("\\|");
|
||||||
|
if ( papers.length < 2) {
|
||||||
|
throw new RRException("打印机纸盒数量不对");
|
||||||
|
}
|
||||||
|
String paperStatus = "";
|
||||||
|
// 如果是A4,当前是取第一层纸盒作为A4
|
||||||
|
if (papersource.equals("A4")) {
|
||||||
|
paperStatus = papers[0];
|
||||||
|
}
|
||||||
|
// 如果是A5,当前是取第二层纸盒只作为A5
|
||||||
|
if (papersource.equals("A5")) {
|
||||||
|
paperStatus = papers[1];
|
||||||
|
}
|
||||||
|
if ( !(paperStatus.equals(MS439PaperStatusEnum.PAPERFULL.getPrintCode()) || paperStatus.equals(MS439PaperStatusEnum.PAPERLOW.getPrintCode()))){
|
||||||
|
throw new RRException(500, paperStatus);
|
||||||
|
}
|
||||||
|
|
||||||
PrinterStatus ms439 = status.getData();
|
PrinterStatus ms439 = status.getData();
|
||||||
// 校验打印机是否正常,除了HEALTHY都抛异常
|
// 校验打印机是否正常,除了HEALTHY都抛异常
|
||||||
if (!ms439.getStDeviceStatus().equals(MS439DeviceStatusEnum.HEALTHY.getPrintCode()) ) {
|
if (!ms439.getStDeviceStatus().equals(MS439DeviceStatusEnum.HEALTHY.getPrintCode()) ) {
|
||||||
|
@ -118,11 +140,12 @@ public class MS439PrintServiceImpl implements MS439PrintService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验墨盒 满或者少才放行,当前获取为未知
|
// 校验墨盒 满或者少才放行,当前获取为未知
|
||||||
if ( !(ms439.getStInk().equals(MS439InkStatusEnum.INKFULL.getPrintCode()) || ms439.getStInk().equals(MS439InkStatusEnum.INKLOW.getPrintCode())
|
if ( false && !(ms439.getStInk().equals(MS439InkStatusEnum.INKFULL.getPrintCode()) || ms439.getStInk().equals(MS439InkStatusEnum.INKLOW.getPrintCode())
|
||||||
|| ms439.getStInk().equals(MS439InkStatusEnum.INKUNKNOWN.getPrintCode()))){
|
|| ms439.getStInk().equals(MS439InkStatusEnum.INKUNKNOWN.getPrintCode()))){
|
||||||
throw new RRException(500, ms439.getStInk());
|
throw new RRException(500, ms439.getStInk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thirdService.close("HtmPrinter");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,12 @@ import com.dpkj.common.utils.ThirdService;
|
||||||
import com.dpkj.modules.print.enums.*;
|
import com.dpkj.modules.print.enums.*;
|
||||||
import com.dpkj.modules.print.service.PrintService;
|
import com.dpkj.modules.print.service.PrintService;
|
||||||
import com.dpkj.modules.print.vo.PrinterStatus;
|
import com.dpkj.modules.print.vo.PrinterStatus;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.thymeleaf.util.StringUtils;
|
import org.thymeleaf.util.StringUtils;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 挂号服务打印
|
* 挂号服务打印
|
||||||
|
@ -23,6 +25,7 @@ import javax.annotation.Resource;
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
* @since 2025-02-08 10:36:25
|
* @since 2025-02-08 10:36:25
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service("registerService")
|
@Service("registerService")
|
||||||
public class RegisterServiceImpl implements PrintService {
|
public class RegisterServiceImpl implements PrintService {
|
||||||
|
|
||||||
|
@ -31,6 +34,8 @@ 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);
|
||||||
|
|
||||||
StringBuilder filePath = new StringBuilder(saveDir);
|
StringBuilder filePath = new StringBuilder(saveDir);
|
||||||
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
// 校验是否选中了模板,如果没选中模板的话则不需要另外生成了
|
||||||
if ( !StringUtils.isEmpty(template) && !StringUtils.isEmpty(saveDir)){
|
if ( !StringUtils.isEmpty(template) && !StringUtils.isEmpty(saveDir)){
|
||||||
|
@ -52,11 +57,31 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
param.put("mediaCtrl", 1);
|
param.put("mediaCtrl", 1);
|
||||||
param.put("fields", "LOGO=" + filePath);
|
param.put("fields", "LOGO=" + filePath);
|
||||||
lexMarkDTO.setParam(param.toJSONString());
|
lexMarkDTO.setParam(param.toJSONString());
|
||||||
return thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
LexMarkResultDTO<LexMarkResultDTO.Param> paramLexMarkResultDTO = thirdService.callDevice(lexMarkDTO, LexMarkResultDTO.Param.class);
|
||||||
|
// 切纸
|
||||||
|
this.thirdService.cutPaper("ReceiptPrinter", "ControlMedia", 4);
|
||||||
|
|
||||||
|
File file = new File(filePath.toString());
|
||||||
|
// 检查文件是否存在
|
||||||
|
if (file.exists() ) {
|
||||||
|
// 尝试删除文件
|
||||||
|
if (file.delete()) {
|
||||||
|
log.info("文件删除成功: " + filePath);
|
||||||
|
} else {
|
||||||
|
log.info("文件删除失败: " + filePath);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.info("文件不存在: " + filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.thirdService.close("ReceiptPrinter");
|
||||||
|
return paramLexMarkResultDTO;
|
||||||
}
|
}
|
||||||
|
|
||||||
@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);
|
||||||
|
@ -71,12 +96,12 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
PrinterStatus ms439 = status.getData();
|
PrinterStatus ms439 = status.getData();
|
||||||
// 获取打印机纸张
|
// 获取打印机纸张
|
||||||
String stPaperEx = ms439.getStPaperEx();
|
String stPaperEx = ms439.getStPaperEx();
|
||||||
if (stPaperEx == null || stPaperEx.equals("")) {
|
if (stPaperEx == null || stPaperEx.isEmpty()) {
|
||||||
throw new RRException(501, "获取打印机纸张状态出问题");
|
throw new RRException("获取打印机纸张状态出问题");
|
||||||
}
|
}
|
||||||
String[] papers = stPaperEx.split("\\|");
|
String[] papers = stPaperEx.split("\\|");
|
||||||
if ( papers.length < 1) {
|
if ( papers.length < 1) {
|
||||||
throw new RRException(501, "打印机纸盒数量不对");
|
throw new RRException("打印机纸盒数量不对");
|
||||||
}
|
}
|
||||||
String paperStatus = papers[0];
|
String paperStatus = papers[0];
|
||||||
if ( !(paperStatus.equals(MS439PaperStatusEnum.PAPERFULL.getPrintCode()) || paperStatus.equals(MS439PaperStatusEnum.PAPERLOW.getPrintCode()))){
|
if ( !(paperStatus.equals(MS439PaperStatusEnum.PAPERFULL.getPrintCode()) || paperStatus.equals(MS439PaperStatusEnum.PAPERLOW.getPrintCode()))){
|
||||||
|
@ -94,16 +119,17 @@ public class RegisterServiceImpl implements PrintService {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验磁带 满或者少才放行
|
// 校验磁带 满或者少才放行
|
||||||
if ( !(ms439.getStToner().equals(MS439TonerStatusEnum.TONERFULL.getPrintCode()) || ms439.getStToner().equals(MS439TonerStatusEnum.TONERLOW.getPrintCode()))){
|
if ( false && !(ms439.getStToner().equals(MS439TonerStatusEnum.TONERFULL.getPrintCode()) || ms439.getStToner().equals(MS439TonerStatusEnum.TONERLOW.getPrintCode()))){
|
||||||
throw new RRException(500, ms439.getStToner());
|
throw new RRException(500, ms439.getStToner());
|
||||||
}
|
}
|
||||||
|
|
||||||
// 校验墨盒 满或者少才放行,当前获取为未知
|
// 校验墨盒 满或者少才放行,当前获取为未知
|
||||||
if ( !(ms439.getStInk().equals(MS439InkStatusEnum.INKFULL.getPrintCode()) || ms439.getStInk().equals(MS439InkStatusEnum.INKLOW.getPrintCode())
|
if ( false && !(ms439.getStInk().equals(MS439InkStatusEnum.INKFULL.getPrintCode()) || ms439.getStInk().equals(MS439InkStatusEnum.INKLOW.getPrintCode())
|
||||||
|| ms439.getStInk().equals(MS439InkStatusEnum.INKUNKNOWN.getPrintCode()))){
|
|| ms439.getStInk().equals(MS439InkStatusEnum.INKUNKNOWN.getPrintCode()))){
|
||||||
throw new RRException(500, ms439.getStInk());
|
throw new RRException(500, ms439.getStInk());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.thirdService.close("ReceiptPrinter");
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue