chenrui
2025-02-27 146edfb05602373ad5b36771e1ede1e395d8ab62
inspect-server/src/main/java/com/ruoyi/inspect/service/impl/InsOrderPlanServiceImpl.java
@@ -30,20 +30,18 @@
import com.ruoyi.basic.pojo.IfsInventoryQuantity;
import com.ruoyi.basic.pojo.StandardTemplate;
import com.ruoyi.basic.service.StandardTemplateService;
import com.ruoyi.common.constant.DictDataConstants;
import com.ruoyi.common.constant.InsOrderTypeConstants;
import com.ruoyi.common.core.domain.entity.Custom;
import com.ruoyi.common.core.domain.entity.InformationNotification;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.domain.entity.User;
import com.ruoyi.common.utils.DateImageUtil;
import com.ruoyi.common.utils.QueryWrappers;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.WxCpUtils;
import com.ruoyi.common.utils.*;
import com.ruoyi.framework.exception.ErrorException;
import com.ruoyi.inspect.dto.*;
import com.ruoyi.inspect.mapper.*;
import com.ruoyi.inspect.pojo.*;
import com.ruoyi.inspect.service.*;
import com.ruoyi.inspect.util.HackLoopTableRenderPolicy;
import com.ruoyi.inspect.vo.InsOrderPlanTaskSwitchVo;
import com.ruoyi.inspect.vo.InsOrderPlanVO;
import com.ruoyi.performance.mapper.AuxiliaryOutputWorkingHoursMapper;
@@ -57,6 +55,7 @@
import com.ruoyi.system.service.InformationNotificationService;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
@@ -592,8 +591,27 @@
        return insSampleUserMapper.insert(insSampleUser);
    }
    /**
     * 查询模板内容
     * @param order
     * @param insProducts
     */
    private void getTemplateThing(InsOrder order, List<InsProduct> insProducts) {
        Set<Integer> set = new HashSet<>();
        // 检验项分类+检验项+检验子项的拼接
        List<String> itemNameList = insProducts.stream().map(insProduct -> {
            String itemName = "";
            if (StringUtils.isNotBlank(insProduct.getInspectionItemClass())) {
                itemName += insProduct.getInspectionItemClass().trim();
            }
            if (StringUtils.isNotBlank(insProduct.getInspectionItem())) {
                itemName += insProduct.getInspectionItem().trim();
            }
            if (StringUtils.isNotBlank(insProduct.getInspectionItemSubclass())) {
                itemName += insProduct.getInspectionItemSubclass().trim();
            }
            return itemName;
        }).collect(Collectors.toList());
        // 查询订单状态判断是否是查历史模板
        if (order.getIsFirstSubmit() != null && order.getIsFirstSubmit().equals(1)) {
            InsOrderState insOrderState = insOrderStateMapper.selectOne(Wrappers.<InsOrderState>lambdaQuery()
@@ -613,7 +631,11 @@
                                .eq(InsOrderStandardTemplate::getInsOrderId, order.getId()));
                        thing = one.getThing();
                        if (StrUtil.isNotEmpty(thing)) {
                            thing = GZipUtil.uncompress(thing);
                            JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0)));
                            // 清除没有关联的检验项
                            eliminateItem(sheet, itemNameList);
                            JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config")));
                            List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class);
                            Map<String, Object> style = new HashMap<>();
@@ -634,13 +656,12 @@
            }
            String thing = null;
            if (product.getTemplateId() != null && set.add(product.getTemplateId())) {
                long begin = System.currentTimeMillis();
                thing = standardTemplateService.getStandTempThingById(product.getTemplateId());
                long end = System.currentTimeMillis();
                System.out.println("=========时间====" + (end - begin));
            }
            if (StrUtil.isNotEmpty(thing)) {
                JSONObject sheet = JSON.parseObject(JSON.toJSONString(JSON.parseArray(JSON.toJSONString(JSON.parseObject(thing).get("data"))).get(0)));
                // 清除没有关联的检验项
                eliminateItem(sheet, itemNameList);
                JSONObject config = JSON.parseObject(JSON.toJSONString(sheet.get("config")));
                List<JSONObject> cellData = JSON.parseArray(JSON.toJSONString(sheet.get("celldata")), JSONObject.class);
                Map<String, Object> style = new HashMap<>();
@@ -648,12 +669,93 @@
                style.put("columnlen", config.get("columnlen"));
                product.setTemplate(cellData);
                product.setStyle(style);
                long begin = System.currentTimeMillis();
                product.setTemplateName(standardTemplateService.getStandTempNameById(product.getTemplateId()));
                long end = System.currentTimeMillis();
                System.out.println("=========时间22222====" + (end - begin));
            }
        }
    }
    /**
     * 清除没有使用的检验项
     * @param sheet
     * @param itemNameList
     */
    private static void eliminateItem(JSONObject sheet, List<String> itemNameList) {
        // 获取到 检验项分类+检验项+检验子项的拼接,如果模板里的信息跟接口返回的检验项信息能够匹配则展示出来
        // 循环行数判断是否
        JSONArray dataListJSONArray = sheet.getJSONArray("data");
        // 添加坐标map
        Map<String, String> coordinatesMap = new HashMap<>();
        // 需要移除的索引
        List<Integer> deleteIndex = new ArrayList<>();
        // 循环列
        for (int r = 0; r < dataListJSONArray.size(); r++) {
            JSONArray dataList = dataListJSONArray.getJSONArray(r);
            // 循环行
            String itemName = "";
            // 判断是否显示
            boolean isShow = false;
            for (int c = 0; c < dataList.size(); c++) {
                // 查询批注
                JSONObject jsonObject = dataList.getJSONObject(c);
                try {
                    if (jsonObject.getJSONObject("ps").getString("value").equals("检验项分类")) {
                        String value = jsonObject.getString("v").trim();
                        itemName += value;
                        // 添加坐标
                        String coordinates = coordinatesJoint(r, c);
                        coordinatesMap.put(coordinates, value);
                        isShow = true;
                    } else if (jsonObject.getJSONObject("ps").getString("value").equals("检验项")) {
                        String value = jsonObject.getString("v").trim();
                        itemName += value;
                        // 添加坐标
                        String coordinates = coordinatesJoint(r, c);
                        coordinatesMap.put(coordinates, value);
                        isShow = true;
                    } else if (jsonObject.getJSONObject("ps").getString("value").equals("检验子项")) {
                        String value = jsonObject.getString("v").trim();
                        itemName += value;
                        // 添加坐标
                        String coordinates = coordinatesJoint(r, c);
                        coordinatesMap.put(coordinates, value);
                        isShow = true;
                    }
                } catch (Exception e) {
                    // 判断是否有mc合并单元格
                    if (jsonObject != null && jsonObject.getJSONObject("mc") != null) {
                        // 查询坐标进行添加
                        String value = coordinatesMap.get(coordinatesJoint(jsonObject.getJSONObject("mc").getInteger("r"), jsonObject.getJSONObject("mc").getInteger("c")));
                        if (StringUtils.isNotBlank(value) && !itemName.contains(value)) {
                            itemName += value;
                        }
                    }
                }
            }
            // 判断该订单是否有改检验项, 没有剔除
            if (isShow) {
                if (!itemNameList.contains(itemName)) {
                    dataListJSONArray.remove(r);
                    r--;
                }
            }
        }
    }
    /**
     * 坐标拼接
     * @param r 横坐标
     * @param c 纵坐标
     * @return
     */
    private static String coordinatesJoint(int r, int c) {
        String coordinates = "";
        coordinates = "r:" + r + ",c:" + c;
        return coordinates;
    }
    @Override
@@ -752,9 +854,6 @@
            }
            return null;
        });
        // todo: 删除数采采集次数
//        String key = "frequency" + ":" + entrustCode + ":*";
//        RedisUtil.delsLike(key);
        // 提交生成报告
        this.generateReport(orderId);
@@ -798,8 +897,7 @@
            }
        }
        // todo: 成品抽样添加合格状态
        // 成品抽样添加合格状态
        // 判断是否有抽样信息
        if (order.getQuarterItemId() != null) {
            // 判断是否有不合格
@@ -1527,9 +1625,9 @@
            standardMethod2.append("、").append(s);
        }
        standardMethod2.replace(0, 1, "");
        // todo: 检测类型
//        List<SysDictData> sysDictData = iSysDictTypeService.selectDictDataByName("");
        String orderType = null;
        // 样品类型
        String orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE, insOrder.getOrderType());
        List<RowRenderData> rows = new ArrayList<>();
        List<TextRenderData> text = new ArrayList<>();
@@ -1892,6 +1990,8 @@
                    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);
@@ -1906,8 +2006,6 @@
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 修改换行和合并问题
        updaeMerge(insReport, null, true);
    }
    /**
@@ -2275,10 +2373,19 @@
        tables.forEach(table -> {
            table.put("tableSize", tables.size() + 1);
        });
        // 设备信息
        List<Map<String, String>> deviceList = null;
        if (deviceSet.size() != 0) {
        if (CollectionUtils.isNotEmpty(deviceSet)) {
            deviceList = insOrderMapper.selectDeviceList(deviceSet);
        }
        if (CollectionUtils.isNotEmpty(deviceList)) {
            int count = 1;
            for (Map<String, String> stringMap : deviceList) {
                stringMap.put("index", String.valueOf(count));
                count++;
            }
        }
        Map<String, String> codeStr = new HashMap<>();
        codeStr.put("报告编号", insReport.getCode());
        codeStr.put("样品名称", insOrder.getSample());
@@ -2286,19 +2393,23 @@
        codeStr.put("发放日期", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
        String modelStr = CollUtil.join(models, "\n");
        String finalModelStr = modelStr;
        // todo: 查询字典
        // 检测类型
        String orderType = null;
        String formType = null;
        orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE, insOrder.getOrderType());
        // 判断第一个字典是否为空
        if (StringUtils.isBlank(orderType)) {
            orderType = iSysDictTypeService.selectLabelByDict(DictDataConstants.CHECK_TYPE1, insOrder.getOrderType());
        }
        // 来样方式
        String formType = iSysDictTypeService.selectLabelByDict(DictDataConstants.FORM_TYPE, insOrder.getFormType());
        // 样品状态
        String sampleStatus = null;
        String sampleStatus = iSysDictTypeService.selectLabelByDict(DictDataConstants.SAMPLE_STATUS_LIST, insOrder.getSampleStatus());
        ;
        ConfigureBuilder builder = Configure.builder();
        builder.useSpringEL(true);
        List<Map<String, String>> finalDeviceList = deviceList;
        Integer userId = insSampleUserMapper.selectOne(Wrappers.<InsSampleUser>lambdaQuery().eq(InsSampleUser::getInsSampleId, orderId).last("limit 1")).getUserId();
        // 公司信息
        Custom custom = customMapper.selectById(insOrder.getCompanyId());
        // 查询判断是否有不判定项目,和全都是判定项
@@ -2388,11 +2499,18 @@
        environment = (ObjectUtils.isNotEmpty(insOrder.getTemperature()) ? insOrder.getTemperature() + "℃ " : "") + (ObjectUtils.isNotEmpty(insOrder.getHumidity()) ? insOrder.getHumidity() + "%" : "");
        String finalEnvironment = environment;
        LocalDateTime finalSendTime = sendTime;
        String finalResultCh = resultCh;
        String finalResultEn = resultEn;
        String finalOrderType = orderType;
        List<Map<String, String>> finalDeviceList = deviceList;
        String finalModelStr = modelStr;
        InputStream inputStream = this.getClass().getResourceAsStream("/static/report-template.docx");
        XWPFTemplate template = XWPFTemplate.compile(inputStream, builder.build()).render(
        Configure configure = Configure.builder()
                .bind("deviceList", new HackLoopTableRenderPolicy())
                .build();
        XWPFTemplate template = XWPFTemplate.compile(inputStream, configure).render(
                new HashMap<String, Object>() {{
                    put("order", insOrder);
                    put("report", insReport);
@@ -2415,7 +2533,7 @@
                    put("images", images);
                    put("examineUrl", null);
                    put("ratifyUrl", null);
                    put("orderType", orderType);
                    put("orderType", finalOrderType);
                    put("getTime", finalSendTime.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日")));
                    put("getTimeEn", monthNames[finalSendTime.getMonthValue() - 1] + " " + finalSendTime.format(DateTimeFormatter.ofPattern("dd, yyyy")));
                    put("seal1", null);
@@ -2427,6 +2545,8 @@
                    put("sampleStatus", sampleStatus);
                }});
        try {
            // 修改换行和合并问题
            updaeMerge(template.getXWPFDocument(), false);
            String name = insReport.getCode().replace("/", "") + ".docx";
            template.writeAndClose(Files.newOutputStream(Paths.get(wordUrl + "/" + name)));
            insReport.setUrl("/word/" + name);
@@ -2439,8 +2559,6 @@
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        // 修改换行和合并问题
        updaeMerge(insReport, deviceList, false);
    }
    /**
@@ -2511,188 +2629,165 @@
    /**
     * 合并单元格
     * @param insReport
     * @param deviceList
     */
    private void updaeMerge(InsReport insReport, List<Map<String, String>> deviceList, boolean isSmall) {
    private void updaeMerge(XWPFDocument document, boolean isSmall) {
        // 处理合并单元格的问题
        String path = wordUrl + insReport.getUrl().replaceFirst("/word", "");
        try {
            // 获取文档中的所有表格
            FileInputStream stream = new FileInputStream(path);
            XWPFDocument document = new XWPFDocument(stream);
            List<XWPFTable> xwpfTables = document.getTables();
            // 遍历表格,但跳过第一个表格(如果deviceList为null,则额外跳过第二个)
            for (int i = 1; i < xwpfTables.size() - (deviceList == null ? 1 : 2); i++) {
                // 创建一个HashSet来存储唯一的字符串(这里基于"∑"分割后的第二部分)
                Set<String> set1 = new HashSet<>();
                // 创建一个HashMap来存储每个唯一字符串及其对应的单元格位置信息
                Map<String, Map<String, Integer>> maps = new HashMap<>();
                // 遍历当前表格的所有行
                for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) {
                    // 遍历当前行的所有单元格
                    for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) {
                        // 检查单元格文本中是否包含"∑"
                        if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("∑") > -1) {
                            String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑");
                            // 如果分割后的第二部分是新的(即之前未出现过),则添加到set1并创建位置信息map
                            if (set1.add(split[1])) {
                                Map<String, Integer> map = new HashMap<>();
                                // 存储起始行、起始列、结束行(当前行)、结束列(当前列)
                                map.put("sr", j);
                                map.put("sc", k);
                                map.put("er", j + 0);
                                map.put("ec", k + 0);
                                maps.put(split[1], map);
                            } else {
                                // 如果已存在,则更新结束行或结束列
                                Map<String, Integer> map1 = maps.get(split[1]);
                                if (j == map1.get("sr")) {
                                    map1.put("ec", map1.get("ec") + 1);
                                } else if (k == map1.get("sc")) {
                                    map1.put("er", map1.get("er") + 1);
                                }
        // 获取文档中的所有表格
        List<XWPFTable> xwpfTables = document.getTables();
        // 遍历表格
        for (int i = 1; i < xwpfTables.size(); i++) {
            // 创建一个HashSet来存储唯一的字符串(这里基于"∑"分割后的第二部分)
            Set<String> set1 = new HashSet<>();
            // 创建一个HashMap来存储每个唯一字符串及其对应的单元格位置信息
            Map<String, Map<String, Integer>> maps = new HashMap<>();
            // 遍历当前表格的所有行
            for (int j = 0; j < xwpfTables.get(i).getRows().size(); j++) {
                // 遍历当前行的所有单元格
                for (int k = 0; k < xwpfTables.get(i).getRows().get(j).getTableCells().size(); k++) {
                    // 检查单元格文本中是否包含"∑"
                    if (xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().indexOf("∑") > -1) {
                        String[] split = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑");
                        // 如果分割后的第二部分是新的(即之前未出现过),则添加到set1并创建位置信息map
                        if (set1.add(split[1])) {
                            Map<String, Integer> map = new HashMap<>();
                            // 存储起始行、起始列、结束行(当前行)、结束列(当前列)
                            map.put("sr", j);
                            map.put("sc", k);
                            map.put("er", j + 0);
                            map.put("ec", k + 0);
                            maps.put(split[1], map);
                        } else {
                            // 如果已存在,则更新结束行或结束列
                            Map<String, Integer> map1 = maps.get(split[1]);
                            if (j == map1.get("sr")) {
                                map1.put("ec", map1.get("ec") + 1);
                            } else if (k == map1.get("sc")) {
                                map1.put("er", map1.get("er") + 1);
                            }
                            // 判断小高报告还是大报告
                            if (isSmall) {
                                // 获取单元格
                                XWPFTableCell cell = xwpfTables.get(i).getRows().get(j).getTableCells().get(k);
                                XWPFParagraph paragraph = cell.getParagraphArray(0);
                                String originalText = paragraph.getText();
                                String newText = originalText.split("∑")[0];
                                List<XWPFRun> runs = paragraph.getRuns();
                                for (XWPFRun run : runs) {
                                    run.setText("", 0); // 清空 run 中的文本
                                }
                                if (!runs.isEmpty()) {
                                    XWPFRun run = runs.get(0);
                                    run.setText(newText);
                                    // 复制样式
                                    run.setFontFamily(paragraph.getRuns().get(0).getFontFamily());
                                    run.setFontSize(paragraph.getRuns().get(0).getFontSize());
                                    run.setBold(paragraph.getRuns().get(0).isBold());
                                    run.setItalic(paragraph.getRuns().get(0).isItalic());
                                    run.setUnderline(paragraph.getRuns().get(0).getUnderline());
                                    run.setColor(paragraph.getRuns().get(0).getColor());
                                }
                                cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                                paragraph.setAlignment(ParagraphAlignment.CENTER);
                            } else {
                                // 移除包含"∑"的段落,并重新设置单元格文本和样式
                                String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑")[0];
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                                xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
                        }
                        // 判断小高报告还是大报告
                        if (isSmall) {
                            // 获取单元格
                            XWPFTableCell cell = xwpfTables.get(i).getRows().get(j).getTableCells().get(k);
                            XWPFParagraph paragraph = cell.getParagraphArray(0);
                            String originalText = paragraph.getText();
                            String newText = originalText.split("∑")[0];
                            List<XWPFRun> runs = paragraph.getRuns();
                            for (XWPFRun run : runs) {
                                run.setText("", 0); // 清空 run 中的文本
                            }
                            if (!runs.isEmpty()) {
                                XWPFRun run = runs.get(0);
                                run.setText(newText);
                                // 复制样式
                                run.setFontFamily(paragraph.getRuns().get(0).getFontFamily());
                                run.setFontSize(paragraph.getRuns().get(0).getFontSize());
                                run.setBold(paragraph.getRuns().get(0).isBold());
                                run.setItalic(paragraph.getRuns().get(0).isItalic());
                                run.setUnderline(paragraph.getRuns().get(0).getUnderline());
                                run.setColor(paragraph.getRuns().get(0).getColor());
                            }
                            cell.setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                            paragraph.setAlignment(ParagraphAlignment.CENTER);
                        } else {
                            // 移除包含"∑"的段落,并重新设置单元格文本和样式
                            String str = xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getText().split("∑")[0];
                            xwpfTables.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                            xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setText(str);
                            xwpfTables.get(i).getRows().get(j).getTableCells().get(k).setVerticalAlignment(XWPFTableCell.XWPFVertAlign.CENTER);
                            xwpfTables.get(i).getRows().get(j).getTableCells().get(k).getParagraphArray(0).setAlignment(ParagraphAlignment.CENTER);
                        }
                    }
                }
            }
                // 单元格排序, 避免格式错乱
                List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet());
                entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc"));
            // 单元格排序, 避免格式错乱
            List<Map.Entry<String, Map<String, Integer>>> entries = new ArrayList<>(maps.entrySet());
            entries.sort((o1, o2) -> o1.getValue().get("sc") - o2.getValue().get("sc"));
                // 按照顺序添加进集合
                List<String> list = new ArrayList<>();
                for (Map.Entry<String, Map<String, Integer>> entry : entries) {
                    list.add(entry.getKey());
                }
            // 按照顺序添加进集合
            List<String> list = new ArrayList<>();
            for (Map.Entry<String, Map<String, Integer>> entry : entries) {
                list.add(entry.getKey());
            }
                for (int a = list.size() - 1; a >= 0; a--) {
                    Map<String, Integer> v = maps.get(list.get(a));
                    for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
                        if (v.get("ec") > v.get("sc")) {
                            try {
                                TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec"));
                            } catch (Exception e) {
                            }
                        }
                    }
                    if (v.get("er") > v.get("sr")) {
            for (int a = list.size() - 1; a >= 0; a--) {
                Map<String, Integer> v = maps.get(list.get(a));
                for (int j = 0; j < v.get("er") - v.get("sr") + 1; j++) {
                    if (v.get("ec") > v.get("sc")) {
                        try {
                            TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er"));
                            TableTools.mergeCellsHorizonal(xwpfTables.get(i), v.get("sr") + j, v.get("sc"), v.get("ec"));
                        } catch (Exception e) {
                        }
                    }
                }
                if (v.get("er") > v.get("sr")) {
                    try {
                        TableTools.mergeCellsVertically(xwpfTables.get(i), v.get("sc"), v.get("sr"), v.get("er"));
                    } catch (Exception e) {
                    }
                }
            }
            FileOutputStream fileOutputStream = new FileOutputStream(path);
            document.write(fileOutputStream);
            fileOutputStream.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        //处理中英文换行的问题
        try {
            FileInputStream stream1 = new FileInputStream(path);
            XWPFDocument document1 = new XWPFDocument(stream1);
            List<XWPFTable> xwpfTables1 = document1.getTables();
            for (int i = 1; i < xwpfTables1.size() - (deviceList == null ? 1 : 2); i++) {
                for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) {
                    for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) {
                        if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) {
                            if (isSmall) {
                                // 获取原有段落的第一个 XWPFRun
                                String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
                                XWPFParagraph oldParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getParagraphs().get(0);
                                XWPFRun oldRun = oldParagraph.getRuns().get(0);
                                // 保存原有样式
                                String fontFamily = oldRun.getFontFamily();
                                int fontSize = oldRun.getFontSize();
                                boolean isBold = oldRun.isBold();
                                boolean isItalic = oldRun.isItalic();
                                boolean isUnderline = oldRun.getUnderline() != UnderlinePatterns.NONE;
                                // 删除原有段落
                                xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                                // 添加新段落
                                XWPFParagraph newParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
                                XWPFRun newRun = newParagraph.createRun();
                                // 应用保存的样式
                                newRun.setFontFamily(fontFamily);
                                newRun.setFontSize(fontSize);
                                newRun.setBold(isBold);
                                newRun.setItalic(isItalic);
                                if (isUnderline) {
                                    newRun.setUnderline(UnderlinePatterns.SINGLE);
                                }
                                // 设置新文本
                                String[] split = text.split("@");
                                newRun.setText(split[0]);
                                if (split.length > 1) {
                                    newRun.addBreak();
                                    newRun.setText(split[1]);
                                }
                                // 设置段落对齐方式
                                newParagraph.setAlignment(ParagraphAlignment.CENTER);
                            } else {
                                String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
                                String[] split = text.split("@");
                                xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                                XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
                                XWPFRun run = xwpfParagraph.createRun();
                                run.setText(split[0]);
                                if (ObjectUtils.isNotNull(split[1])) {
                                    run.addBreak();
                                    run.setText(split[1]);
                                }
                                xwpfParagraph.setAlignment(ParagraphAlignment.CENTER);
        List<XWPFTable> xwpfTables1 = document.getTables();
        for (int i = 1; i < xwpfTables1.size(); i++) {
            for (int j = 0; j < xwpfTables1.get(i).getRows().size(); j++) {
                for (int k = 0; k < xwpfTables1.get(i).getRows().get(j).getTableCells().size(); k++) {
                    if (xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText().contains("@")) {
                        if (isSmall) {
                            // 获取原有段落的第一个 XWPFRun
                            String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
                            XWPFParagraph oldParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getParagraphs().get(0);
                            XWPFRun oldRun = oldParagraph.getRuns().get(0);
                            // 保存原有样式
                            String fontFamily = oldRun.getFontFamily();
                            int fontSize = oldRun.getFontSize();
                            boolean isBold = oldRun.isBold();
                            boolean isItalic = oldRun.isItalic();
                            boolean isUnderline = oldRun.getUnderline() != UnderlinePatterns.NONE;
                            // 删除原有段落
                            xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                            // 添加新段落
                            XWPFParagraph newParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
                            XWPFRun newRun = newParagraph.createRun();
                            // 应用保存的样式
                            newRun.setFontFamily(fontFamily);
                            newRun.setFontSize(fontSize);
                            newRun.setBold(isBold);
                            newRun.setItalic(isItalic);
                            if (isUnderline) {
                                newRun.setUnderline(UnderlinePatterns.SINGLE);
                            }
                            // 设置新文本
                            String[] split = text.split("@");
                            newRun.setText(split[0]);
                            if (split.length > 1) {
                                newRun.addBreak();
                                newRun.setText(split[1]);
                            }
                            // 设置段落对齐方式
                            newParagraph.setAlignment(ParagraphAlignment.CENTER);
                        } else {
                            String text = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).getText();
                            String[] split = text.split("@");
                            xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).removeParagraph(0);
                            XWPFParagraph xwpfParagraph = xwpfTables1.get(i).getRows().get(j).getTableCells().get(k).addParagraph();
                            XWPFRun run = xwpfParagraph.createRun();
                            run.setText(split[0]);
                            if (ObjectUtils.isNotNull(split[1])) {
                                run.addBreak();
                                run.setText(split[1]);
                            }
                            xwpfParagraph.setAlignment(ParagraphAlignment.CENTER);
                        }
                    }
                }
            }
            FileOutputStream fileOutputStream1 = new FileOutputStream(path);
            document1.write(fileOutputStream1);
            fileOutputStream1.close();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }