diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleSubBillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleSubBillServiceImpl.java index 270c107e3..526d584f9 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleSubBillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleSubBillServiceImpl.java @@ -99,6 +99,122 @@ public class EmisSettleSubBillServiceImpl extends EmisBaseService implements IEm throw new EmisBizError(EmisBizErrorType.FAIL,"订单已取消"); } + String tplName=""; + // 快递 + if("1".equals(tplType) ){ + tplName="tpl/ws_kd_in_tpl.docx"; + } + + BigDecimal totalAllPrice=BigDecimal.ZERO; + try { + OutputStream outputStream = response.getOutputStream(); + InputStream fis = new ClassPathResource(tplName).getInputStream(); + /*1.根据模板生成文档*/ + String fileName = URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(), "UTF-8"); + + List declareGoodsList = new ArrayList(); + + // 填充模版数据 + LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); + Configure config = Configure.builder().bind("cargoList", policy).build(); + + + 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_HH_MM_SS, 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()); + + String salesmenPhone=""; + if(!StringUtils.isEmpty(emisWaybillOld.getSalesmen())){ + SysUser salesmenUser = getEmisStaffByEmpName(emisWaybillOld.getSalesmen()); + if (salesmenUser != null) { + salesmenPhone=salesmenUser.getPhonenumber(); + } + } + fillMap.put("salesmenPhone", salesmenPhone); + fillMap.put("orderRemark", emisWaybillOld.getOrderRemark()); + + + fillMap.put("sendProvinceName", emisWaybillOld.getSendProvinceName()); + fillMap.put("sendCityName", emisWaybillOld.getSendCityName()); + + fillMap.put("recvProvinceName", emisWaybillOld.getReceiveProvinceName()); + fillMap.put("recvCityName", emisWaybillOld.getReceiveCityName()); + + fillMap.put("cargoList", declareGoodsList); + fillMap.put("totalAllPrice", totalAllPrice.stripTrailingZeros().toPlainString()); + + // 生成模版 + XWPFTemplate template = XWPFTemplate.compile(fis, config).render(fillMap); + + // docx + if("docx".equals(fileType)){ + response.setContentType("application/octet-stream;charset=UTF-8"); + response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".docx"); + response.addHeader("Access-Control-Expose-Headers", "Content-disposition"); + template.write(outputStream); + } + // pdf + else { + response.setContentType("application/pdf"); + 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); + } + catch (Exception ex){ + ex.printStackTrace(); + throw new EmisBizError(EmisBizErrorType.FAIL,"生成出错:"+ ex.getMessage()); + } + } + + // + public void genCustBillTplFile_old(HttpServletResponse response, String billCode,String tplType, String fileType) throws EmisBizError { + + if(StringUtils.isEmpty(billCode)){ + throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"运单号为空"); + } + + EmisWaybill emisWaybillOld = getWaybillByBillCode(billCode); + if(emisWaybillOld==null){ + throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"运单不存在"); + } + + if(OrderStatus.CANCEL.statusCode.equals(emisWaybillOld.getOrderStatus())){ + throw new EmisBizError(EmisBizErrorType.FAIL,"订单已取消"); + } + String tplName=""; // 根据不同线路使用不同模版 // 账单模版