fix(接口测试): 测试用例导入表头提示优化
This commit is contained in:
parent
dbf18cde4a
commit
9b1ff67b7f
|
@ -29,12 +29,7 @@ public abstract class EasyExcelListener<T> extends AnalysisEventListener<T> {
|
||||||
*/
|
*/
|
||||||
protected static final int BATCH_COUNT = 2000;
|
protected static final int BATCH_COUNT = 2000;
|
||||||
|
|
||||||
protected Class<T> clazz;
|
protected Class clazz;
|
||||||
|
|
||||||
public EasyExcelListener() {
|
|
||||||
Type type = getClass().getGenericSuperclass();
|
|
||||||
this.clazz = (Class<T>) ((ParameterizedType) type).getActualTypeArguments()[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 每条数据解析都会调用
|
* 每条数据解析都会调用
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
import io.metersphere.base.domain.TestCaseWithBLOBs;
|
||||||
import io.metersphere.commons.constants.TestCaseConstants;
|
import io.metersphere.commons.constants.TestCaseConstants;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.excel.domain.TestCaseExcelData;
|
import io.metersphere.excel.domain.TestCaseExcelData;
|
||||||
import io.metersphere.i18n.Translator;
|
import io.metersphere.i18n.Translator;
|
||||||
import io.metersphere.track.service.TestCaseService;
|
import io.metersphere.track.service.TestCaseService;
|
||||||
|
@ -25,8 +26,9 @@ public class TestCaseDataListener extends EasyExcelListener<TestCaseExcelData> {
|
||||||
|
|
||||||
Set<String> userIds;
|
Set<String> userIds;
|
||||||
|
|
||||||
public TestCaseDataListener(TestCaseService testCaseService, String projectId, Set<String> testCaseNames, Set<String> userIds) {
|
public TestCaseDataListener(Class clazz, String projectId, Set<String> testCaseNames, Set<String> userIds) {
|
||||||
this.testCaseService = testCaseService;
|
this.clazz = clazz;
|
||||||
|
this.testCaseService = (TestCaseService) CommonBeanFactory.getBean("testCaseService");
|
||||||
this.projectId = projectId;
|
this.projectId = projectId;
|
||||||
this.testCaseNames = testCaseNames;
|
this.testCaseNames = testCaseNames;
|
||||||
this.userIds = userIds;
|
this.userIds = userIds;
|
||||||
|
|
|
@ -317,8 +317,9 @@ public class TestCaseService {
|
||||||
Set<String> userIds = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getUserId).collect(Collectors.toSet());
|
Set<String> userIds = userRoleMapper.selectByExample(userRoleExample).stream().map(UserRole::getUserId).collect(Collectors.toSet());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
EasyExcelListener easyExcelListener = new TestCaseDataListener(this, projectId, testCaseNames, userIds);
|
Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal();
|
||||||
EasyExcelFactory.read(multipartFile.getInputStream(), new TestCaseExcelDataFactory().getExcelDataByLocal(), easyExcelListener).sheet().doRead();
|
EasyExcelListener easyExcelListener = new TestCaseDataListener(clazz, projectId, testCaseNames, userIds);
|
||||||
|
EasyExcelFactory.read(multipartFile.getInputStream(), clazz, easyExcelListener).sheet().doRead();
|
||||||
errList = easyExcelListener.getErrList();
|
errList = easyExcelListener.getErrList();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e.getMessage(), e);
|
LogUtil.error(e.getMessage(), e);
|
||||||
|
|
Loading…
Reference in New Issue