framework/pom.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
framework/src/main/java/com/yuanchu/mom/utils/MatrixToImageWriter.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/resources/mapper/InsOrderMapper.xml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
inspect-server/src/main/resources/static/report-template.docx | 补丁 | 查看 | 原始文档 | blame | 历史 | |
system-run/src/main/resources/application-dev.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
framework/pom.xml
@@ -39,5 +39,11 @@ <artifactId>java-jwt</artifactId> </dependency> <dependency> <groupId>com.google.zxing</groupId> <artifactId>core</artifactId> <version>3.3.3</version> </dependency> </dependencies> </project> framework/src/main/java/com/yuanchu/mom/utils/MatrixToImageWriter.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,72 @@ package com.yuanchu.mom.utils; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.imageio.ImageIO; import com.google.zxing.BarcodeFormat; import com.google.zxing.EncodeHintType; import com.google.zxing.MultiFormatWriter; import com.google.zxing.WriterException; import com.google.zxing.common.BitMatrix; import com.yuanchu.mom.exception.ErrorException; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** * é ç½®å¾ååå ¥å¨ * * @author z1292 * */ public class MatrixToImageWriter { private final int BLACK = 0xFF000000; private final int WHITE = 0xFFFFFFFF; private BufferedImage toBufferedImage(BitMatrix matrix) { int width = matrix.getWidth(); int height = matrix.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, matrix.get(x, y) ? BLACK : WHITE); } } return image; } private void writeToFile(BitMatrix matrix, String format, File file) throws IOException { BufferedImage image = toBufferedImage(matrix); if (!ImageIO.write(image, format, file)) { throw new ErrorException("Could not write an image of format " + format + " to " + file); } } public String code(String content, String path) { try { String codeName = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd&HH_mm_ss"));// äºç»´ç çå¾çå String imageType = "jpg";// å¾çç±»å MultiFormatWriter multiFormatWriter = new MultiFormatWriter(); Map<EncodeHintType, Object> hints = new HashMap<>(); hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); hints.put(EncodeHintType.MARGIN, 0); BitMatrix bitMatrix = multiFormatWriter.encode(content, BarcodeFormat.QR_CODE, 400, 400, hints); File file1 = new File(path, codeName + "." + imageType); writeToFile(bitMatrix, imageType, file1); return file1.getPath(); } catch (WriterException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } throw new ErrorException("äºç»´ç çæå¤±è´¥"); } } inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -27,6 +27,8 @@ import com.yuanchu.mom.service.InsOrderService; import com.yuanchu.mom.service.StandardTemplateService; import com.yuanchu.mom.utils.GiveCode; import com.yuanchu.mom.utils.JackSonUtil; import com.yuanchu.mom.utils.MatrixToImageWriter; import com.yuanchu.mom.utils.QueryWrappers; import com.yuanchu.mom.vo.InsOrderPlanVO; import org.apache.poi.xwpf.usermodel.TableRowAlign; @@ -76,6 +78,9 @@ @Value("${wordUrl}") private String wordUrl; @Value("${twoCode}") private String twoCode; @Resource private GiveCode giveCode; @@ -419,6 +424,18 @@ table.put("tableSize", tables.size() + 1); }); List<Map<String, String>> deviceList = insOrderMapper.selectDeviceList(deviceSet); Map<String, String> codeStr = new HashMap<>(); codeStr.put("æ¥åç¼å·", insReport.getCode()); codeStr.put("æ ·ååç§°", insOrder.getSample()); codeStr.put("è§æ ¼åå·", samples.get(0).getModel()); codeStr.put("åæ¾æ¥æ", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))); String codePath; try { codePath = new MatrixToImageWriter().code(JackSonUtil.marshal(codeStr).replaceAll("\\{","") .replaceAll("}","").replaceAll(",","").replaceAll("\"",""), twoCode); } catch (Exception e) { throw new RuntimeException(e); } ConfigureBuilder builder = Configure.builder(); builder.useSpringEL(true); XWPFTemplate template = XWPFTemplate.compile(url, builder.build()).render( @@ -432,9 +449,10 @@ put("tableSize", tables.size() + 1); put("standardMethod", standardMethod2); put("deviceList", deviceList); put("twoCode", Pictures.ofLocal(codePath).create()); }}); try { String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx"; String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd&HH_mm_ss")) + ".docx"; template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name))); insReport.setUrl("/word/" + name); insReportMapper.insert(insReport); inspect-server/src/main/resources/mapper/InsOrderMapper.xml
@@ -142,11 +142,11 @@ ${ew.customSqlSegment} </if> </select> <select id="selectDeviceList" resultType="java.util.Map" parameterType="java.util.Set"> select device_name,specification_model,factory_no,latest_traceability from device <select id="selectDeviceList" resultType="java.util.Map"> select device_name,specification_model,factory_no,date_format(latest_traceability, '%Y-%m-%d') latest_traceability from device where device_name in <foreach collection="array" open="(" separator="," close=")" item="val"> ${val} <foreach collection="names" index="index" open="(" separator="," close=")" item="val"> #{val} </foreach> </select> inspect-server/src/main/resources/static/report-template.docxBinary files differ
system-run/src/main/resources/application-dev.yml
@@ -5,7 +5,7 @@ logging: config: classpath:logback-spring.xml # æ¥å¿åå¨è·¯å¾+++++++++++++++++++++++++++è¿ç»´éè¦é ç½®+++++++++++++++++++++++++++ file-location: D:\Download\log file-location: D:\é¡¹ç®æä»¶åå¨\log # æ°æ®åºå¤ä»½è·¯å¾ backup: @@ -18,11 +18,12 @@ # ç §çåå¨è·¯å¾+++++++++++++++++++++++++++è¿ç»´éè¦é ç½®+++++++++++++++++++++++++++ file: path: D:\Download\å ¬å¸åå¨å°å path: D:\é¡¹ç®æä»¶åå¨\image # ä¸ä¼ æä»¶å è®¸çæ©å±å allowed: png,jpg,jpeg,gif wordUrl: D:\Download\å ¬å¸åå¨å°å wordUrl: D:\é¡¹ç®æä»¶åå¨\word twoCode: D:\é¡¹ç®æä»¶åå¨\two_code mybatis-plus: type-aliases-package: com.yuanchu.mom.pojo