From 5c1c3086984063cd8d51a088c7049044caae2ab9 Mon Sep 17 00:00:00 2001 From: linfso Date: Sun, 16 Mar 2025 22:49:41 +0800 Subject: [PATCH] md --- .../erp/web/emis/EmisWaybillController.java | 4 +- .../impl/EmisSettleSubBillServiceImpl.java | 126 +----------------- 2 files changed, 4 insertions(+), 126 deletions(-) diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java index 4f69131b0..10ffacc4e 100644 --- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java +++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisWaybillController.java @@ -376,7 +376,7 @@ public class EmisWaybillController extends EmisBaseController @RequestMapping("/exportCustBillTpl") public void exportCustBillTpl(HttpServletResponse response,String billCode,String fileType) { try{ - emisSettleSubBillService.genCustBillTplFile(response,billCode,"pdf","1"); + emisSettleSubBillService.genCustBillTplFile(response,billCode,"1","pdf"); } catch(EmisBizError ex){ ex.printStackTrace(); @@ -392,7 +392,7 @@ public class EmisWaybillController extends EmisBaseController @RequestMapping("/exportCustTaxBillTpl") public void exportCustTaxBillTpl(HttpServletResponse response,String billCode,String fileType) { try{ - emisSettleSubBillService.genCustBillTplFile(response,billCode,"pdf","2"); + emisSettleSubBillService.genCustBillTplFile(response,billCode,"2","pdf"); } catch(EmisBizError ex){ ex.printStackTrace(); 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 bbc16d606..9fb9f5b73 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 @@ -85,6 +85,7 @@ public class EmisSettleSubBillServiceImpl extends EmisBaseService implements IEm } + @Override public void genCustBillTplFile(HttpServletResponse response, String billCode,String tplType, String fileType) throws EmisBizError { @@ -101,129 +102,6 @@ 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"; -// tplName="tpl/cust_bill_tpl.docx"; - } - else if("2".equals(tplType) ){ - tplName="tpl/cust_tax_bill_tpl.docx"; - } - - log.error("===>tplName==>"+tplName); - - BigDecimal totalAllPrice=BigDecimal.ZERO; - try { - OutputStream outputStream = response.getOutputStream(); - InputStream fis = new ClassPathResource(tplName).getInputStream(); - /*1.根据模板生成文档*/ - String fileName = billCode; - - List declareGoodsList = null; - declareGoodsList = new ArrayList(); - EmisWaybillDeclareGoods cargoDeclareGoods = new EmisWaybillDeclareGoods(); - cargoDeclareGoods.setGoodsName(emisWaybillOld.getGoodsInfo()); - cargoDeclareGoods.setCargoQty(new BigDecimal(emisWaybillOld.getParcelQty().toString())); - declareGoodsList.add(cargoDeclareGoods); - - // 填充模版数据 - 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("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=""; // 根据不同线路使用不同模版 // 账单模版 @@ -240,7 +118,7 @@ public class EmisSettleSubBillServiceImpl extends EmisBaseService implements IEm OutputStream outputStream = response.getOutputStream(); InputStream fis = new ClassPathResource(tplName).getInputStream(); /*1.根据模板生成文档*/ - String fileName = URLEncoder.encode(emisWaybillOld.getBillCode()+"-"+tplType, "UTF-8"); + String fileName = URLEncoder.encode(billCode+"-"+tplType, "UTF-8"); // 填充模版数据 LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();