value
2024-04-15 f5041d3a0a706809bc351ff6d0694935f33abc9f
新增报告插入二维码
已修改5个文件
已添加1个文件
113 ■■■■■ 文件已修改
framework/pom.xml 6 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/com/yuanchu/mom/utils/MatrixToImageWriter.java 72 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/mapper/InsOrderMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/static/report-template.docx 补丁 | 查看 | 原始文档 | blame | 历史
system-run/src/main/resources/application-dev.yml 7 ●●●●● 补丁 | 查看 | 原始文档 | 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.docx
Binary 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