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 65b8d843f..f490e6e7e 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 @@ -365,6 +365,40 @@ public class EmisWaybillController extends EmisBaseController } + /** + * 导出客户账单模版 + * @param response + * @param orderSn + */ + @Log(title = "导出客户账单模版", businessType = BusinessType.EXPORT) + @RequestMapping("/exportCustBillTpl") + public void exportCustBillTpl(HttpServletResponse response,String orderSn,String fileType) { + + try{ + emisWaybillService.genWarehouseInTplFile(response,orderSn,fileType); + } + catch(EmisBizError ex){ + ex.printStackTrace(); + } + } + + /** + * 导出客户账单模版 + * @param response + * @param billCode + */ + @Log(title = "导出客户税金账单模版", businessType = BusinessType.EXPORT) + @RequestMapping("/exportCustTaxBillTpl") + public void exportCustTaxBillTpl(HttpServletResponse response,String billCode,String fileType) { + + try{ + emisWaybillService.genWarehouseInTplFile(response,billCode,fileType); + } + catch(EmisBizError ex){ + ex.printStackTrace(); + } + } + @Log(title = "运单实时下单", businessType = BusinessType.INSERT) @PostMapping(value = "/realSubmitOrder") public AjaxResult realSubmitOrder(@Validated @RequestBody WaybillOrder waybillOrder, Integer isModify) diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSettleSubBillService.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSettleSubBillService.java index eaec7ea9c..df99931a1 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSettleSubBillService.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/IEmisSettleSubBillService.java @@ -15,6 +15,9 @@ import java.util.Map; import com.xdadan.erp.common.core.audit.IDataAuditService; import com.xdadan.erp.emis.domain.EmisSettleSubBill; import com.xdadan.erp.emis.domain.EmisWaybill; +import com.xdadan.erp.emis.domain.exception.EmisBizError; + +import javax.servlet.http.HttpServletResponse; /** * @ClassName EmisSettleSubBillService @@ -44,6 +47,8 @@ public interface IEmisSettleSubBillService extends IDataAuditService public List selectHasPayMapList(String settleBillNo); + public void genCustBillTplFile(HttpServletResponse response, String billCode,String tplType, String fileType) throws EmisBizError; + /** * 查询统计信息 diff --git a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java index 1b01e2d76..9d7e118a1 100644 --- a/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java +++ b/emis-biz/src/main/java/com/xdadan/erp/emis/service/impl/EmisSettleBillServiceImpl.java @@ -755,7 +755,6 @@ public class EmisSettleBillServiceImpl extends EmisBaseService implements IEmisS continue; } - EmisSettleSubBill subBill = emisSettleSubBillMapper.selectSettleSubBillBySubBillNo(billNo); BigDecimal sumMoney = BigDecimal.valueOf(Double.valueOf(item.get("sumMoney").toString())); totalMoney = totalMoney.add(sumMoney); 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 9ed7bed61..7664f42ca 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 @@ -10,26 +10,55 @@ package com.xdadan.erp.emis.service.impl; +import java.awt.image.BufferedImage; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.io.OutputStream; +import java.math.BigDecimal; +import java.net.URLEncoder; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; -import com.xdadan.erp.emis.domain.EmisWaybill; +import com.deepoove.poi.XWPFTemplate; +import com.deepoove.poi.config.Configure; +import com.deepoove.poi.data.PictureType; +import com.deepoove.poi.data.Pictures; +import com.deepoove.poi.plugin.table.LoopRowTableRenderPolicy; +import com.xdadan.erp.common.core.domain.entity.SysUser; +import com.xdadan.erp.common.utils.BarcodeUtils; +import com.xdadan.erp.common.utils.DateUtils; +import com.xdadan.erp.common.utils.DictUtils; +import com.xdadan.erp.emis.domain.*; +import com.xdadan.erp.emis.domain.enumtype.EmisBizErrorType; +import com.xdadan.erp.emis.domain.enumtype.OrderStatus; +import com.xdadan.erp.emis.domain.exception.EmisBizError; import com.xdadan.erp.emis.mapper.EmisSettleInvoiceRelMapper; import com.xdadan.erp.emis.mapper.EmisSettlePayRelMapper; +import com.xdadan.erp.emis.service.EmisBaseService; +import com.xdadan.erp.emis.service.warehouse.DocUtils; +import com.xdadan.erp.emis.utils.sensitive.Convert; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Service; -import com.xdadan.erp.emis.domain.EmisSettleSubBill; import com.xdadan.erp.emis.mapper.EmisSettleSubBillMapper; import com.xdadan.erp.emis.service.IEmisSettleSubBillService; +import org.springframework.util.CollectionUtils; -/** +import javax.servlet.http.HttpServletResponse; + + /** * 结算子账单Service业务层处理 * * @author linfso * @date 2024-07-03 18:54:52 */ @Service -public class EmisSettleSubBillServiceImpl implements IEmisSettleSubBillService +public class EmisSettleSubBillServiceImpl extends EmisBaseService implements IEmisSettleSubBillService { @Autowired private EmisSettleSubBillMapper emisSettleSubBillMapper; @@ -53,6 +82,139 @@ public class EmisSettleSubBillServiceImpl implements IEmisSettleSubBillService return emisSettleSubBillMapper.selectEmisSettleSubBillById((Long)id); } + + @Override + public void genCustBillTplFile(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=""; + // 根据不同线路使用不同模版 + // 账单模版 + if("1".equals(tplType) ){ + tplName="tpl/cust_bill_tpl.docx"; + } + // 空运 + else if("2".equals(tplType) ){ + tplName="tpl/cust_tax_bill_tpl.docx"; + } + + try { + OutputStream outputStream = response.getOutputStream(); + InputStream fis = new ClassPathResource(tplName).getInputStream(); + /*1.根据模板生成文档*/ + String fileName = URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(), "UTF-8"); + + // 填充模版数据 + LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); + Configure config = Configure.builder().bind("feeList", policy).build(); + + Map fillMap = new HashMap<>(); + fillMap.put("productName", emisWaybillOld.getProductTypeName()); + fillMap.put("sendDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, emisWaybillOld.getSendDate())); + + 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("goodsInfo", emisWaybillOld.getGoodsInfo()); + fillMap.put("parcelQty", emisWaybillOld.getParcelQty()); + fillMap.put("settlementWeight", emisWaybillOld.getSettlementWeight()); + fillMap.put("productTypeName", emisWaybillOld.getProductTypeName()); + + 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("sendProvinceName", emisWaybillOld.getSendProvinceName()); + + fillMap.put("recvProvinceName", emisWaybillOld.getReceiveProvinceName()); + fillMap.put("recvCityName", emisWaybillOld.getReceiveCityName()); + + BigDecimal dutyFee = BigDecimal.ZERO; + String dutyFeeCurrency = "CNY"; + + EmisSettleSubBill billItem = getSettleSubBillBySubBillNo(emisWaybillOld.getBillCode()); + List feeItemList = billItem.getFeeitemList(); + List> listMap = new ArrayList<>(); + if (!CollectionUtils.isEmpty(feeItemList)) { + for (EmisSettleSubBillFeeitem feeitem : feeItemList) { + Map voMap = new HashMap<>(); + voMap.put("feeName", feeitem.getFeeName()); + voMap.put("fee", feeitem.getBillFee().stripTrailingZeros().toPlainString()); + voMap.put("currency", feeitem.getCurrency()); + listMap.add(voMap); + + if("2004".equals(feeitem.getFeeCode())){ + dutyFee=feeitem.getBillFee(); + dutyFeeCurrency = feeitem.getCurrency(); + } + } + } + fillMap.put("feeList", listMap); + fillMap.put("totalFee", billItem.getBillFee().stripTrailingZeros().toPlainString()); + fillMap.put("dutyFee", dutyFee.stripTrailingZeros().toPlainString()); + fillMap.put("dutyFeeCurrency", dutyFeeCurrency); + + // 生成模版 + 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()); + } + + } + + /** * 查询结算子账单 * 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 2f53ef14b..34f860978 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 @@ -1364,6 +1364,8 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb } + + /** * 下单接口 * @param emisWaybillSave diff --git a/emis-biz/src/main/resources/tpl/cust_bill_tpl.docx b/emis-biz/src/main/resources/tpl/cust_bill_tpl.docx new file mode 100644 index 000000000..39205b2d3 Binary files /dev/null and b/emis-biz/src/main/resources/tpl/cust_bill_tpl.docx differ diff --git a/emis-biz/src/main/resources/tpl/cust_tax_bill_tpl.docx b/emis-biz/src/main/resources/tpl/cust_tax_bill_tpl.docx new file mode 100644 index 000000000..d07f6b931 Binary files /dev/null and b/emis-biz/src/main/resources/tpl/cust_tax_bill_tpl.docx differ