src/main/java/com/zy/common/utils/QrCode.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/zy/common/web/FileController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/webapp/static/js/trayCode/trayCode.js | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
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); 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(); } } 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();