This commit is contained in:
linfso 2024-07-28 14:28:30 +08:00
parent 888f8317dc
commit f18d6b698a
2 changed files with 82 additions and 78 deletions

View File

@ -193,6 +193,6 @@ public interface IEmisWaybillService
public List<EmisWaybill> selectPrintWaybillList(EmisWaybill emisWaybill); public List<EmisWaybill> selectPrintWaybillList(EmisWaybill emisWaybill);
public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError, IOException ; public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError ;
} }

View File

@ -2212,7 +2212,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
} }
@Override @Override
public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError, IOException { public void genWarehouseInTplFile(HttpServletResponse response, String orderSn) throws EmisBizError {
if(StringUtils.isEmpty(orderSn)){ if(StringUtils.isEmpty(orderSn)){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空"); throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空");
@ -2260,42 +2260,43 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
tplName="tpl/ws_ls_in_tpl.docx"; tplName="tpl/ws_ls_in_tpl.docx";
} }
OutputStream outputStream=response.getOutputStream(); try {
OutputStream outputStream = response.getOutputStream();
InputStream fis = new ClassPathResource(tplName).getInputStream(); InputStream fis = new ClassPathResource(tplName).getInputStream();
/*1.根据模板生成文档*/ /*1.根据模板生成文档*/
String fileName= URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(),"UTF-8"); String fileName = URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(), "UTF-8");
// 货物清单 // 货物清单
EmisWaybillCargo queryCargo = new EmisWaybillCargo(); EmisWaybillCargo queryCargo = new EmisWaybillCargo();
queryCargo.setWaybillId(emisWaybillOld.getId()); queryCargo.setWaybillId(emisWaybillOld.getId());
List<EmisWaybillCargo> cargoList=emisWaybillCargoMapper.selectEmisWaybillCargoList(queryCargo); List<EmisWaybillCargo> cargoList = emisWaybillCargoMapper.selectEmisWaybillCargoList(queryCargo);
// 生成条码 // 生成条码
int width=400; int width = 400;
int height=70; int height = 70;
BufferedImage barcodeImageBuffer = BarcodeUtils.getBarCodeWithWord(emisWaybillOld.getIntoWarehouseBillCode(),width,height,100); BufferedImage barcodeImageBuffer = BarcodeUtils.getBarCodeWithWord(emisWaybillOld.getIntoWarehouseBillCode(), width, height, 100);
// 填充模版数据 // 填充模版数据
LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy(); LoopRowTableRenderPolicy policy = new LoopRowTableRenderPolicy();
Configure config = Configure.builder().bind("cargoList", policy).build(); Configure config = Configure.builder().bind("cargoList", policy).build();
String customsEclaration=""; String customsEclaration = "";
if(!StringUtils.isEmpty(emisWaybillOld.getCustomsEclaration())){ if (!StringUtils.isEmpty(emisWaybillOld.getCustomsEclaration())) {
customsEclaration=DictUtils.getDictLabel("emis_declare_mode",emisWaybillOld.getCustomsEclaration()); customsEclaration = DictUtils.getDictLabel("emis_declare_mode", emisWaybillOld.getCustomsEclaration());
} }
String customsClear=""; String customsClear = "";
if(!StringUtils.isEmpty(emisWaybillOld.getCustomsClear())){ if (!StringUtils.isEmpty(emisWaybillOld.getCustomsClear())) {
customsClear=DictUtils.getDictLabel("emis_customs_clear",emisWaybillOld.getCustomsClear()); customsClear = DictUtils.getDictLabel("emis_customs_clear", emisWaybillOld.getCustomsClear());
} }
Map<String,Object> fillMap = new HashMap<>(); Map<String, Object> fillMap = new HashMap<>();
fillMap.put("wsInNo", emisWaybillOld.getIntoWarehouseBillCode()); fillMap.put("wsInNo", emisWaybillOld.getIntoWarehouseBillCode());
fillMap.put("country", emisWaybillOld.getReceiveCountryName()); fillMap.put("country", emisWaybillOld.getReceiveCountryName());
fillMap.put("warehouse", emisWaybillOld.getIntoWarehouseName()); fillMap.put("warehouse", emisWaybillOld.getIntoWarehouseName());
fillMap.put("productName", emisWaybillOld.getProductTypeName()); fillMap.put("productName", emisWaybillOld.getProductTypeName());
fillMap.put("estDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,emisWaybillOld.getPickStartDate()==null?emisWaybillOld.getOrderDate():emisWaybillOld.getPickStartDate())); fillMap.put("estDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, emisWaybillOld.getPickStartDate() == null ? emisWaybillOld.getOrderDate() : emisWaybillOld.getPickStartDate()));
fillMap.put("declareType", customsEclaration); fillMap.put("declareType", customsEclaration);
fillMap.put("eDeclareType", customsClear); fillMap.put("eDeclareType", customsClear);
fillMap.put("supplier", ""); fillMap.put("supplier", "");
@ -2328,21 +2329,24 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
fillMap.put("cargoList", emisWaybillOld.getCargoList()); fillMap.put("cargoList", emisWaybillOld.getCargoList());
// 生成模版 // 生成模版
XWPFTemplate template = XWPFTemplate.compile(fis,config).render(fillMap); XWPFTemplate template = XWPFTemplate.compile(fis, config).render(fillMap);
response.setContentType("application/octet-stream"); response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;fileName="+ fileName +".pdf"); response.setHeader("Content-Disposition", "attachment;fileName=" + fileName + ".pdf");
ByteArrayOutputStream bos=new ByteArrayOutputStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream();
template.write(bos); template.write(bos);
ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
DocUtils.wordToPdf(bis, outputStream); DocUtils.wordToPdf(bis, outputStream);
response.flushBuffer(); response.flushBuffer();
IOUtils.closeQuietly(fis); IOUtils.closeQuietly(fis);
IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(outputStream);
}
catch (Exception ex){
throw new EmisBizError(EmisBizErrorType.FAIL,"生成进仓单出错:"+ ex.getMessage());
}
} }