value
2024-04-03 3bd27d6f6892e60658ca39763d9200743932ee36
检验报告
已修改11个文件
已添加3个文件
139 ■■■■ 文件已修改
framework/src/main/java/com/yuanchu/mom/config/OpenFifer.java 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/com/yuanchu/mom/utils/GiveCode.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/pom.xml 11 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/controller/InsReportController.java 8 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/mapper/InsProductMapper.java 4 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/service/InsReportService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java 69 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java 27 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/mapper/InsProductMapper.xml 3 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
inspect-server/src/main/resources/static/report-template.docx 补丁 | 查看 | 原始文档 | blame | 历史
system-run/src/main/resources/application-dev.yml 4 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
system-run/src/main/resources/application.yml 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
wordToHtml.html 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
wordToHtml_styles.css 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
framework/src/main/java/com/yuanchu/mom/config/OpenFifer.java
@@ -27,7 +27,8 @@
    @Value("${outPath}")
    private String outPath;
    @Value("${wordUrl}")
    private String wordUrl;
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //配置拦截器访问静态资源
@@ -38,6 +39,7 @@
        //设置文件虚拟路径映射
        registry.addResourceHandler("/img/**").addResourceLocations("file:"+filePath+"/");
        registry.addResourceHandler("/outPath/**").addResourceLocations("file:"+outPath);
        registry.addResourceHandler("/word/**").addResourceLocations("file:"+wordUrl+"/");
    }
    @Override
framework/src/main/java/com/yuanchu/mom/utils/GiveCode.java
@@ -21,7 +21,7 @@
        String nums = num + "";
        if(nums.length() == 1) nums = "00" + num;
        else if(nums.length() == 2) nums = "0" + num;
        return code + date2 + symbol + nums;
        return code + (date2==null?date:date2) + symbol + nums;
    }
}
inspect-server/pom.xml
@@ -32,6 +32,15 @@
            <artifactId>poi-tl</artifactId>
            <version>1.12.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>5.3.18</version>
        </dependency>
        <dependency>
            <groupId>e-iceblue</groupId>
            <artifactId>spire.doc.free</artifactId>
            <version>5.2.0</version>
        </dependency>
    </dependencies>
</project>
inspect-server/src/main/java/com/yuanchu/mom/controller/InsReportController.java
@@ -1,6 +1,7 @@
package com.yuanchu.mom.controller;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yuanchu.mom.annotation.ValueAuth;
import com.yuanchu.mom.dto.ReportPageDto;
import com.yuanchu.mom.dto.SampleOrderDto;
import com.yuanchu.mom.service.InsReportService;
@@ -32,4 +33,11 @@
        return Result.success(insReportService.pageInsReport(page, reportPageDto));
    }
    @ApiOperation(value = "Word转HTML")
    @PostMapping("/wordToHtml")
    @ValueAuth
    public Result wordToHtml(String path) {
        return Result.success("转换成功", insReportService.wordToHtml(path));
    }
}
inspect-server/src/main/java/com/yuanchu/mom/mapper/InsProductMapper.java
@@ -3,6 +3,8 @@
import com.yuanchu.mom.pojo.InsProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import java.util.Map;
/**
* @author Administrator
* @description é’ˆå¯¹è¡¨ã€ins_product(检验项目)】的数据库操作Mapper
@@ -13,6 +15,8 @@
    int selectOrderManDay(Integer orderId);
    Map<String, String> selectUserById(Integer userId);
}
inspect-server/src/main/java/com/yuanchu/mom/service/InsReportService.java
@@ -17,4 +17,6 @@
    Map<String,Object> pageInsReport(Page page, ReportPageDto reportPageDto);
    String wordToHtml(String path);
}
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -11,24 +11,33 @@
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.config.ConfigureBuilder;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.dto.InsOrderPlanDTO;
import com.yuanchu.mom.dto.SampleProductDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.mapper.*;
import com.yuanchu.mom.pojo.*;
import com.yuanchu.mom.service.InsOrderPlanService;
import com.yuanchu.mom.service.InsOrderService;
import com.yuanchu.mom.service.StandardTemplateService;
import com.yuanchu.mom.utils.GiveCode;
import com.yuanchu.mom.utils.QueryWrappers;
import com.yuanchu.mom.vo.InsOrderPlanVO;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.ResourceUtils;
import javax.annotation.Resource;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.stream.Collectors;
@@ -36,24 +45,34 @@
 * æ£€éªŒä»»åŠ¡-业务实现层
 */
@Service
@AllArgsConstructor
//@AllArgsConstructor
public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService {
    @Resource
    private InsSampleMapper insSampleMapper;
    @Resource
    private InsSampleUserMapper insSampleUserMapper;
    @Resource
    private GetLook getLook;
    @Resource
    private InsOrderMapper insOrderMapper;
    @Resource
    private InsOrderService insOrderService;
    @Resource
    private StandardTemplateService standardTemplateService;
    @Resource
    private InsOrderStateMapper insOrderStateMapper;
    @Resource
    private InsProductMapper insProductMapper;
    @Value("${wordUrl}")
    private String wordUrl;
    @Resource
    private GiveCode giveCode;
    @Resource
    private InsReportMapper insReportMapper;
    @Override
    public Map<String, Object> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
@@ -162,22 +181,36 @@
        insOrderStateMapper.update(null, Wrappers.<InsOrderState>lambdaUpdate().eq(InsOrderState::getInsOrderId, orderId).eq(InsOrderState::getLaboratory, laboratory).set(InsOrderState::getInsTime, LocalDateTime.now()).set(InsOrderState::getInsState, num).set(InsOrderState::getVerifyTell, tell).set(InsOrderState::getVerifyUser, getLook.selectPowerByMethodAndUserId(null).get("userId")));
        List<InsOrderState> insOrderStates = insOrderStateMapper.selectList(Wrappers.<InsOrderState>lambdaQuery().eq(InsOrderState::getInsOrderId, orderId));
        long count = insOrderStates.stream().filter(a -> a.getInsState() == 5).count();
        if (count == insOrderStates.size()) {
            XWPFTemplate template = XWPFTemplate.compile("template.docx").render(
        if (count == insOrderStates.size() && num == 5) {
            InsOrder insOrder = insOrderMapper.selectById(orderId);
            Map<String, String> user = insProductMapper.selectUserById(insOrder.getUserId());
            List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId);
            samples.forEach(System.out::println);
            InsReport insReport = new InsReport();
            insReport.setCode(giveCode.giveCode("JCZX/TX-", "ins_report", "-", "yyMMdd"));
            insReport.setInsOrderId(orderId);
            String url;
            try {
                url = ResourceUtils.getURL("classpath:static/report-template.docx").getPath();
            } catch (FileNotFoundException e) {
                throw new ErrorException("找不到模板文件");
            }
            XWPFTemplate template = XWPFTemplate.compile(url).render(
                    new HashMap<String, Object>() {{
                        put("title", "Hi, poi-tl Word模板引擎");
                        put("order", insOrder);
                        put("report", insReport);
                        put("user", user);
                        put("samples", samples);
                        put("sampleSize", samples.size() + samples.get(0).getUnit());
                    }});
            try {
                template.writeAndClose(new FileOutputStream("output.docx"));
                String name = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yy_MM_dd_HH_mm_ss")) + ".docx";
                template.writeAndClose(new FileOutputStream(wordUrl + "/" + name));
                insReport.setUrl("/word/"+ name);
                insReportMapper.insert(insReport);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId));
            insSamples.forEach(a -> {
                System.out.println(a);
                List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery().eq(InsProduct::getInsSampleId, a.getId()));
                insProducts.forEach(System.out::println);
            });
        }
        return 1;
    }
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsReportServiceImpl.java
@@ -1,19 +1,28 @@
package com.yuanchu.mom.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.yuanchu.mom.common.GetLook;
import com.yuanchu.mom.common.PrintChina;
import com.yuanchu.mom.dto.InsOrderPlanDTO;
import com.yuanchu.mom.dto.ReportPageDto;
import com.yuanchu.mom.dto.SampleOrderDto;
import com.yuanchu.mom.exception.ErrorException;
import com.yuanchu.mom.pojo.InsReport;
import com.yuanchu.mom.service.InsReportService;
import com.yuanchu.mom.mapper.InsReportMapper;
import com.yuanchu.mom.utils.QueryWrappers;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@@ -23,13 +32,17 @@
* @createDate 2024-03-17 22:10:02
*/
@Service
@AllArgsConstructor
public class InsReportServiceImpl extends ServiceImpl<InsReportMapper, InsReport>
    implements InsReportService{
    @Resource
    private GetLook getLook;
    @Resource
    private InsReportMapper insReportMapper;
    @Value("${wordUrl}")
    private String wordUrl;
    @Override
    public Map<String, Object> pageInsReport(Page page, ReportPageDto reportPageDto) {
@@ -40,6 +53,18 @@
        map.put("body", insReportMapper.pageInsReport(page, QueryWrappers.queryWrappers(reportPageDto)));
        return map;
    }
    @Override
    public String wordToHtml(String path) {
        try(ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            Document document = new Document();
            document.loadFromFile(path.replace("/word", wordUrl));
            document.saveToFile(outputStream, FileFormat.Html);
            return outputStream.toString();
        } catch (Exception e) {
            throw new ErrorException("转换失败");
        }
    }
}
inspect-server/src/main/resources/mapper/InsProductMapper.xml
@@ -46,4 +46,7 @@
        left join ins_product ip on isa.id = ip.ins_sample_id
        where io.id = #{orderId}
    </select>
    <select id="selectUserById" resultType="java.util.Map">
        select name,company,phone,address from user where id = #{userId}
    </select>
</mapper>
inspect-server/src/main/resources/static/report-template.docx
Binary files differ
system-run/src/main/resources/application-dev.yml
@@ -18,10 +18,12 @@
# ç…§ç‰‡å­˜å‚¨è·¯å¾„+++++++++++++++++++++++++++运维需要配置+++++++++++++++++++++++++++
file:
  path: D:\Download
  path: D:\项目文件存储\image
  # ä¸Šä¼ æ–‡ä»¶å…è®¸çš„æ‰©å±•名
  allowed: png,jpg,jpeg,gif
wordUrl: D:\项目文件存储\word
mybatis-plus:
  type-aliases-package: com.yuanchu.mom.pojo
  mapper-locations: classpath*:/mapper/*.xml
system-run/src/main/resources/application.yml
@@ -26,4 +26,4 @@
  okhttp:
    enabled: true # å¼€å¯ okhttp
outPath: D:/Download/
outPath: D:\项目文件存储\image
wordToHtml.html
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /><title></title><link href="wordToHtml_styles.css" type="text/css" rel="stylesheet"/></head><body /></html>
wordToHtml_styles.css
¶Ô±ÈÐÂÎļþ
@@ -0,0 +1,2 @@
body{ font-family:'Times New Roman'; font-size:1em; }
ul, ol{ margin-top: 0; margin-bottom: 0; }