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;
@@ -36,6 +37,7 @@
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.*;
@@ -45,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;
@@ -74,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;
@@ -90,6 +87,9 @@
 */
@Service
public class InsOrderPlanServiceImpl extends ServiceImpl<InsOrderMapper, InsOrder> implements InsOrderPlanService {
    private static final int DETECTION_REPORT = 0;
    private static final int INSPECTION_REPORT = 1;
    @Resource
    private InsSampleMapper insSampleMapper;
@@ -131,6 +131,8 @@
    @Resource
    private IfsInventoryQuantityMapper ifsInventoryQuantityMapper;
    @Resource
    private IfsPartPropsRecordMapper ifsPartPropsRecordMapper;
    @Resource
    private InsReportService insReportService;
    @Resource
    private InsUnqualifiedRetestProductMapper insUnqualifiedRetestProductMapper;
@@ -167,9 +169,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())) {
@@ -277,9 +277,14 @@
    }
    @Override
    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory) {
    public Map<String,Object> checkSubmitPlan(Integer orderId, String laboratory, Integer reportType) {
        Map<String, Object> map = new HashMap<>();
        List<String> collect = new ArrayList<>();
        if (Objects.equals(DETECTION_REPORT, reportType)) {
            map.put("errorMsg", collect);
            map.put("unInsOrderCount", 0L);
            return map;
        }
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId).select(InsSample::getId));
        List<Integer> ids = insSamples.stream().map(a -> a.getId()).collect(Collectors.toList());
        List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
@@ -769,8 +774,21 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode,Boolean registerInsResults) {
        InsOrder order = insOrderMapper.selectById(orderId);
    public int submitPlan(Integer orderId, String laboratory, Integer verifyUser, String entrustCode, Boolean registerInsResults, Integer reportType) {
        if (!Objects.equals(DETECTION_REPORT, reportType) && !Objects.equals(INSPECTION_REPORT, reportType)) {
            throw new ErrorException("请选择报告类型");
        }
        InsOrder order = insOrderMapper.selectOne(Wrappers.<InsOrder>lambdaQuery()
                .eq(InsOrder::getId, orderId)
                .last("FOR UPDATE"));
        InsReport existingReport = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
                .eq(InsReport::getInsOrderId, orderId));
        if (existingReport != null && existingReport.getReportType() != null
                && !Objects.equals(existingReport.getReportType(), reportType)) {
            throw new ErrorException("同一检验订单只能使用一种报告类型");
        }
        boolean isInspectionReport = Objects.equals(INSPECTION_REPORT, reportType);
        registerInsResults = isInspectionReport && Boolean.TRUE.equals(registerInsResults);
        // 1. 判断是否有重复编号, 有重复编号做提醒
        Long codeCount = insOrderMapper.selectCount(Wrappers.<InsOrder>lambdaQuery()
                .ne(InsOrder::getState, -1)
@@ -796,13 +814,18 @@
                .in(InsProduct::getInsSampleId, InsSampleIds)
                .eq(InsProduct::getSonLaboratory, laboratory)
                .eq(InsProduct::getState, 1)
                .and(wrapper -> wrapper
                        .isNull(InsProduct::getInsResult)
                        .or()
                        .eq(InsProduct::getInsResult, 2)
                )
                .and(wrapper -> {
                    if (Objects.equals(reportType, DETECTION_REPORT)) {
                        wrapper.isNull(InsProduct::getLastValue).or().eq(InsProduct::getLastValue, "");
                    } else {
                        wrapper.isNull(InsProduct::getInsResult).or().eq(InsProduct::getInsResult, 2);
                    }
                })
                .ne(InsProduct::getIsBinding, 1));
        insProducts.addAll(insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory));
        if (Objects.equals(reportType, INSPECTION_REPORT)) {
            List<InsProduct> insProducts1 = insProductMapper.selectFiberInsProduct(InsSampleIds, laboratory);
            insProducts.addAll(insProducts1);
        }
        if (insProducts.size() > 0) {
            String str = "";
            int count = 0;
@@ -866,7 +889,7 @@
        });
        // 8.提交生成报告
        this.generateReport(orderId);
        this.generateReport(orderId, reportType);
        // 9.添加临时pdf生成地址
        InsReport report = insReportMapper.selectOne(Wrappers.<InsReport>lambdaQuery()
@@ -880,7 +903,7 @@
        // 11.成品抽样添加合格状态
        // 判断是否有抽样信息
        if (order.getQuarterItemId() != null) {
        if (isInspectionReport && order.getQuarterItemId() != null) {
            // 判断是否有不合格
            this.addProductSpotCheck(insSamples, order);
        }
@@ -935,7 +958,7 @@
        });
        // 14.ifs移库(原材料需要进行移库操作) --> 最后执行,因为失败无法回滚
        if (ifsInventoryQuantity != null) {
        if (ifsInventoryQuantity != null && isInspectionReport) {
            // 登记检验结果
            // 判断是否有不合格, 有不合格不能移库
            // todo: ifs移库
@@ -949,7 +972,7 @@
            });
        } else {
        } else if (isInspectionReport) {
            // 修改成品状态
            // 判断是否有不合格
            Long unqualifiedCount = insReportService.getUnqualifiedCount(order);
@@ -976,7 +999,7 @@
    private void addAnalysis(List<InsProduct> productList, IfsInventoryQuantity ifsInventoryQuantity, InsOrder order, String sendUserAccount) {
        for (InsProduct insProduct : productList) {
            // 判断是否是数值类型
            if (insProduct.getInspectionValueType().equals("1") && insProduct.getInsResult().equals(1)) {
            if ("1".equals(insProduct.getInspectionValueType()) && Objects.equals(insProduct.getInsResult(), 1)) {
                List<InsProductDeviationWarningDetail> insProductAnalysisDtoList = insProductMapper.selectAnalysis(insProduct, ifsInventoryQuantity.getSupplierName());
                if (CollectionUtils.isEmpty(insProductAnalysisDtoList)) {
@@ -1266,22 +1289,24 @@
     * 生成报告
     * @param orderId
     */
    private void generateReport(Integer orderId) {
    private void generateReport(Integer orderId, Integer reportType) {
        /*样品下的项目只要有一个项目不合格则检验结果为0,否则为1*/
        //这里的insSamples是订单下的所有样品包括("/")
        List<InsSample> insSamples = insSampleMapper.selectList(Wrappers.<InsSample>lambdaQuery().eq(InsSample::getInsOrderId, orderId));
        if (Objects.equals(reportType, INSPECTION_REPORT)) {
        for (InsSample insSample : insSamples) {
            List<InsProduct> insProducts = insProductMapper.selectList(Wrappers.<InsProduct>lambdaQuery()
                    .eq(InsProduct::getInsSampleId, insSample.getId())
                    .eq(InsProduct::getState, 1)
                    .ne(InsProduct::getIsBinding, 1));
            List<Integer> results = insProducts.stream().map(InsProduct::getInsResult).filter(str -> str != null).collect(Collectors.toList());
            List<Integer> results = insProducts.stream().map(InsProduct::getInsResult).filter(Objects::nonNull).collect(Collectors.toList());
            if (results.contains(0)) {
                insSample.setInsResult(0);
            } else {
                insSample.setInsResult(1);
            }
            insSampleMapper.updateById(insSample);
        }
        }
        InsOrder insOrder = insOrderMapper.selectById(orderId);
        // 抽检变成委托检验
@@ -1292,10 +1317,10 @@
        // 判断是大报告还是小报告  进厂小报告, 其他都是大报告
        if (insOrder.getOrderType().equals(InsOrderTypeConstants.ENTER_THE_FACTORY)) {
            // 生成小报告
            addSmallReport(orderId, insOrder, insSamples);
            addSmallReport(orderId, insOrder, insSamples, reportType);
        } else {
            //生成大报告
            addBitReport(orderId, insOrder);
            addBitReport(orderId, insOrder, reportType);
        }
    }
@@ -1637,16 +1662,117 @@
    /*****************************************************  小报告    ***************************************************************************/
    /**
     * 设置表格样式
     * @param max 标识最大个数
     * @return
     */
    private TableStyle setTableStyle(int max, boolean showResult){
        //设置样式
        TableStyle tableStyle = new TableStyle();
        if (!showResult) {
            switch (max) {
                case 1: tableStyle.setColWidths(new int[]{650, 3000, 850, 2400, 3100}); break;
                case 2: tableStyle.setColWidths(new int[]{650, 2800, 850, 2200, 1750, 1750}); break;
                case 3: tableStyle.setColWidths(new int[]{650, 2600, 850, 1800, 1400, 1400, 1400}); break;
                case 4: tableStyle.setColWidths(new int[]{650, 2400, 850, 1600, 1125, 1125, 1125, 1125}); break;
                case 5: tableStyle.setColWidths(new int[]{650, 2200, 850, 1500, 960, 960, 960, 960, 960}); break;
                default: break;
            }
        } else 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));
            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
     */
    private void addSmallReport(Integer orderId, InsOrder insOrder, List<InsSample> insSamples) {
    private void addSmallReport(Integer orderId, InsOrder insOrder, List<InsSample> insSamples, Integer reportType) {
        InsReport insReport = new InsReport();
        AtomicReference<String> resultCh = new AtomicReference<>("");
        boolean showResult = Objects.equals(reportType, INSPECTION_REPORT);
        insReport.setCode(insOrder.getEntrustCode());
        insReport.setInsOrderId(orderId);
        insReport.setReportType(reportType);
        InsSample insSample = insSamples.get(0);
        // 填充基础数据
        EnterFactoryReport enterFactoryReport = new EnterFactoryReport();
@@ -1654,11 +1780,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());
        // 检测依据
@@ -1676,6 +1808,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()
@@ -1686,21 +1819,170 @@
        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 -> !showResult || f.getInsResult() != 3)
                    .collect(Collectors.toList());
            int maxCableTag = 5;//单个表格,电缆颜色标识最大个数
            templateName = showResult ? "/static/small-wg-report-template.docx" : "/static/small-wg-detection-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, showResult);
            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, showResult);
                tableRenderData2.setRows(newRows);
            tableRenderData2.setTableStyle(setTableStyle(newCableTags.size(), showResult));
                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, showResult));
            if (showResult && !resultCh.get().isEmpty()) {
                resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。(盖章有效)");
            } else if (showResult) {
                resultCh.set("本产品符合相关标准要求,经检验合格准予出厂(盖章有效)");
            }
        }else{
            templateName = showResult ? "/static/small-report-template.docx" : "/static/small-detection-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, showResult);
            tableRenderData.setRows(rows);
            tableRenderData.setTableStyle(setTableStyle(max, showResult));
            if (showResult && !resultCh.get().equals("")) {
                resultCh.set("经检验," + resultCh.get() + "所检项目不合格,其余所检项目均合格。");
            } else if (showResult) {
                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("/", "") + (showResult ? "-J.docx" : "-C.docx");
            Files.createDirectories(Paths.get(wordUrl));
            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, boolean showResult) {
        item.forEach((s, sampleProductDtoInside) -> {
            // 添加检验项
            SampleProductExportDto dto2 = new SampleProductExportDto();
@@ -1713,19 +1995,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());
@@ -1754,19 +2040,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());
@@ -1784,8 +2074,9 @@
        });
        // 添加小报告表头
        text = addSmallHead(text, max, rows);
        if(hasAddHead){
            text = addSmallHead(text, max, rows, cableTagList, showResult);
        }
        // 中间检测值添加
        for (int i = 0; i < sampleList.size(); i++) {
@@ -1802,7 +2093,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");
@@ -1832,21 +2125,21 @@
            if (CollectionUtils.isNotEmpty(sample.getLastValueList())
                    && sample.getLastValueList().size() == max) {
                // 判断是否是外观, 外观全部合格的话需要合并
                if (sample.getInspectionItem().contains("外观")) {
                if (showResult && sample.getInspectionItem().contains("外观")) {
                    // 判定结果
                    boolean falg = false;
                    if (CollectionUtils.isNotEmpty(sample.getLastValueList())) {
                        // 判断是否有一个错误
                        if (sample.getInsResultList().stream().anyMatch(s -> s.equals(2))) {
                        if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 2))) {
                            falg = true;
                        } else {
                            boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0));
                            boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0));
                            if (!error) {
                                falg = true;
                            }
                        }
                    } else {
                        if (!sample.getInsResult().equals(2)) {
                        if (!Objects.equals(sample.getInsResult(), 2)) {
                            falg = true;
                        }
                    }
@@ -1889,7 +2182,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");
@@ -1901,7 +2194,7 @@
            // 判定结果
            String result = "";
            if (sample.getInsResult() != null) {
            if (showResult && sample.getInsResult() != null) {
                switch (sample.getInsResult()) {
                    case 1:
                        result = "√";
@@ -1914,20 +2207,20 @@
                        break;
                }
            }
            if (CollectionUtils.isNotEmpty(sample.getLastValueList())) {
            if (showResult && CollectionUtils.isNotEmpty(sample.getLastValueList())) {
                // 判断是否有一个错误
                if (sample.getInsResultList().stream().anyMatch(s -> s.equals(3))) {
                if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 3))) {
                    result = "-";
                } else {
                    boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0));
                    boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0));
                    if (error) {
                        List<String> collect = new ArrayList<>();
                        int index = 1;
                        for (Integer count : sample.getInsResultList()) {
                            String type;
                            if (count.equals(0)) {
                            if (Objects.equals(count, 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("")) {
@@ -1949,6 +2242,7 @@
                }
            }
            if (showResult) {
            TextRenderData middleRenderData7 = new TextRenderData();
            middleRenderData7.setText(result);
            Style middleStyle7 = new Style();
@@ -1956,6 +2250,7 @@
            middleStyle7.setColor("000000");
            middleRenderData7.setStyle(middleStyle7);
            text.add(middleRenderData7);
            }
            TextRenderData[] text2 = text.toArray(new TextRenderData[0]);
            rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create();
@@ -1967,95 +2262,16 @@
            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, boolean showResult) {
        RowRenderData rowRenderData;
//        // 头
        TextRenderData headRenderData1 = new TextRenderData();
@@ -2092,13 +2308,14 @@
        for (int i = 0; i < max; i++) {
            TextRenderData headRenderData6 = new TextRenderData();
            headRenderData6.setText("检验结果∑6");
            headRenderData6.setText(showResult ? "检验结果∑6" : "检测数据∑6");
            Style headStyle6 = new Style();
            headStyle6.setFontFamily("宋体");
            headStyle6.setColor("000000");
            headRenderData6.setStyle(headStyle6);
            text.add(headRenderData6);
        }
        if (showResult) {
        TextRenderData headRenderData7 = new TextRenderData();
        headRenderData7.setText("单项判断");
        Style headStyle7 = new Style();
@@ -2106,6 +2323,7 @@
        headStyle7.setColor("000000");
        headRenderData7.setStyle(headStyle7);
        text.add(headRenderData7);
        }
        TextRenderData[] text3 = text.toArray(new TextRenderData[0]);
        rowRenderData = Rows.of(text3).center().rowAtleastHeight(1).create();
@@ -2113,7 +2331,7 @@
        text = new ArrayList<>();
        // 第二行(可能没有)
        if (max > 1) {
        if (max > 1 && CollectionUtil.isEmpty(cableTagList)) {
            TextRenderData tagRenderData1 = new TextRenderData();
            tagRenderData1.setText("");
            Style tagStyle1 = new Style();
@@ -2155,6 +2373,7 @@
                tagRenderData6.setStyle(tagStyle6);
                text.add(tagRenderData6);
            }
            if (showResult) {
            TextRenderData tagRenderData7 = new TextRenderData();
            tagRenderData7.setText("");
            Style tagStyle7 = new Style();
@@ -2162,6 +2381,7 @@
            tagStyle7.setColor("000000");
            tagRenderData7.setStyle(tagStyle7);
            text.add(tagRenderData7);
            }
            TextRenderData[] text4 = text.toArray(new TextRenderData[0]);
            rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create();
@@ -2170,7 +2390,64 @@
        }
        //如果有电缆颜色,生成颜色标识行
        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);
            }
            if (showResult) {
            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;
    }
@@ -2182,12 +2459,14 @@
     * @param insOrder
     * @param
     */
    private void addBitReport(Integer orderId, InsOrder insOrder) {
    private void addBitReport(Integer orderId, InsOrder insOrder, Integer reportType) {
        //samples是不包括带有"/"的样品
        List<SampleProductDto> samples = insSampleMapper.selectSampleProductListByOrderId(orderId);
        InsReport insReport = new InsReport();
        insReport.setCode(insOrder.getEntrustCode());
        insReport.setInsOrderId(orderId);
        insReport.setReportType(reportType);
        boolean showResult = Objects.equals(reportType, INSPECTION_REPORT);
        List<Map<String, Object>> tables = new ArrayList<>();
        Set<String> standardMethod = new HashSet<>();
        Set<String> deviceSet = new HashSet<>();
@@ -2198,7 +2477,7 @@
        List<String> resultChList = new ArrayList<>();
        List<String> resultEnList = new ArrayList<>();
        // 判断是否是只有一个样品
        boolean isOneSample = samples.size() == 1 ? true : false;
        boolean isOneSample = samples.size() == 1;
        /*基础报告(根据绘制的原始记录模版形成)*/
        samples.forEach(a -> {
            models.add(a.getModel());
@@ -2277,15 +2556,15 @@
            }
            // 表头添加
            addHead(a, text, rowRenderData, rows, max, cableTags);
            addHead(a, text, rowRenderData, rows, max, cableTags, showResult);
            text = new ArrayList<>();
            // 添加检测值
            productSize.set(addTestValue(a, text, rowRenderData, rows, max, resultChList, resultEnList, insSamples, cableTags, isOneSample));
            productSize.set(addTestValue(a, text, rowRenderData, rows, max, resultChList, resultEnList, insSamples, cableTags, isOneSample, showResult));
            text = new ArrayList<>();
            // 结尾添加
            addEnding(text, rowRenderData, rows, max);
            addEnding(text, rowRenderData, rows, max, showResult);
            text = new ArrayList<>();
            List<TableRenderData> tables1 = new ArrayList<>();
@@ -2316,26 +2595,27 @@
                    newTableRenderData.setRows(new ArrayList<>(firstTwoRows));
                    //设置样式
                    TableStyle tableStyle = new TableStyle();
                    for (int i = 1; i <= max; i++) {
                        // 根据减压那结果个数修改长度
                        switch (i) {
                            case 1:
                                tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
                                break;
                            case 2:
                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
                                break;
                            case 3:
                                tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
                                break;
                            case 4:
                                tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
                                break;
                            case 5:
                                tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
                                break;
                        }
                    }
//                    for (int i = 1; i <= max; i++) {
//                    }
                    // 根据检验结果个数修改长度
                    tableStyle.setColWidths(calcTableColWidths(max, showResult));
//                    switch (max) {
//                        case 1:
//                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
//                            break;
//                        case 2:
//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
//                            break;
//                        case 3:
//                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
//                            break;
//                        case 4:
//                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
//                            break;
//                        case 5:
//                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200});
//                            break;
//                    }
                    tableStyle.setWidth("10000");
                    tableStyle.setAlign(TableRowAlign.CENTER);
                    BorderStyle borderStyle = new BorderStyle();
@@ -2358,42 +2638,43 @@
                }
                tableRenderData.getRows().add(row);
            }
            if (!tableRenderData.getRows().isEmpty() && tableRenderData.getRows().size() != 3) {
            TableStyle tableStyle = new TableStyle();
            if (tableRenderData.getRows().size() != 3) {
                //设置样式
                TableStyle tableStyle = new TableStyle();
                for (int i = 1; i <= max; i++) {
                    // 根据减压那结果个数修改长度
                    switch (i) {
                        case 1:
                            tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
                            break;
                        case 2:
                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
                            break;
                        case 3:
                            tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
                            break;
                        case 4:
                            tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
                            break;
                        case 5:
                            tableStyle.setColWidths(new int[]{650, 1100, 1100, 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.THICK);
                borderStyle.setSize(14);
                tableStyle.setLeftBorder(borderStyle);
                tableStyle.setTopBorder(borderStyle);
                tableStyle.setRightBorder(borderStyle);
                tableStyle.setBottomBorder(borderStyle);
                tableRenderData.setTableStyle(tableStyle);
                tables1.add(tableRenderData);
//                for (int i = 1; i <= max; i++) {
//                }
                // 根据检验结果个数修改长度
                tableStyle.setColWidths(calcTableColWidths(max, showResult));
//                switch (max) {
//                    case 1:
//                        tableStyle.setColWidths(new int[]{650, 2000, 2000, 850, 2200, 2100, 1200});
//                        break;
//                    case 2:
//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200});
//                        break;
//                    case 3:
//                        tableStyle.setColWidths(new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200});
//                        break;
//                    case 4:
//                        tableStyle.setColWidths(new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200});
//                        break;
//                    case 5:
//                        tableStyle.setColWidths(new int[]{650, 1100, 1100, 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.THICK);
            borderStyle.setSize(14);
            tableStyle.setLeftBorder(borderStyle);
            tableStyle.setTopBorder(borderStyle);
            tableStyle.setRightBorder(borderStyle);
            tableStyle.setBottomBorder(borderStyle);
            tableRenderData.setTableStyle(tableStyle);
            tables1.add(tableRenderData);
            tables1.forEach(table -> {
                Map<String, Object> tableMap = new HashMap<>();
                tableMap.put("table", table);
@@ -2451,7 +2732,7 @@
        Custom custom = customMapper.selectById(insOrder.getCompanyId());
        // 查询判断是否有不判定项目,和全都是判定项
        int judgeType = insProductMapper.selectNoJudge(insOrder.getId());
        int judgeType = showResult ? insProductMapper.selectNoJudge(insOrder.getId()) : 0;
        String resultCh = "";
        String resultEn = "";
        for (String reference : resultChList) {
@@ -2543,7 +2824,7 @@
        List<Map<String, String>> finalDeviceList = deviceList;
        String finalModelStr = modelStr;
        InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx");
        InputStream inputStream = this.getClass().getResourceAsStream(showResult ? "/static/report-template.docx" : "/static/detection-report-template.docx");
        Configure configure = Configure.builder()
                .bind("deviceList", new HackLoopTableRenderPolicy())
                .useSpringEL(true)
@@ -2586,8 +2867,9 @@
        try {
            // 修改换行和合并问题
            updaeMerge(template.getXWPFDocument(), false);
            String name = insReport.getCode().replace("/", "") + ".docx";
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name)));
            String name = insReport.getCode().replace("/", "") + (showResult ? ".docx" : "-C.docx");
            Files.createDirectories(Paths.get(wordUrl));
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl, name)));
            insReport.setUrl("/word/" + name);
            insReport.setWriteUserId(SecurityUtils.getUserId().intValue());//提交人
            insReport.setWriteTime(LocalDateTime.now());//提交时间
@@ -2599,6 +2881,55 @@
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
    /**
     * 计算表格列宽度
     * @param max 最大检验个数
     * @return
     */
    private static int[] calcTableColWidths(int max, boolean showResult){
        if (!showResult) {
            switch (max) {
                case 1: return new int[]{650, 2200, 2200, 850, 2300, 1800};
                case 2: return new int[]{650, 1600, 1600, 850, 1900, 1700, 1700};
                case 3: return new int[]{650, 1400, 1400, 850, 1600, 1375, 1375, 1375};
                case 4: return new int[]{650, 1250, 1250, 850, 1450, 1140, 1140, 1140, 1140};
                case 5: return new int[]{650, 1150, 1150, 850, 1300, 980, 980, 980, 980, 980};
                default: return new int[0];
            }
        }
        int[] colWidths = null;
        switch (max) {
            case 1:
                colWidths = new int[]{650, 2000, 2000, 850, 2200, 2100, 1200};
                break;
            case 2:
                colWidths = new int[]{650, 1400, 1400, 850, 2100, 1200, 1200, 1200};
                break;
            case 3:
                colWidths = new int[]{650, 1400, 1400, 850, 1500, 1000, 1000, 1000, 1200};
                break;
            case 4:
                colWidths = new int[]{650, 1200, 1200, 850, 1400, 850, 850, 850, 850, 1200};
                break;
            case 5:
                colWidths = new int[]{650, 1100, 1100, 850, 1350, 750, 750, 750, 750, 750, 1200};
                break;
        }
        if(ObjectUtils.isNull(colWidths)){
            List<Integer> defaultColWidths = new ArrayList<>(Arrays.asList(650, 1100, 1100, 850, 1350));
            int totalWidth = 3000;//总宽度
            int byOneWidth = totalWidth/max;//每一个的宽度
            int realWidth = 0;//实际宽度
            for (int i = 0; i < max; i++) {
                realWidth+=byOneWidth;
                defaultColWidths.add(byOneWidth);
            }
            defaultColWidths.add(1200+(totalWidth-realWidth));
            return defaultColWidths.stream().mapToInt(Integer::intValue).toArray();
        }
        return colWidths;
    }
    /**
@@ -2616,9 +2947,9 @@
        // 获取检测内容判断是否超出
        if (StringUtils.isNotBlank(dataText) && dataText.contains("@")) {
            double number = 1;
            double chinaLength = 0;
            double englishLength = 0;
            double valueLength = 0;
            double chinaLength = 14;
            double englishLength = 28;
            double valueLength = 6;
            // 根据线芯个数判断距离
            switch (max) {
                case 1:
@@ -2841,7 +3172,7 @@
     * @param max
     * @param cableTags 线芯颜色
     */
    private static void addHead(SampleProductDto sample, List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, List<String> cableTags) {
    private static void addHead(SampleProductDto sample, List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, List<String> cableTags, boolean showResult) {
        // 第一行
        TextRenderData firstRenderData1 = new TextRenderData();
        firstRenderData1.setText("样品编号@Sample No.∑1");
@@ -2918,6 +3249,11 @@
            }
        }
        // 检测报告不展示“结论”列,首行也要同步减少一个单元格,
        // 否则首行为 max + 6 列、其余行为 max + 5 列,poi-tl 无法渲染表格。
        if (!showResult && !text.isEmpty()) {
            text.remove(text.size() - 1);
        }
        TextRenderData[] text2 = text.toArray(new TextRenderData[0]);
        rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create();
        rows.add(rowRenderData);
@@ -2966,13 +3302,14 @@
        for (int i = 0; i < max; i++) {
            TextRenderData headRenderData6 = new TextRenderData();
            headRenderData6.setText("检验结果@Test result∑6");
            headRenderData6.setText(showResult ? "检验结果@Test result∑6" : "检测数据@Test data∑6");
            Style headStyle6 = new Style();
            headStyle6.setFontFamily("宋体");
            headStyle6.setColor("000000");
            headRenderData6.setStyle(headStyle6);
            text.add(headRenderData6);
        }
        if (showResult) {
        TextRenderData headRenderData7 = new TextRenderData();
        headRenderData7.setText("结论@Conclusion");
        Style headStyle7 = new Style();
@@ -2980,6 +3317,7 @@
        headStyle7.setColor("000000");
        headRenderData7.setStyle(headStyle7);
        text.add(headRenderData7);
        }
        TextRenderData[] text3 = text.toArray(new TextRenderData[0]);
        rowRenderData = Rows.of(text3).center().rowAtleastHeight(1).create();
@@ -3037,6 +3375,7 @@
                cableRenderData6.setStyle(cableStyle6);
                text.add(cableRenderData6);
            }
            if (showResult) {
            TextRenderData cableRenderData7 = new TextRenderData();
            cableRenderData7.setText("-");
            Style cableStyle7 = new Style();
@@ -3044,6 +3383,7 @@
            cableStyle7.setColor("000000");
            cableRenderData7.setStyle(cableStyle7);
            text.add(cableRenderData7);
            }
            TextRenderData[] text4 = text.toArray(new TextRenderData[0]);
            rowRenderData = Rows.of(text4).center().rowAtleastHeight(1).create();
@@ -3076,7 +3416,7 @@
                             List<String> resultChList,
                             List<String> resultEhList,
                             InsSample insSamples, List<String> cableTags,
                             boolean isOneSample) {
                             boolean isOneSample, boolean showResult) {
        // 检验项总数
        AtomicInteger productSize = new AtomicInteger(1);
        // 不合格信息
@@ -3484,7 +3824,6 @@
        // 检验项分类      检验项  检验子项
        Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapCn = new LinkedHashMap<>();
        Map<String, LinkedHashMap<String, List<String>>> errorClassItemMapEn = new LinkedHashMap<>();
        // 中间检测值添加
        for (int i = 0; i < sampleList.size(); i++) {
            SampleProductExportDto sample = sampleList.get(i);
@@ -3565,7 +3904,9 @@
            // 判断是否有电缆标识map
            if (CollectionUtils.isNotEmpty(sample.getCableTagValueMap())) {
                sample.setLastValueList(new ArrayList<>(sample.getCableTagValueMap().values()));
                TreeMap<String, String> cableTagValues = new TreeMap<>(Comparator.comparingInt(cableTags::indexOf));
                cableTagValues.putAll(sample.getCableTagValueMap());
                sample.setLastValueList(new ArrayList<>(cableTagValues.values()));
            }
            if (CollectionUtils.isNotEmpty(sample.getCableTagResultMap())) {
                sample.setInsResultList(new ArrayList<>(sample.getCableTagResultMap().values()));
@@ -3599,6 +3940,7 @@
                }
            }
            // 判定结果
            if (showResult) {
            String result = "";
            if (sample.getInsResult() != null) {
                switch (sample.getInsResult()) {
@@ -3615,16 +3957,16 @@
            }
            if (CollectionUtils.isNotEmpty(sample.getLastValueList())) {
                // 判断是否有一个错误
                if (sample.getInsResultList().stream().anyMatch(s -> s.equals(3))) {
                if (sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 3))) {
                    result = "-";
                } else {
                    boolean error = sample.getInsResultList().stream().anyMatch(s -> s.equals(0));
                    boolean error = sample.getInsResultList().stream().anyMatch(s -> Objects.equals(s, 0));
                    if (error) {
                        List<String> collect = new ArrayList<>();
                        int index = 0;
                        for (Integer count : sample.getInsResultList()) {
                            String type;
                            if (count.equals(0)) {
                            if (Objects.equals(count, 0)) {
                                String itemCh = "";
                                String itemEn = "";
                                // 添加不合格描述
@@ -3658,6 +4000,7 @@
                }
            }
            if (showResult) {
            TextRenderData headRenderData7 = new TextRenderData();
            headRenderData7.setText(result);
            Style headStyle7 = new Style();
@@ -3665,6 +4008,8 @@
            headStyle7.setColor("000000");
            headRenderData7.setStyle(headStyle7);
            text.add(headRenderData7);
            }
            }
            TextRenderData[] text2 = text.toArray(new TextRenderData[0]);
            rowRenderData = Rows.of(text2).center().rowAtleastHeight(1).create();
@@ -3825,7 +4170,7 @@
                sampleProductDto2.setLastValue(sampleProductDto2.getLastValue().trim());
            }
            if (sampleProductDto2.getInsResult().equals(0)) {
            if (Objects.equals(sampleProductDto2.getInsResult(), 0)) {
                // 查询不合格复测
                Long count = insUnqualifiedRetestProductMapper.selectCount(Wrappers.<InsUnqualifiedRetestProduct>lambdaQuery()
                        .eq(InsUnqualifiedRetestProduct::getInsProductId, sampleProductDto2.getInsProductId())
@@ -3889,7 +4234,7 @@
     * @param rowRenderData
     * @param rows
     */
    private static void addEnding(List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max) {
    private static void addEnding(List<TextRenderData> text, RowRenderData rowRenderData, List<RowRenderData> rows, int max, boolean showResult) {
        for (int i = 0; i < 2; i++) {
            TextRenderData endingRenderData = new TextRenderData();
            endingRenderData.setText("备注∑1999");
@@ -3900,9 +4245,9 @@
            text.add(endingRenderData);
        }
        for (int i = 0; i < 5 + max - 1; i++) {
        for (int i = 0; i < (showResult ? 5 : 4) + max - 1; i++) {
            TextRenderData endingRenderData = new TextRenderData();
            endingRenderData.setText("“√”表示项目合格,“×”表示项目不合格,“-”表示不要判定,“/”表示没有标准要求。@“√” indicates test ltem is qualified,“×” indicates test ltem is unqualified,“-” indicates test ltem judgment is not required,“/” indicates test ltem is no test requirement.∑2000");
            endingRenderData.setText(showResult ? "“√”表示项目合格,“×”表示项目不合格,“-”表示不要判定,“/”表示没有标准要求。@“√” indicates test ltem is qualified,“×” indicates test ltem is unqualified,“-” indicates test ltem judgment is not required,“/” indicates test ltem is no test requirement.∑2000" : "");
            Style endingStyle = new Style();
            endingStyle.setFontFamily("宋体");
            endingStyle.setColor("000000");