diff --git a/common/src/main/java/com/foreverwin/mesnac/common/model/LabelPrintDto.java b/common/src/main/java/com/foreverwin/mesnac/common/model/LabelPrintDto.java new file mode 100644 index 00000000..2e12ea55 --- /dev/null +++ b/common/src/main/java/com/foreverwin/mesnac/common/model/LabelPrintDto.java @@ -0,0 +1,224 @@ +package com.foreverwin.mesnac.common.model; + +import java.io.Serializable; +import java.math.BigDecimal; + +/** + * 标签打印参数类 + * + */ +public class LabelPrintDto implements Serializable { + + private String site; + private String user; + //打印机 + private String printer; + //打印模板名称 + private String printTemplate; + //物料编码 + private String item; + //物料描述 + private String itemDescription; + //供应商 + private String supplier; + //批次号 + private String batch; + //工作指令 + private String workOrder; + //图纸版本号 + private String drawingVersion; + //产品条码 + private String sfc; + //数量 + private BigDecimal qty; + //下料尺寸 + private String blankingSize; + //下道工序 + private String operation; + + private String label; + //订单号 + private String shopOrder; + // 特定打印的数量 + private BigDecimal sfcQty; + + //是否主观件 + private boolean mainPart; + + //入库转 + private String itemTypeOrder; + + public String getItemTypeOrder() { + return itemTypeOrder; + } + + public void setItemTypeOrder(String itemTypeOrder) { + this.itemTypeOrder = itemTypeOrder; + } + + public boolean getMainPart() { + return mainPart; + } + + public void setMainPart(boolean mainPart) { + this.mainPart = mainPart; + } + + public BigDecimal getSfcQty() { + return sfcQty; + } + + public void setSfcQty(BigDecimal sfcQty) { + this.sfcQty = sfcQty; + } + + //项目号 + private String itemNumber; + + public String getItemNumber() { + return itemNumber; + } + + public void setItemNumber(String itemNumber) { + this.itemNumber = itemNumber; + } + + public String getShopOrder() { + return shopOrder; + } + + public void setShopOrder(String shopOrder) { + this.shopOrder = shopOrder; + } + + public Integer getPrintNum() { + return printNum; + } + + public void setPrintNum(Integer printNum) { + this.printNum = printNum; + } + + //打印数量 + private Integer printNum; + + public String getLabel() { + return label; + } + + public void setLabel(String label) { + this.label = label; + } + + public String getItem() { + return item; + } + + public void setItem(String item) { + this.item = item; + } + + public String getItemDescription() { + return itemDescription; + } + + public void setItemDescription(String itemDescription) { + this.itemDescription = itemDescription; + } + + public String getSupplier() { + return supplier; + } + + public void setSupplier(String supplier) { + this.supplier = supplier; + } + + public String getBatch() { + return batch; + } + + public void setBatch(String batch) { + this.batch = batch; + } + + public String getWorkOrder() { + return workOrder; + } + + public void setWorkOrder(String workOrder) { + this.workOrder = workOrder; + } + + public String getDrawingVersion() { + return drawingVersion; + } + + public void setDrawingVersion(String drawingVersion) { + this.drawingVersion = drawingVersion; + } + + public String getSfc() { + return sfc; + } + + public void setSfc(String sfc) { + this.sfc = sfc; + } + + public BigDecimal getQty() { + return qty; + } + + public void setQty(BigDecimal qty) { + this.qty = qty; + } + + public String getBlankingSize() { + return blankingSize; + } + + public void setBlankingSize(String blankingSize) { + this.blankingSize = blankingSize; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public String getSite() { + return site; + } + + public void setSite(String site) { + this.site = site; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + public String getPrinter() { + return printer; + } + + public void setPrinter(String printer) { + this.printer = printer; + } + + public String getPrintTemplate() { + return printTemplate; + } + + public void setPrintTemplate(String printTemplate) { + this.printTemplate = printTemplate; + } +} diff --git a/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java b/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java new file mode 100644 index 00000000..8405ca23 --- /dev/null +++ b/common/src/main/java/com/foreverwin/mesnac/common/util/DrawPrepareProducts.java @@ -0,0 +1,63 @@ +package com.foreverwin.mesnac.common.util; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.FileOutputStream; + +public class DrawPrepareProducts { + /** + * + * @param srcImgPath + * @param outImgPath + * @param markContentColor + * @param shf + * @param wlms + * @param sl + * @param ddh + * @param gx + * @param xlcc + * @param cptm + * @param wlbm + */ + public static void mark(String srcImgPath, String outImgPath, Color markContentColor, String shf, + String wlms, String sl, String ddh, String gx, String xlcc, String cptm, String wlbm){ + try { + // 读取原图片信息 + File srcImgFile = new File(srcImgPath); + BufferedImage srcImg = ImageIO.read(srcImgFile); + int srcImgWidth = srcImg.getWidth(null); + int srcImgHeight = srcImg.getHeight(null); + // 加水印 + BufferedImage bufImg = new BufferedImage(srcImgWidth, srcImgHeight, BufferedImage.TYPE_INT_RGB); + Graphics2D g = bufImg.createGraphics(); + g.drawImage(srcImg, 0, 0, srcImgWidth, srcImgHeight, null); +// Font font = new Font("Courier New", Font.PLAIN, 12); + Font font = new Font("宋体", Font.PLAIN, 30); + g.setColor(markContentColor); // 根据图片的背景设置水印颜色 + g.setFont(font); +// g.drawString(shf, 10, 70); +// g.drawString(wlms, 10, 150); +// g.drawString(sl, 10, 230); +// g.drawString(ddh, 420, 230); +// g.drawString(gx, 10, 330); +// g.drawString(xlcc, 10, 440); +// g.drawString(cptm, 10, 520); +// g.drawString(wlbm, 10, 600); + g.dispose(); + //生成二维码图片 +// QRUtils.encode("012345678912","D:\\QRCODE.jpg",false); + //插入生成好的二维码图片 + QRUtils.insertImage(bufImg,"D:\\img\\QRCODE.jpg",false); + // 输出图片 + FileOutputStream outImgStream = new FileOutputStream(outImgPath); + ImageIO.write(bufImg, "jpg", outImgStream); + outImgStream.flush(); + outImgStream.close(); + } catch (Exception e) { + e.printStackTrace(); + } +// return outImgPath; + } +} diff --git a/common/src/main/java/com/foreverwin/mesnac/common/util/QRUtils.java b/common/src/main/java/com/foreverwin/mesnac/common/util/QRUtils.java new file mode 100644 index 00000000..9825c442 --- /dev/null +++ b/common/src/main/java/com/foreverwin/mesnac/common/util/QRUtils.java @@ -0,0 +1,150 @@ +package com.foreverwin.mesnac.common.util; + + +import com.google.zxing.BarcodeFormat; +import com.google.zxing.EncodeHintType; +import com.google.zxing.MultiFormatWriter; +import com.google.zxing.common.BitMatrix; +import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; + +import javax.imageio.ImageIO; +import java.awt.*; +import java.awt.geom.RoundRectangle2D; +import java.awt.image.BufferedImage; +import java.io.File; +import java.util.Hashtable; + +public class QRUtils { + private static final String CHARSET = "utf-8"; + private static final String FORMAT_NAME = "JPG"; + // 二维码尺寸 + private static final int QRCODE_SIZE = 300; + // LOGO宽度 + private static final int WIDTH = 60; + // LOGO高度 + private static final int HEIGHT = 60; + + private static BufferedImage createImage(String content, String imgPath) throws Exception { + Hashtable hints = new Hashtable(); + hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); + hints.put(EncodeHintType.CHARACTER_SET, CHARSET); + hints.put(EncodeHintType.MARGIN, 1); + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, + BarcodeFormat.QR_CODE, QRCODE_SIZE, QRCODE_SIZE, hints); + int width = bitMatrix.getWidth(); + int height = bitMatrix.getHeight(); + BufferedImage image = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + for (int x = 0; x < width; x++) { + for (int y = 0; y < height; y++) { + image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 + : 0xFFFFFFFF); + } + } + if (imgPath == null || "".equals(imgPath)) { + return image; + } + // 插入图片 + return image; + } + + /** + * 插入LOGO + * + * @param source + * 二维码图片 + * @param imgPath + * LOGO图片地址 + * @param needCompress + * 是否压缩 + * @throws Exception + */ + public static void insertImage(BufferedImage source, String imgPath, + boolean needCompress) throws Exception { + File file = new File(imgPath); + if (!file.exists()) { + System.err.println(""+imgPath+" 该文件不存在!"); + return; + } + Image src = ImageIO.read(new File(imgPath)); + int width = 150; + int height = 150; + if (needCompress) { // 压缩LOGO + if (width > WIDTH) { + width = WIDTH; + } + if (height > HEIGHT) { + height = HEIGHT; + } + Image image = src.getScaledInstance(width, height, + Image.SCALE_SMOOTH); + BufferedImage tag = new BufferedImage(width, height, + BufferedImage.TYPE_INT_RGB); + Graphics g = tag.getGraphics(); + g.drawImage(image, 0, 0, null); // 绘制缩小后的图 + g.dispose(); + src = image; + } + // 插入LOGO + Graphics2D graph = source.createGraphics(); + int x = 449; + int y = 280; + graph.drawImage(src, x, y, width, height, null); + Shape shape = new RoundRectangle2D.Float(x, y, width, width, 6, 6); + graph.setStroke(new BasicStroke(3f)); + graph.draw(shape); + graph.dispose(); + } + + /** + * 生成二维码(内嵌LOGO) + * + * @param content + * 内容 + * @param logoPath + * LOGO地址 + * @param destPath + * 存放目录 + * @param needCompress + * 是否压缩LOGO + * @throws Exception + */ + public static String encode(String content, String logoPath, String destPath) throws Exception { + BufferedImage image = QRUtils.createImage(content, logoPath); + mkdirs(destPath); + String file = "QRCODE.jpg"; + ImageIO.write(image, FORMAT_NAME, new File(destPath+"/"+file)); + return file; + } + /** + * 当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) + * @date 2013-12-11 上午10:16:36 + * @param destPath 存放目录 + */ + public static void mkdirs(String destPath) { + File file =new File(destPath); + //当文件夹不存在时,mkdirs会自动创建多层目录,区别于mkdir.(mkdir如果父目录不存在则会抛出异常) + if (!file.exists() && !file.isDirectory()) { + file.mkdirs(); + } + } + + +// public static void main(String[] args) throws Exception { +//// String text = "MESNAC"; //这里设置自定义网站url +//// String logoPath = "D:\\img\\QRCODE.jpg"; +//// String destPath = "D:\\img\\"; +//// int width = 210; +//// int height = 210; +//// BufferedImage image = new BufferedImage(width, height, +//// BufferedImage.TYPE_INT_RGB); +////// insertImage(image,logoPath,true); +//// System.out.println(QRUtils.encode(text, logoPath, destPath)); +//// } + +// public static void main(String[] args) { +// DrawPrepareProducts.mark("D:\\img\\original.png", "D:\\img\\finall.png", +// Color.black, "收货方","物料描述","数量","订单号","工序","下料尺寸","产品条码","物料编码"); +// } + +}