deslrey
2 天以前 4f258638d62ccaae0050f1ed6c7231941b66fb50
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -2,6 +2,7 @@
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
@@ -30,13 +31,13 @@
import com.ruoyi.basic.pojo.IfsInventoryQuantity;
import com.ruoyi.basic.pojo.StandardTemplate;
import com.ruoyi.basic.service.StandardTemplateService;
import com.ruoyi.basic.vo.IfsInventoryQuantityVO;
import com.ruoyi.common.constant.DictDataConstants;
import com.ruoyi.common.constant.InsOrderTypeConstants;
import com.ruoyi.common.constant.MenuJumpPathConstants;
import com.ruoyi.common.core.domain.entity.Custom;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.enums.OrderType;
import com.ruoyi.common.utils.*;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.*;
@@ -46,13 +47,10 @@
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo;
import com.ruoyi.inspect.vo.InsOrderPlanVO;
import com.ruoyi.inspect.vo.InsSampleUserVO;
import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper;
import com.ruoyi.performance.mapper.PerformanceShiftMapper;
import com.ruoyi.performance.mapper.ShiftTimeMapper;
import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHours;
import com.ruoyi.performance.pojo.AuxiliaryOutputWorkingHoursTemporary;
import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursService;
import com.ruoyi.performance.service.AuxiliaryOutputWorkingHoursTemporaryService;
import com.ruoyi.system.mapper.CustomMapper;
import com.ruoyi.system.mapper.UserMapper;
import com.ruoyi.system.service.ISysDictTypeService;
@@ -75,9 +73,7 @@
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -132,6 +128,8 @@
    @Resource
    private IfsInventoryQuantityMapper ifsInventoryQuantityMapper;
    @Resource
    private IfsPartPropsRecordMapper ifsPartPropsRecordMapper;
    @Resource
    private InsReportService insReportService;
    @Resource
    private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper;
@@ -168,9 +166,7 @@
    public IPage<InsOrderPlanVO> selectInsOrderPlanList(Page page, InsOrderPlanDTO insOrderPlanDTO) {
        // todo: 仅看自己或者实验室
        //获取当前人所属实验室id
        String laboratory = null;
        String userName = null;
        Integer userId = null;
        if (ObjectUtil.isNotEmpty(insOrderPlanDTO.getUserId())) {
@@ -181,13 +177,17 @@
        Integer isCheck = insOrderPlanDTO.getIsCheck();
        insOrderPlanDTO.setIsCheck(null);
        String sonLaboratory = insOrderPlanDTO.getSonLaboratory();//试验室
        // 数据置空,防止反射生成重复数据
        String materialProp = insOrderPlanDTO.getMaterialProp();
        insOrderPlanDTO.setMaterialProp(null);
        IPage<InsOrderPlanVO> insOrderPage = insSampleMapper.findInsSampleAndOrder(page,
                QueryWrappers.queryWrappers(insOrderPlanDTO),
                userName,
                userId,
                sonLaboratory,
                laboratory,
                isCheck);
                isCheck,
                materialProp);
        return insOrderPage;
    }
@@ -278,7 +278,7 @@
    }
    @Override
    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory) {
    public Map<String, Object> checkSubmitPlan(Integer orderId, String laboratory) {
        Map<String, Object> map = new HashMap<>();
        List<String> collect = new ArrayList<>();
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
@@ -308,15 +308,15 @@
        //查询ifs拆分订单是否有已下单但是未检完的单子
        long count = 0L;
        InsOrder insOrder = insOrderMapper.selectById(orderId);
        if(Objects.nonNull(insOrder.getIfsInventoryId())){
        if (Objects.nonNull(insOrder.getIfsInventoryId())) {
            IfsInventoryQuantity one = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
            //过滤出不合格或未提交的单子
            count = ifsInventoryQuantityMapper.selectSplitOrderList(one.getPartNo(),one.getLineNo(),one.getReleaseNo(),one.getReceiptNo(),one.getOrderNo())
            count = ifsInventoryQuantityMapper.selectSplitOrderList(one.getPartNo(), one.getLineNo(), one.getReleaseNo(), one.getReceiptNo(), one.getOrderNo())
                    .stream()
                    .filter(f->(Objects.nonNull(f.getInsOrderId()) && !Objects.equals(f.getInsOrderId(),orderId)) && (Objects.isNull(f.getInsResult()) || 0==f.getInsResult())).count();
                    .filter(f -> (Objects.nonNull(f.getInsOrderId()) && !Objects.equals(f.getInsOrderId(), orderId)) && (Objects.isNull(f.getInsResult()) || 0 == f.getInsResult())).count();
        }
        map.put("errorMsg",collect);
        map.put("unInsOrderCount",count);
        map.put("errorMsg", collect);
        map.put("unInsOrderCount", count);
        return map;
    }
@@ -624,6 +624,7 @@
    /**
     * 查询模板内容
     *
     * @param order
     * @param insProducts
     */
@@ -688,6 +689,7 @@
    /**
     * todo: 原始记录模板清除没有使用的检验项(暂时有bug无法使用)
     *
     * @param sheet
     * @param itemNameList
     */
@@ -760,6 +762,7 @@
    /**
     * 坐标拼接
     *
     * @param r 横坐标
     * @param c 纵坐标
     * @return
@@ -772,7 +775,7 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode,Boolean registerInsResults) {
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode, Boolean registerInsResults) {
        InsOrder order = insOrderMapper.selectById(orderId);
        // 1. 判断是否有重复编号, 有重复编号做提醒
        Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
@@ -811,7 +814,7 @@
            int count = 0;
            for (InsProduct product : insProducts) {
                count++;
                str +=  (count != 0 ? "\n" : "") + count + ":" +
                str += (count != 0 ? "\n" : "") + count + ":" +
                        product.getInspectionItemClass() + " " +
                        product.getInspectionItem() + " " +
                        product.getInspectionItemSubclass();
@@ -941,7 +944,7 @@
            // 登记检验结果
            // 判断是否有不合格, 有不合格不能移库
            // todo: ifs移库
            insReportService.isRawMaterial(order,registerInsResults,false);
            insReportService.isRawMaterial(order, registerInsResults, false);
            // 15 判断当前样品是否为原材料, 原材料需要进行数据分析, 判断之前10条数据同一个供应商, 同一个检验项的偏差是否超过10%
            // 查询ifs信息获取获取前10个供应商一样的, 检验项一样信息
@@ -968,6 +971,7 @@
    /**
     * *****添加分析数据******
     *
     * @param productList
     * @param ifsInventoryQuantity
     * @param order
@@ -1058,6 +1062,7 @@
    /**
     * *****计算偏差****
     *
     * @param data
     * @param targetStr
     * @return
@@ -1083,11 +1088,12 @@
    /**
     * *****计算偏差****
     *
     * @param targetStr
     * @return
     */
    public static double isDeviationOverTenPercentByAsked(String asked, String targetStr) {
        if(!isNumeric(asked)) return 0;
        if (!isNumeric(asked)) return 0;
        double average = Double.parseDouble(asked);
        double target = Double.parseDouble(targetStr);
@@ -1101,6 +1107,7 @@
    /**
     * ******原始记录模板复制*****
     *
     * @param orderId
     * @param ids
     */
@@ -1134,6 +1141,7 @@
    /**
     * 检验任务复核
     *
     * @param orderId
     * @param laboratory
     * @param type
@@ -1263,6 +1271,7 @@
    /**
     * 生成报告
     *
     * @param orderId
     */
    private void generateReport(Integer orderId) {
@@ -1302,6 +1311,7 @@
    /**
     * 电缆配置, 查看配置标识
     *
     * @param id
     * @param laboratory
     * @return
@@ -1313,6 +1323,7 @@
    /**
     * 原材料查看标识
     *
     * @param id
     * @param laboratory
     * @return
@@ -1324,6 +1335,7 @@
    /**
     * 查看重复标识
     *
     * @param id
     * @param laboratory
     * @return
@@ -1335,6 +1347,7 @@
    /**
     * 新增不合格复测内容
     *
     * @return
     */
    @Override
@@ -1531,6 +1544,7 @@
    /**
     * 查询进货原始记录
     *
     * @param insOrderId
     * @return
     */
@@ -1586,6 +1600,7 @@
    /**
     * 保存原材料进货验证
     *
     * @param factoryVerify
     * @return
     */
@@ -1636,7 +1651,100 @@
    /*****************************************************  小报告    ***************************************************************************/
    /**
     * 设置表格样式
     *
     * @param max 标识最大个数
     * @return
     */
    private TableStyle setTableStyle(int max) {
        //设置样式
        TableStyle tableStyle = new TableStyle();
        if (max <= 5) {
            for (int i = 1; i <= max; i++) {
                // 根据检验结果个数修改长度
                switch (i) {
                    case 1:
                        tableStyle.setColWidths(new int[]{650, 2900, 850, 2300, 2100, 1200});
                        break;
                    case 2:
                        tableStyle.setColWidths(new int[]{650, 2700, 850, 2200, 1200, 1200, 1200});
                        break;
                    case 3:
                        tableStyle.setColWidths(new int[]{650, 2700, 850, 1600, 1000, 1000, 1000, 1200});
                        break;
                    case 4:
                        tableStyle.setColWidths(new int[]{650, 2400, 850, 1500, 850, 850, 850, 850, 1200});
                        break;
                    case 5:
                        tableStyle.setColWidths(new int[]{650, 2200, 850, 1350, 770, 770, 770, 770, 770, 1100});
                        break;
                }
            }
        }
        tableStyle.setWidth("10000");
        tableStyle.setAlign(TableRowAlign.CENTER);
        BorderStyle borderStyle = new BorderStyle();
        borderStyle.setColor("000000");
        borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE);
        borderStyle.setSize(4);
        tableStyle.setLeftBorder(borderStyle);
        tableStyle.setRightBorder(borderStyle);
        tableStyle.setInsideHBorder(borderStyle); // 设置水平内边框
        tableStyle.setInsideVBorder(borderStyle);
        return tableStyle;
    }
    /**
     * 处理有电缆颜色标识的检测项
     *
     * @param cableTags  电缆颜色标识
     * @param collect    检测项列表
     * @param startIndex 起始下标
     * @param endIndex   结束下标
     * @return
     */
    private List<SampleProductExportDto> transformSampleProduct(List<String> cableTags, Map<String, List<SampleProductExportDto>> collect, int startIndex, int endIndex) {
        List<SampleProductExportDto> sampleProductExportDtos = new ArrayList<>();
        for (String s : collect.keySet()) {
            List<String> lastValueList = new ArrayList<>();
            SampleProductExportDto dto = new SampleProductExportDto();
            BeanUtil.copyProperties(collect.get(s).get(0), dto);
            Set<String> tellSet = new HashSet<>();
            for (int i = startIndex; i < endIndex; i++) {
                String cableTag = cableTags.get(i);
                for (SampleProductExportDto sDto : collect.get(s)) {
                    tellSet.add(sDto.getTell());
                    if (sDto.getCableTag().equals(cableTag)) {
                        lastValueList.add(sDto.getLastValue());
                    }
                }
            }
            //切割电缆配置项
            dto.setTell(String.join("\n", tellSet.stream().sorted(Comparator.naturalOrder()).collect(Collectors.toList())));
            dto.setLastValueList(lastValueList);
            sampleProductExportDtos.add(dto);
        }
        return sampleProductExportDtos;
    }
    /**
     * 检测项排序
     *
     * @param sourceMap
     * @param targetMap
     */
    private void sortSampleProduct(Map<String, List<SampleProductExportDto>> sourceMap, Map<String, List<SampleProductExportDto>> targetMap) {
        List<Map.Entry<String, List<SampleProductExportDto>>> entries = new ArrayList<>(sourceMap.entrySet());
        entries.sort(Comparator.comparingInt(o -> (o.getValue().get(0).getSort() == null ? 0 : o.getValue().get(0).getSort())));
        for (Map.Entry<String, List<SampleProductExportDto>> entry : entries) {
            targetMap.put(entry.getKey(), entry.getValue());
        }
    }
    /**
     * 小报告生成
     *
     * @param orderId
     * @param insOrder
     * @param insSamples
@@ -1653,11 +1761,17 @@
        enterFactoryReport.setSample(insOrder.getSample());
        // 获取ifs数据
        IfsInventoryQuantity ifsInventoryQuantity = ifsInventoryQuantityMapper.selectById(insOrder.getIfsInventoryId());
        //查询零件属性
        IfsPartPropsRecord ifsPartPropsRecord = ifsPartPropsRecordMapper.selectOne(Wrappers.<IfsPartPropsRecord>lambdaQuery()
                .eq(IfsPartPropsRecord::getIfsInventoryId, ifsInventoryQuantity.getId()));
        if (Objects.nonNull(ifsPartPropsRecord)) {
            enterFactoryReport.setOuterColor(ifsPartPropsRecord.getOuterColor());
        }
        enterFactoryReport.setQtyArrived(ifsInventoryQuantity.getQtyArrived() == null ? "" :
                ifsInventoryQuantity.getQtyArrived().stripTrailingZeros().toPlainString() + ifsInventoryQuantity.getBuyUnitMeas());
        enterFactoryReport.setQuantity(insOrder.getTestQuantity());
        enterFactoryReport.setPartDesc(insOrder.getPartDetail());
        enterFactoryReport.setSupplierName("**********");
        enterFactoryReport.setSupplierName(ifsInventoryQuantity.getSupplierName());
        enterFactoryReport.setLotBatchNo(ifsInventoryQuantity.getUpdateBatchNo());
        // 检测依据
@@ -1675,6 +1789,7 @@
        List<RowRenderData> rows = new ArrayList<>();
        List<TextRenderData> text = new ArrayList<>();
        RowRenderData rowRenderData = null;
        List<Map<String, Object>> cableTagEnclosureTables = new ArrayList<>();
        // 查询检验内容
        List<SampleProductExportDto> sampleProductDto2s = insOrderMapper.selectSampleBySampleId(insSamples.stream()
@@ -1685,21 +1800,168 @@
        List<SampleProductExportDto> sampleList = new ArrayList<>();
        Integer max = insSamples.stream().mapToInt(InsSample::getQuantity).sum();
        TableRenderData tableRenderData = new TableRenderData();
        String templateName;
        if (StringUtils.equals(OrderType.WG.getValue(), ifsInventoryQuantity.getOrderType())) {
            //过滤不判定的检测项
            List<SampleProductExportDto> filterItems = sampleProductDto2s.stream().filter(f -> f.getInsResult() != 3).collect(Collectors.toList());
            int maxCableTag = 5;//单个表格,电缆颜色标识最大个数
            templateName = "/static/small-wg-report-template.docx";
            //查询检验单消息
            InsSampleUserVO insSampleUser = insSampleUserMapper.selectUserNameByOrderId(orderId);
            if (Objects.nonNull(insSampleUser)) {
                enterFactoryReport.setPartDesc(insSampleUser.getModel());
                enterFactoryReport.setInspector(insSampleUser.getInspector());
                enterFactoryReport.setInspectDate(insSampleUser.getInspectDate());
            }
        // 转成Mpa进行排序
        Map<String, List<SampleProductExportDto>> sortedMap = sampleProductDto2s.stream()
                .filter(sampleProductDto2 -> StringUtils.isNotBlank(sampleProductDto2.getInspectionItem()))
                .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem));
        List<Map.Entry<String, List<SampleProductExportDto>>> entries = new ArrayList<>(sortedMap.entrySet());
        entries.sort((o1, o2) -> (o1.getValue().get(0).getSort() == null ? 0 : o1.getValue().get(0).getSort())
                - (o2.getValue().get(0).getSort() == null ? 0 : o2.getValue().get(0).getSort()));
        // 创建一个 LinkedHashMap 来保持插入顺序
        Map<String, List<SampleProductExportDto>> item = new LinkedHashMap<>();
        for (Map.Entry<String, List<SampleProductExportDto>> entry : entries) {
            item.put(entry.getKey(), entry.getValue());
            Map<String, List<SampleProductExportDto>> totalItem = new LinkedHashMap<>();//检测项列表
            Map<String, List<SampleProductExportDto>> cableTagItem = new LinkedHashMap<>();//电缆配置检测项
            Map<String, List<SampleProductExportDto>> cableTagEnclosureItem = new LinkedHashMap<>();//电缆配置检测项附件
            AtomicInteger finalIndex = new AtomicInteger(1);
            List<String> cableTags = insOrderMapper.selectSampleCableTag(insSample.getId());
            max = Math.max(cableTags.size(), 1);
            //处理电缆配置检测项
            Map<String, List<SampleProductExportDto>> tempMap = new HashMap<>();
            Map<String, List<SampleProductExportDto>> tempMap2 = new HashMap<>();
            Map<String, List<SampleProductExportDto>> listMap2 = filterItems.stream()
                    .filter(f -> StringUtils.isNotBlank(f.getCableTag()) && StringUtils.isNotBlank(f.getInspectionItem()))
                    .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem));
            for (String key : listMap2.keySet()) {
                List<SampleProductExportDto> sampleProductExportDtos;
                List<SampleProductExportDto> sampleProductExportDtos2;
                //处理电缆配置项
                Map<String, List<SampleProductExportDto>> collect = listMap2.get(key).stream().collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItemSubclass));
                if (cableTags.size() > maxCableTag) {
                    sampleProductExportDtos = transformSampleProduct(cableTags, collect, 0, maxCableTag);
                    sampleProductExportDtos2 = transformSampleProduct(cableTags, collect, maxCableTag, cableTags.size());
                    tempMap2.put(key, sampleProductExportDtos2);
                } else {
                    sampleProductExportDtos = transformSampleProduct(cableTags, collect, 0, cableTags.size());
                }
                cableTagItem.put(key, sampleProductExportDtos);
            }
            //处理非电缆配置检测项
            Map<String, List<SampleProductExportDto>> listMap = filterItems.stream()
                    .filter(f -> StringUtils.isBlank(f.getCableTag()) && StringUtils.isNotBlank(f.getInspectionItem()))
                    .collect(Collectors.groupingBy(s -> s.getInspectionItem() + "&"));
            //合并检测项列表
            tempMap.putAll(cableTagItem);
            tempMap.putAll(listMap);
            sortSampleProduct(tempMap, totalItem);
            int tagNum = Math.min(max, maxCableTag);
            List<String> tagList = cableTags.isEmpty() ? new ArrayList<>() : cableTags.subList(0, tagNum);
            handlerSampleItems(OrderType.WG.getValue(), totalItem, finalIndex, sampleList, tagNum, text, rows, rowRenderData, resultCh, tagList, true);
            if (CollectionUtil.isNotEmpty(tempMap2)) {
                sortSampleProduct(tempMap2, cableTagEnclosureItem);
                //生成附件电缆表格
                TableRenderData tableRenderData2 = new TableRenderData();
                List<String> newCableTags = cableTags.subList(maxCableTag, cableTags.size());
                AtomicInteger finalIndex2 = new AtomicInteger(1);
                List<TextRenderData> newText = new ArrayList<TextRenderData>();
                List<RowRenderData> newRows = new ArrayList<>();
                RowRenderData newRowRenderData = null;
                handlerSampleItems(OrderType.WG.getValue(), cableTagEnclosureItem, finalIndex2, new ArrayList<>(), newCableTags.size(), newText, newRows, newRowRenderData, resultCh, newCableTags, true);
                tableRenderData2.setRows(newRows);
                tableRenderData2.setTableStyle(setTableStyle(newCableTags.size()));
                HashMap<String, Object> tableMap = new HashMap<>();
                tableMap.put("enclosureTable", tableRenderData2);
                tableMap.put("resultCh", resultCh);
                tableMap.put("writeUrl", null);
                tableMap.put("examineUrl", null);
                tableMap.put("ratifyUrl", null);
                tableMap.put("writeDateUrl", null);
                tableMap.put("examineDateUrl", null);
                tableMap.put("ratifyDateUrl", null);
                tableMap.put("seal1", null);
                cableTagEnclosureTables.add(tableMap);
            }
            tableRenderData.setRows(rows);
            tableRenderData.setTableStyle(setTableStyle(tagNum));
            if (!resultCh.get().isEmpty()) {
                resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。(盖章有效)");
            } else {
                resultCh.set("本产品符合相关标准要求,经检验合格准予出厂(盖章有效)");
            }
        } else {
            templateName = "/static/small-report-template.docx";
            // 转成Mpa进行排序
            Map<String, List<SampleProductExportDto>> sortedMap = sampleProductDto2s.stream()
                    .filter(sampleProductDto2 -> StringUtils.isNotBlank(sampleProductDto2.getInspectionItem()))
                    .collect(Collectors.groupingBy(SampleProductExportDto::getInspectionItem));
//            // 创建一个 LinkedHashMap 来保持插入顺序
            Map<String, List<SampleProductExportDto>> item = new LinkedHashMap<>();
            sortSampleProduct(sortedMap, item);
            AtomicInteger finalIndex = new AtomicInteger(1);
            handlerSampleItems(OrderType.RAW.getValue(), item, finalIndex, sampleList, max, text, rows, rowRenderData, resultCh, null, true);
            tableRenderData.setRows(rows);
            tableRenderData.setTableStyle(setTableStyle(max));
            if (!resultCh.get().equals("")) {
                resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。");
            } else {
                resultCh.set("经检验此批" + enterFactoryReport.getSample() + "各项目均符合检验规范要求。");
            }
        }
        AtomicInteger finalIndex = new AtomicInteger(1);
        ConfigureBuilder builder = Configure.builder();
        builder.useSpringEL(true);
        InputStream inputStream = this.getClass().getResourceAsStream(templateName);
        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
                new HashMap<String, Object>() {{
                    put("report", enterFactoryReport);
                    put("standardMethod", standardMethod2.toString().equals("null") ? "" : standardMethod2);
                    put("orderType", orderType);
                    put("table", tableRenderData);
                    put("enclosureTables", cableTagEnclosureTables.isEmpty() ? null : cableTagEnclosureTables);
                    put("resultCh", resultCh);
                    put("writeUrl", null);
                    put("examineUrl", null);
                    put("ratifyUrl", null);
                    put("writeDateUrl", null);
                    put("examineDateUrl", null);
                    put("ratifyDateUrl", null);
                    put("seal1", null);
                }});
        try {
            // 修改换行和合并问题
            updaeMerge(template.getXWPFDocument(), true);
            String name = insReport.getCode().replace("/", "") + "-J.docx";
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name)));
            insReport.setUrl("/word/" + name);
            insReport.setIsPass(0);
            insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人
            insReport.setWriteTime(LocalDateTime.now());//提交时间
            // 查询报告, 判断之前是否添加过, 添加过删除
            insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                    .eq(InsReport::getInsOrderId, insOrder.getId()));
            insReportMapper.insert(insReport);
            inputStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 处理常规检测项
     *
     * @param item
     * @param finalIndex
     * @param sampleList
     * @param max
     * @param text
     * @param rows
     * @param rowRenderData
     * @param resultCh
     */
    private static void handlerSampleItems(String orderType, Map<String, List<SampleProductExportDto>> item, AtomicInteger finalIndex, List<SampleProductExportDto> sampleList, Integer max, List<TextRenderData> text, List<RowRenderData> rows, RowRenderData rowRenderData, AtomicReference<String> resultCh, List<String> cableTagList, Boolean hasAddHead) {
        item.forEach((s, sampleProductDtoInside) -> {
            // 添加检验项
            SampleProductExportDto dto2 = new SampleProductExportDto();
@@ -1712,19 +1974,23 @@
                // 处理集合
                Map<String, SampleProductExportDto> map = new LinkedHashMap<>();
                for (SampleProductExportDto productDto2 : sampleProductDtoInside) {
                    String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem();
                    String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem() + productDto2.getCableTag();
                    if (map.containsKey(productName)) {
                        // 如果名称已经存在,添加 lastValue 值到 lastValueList 列表
                        map.get(productName)
                                .getLastValueList()
                                .add(productDto2.getLastValue());
                        if (CollectionUtil.isEmpty(map.get(productName).getLastValueList()) || StringUtils.equals(OrderType.RAW.getValue(), orderType)) {
                            map.get(productName)
                                    .getLastValueList()
                                    .add(productDto2.getLastValue());
                        }
                        map.get(productName)
                                .getInsResultList()
                                .add(productDto2.getInsResult());
                    } else {
                        // 如果名称不存在,直接放入 map
                        productDto2.setLastValueList(new ArrayList<>()); // 检验内容
                        productDto2.getLastValueList().add(productDto2.getLastValue());
                        if (CollectionUtil.isEmpty(productDto2.getLastValueList()) || StringUtils.equals(OrderType.RAW.getValue(), orderType)) {
                            productDto2.setLastValueList(new ArrayList<>()); // 检验内容
                            productDto2.getLastValueList().add(productDto2.getLastValue());
                        }
                        productDto2.setInsResultList(new ArrayList<>()); // 结果
                        productDto2.getInsResultList().add(productDto2.getInsResult());
@@ -1753,19 +2019,23 @@
                // 处理集合
                Map<String, SampleProductExportDto> map = new LinkedHashMap<>();
                for (SampleProductExportDto productDto2 : sampleProductDtoInside) {
                    String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem() + productDto2.getInspectionItemSubclass();
                    String productName = productDto2.getInspectionItemClass() + productDto2.getInspectionItem() + productDto2.getInspectionItemSubclass() + productDto2.getCableTag();
                    if (map.containsKey(productName)) {
                        // 如果名称已经存在,添加 lastValue 值到 lastValueList 列表
                        map.get(productName)
                                .getLastValueList()
                                .add(productDto2.getLastValue());
                        if (CollectionUtil.isEmpty(map.get(productName).getLastValueList()) || StringUtils.equals(OrderType.RAW.getValue(), orderType)) {
                            map.get(productName)
                                    .getLastValueList()
                                    .add(productDto2.getLastValue());
                        }
                        map.get(productName)
                                .getInsResultList()
                                .add(productDto2.getInsResult());
                    } else {
                        // 如果名称不存在,直接放入 map
                        productDto2.setLastValueList(new ArrayList<>()); // 检验内容
                        productDto2.getLastValueList().add(productDto2.getLastValue());
                        if (CollectionUtil.isEmpty(productDto2.getLastValueList()) || StringUtils.equals(OrderType.RAW.getValue(), orderType)) {
                            productDto2.setLastValueList(new ArrayList<>()); // 检验内容
                            productDto2.getLastValueList().add(productDto2.getLastValue());
                        }
                        productDto2.setInsResultList(new ArrayList<>()); // 结果
                        productDto2.getInsResultList().add(productDto2.getInsResult());
@@ -1783,8 +2053,9 @@
        });
        // 添加小报告表头
        text = addSmallHead(text, max, rows);
        if (hasAddHead) {
            text = addSmallHead(text, max, rows, cableTagList);
        }
        // 中间检测值添加
        for (int i = 0; i < sampleList.size(); i++) {
@@ -1801,7 +2072,9 @@
            // 检验项目
            TextRenderData middleRenderData2 = new TextRenderData();
            middleRenderData2.setText(sample.getInspectionName());
            String[] split = sample.getInspectionName().split("&");
            String itemName = split.length > 0 ? split[0] : sample.getInspectionName();
            middleRenderData2.setText(itemName + "∑" + itemName + i + "_" + finalIndex);
            Style middleStyle2 = new Style();
            middleStyle2.setFontFamily("宋体");
            middleStyle2.setColor("000000");
@@ -1888,7 +2161,7 @@
                    TextRenderData middleRenderData6 = new TextRenderData();
                    middleRenderData6.setText((StringUtils.isNotEmpty(sample.getLastValue()) ?
                            sample.getLastValue() : "")
                            + "∑" + (7 + i));
                            + "∑" + (finalIndex.get() + "_" + i));
                    Style middleStyle6 = new Style();
                    middleStyle6.setFontFamily("宋体");
                    middleStyle6.setColor("000000");
@@ -1926,7 +2199,7 @@
                            String type;
                            if (count.equals(0)) {
                                // 添加不合格描述
                                String item1 = (max == 1 ? "" : "第" + Integer.toString(index) + "次")
                                String item1 = (max == 1 ? "" : "第" + index + "次")
                                        + sample.getInspectionItem()
                                        + (StringUtils.isBlank(sample.getInspectionItemSubclass()) ? "" : "" + sample.getInspectionItemSubclass());
                                if (resultCh.get().equals("")) {
@@ -1966,95 +2239,18 @@
            text = new ArrayList<>();
        }
        TableRenderData tableRenderData = new TableRenderData();
        tableRenderData.setRows(rows);
        //设置样式
        TableStyle tableStyle = new TableStyle();
        for (int i = 1; i <= max; i++) {
            // 根据减压那结果个数修改长度
            switch (i) {
                case 1:
                    tableStyle.setColWidths(new int[]{650, 2900, 850, 2300, 2100, 1200});
                    break;
                case 2:
                    tableStyle.setColWidths(new int[]{650, 2700, 850, 2200, 1200, 1200, 1200});
                    break;
                case 3:
                    tableStyle.setColWidths(new int[]{650, 2700, 850, 1600, 1000, 1000, 1000, 1200});
                    break;
                case 4:
                    tableStyle.setColWidths(new int[]{650, 2400, 850, 1500, 850, 850, 850, 850, 1200});
                    break;
                case 5:
                    tableStyle.setColWidths(new int[]{650, 2200, 850, 1350, 750, 750, 750, 750, 750, 1200});
                    break;
            }
        }
        tableStyle.setWidth("10000");
        tableStyle.setAlign(TableRowAlign.CENTER);
        BorderStyle borderStyle = new BorderStyle();
        borderStyle.setColor("000000");
        borderStyle.setType(XWPFTable.XWPFBorderType.SINGLE);
        borderStyle.setSize(4);
        tableStyle.setLeftBorder(borderStyle);
        tableStyle.setRightBorder(borderStyle);
        tableStyle.setInsideHBorder(borderStyle); // 设置水平内边框
        tableStyle.setInsideVBorder(borderStyle);
        tableRenderData.setTableStyle(tableStyle);
        if (!resultCh.get().equals("")) {
            resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。");
        } else {
            resultCh.set("经检验此批" + enterFactoryReport.getSample() + "各项目均符合检验规范要求。");
        }
        ConfigureBuilder builder = Configure.builder();
        builder.useSpringEL(true);
        InputStream inputStream = this.getClass().getResourceAsStream("/static/small-report-template.docx");
        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
                new HashMap<String, Object>() {{
                    put("report", enterFactoryReport);
                    put("standardMethod", standardMethod2.toString().equals("null") ? "" : standardMethod2);
                    put("orderType", orderType);
                    put("table", tableRenderData);
                    put("resultCh", resultCh);
                    put("writeUrl", null);
                    put("examineUrl", null);
                    put("ratifyUrl", null);
                    put("writeDateUrl", null);
                    put("examineDateUrl", null);
                    put("ratifyDateUrl", null);
                    put("seal1", null);
                }});
        try {
            // 修改换行和合并问题
            updaeMerge(template.getXWPFDocument(), true);
            String name = insReport.getCode().replace("/", "") + "-J.docx";
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name)));
            insReport.setUrl("/word/" + name);
            insReport.setIsPass(0);
            insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人
            insReport.setWriteTime(LocalDateTime.now());//提交时间
            // 查询报告, 判断之前是否添加过, 添加过删除
            insReportMapper.delete(Wrappers.<InsReport>lambdaQuery()
                    .eq(InsReport::getInsOrderId, insOrder.getId()));
            insReportMapper.insert(insReport);
            inputStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 添加小宝表头
     * 添加小报告表头
     *
     * @param text
     * @param max
     * @param rows
     * @return
     */
    private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows) {
    private static List<TextRenderData> addSmallHead(List<TextRenderData> text, Integer max, List<RowRenderData> rows, List<String> cableTagList) {
        RowRenderData rowRenderData;
//        // 头
        TextRenderData headRenderData1 = new TextRenderData();
@@ -2112,7 +2308,7 @@
        text = new ArrayList<>();
        // 第二行(可能没有)
        if (max > 1) {
        if (max > 1 && CollectionUtil.isEmpty(cableTagList)) {
            TextRenderData tagRenderData1 = new TextRenderData();
            tagRenderData1.setText("");
            Style tagStyle1 = new Style();
@@ -2166,8 +2362,62 @@
            rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create();
            rows.add(rowRenderData);
            text = new ArrayList<>();
        }
        //如果有电缆颜色,生成颜色标识行
        if (CollectionUtil.isNotEmpty(cableTagList)) {
            TextRenderData tagRenderData1 = new TextRenderData();
            tagRenderData1.setText("");
            Style tagStyle1 = new Style();
            tagStyle1.setFontFamily("宋体");
            tagStyle1.setColor("000000");
            tagRenderData1.setStyle(tagStyle1);
            text.add(tagRenderData1);
            TextRenderData tagRenderData2 = new TextRenderData();
            tagRenderData2.setText("绝缘线芯颜色和标志");
            Style tagStyle2 = new Style();
            tagStyle2.setFontFamily("宋体");
            tagStyle2.setColor("000000");
            tagRenderData2.setStyle(tagStyle2);
            text.add(tagRenderData2);
            TextRenderData tagRenderData4 = new TextRenderData();
            tagRenderData4.setText("/");
            Style tagStyle4 = new Style();
            tagStyle4.setFontFamily("宋体");
            tagStyle4.setColor("000000");
            tagRenderData4.setStyle(tagStyle4);
            text.add(tagRenderData4);
            TextRenderData tagRenderData5 = new TextRenderData();
            tagRenderData5.setText("/");
            Style tagStyle5 = new Style();
            tagStyle5.setFontFamily("宋体");
            tagStyle5.setColor("000000");
            tagRenderData5.setStyle(tagStyle5);
            text.add(tagRenderData5);
            for (String cableTag : cableTagList) {
                TextRenderData tagRenderData6 = new TextRenderData();
                tagRenderData6.setText(cableTag);
                Style tagStyle6 = new Style();
                tagStyle6.setFontFamily("宋体");
                tagStyle6.setColor("000000");
                tagRenderData6.setStyle(tagStyle6);
                text.add(tagRenderData6);
            }
            TextRenderData tagRenderData7 = new TextRenderData();
            tagRenderData7.setText("/");
            Style tagStyle7 = new Style();
            tagStyle7.setFontFamily("宋体");
            tagStyle7.setColor("000000");
            tagRenderData7.setStyle(tagStyle7);
            text.add(tagRenderData7);
            TextRenderData[] text4 = text.toArray(new TextRenderData[0]);
            rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create();
            rows.add(rowRenderData);
            text = new ArrayList<>();
        }
        return text;
@@ -2177,6 +2427,7 @@
    /**
     * 创建大报告
     *
     * @param orderId
     * @param insOrder
     * @param
@@ -2602,6 +2853,7 @@
    /**
     * 调整高度
     *
     * @param row
     * @param rowHeight
     * @return
@@ -2833,12 +3085,13 @@
    /**
     * 添加报告表头
     *
     * @param sample
     * @param text
     * @param rowRenderData
     * @param rows
     * @param max
     * @param cableTags 线芯颜色
     * @param cableTags     线芯颜色
     */
    private static void addHead(SampleProductDto sample, List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, List<String> cableTags) {
        // 第一行
@@ -3056,16 +3309,17 @@
    /**
     * 添加检测值
     * @param a   当前样品
     *
     * @param a             当前样品
     * @param text
     * @param rowRenderData
     * @param rows
     * @param max  检验数量
     * @param max           检验数量
     * @param resultChList  不符合信息中文
     * @param resultEhList  不符合信息英文
     * @param insSamples
     * @param cableTags 线芯颜色
     * @param isOneSample 判断是否是只有一个样品
     * @param cableTags     线芯颜色
     * @param isOneSample   判断是否是只有一个样品
     */
    private int addTestValue(SampleProductDto a,
                             List<TextRenderData> text,
@@ -3744,6 +3998,7 @@
    /**
     * 添加报告结论中英文
     *
     * @param sample
     * @param itemCh
     * @param itemEn
@@ -3803,6 +4058,7 @@
    /**
     * 格式化修改检验项
     *
     * @param sampleProductDto2s
     */
    private void formatProducts(List<SampleProductExportDto> sampleProductDto2s) {
@@ -3872,6 +4128,7 @@
    /**
     * 添加结尾
     *
     * @param text
     * @param rowRenderData
     * @param rows
@@ -3903,6 +4160,7 @@
    /**
     * 判断当前内容是否是科学计数法
     *
     * @param str
     * @return
     */
@@ -3919,6 +4177,7 @@
    /**
     * 修改要求描述的科学计数法
     *
     * @param input
     */
    public static String convertToScientificNotation(String input) {
@@ -3948,6 +4207,7 @@
    /**
     * 展示成科学计数法
     *
     * @param number
     * @return
     */
@@ -4044,6 +4304,7 @@
    /**
     * 根据要求描述保留结果小数点位数
     *
     * @param reference
     * @param value
     * @return
@@ -4112,6 +4373,7 @@
    /**
     * 保留位数, 如果等于0 返回找到的一个非0位数
     *
     * @param number 当前数字
     * @param scale  原本保留的位数
     * @return
@@ -4150,9 +4412,10 @@
    /**
     * *****保存元此阿里进货验证原始记录*****
     * @param insOrderId 订单Id
     * @param examineUserId  复核人Id
     * @param writeUserId  检验员Id
     *
     * @param insOrderId    订单Id
     * @param examineUserId 复核人Id
     * @param writeUserId   检验员Id
     */
    private void reportFactoryVerify(Integer insOrderId, Integer examineUserId, Integer writeUserId) {
        // 查询进货验证原始记录
@@ -4305,6 +4568,7 @@
    /**
     * ***格式化进厂验证内容****
     *
     * @param basicType
     * @return
     */
@@ -4334,6 +4598,7 @@
    /**
     * ***word转换pdf***
     *
     * @param path
     * @return
     */
@@ -4382,6 +4647,7 @@
    /**
     * *****修改成品抽样状态******
     *
     * @param insSamples
     * @param order
     */
@@ -4419,6 +4685,7 @@
    /**
     * 添加工时
     *
     * @param userId
     * @param insProduct
     * @param insOrder