diff --git a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/IXddTplPrint.java b/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/IXddTplPrint.java deleted file mode 100644 index 05e0fbc..0000000 --- a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/IXddTplPrint.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.xdadan.erp.oms2c.service.print; - -import com.xdadan.erp.oms.common.core.domain.AjaxResult; - -import java.io.OutputStream; -import java.util.Map; - -public interface IXddTplPrint { - - public AjaxResult genPDF(Map order, OutputStream os) throws Exception; - - public AjaxResult genPNG(Map order, OutputStream os) throws Exception; - - - public String genPNGBase64(Map order) throws Exception; - -} diff --git a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ItemCell.java b/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ItemCell.java deleted file mode 100644 index 6c37bd0..0000000 --- a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ItemCell.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.xdadan.erp.oms2c.service.print; - -import com.itextpdf.text.Element; - -/** - * 打印单元信息 - */ -public class ItemCell { - - String name; - - String value; - - int fontSize; - - boolean isBold; - -// Element.ALIGN_CENTER - int alignment; - - String objType; - - public ItemCell(String name, String value, int fontSize, boolean isBold, int alignment, String objType) { - this.name = name; - this.value = value; - this.fontSize = fontSize; - this.isBold = isBold; - this.alignment = alignment; - this.objType = objType; - } - - public ItemCell(String name, String value, int fontSize, boolean isBold, String objType) { - this.name = name; - this.value = value; - this.fontSize = fontSize; - this.isBold = false; - this.alignment = Element.ALIGN_LEFT; - this.objType = objType; - } - - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public int getFontSize() { - return fontSize; - } - - public void setFontSize(int fontSize) { - this.fontSize = fontSize; - } - - public boolean isBold() { - return isBold; - } - - public void setBold(boolean bold) { - isBold = bold; - } - - public String getObjType() { - return objType; - } - - public void setObjType(String objType) { - this.objType = objType; - } - - public int getAlignment() { - return alignment; - } - - public void setAlignment(int alignment) { - this.alignment = alignment; - } -} diff --git a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/XddBasePrint.java b/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/XddBasePrint.java deleted file mode 100644 index 8101315..0000000 --- a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/XddBasePrint.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.xdadan.erp.oms2c.service.print; - -import com.itextpdf.text.*; -import com.itextpdf.text.pdf.*; -import com.itextpdf.xmp.impl.Base64; -import com.xdadan.erp.oms2c.utils.BarcodeZxingUtil; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.lang3.StringUtils; - -import javax.imageio.ImageIO; -import java.awt.image.BufferedImage; -import java.io.*; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public abstract class XddBasePrint implements IXddTplPrint { - /** - * 抽象类 , 子类必须配置 - * @param orderMap - * @return - */ - protected abstract ArrayList getItemCelconfig(Map orderMap); - - protected void genPdfByTpl(ArrayList printItems, InputStream tplInStream, OutputStream pdfOutStream){ - PdfReader reader; - PdfStamper stamper; - try { - reader = new PdfReader(tplInStream);//读取pdf模板 - stamper = new PdfStamper(reader, pdfOutStream); - //方法二:使用iTextAsian.jar中的字体 - BaseFont baseFont = BaseFont.createFont("STSong-Light", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); -// Font font = new Font(baseFont); - AcroFields form = stamper.getAcroFields(); - form.addSubstitutionFont(baseFont); - - for(ItemCell itemCell:printItems){ - if("Text".equals(itemCell.getObjType())) { - addText(stamper, form, itemCell); - } - else if("BarCode".equals(itemCell.getObjType())) { - insertBarCodeImage(stamper, form, itemCell); - } - } - - stamper.setFormFlattening(true);//如果为false那么生成的PDF文件还能编辑,一定要设为true - stamper.close(); - } - catch (Exception ex){ - ex.printStackTrace(); - } - } - - protected void genPdfByTplBase64(ArrayList printItems, String tplBase64Data, OutputStream pdfOutStream){ - PdfReader reader; - PdfStamper stamper; - try { - String tplData = Base64.decode(tplBase64Data); - InputStream tplInStream = new ByteArrayInputStream(tplData.getBytes(Charset.forName("UTF-8"))); - reader = new PdfReader(tplInStream);//读取pdf模板 - stamper = new PdfStamper(reader, pdfOutStream); - //方法二:使用iTextAsian.jar中的字体 - BaseFont baseFont = BaseFont.createFont("STSong-Light", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED); -// Font font = new Font(baseFont); - AcroFields form = stamper.getAcroFields(); - form.addSubstitutionFont(baseFont); - - for(ItemCell itemCell:printItems){ - if("Text".equals(itemCell.getObjType())) { - addText(stamper, form, itemCell); - } - else if("BarCode".equals(itemCell.getObjType())) { - insertBarCodeImage(stamper, form, itemCell); - } - } - - stamper.setFormFlattening(true);//如果为false那么生成的PDF文件还能编辑,一定要设为true - stamper.close(); - } - catch (Exception ex){ - ex.printStackTrace(); - } - } - - - protected void insertBarCodeImage(PdfStamper stamper, AcroFields s, ItemCell itemCell) - { - try - { - List photograph = s.getFieldPositions(itemCell.getName()); - if(CollectionUtils.isEmpty(photograph)){ - return; - } - - Rectangle rect = photograph.get(0).position; - - float x = rect.getLeft(); - float y = rect.getBottom(); - -// BufferedImage outputImage = BarCode4jUtils.getBarCodeImage(mailNo,(int)rect.getWidth(),(int)rect.getHeight()); - BufferedImage outputImage = BarcodeZxingUtil.getBarCodeImage(itemCell.getValue(),(int)rect.getWidth()*4,(int)rect.getHeight()*4); -// BufferedImage outputImage = BarcodeZxingUtil.getBarCodeImage2(mailNo,(int)rect.getWidth(),(int)rect.getHeight()); - ByteArrayOutputStream baos = new ByteArrayOutputStream();//io流 - ImageIO.write(outputImage, "png", baos);//写入流中 - byte[] bytes = baos.toByteArray();//转换成字节 - Image image = Image.getInstance(bytes); - image.setAbsolutePosition(x,y); - // 禁止缩放 - image.scaleAbsolute(rect.getWidth(), rect.getHeight()); - PdfContentByte cb = stamper.getOverContent((int)photograph.get(0).page); - cb.addImage(image); - - } - catch (Exception e) { - e.printStackTrace(); - } - - } - - protected void addText(PdfStamper stamper, AcroFields s, ItemCell itemCell) throws IOException, DocumentException { - - if(StringUtils.isEmpty(itemCell.getValue())){ - return; - } -// BaseFont bf = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED); -// BaseFont bf = BaseFont.createFont("/font/simhei.ttf", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); - BaseFont bf = BaseFont.createFont("/font/simsun.ttf", BaseFont.IDENTITY_H,BaseFont.NOT_EMBEDDED); - - Font font = new Font(bf, itemCell.getFontSize(), itemCell.isBold()?Font.BOLD:Font.NORMAL); - -// Font font = new Font("微软雅黑", fontSize,Font.BOLD); - //Font font = FontFactory.getFont(FontFactory.COURIER, 20, Font.BOLD, BaseColor.RED); - List multiLinePosition = s.getFieldPositions(itemCell.getName()); - if(CollectionUtils.isEmpty(multiLinePosition)){ - return; - } - int page = multiLinePosition.get(0).page; - Rectangle rectangle = multiLinePosition.get(0).position; - float left = rectangle.getLeft(); - float right = rectangle.getRight(); - float top = rectangle.getTop(); - float bottom = rectangle.getBottom(); - PdfContentByte pdfContentByte = stamper.getOverContent(page); - ColumnText columnText = new ColumnText(pdfContentByte); - - Rectangle r = new Rectangle(left, bottom, right, top); - columnText.setSimpleColumn(r); - - //FontFactory.getFont(FontFactory.COURIER, 20, Font.BOLD, BaseColor.RED) - Chunk chunk = new Chunk(itemCell.getValue()); - Paragraph paragraph = new Paragraph(itemCell.getFontSize(), chunk); -// Paragraph paragraph = new Paragraph(chunk); - //paragraph.setSpacingBefore(16); - columnText.addText(paragraph); - // 设置字体,如果不设置添加的中文将无法显示 - paragraph.setFont(font); - paragraph.setAlignment(itemCell.alignment); - columnText.addElement(paragraph); - columnText.go(); - } - - - - public static void main(String[] args) throws IOException { - //String target = "/Users/zhiyu/Desktop/test/aaa_bin.bmp"; - String target = "/Users/alan/Downloads/banner_tanex.jpg"; - File file = new File(target); - BufferedImage image = ImageIO.read(file); - drawGraphic(0, 0, image); - } - - public static void drawGraphic(int start_x, int start_y, BufferedImage image) { - int width = image.getWidth(); - int height = image.getHeight(); - - int col = (width - 1) / 8 + 1; - - String str = ""; - byte[] arrayOfByte = new byte[width * height]; - - int h = 0; - //int b1 = 0; - int arrindex = 0; - //int m = 0; - - - while (h < height) { - for (int w = 0; w < width; w++) { - arrindex = h * col + w / 8; - System.out.println("w:" + w + ", h:" + h); - if ((image.getRGB(w, h) & 0xFFFFFF) < 3092271) { - int n = arrindex; - byte[] arrayOfByte1 = arrayOfByte; - - arrayOfByte1[n] = (byte) (arrayOfByte1[n] | 128 >> w % 8); - } else { - int n = arrindex; - byte[] arrayOfByte1 = arrayOfByte; - - arrayOfByte1[n] = (byte) (arrayOfByte1[n] & (128 >> w % 8 ^ 0xFFFFFFFF)); - } - } - ++h; - //if ((++h - b1) * col >= 1024 || h == height) { - // str = bbbb(aaaaaa(arrayOfByte, m, arrindex - m + 1)); - // m = arrindex + 1; - // String str1 = "EG " + col + " " + (h - b1) + " " + start_x + " " + (start_y + b1) + " " + str + "\r\n"; - // - // System.out.println(str1); - // //b(str1); - // b1 = h; - // k++; - //} - } - - str = toHexString(copy(arrayOfByte, 0, arrindex + 1)); - System.out.println(str); - - } - static String toHexString(byte[] paramArrayOfbyte) { - String str = ""; - for (int i = 0; i < paramArrayOfbyte.length; i++) { - String hex = Integer.toHexString(paramArrayOfbyte[i] & 0xFF); - if (hex.length() == 1) { - hex = '0' + hex; - } - str = str + hex; - } - return str; - } - - private static byte[] copy(byte[] paramArrayOfbyte, int start, int length) { - byte[] arrayOfByte = new byte[length]; - for (int i = 0; i < length; i++) { - arrayOfByte[i] = paramArrayOfbyte[start + i]; - } - return arrayOfByte; - } - - - -} diff --git a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ZPLConveterUtil.java b/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ZPLConveterUtil.java deleted file mode 100644 index 99c49e4..0000000 --- a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/ZPLConveterUtil.java +++ /dev/null @@ -1,381 +0,0 @@ -package com.xdadan.erp.oms2c.service.print; - -import lombok.extern.slf4j.Slf4j; -import org.apache.pdfbox.pdmodel.PDDocument; -import org.apache.pdfbox.rendering.ImageType; -import org.apache.pdfbox.rendering.PDFRenderer; - -import javax.imageio.ImageIO; -import java.awt.*; -import java.awt.image.BufferedImage; -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -@Slf4j -public class ZPLConveterUtil { - private static int blackLimit = 380; - private static int total; - private static int widthBytes; - /** - * 是否压缩 true=压缩 false=不压缩 - **/ - private static boolean isCompressHex = true; - private static Map mapCode = new HashMap(); - { - mapCode.put(1, "G"); - mapCode.put(2, "H"); - mapCode.put(3, "I"); - mapCode.put(4, "J"); - mapCode.put(5, "K"); - mapCode.put(6, "L"); - mapCode.put(7, "M"); - mapCode.put(8, "N"); - mapCode.put(9, "O"); - mapCode.put(10, "P"); - mapCode.put(11, "Q"); - mapCode.put(12, "R"); - mapCode.put(13, "S"); - mapCode.put(14, "T"); - mapCode.put(15, "U"); - mapCode.put(16, "V"); - mapCode.put(17, "W"); - mapCode.put(18, "X"); - mapCode.put(19, "Y"); - mapCode.put(20, "g"); - mapCode.put(40, "h"); - mapCode.put(60, "i"); - mapCode.put(80, "j"); - mapCode.put(100, "k"); - mapCode.put(120, "l"); - mapCode.put(140, "m"); - mapCode.put(160, "n"); - mapCode.put(180, "o"); - mapCode.put(200, "p"); - mapCode.put(220, "q"); - mapCode.put(240, "r"); - mapCode.put(260, "s"); - mapCode.put(280, "t"); - mapCode.put(300, "u"); - mapCode.put(320, "v"); - mapCode.put(340, "w"); - mapCode.put(360, "x"); - mapCode.put(380, "y"); - mapCode.put(400, "z"); - } - - /** - * the BufferedImage to String - * - * @param orginalImage - * @return - * @throws IOException - */ - private static String createBody(BufferedImage orginalImage) throws IOException { - StringBuffer sb = new StringBuffer(); - Graphics2D graphics = orginalImage.createGraphics(); - graphics.drawImage(orginalImage, 0, 0, null); - int height = orginalImage.getHeight(); - int width = orginalImage.getWidth(); - int rgb, red, green, blue, index=0; - char auxBinaryChar[] = {'0', '0', '0', '0', '0', '0', '0', '0'}; - widthBytes = width/8; - if(width%8>0){ - widthBytes= (((int)(width/8))+1); - } else { - widthBytes= width/8; - } - total = widthBytes*height; - for (int h = 0; h> 16 ) & 0x000000FF; - green = (rgb >> 8 ) & 0x000000FF; - blue = (rgb) & 0x000000FF; - char auxChar = '1'; - int totalColor = red + green + blue; - if(totalColor>blackLimit){ - auxChar = '0'; - } - auxBinaryChar[index] = auxChar; - index++; - if(index==8 || w==(width-1)){ - sb.append(fourByteBinary(new String(auxBinaryChar))); - auxBinaryChar = new char[]{'0', '0', '0', '0', '0', '0', '0', '0'}; - index=0; - } - } - sb.append("\n"); - } - return sb.toString(); - } - - - private static String fourByteBinary(String binaryStr){ - int decimal = Integer.parseInt(binaryStr,2); - if (decimal>15){ - return Integer.toString(decimal,16).toUpperCase(); - } else { - return "0" + Integer.toString(decimal,16).toUpperCase(); - } - } - - /** - * Image to zpl string data. - * - * @param image - * @return - * @throws IOException - */ - public String convertFromImg(BufferedImage image) throws IOException { - String cuerpo = createBody(image); - if (isCompressHex) { - cuerpo = encodeHexAscii(cuerpo, 20); - } - return headDoc() + cuerpo + footDoc(); - - } - - private static String encodeHexAscii(String code){ - int maxlinea = widthBytes * 2; - StringBuffer sbCode = new StringBuffer(); - StringBuffer sbLinea = new StringBuffer(); - String previousLine = null; - int counter = 1; - char aux = code.charAt(0); - boolean firstChar = false; - for(int i = 1; i< code.length(); i++ ){ - if(firstChar){ - aux = code.charAt(i); - firstChar = false; - continue; - } - if(code.charAt(i)=='\n'){ - if(counter>=maxlinea && aux=='0'){ - sbLinea.append(","); - } else if(counter>=maxlinea && aux=='F'){ - sbLinea.append("!"); - } else if (counter>20){ - int multi20 = (counter/20)*20; - int resto20 = (counter%20); - sbLinea.append(mapCode.get(multi20)); - if(resto20!=0){ - sbLinea.append(mapCode.get(resto20) + aux); - } else { - sbLinea.append(aux); - } - } else { - sbLinea.append(mapCode.get(counter) + aux); - if(mapCode.get(counter)==null){ - } - } - counter = 1; - firstChar = true; - if(sbLinea.toString().equals(previousLine)){ - sbCode.append(":"); - } else { - sbCode.append(sbLinea.toString()); - } - previousLine = sbLinea.toString(); - sbLinea.setLength(0); - continue; - } - if(aux == code.charAt(i)){ - counter++; - } else { - if(counter>20){ - int multi20 = (counter/20)*20; - int resto20 = (counter%20); - sbLinea.append(mapCode.get(multi20)); - if(resto20!=0){ - sbLinea.append(mapCode.get(resto20) + aux); - } else { - sbLinea.append(aux); - } - } else { - sbLinea.append(mapCode.get(counter) + aux); - } - counter = 1; - aux = code.charAt(i); - } - } - return sbCode.toString(); - } - - private String encodeHexAscii(String code,int number) { - int maxlinea = widthBytes * 2; - StringBuffer sbCode = new StringBuffer(); - StringBuffer sbLinea = new StringBuffer(); - String previousLine = null; - int counter = 1; - char aux = code.charAt(0); - boolean firstChar = false; - for (int i = 1; i < code.length(); i++) { - if (firstChar) { - aux = code.charAt(i); - firstChar = false; - continue; - } - if (code.charAt(i) == '\n') { - if (counter >= maxlinea && aux == '0') { - sbLinea.append(","); - } else if (counter >= maxlinea && aux == 'F') { - sbLinea.append("!"); - } else if (counter > number) { - int multi20 = (counter / number) * number; - int resto20 = (counter % number); - sbLinea.append(mapCode.get(multi20)); - if (resto20 != 0) { - sbLinea.append(mapCode.get(resto20) + aux); - } else { - sbLinea.append(aux); - } - } else { - sbLinea.append(mapCode.get(counter) + aux); - if (mapCode.get(counter) == null) { - } - } - counter = 1; - firstChar = true; - if (sbLinea.toString().equals(previousLine)) { - sbCode.append(":"); - } else { - sbCode.append(sbLinea.toString()); - } - previousLine = sbLinea.toString(); - sbLinea.setLength(0); - continue; - } - if (aux == code.charAt(i)) { - counter++; - } else { - if (counter > number) { - int multi20 = (counter / number) * number; - int resto20 = (counter % number); - sbLinea.append(mapCode.get(multi20)); - if (resto20 != 0) { - sbLinea.append(mapCode.get(resto20) + aux); - } else { - sbLinea.append(aux); - } - } else { - sbLinea.append(mapCode.get(counter) + aux); - } - counter = 1; - aux = code.charAt(i); - } - } - return sbCode.toString(); - } - - private static String headDoc(){ - String str = "^XA " + - "^FO0,0^GFA,"+ total + ","+ total + "," + widthBytes +", "; - return str; - } - - private static String footDoc(){ - String str = "^FS"+ - "^XZ"; - return str; - } - - public void setCompressHex(boolean compressHex) { - this.isCompressHex = compressHex; - } - public void setBlacknessLimitPercentage(int percentage){ - blackLimit = (percentage * 768 / 100); - } - - - /** - * PDF转ZPL格式 - * @param pdf pdf文件字节数组 - * @return 返回ZPL格式 - * @throws IOException - */ - public static String convertPdfToZpl(byte[] pdf) throws IOException { - PDDocument doc = PDDocument.load(pdf); - PDFRenderer renderer = new PDFRenderer(doc); - BufferedImage orginalImage = renderer.renderImageWithDPI(0, 200); - return ZPLConveterUtil.convertImgToZpl(orginalImage); - } - - /** - * PDF转ZPL格式(压缩会返回用null表示英文字母的字符串) - * @param pdfPath pdf文件路径 - * @return 返回ZPL格式 - * @throws IOException - */ - public static String convertPdfToZpl(String pdfPath) throws IOException { - PDDocument doc = PDDocument.load(new File(pdfPath)); - PDFRenderer renderer = new PDFRenderer(doc); - BufferedImage orginalImage = renderer.renderImageWithDPI(0, 200); - return ZPLConveterUtil.convertImgToZpl(orginalImage); - } - - /** - * PDF转ZPL格式(压缩不会返回用null表示的字符串,压缩的更彻底一点) - * @param pdfPath pdf文件路径 - * @return 返回ZPL格式 - */ - public static String convertPDFToZPL(String pdfPath) { - File sourceFile = new File(pdfPath); - PDDocument document = null; - try { - if (sourceFile.exists()) { - document = PDDocument.load(sourceFile); - PDFRenderer pdfRenderer = new PDFRenderer(document); - int dpi = 203;// use less dpi for to save more space in harddisk. For professional usage you - BufferedImage bImage = pdfRenderer.renderImageWithDPI(0, dpi, ImageType.RGB); - ZPLConveterUtil zplConveterUtil = new ZPLConveterUtil(); - String zplStr = zplConveterUtil.convertFromImg(bImage); - zplStr = zplStr.replace("\n", ""); - return zplStr; - } else { - log.error("generate pdf failed"); - } - } catch (Exception e) { - log.error("error is {}", e); - } finally { - try { - if (document != null) { - document.close(); - } - } catch (IOException e) { - log.error("close stram failed,the exception is {}", e); - } - } - return ""; - } - - /** - * PDF转ZPL格式 - * @param imagePath 图片文件路径 - * @return 返回ZPL格式 - * @throws IOException - */ - public static String convertImgToZpl(String imagePath) throws IOException { - BufferedImage orginalImage = ImageIO.read(new File(imagePath)); - return ZPLConveterUtil.convertImgToZpl(orginalImage); - } - - public static String convertImgToZpl(BufferedImage image) throws IOException { - String cuerpo = createBody(image); - if(isCompressHex) - cuerpo = encodeHexAscii(cuerpo); - return headDoc() + cuerpo + footDoc(); - } - - public static void main(String[] args) throws Exception { - String pdf = ZPLConveterUtil.convertPdfToZpl("D:\\label.pdf"); - System.out.println(pdf); - -// String pdf2 = ZPLConveterUtil.convertPDFToZPL("D:\\label.pdf"); -// System.out.println(pdf2); - } -} - diff --git a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/tanex/TanexTplPrintImpl.java b/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/tanex/TanexTplPrintImpl.java deleted file mode 100644 index eaa841d..0000000 --- a/emis-oms2c/src/main/java/com/xdadan/erp/oms2c/service/print/tanex/TanexTplPrintImpl.java +++ /dev/null @@ -1,241 +0,0 @@ -package com.xdadan.erp.oms2c.service.print.tanex; - -import com.alibaba.fastjson.JSON; -import com.itextpdf.text.Element; -import com.xdadan.erp.oms.common.core.domain.AjaxResult; -import com.xdadan.erp.oms2c.service.print.IXddTplPrint; -import com.xdadan.erp.oms2c.service.print.ItemCell; -import com.xdadan.erp.oms2c.service.print.XddBasePrint; -import com.xdadan.erp.oms2c.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.ByteArrayOutputStream; -import java.io.FileOutputStream; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Base64; -import java.util.HashMap; -import java.util.Map; - -public class TanexTplPrintImpl extends XddBasePrint { - - /** - * 模版文件 - */ - private static String tplName="tpl/tanex_sd_2.pdf"; -// private static String tplName="/Users/alan/work/git/doitinfo/ai/logistic/src/main/resources/print_tpl/tanex/tanex_sd_2.pdf"; - - /** - * 单元条目配置 - * @param orderMap - * @return - */ - @Override - protected ArrayList getItemCelconfig(Map orderMap) { - ArrayList printItems = new ArrayList<>(); - - String package3dm = ""; - String packageWJC = ""; - - String pdfInfo =MapUtils.getString(orderMap,"pdf_info",""); - 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,10,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,"yd_sn",""); - printItems.add(new ItemCell("logisticNo", logisticNo,7,true,Element.ALIGN_CENTER,"Text")); - - // 条码显示 - printItems.add(new ItemCell("barcodeImg1", MapUtils.getString(orderMap,"yd_sn",""),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); -// address= Convert.address(address); - String consignee=MapUtils.getString(orderMap,"consignee",""); - consignee= Convert.chineseNameFirst(consignee); - - printItems.add(new ItemCell("company", MapUtils.getString(orderMap,"company",""),8,true,"Text")); - printItems.add(new ItemCell("consignee", consignee,9,true,"Text")); - printItems.add(new ItemCell("mobile", mobile,9,true,"Text")); - printItems.add(new ItemCell("address", MapUtils.getString(orderMap,"address",""),8,false,"Text")); - - - String sendPersonAndMobile= Convert.mobile(MapUtils.getString(orderMap,"send_person",""))+" " + Convert.mobile(MapUtils.getString(orderMap,"send_mobile","")); - printItems.add(new ItemCell("sendCompany", MapUtils.getString(orderMap,"send_company",""),8,true,"Text")); -// printItems.add(new ItemCell("sendMobile", MapUtils.getString(orderMap,"send_mobile",""),22,true,"Text")); -// printItems.add(new ItemCell("sendPerson", MapUtils.getString(orderMap,"send_person",""),22,true,"Text")); - printItems.add(new ItemCell("sendPersonAndMobile", MapUtils.getString(orderMap,"send_person",""),8,true,"Text")); -// printItems.add(new ItemCell("remark", MapUtils.getString(orderMap,"remark",""),22,true,"Text")); - printItems.add(new ItemCell("sendAddress", MapUtils.getString(orderMap,"send_address",""),8,false,"Text")); - - String goodsInfo="货物信息:"+MapUtils.getString(orderMap,"goods_info",""); - printItems.add(new ItemCell("goodsInfo", goodsInfo,6,false,"Text")); - - String parcelQty = "件数:"+MapUtils.getString(orderMap,"parcel_qty","")+"件"; - printItems.add(new ItemCell("parcelQty", parcelQty,6,true,"Text")); - printItems.add(new ItemCell("createDay", MapUtils.getString(orderMap,"create_day",""),6,true,"Text")); - - String extData =MapUtils.getString(orderMap,"ext_data",""); - 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 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 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, 280, ImageType.RGB); - ImageIO.write(bufferedImage, "png", os); - return ar; - } - - @Override - public String genPNGBase64(Map 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, 280, 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; - } - - - 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 order=new HashMap<>(); - order.put("order_sn", "DT20210901001"); - order.put("yd_sn", "SF1374689807723"); - order.put("kdgs", "TANEX"); - order.put("pdf_info", "[山东淄博-胡志明][越南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("ext_data", "{\"k1\":\"阿尔巴尼亚\",\"k2\":\"阿尔巴尼亚快递\",\"k3\":\"阿尔巴尼亚国际特快\",\"k4\":\"1-10工作日\",\"k5\":\"阿尔AL\",\"k6\":\"山东淄博-阿尔巴尼亚地拉那\"}"); -// order.put("sendPersonAndMobile", "Vancouver"+" "+"1604-683-1088"); - order.put("goods_info", "日常用品"); - order.put("parcel_qty", "1"); - order.put("create_day", "2023-12-30"); - - ByteArrayOutputStream os = new ByteArrayOutputStream(); - - IXddTplPrint xtp = new TanexTplPrintImpl(); - xtp.genPDF(order,os); -// xtp.genPNG(order,os); - - // 生成pdf base64 - byte[] pdfBytes = os.toByteArray(); - String pdfBase64Str = Base64.getEncoder().encodeToString(pdfBytes); - 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(); - } - } - - -} diff --git a/emis-oms2c/src/main/resources/font/simhei.ttf b/emis-oms2c/src/main/resources/font/simhei.ttf deleted file mode 100644 index 60a4819..0000000 Binary files a/emis-oms2c/src/main/resources/font/simhei.ttf and /dev/null differ diff --git a/emis-oms2c/src/main/resources/font/simsun.ttc b/emis-oms2c/src/main/resources/font/simsun.ttc deleted file mode 100644 index 23d5c4a..0000000 Binary files a/emis-oms2c/src/main/resources/font/simsun.ttc and /dev/null differ diff --git a/emis-oms2c/src/main/resources/font/simsun.ttf b/emis-oms2c/src/main/resources/font/simsun.ttf deleted file mode 100644 index e0115ab..0000000 Binary files a/emis-oms2c/src/main/resources/font/simsun.ttf and /dev/null differ diff --git a/emis-oms2c/src/main/resources/mapper/EmisElectronicPagApplyMapper.xml b/emis-oms2c/src/main/resources/mapper/EmisElectronicPagApplyMapper.xml deleted file mode 100644 index c1bb8d9..0000000 --- a/emis-oms2c/src/main/resources/mapper/EmisElectronicPagApplyMapper.xml +++ /dev/null @@ -1,269 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select id, prefix, apply_seq, apply_date, provide_type, material_code, material_name, apply_man_code, apply_site_code, apply_count, unit_money, sum_money, bl_send, send_date, send_man_code, send_site_code, send_center_man_code, send_center_site_code, bl_cancel, cancel_man_code, cancel_date, cancel_site_code, user_site_code, provide_flag, del_flag, create_by, create_time, update_by, update_time, remark, create_site, update_site from emis_electronic_pag_apply - - - - - - - - - - insert into emis_electronic_pag_apply - - id, - prefix, - apply_seq, - apply_date, - provide_type, - material_code, - material_name, - apply_man_code, - apply_site_code, - apply_count, - unit_money, - sum_money, - bl_send, - send_date, - send_man_code, - send_site_code, - send_center_man_code, - send_center_site_code, - bl_cancel, - cancel_man_code, - cancel_date, - cancel_site_code, - user_site_code, - provide_flag, - del_flag, - create_by, - create_time, - update_by, - update_time, - remark, - create_site, - update_site, - - - #{id}, - #{prefix}, - #{applySeq}, - #{applyDate}, - #{provideType}, - #{materialCode}, - #{materialName}, - #{applyManCode}, - #{applySiteCode}, - #{applyCount}, - #{unitMoney}, - #{sumMoney}, - #{blSend}, - #{sendDate}, - #{sendManCode}, - #{sendSiteCode}, - #{sendCenterManCode}, - #{sendCenterSiteCode}, - #{blCancel}, - #{cancelManCode}, - #{cancelDate}, - #{cancelSiteCode}, - #{userSiteCode}, - #{provideFlag}, - #{delFlag}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - #{remark}, - #{createSite}, - #{updateSite}, - - - - - update emis_electronic_pag_apply - - prefix = #{prefix}, - apply_seq = #{applySeq}, - apply_date = #{applyDate}, - provide_type = #{provideType}, - material_code = #{materialCode}, - material_name = #{materialName}, - apply_man_code = #{applyManCode}, - apply_site_code = #{applySiteCode}, - apply_count = #{applyCount}, - unit_money = #{unitMoney}, - sum_money = #{sumMoney}, - bl_send = #{blSend}, - send_date = #{sendDate}, - send_man_code = #{sendManCode}, - send_site_code = #{sendSiteCode}, - send_center_man_code = #{sendCenterManCode}, - send_center_site_code = #{sendCenterSiteCode}, - bl_cancel = #{blCancel}, - cancel_man_code = #{cancelManCode}, - cancel_date = #{cancelDate}, - cancel_site_code = #{cancelSiteCode}, - user_site_code = #{userSiteCode}, - provide_flag = #{provideFlag}, - del_flag = #{delFlag}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - remark = #{remark}, - create_site = #{createSite}, - update_site = #{updateSite}, - - where id = #{id} - - - - update emis_electronic_pag_apply set del_flag='1' where id = #{id} - - - - update emis_electronic_pag_apply set del_flag='1' where id in - - #{id} - - - - \ No newline at end of file diff --git a/emis-oms2c/src/main/resources/mapper/EmisElectronicPagMapper.xml b/emis-oms2c/src/main/resources/mapper/EmisElectronicPagMapper.xml deleted file mode 100644 index 12100da..0000000 --- a/emis-oms2c/src/main/resources/mapper/EmisElectronicPagMapper.xml +++ /dev/null @@ -1,178 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - select id, prefix, start_no, end_no, bill_count, unit_money, bill_fee, cur_start_no, has_bill_count, provide_date, provide_man, provide_site, status, del_flag, create_by, create_time, update_by, update_time, remark, create_site, update_site from emis_electronic_pag - - - - - - - - - - insert into emis_electronic_pag - - id, - prefix, - start_no, - end_no, - bill_count, - unit_money, - bill_fee, - cur_start_no, - has_bill_count, - provide_date, - provide_man, - provide_site, - status, - del_flag, - create_by, - create_time, - update_by, - update_time, - remark, - create_site, - update_site, - - - #{id}, - #{prefix}, - #{startNo}, - #{endNo}, - #{billCount}, - #{unitMoney}, - #{billFee}, - #{curStartNo}, - #{hasBillCount}, - #{provideDate}, - #{provideMan}, - #{provideSite}, - #{status}, - #{delFlag}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - #{remark}, - #{createSite}, - #{updateSite}, - - - - - update emis_electronic_pag - - prefix = #{prefix}, - start_no = #{startNo}, - end_no = #{endNo}, - bill_count = #{billCount}, - unit_money = #{unitMoney}, - bill_fee = #{billFee}, - cur_start_no = #{curStartNo}, - has_bill_count = #{hasBillCount}, - provide_date = #{provideDate}, - provide_man = #{provideMan}, - provide_site = #{provideSite}, - status = #{status}, - del_flag = #{delFlag}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - remark = #{remark}, - create_site = #{createSite}, - update_site = #{updateSite}, - - where id = #{id} - - - - delete from emis_electronic_pag where id = #{id} - - - - delete from emis_electronic_pag where id in - - #{id} - - - \ No newline at end of file diff --git a/emis-oms2c/src/main/resources/mapper/EmisElectronicSitePagMapper.xml b/emis-oms2c/src/main/resources/mapper/EmisElectronicSitePagMapper.xml deleted file mode 100644 index 386ba78..0000000 --- a/emis-oms2c/src/main/resources/mapper/EmisElectronicSitePagMapper.xml +++ /dev/null @@ -1,208 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - select id, prefix, start_no, end_no, cur_start_no, use_site_code, material_code, bill_count, unit_money, has_bill_count, bill_fee, provide_date, provide_man, provide_site, apply_seq, center_pag_id, provide_flag, status, del_flag, create_by, create_time, update_by, update_time, remark, create_site, update_site from emis_electronic_site_pag - - - - - - - - - - insert into emis_electronic_site_pag - - id, - prefix, - start_no, - end_no, - cur_start_no, - use_site_code, - material_code, - bill_count, - unit_money, - has_bill_count, - bill_fee, - provide_date, - provide_man, - provide_site, - apply_seq, - center_pag_id, - provide_flag, - status, - del_flag, - create_by, - create_time, - update_by, - update_time, - remark, - create_site, - update_site, - - - #{id}, - #{prefix}, - #{startNo}, - #{endNo}, - #{curStartNo}, - #{useSiteCode}, - #{materialCode}, - #{billCount}, - #{unitMoney}, - #{hasBillCount}, - #{billFee}, - #{provideDate}, - #{provideMan}, - #{provideSite}, - #{applySeq}, - #{centerPagId}, - #{provideFlag}, - #{status}, - #{delFlag}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - #{remark}, - #{createSite}, - #{updateSite}, - - - - - update emis_electronic_site_pag - - prefix = #{prefix}, - start_no = #{startNo}, - end_no = #{endNo}, - cur_start_no = #{curStartNo}, - use_site_code = #{useSiteCode}, - material_code = #{materialCode}, - bill_count = #{billCount}, - unit_money = #{unitMoney}, - has_bill_count = #{hasBillCount}, - bill_fee = #{billFee}, - provide_date = #{provideDate}, - provide_man = #{provideMan}, - provide_site = #{provideSite}, - apply_seq = #{applySeq}, - center_pag_id = #{centerPagId}, - provide_flag = #{provideFlag}, - status = #{status}, - del_flag = #{delFlag}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - remark = #{remark}, - create_site = #{createSite}, - update_site = #{updateSite}, - - where id = #{id} - - - - delete from emis_electronic_site_pag where id = #{id} - - - - delete from emis_electronic_site_pag where id in - - #{id} - - - \ No newline at end of file diff --git a/emis-oms2c/src/main/resources/mapper/EmisFeeTypeMapper.xml b/emis-oms2c/src/main/resources/mapper/EmisFeeTypeMapper.xml deleted file mode 100644 index 42d6c07..0000000 --- a/emis-oms2c/src/main/resources/mapper/EmisFeeTypeMapper.xml +++ /dev/null @@ -1,113 +0,0 @@ - - - - - - - - - - - - - - - select id, fee_type_code, fee_type_name, fee_type_name_en, status, remark, tenant_id, del_flag, create_by, create_time, update_by, update_time, create_site, update_site from emis_fee_type - - - - - - - - insert into emis_fee_type - - id, - fee_type_code, - fee_type_name, - fee_type_name_en, - status, - remark, - tenant_id, - del_flag, - create_by, - create_time, - update_by, - update_time, - create_site, - update_site, - - - #{id}, - #{feeTypeCode}, - #{feeTypeName}, - #{feeTypeNameEn}, - #{status}, - #{remark}, - #{tenantId}, - #{delFlag}, - #{createBy}, - #{createTime}, - #{updateBy}, - #{updateTime}, - #{createSite}, - #{updateSite}, - - - - - update emis_fee_type - - fee_type_code = #{feeTypeCode}, - fee_type_name = #{feeTypeName}, - fee_type_name_en = #{feeTypeNameEn}, - status = #{status}, - remark = #{remark}, - tenant_id = #{tenantId}, - del_flag = #{delFlag}, - create_by = #{createBy}, - create_time = #{createTime}, - update_by = #{updateBy}, - update_time = #{updateTime}, - create_site = #{createSite}, - update_site = #{updateSite}, - - where id = #{id} - - - - delete from emis_fee_type where id = #{id} - - - - delete from emis_fee_type where id in - - #{id} - - - \ No newline at end of file diff --git a/emis-oms2c/src/main/resources/tpl/tanex_sd_2.pdf b/emis-oms2c/src/main/resources/tpl/tanex_sd_2.pdf deleted file mode 100644 index 95f301a..0000000 Binary files a/emis-oms2c/src/main/resources/tpl/tanex_sd_2.pdf and /dev/null differ