chenrui
2025-03-24 28931a8caa40a965738838e967533762162a7583
inspect-server/src/main/java/com/yuanchu/mom/service/impl/InsOrderPlanServiceImpl.java
@@ -24,6 +24,7 @@
import com.yuanchu.mom.service.*;
import com.yuanchu.mom.utils.*;
import com.yuanchu.mom.vo.*;
import org.apache.poi.hwpf.usermodel.*;
import org.apache.poi.ss.usermodel.CellValue;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
@@ -35,6 +36,7 @@
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import java.io.*;
import java.nio.file.Files;
@@ -48,6 +50,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import org.apache.poi.hwpf.HWPFDocument;
/**
 * 检验任务-业务实现层
@@ -357,6 +361,14 @@
            } else if (ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验") && split[split.length - 1].equals("csv") && insOrder.getSampleType().equals("无源器件")) {
                dianLuUtils.readDianLuFile3(sampleId, insOrderFile);
            }
            // 电路实验返回文件名
            if(ObjectUtils.isNotEmpty(sonLaboratory) && sonLaboratory.equals("电路试验")){
                return pathName;
            }
            // 震动doc文件解析
            if(filename.toLowerCase().contains(".doc") && sonLaboratory.equals("振动")){
                return docAnalysis(urlString,orderId,sampleId,file.getOriginalFilename());
            }
        } catch (Exception e) {
            throw new ErrorException(e.getMessage());
        }
@@ -652,6 +664,16 @@
                } catch (Exception e) {
                    result.setAfterCheck("");//''
                }
                //实验结果
                try {
                    JSONObject resValue = JSON.parseObject(JSON.toJSONString(jo.get("testResult")));
                    if (resValue.get("v") != null) {
                        Object o = JSON.parseObject(JSON.toJSONString(resValue.get("v"))).get("v");
                        result.setTestResult(o.equals("") ? null : (o.toString()));
                    }
                } catch (Exception e) {
                    result.setTestResult("");//''
                }
                //设备编号
                if (jo.get("equipValue") != null) {
                    JSONArray jsonArray2 = JSON.parseArray(JSON.toJSONString(jo.get("equipValue")));
@@ -894,6 +916,122 @@
        return 1;
    }
    /**
     * 震动doc文件解析
     * @param urlString
     * @param orderId
     * @param sampleId
     * @param originFileName
     * @return
     */
    private Map<String, String> docAnalysis(String urlString,Integer orderId,Integer sampleId,String originFileName) {
        Map<String, String> analysisMap = new HashMap<>();
        try {
            File file = new File(urlString);
            HWPFDocument document = new HWPFDocument(new FileInputStream(file));
            Range range = document.getRange();
            TableIterator tableIterator = new TableIterator(range);
            List<Table> tableList = new ArrayList<>();
            while (tableIterator.hasNext()) {
                tableList.add(tableIterator.next());
            }
            for (int tableIndex = 0; tableIndex < tableList.size(); tableIndex++) {
                // 取第一个表单限制参数的  振动台型号、运动部件等效质量、试件质量数值
                if(tableIndex == 0){
                    Table table = tableList.get(0);
                    for (int i = 0; i < table.numRows(); i++) {
                        if(table.getRow(i).numCells() < 2){
                            continue;
                        }
                        String columnText = ObjectUtils.isEmpty(table.getRow(i).getCell(0))? "" : table.getRow(i).getCell(0).text();
                        String columnValue = ObjectUtils.isEmpty(table.getRow(i).getCell(1))? "" : table.getRow(i).getCell(1).text();
                        if(columnValue.contains("\u0007")){
                            columnValue = columnValue.replace("\u0007","");
                        }
                        if(columnText.contains("\u0007")){
                            columnText = columnText.replace("\u0007","");
                        }
                        if(columnText.equals("振动台型号")){
                            analysisMap.put("11",columnValue);
                        }
                        if(columnText.equals("运动部件等效质量")){
                            analysisMap.put("12",columnValue);
                        }
                        if(columnText.equals("试件质量")){
                            analysisMap.put("1",columnValue);
                        }
                    }
                }
                //取第一个表单输入通道参数第一条数据
                if(tableIndex == 1){
                    Table table = tableList.get(1);
                    if(ObjectUtils.isNotEmpty(table) && table.numRows() > 1 && table.getRow(1).numCells() >= 3){
                        String columnValue = ObjectUtils.isEmpty(table.getRow(1).getCell(2))? "" : table.getRow(1).getCell(2).text();
                        if(columnValue.contains("\u0007")){
                            columnValue = columnValue.replace("\u0007","");
                        }
                        analysisMap.put("9",columnValue);
                    }
                }
                // 取最后一个表单第三第四行信息
                if(tableIndex == tableList.size() - 1){
                    Table table = tableList.get(tableIndex);
                    for (int i = 0; i < table.numRows(); i++) {
                        if(table.getRow(i).numCells() < 2){
                            continue;
                        }
                        String columnText = ObjectUtils.isEmpty(table.getRow(i).getCell(0))? "" : table.getRow(i).getCell(0).text();
                        String columnValue = ObjectUtils.isEmpty(table.getRow(i).getCell(1))? "" : table.getRow(i).getCell(1).text();
                        if(columnValue.contains("\u0007")){
                            columnValue = columnValue.replace("\u0007","");
                        }
                        if(columnText.contains("\u0007")){
                            columnText = columnText.replace("\u0007","");
                        }
                        if(columnText.contains("总运行时间")){
                            analysisMap.put("13",columnValue);
                        }
                        if(columnText.contains("试验扫频数")){
                            analysisMap.put("10",columnValue);
                        }
                    }
                }
            }
            // 图片绑定
            List<Picture> pictureList = document.getPicturesTable().getAllPictures();
            String[] split = originFileName.split("\\.");
            String docName = "";
            if(null != split && split.length > 0){
                docName = split[0];
            }
            for (Picture picture : pictureList) {
                byte[] pictureData = picture.getContent();
                File imgDir = new File(imgUrl);
                if (!imgDir.exists()) {
                    imgDir.mkdirs();
                }
                String filename = docName + "_" + UUID.randomUUID()+".png";
                File pictureFile = new File(imgUrl + File.separatorChar + filename);
                // 创建输出流以将图片数据写入到指定路径
                try (OutputStream outputStream = new FileOutputStream(pictureFile)) {
                    // 写入数据
                    outputStream.write(pictureData);
                }
                InsOrderFile insOrderFile = new InsOrderFile();
                insOrderFile.setInsOrderId(orderId);
                insOrderFile.setInsSampleId(sampleId);
                insOrderFile.setSonLaboratory("振动");
                insOrderFile.setType(1);
                insOrderFile.setFileName(filename);
                insOrderFile.setFileUrl(filename);
                insOrderFileMapper.insert(insOrderFile);
            }
        }catch (Exception e){
            log.error(e.getMessage());
        }
        return analysisMap;
    }
    //温湿度试验+功率试验的保存检验内容
    @Override
    public int saveInsContext3(InsProductResult insProductResult) {
@@ -1072,6 +1210,9 @@
                    /*生成对应的检验报告*/
                    List<InsReportDto1> insReportDto1s=insOrderUserMapper.selectInsReportDto1(insOrder.getId());
                    createReport(insOrder.getId(),insReportDto1s);
                    //该订单闭环
                    insOrder.setState(4);
                    insOrderMapper.updateById(insOrder);
                    break;
            }
        }
@@ -1159,6 +1300,9 @@
                    /*生成对应的检验报告*/
                    List<InsReportDto1> insReportDto1s=insOrderUserMapper.selectInsReportDto1(insOrder.getId());
                    createReport(insOrder.getId(),insReportDto1s);
                    //订单闭环
                    insOrder.setState(4);
                    insOrderMapper.updateById(insOrder);
                    break;
            }
        }
@@ -1170,11 +1314,12 @@
    private void createReport(Integer orderId,List<InsReportDto1> insReportDto1s){
        for (InsReportDto1 insReportDto1 : insReportDto1s) {
            if (ObjectUtils.isNotEmpty(insReportDto1.getInsReportDto2s())){
                try{
                    wordUtils.generateReport(orderId, insReportDto1);
                }catch (Exception e){
                    throw new ErrorException("报告格式生成有误,请联系管理员!");
                }
                wordUtils.generateReport(orderId, insReportDto1);
//                try{
//                    wordUtils.generateReport(orderId, insReportDto1);
//                }catch (Exception e){
//                    throw new ErrorException("报告格式生成有误,请联系管理员!");
//                }
            }
        }
    }
@@ -1237,8 +1382,8 @@
            String str = "";
            int count = 0;
            for (InsProduct product : insProducts) {
                //辐射试验,温湿度试验,功率试验的检验项目,不需要去手动填写检验值,只需要上传表格文件就可以了,后台提交的时候校验跳过这个检验项目
                if (product.getInspectionItem().equals("辐射试验") || product.getInspectionItem().equals("温湿度试验") || product.getInspectionItem().equals("功率试验")) {
                //温湿度试验,功率试验的检验项目,不需要去手动填写检验值,只需要上传表格文件就可以了,后台提交的时候校验跳过这个检验项目
                if ( product.getInspectionItem().equals("温湿度试验") || product.getInspectionItem().equals("功率试验")) {
                    product.setInsResult(3);//不判定
                    insProductMapper.updateById(product);
                    continue;