This commit is contained in:
linfso 2025-01-11 15:51:24 +08:00
parent 7edb55f18f
commit 9c59416fd6
2 changed files with 202 additions and 5 deletions

View File

@ -3946,8 +3946,8 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
return emisWaybillMapper.selectPrintWaybillList(emisWaybill);
}
@Override
public void genWarehouseInTplFileByOms(HttpServletResponse response, String orderSn) throws EmisBizError {
@Deprecated
public void tmp_genWarehouseInTplFileByOms(HttpServletResponse response, String orderSn) throws EmisBizError {
if(StringUtils.isEmpty(orderSn)){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空");
@ -4103,9 +4103,8 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
}
@Override
public void genWarehouseInTplFile(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError {
public void genWarehouseInTplFileByOms(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError {
if(StringUtils.isEmpty(orderSn)){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空");
@ -4153,6 +4152,7 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
tplName="tpl/ws_ls_in_tpl.docx";
}
BigDecimal totalPrice=BigDecimal.ZERO;
try {
OutputStream outputStream = response.getOutputStream();
InputStream fis = new ClassPathResource(tplName).getInputStream();
@ -4168,6 +4168,17 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
queryDeclareGoods.setWaybillId(emisWaybillOld.getId());
declareGoodsList=emisWaybillDeclareGoodsMapper.selectEmisWaybillDeclareGoodsList(queryDeclareGoods);
if(!CollectionUtils.isEmpty(declareGoodsList)){
for (EmisWaybillDeclareGoods itemGoods:declareGoodsList) {
itemGoods.setPrice(itemGoods.getPrice().stripTrailingZeros());
itemGoods.setCargoQty(itemGoods.getCargoQty().stripTrailingZeros());
if(itemGoods.getPrice()!=null) {
totalPrice = totalPrice.add(itemGoods.getPrice())
}
}
}
}
// 非快递不需要明细
else {
@ -4239,7 +4250,193 @@ public class EmisWaybillServiceImpl extends EmisBaseService implements IEmisWayb
fillMap.put("barcode", Pictures.ofBufferedImage(barcodeImageBuffer, PictureType.JPEG).size(width, height).create());
fillMap.put("cargoList", declareGoodsList);
// fillMap.put("cargoList", emisWaybillOld.getCargoList());
fillMap.put("totalPrice", totalPrice.stripTrailingZeros());
// 生成模版
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());
}
}
@Override
public void genWarehouseInTplFile(HttpServletResponse response, String orderSn,String fileType) throws EmisBizError {
if(StringUtils.isEmpty(orderSn)){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单号为空");
}
EmisWaybill emisWaybillOld = this.selectEmisWaybillByOrderSn(orderSn);
if(emisWaybillOld==null){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"订单不存在");
}
if(OrderStatus.CANCEL.statusCode.equals(emisWaybillOld.getOrderStatus())){
throw new EmisBizError(EmisBizErrorType.FAIL,"订单已取消");
}
if(!"1".equals(emisWaybillOld.getPickupMethod()) && !"3".equals(emisWaybillOld.getPickupMethod())){
throw new EmisBizError(EmisBizErrorType.FAIL,"取件方式非仓库收货/整柜提货");
}
if(StringUtils.isEmpty(emisWaybillOld.getIntoWarehouseBillCode())){
throw new EmisBizError(EmisBizErrorType.NOT_EXISTS,"进仓预报单号为空");
}
// 根据不同线路使用不同模版
String tplName="tpl/ws_ls_in_tpl.docx";
EmisTransLine emisTransLine = getTransLineByCode(emisWaybillOld.getTransLineType());
// 快递
if("1".equals(emisTransLine.getTransType()) ){
tplName="tpl/ws_kd_in_tpl.docx";
}
// 空运
else if("2".equals(emisTransLine.getTransType()) ){
tplName="tpl/ws_air_in_tpl.docx";
}
// 陆运
else if("3".equals(emisTransLine.getTransType()) ){
tplName="tpl/ws_ls_in_tpl.docx";
}
// 海运
else if("4".equals(emisTransLine.getTransType()) ){
tplName="tpl/ws_ls_in_tpl.docx";
}
// 铁路
else if("4".equals(emisTransLine.getTransType()) ){
tplName="tpl/ws_ls_in_tpl.docx";
}
BigDecimal totalPrice=BigDecimal.ZERO;
try {
OutputStream outputStream = response.getOutputStream();
InputStream fis = new ClassPathResource(tplName).getInputStream();
/*1.根据模板生成文档*/
String fileName = URLEncoder.encode(emisWaybillOld.getIntoWarehouseBillCode(), "UTF-8");
List<EmisWaybillDeclareGoods> declareGoodsList = null;
// 快递需要明细
if("1".equals(emisTransLine.getTransType()) ){
// 货物清单 使用货物总览
EmisWaybillDeclareGoods queryDeclareGoods = new EmisWaybillDeclareGoods();
queryDeclareGoods.setWaybillId(emisWaybillOld.getId());
declareGoodsList=emisWaybillDeclareGoodsMapper.selectEmisWaybillDeclareGoodsList(queryDeclareGoods);
if(!CollectionUtils.isEmpty(declareGoodsList)){
for (EmisWaybillDeclareGoods itemGoods:declareGoodsList) {
itemGoods.setPrice(itemGoods.getPrice().stripTrailingZeros());
itemGoods.setCargoQty(itemGoods.getCargoQty().stripTrailingZeros());
if(itemGoods.getPrice()!=null) {
totalPrice = totalPrice.add(itemGoods.getPrice())
}
}
}
}
// 非快递不需要明细
else {
declareGoodsList = new ArrayList<EmisWaybillDeclareGoods>();
EmisWaybillDeclareGoods cargoDeclareGoods = new EmisWaybillDeclareGoods();
cargoDeclareGoods.setGoodsName(emisWaybillOld.getGoodsInfo());
cargoDeclareGoods.setWeight(BigDecimal.valueOf(Double.valueOf(emisWaybillOld.getBillWeight().stripTrailingZeros().toPlainString())));
cargoDeclareGoods.setVolume(BigDecimal.valueOf(Double.valueOf(emisWaybillOld.getTotalVolume().stripTrailingZeros().toPlainString())));
cargoDeclareGoods.setLength(BigDecimal.ZERO);
cargoDeclareGoods.setWidth(BigDecimal.ZERO);
cargoDeclareGoods.setHeight(BigDecimal.ZERO);
cargoDeclareGoods.setCargoQty(BigDecimal.valueOf(emisWaybillOld.getParcelQty()));
declareGoodsList.add(cargoDeclareGoods);
}
// 生成条码
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();
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<String, Object> 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());
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", declareGoodsList);
fillMap.put("totalPrice", totalPrice.stripTrailingZeros());
// 生成模版
XWPFTemplate template = XWPFTemplate.compile(fis, config).render(fillMap);