From e3a6e8fa3f05673247354f743e61a91f2495042d Mon Sep 17 00:00:00 2001 From: zpl Date: Mon, 9 Aug 2021 10:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=89=93=E5=8D=B0=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/PrintLogServiceImpl.java | 49 +++++++------------ .../impl/SurplusReturnServiceImpl.java | 24 +++++---- 2 files changed, 32 insertions(+), 41 deletions(-) diff --git a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java index d1f4a09e..6f50e552 100644 --- a/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java +++ b/common/src/main/java/com/foreverwin/mesnac/common/service/impl/PrintLogServiceImpl.java @@ -6,6 +6,7 @@ import cn.hutool.json.JSONString; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.fasterxml.jackson.databind.ObjectMapper; import com.foreverwin.mesnac.common.constant.Constants; import com.foreverwin.mesnac.common.dto.LabelPrintDto; import com.foreverwin.mesnac.common.model.PrintLog; @@ -60,52 +61,38 @@ public class PrintLogServiceImpl extends ServiceImpl i @Override public void labelPrint(String site, String user, List printList) { - List labelPrintDtoList = new ArrayList<>(); - StringBuffer stringBuffer = new StringBuffer(""); + // 获取printParam,并拼接为json格式字符串 + StringBuffer stringBuffer = new StringBuffer("["); for (PrintLog printLog : printList) { - LabelPrintDto labelPrintDto = new LabelPrintDto(); - // 打印机名称、打印模板 - labelPrintDto.setPrinter(printLog.getPrintName()); - labelPrintDto.setPrintTemplate(printLog.getPrintTemplate()); - // {"ITEM":"500100010001","INVENTORY":"500100010001*20210721","ITEM_DESC":"测试物料","SUPPLIER":"BA002"} - // 打印参数:物料编号、物料描述、供应商、批次号 String printParam = printLog.getPrintParam(); - JSONObject jsonObject = JSONObject.parseObject(printParam); - String item = jsonObject.getString("ITEM"); - String item_desc = jsonObject.getString("ITEM_DESC"); - String supplier = jsonObject.getString("SUPPLIER"); - String inventory = jsonObject.getString("INVENTORY"); - labelPrintDto.setItem(item); - labelPrintDto.setItemDescription(item_desc); - labelPrintDto.setSupplier(supplier); - labelPrintDto.setBatch(inventory); - /* - labelPrintDto.setItem(printLog.getItem()); - labelPrintDto.setItemDescription(printLog.getItemDescription());*/ - labelPrintDtoList.add(labelPrintDto); - stringBuffer.append(printParam).append(","); + stringBuffer.append(printParam.replace("[","").replace("]","")).append(","); } - String jsonList = JSON.toJSONString(labelPrintDtoList); - String post = HttpUtil.post(printServer, JSON.toJSONString(labelPrintDtoList), 30000); + StringBuffer append = stringBuffer.deleteCharAt(stringBuffer.length() - 1).append("]"); + List list= JSONArray.parseArray(append.toString(), LabelPrintDto.class); + // 打印机、打印模板 + for (int i = 0; i < list.size(); i++) { + list.get(i).setPrinter(printList.get(i).getPrintName()); + list.get(i).setPrintTemplate(printList.get(i).getPrintTemplate()); + } + String post = HttpUtil.post(printServer, JSON.toJSONString(list), 60000); /** * {"msg":"打印成功","code":0} * {"msg":"打印失败","code":500} * 根据返回值,更新打印机信息-printName及打印是否成功信息isPrint */ JSONObject jsonObject = JSONObject.parseObject(post); - String code = jsonObject.getString("code"); - if (code == null){ - + Integer code = jsonObject.getInteger("code"); + String msg = jsonObject.getString("msg"); + if (code == 500){ + throw BusinessException.build(msg); } + // 更新打印记录:是否已打印、使用的打印机、打印次数 List printLogList = new ArrayList<>(); - if (post.indexOf("500") != -1){ - throw BusinessException.build("打印失败!"); - } for (PrintLog printLog : printList) { PrintLog printLogOne = new PrintLog(); printLogOne.setHandle(printLog.getHandle()); printLogOne.setIsPrint("true"); - // 更新日志 + printLogOne.setPrintNum(printLog.getPrintNum()+1); if (printLog.getCategory().equals(Constants.PRINT_TYPE_INV)){ printLogOne.setPrintName(printLog.getPrintName()); } diff --git a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SurplusReturnServiceImpl.java b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SurplusReturnServiceImpl.java index 8f25066c..ce92e030 100644 --- a/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SurplusReturnServiceImpl.java +++ b/dispatch/src/main/java/com/foreverwin/mesnac/dispatch/service/impl/SurplusReturnServiceImpl.java @@ -1,7 +1,9 @@ package com.foreverwin.mesnac.dispatch.service.impl; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.foreverwin.mesnac.common.constant.Constants; +import com.foreverwin.mesnac.common.dto.LabelPrintDto; import com.foreverwin.mesnac.common.enums.HandleEnum; import com.foreverwin.mesnac.common.model.PrintLog; import com.foreverwin.mesnac.common.service.PrintLogService; @@ -198,24 +200,26 @@ public class SurplusReturnServiceImpl extends ServiceImpl inventoryAssyDataList = inventoryAssyDataService.selectList(inventoryAssyData); - if (inventoryAssyDataList.size() == 1){ - jsonObject.put("SUPPLIER", inventoryAssyDataList.get(0).getDataAttr()); // 供应商 - }else { + if (inventoryAssyDataList.size() != 1){ throw BusinessException.build("未正确找到当前批次的供应商!"); } - jsonObject.put("INVENTORY", surplusInventory); // 批次号 - printLog.setPrintParam(jsonObject.toString()); + String dataAttr = inventoryAssyDataList.get(0).getDataAttr(); + + // 记录打印参数:物料、物料编码、供应商、批次号 + LabelPrintDto labelPrintDto = new LabelPrintDto(); + labelPrintDto.setItem(inventoryModel.getItemBo().split(",")[1]); + labelPrintDto.setItemDescription(inventoryModel.getDescription()); + labelPrintDto.setSupplier(dataAttr); + labelPrintDto.setBatch(surplusInventory); + + printLog.setPrintParam(JSON.toJSONString(labelPrintDto)); printLog.setInventory(surplusInventory); printLog.setItemBo(inventoryModel.getItemBo()); - //printLog.setIsPrint("false"); printLog.setCreateUser(user); printLog.setCreatedDateTime(dateTime); printLogService.save(printLog);