md
This commit is contained in:
parent
27565d5fed
commit
e5a9f6f037
@ -37,6 +37,7 @@ import com.xdadan.erp.emis.domain.exception.EmisBizError;
|
||||
import com.xdadan.erp.emis.domain.vo.*;
|
||||
import com.xdadan.erp.emis.service.*;
|
||||
import com.xdadan.erp.emis.service.print.IXddTplPrint;
|
||||
import com.xdadan.erp.emis.service.print.tanex.TanexSubBillPrintImpl;
|
||||
import com.xdadan.erp.emis.service.print.tanex.TanexTplPrintImpl;
|
||||
import com.xdadan.erp.emis.utils.PrintUtils;
|
||||
import com.xdadan.erp.emis.utils.WaybillHelper;
|
||||
@ -693,19 +694,31 @@ public class EmisWaybillController extends EmisBaseController
|
||||
if(tplCodeArr.length>0){
|
||||
for (String tpCodeItem:tplCodeArr) {
|
||||
if("TAN-GC-130".equals(tpCodeItem)) {
|
||||
|
||||
// 循环获取主单信息
|
||||
String billSubCodeAllStr="";
|
||||
String[] billCodeArr = billCode.split(",");
|
||||
if(billCodeArr.length>0){
|
||||
IXddTplPrint xtp = new TanexSubBillPrintImpl();
|
||||
for (String billCodeItem:billCodeArr) {
|
||||
EmisWaybill emisWaybill= emisBaseService.getWaybillByBillCode(billCodeItem);
|
||||
billSubCodeAllStr=billSubCodeAllStr+emisWaybill.getBillCodeSub()+",";
|
||||
// EmisWaybill emisWaybill= emisBaseService.getWaybillByBillCode(billCodeItem);
|
||||
// billSubCodeAllStr=billSubCodeAllStr+emisWaybill.getBillCodeSub()+",";
|
||||
|
||||
Map<String, Object> order = emisBaseService.getWaybillPrintOrder(billCodeItem, billCodeRange,tpCodeItem, "zh", "",printManCode);
|
||||
String pdfBase64Data=xtp.genPNGBase64(order);
|
||||
JSONObject jObj=new JSONObject();
|
||||
jObj.put("result","success");
|
||||
jObj.put("billCodeItem",billCodeItem);
|
||||
jObj.put("file",pdfBase64Data);
|
||||
|
||||
fileArrAll.add(jObj);
|
||||
}
|
||||
}
|
||||
|
||||
String strArry = PrintUtils.getPdfByBillCode(billSubCodeAllStr, tpCodeItem, printManCode);
|
||||
JSONArray fileArr = JSONArray.parseArray(strArry);
|
||||
fileArrAll.addAll(fileArr);
|
||||
|
||||
// String strArry = PrintUtils.getPdfByBillCode(billSubCodeAllStr, tpCodeItem, printManCode);
|
||||
// JSONArray fileArr = JSONArray.parseArray(strArry);
|
||||
// fileArrAll.addAll(fileArr);
|
||||
}else{
|
||||
// 直接获取
|
||||
String strArry = PrintUtils.getPdfByBillCode(billCode, tpCodeItem, printManCode);
|
||||
|
||||
@ -14,4 +14,6 @@ public interface IXddTplPrint {
|
||||
|
||||
public String genPNGBase64(Map<String, Object> order) throws Exception;
|
||||
|
||||
public String genPDFBase64(Map<String, Object> order) throws Exception;
|
||||
|
||||
}
|
||||
|
||||
@ -13,6 +13,12 @@ public class ItemCell {
|
||||
|
||||
int fontSize;
|
||||
|
||||
int left;
|
||||
int top;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
boolean isBold;
|
||||
|
||||
// Element.ALIGN_CENTER
|
||||
@ -33,7 +39,7 @@ public class ItemCell {
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
this.fontSize = fontSize;
|
||||
this.isBold = false;
|
||||
this.isBold = isBold;
|
||||
this.alignment = Element.ALIGN_LEFT;
|
||||
this.objType = objType;
|
||||
}
|
||||
@ -86,4 +92,36 @@ public class ItemCell {
|
||||
public void setAlignment(int alignment) {
|
||||
this.alignment = alignment;
|
||||
}
|
||||
|
||||
public int getLeft() {
|
||||
return left;
|
||||
}
|
||||
|
||||
public void setLeft(int left) {
|
||||
this.left = left;
|
||||
}
|
||||
|
||||
public int getTop() {
|
||||
return top;
|
||||
}
|
||||
|
||||
public void setTop(int top) {
|
||||
this.top = top;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return width;
|
||||
}
|
||||
|
||||
public void setWidth(int width) {
|
||||
this.width = width;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return height;
|
||||
}
|
||||
|
||||
public void setHeight(int height) {
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,265 @@
|
||||
package com.xdadan.erp.emis.service.print.tanex;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.itextpdf.text.Element;
|
||||
import com.xdadan.erp.common.core.domain.AjaxResult;
|
||||
import com.xdadan.erp.common.utils.DateUtils;
|
||||
import com.xdadan.erp.emis.service.print.IXddTplPrint;
|
||||
import com.xdadan.erp.emis.service.print.ItemCell;
|
||||
import com.xdadan.erp.emis.service.print.XddBasePrint;
|
||||
import com.xdadan.erp.emis.utils.sensitive.Convert;
|
||||
import org.apache.commons.collections.MapUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.pdfbox.pdmodel.PDDocument;
|
||||
import org.apache.pdfbox.rendering.ImageType;
|
||||
import org.apache.pdfbox.rendering.PDFRenderer;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
|
||||
public class TanexSubBillPrintImpl extends XddBasePrint {
|
||||
|
||||
/**
|
||||
* 模版文件
|
||||
*/
|
||||
private static String tplName="/Users/alan/work/git/tanex56/emis-service/emis-biz/src/main/resources/tpl/tanex_zd_tpl.pdf";
|
||||
|
||||
/**
|
||||
* 单元条目配置
|
||||
* @param orderMap
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
protected ArrayList<ItemCell> getItemCelconfig(Map<String, Object> orderMap) {
|
||||
ArrayList<ItemCell> printItems = new ArrayList<>();
|
||||
|
||||
String package3dm = "";
|
||||
String packageWJC = "";
|
||||
|
||||
String pdfInfo =MapUtils.getString(orderMap,"pdfInfo","");
|
||||
if(!StringUtils.isEmpty(pdfInfo)) {
|
||||
String[] pdfInfoArr = pdfInfo.split("]");
|
||||
if (pdfInfoArr.length > 0) {
|
||||
package3dm = pdfInfoArr[0].replace("[", "");
|
||||
packageWJC = pdfInfoArr[1].replace("[", "");
|
||||
}
|
||||
}
|
||||
|
||||
// 设置打印参数信息
|
||||
String orderSn="订单号:"+MapUtils.getString(orderMap,"order_sn","");
|
||||
printItems.add(new ItemCell("package3dm",package3dm,12,true,Element.ALIGN_CENTER,"Text"));
|
||||
printItems.add(new ItemCell("packageWJC",packageWJC,16,true,Element.ALIGN_CENTER,"Text"));
|
||||
printItems.add(new ItemCell("orderSn", orderSn,6,true,"Text"));
|
||||
|
||||
String logisticNo=""+MapUtils.getString(orderMap,"ydSn","");
|
||||
printItems.add(new ItemCell("logisticNo", logisticNo,7,true,Element.ALIGN_CENTER,"Text"));
|
||||
|
||||
// 条码显示
|
||||
printItems.add(new ItemCell("barcodeImg1", MapUtils.getString(orderMap,"ydSn",""),1,true,"BarCode"));
|
||||
// printItems.add(new ItemCell("barcodeImg2", MapUtils.getString(orderMap,"yd_sn",""),22,true,"BarCode"));
|
||||
|
||||
String mobile=MapUtils.getString(orderMap,"mobile","");
|
||||
// mobile= Convert.mobile(mobile);
|
||||
// String address= Convert.address(address);
|
||||
String consignee=MapUtils.getString(orderMap,"consignee","");
|
||||
// consignee= Convert.chineseNameFirst(consignee);
|
||||
|
||||
printItems.add(new ItemCell("company", MapUtils.getString(orderMap,"company",""),7,true,"Text"));
|
||||
printItems.add(new ItemCell("consignee", consignee,7,true,"Text"));
|
||||
printItems.add(new ItemCell("mobile", mobile,7,true,"Text"));
|
||||
printItems.add(new ItemCell("address", MapUtils.getString(orderMap,"address",""),7,true,"Text"));
|
||||
|
||||
String goodsInfo=""+MapUtils.getString(orderMap,"goodsInfo","");
|
||||
printItems.add(new ItemCell("goodsInfo", goodsInfo,7,true,"Text"));
|
||||
|
||||
String parcelQty = MapUtils.getString(orderMap,"subSeqNum","")+
|
||||
"/"+MapUtils.getString(orderMap,"parcelQty","")
|
||||
+"|"+MapUtils.getString(orderMap,"billWeight","")+"kg"
|
||||
+"|"+MapUtils.getString(orderMap,"totalVolume","")+"m3";
|
||||
printItems.add(new ItemCell("parcelQty", parcelQty,7,true,Element.ALIGN_CENTER,"Text"));
|
||||
printItems.add(new ItemCell("sendDate", MapUtils.getString(orderMap,"sendDate",""),7,true,"Text"));
|
||||
printItems.add(new ItemCell("packType", MapUtils.getString(orderMap,"packType",""),7,true,"Text"));
|
||||
printItems.add(new ItemCell("paymentType", MapUtils.getString(orderMap,"paymentType",""),7,true,"Text"));
|
||||
printItems.add(new ItemCell("dispatchType", MapUtils.getString(orderMap,"dispatchType",""),7,true,"Text"));
|
||||
printItems.add(new ItemCell("shortLogisticNo", MapUtils.getString(orderMap,"shortLogisticNo",""),20,true,Element.ALIGN_CENTER,"Text"));
|
||||
|
||||
String printInfo=""+MapUtils.getString(orderMap,"printDate","")
|
||||
+ "/" +MapUtils.getString(orderMap,"printMan","")
|
||||
+ "/" +MapUtils.getString(orderMap,"printCount","");
|
||||
printItems.add(new ItemCell("printInfo", printInfo,7,true,"Text"));
|
||||
|
||||
String remark="备注:"+MapUtils.getString(orderMap,"remark","");
|
||||
printItems.add(new ItemCell("remark", remark,7,true,"Text"));
|
||||
|
||||
String extData =MapUtils.getString(orderMap,"extData","");
|
||||
if(!StringUtils.isEmpty(extData)){
|
||||
// 解析gson数据
|
||||
try
|
||||
{
|
||||
Map mapExtData = JSON.parseObject(extData,Map.class);
|
||||
// printItems.add(new ItemCell("k1", MapUtils.getString(mapExtData,"k1",""),8,true,"Text"));
|
||||
// printItems.add(new ItemCell("k2", MapUtils.getString(mapExtData,"k2",""),8,true,"Text"));
|
||||
printItems.add(new ItemCell("k3", MapUtils.getString(mapExtData,"k3",""),15,true,Element.ALIGN_CENTER,"Text"));
|
||||
// printItems.add(new ItemCell("k4", MapUtils.getString(mapExtData,"k4",""),8,true,"Text"));
|
||||
// printItems.add(new ItemCell("k5", MapUtils.getString(mapExtData,"k5",""),8,true,"Text"));
|
||||
// printItems.add(new ItemCell("k6", MapUtils.getString(mapExtData,"k6",""),8,true,"Text"));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
return printItems;
|
||||
}
|
||||
|
||||
/**
|
||||
* 主要控制模版的字体显示
|
||||
* @param orderMap
|
||||
* @param os
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
@Override
|
||||
public AjaxResult genPDF(Map<String, Object> orderMap, OutputStream os) throws Exception {
|
||||
AjaxResult ar = new AjaxResult();
|
||||
|
||||
ClassPathResource classPathResource = new ClassPathResource(tplName);
|
||||
// InputStream tplInStream = classPathResource.getInputStream();
|
||||
InputStream tplInStream = new FileInputStream(new File(tplName));
|
||||
//
|
||||
// 生成pdf文件
|
||||
genPdfByTpl(getItemCelconfig(orderMap),tplInStream,os);
|
||||
|
||||
return ar;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public AjaxResult genPNG(Map<String, Object> order, OutputStream os) throws Exception {
|
||||
AjaxResult ar = new AjaxResult();
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
genPDF(order, bos);
|
||||
PDDocument document = PDDocument.load(bos.toByteArray());
|
||||
PDFRenderer renderer = new PDFRenderer(document);
|
||||
BufferedImage bufferedImage = renderer.renderImageWithDPI(0, 200, ImageType.RGB);
|
||||
ImageIO.write(bufferedImage, "png", os);
|
||||
return ar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String genPNGBase64(Map<String, Object> order) throws Exception {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
|
||||
// 生成pdf
|
||||
genPDF(order,bos);
|
||||
PDDocument document = PDDocument.load(bos.toByteArray());
|
||||
// bos.close();
|
||||
PDFRenderer renderer = new PDFRenderer(document);
|
||||
BufferedImage bufferedImage = renderer.renderImageWithDPI(0, 200, ImageType.RGB);
|
||||
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
ImageIO.write(bufferedImage, "jpg", out);
|
||||
|
||||
Base64.Encoder encoder = Base64.getEncoder();
|
||||
|
||||
String base64Str = "data:image/jpg;base64,"+encoder.encodeToString(out.toByteArray());
|
||||
System.out.println(base64Str);
|
||||
|
||||
return base64Str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String genPDFBase64(Map<String, Object> order) throws Exception {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
// 生成pdfbase64
|
||||
genPDF(order,bos);
|
||||
byte[] pdfBytes = bos.toByteArray();
|
||||
String pdfBase64Str = Base64.getEncoder().encodeToString(pdfBytes);
|
||||
return pdfBase64Str;
|
||||
}
|
||||
|
||||
|
||||
public static void testPrint(int i) throws Exception {
|
||||
|
||||
// String newPDFPath = "/Users/alan/Downloads/ynmb_blank_t21.pdf";
|
||||
String newPDFPath = "/Users/alan/Downloads/ynmb_blank_t_x"+i+".png";
|
||||
FileOutputStream out = new FileOutputStream(newPDFPath);//输出流
|
||||
|
||||
|
||||
Map<String,Object> order=new HashMap<>();
|
||||
order.put("orderSn", "DT20210901001");
|
||||
order.put("ydSn", "SF1374689807723");
|
||||
order.put("kdgs", "TANEX");
|
||||
order.put("pdfInfo", "[山东淄博-胡志明][越南DN]");
|
||||
// order.put("packageWJC", ".");
|
||||
// order.put("address", Convert.address("上海市黄浦区河南南路1009弄3号902室上海市黄浦区河南南路1009弄3号902室上海市黄浦区河南南路1009弄3号902室"));
|
||||
order.put("address", "上海市黄浦区河南南路1009弄3号902室上海市黄浦区河南南路1009弄3号902室上海市黄浦区河南南路1009弄3号902室");
|
||||
order.put("company", "SDSDS");
|
||||
order.put("mobile", Convert.mobile("13818228246"));
|
||||
order.put("consignee", Convert.chineseNameFirst("张三"));
|
||||
|
||||
// order.put("consigneeAndMobile", Convert.chineseNameFirst("张三"+" "+"13818228246"));
|
||||
order.put("send_address", "Vancouver");
|
||||
order.put("send_company", "2324");
|
||||
order.put("send_mobile", "1604-683-1088");
|
||||
order.put("send_person", "Vancouver");
|
||||
order.put("extData", "{\"k1\":\"阿尔巴尼亚\",\"k2\":\"阿尔巴尼亚快递\",\"k3\":\"阿尔巴尼亚国际特快\",\"k4\":\"1-10工作日\",\"k5\":\"阿尔AL\",\"k6\":\"山东淄博-阿尔巴尼亚地拉那\"}");
|
||||
// order.put("sendPersonAndMobile", "Vancouver"+" "+"1604-683-1088");
|
||||
order.put("goodsInfo", "日常用品");
|
||||
order.put("parcelQty", "1");
|
||||
order.put("packType", "纸箱");
|
||||
order.put("paymentType", "现金");
|
||||
order.put("dispatchType", "派送");
|
||||
order.put("shortLogisticNo", "123213");
|
||||
order.put("remark", "test");
|
||||
order.put("billWeight", "12");
|
||||
order.put("totalVolume", "12");
|
||||
order.put("subSeqNum", "1");
|
||||
order.put("sendDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date()));
|
||||
order.put("printDay", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD,new Date()));
|
||||
order.put("printDate", DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,new Date()));
|
||||
order.put("printMan", "12321");
|
||||
order.put("printCount", 1);
|
||||
|
||||
ByteArrayOutputStream os = new ByteArrayOutputStream();
|
||||
|
||||
IXddTplPrint xtp = new TanexSubBillPrintImpl();
|
||||
// xtp.genPDF(order,os);
|
||||
// xtp.genPNG(order,out);
|
||||
|
||||
// 生成pdf base64
|
||||
// byte[] pdfBytes = os.toByteArray();
|
||||
// String pdfBase64Str = Base64.getEncoder().encodeToString(pdfBytes);
|
||||
String pdfBase64Str =xtp.genPDFBase64(order);
|
||||
System.out.println(pdfBase64Str);
|
||||
|
||||
// xtp.genPNGBase64(order);
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
try {
|
||||
|
||||
for(int i=0;i<1;i++){
|
||||
testPrint(i);
|
||||
}
|
||||
|
||||
|
||||
// xtp.testPdfPrint("/Users/alan/work/git/doitinfo/ai/logistic/src/main/resources/print_tpl/ynmb_blank.pdf","/Users/alan/Downloads/ynmb_blank_t21.pdf");
|
||||
// testPdfPrint("/Users/alan/work/git/doitinfo/ai/logistic/src/main/resources/print_tpl/ynmb_blank.pdf","/Users/alan/Downloads/ynmb_blank_t21.pdf");
|
||||
// testPdfPrint2Png("/Users/alan/work/git/doitinfo/ai/logistic/src/main/resources/print_tpl/lt_blank_bd.pdf","/Users/alan/Downloads/ynmb_blank_t10.png");
|
||||
// testPdfPrint2Png("/Users/alan/Downloads/ynmb_blank_t21.pdf","/Users/alan/Downloads/ynmb_blank_x1.png");
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -16,10 +16,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
@ -30,7 +27,8 @@ public class TanexTplPrintImpl extends XddBasePrint {
|
||||
/**
|
||||
* 模版文件
|
||||
*/
|
||||
private static String tplName="tpl/tanex_sd_2.pdf";
|
||||
// private static String tplName="tpl/tanex_sd_2.pdf";
|
||||
private static String tplName="/Users/alan/work/git/tanex56/emis-service/emis-biz/src/main/resources/tpl/tanex_zd_tpl.pdf";
|
||||
// private static String tplName="/Users/alan/work/git/doitinfo/ai/logistic/src/main/resources/print_tpl/tanex/tanex_sd_2.pdf";
|
||||
|
||||
/**
|
||||
@ -126,9 +124,9 @@ public class TanexTplPrintImpl extends XddBasePrint {
|
||||
AjaxResult ar = new AjaxResult();
|
||||
|
||||
ClassPathResource classPathResource = new ClassPathResource(tplName);
|
||||
InputStream tplInStream = classPathResource.getInputStream();
|
||||
// InputStream tplInStream = new FileInputStream(new File(tplName));
|
||||
|
||||
// InputStream tplInStream = classPathResource.getInputStream();
|
||||
InputStream tplInStream = new FileInputStream(new File(tplName));
|
||||
//
|
||||
// 生成pdf文件
|
||||
genPdfByTpl(getItemCelconfig(orderMap),tplInStream,os);
|
||||
|
||||
@ -149,6 +147,17 @@ public class TanexTplPrintImpl extends XddBasePrint {
|
||||
return ar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String genPDFBase64(Map<String, Object> order) throws Exception {
|
||||
|
||||
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
||||
// 生成pdfbase64
|
||||
genPDF(order,bos);
|
||||
byte[] pdfBytes = bos.toByteArray();
|
||||
String pdfBase64Str = Base64.getEncoder().encodeToString(pdfBytes);
|
||||
return pdfBase64Str;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String genPNGBase64(Map<String, Object> order) throws Exception {
|
||||
|
||||
@ -207,7 +216,7 @@ public class TanexTplPrintImpl extends XddBasePrint {
|
||||
|
||||
IXddTplPrint xtp = new TanexTplPrintImpl();
|
||||
xtp.genPDF(order,os);
|
||||
// xtp.genPNG(order,os);
|
||||
xtp.genPNG(order,out);
|
||||
|
||||
// 生成pdf base64
|
||||
byte[] pdfBytes = os.toByteArray();
|
||||
|
||||
BIN
emis-biz/src/main/resources/tpl/tanex_zd_tpl.pdf
Normal file
BIN
emis-biz/src/main/resources/tpl/tanex_zd_tpl.pdf
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user