修改测试用例导出内容排序

This commit is contained in:
曾威嶂 2025-07-21 13:50:48 +08:00
parent 851cfd5599
commit 986ac5bc96
1 changed files with 31 additions and 14 deletions

View File

@ -1,6 +1,7 @@
package com.microservices.pms.project.service.impl;
import com.alibaba.fastjson2.JSONObject;
import com.microservices.common.core.constant.SecurityConstants;
import com.microservices.common.core.exception.ServiceException;
import com.microservices.common.core.utils.DateUtils;
import com.microservices.common.core.utils.JSONUtils;
@ -31,7 +32,9 @@ import com.microservices.pms.project.service.IPmsProjectTestcaseStepService;
import com.microservices.pms.project.service.IPmsProjectTestcaseTypeService;
import com.microservices.pms.utils.PmsConstants;
import com.microservices.pms.utils.PmsUtils;
import com.microservices.system.api.RemoteUserService;
import com.microservices.system.api.domain.SysUser;
import com.microservices.system.api.utils.FeignUtils;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -45,6 +48,7 @@ import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Field;
import java.math.BigInteger;
import java.time.DateTimeException;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
@ -85,6 +89,8 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
private IPmsProductRequirementService pmsProductRequirementService;
@Autowired
private PmsProjectTestcaseStepMapper pmsProjectTestcaseStepMapper;
@Autowired
private RemoteUserService remoteUserService;
/**
* 查询测试用例管理
@ -789,12 +795,16 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
autoWrap(xwpfTable.getRow(i + 9).getCell(4), 62,expected.get(i),false,false);
}
if(pendingOutputData.getUpdate_time()!=null ){
autoWrap(xwpfTable.getRow(i + 9).getCell(2),62, pendingOutputData.getUpdate_by(), false,false);
String nikeName = Objects.requireNonNull(FeignUtils.getReturnData(remoteUserService.getSysUserByUserName(pendingOutputData.getUpdate_by(), SecurityConstants.INNER))).getNickName();
autoWrap(xwpfTable.getRow(i + 9).getCell(2),62, nikeName, false,false);
autoWrap(xwpfTable.getRow(i + 9).getCell(6),62, String.format("%1$tY-%1$tm-%1$td",pendingOutputData.getUpdate_time()), false,false);
} else{
if(pendingOutputData.getCreate_time()!=null ){
autoWrap(xwpfTable.getRow(i + 9).getCell(2),62, pendingOutputData.getCreate_by(), false,false);
String nikeName = Objects.requireNonNull(FeignUtils.getReturnData(remoteUserService.getSysUserByUserName(pendingOutputData.getCreate_by(), SecurityConstants.INNER))).getNickName();
autoWrap(xwpfTable.getRow(i + 9).getCell(2),62, nikeName, false,false);
autoWrap(xwpfTable.getRow(i + 9).getCell(6),62, String.format("%1$tY-%1$tm-%1$td",pendingOutputData.getCreate_time()), false,false);
}else{
autoWrap(xwpfTable.getRow(i + 10).getCell(6),62, "2025-01-01", false,false);
}
}
@ -803,9 +813,12 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
private void creatTableTemplate(XWPFDocument xwpfDocument,PendingOutputDataVo pendingOutputData) {
//获取此用例步骤数
int stepNumber = pendingOutputData.getContent_list().size();
int stepNumber = 1;
if (pendingOutputData.getId() != null){
stepNumber = pendingOutputData.getContent_list().size();
}
// 创建表格 - 宽度设置为所有列宽度之和
XWPFTable table = xwpfDocument.createTable(stepNumber + 13, 9);
XWPFTable table = xwpfDocument.createTable(stepNumber + 14, 9);
// 不显示表格最后行
hideTableRow(table);
@ -909,10 +922,10 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
XWPFParagraph titleParagraph = doc.createParagraph();
titleParagraph.setAlignment(ParagraphAlignment.CENTER);
XWPFRun run = titleParagraph.createRun();
run.setText("");
run.setText("" + chapter + " - ");
// 设置标题样式
run.setFontFamily("Times New Roman");
run.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
run.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
run.setFontSize(12);
CTRPr rPr0 = run.getCTR().isSetRPr() ? run.getCTR().getRPr() : run.getCTR().addNewRPr();
rPr0.addNewSz().setVal(BigInteger.valueOf(21));
@ -925,14 +938,14 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
// 创建域代码
XWPFRun codeRun = titleParagraph.createRun();
String domainCode = " SEQ Table \\* ARABIC \\s " + chapter;
String domainCode = " SEQ Table \\* ARABIC \\s "; //+ chapter;
codeRun.setText(domainCode);
// 设置字体大小可根据需要调整
CTRPr rPr1 = codeRun.getCTR().isSetRPr() ? codeRun.getCTR().getRPr() : codeRun.getCTR().addNewRPr();
rPr1.addNewSz().setVal(BigInteger.valueOf(21));
rPr1.addNewSzCs().setVal(BigInteger.valueOf(21));
codeRun.setFontFamily("Times New Roman");
codeRun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
codeRun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
// 创建域分隔字符
XWPFRun sepRun = titleParagraph.createRun();
@ -945,13 +958,13 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
// 创建域结果
XWPFRun resultRun = titleParagraph.createRun();
resultRun.setText(chapter + " - " + tableCount);
resultRun.setText(String.valueOf(tableCount));
// 设置字体大小可根据需要调整
CTRPr rPr3 = resultRun.getCTR().isSetRPr() ? resultRun.getCTR().getRPr() : resultRun.getCTR().addNewRPr();
rPr3.addNewSz().setVal(BigInteger.valueOf(21));
rPr3.addNewSzCs().setVal(BigInteger.valueOf(21));
resultRun.setFontFamily("Times New Roman");
resultRun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
resultRun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
// 创建域结束字符
XWPFRun endRun = titleParagraph.createRun();
@ -965,7 +978,7 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
rPr4.addNewSz().setVal(BigInteger.valueOf(21));
rPr4.addNewSzCs().setVal(BigInteger.valueOf(21));
titlerun.setFontFamily("Times New Roman");
titlerun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
titlerun.setFontFamily("", XWPFRun.FontCharRange.eastAsia);
}
/**
@ -1614,9 +1627,13 @@ public class PmsProjectTestcaseServiceImpl implements IPmsProjectTestcaseService
testcaseStep.setExpectedResult(getTableCellValue(tableRows, i, 2));
testcaseSteps.add(testcaseStep);
} else {
testcase.setCreateBy(getTableCellValue(tableRows, i, 1));
Date date = stringToDateUsingDateTimeFormatter(getTableCellValue(tableRows, i , 3), "yyyy-MM-dd");
testcase.setCreateTime(date);
testcase.setCreateBy(SecurityUtils.getUsername());
try{
Date date = stringToDateUsingDateTimeFormatter(getTableCellValue(tableRows, i , 3), "yyyy-MM-dd");
testcase.setCreateTime(date);
} catch (DateTimeException e) {
throw new ServiceException("日期解析失败,请按模板格式填写设计日期");
}
break;
}
}