消息数据转换

This commit is contained in:
2026-04-16 16:14:16 +08:00
parent a2839952b4
commit 9b48d49904
2 changed files with 11 additions and 11 deletions

View File

@@ -82,15 +82,15 @@ public class PrintMqListener {
public void otherPrint(String data) { public void otherPrint(String data) {
JSONObject jsonObject = JSONObject.parseObject(data); JSONObject jsonObject = JSONObject.parseObject(data);
Long shopId = jsonObject.getLong("shopId"); Long shopId = jsonObject.getLong("shopId");
Object o = jsonObject.getObject("data", Object.class);
String printTypeEnum = jsonObject.getString("printTypeEnum"); String printTypeEnum = jsonObject.getString("printTypeEnum");
JSONObject data2 = jsonObject.getJSONObject("data");
PrinterHandler.PrintTypeEnum typeEnum = PrinterHandler.PrintTypeEnum.valueOf(printTypeEnum); PrinterHandler.PrintTypeEnum typeEnum = PrinterHandler.PrintTypeEnum.valueOf(printTypeEnum);
SysPrintData sysPrintData = new SysPrintData(); SysPrintData sysPrintData = new SysPrintData();
sysPrintData.setShopId(shopId); sysPrintData.setShopId(shopId);
sysPrintData.setData(JSONObject.toJSONString(o)); sysPrintData.setData(data2.toJSONString());
sysPrintData.setType(typeEnum.toString()); sysPrintData.setType(typeEnum.toString());
printDataService.save(sysPrintData); printDataService.save(sysPrintData);
rabbitPublisher.sendOtherPrintLocalMsg(shopId, printTypeEnum, sysPrintData.getId()); rabbitPublisher.sendOtherPrintLocalMsg(shopId, printTypeEnum, sysPrintData.getId());
printConfig.otherHandler(shopId, o, typeEnum); printConfig.otherHandler(shopId, data2, typeEnum);
} }
} }

View File

@@ -176,7 +176,7 @@ public class PrintConfig implements ApplicationRunner {
* @param data 传递的数据 * @param data 传递的数据
* @param printTypeEnum IN_STOCK DAY_REPORT PRODUCT_REPORT RECHARGE STOCK_CHECK * @param printTypeEnum IN_STOCK DAY_REPORT PRODUCT_REPORT RECHARGE STOCK_CHECK
*/ */
public void otherHandler(Long shopId, Object data, PrinterHandler.PrintTypeEnum printTypeEnum) { public void otherHandler(Long shopId, JSONObject data, PrinterHandler.PrintTypeEnum printTypeEnum) {
if (shopId == null || Objects.isNull(data)) { if (shopId == null || Objects.isNull(data)) {
log.info("otherHandler 打印数据为空, shopId: {}, data: {}", shopId, data); log.info("otherHandler 打印数据为空, shopId: {}, data: {}", shopId, data);
return; return;
@@ -186,38 +186,38 @@ public class PrintConfig implements ApplicationRunner {
case PrinterHandler.PrintTypeEnum.STOCK: case PrinterHandler.PrintTypeEnum.STOCK:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.stockPrint(machine, shopInfo.getShopName(), (StockPrintDTO) data)); .stockPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), StockPrintDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.DAY_REPORT: case PrinterHandler.PrintTypeEnum.DAY_REPORT:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.dayReportPrint(machine, shopInfo.getShopName(), (DayReportPrintDTO) data)); .dayReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), DayReportPrintDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT: case PrinterHandler.PrintTypeEnum.PRODUCT_REPORT:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.productReportPrint(machine, shopInfo.getShopName(), (ProductReportPrintDTO) data)); .productReportPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), ProductReportPrintDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.RECHARGE: case PrinterHandler.PrintTypeEnum.RECHARGE:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.rechargePrint(machine, shopInfo.getShopName(), (RechargePrintDTO) data)); .rechargePrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), RechargePrintDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.STOCK_CHECK: case PrinterHandler.PrintTypeEnum.STOCK_CHECK:
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.stockCheckPrint(machine, shopInfo.getShopName(), (StockCheckPrintDTO) data)); .stockCheckPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), StockCheckPrintDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.HANDOVER: case PrinterHandler.PrintTypeEnum.HANDOVER:
log.info("准备开始打印交班"); log.info("准备开始打印交班");
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()).handoverPrint(machine, shopInfo.getShopName(), (HandoverRecordDTO) data)); .forEach(machine -> getPrinter(machine.getBrand()).handoverPrint(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), HandoverRecordDTO.class)));
break; break;
case PrinterHandler.PrintTypeEnum.CALL: case PrinterHandler.PrintTypeEnum.CALL:
log.info("准备开始打印叫号单"); log.info("准备开始打印叫号单");
getPrintMachine(shopId, printTypeEnum) getPrintMachine(shopId, printTypeEnum)
.forEach(machine -> getPrinter(machine.getBrand()) .forEach(machine -> getPrinter(machine.getBrand())
.callNumPrintBefore(machine, shopInfo.getShopName(), (CallQueue) data)); .callNumPrintBefore(machine, shopInfo.getShopName(), JSONObject.parseObject(data.toJSONString(), CallQueue.class)));
break; break;
default: default:
throw new CzgException("otherHandler 未知打印类型"); throw new CzgException("otherHandler 未知打印类型");