From 2580ade8b1369051fd32089fb4d95d427ea485e6 Mon Sep 17 00:00:00 2001 From: luxiaotao1123 <t1341870251@163.com> Date: 星期五, 03 七月 2020 08:29:58 +0800 Subject: [PATCH] # --- src/main/webapp/static/js/trayCode/trayCode.js | 9 ++++++++- src/main/java/com/zy/common/utils/QrCode.java | 8 ++++++-- src/main/java/com/zy/common/web/FileController.java | 34 +++++++++++++++++++++++++++++++++- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/zy/common/utils/QrCode.java b/src/main/java/com/zy/common/utils/QrCode.java index d2e86c6..ee63247 100644 --- a/src/main/java/com/zy/common/utils/QrCode.java +++ b/src/main/java/com/zy/common/utils/QrCode.java @@ -23,11 +23,15 @@ private static final int QRCODE_SIZE = 150; public static BufferedImage createImg(String content) throws WriterException { - ConcurrentHashMap hints = new ConcurrentHashMap(); + return createImg(content, QRCODE_SIZE, QRCODE_SIZE); + } + + public static BufferedImage createImg(String content, Integer wid, Integer hei) throws WriterException { + ConcurrentHashMap<EncodeHintType, Object> hints = new ConcurrentHashMap<>(); 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); + BitMatrix bitMatrix = new MultiFormatWriter().encode(content, BarcodeFormat.QR_CODE, wid, hei, hints); int width = bitMatrix.getWidth(); int height = bitMatrix.getHeight(); BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); diff --git a/src/main/java/com/zy/common/web/FileController.java b/src/main/java/com/zy/common/web/FileController.java index 3074912..37a78dd 100644 --- a/src/main/java/com/zy/common/web/FileController.java +++ b/src/main/java/com/zy/common/web/FileController.java @@ -2,16 +2,23 @@ import com.alibaba.excel.EasyExcel; import com.baomidou.mybatisplus.mapper.EntityWrapper; +import com.core.common.BaseRes; +import com.core.common.Cools; import com.core.common.R; import com.zy.asrs.entity.MatCode; import com.zy.asrs.service.MatCodeService; +import com.zy.common.config.AdminInterceptor; +import com.zy.common.utils.BarcodeUtils; +import com.zy.common.utils.QrCode; import com.zy.common.utils.excel.matcode.MatCodeExcel; import com.zy.common.utils.excel.matcode.MatCodeExcelListener; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; +import javax.imageio.ImageIO; import javax.servlet.http.HttpServletResponse; +import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URLEncoder; import java.util.ArrayList; @@ -22,7 +29,7 @@ * Created by vincent on 2019-11-25 */ @RestController -@RequestMapping("excel/") +@RequestMapping("file/") public class FileController { @Autowired @@ -62,4 +69,29 @@ EasyExcel.write(response.getOutputStream(), MatCodeExcel.class).sheet("妯℃澘").doWrite(excels); } + @RequestMapping(value = "/barcode/qrcode/auth") +// @ManagerAuth(memo = "鐗╂枡缂栫爜鏉″舰鐮佽幏鍙�(type:1(鏉″舰鐮�);2(浜岀淮鐮�)") + public R matCodeBarcode(@RequestParam(defaultValue = "1") Integer type + , @RequestParam String param + , @RequestParam(required = false) Integer width + , @RequestParam(required = false) Integer height + , HttpServletResponse response) throws Exception { + AdminInterceptor.cors(response); + if (Cools.isEmpty(param)){ + return R.parse(BaseRes.EMPTY); + } + BufferedImage img; + if (type == 1) { + img = BarcodeUtils.encode(param, width, height); + } else { + img = QrCode.createImg(param, width, height); + } + if (!ImageIO.write(img, "jpg", response.getOutputStream())) { + throw new IOException("Could not write an image of format jpg"); + } + response.getOutputStream().flush(); + response.getOutputStream().close(); + return R.ok(); + } + } diff --git a/src/main/webapp/static/js/trayCode/trayCode.js b/src/main/webapp/static/js/trayCode/trayCode.js index b3ee7da..23ee0f7 100644 --- a/src/main/webapp/static/js/trayCode/trayCode.js +++ b/src/main/webapp/static/js/trayCode/trayCode.js @@ -304,11 +304,18 @@ success: function (res) { if (res.code === 200){ for (let i=0;i<res.data.length;i++){ - res.data[i]["barcodeUrl"]=baseUrl+"/macCode/code/auth?type="+data.field.type+"¶m="+res.data[i].item; + if (data.field.type === '1') { + res.data[i]["barcodeUrl"]=baseUrl+"/file/barcode/qrcode/auth?" + + "type="+data.field.type+"¶m="+res.data[i].item+"&width="+500+"&height="+200; + } else { + res.data[i]["barcodeUrl"]=baseUrl+"/file/barcode/qrcode/auth?" + + "type="+data.field.type+"¶m="+res.data[i].item+"&width="+200+"&height="+200; + } } var tpl = $('#trayCodeTemplate').html(); var template = Handlebars.compile(tpl); var html = template(res); + console.log(html) let box = $("#printBox"); box.html(html); box.show(); -- Gitblit v1.9.1