diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java index b26c1c442..837967297 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisWaybillService.java @@ -193,6 +193,6 @@ public interface IEmisWaybillService public List selectPrintWaybillList(EmisWaybill emisWaybill); - public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError, IOException ; + public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError ; } diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java index 973bb0c16..a631cade8 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisWaybillServiceImpl.java @@ -2212,7 +2212,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } @Override - public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError, IOException { + public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError { if(StringUtils.isEmpty(orderSn)){ throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空"); @@ -2260,90 +2260,94 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb tplName="tpl/ws_ls_in_tpl.docx"; } - OutputStream outputStream=response.getOutputStream(); - InputStream fis = new ClassPathResource(tplName).getInputStream(); - /*1.根据模板生成文档*/ - String fileName= URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(),"UTF-8"); + try { + OutputStream outputStream = response.getOutputStream(); + InputStream fis = new ClassPathResource(tplName).getInputStream(); + /*1.根据模板生成文档*/ + String fileName = URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(), "UTF-8"); - // 货物清单 - EmisWaybillCargo queryCargo = new EmisWaybillCargo(); - queryCargo.setWaybillId(emisWaybillOld.getId()); - List cargoList=emisWaybillCargoMapper.selectEmisWaybillCargoList(queryCargo); + // 货物清单 + EmisWaybillCargo queryCargo = new EmisWaybillCargo(); + queryCargo.setWaybillId(emisWaybillOld.getId()); + List cargoList = emisWaybillCargoMapper.selectEmisWaybillCargoList(queryCargo); - // 生成条码 - int width=400; - int height=70; - BufferedImage barcodeImageBuffer = BarcodeUtils.getBarCodeWithWord(emisWaybillOld.getIntoWarehouseBillCode(),width,height,100); + // 生成条码 + int width = 400; + int height = 70; + BufferedImage barcodeImageBuffer = BarcodeUtils.getBarCodeWithWord(emisWaybillOld.getIntoWarehouseBillCode(), width, height, 100); - // 填充模版数据 - LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); - Configure config = Configure.builder().bind("cargoList", policy).build(); + // 填充模版数据 + LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); + Configure config = Configure.builder().bind("cargoList", policy).build(); - String customsEclaration=""; - if(!StringUtils.isEmpty(emisWaybillOld.getCustomsEclaration())){ - customsEclaration=DictUtils.getDictLabel("emis_declare_mode",emisWaybillOld.getCustomsEclaration()); + String customsEclaration = ""; + if (!StringUtils.isEmpty(emisWaybillOld.getCustomsEclaration())) { + customsEclaration = DictUtils.getDictLabel("emis_declare_mode", emisWaybillOld.getCustomsEclaration()); + } + + String customsClear = ""; + if (!StringUtils.isEmpty(emisWaybillOld.getCustomsClear())) { + customsClear = DictUtils.getDictLabel("emis_customs_clear", emisWaybillOld.getCustomsClear()); + } + + Map fillMap = new HashMap<>(); + fillMap.put("wsInNo", emisWaybillOld.getIntoWarehouseBillCode()); + fillMap.put("country", emisWaybillOld.getReceiveCountryName()); + fillMap.put("warehouse", emisWaybillOld.getIntoWarehouseName()); + fillMap.put("productName", emisWaybillOld.getProductTypeName()); + fillMap.put("estDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, emisWaybillOld.getPickStartDate() == null ? emisWaybillOld.getOrderDate() : emisWaybillOld.getPickStartDate())); + fillMap.put("declareType", customsEclaration); + fillMap.put("eDeclareType", customsClear); + fillMap.put("supplier", ""); + + fillMap.put("sendName", Convert.chineseName(emisWaybillOld.getSendName())); + fillMap.put("sendTel", Convert.mobile(emisWaybillOld.getSendMobile())); + fillMap.put("sendAddress", Convert.address(emisWaybillOld.getSendAddress())); + fillMap.put("sendCompany", emisWaybillOld.getSendCompany()); + fillMap.put("sendCountry", emisWaybillOld.getSendCountryName()); + + fillMap.put("recvName", Convert.chineseName(emisWaybillOld.getReceiveName())); + fillMap.put("recvTel", Convert.mobile(emisWaybillOld.getReceiveMobile())); + fillMap.put("recvAddress", Convert.address(emisWaybillOld.getReceiveAddress())); + fillMap.put("recvCompany", emisWaybillOld.getReceiveCompany()); + fillMap.put("recvCountry", emisWaybillOld.getReceiveCountryName()); + + fillMap.put("wsContact", emisWaybillOld.getIntoWarehouseContact()); + fillMap.put("wsPhone", emisWaybillOld.getIntoWarehousePhone()); + fillMap.put("wsAddress", emisWaybillOld.getIntoWarehouseAddress()); + fillMap.put("salesmen", emisWaybillOld.getSalesmen()); + + fillMap.put("sendProvinceName", emisWaybillOld.getSendProvinceName()); + fillMap.put("sendCityName", emisWaybillOld.getSendCityName()); + + fillMap.put("recvProvinceName", emisWaybillOld.getReceiveProvinceName()); + fillMap.put("recvCityName", emisWaybillOld.getReceiveCityName()); + + fillMap.put("barcode", Pictures.ofBufferedImage(barcodeImageBuffer, PictureType.JPEG).size(width, height).create()); + + fillMap.put("cargoList", emisWaybillOld.getCargoList()); + + // 生成模版 + XWPFTemplate template = XWPFTemplate.compile(fis, config).render(fillMap); + + response.setContentType("application/octet-stream"); + response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf"); + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + template.write(bos); + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + + DocUtils.wordToPdf(bis, outputStream); + response.flushBuffer(); + + IOUtils.closeQuietly(fis); + IOUtils.closeQuietly(outputStream); } - - String customsClear=""; - if(!StringUtils.isEmpty(emisWaybillOld.getCustomsClear())){ - customsClear=DictUtils.getDictLabel("emis_customs_clear",emisWaybillOld.getCustomsClear()); + catch (Exception ex){ + throw new EmisBizError(EmisBizErrorType.FAIL,"生成进仓单出错:"+ ex.getMessage()); } - Map fillMap = new HashMap<>(); - fillMap.put("wsInNo", emisWaybillOld.getIntoWarehouseBillCode()); - fillMap.put("country", emisWaybillOld.getReceiveCountryName()); - fillMap.put("warehouse", emisWaybillOld.getIntoWarehouseName()); - fillMap.put("productName", emisWaybillOld.getProductTypeName()); - fillMap.put("estDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,emisWaybillOld.getPickStartDate()==null?emisWaybillOld.getOrderDate():emisWaybillOld.getPickStartDate())); - fillMap.put("declareType", customsEclaration); - fillMap.put("eDeclareType", customsClear); - fillMap.put("supplier", ""); - - fillMap.put("sendName", Convert.chineseName(emisWaybillOld.getSendName())); - fillMap.put("sendTel", Convert.mobile(emisWaybillOld.getSendMobile())); - fillMap.put("sendAddress", Convert.address(emisWaybillOld.getSendAddress())); - fillMap.put("sendCompany", emisWaybillOld.getSendCompany()); - fillMap.put("sendCountry", emisWaybillOld.getSendCountryName()); - - fillMap.put("recvName", Convert.chineseName(emisWaybillOld.getReceiveName())); - fillMap.put("recvTel", Convert.mobile(emisWaybillOld.getReceiveMobile())); - fillMap.put("recvAddress", Convert.address(emisWaybillOld.getReceiveAddress())); - fillMap.put("recvCompany", emisWaybillOld.getReceiveCompany()); - fillMap.put("recvCountry", emisWaybillOld.getReceiveCountryName()); - - fillMap.put("wsContact", emisWaybillOld.getIntoWarehouseContact()); - fillMap.put("wsPhone", emisWaybillOld.getIntoWarehousePhone()); - fillMap.put("wsAddress", emisWaybillOld.getIntoWarehouseAddress()); - fillMap.put("salesmen", emisWaybillOld.getSalesmen()); - - fillMap.put("sendProvinceName", emisWaybillOld.getSendProvinceName()); - fillMap.put("sendCityName", emisWaybillOld.getSendCityName()); - - fillMap.put("recvProvinceName", emisWaybillOld.getReceiveProvinceName()); - fillMap.put("recvCityName", emisWaybillOld.getReceiveCityName()); - - fillMap.put("barcode", Pictures.ofBufferedImage(barcodeImageBuffer, PictureType.JPEG).size(width, height).create()); - - fillMap.put("cargoList", emisWaybillOld.getCargoList()); - - // 生成模版 - XWPFTemplate template = XWPFTemplate.compile(fis,config).render(fillMap); - - response.setContentType("application/octet-stream"); - response.setHeader("Content-Disposition", "attachment;fileName="+ fileName +".pdf"); - - ByteArrayOutputStream bos=new ByteArrayOutputStream(); - template.write(bos); - ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); - - DocUtils.wordToPdf(bis, outputStream); - response.flushBuffer(); - - - IOUtils.closeQuietly(fis); - IOUtils.closeQuietly(outputStream); - }