JsonToExcelConverter.java 27.6 KB
package com.glsk.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Iterator;
import java.util.Map;

@Slf4j
public class JsonToExcelConverter {

    public static void convertJsonToExcel(String jsonString, String fileName, String author) throws IOException {

            Workbook workbook = new XSSFWorkbook();
//            int lastDotIndex = fileName.lastIndexOf('.');
//            fileName = fileName.substring(0, lastDotIndex);

            Sheet sheet = workbook.createSheet(fileName);

            sheet.setColumnWidth(0, 256 * 12);
            sheet.setColumnWidth(1, 256 * 20);
            sheet.setColumnWidth(2, 256 * 20);
            sheet.setColumnWidth(3, 256 * 50);
            sheet.setColumnWidth(4, 256 * 50);
            sheet.setColumnWidth(5, 256 * 20);
            sheet.setColumnWidth(6, 256 * 12);
            sheet.setColumnWidth(7, 256 * 12);
            sheet.setColumnWidth(8, 256 * 12);
            sheet.setColumnWidth(9, 256 * 12);
            sheet.setColumnWidth(10, 256 * 12);
            sheet.setColumnWidth(11, 256 * 12);

            setAutoRowHeight(sheet);

            CellStyle headerStyle = workbook.createCellStyle();
//            headerStyle.setFillForegroundColor(HSSFColor.HSSFColorPredefined.GREEN.getIndex());
            headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
            headerStyle.setAlignment(HorizontalAlignment.LEFT);
            headerStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            Font font = workbook.createFont();
            font.setBold(true);
//            font.setColor(HSSFColor.HSSFColorPredefined.DARK_GREEN.getIndex());
            font.setFontHeightInPoints((short) 11);
            headerStyle.setFont(font);

            Row headerRow = sheet.createRow(0);
            Cell cell1 = headerRow.createCell(0);
            cell1.setCellStyle(headerStyle);
            cell1.setCellValue("需求ID");
            Cell cell2 = headerRow.createCell(1);
            cell2.setCellStyle(headerStyle);
            cell2.setCellValue("用例目录");
            Cell cell3 = headerRow.createCell(2);
            cell3.setCellStyle(headerStyle);
            cell3.setCellValue("用例名称");
            Cell cell4 = headerRow.createCell(3);
            cell4.setCellStyle(headerStyle);
            cell4.setCellValue("前置条件");
            Cell cell5 = headerRow.createCell(4);
            cell5.setCellStyle(headerStyle);
            cell5.setCellValue("用例步骤");
            Cell cell6 = headerRow.createCell(5);
            cell6.setCellStyle(headerStyle);
            cell6.setCellValue("预期结果");
            Cell cell7 = headerRow.createCell(6);
            cell7.setCellStyle(headerStyle);
            cell7.setCellValue("用例类型");
            Cell cell8 = headerRow.createCell(7);
            cell8.setCellStyle(headerStyle);
            cell8.setCellValue("用例状态");
            Cell cell9 = headerRow.createCell(8);
            cell9.setCellStyle(headerStyle);
            cell9.setCellValue("用例等级");
            Cell cell10 = headerRow.createCell(9);
            cell10.setCellStyle(headerStyle);
            cell10.setCellValue("创建人");
            Cell cell11 = headerRow.createCell(10);
            cell11.setCellStyle(headerStyle);
            cell11.setCellValue("用例权重");
            Cell cell12 = headerRow.createCell(11);
            cell12.setCellStyle(headerStyle);
            cell12.setCellValue("用例方向");


            CellStyle bodyStyle = workbook.createCellStyle();
            bodyStyle.setAlignment(HorizontalAlignment.LEFT);
            bodyStyle.setVerticalAlignment(VerticalAlignment.CENTER);
            bodyStyle.setWrapText(true);

            Font font2 = workbook.createFont();
            font2.setFontHeightInPoints((short) 10);
            bodyStyle.setFont(font2);



            ObjectMapper objectMapper = new ObjectMapper();
            JsonNode rootNode = objectMapper.readTree(jsonString);
//            String innerJsonString = rootNode.get("text").asText();
//            JsonNode innerNode = objectMapper.readTree(innerJsonString);
            JsonNode testCases = rootNode.get("testCases");
            System.out.println("测试用例数量: " + testCases.size());

            for (int i = 0; i < testCases.size(); i++) {
                JsonNode testCase = testCases.get(i);

                Row bodyRow = sheet.createRow(i + 1);
                Cell bodyCell0 = bodyRow.createCell(0);
                bodyCell0.setCellStyle(bodyStyle);
                bodyCell0.setCellValue(testCase.get("reqmtId").asText());
                Cell bodyCell1 = bodyRow.createCell(1);
                bodyCell1.setCellStyle(bodyStyle);
                bodyCell1.setCellValue(testCase.get("category").asText());
                Cell bodyCell2 = bodyRow.createCell(2);
                bodyCell2.setCellStyle(bodyStyle);
                bodyCell2.setCellValue(testCase.get("name").asText());
                Cell bodyCell3 = bodyRow.createCell(3);
                bodyCell3.setCellStyle(bodyStyle);
                bodyCell3.setCellValue(testCase.get("preconditions").asText());

                JsonNode steps = testCase.get("steps");
                String stepsStr = "";
                for (int j = 0; j < steps.size(); j++) {
                    stepsStr += steps.get(j).asText() + "\n";
                }
                Cell bodyCell4 = bodyRow.createCell(4);
                bodyCell4.setCellStyle(bodyStyle);
                bodyCell4.setCellValue(stepsStr);

                Cell bodyCell5 = bodyRow.createCell(5);
                bodyCell5.setCellStyle(bodyStyle);
                bodyCell5.setCellValue(testCase.get("expected").asText());

                Cell bodyCell6 = bodyRow.createCell(6);
                bodyCell6.setCellStyle(bodyStyle);
                bodyCell6.setCellValue(testCase.get("type").asText());
                Cell bodyCell7 = bodyRow.createCell(7);
                bodyCell7.setCellStyle(bodyStyle);
                bodyCell7.setCellValue("正常");
                Cell bodyCell8 = bodyRow.createCell(8);
                bodyCell8.setCellStyle(bodyStyle);
                bodyCell8.setCellValue(testCase.get("level").asText());
                Cell bodyCell9 = bodyRow.createCell(9);
                bodyCell9.setCellStyle(bodyStyle);
                bodyCell9.setCellValue(author);
                Cell bodyCell10 = bodyRow.createCell(10);
                bodyCell10.setCellStyle(bodyStyle);
                bodyCell10.setCellValue(testCase.get("weight").asText());
                Cell bodyCell11 = bodyRow.createCell(11);
                bodyCell11.setCellStyle(bodyStyle);
                bodyCell11.setCellValue(testCase.get("direction").asText());


            }


            // 写入文件
        String outputPath = "/var/www/downloads/" + author + File.separator + fileName + ".xlsx";

//            String outputPath = "E:\\Agi_Project\\glsk-mcp\\glsk-mcp-server\\data\\output\\" + author + File.separator + fileName + ".xlsx";

            Path outputFilePath = Paths.get(outputPath);
            Path parentDir = outputFilePath.getParent();
            if (!Files.exists(parentDir)) {
                Files.createDirectories(parentDir);
            }

            try (FileOutputStream outputStream = new FileOutputStream(outputPath)) {
                workbook.write(outputStream);
            }

            workbook.close();
            log.info("fileName:{}生成excel完成",fileName);

    }

    /**
     * 简洁版:设置自适应行高
     * @param sheet Excel工作表
     */
    public static void setAutoRowHeight(Sheet sheet) {
        for (Row row : sheet) {
            setRowHeightByContent(row);
        }
    }

    /**
     * 根据内容设置单行高度
     */
    private static void setRowHeightByContent(Row row) {
        float maxHeight = 20f; // 默认最小高度20磅

        for (Cell cell : row) {
            String text = getCellText(cell);
            if (text != null && !text.isEmpty()) {
                // 计算文本需要的行数
                int lines = calculateLines(text, cell);
                float cellHeight = lines * 18f; // 每行约18磅
                maxHeight = Math.max(maxHeight, cellHeight);
            }
        }

        // 限制最大高度为100磅
        row.setHeightInPoints(Math.min(maxHeight, 100f));
    }

    /**
     * 计算文本在单元格中的行数
     */
    private static int calculateLines(String text, Cell cell) {
        CellStyle style = cell.getCellStyle();

        // 如果没有自动换行,只有显式换行符才影响行数
        if (!style.getWrapText()) {
            return countNewlines(text) + 1;
        }

        // 获取列宽(字符数)
        int colWidth = getColumnWidthInChars(cell.getSheet(), cell.getColumnIndex());

        // 计算总行数(显式换行符 + 自动换行)
        String[] paragraphs = text.split("\n");
        int totalLines = 0;

        for (String para : paragraphs) {
            if (para.isEmpty()) {
                totalLines++;
                continue;
            }

            // 根据列宽计算段落行数
            int paraLines = (int) Math.ceil((double) getTextLength(para) / colWidth);
            totalLines += Math.max(1, paraLines);
        }

        return Math.max(1, totalLines);
    }

    /**
     * 获取列宽(字符数)
     */
    private static int getColumnWidthInChars(Sheet sheet, int colIndex) {
        int width = sheet.getColumnWidth(colIndex);
        return Math.max(1, (int) (width / 256.0));
    }

    /**
     * 计算文本有效长度(考虑中英文)
     */
    private static int getTextLength(String text) {
        int length = 0;
        for (char c : text.toCharArray()) {
            length += (c >= '\u4e00' && c <= '\u9fa5') ? 2 : 1;
        }
        return length;
    }

    /**
     * 计算换行符数量
     */
    private static int countNewlines(String text) {
        return text.split("\n", -1).length - 1;
    }

    /**
     * 获取单元格文本
     */
    private static String getCellText(Cell cell) {
        if (cell == null) return "";

        switch (cell.getCellType()) {
            case STRING: return cell.getStringCellValue();
            case NUMERIC:
                if (DateUtil.isCellDateFormatted(cell)) {
                    return cell.getDateCellValue().toString();
                }
                return String.valueOf(cell.getNumericCellValue());
            case BOOLEAN: return String.valueOf(cell.getBooleanCellValue());
            case FORMULA:
                try {
                    return cell.getStringCellValue();
                } catch (Exception e) {
                    return cell.getCellFormula();
                }
            default: return "";
        }
    }

    public static void main(String[] args) throws IOException {
        String jsonString = "{\"testCases\": [{\"category\": \"数据分析平台-数据看板功能页面-仪表盘展示\", \"name\": \"检验默认数据看板加载的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、用户已登录系统且具备数据看板访问权限\\n2、系统中存在至少一个预配置的默认看板\\n3、后端服务正常运行,数据库连接可用\", \"steps\": [\"1、进入数据看板功能页面\", \"2、确认未手动选择其他看板\", \"3、观察页面初始加载内容\"], \"expected\": \"系统成功加载默认配置的数据看板,包含正确的图表组件、时间范围(最近7天)和关键指标数据,无空白或错误提示\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"S\"}, {\"category\": \"数据分析平台-数据看板功能页面-仪表盘切换\", \"name\": \"检验不同数据看板间切换功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、用户已登录并进入数据看板功能页面\\n2、系统中存在至少两个已配置的看板(如销售看板、运营看板)\", \"steps\": [\"1、在看板选择下拉菜单中选择‘销售看板’\", \"2、等待页面完全加载\", \"3、记录当前显示内容\", \"4、切换至‘运营看板’\", \"5、等待新看板加载完成\"], \"expected\": \"每次切换后,页面正确渲染对应看板的布局、图表类型、数据维度及过滤条件,且前后看板内容不混杂\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"S\"}, {\"category\": \"数据分析平台-数据看板功能页面-时间范围筛选\", \"name\": \"检验自定义时间范围筛选功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、当前看板支持时间维度筛选\\n2、系统中有历史数据覆盖过去一年\", \"steps\": [\"1、点击时间筛选器控件\", \"2、选择‘自定义时间范围’\", \"3、设置起始时间为‘2023-04-01’,结束时间为‘2023-04-30’\", \"4、点击‘应用’按钮\"], \"expected\": \"所有图表中的数据均按指定时间范围重新计算并刷新显示,标题或图例中标注的时间区间同步更新为‘2023-04-01 至 2023-04-30’\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"数据分析平台-数据看板功能页面-图表交互\", \"name\": \"检验图表钻取功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、当前看板包含可钻取的柱状图(如按地区销售额分布)\\n2、底层明细数据存在\", \"steps\": [\"1、定位到‘各区域销售额’柱状图\", \"2、点击某一柱子(例如‘华东区’)\", \"3、观察页面变化\"], \"expected\": \"系统跳转至下一级视图或弹出浮层,展示该区域(华东区)更细粒度的数据(如城市维度),同时保留返回上级的导航路径\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"数据分析平台-数据看板功能页面-权限控制\", \"name\": \"检验无权限用户访问数据看板时的行为\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、测试账号A不具备任何数据看板访问权限\\n2、系统开启权限校验机制\", \"steps\": [\"1、使用账号A登录系统\", \"2、尝试直接访问数据看板功能页面URL\", \"3、观察系统响应\"], \"expected\": \"系统阻止访问,提示‘您没有权限查看此页面’,并拒绝渲染任何敏感数据,可能重定向至首页或权限申请页\", \"type\": \"安全测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"数据分析平台-数据看板功能页面-异常处理\", \"name\": \"检验网络中断情况下看板加载失败的提示准确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、用户处于正常登录状态\\n2、通过工具模拟客户端与服务器之间的网络断开\", \"steps\": [\"1、进入数据看板功能页面\", \"2、触发网络中断\", \"3、尝试刷新页面或切换看板\"], \"expected\": \"系统在合理超时后(≤10秒)显示明确的错误提示:‘网络连接失败,请检查网络后重试’,并提供‘重试’按钮\", \"type\": \"功能测试\", \"level\": \"中\", \"weight\": \"B\"}, {\"category\": \"数据分析平台-数据看板功能页面-性能表现\", \"name\": \"检验大数据量下看板首次加载的响应时间\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、看板包含5个以上复杂图表(含多维聚合查询)\\n2、关联数据总量超过100万条\\n3、测试环境网络带宽限制为10Mbps\", \"steps\": [\"1、清空浏览器缓存\", \"2、进入数据看板功能页面\", \"3、记录从发起请求到主视觉元素渲染完成的时间\"], \"expected\": \"首屏加载时间不超过5秒,所有图表数据完整呈现,无卡顿或白屏超过3秒的情况\", \"type\": \"性能测试\", \"level\": \"高\", \"weight\": \"B\"}, {\"category\": \"数据分析平台-数据看板功能页面-界面一致性\", \"name\": \"检验不同分辨率下看板布局的自适应能力\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、使用支持响应式测试的浏览器(如Chrome DevTools)\\n2、当前看板采用栅格化布局\", \"steps\": [\"1、将浏览器窗口调整为1920x1080分辨率\", \"2、观察看板布局\", \"3、依次切换至1366x768、移动端750px宽度\", \"4、检查元素错位、溢出或隐藏情况\"], \"expected\": \"在各主流分辨率下,看板组件自动适配布局,无水平滚动条出现,关键信息始终可见,字体大小可读\", \"type\": \"用户界面测试\", \"level\": \"中\", \"weight\": \"B\"}, {\"category\": \"数据分析平台-数据看板功能页面-导出功能\", \"name\": \"检验看板整体导出为PDF格式的完整性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、当前看板已正确加载\\n2、浏览器允许弹出窗口和文件下载\", \"steps\": [\"1、点击‘导出’按钮\", \"2、选择‘导出为PDF’选项\", \"3、确认导出设置(包含图表、时间范围等)\", \"4、执行导出操作\"], \"expected\": \"成功生成PDF文件,打开后包含完整的看板截图,图表清晰可辨,时间范围标注正确,页眉页脚信息齐全\", \"type\": \"功能测试\", \"level\": \"中\", \"weight\": \"B\"}, {\"category\": \"数据分析平台-数据看板功能页面-刷新机制\", \"name\": \"检验定时自动刷新功能的有效性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、当前看板启用‘每5分钟自动刷新’设置\\n2、后台数据源在此期间发生变更\", \"steps\": [\"1、保持看板页面处于激活状态\", \"2、等待第一个5分钟周期结束\", \"3、观察页面是否自动刷新\", \"4、对比刷新前后某关键指标数值变化\"], \"expected\": \"系统在设定间隔(±10秒容差)内自动触发数据刷新,图表内容更新为最新数据,页面无闪退或异常跳转\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-查询功能\", \"name\": \"检验按评估单编号模糊查询功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统已启动并正常运行\\n2、存在至少3条评估单记录,其中包含编号为'PGD2024001'、'PGD2024002'、'XGDPG2024001'的评估单\\n3、当前用户具有评估单列表查看权限\", \"steps\": [\"1、登录系统并进入【评估单列表】页面\", \"2、在搜索框中输入'PGD2024'\", \"3、点击【查询】按钮\"], \"expected\": \"系统仅显示评估单编号包含'PGD2024'的记录(即'PGD2024001'和'PGD2024002'),不显示'XGDPG2024001',共返回2条数据\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-查询功能\", \"name\": \"检验按评估单状态筛选功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在评估单状态为'草稿'、'待审核'、'已完成'的记录各不少于1条\\n2、用户已登录并具备评估单列表访问权限\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、在状态下拉框中选择'待审核'\", \"3、点击【查询】按钮\"], \"expected\": \"列表仅展示状态为'待审核'的评估单,其他状态的记录不显示,且分页统计数量与实际结果一致\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-查询功能\", \"name\": \"检验起止时间范围查询功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在创建时间为2024-01-01、2024-03-15、2024-06-20的评估单\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、设置创建时间起始为'2024-02-01',结束为'2024-05-31'\", \"3、点击【查询】按钮\"], \"expected\": \"仅显示创建时间为2024-03-15的评估单,其余两条不在时间范围内的记录不显示\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-查询功能\", \"name\": \"检验多条件组合查询功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在满足不同组合条件的评估单数据\\n2、用户具备查询权限\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、输入评估单编号关键字'PGD'\", \"3、选择状态为'草稿'\", \"4、设置创建时间范围为'2024-01-01'至'2024-12-31'\", \"5、点击【查询】按钮\"], \"expected\": \"系统仅返回编号包含'PGD'、状态为'草稿'、且创建时间在2024年内的评估单记录,三者条件同时满足\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"S\"}, {\"category\": \"评估系统-评估单列表-查询功能\", \"name\": \"检验查询结果为空时系统的提示信息\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中无编号为'NONEXIST001'的评估单\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、在搜索框中输入'NONEXIST001'\", \"3、点击【查询】按钮\"], \"expected\": \"列表区域显示'暂无数据'或类似友好提示信息,无错误堆栈或空白页面\", \"type\": \"功能测试\", \"level\": \"中\", \"weight\": \"B\"}, {\"category\": \"评估系统-评估单列表-分页功能\", \"name\": \"检验默认每页显示10条数据的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在至少15条评估单记录\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、不进行任何筛选操作,直接查看列表\"], \"expected\": \"页面默认展示前10条评估单记录,分页控件显示当前第1页/共2页\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-分页功能\", \"name\": \"检验翻页功能的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在至少25条评估单数据\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、确认当前为第一页,查看显示的数据条数\", \"3、点击【下一页】按钮\", \"4、再次点击【下一页】按钮\"], \"expected\": \"第二页显示第11-20条数据,第三页显示第21-25条数据,数据不重复也不遗漏\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-排序功能\", \"name\": \"检验按创建时间降序排列的默认排序规则\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中存在多条不同创建时间的评估单\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、观察列表中评估单的排列顺序\"], \"expected\": \"评估单按照创建时间从最新到最旧排列,最新创建的记录位于第一行\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-导出功能\", \"name\": \"检验导出当前查询结果为Excel文件的功能\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、列表中存在至少1条可导出的数据\\n2、浏览器允许下载文件\\n3、用户有导出权限\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、执行一次有效查询,获得若干结果\", \"3、点击【导出】按钮\", \"4、确认导出操作\"], \"expected\": \"系统生成并下载一个Excel文件,文件名包含'评估单列表_YYYYMMDD_HHMMSS'格式的时间戳,文件内容与当前查询结果完全一致\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}, {\"category\": \"评估系统-评估单列表-界面显示\", \"name\": \"检验列表字段显示完整性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、用户已登录\\n2、存在评估单数据\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、浏览表格列头信息\"], \"expected\": \"表格应完整显示以下字段:评估单编号、评估对象名称、评估类型、状态、创建人、创建时间、最后修改时间、操作(含编辑/查看按钮)\", \"type\": \"用户界面测试\", \"level\": \"中\", \"weight\": \"B\"}, {\"category\": \"评估系统-评估单列表-权限控制\", \"name\": \"检验无权限用户访问评估单列表时的行为\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、准备一个未被授权访问评估模块的用户账号\", \"steps\": [\"1、使用该账号登录系统\", \"2、尝试通过URL直连访问【评估单列表】页面\"], \"expected\": \"系统应跳转至权限不足提示页面或重定向至首页,不得显示敏感数据\", \"type\": \"安全测试\", \"level\": \"高\", \"weight\": \"B\"}, {\"category\": \"评估系统-评估单列表-性能测试\", \"name\": \"检验大数据量下列表加载性能\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、数据库中预置10万条评估单记录\\n2、测试环境网络稳定\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、执行默认查询\", \"3、记录从请求发出到数据渲染完成的时间\"], \"expected\": \"在100条/页的配置下,前端页面数据加载响应时间不超过3秒,数据库查询耗时小于1.5秒\", \"type\": \"性能测试\", \"level\": \"高\", \"weight\": \"B\"}, {\"category\": \"评估系统-评估单列表-异常处理\", \"name\": \"检验输入SQL注入语句时系统的防御能力\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、用户已登录\\n2、系统开启安全审计日志\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、在搜索框中输入恶意字符:' OR '1'='1\", \"3、点击【查询】按钮\"], \"expected\": \"系统正常响应,不返回全部数据;后端日志记录可疑请求行为;前端无脚本执行或报错信息泄露\", \"type\": \"安全测试\", \"level\": \"高\", \"weight\": \"B\"}, {\"category\": \"评估系统-评估单列表-操作交互\", \"name\": \"检验点击操作列【查看】按钮跳转详情页的正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、存在至少一条评估单记录\\n2、用户已登录并具备查看权限\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、找到任意一条评估单记录\", \"3、点击其操作列中的【查看】按钮\"], \"expected\": \"页面成功跳转至该评估单的详情页面,URL中包含正确的评估单ID参数,详情页数据与列表中对应一致\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"S\"}, {\"category\": \"评估系统-评估单列表-边界值测试\", \"name\": \"检验页码跳转至最大页后的数据显示正确性\", \"reqmtId\": \"1026780\", \"preconditions\": \"1、系统中共有23条评估单数据,每页显示10条\\n2、用户已登录\", \"steps\": [\"1、进入【评估单列表】页面\", \"2、点击分页控件的最后一页按钮或输入页码'3'并跳转\"], \"expected\": \"第三页正确显示剩余3条数据(第21-23条),无空行或重复数据\", \"type\": \"功能测试\", \"level\": \"高\", \"weight\": \"A\"}]}";


        convertJsonToExcel(jsonString, "二手车测试" , "Mr.Wang");

    }



//        try {
//            convertJsonToExcel(jsonString);
//        } catch (IOException e) {
//            throw new RuntimeException(e);
//        }
//    }
}