refactor: 重构功能用例导入后端
This commit is contained in:
parent
d41d3d9704
commit
87c216f01c
|
@ -524,7 +524,10 @@ public class ProjectService {
|
|||
}
|
||||
|
||||
public boolean useCustomNum(String projectId) {
|
||||
Project project = this.getProjectById(projectId);
|
||||
return useCustomNum(this.getProjectById(projectId));
|
||||
}
|
||||
|
||||
public boolean useCustomNum(Project project) {
|
||||
if (project != null) {
|
||||
Boolean customNum = project.getCustomNum();
|
||||
// 未开启自定义ID
|
||||
|
|
|
@ -27,10 +27,7 @@ import io.metersphere.notice.annotation.SendNotice;
|
|||
import io.metersphere.service.CheckPermissionService;
|
||||
import io.metersphere.service.FileService;
|
||||
import io.metersphere.track.dto.TestCaseDTO;
|
||||
import io.metersphere.track.request.testcase.EditTestCaseRequest;
|
||||
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
|
||||
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
|
||||
import io.metersphere.track.request.testcase.TestCaseMinderEditRequest;
|
||||
import io.metersphere.track.request.testcase.*;
|
||||
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||
import io.metersphere.track.service.TestCaseService;
|
||||
|
@ -259,18 +256,11 @@ public class TestCaseController {
|
|||
}
|
||||
|
||||
|
||||
@PostMapping("/import/{projectId}/{userId}/{importType}")
|
||||
@PostMapping("/import")
|
||||
@MsAuditLog(module = "track_test_case", type = OperLogConstants.IMPORT, project = "#projectId")
|
||||
public ExcelResponse testCaseImport(MultipartFile file, @PathVariable String projectId, @PathVariable String userId, @PathVariable String importType, HttpServletRequest request) {
|
||||
checkPermissionService.checkProjectOwner(projectId);
|
||||
return testCaseService.testCaseImport(file, projectId, userId, importType, request);
|
||||
}
|
||||
|
||||
@PostMapping("/importIgnoreError/{projectId}/{userId}/{importType}")
|
||||
@MsAuditLog(module = "track_test_case", type = OperLogConstants.IMPORT, project = "#projectId")
|
||||
public ExcelResponse testCaseImportIgnoreError(MultipartFile file, @PathVariable String projectId, @PathVariable String userId, @PathVariable String importType, HttpServletRequest request) {
|
||||
checkPermissionService.checkProjectOwner(projectId);
|
||||
return testCaseService.testCaseImportIgnoreError(file, projectId, userId, importType, request);
|
||||
public ExcelResponse testCaseImport(@RequestPart("request") TestCaseImportRequest request, @RequestPart("file") MultipartFile file, HttpServletRequest httpRequest) {
|
||||
checkPermissionService.checkProjectOwner(request.getProjectId());
|
||||
return testCaseService.testCaseImport(file, request, httpRequest);
|
||||
}
|
||||
|
||||
@GetMapping("/export/template/{projectId}/{importType}")
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
package io.metersphere.track.request.testcase;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class TestCaseImportRequest {
|
||||
private String projectId;
|
||||
private String userId;
|
||||
private String importType;
|
||||
private String version;
|
||||
private boolean ignore;
|
||||
}
|
|
@ -48,10 +48,7 @@ import io.metersphere.performance.service.PerformanceTestService;
|
|||
import io.metersphere.service.*;
|
||||
import io.metersphere.track.dto.TestCaseCommentDTO;
|
||||
import io.metersphere.track.dto.TestCaseDTO;
|
||||
import io.metersphere.track.request.testcase.EditTestCaseRequest;
|
||||
import io.metersphere.track.request.testcase.QueryTestCaseRequest;
|
||||
import io.metersphere.track.request.testcase.TestCaseBatchRequest;
|
||||
import io.metersphere.track.request.testcase.TestCaseMinderEditRequest;
|
||||
import io.metersphere.track.request.testcase.*;
|
||||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||
import io.metersphere.xmind.XmindCaseParser;
|
||||
import io.metersphere.xmind.pojo.TestCaseXmindData;
|
||||
|
@ -708,47 +705,64 @@ public class TestCaseService {
|
|||
}
|
||||
|
||||
|
||||
public ExcelResponse testCaseImport(MultipartFile multipartFile, String projectId, String userId, String importType, HttpServletRequest request) {
|
||||
|
||||
ExcelResponse excelResponse = new ExcelResponse();
|
||||
boolean isUpdated = false; //判断是否更新了用例
|
||||
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
|
||||
QueryTestCaseRequest queryTestCaseRequest = new QueryTestCaseRequest();
|
||||
queryTestCaseRequest.setProjectId(projectId);
|
||||
boolean useCunstomId = projectService.useCustomNum(projectId);
|
||||
List<TestCase> testCases = extTestCaseMapper.getTestCaseNames(queryTestCaseRequest);
|
||||
Set<String> savedIds = new HashSet<>();
|
||||
Set<String> testCaseNames = new HashSet<>();
|
||||
for (TestCase testCase : testCases) {
|
||||
if (useCunstomId) {
|
||||
savedIds.add(testCase.getCustomNum());
|
||||
} else {
|
||||
savedIds.add(String.valueOf(testCase.getNum()));
|
||||
}
|
||||
|
||||
testCaseNames.add(testCase.getName());
|
||||
}
|
||||
List<ExcelErrData<TestCaseExcelData>> errList = null;
|
||||
public ExcelResponse testCaseImport(MultipartFile multipartFile, TestCaseImportRequest request, HttpServletRequest httpRequest) {
|
||||
if (multipartFile == null) {
|
||||
MSException.throwException(Translator.get("upload_fail"));
|
||||
}
|
||||
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
||||
try {
|
||||
XmindCaseParser xmindParser = new XmindCaseParser(this, userId, projectId, testCaseNames, useCunstomId, importType);
|
||||
errList = xmindParser.parse(multipartFile);
|
||||
if (CollectionUtils.isEmpty(xmindParser.getNodePaths())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getTestCase())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getUpdateTestCase())) {
|
||||
if (errList == null) {
|
||||
errList = new ArrayList<>();
|
||||
}
|
||||
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + ":" + Translator.get("upload_content_is_null"));
|
||||
errList.add(excelErrData);
|
||||
excelResponse.setErrList(errList);
|
||||
return testCaseXmindImport(multipartFile, request, httpRequest);
|
||||
} else {
|
||||
return testCaseExcelImport(multipartFile, request, httpRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private List<TestCase> getTestCaseForImport(String projectId) {
|
||||
QueryTestCaseRequest queryTestCaseRequest = new QueryTestCaseRequest();
|
||||
queryTestCaseRequest.setProjectId(projectId);
|
||||
return extTestCaseMapper.getTestCaseNames(queryTestCaseRequest);
|
||||
}
|
||||
|
||||
private ExcelResponse getImportResponse(List<ExcelErrData<TestCaseExcelData>> errList, boolean isUpdated) {
|
||||
ExcelResponse excelResponse = new ExcelResponse();
|
||||
//如果包含错误信息就导出错误信息
|
||||
if (!errList.isEmpty()) {
|
||||
excelResponse.setSuccess(false);
|
||||
excelResponse.setErrList(errList);
|
||||
excelResponse.setIsUpdated(isUpdated);
|
||||
} else {
|
||||
excelResponse.setSuccess(true);
|
||||
}
|
||||
return excelResponse;
|
||||
}
|
||||
|
||||
private ExcelResponse testCaseXmindImport(MultipartFile multipartFile, TestCaseImportRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
String projectId = request.getProjectId();
|
||||
List<ExcelErrData<TestCaseExcelData>> errList = new ArrayList<>();
|
||||
Project project = projectService.getProjectById(projectId);
|
||||
boolean useCunstomId = projectService.useCustomNum(project);
|
||||
|
||||
Set<String> testCaseNames = getTestCaseForImport(projectId).stream()
|
||||
.map(TestCase::getName)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
try {
|
||||
XmindCaseParser xmindParser = new XmindCaseParser(this, request.getUserId(), projectId, testCaseNames, useCunstomId, request.getImportType());
|
||||
errList = xmindParser.parse(multipartFile);
|
||||
if (CollectionUtils.isEmpty(xmindParser.getNodePaths())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getTestCase())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getUpdateTestCase())) {
|
||||
if (errList == null) {
|
||||
errList = new ArrayList<>();
|
||||
}
|
||||
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + ":" + Translator.get("upload_content_is_null"));
|
||||
errList.add(excelErrData);
|
||||
}
|
||||
|
||||
List<String> names = new LinkedList<>();
|
||||
List<String> ids = new LinkedList<>();
|
||||
if (!request.isIgnore()) {
|
||||
if (errList.isEmpty()) {
|
||||
List<String> names = new LinkedList<>();
|
||||
List<String> ids = new LinkedList<>();
|
||||
if (CollectionUtils.isNotEmpty(xmindParser.getNodePaths())) {
|
||||
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
|
||||
}
|
||||
|
@ -763,58 +777,111 @@ public class TestCaseService {
|
|||
names.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getName).collect(Collectors.toList()));
|
||||
ids.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getId).collect(Collectors.toList()));
|
||||
}
|
||||
request.setAttribute("ms-req-title", String.join(",", names));
|
||||
request.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
||||
httpRequest.setAttribute("ms-req-title", String.join(",", names));
|
||||
httpRequest.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
||||
}
|
||||
xmindParser.clear();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(e.getMessage());
|
||||
} else {
|
||||
List<TestCaseWithBLOBs> continueCaseList = xmindParser.getContinueValidatedCase();
|
||||
if (CollectionUtils.isNotEmpty(continueCaseList) || CollectionUtils.isNotEmpty(xmindParser.getUpdateTestCase())) {
|
||||
if (CollectionUtils.isNotEmpty(xmindParser.getUpdateTestCase())) {
|
||||
continueCaseList.removeAll(xmindParser.getUpdateTestCase());
|
||||
this.updateImportData(xmindParser.getUpdateTestCase(), projectId);
|
||||
names = xmindParser.getTestCase().stream().map(TestCase::getName).collect(Collectors.toList());
|
||||
ids = xmindParser.getTestCase().stream().map(TestCase::getId).collect(Collectors.toList());
|
||||
}
|
||||
List<String> nodePathList = xmindParser.getValidatedNodePath();
|
||||
if (CollectionUtils.isNotEmpty(nodePathList)) {
|
||||
testCaseNodeService.createNodes(nodePathList, projectId);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(continueCaseList)) {
|
||||
// Collections.reverse(continueCaseList);
|
||||
this.saveImportData(continueCaseList, projectId);
|
||||
names.addAll(continueCaseList.stream().map(TestCase::getName).collect(Collectors.toList()));
|
||||
ids.addAll(continueCaseList.stream().map(TestCase::getId).collect(Collectors.toList()));
|
||||
|
||||
}
|
||||
httpRequest.setAttribute("ms-req-title", String.join(",", names));
|
||||
httpRequest.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
||||
}
|
||||
|
||||
}
|
||||
xmindParser.clear();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e);
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
return getImportResponse(errList, false);
|
||||
}
|
||||
|
||||
private ExcelResponse testCaseExcelImport(MultipartFile multipartFile, TestCaseImportRequest request,
|
||||
HttpServletRequest httpRequest) {
|
||||
String projectId = request.getProjectId();
|
||||
Set<String> userIds;
|
||||
Project project = projectService.getProjectById(projectId);
|
||||
boolean useCunstomId = projectService.useCustomNum(project);
|
||||
|
||||
Set<String> savedIds = new HashSet<>();
|
||||
Set<String> testCaseNames = new HashSet<>();
|
||||
List<ExcelErrData<TestCaseExcelData>> errList = new ArrayList<>();
|
||||
boolean isUpdated = false;
|
||||
|
||||
List<TestCase> testCases = getTestCaseForImport(projectId);
|
||||
for (TestCase testCase : testCases) {
|
||||
if (useCunstomId) {
|
||||
savedIds.add(testCase.getCustomNum());
|
||||
} else {
|
||||
savedIds.add(String.valueOf(testCase.getNum()));
|
||||
}
|
||||
|
||||
} else {
|
||||
testCaseNames.add(testCase.getName());
|
||||
}
|
||||
|
||||
if (!request.isIgnore()) {
|
||||
QueryMemberRequest queryMemberRequest = new QueryMemberRequest();
|
||||
queryMemberRequest.setProjectId(projectId);
|
||||
Set<String> userIds = userService.getProjectMemberList(queryMemberRequest)
|
||||
userIds = userService.getProjectMemberList(queryMemberRequest)
|
||||
.stream()
|
||||
.map(User::getId)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
try {
|
||||
//根据本地语言环境选择用哪种数据对象进行存放读取的数据
|
||||
Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal();
|
||||
TestCaseTemplateService testCaseTemplateService = CommonBeanFactory.getBean(TestCaseTemplateService.class);
|
||||
TestCaseTemplateDao testCaseTemplate = testCaseTemplateService.getTemplate(projectId);
|
||||
List<CustomFieldDao> customFields = null;
|
||||
if (testCaseTemplate == null) {
|
||||
customFields = new ArrayList<>();
|
||||
} else {
|
||||
customFields = testCaseTemplate.getCustomFields();
|
||||
}
|
||||
TestCaseNoModelDataListener easyExcelListener = new TestCaseNoModelDataListener(false, clazz, customFields, projectId, testCaseNames, savedIds, userIds, useCunstomId, importType);
|
||||
//读取excel数据
|
||||
EasyExcelFactory.read(multipartFile.getInputStream(), easyExcelListener).sheet().doRead();
|
||||
request.setAttribute("ms-req-title", String.join(",", easyExcelListener.getNames()));
|
||||
request.setAttribute("ms-req-source-id", JSON.toJSONString(easyExcelListener.getIds()));
|
||||
|
||||
errList = easyExcelListener.getErrList();
|
||||
isUpdated = easyExcelListener.isUpdated();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
//如果包含错误信息就导出错误信息
|
||||
if (!errList.isEmpty()) {
|
||||
excelResponse.setSuccess(false);
|
||||
excelResponse.setErrList(errList);
|
||||
excelResponse.setIsUpdated(isUpdated);
|
||||
} else {
|
||||
excelResponse.setSuccess(true);
|
||||
GroupExample groupExample = new GroupExample();
|
||||
groupExample.createCriteria().andTypeIn(Arrays.asList(UserGroupType.WORKSPACE, UserGroupType.PROJECT));
|
||||
List<Group> groups = groupMapper.selectByExample(groupExample);
|
||||
List<String> groupIds = groups.stream().map(Group::getId).collect(Collectors.toList());
|
||||
|
||||
UserGroupExample userGroupExample = new UserGroupExample();
|
||||
userGroupExample.createCriteria()
|
||||
.andGroupIdIn(groupIds)
|
||||
.andSourceIdEqualTo(project.getWorkspaceId());
|
||||
userIds = userGroupMapper.selectByExample(userGroupExample).stream().map(UserGroup::getUserId).collect(Collectors.toSet());
|
||||
}
|
||||
return excelResponse;
|
||||
|
||||
try {
|
||||
//根据本地语言环境选择用哪种数据对象进行存放读取的数据
|
||||
Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal();
|
||||
TestCaseTemplateService testCaseTemplateService = CommonBeanFactory.getBean(TestCaseTemplateService.class);
|
||||
TestCaseTemplateDao testCaseTemplate = testCaseTemplateService.getTemplate(projectId);
|
||||
List<CustomFieldDao> customFields = null;
|
||||
if (testCaseTemplate == null) {
|
||||
customFields = new ArrayList<>();
|
||||
} else {
|
||||
customFields = testCaseTemplate.getCustomFields();
|
||||
}
|
||||
TestCaseNoModelDataListener easyExcelListener = new TestCaseNoModelDataListener(request.isIgnore(), clazz, customFields, projectId, testCaseNames,
|
||||
savedIds, userIds, useCunstomId, request.getImportType());
|
||||
|
||||
//读取excel数据
|
||||
EasyExcelFactory.read(multipartFile.getInputStream(), easyExcelListener).sheet().doRead();
|
||||
httpRequest.setAttribute("ms-req-title", String.join(",", easyExcelListener.getNames()));
|
||||
httpRequest.setAttribute("ms-req-source-id", JSON.toJSONString(easyExcelListener.getIds()));
|
||||
|
||||
errList = easyExcelListener.getErrList();
|
||||
isUpdated = easyExcelListener.isUpdated();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
return getImportResponse(errList, isUpdated);
|
||||
}
|
||||
|
||||
public void saveImportData(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||
|
@ -1865,122 +1932,6 @@ public class TestCaseService {
|
|||
extTestCaseMapper.updateTestCaseCustomNumByProjectId(projectId);
|
||||
}
|
||||
|
||||
public ExcelResponse testCaseImportIgnoreError(MultipartFile multipartFile, String projectId, String userId, String importType, HttpServletRequest request) {
|
||||
|
||||
ExcelResponse excelResponse = new ExcelResponse();
|
||||
boolean isUpdated = false; //判断是否更新了用例
|
||||
String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId();
|
||||
QueryTestCaseRequest queryTestCaseRequest = new QueryTestCaseRequest();
|
||||
queryTestCaseRequest.setProjectId(projectId);
|
||||
List<TestCase> testCases = extTestCaseMapper.getTestCaseNames(queryTestCaseRequest);
|
||||
boolean useCunstomId = projectService.useCustomNum(projectId);
|
||||
Set<String> savedIds = new HashSet<>();
|
||||
Set<String> testCaseNames = new HashSet<>();
|
||||
for (TestCase testCase : testCases) {
|
||||
if (useCunstomId) {
|
||||
savedIds.add(testCase.getCustomNum());
|
||||
} else {
|
||||
savedIds.add(String.valueOf(testCase.getNum()));
|
||||
}
|
||||
testCaseNames.add(testCase.getName());
|
||||
}
|
||||
List<ExcelErrData<TestCaseExcelData>> errList = null;
|
||||
if (multipartFile == null) {
|
||||
MSException.throwException(Translator.get("upload_fail"));
|
||||
}
|
||||
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
||||
try {
|
||||
XmindCaseParser xmindParser = new XmindCaseParser(this, userId, projectId, testCaseNames, useCunstomId, importType);
|
||||
errList = xmindParser.parse(multipartFile);
|
||||
if (CollectionUtils.isEmpty(xmindParser.getNodePaths())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getTestCase())
|
||||
&& CollectionUtils.isEmpty(xmindParser.getUpdateTestCase())) {
|
||||
if (errList == null) {
|
||||
errList = new ArrayList<>();
|
||||
}
|
||||
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + ":" + Translator.get("upload_content_is_null"));
|
||||
errList.add(excelErrData);
|
||||
excelResponse.setErrList(errList);
|
||||
}
|
||||
List<TestCaseWithBLOBs> continueCaseList = xmindParser.getContinueValidatedCase();
|
||||
if (CollectionUtils.isNotEmpty(continueCaseList) || CollectionUtils.isNotEmpty(xmindParser.getUpdateTestCase())) {
|
||||
List<String> names = new LinkedList<>();
|
||||
List<String> ids = new LinkedList<>();
|
||||
|
||||
if (CollectionUtils.isNotEmpty(xmindParser.getUpdateTestCase())) {
|
||||
continueCaseList.removeAll(xmindParser.getUpdateTestCase());
|
||||
this.updateImportData(xmindParser.getUpdateTestCase(), projectId);
|
||||
names = xmindParser.getTestCase().stream().map(TestCase::getName).collect(Collectors.toList());
|
||||
ids = xmindParser.getTestCase().stream().map(TestCase::getId).collect(Collectors.toList());
|
||||
}
|
||||
List<String> nodePathList = xmindParser.getValidatedNodePath();
|
||||
if (CollectionUtils.isNotEmpty(nodePathList)) {
|
||||
testCaseNodeService.createNodes(nodePathList, projectId);
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(continueCaseList)) {
|
||||
// Collections.reverse(continueCaseList);
|
||||
this.saveImportData(continueCaseList, projectId);
|
||||
names.addAll(continueCaseList.stream().map(TestCase::getName).collect(Collectors.toList()));
|
||||
ids.addAll(continueCaseList.stream().map(TestCase::getId).collect(Collectors.toList()));
|
||||
|
||||
}
|
||||
request.setAttribute("ms-req-title", String.join(",", names));
|
||||
request.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
||||
|
||||
}
|
||||
xmindParser.clear();
|
||||
} catch (Exception e) {
|
||||
LogUtil.error(e.getMessage(), e);
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
} else {
|
||||
GroupExample groupExample = new GroupExample();
|
||||
groupExample.createCriteria().andTypeIn(Arrays.asList(UserGroupType.WORKSPACE, UserGroupType.PROJECT));
|
||||
List<Group> groups = groupMapper.selectByExample(groupExample);
|
||||
List<String> groupIds = groups.stream().map(Group::getId).collect(Collectors.toList());
|
||||
|
||||
UserGroupExample userGroupExample = new UserGroupExample();
|
||||
userGroupExample.createCriteria()
|
||||
.andGroupIdIn(groupIds)
|
||||
.andSourceIdEqualTo(currentWorkspaceId);
|
||||
Set<String> userIds = userGroupMapper.selectByExample(userGroupExample).stream().map(UserGroup::getUserId).collect(Collectors.toSet());
|
||||
|
||||
try {
|
||||
//根据本地语言环境选择用哪种数据对象进行存放读取的数据
|
||||
Class clazz = new TestCaseExcelDataFactory().getExcelDataByLocal();
|
||||
TestCaseTemplateService testCaseTemplateService = CommonBeanFactory.getBean(TestCaseTemplateService.class);
|
||||
TestCaseTemplateDao testCaseTemplate = testCaseTemplateService.getTemplate(projectId);
|
||||
List<CustomFieldDao> customFields = null;
|
||||
if (testCaseTemplate == null) {
|
||||
customFields = new ArrayList<>();
|
||||
} else {
|
||||
customFields = testCaseTemplate.getCustomFields();
|
||||
}
|
||||
TestCaseNoModelDataListener easyExcelListener = new TestCaseNoModelDataListener(true, clazz, customFields, projectId, testCaseNames, savedIds, userIds, useCunstomId, importType);
|
||||
//读取excel数据
|
||||
EasyExcelFactory.read(multipartFile.getInputStream(), easyExcelListener).sheet().doRead();
|
||||
request.setAttribute("ms-req-title", String.join(",", easyExcelListener.getNames()));
|
||||
request.setAttribute("ms-req-source-id", JSON.toJSONString(easyExcelListener.getIds()));
|
||||
errList = easyExcelListener.getErrList();
|
||||
isUpdated = easyExcelListener.isUpdated();
|
||||
} catch (Exception e) {
|
||||
|
||||
LogUtil.error(e);
|
||||
MSException.throwException(e.getMessage());
|
||||
}
|
||||
}
|
||||
//如果包含错误信息就导出错误信息
|
||||
if (!errList.isEmpty()) {
|
||||
excelResponse.setSuccess(false);
|
||||
excelResponse.setErrList(errList);
|
||||
excelResponse.setIsUpdated(isUpdated);
|
||||
} else {
|
||||
excelResponse.setSuccess(true);
|
||||
}
|
||||
|
||||
return excelResponse;
|
||||
}
|
||||
|
||||
public String getLogDetails(String id) {
|
||||
TestCaseWithBLOBs bloBs = testCaseMapper.selectByPrimaryKey(id);
|
||||
if (bloBs != null) {
|
||||
|
|
|
@ -52,7 +52,7 @@
|
|||
:on-remove="handleRemove"
|
||||
:file-list="fileList">
|
||||
<template v-slot:trigger>
|
||||
<el-button size="mini" type="success" plain>{{$t('test_track.case.import.click_upload')}}</el-button>
|
||||
<el-button size="mini" type="success" plain>{{$t('commons.please_select')}}</el-button>
|
||||
</template>
|
||||
<template v-slot:tip>
|
||||
<div v-if="isExcel" class="el-upload__tip">{{$t('test_track.case.import.upload_limit')}}</div>
|
||||
|
@ -62,7 +62,8 @@
|
|||
</el-row>
|
||||
|
||||
<el-row class="import-row">
|
||||
<el-button :disabled="!lastFile" size="small" @click="upload">{{$t('test_track.case.import.click_upload')}}</el-button>
|
||||
<el-button :disabled="!lastFile" size="small" @click="upload(false)">{{$t('test_track.case.import.click_upload')}}</el-button>
|
||||
<version-select v-xpack :project-id="projectId" @changeVersion="changeVersion"/>
|
||||
</el-row>
|
||||
|
||||
<el-row>
|
||||
|
@ -75,9 +76,9 @@
|
|||
|
||||
<el-row style="text-align: right" v-if="showContinueBtn">
|
||||
<div style="margin-right: 20px;margin-bottom: 10px;">
|
||||
<el-checkbox v-model="uploadIgnoreError">{{ $t('test_track.case.import.ignore_error') }}</el-checkbox>
|
||||
<el-checkbox :value="true" :disabled="true">{{ $t('test_track.case.import.ignore_error') }}</el-checkbox>
|
||||
</div>
|
||||
<el-button type="primary" @click="uploadContinue">{{ $t('test_track.case.import.continue_upload') }}
|
||||
<el-button type="primary" @click="upload(true)">{{ $t('test_track.case.import.continue_upload') }}
|
||||
</el-button>
|
||||
<el-button @click="$emit('close')">{{ $t('commons.cancel') }}</el-button>
|
||||
</el-row>
|
||||
|
@ -86,12 +87,13 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import {TokenKey} from "@/common/js/constants";
|
||||
import {getCurrentProjectID} from "@/common/js/utils";
|
||||
import {getCurrentProjectID, getCurrentUserId} from "@/common/js/utils";
|
||||
import VersionSelect from "@/business/components/xpack/version/VersionSelect";
|
||||
|
||||
export default {
|
||||
name: "TestCaseCommonImport",
|
||||
props: ['isUpdated', 'tabName', 'name'],
|
||||
components: {VersionSelect},
|
||||
props: ['tabName', 'name'],
|
||||
data() {
|
||||
return {
|
||||
result: {},
|
||||
|
@ -100,7 +102,8 @@ export default {
|
|||
importType: 'Create',
|
||||
showContinueBtn: false,
|
||||
uploadIgnoreError: false,
|
||||
lastFile: null
|
||||
lastFile: null,
|
||||
version: null
|
||||
}
|
||||
},
|
||||
created() {
|
||||
|
@ -116,6 +119,9 @@ export default {
|
|||
isXmind() {
|
||||
return this.name === 'xmind';
|
||||
},
|
||||
projectId() {
|
||||
return getCurrentProjectID();
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
init() {
|
||||
|
@ -164,38 +170,34 @@ export default {
|
|||
handleRemove(file, fileList) {
|
||||
this.lastFile = null;
|
||||
},
|
||||
upload() {
|
||||
upload(isIgnore) {
|
||||
this.isLoading = false;
|
||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
this.result = this.$fileUpload('/test/case/import/' + getCurrentProjectID() + '/' + user.id + '/' + this.importType,
|
||||
this.lastFile, null, {}, response => {
|
||||
let param = {
|
||||
projectId: getCurrentProjectID(),
|
||||
userId: getCurrentUserId(),
|
||||
importType: this.importType,
|
||||
version: this.version,
|
||||
ignore: isIgnore
|
||||
};
|
||||
this.result = this.$fileUpload('/test/case/import',
|
||||
this.lastFile, null, param, response => {
|
||||
let res = response.data;
|
||||
if (res.success) {
|
||||
if (isIgnore) {
|
||||
this.$success(this.$t('test_track.case.import.success'));
|
||||
this.dialogVisible = false;
|
||||
this.$emit("fresh");
|
||||
this.$emit("close", res.isUpdated);
|
||||
} else {
|
||||
this.errList = res.errList;
|
||||
this.isUpdated = res.isUpdated;
|
||||
this.showContinueBtn = true;
|
||||
if (res.success) {
|
||||
this.$success(this.$t('test_track.case.import.success'));
|
||||
this.$emit("close", res.isUpdated);
|
||||
} else {
|
||||
this.errList = res.errList;
|
||||
this.showContinueBtn = true;
|
||||
}
|
||||
}
|
||||
}, erro => {
|
||||
this.fileList = [];
|
||||
this.lastFile = null;
|
||||
});
|
||||
},
|
||||
uploadContinue() {
|
||||
this.isLoading = false;
|
||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
||||
let url = '/test/case/importIgnoreError/' + getCurrentProjectID() + '/' + user.id + '/' + this.importType;
|
||||
this.result = this.$fileUpload(url, this.lastFile, null, {}, response => {
|
||||
this.$success(this.$t('test_track.case.import.success'));
|
||||
this.dialogVisible = false;
|
||||
this.$emit("fresh");
|
||||
}, erro => {
|
||||
this.fileList = [];
|
||||
this.lastFile = null;
|
||||
});
|
||||
changeVersion(data) {
|
||||
this.version = data;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,20 +4,16 @@
|
|||
|
||||
<el-tab-pane :label="$t('test_track.case.import.excel_title')" name="excelImport">
|
||||
<test-case-common-import
|
||||
:is-updated="isUpdated"
|
||||
name="excel"
|
||||
tab-name="excelImport"
|
||||
@fresh="$emit('refreshAll')"
|
||||
@close="close"
|
||||
ref="excelImport"/>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane :label="$t('test_track.case.import.xmind_title')" name="xmindImport">
|
||||
<test-case-common-import
|
||||
:is-updated="isUpdated"
|
||||
name="xmind"
|
||||
tab-name="xmindImport"
|
||||
@fresh="$emit('refreshAll')"
|
||||
@close="close"
|
||||
ref="xmindImport"/>
|
||||
</el-tab-pane>
|
||||
|
@ -38,8 +34,7 @@
|
|||
return {
|
||||
activeName: 'excelImport',
|
||||
dialogVisible: false,
|
||||
isLoading: false,
|
||||
isUpdated: false,
|
||||
isLoading: false
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
@ -57,13 +52,12 @@
|
|||
this.$refs.xmindImport.init();
|
||||
}
|
||||
},
|
||||
close() {
|
||||
close(isUpdated) {
|
||||
removeGoBackListener(this.close);
|
||||
this.dialogVisible = false;
|
||||
//通过excel导入更新过数据的话就刷新页面
|
||||
if (this.isUpdated === true) {
|
||||
if (isUpdated) {
|
||||
//通过excel导入更新过数据的话就刷新页面
|
||||
this.$emit("refreshAll");
|
||||
this.isUpdated = false;
|
||||
}
|
||||
},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue