Commit 3b7b6f41 by zhanglt

生成二维码

parent 26de2b0a
...@@ -87,20 +87,15 @@ public class ProfitWarehousingService extends CrudService<ProfitWarehousingMappe ...@@ -87,20 +87,15 @@ public class ProfitWarehousingService extends CrudService<ProfitWarehousingMappe
file .mkdirs(); file .mkdirs();
} }
ProfitWarehousingInfo profitWarehousingInfo = profitWarehousingInfoMapper.get(infoId); ProfitWarehousingInfo profitWarehousingInfo = profitWarehousingInfoMapper.get(infoId);
GoodsInfo goodsInfo = new GoodsInfo();
goodsInfo.setType(profitWarehousingInfo.getType());
goodsInfo.setName(profitWarehousingInfo.getName());
goodsInfo.setModel(profitWarehousingInfo.getMarking());
String numSeq = CodeUtil.code("WZBM", StaticNumSeq.WZBM); String numSeq = CodeUtil.code("WZBM", StaticNumSeq.WZBM);
QrCode qrCode = new QrCode(); QrCode qrCode = new QrCode();
qrCode.setProfitWarehousingInfo(profitWarehousingInfo); qrCode.setProfitWarehousingInfo(profitWarehousingInfo);
qrCode.setComeFlag("1"); qrCode.setComeFlag("1");
qrCode.setCode(numSeq); qrCode.setCode(numSeq);
qrCode.setState("0"); qrCode.setState("0");
qrCode.setGoodsInfo(goodsInfo);
qrCode.preInsert(); qrCode.preInsert();
try { try {
BuildQcUtil.buildQrOne(qrCode, qrImgPath + "/" + numSeq + ".png", qrImgPath + "/" + numSeq + ".png"); // 生成图片 BuildQcUtil.buildQrOne(qrCode, qrImgPath + "/" + numSeq + ".png", qrImgPath + "/" + numSeq + "_0"+ ".png"); // 生成图片
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -45,7 +45,7 @@ public class BuildQcUtil { ...@@ -45,7 +45,7 @@ public class BuildQcUtil {
TwoDimensionCode.encoderQRCode(JSON.toJSONString(map), qrImgPath, "png", 6); TwoDimensionCode.encoderQRCode(JSON.toJSONString(map), qrImgPath, "png", 6);
File file = new File(qrImgPath); File file = new File(qrImgPath);
try { try {
BufferedImage image = DrawQrcodeUtil.createAssetImageNew(file, qrCode); BufferedImage image = DrawQrcodeUtil.createAssetImageNew2(file, qrCode);
DrawQrcodeUtil drawQrcodeUtil = new DrawQrcodeUtil(); DrawQrcodeUtil drawQrcodeUtil = new DrawQrcodeUtil();
drawQrcodeUtil.writeImage(image, imgPath); drawQrcodeUtil.writeImage(image, imgPath);
} catch (IOException e) { } catch (IOException e) {
......
...@@ -4,6 +4,7 @@ package com.jeeplus.modules.warehouse.qrcode.util; ...@@ -4,6 +4,7 @@ package com.jeeplus.modules.warehouse.qrcode.util;
import com.jeeplus.common.utils.text.EscapeUtil; import com.jeeplus.common.utils.text.EscapeUtil;
import com.jeeplus.modules.sys.entity.Office; import com.jeeplus.modules.sys.entity.Office;
import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo; import com.jeeplus.modules.warehouse.goods.entity.GoodsInfo;
import com.jeeplus.modules.warehouse.profitwarehousing.entity.ProfitWarehousingInfo;
import com.jeeplus.modules.warehouse.qrcode.entity.QrCode; import com.jeeplus.modules.warehouse.qrcode.entity.QrCode;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.junit.Test; import org.junit.Test;
...@@ -301,7 +302,72 @@ public class DrawQrcodeUtil { ...@@ -301,7 +302,72 @@ public class DrawQrcodeUtil {
return bgImage; return bgImage;
} }
public static BufferedImage createAssetImageNew2(File qrcodeFile,QrCode qrCode) throws IOException {
ProfitWarehousingInfo profitWarehousingInfo = qrCode.getProfitWarehousingInfo();
QRcodeSize qRcodeSize = null;
qRcodeSize = new QRcodeSize(8,200,1400,78,200,200,1200,1200,new Color(34,25,21));
BufferedImage bgImage = new BufferedImage(1600, 2400, BufferedImage.TYPE_4BYTE_ABGR);
Graphics2D g2 = bgImage.createGraphics();
BufferedImage qrcodeImage = ImageIO.read(qrcodeFile);
RenderingHints rh=new RenderingHints(RenderingHints. KEY_ANTIALIASING,
RenderingHints. VALUE_ANTIALIAS_ON);
rh.put(RenderingHints.KEY_STROKE_CONTROL
, RenderingHints.VALUE_STROKE_PURE);
rh.put(RenderingHints.KEY_ALPHA_INTERPOLATION
, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2.setRenderingHints(rh);
Font font = new Font("黑体",Font.BOLD,16 * qRcodeSize.getInitfontSize());
g2.setFont(font); //设置字体:字体、字号、大小
g2.setColor(qRcodeSize.color);//设置背景颜色
// g2.setBackground(c);
int contentX = qRcodeSize.getInitContentX();
int contentY = qRcodeSize.getInitContentY() + 200;
//写二维码
g2.drawImage(qrcodeImage,qRcodeSize.getQrcodeX(),qRcodeSize.getQrcodeY(),qRcodeSize.getQrcodeWidth(),qRcodeSize.getQrcodeHeight(),null,null);
//写入货品名称
String contentTitle1 = "货品名称:";
int contentTitle1Width = g2.getFontMetrics().stringWidth(contentTitle1);
g2.drawString(contentTitle1,contentX,contentY);
String name = formatContent(profitWarehousingInfo.getName(),10);
AttributedString as = new AttributedString(name);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, name.length());
g2.drawString(as.getIterator(),contentX+contentTitle1Width,contentY);
//写入货品类型
String contentTitle2 = "货品类型:";
int contentTitle2Width = g2.getFontMetrics().stringWidth(contentTitle2);
g2.drawString(contentTitle2,contentX,contentY+200);
String typeName = formatContent(profitWarehousingInfo.getType().getName(),10);
as = new AttributedString(typeName);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, typeName.length());
g2.drawString(as.getIterator(),contentX+contentTitle2Width,contentY+200);
//写入物资编码
String contentTitle4 = "物资编码:";
int contentTitle4Width = g2.getFontMetrics().stringWidth(contentTitle4);
g2.drawString(contentTitle4,contentX,contentY+400);
String code = qrCode.getCode();
if (code.length() > 10) {
String str1 = code.substring(0, 9);
str1 = formatContent(str1,10);
as = new AttributedString(str1);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str1.length());
g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+400);
String str2 = code.substring(9, code.length());
str2 = formatContent(str2,10);
as = new AttributedString(str2);
as.addAttribute(TextAttribute.FONT, font);
as.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_LOW_DASHED, 0, str2.length());
g2.drawString(as.getIterator(),contentX+contentTitle4Width,contentY+600);
}
return bgImage;
}
/** /**
* 生成二维码包装图片 * 生成二维码包装图片
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment