feat:打印机异常消息提醒
This commit is contained in:
parent
6c3e07e6e4
commit
4be4db0604
@ -74,13 +74,13 @@ public class PrintController {
|
|||||||
Long businessId = printBarcodeModel.getBusinessId();
|
Long businessId = printBarcodeModel.getBusinessId();
|
||||||
String businessCode = printBarcodeModel.getBusinessCode();
|
String businessCode = printBarcodeModel.getBusinessCode();
|
||||||
PrintPrinterConfig printPrinterConfig = printPrinterConfigService.selectPrintPrinterConfigByPrinterCode(printerCode);
|
PrintPrinterConfig printPrinterConfig = printPrinterConfigService.selectPrintPrinterConfigByPrinterCode(printerCode);
|
||||||
|
if (printPrinterConfig == null) {
|
||||||
|
return AjaxResult.error("打印机:" + printerCode + "不存在");
|
||||||
|
}
|
||||||
String ip = printPrinterConfig.getPrinterIp();
|
String ip = printPrinterConfig.getPrinterIp();
|
||||||
String printPort = printPrinterConfig.getPrinterPort().toString();
|
String printPort = printPrinterConfig.getPrinterPort().toString();
|
||||||
String printName = printPrinterConfig.getPrinterName();
|
String printName = printPrinterConfig.getPrinterName();
|
||||||
PrintMessageProto.Printer.DataType dataType = PrintMessageProto.Printer.DataType.IQC_PrintMessage;
|
PrintMessageProto.Printer.DataType dataType = PrintMessageProto.Printer.DataType.IQC_PrintMessage;
|
||||||
if (printPrinterConfig == null) {
|
|
||||||
return AjaxResult.error("打印机:" + printerCode + "不存在");
|
|
||||||
}
|
|
||||||
//根据打印机编码id获取打印机你信息
|
//根据打印机编码id获取打印机你信息
|
||||||
String clientIp = printPrinterConfig.getClientIp();
|
String clientIp = printPrinterConfig.getClientIp();
|
||||||
if (StringUtils.isEmpty(clientIp)) {
|
if (StringUtils.isEmpty(clientIp)) {
|
||||||
@ -88,6 +88,7 @@ public class PrintController {
|
|||||||
}
|
}
|
||||||
PrintMessageProto.Printer msg = null;
|
PrintMessageProto.Printer msg = null;
|
||||||
PrintMessageProto.Printer.PrintInfo printInfo = PrintMessageProto.Printer.PrintInfo.newBuilder().setIp(ip).setCode(printerCode).setName(printName).setPort(printPort).build();
|
PrintMessageProto.Printer.PrintInfo printInfo = PrintMessageProto.Printer.PrintInfo.newBuilder().setIp(ip).setCode(printerCode).setName(printName).setPort(printPort).build();
|
||||||
|
|
||||||
switch (businessType) {
|
switch (businessType) {
|
||||||
case UserConstants.BARCODE_TYPE_ITEM:
|
case UserConstants.BARCODE_TYPE_ITEM:
|
||||||
//物料标签打印
|
//物料标签打印
|
||||||
@ -370,26 +371,20 @@ public class PrintController {
|
|||||||
// msg = PrintMessageProto.Printer.newBuilder().setIqcPrintMessage(iQCPrintMessage).setDataType(dataType).setPrintInfo(printClientInfoMessage).build();
|
// msg = PrintMessageProto.Printer.newBuilder().setIqcPrintMessage(iQCPrintMessage).setDataType(dataType).setPrintInfo(printClientInfoMessage).build();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
// 默认执行代码块
|
return AjaxResult.error("打印机不支持当前模板:" + "(" + businessType + ")");
|
||||||
//封装模板数据
|
|
||||||
//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;
|
|
||||||
}
|
}
|
||||||
// 获取信道数据并发送消息对象给指定打印机客户端
|
// 获取信道数据并发送消息对象给指定打印机客户端
|
||||||
//打印机名称和打印机客户端地址映射 一对一关系
|
//打印机名称和打印机客户端地址映射 一对一关系
|
||||||
ConcurrentHashMap<String, SocketAddress> socketAddress = PrintClientInfoMessageHandler.socketAddressMap;
|
ConcurrentHashMap<String, SocketAddress> socketAddress = PrintClientInfoMessageHandler.socketAddressMap;
|
||||||
//根据客户端和通道信息
|
//根据客户端和通道信息
|
||||||
ConcurrentHashMap<SocketAddress, Channel> channels = PrintServerDefaultHandler.chanelMap;
|
ConcurrentHashMap<SocketAddress, Channel> channels = PrintServerDefaultHandler.chanelMap;
|
||||||
Channel channel = channels.get(socketAddress.get(clientIp));
|
if (channels.isEmpty()
|
||||||
if (channel == null) {
|
|| socketAddress.isEmpty()
|
||||||
|
|| socketAddress.get(clientIp) == null
|
||||||
|
|| channels.get(socketAddress.get(clientIp)) == null) {
|
||||||
return AjaxResult.error("打印机客户端连接异常" + "(" + clientIp + ")");
|
return AjaxResult.error("打印机客户端连接异常" + "(" + clientIp + ")");
|
||||||
}
|
}
|
||||||
|
Channel channel = channels.get(socketAddress.get(clientIp));
|
||||||
channel.writeAndFlush(msg);
|
channel.writeAndFlush(msg);
|
||||||
return AjaxResult.success("打印成功");
|
return AjaxResult.success("打印成功");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user