From 4be4db06047ee68b92c8f85af746882f452707a4 Mon Sep 17 00:00:00 2001 From: yanshikui Date: Mon, 25 Nov 2024 16:36:32 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=89=93=E5=8D=B0=E6=9C=BA=E5=BC=82?= =?UTF-8?q?=E5=B8=B8=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ktg/print/controller/PrintController.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/ktg-print/src/main/java/com/ktg/print/controller/PrintController.java b/ktg-print/src/main/java/com/ktg/print/controller/PrintController.java index 427f62e..9d95870 100644 --- a/ktg-print/src/main/java/com/ktg/print/controller/PrintController.java +++ b/ktg-print/src/main/java/com/ktg/print/controller/PrintController.java @@ -74,13 +74,13 @@ public class PrintController { Long businessId = printBarcodeModel.getBusinessId(); String businessCode = printBarcodeModel.getBusinessCode(); PrintPrinterConfig printPrinterConfig = printPrinterConfigService.selectPrintPrinterConfigByPrinterCode(printerCode); + if (printPrinterConfig == null) { + return AjaxResult.error("打印机:" + printerCode + "不存在"); + } String ip = printPrinterConfig.getPrinterIp(); String printPort = printPrinterConfig.getPrinterPort().toString(); String printName = printPrinterConfig.getPrinterName(); PrintMessageProto.Printer.DataType dataType = PrintMessageProto.Printer.DataType.IQC_PrintMessage; - if (printPrinterConfig == null) { - return AjaxResult.error("打印机:" + printerCode + "不存在"); - } //根据打印机编码id获取打印机你信息 String clientIp = printPrinterConfig.getClientIp(); if (StringUtils.isEmpty(clientIp)) { @@ -88,6 +88,7 @@ public class PrintController { } PrintMessageProto.Printer msg = null; PrintMessageProto.Printer.PrintInfo printInfo = PrintMessageProto.Printer.PrintInfo.newBuilder().setIp(ip).setCode(printerCode).setName(printName).setPort(printPort).build(); + switch (businessType) { case UserConstants.BARCODE_TYPE_ITEM: //物料标签打印 @@ -370,26 +371,20 @@ public class PrintController { // msg = PrintMessageProto.Printer.newBuilder().setIqcPrintMessage(iQCPrintMessage).setDataType(dataType).setPrintInfo(printClientInfoMessage).build(); break; default: - // 默认执行代码块 - //封装模板数据 - //String sampleCode =params.get("sampleCode"); - //String qcObject =params.get("qcObject"); - //String sampleTime =params.get("sampleTime"); - //String batchCode =params.get("batchCode"); - //PrintMessageProt//o.Printer.IQCPrintMessage iQCPrintMessage = PrintMessageProto.Printer.IQCPrintMessage.newBuilder().setSampleCode(sampleCode).setQcObject(qcObject).setSampleTime(sampleTime).setBatchCode(batchCode).build(); - // 构造对应的消息对象 -// msg = PrintMessageProto.Printer.newBuilder().setIqcPrintMessage(iQCPrintMessage).setDataType(dataType).setPrintInfo(printClientInfoMessage).build(); -// break; + return AjaxResult.error("打印机不支持当前模板:" + "(" + businessType + ")"); } // 获取信道数据并发送消息对象给指定打印机客户端 //打印机名称和打印机客户端地址映射 一对一关系 ConcurrentHashMap socketAddress = PrintClientInfoMessageHandler.socketAddressMap; //根据客户端和通道信息 ConcurrentHashMap channels = PrintServerDefaultHandler.chanelMap; - Channel channel = channels.get(socketAddress.get(clientIp)); - if (channel == null) { + if (channels.isEmpty() + || socketAddress.isEmpty() + || socketAddress.get(clientIp) == null + || channels.get(socketAddress.get(clientIp)) == null) { return AjaxResult.error("打印机客户端连接异常" + "(" + clientIp + ")"); } + Channel channel = channels.get(socketAddress.get(clientIp)); channel.writeAndFlush(msg); return AjaxResult.success("打印成功"); }