refactor: 重构功能用例导入后端
This commit is contained in:
parent
7adb8aeeee
commit
aec7427773
|
@ -524,7 +524,10 @@ public class ProjectService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean useCustomNum(String projectId) {
|
public boolean useCustomNum(String projectId) {
|
||||||
Project project = this.getProjectById(projectId);
|
return useCustomNum(this.getProjectById(projectId));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean useCustomNum(Project project) {
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
Boolean customNum = project.getCustomNum();
|
Boolean customNum = project.getCustomNum();
|
||||||
// 未开启自定义ID
|
// 未开启自定义ID
|
||||||
|
|
|
@ -27,10 +27,7 @@ import io.metersphere.notice.annotation.SendNotice;
|
||||||
import io.metersphere.service.CheckPermissionService;
|
import io.metersphere.service.CheckPermissionService;
|
||||||
import io.metersphere.service.FileService;
|
import io.metersphere.service.FileService;
|
||||||
import io.metersphere.track.dto.TestCaseDTO;
|
import io.metersphere.track.dto.TestCaseDTO;
|
||||||
import io.metersphere.track.request.testcase.EditTestCaseRequest;
|
import io.metersphere.track.request.testcase.*;
|
||||||
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.testplan.FileOperationRequest;
|
import io.metersphere.track.request.testplan.FileOperationRequest;
|
||||||
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||||
import io.metersphere.track.service.TestCaseService;
|
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")
|
@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) {
|
public ExcelResponse testCaseImport(@RequestPart("request") TestCaseImportRequest request, @RequestPart("file") MultipartFile file, HttpServletRequest httpRequest) {
|
||||||
checkPermissionService.checkProjectOwner(projectId);
|
checkPermissionService.checkProjectOwner(request.getProjectId());
|
||||||
return testCaseService.testCaseImport(file, projectId, userId, importType, request);
|
return testCaseService.testCaseImport(file, request, httpRequest);
|
||||||
}
|
|
||||||
|
|
||||||
@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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/export/template/{projectId}/{importType}")
|
@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.service.*;
|
||||||
import io.metersphere.track.dto.TestCaseCommentDTO;
|
import io.metersphere.track.dto.TestCaseCommentDTO;
|
||||||
import io.metersphere.track.dto.TestCaseDTO;
|
import io.metersphere.track.dto.TestCaseDTO;
|
||||||
import io.metersphere.track.request.testcase.EditTestCaseRequest;
|
import io.metersphere.track.request.testcase.*;
|
||||||
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.testplan.LoadCaseRequest;
|
import io.metersphere.track.request.testplan.LoadCaseRequest;
|
||||||
import io.metersphere.xmind.XmindCaseParser;
|
import io.metersphere.xmind.XmindCaseParser;
|
||||||
import io.metersphere.xmind.pojo.TestCaseXmindData;
|
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) {
|
public ExcelResponse testCaseImport(MultipartFile multipartFile, TestCaseImportRequest request, HttpServletRequest httpRequest) {
|
||||||
|
|
||||||
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;
|
|
||||||
if (multipartFile == null) {
|
if (multipartFile == null) {
|
||||||
MSException.throwException(Translator.get("upload_fail"));
|
MSException.throwException(Translator.get("upload_fail"));
|
||||||
}
|
}
|
||||||
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
if (multipartFile.getOriginalFilename().endsWith(".xmind")) {
|
||||||
try {
|
return testCaseXmindImport(multipartFile, request, httpRequest);
|
||||||
XmindCaseParser xmindParser = new XmindCaseParser(this, userId, projectId, testCaseNames, useCunstomId, importType);
|
} else {
|
||||||
errList = xmindParser.parse(multipartFile);
|
return testCaseExcelImport(multipartFile, request, httpRequest);
|
||||||
if (CollectionUtils.isEmpty(xmindParser.getNodePaths())
|
}
|
||||||
&& CollectionUtils.isEmpty(xmindParser.getTestCase())
|
}
|
||||||
&& CollectionUtils.isEmpty(xmindParser.getUpdateTestCase())) {
|
|
||||||
if (errList == null) {
|
private List<TestCase> getTestCaseForImport(String projectId) {
|
||||||
errList = new ArrayList<>();
|
QueryTestCaseRequest queryTestCaseRequest = new QueryTestCaseRequest();
|
||||||
}
|
queryTestCaseRequest.setProjectId(projectId);
|
||||||
ExcelErrData excelErrData = new ExcelErrData(null, 1, Translator.get("upload_fail") + ":" + Translator.get("upload_content_is_null"));
|
return extTestCaseMapper.getTestCaseNames(queryTestCaseRequest);
|
||||||
errList.add(excelErrData);
|
}
|
||||||
excelResponse.setErrList(errList);
|
|
||||||
|
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()) {
|
if (errList.isEmpty()) {
|
||||||
List<String> names = new LinkedList<>();
|
|
||||||
List<String> ids = new LinkedList<>();
|
|
||||||
if (CollectionUtils.isNotEmpty(xmindParser.getNodePaths())) {
|
if (CollectionUtils.isNotEmpty(xmindParser.getNodePaths())) {
|
||||||
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
|
testCaseNodeService.createNodes(xmindParser.getNodePaths(), projectId);
|
||||||
}
|
}
|
||||||
|
@ -763,58 +777,111 @@ public class TestCaseService {
|
||||||
names.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getName).collect(Collectors.toList()));
|
names.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getName).collect(Collectors.toList()));
|
||||||
ids.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getId).collect(Collectors.toList()));
|
ids.addAll(xmindParser.getUpdateTestCase().stream().map(TestCase::getId).collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
request.setAttribute("ms-req-title", String.join(",", names));
|
httpRequest.setAttribute("ms-req-title", String.join(",", names));
|
||||||
request.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
httpRequest.setAttribute("ms-req-source-id", JSON.toJSONString(ids));
|
||||||
}
|
}
|
||||||
xmindParser.clear();
|
} else {
|
||||||
} catch (Exception e) {
|
List<TestCaseWithBLOBs> continueCaseList = xmindParser.getContinueValidatedCase();
|
||||||
LogUtil.error(e.getMessage(), e);
|
if (CollectionUtils.isNotEmpty(continueCaseList) || CollectionUtils.isNotEmpty(xmindParser.getUpdateTestCase())) {
|
||||||
MSException.throwException(e.getMessage());
|
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 queryMemberRequest = new QueryMemberRequest();
|
||||||
queryMemberRequest.setProjectId(projectId);
|
queryMemberRequest.setProjectId(projectId);
|
||||||
Set<String> userIds = userService.getProjectMemberList(queryMemberRequest)
|
userIds = userService.getProjectMemberList(queryMemberRequest)
|
||||||
.stream()
|
.stream()
|
||||||
.map(User::getId)
|
.map(User::getId)
|
||||||
.collect(Collectors.toSet());
|
.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 {
|
} 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) {
|
public void saveImportData(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||||
|
@ -1865,122 +1932,6 @@ public class TestCaseService {
|
||||||
extTestCaseMapper.updateTestCaseCustomNumByProjectId(projectId);
|
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) {
|
public String getLogDetails(String id) {
|
||||||
TestCaseWithBLOBs bloBs = testCaseMapper.selectByPrimaryKey(id);
|
TestCaseWithBLOBs bloBs = testCaseMapper.selectByPrimaryKey(id);
|
||||||
if (bloBs != null) {
|
if (bloBs != null) {
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
:on-remove="handleRemove"
|
:on-remove="handleRemove"
|
||||||
:file-list="fileList">
|
:file-list="fileList">
|
||||||
<template v-slot:trigger>
|
<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>
|
||||||
<template v-slot:tip>
|
<template v-slot:tip>
|
||||||
<div v-if="isExcel" class="el-upload__tip">{{$t('test_track.case.import.upload_limit')}}</div>
|
<div v-if="isExcel" class="el-upload__tip">{{$t('test_track.case.import.upload_limit')}}</div>
|
||||||
|
@ -62,7 +62,8 @@
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|
||||||
<el-row class="import-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>
|
||||||
|
|
||||||
<el-row>
|
<el-row>
|
||||||
|
@ -75,9 +76,9 @@
|
||||||
|
|
||||||
<el-row style="text-align: right" v-if="showContinueBtn">
|
<el-row style="text-align: right" v-if="showContinueBtn">
|
||||||
<div style="margin-right: 20px;margin-bottom: 10px;">
|
<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>
|
</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>
|
||||||
<el-button @click="$emit('close')">{{ $t('commons.cancel') }}</el-button>
|
<el-button @click="$emit('close')">{{ $t('commons.cancel') }}</el-button>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
@ -86,12 +87,13 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import {TokenKey} from "@/common/js/constants";
|
import {getCurrentProjectID, getCurrentUserId} from "@/common/js/utils";
|
||||||
import {getCurrentProjectID} from "@/common/js/utils";
|
import VersionSelect from "@/business/components/xpack/version/VersionSelect";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "TestCaseCommonImport",
|
name: "TestCaseCommonImport",
|
||||||
props: ['isUpdated', 'tabName', 'name'],
|
components: {VersionSelect},
|
||||||
|
props: ['tabName', 'name'],
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
result: {},
|
result: {},
|
||||||
|
@ -100,7 +102,8 @@ export default {
|
||||||
importType: 'Create',
|
importType: 'Create',
|
||||||
showContinueBtn: false,
|
showContinueBtn: false,
|
||||||
uploadIgnoreError: false,
|
uploadIgnoreError: false,
|
||||||
lastFile: null
|
lastFile: null,
|
||||||
|
version: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
created() {
|
created() {
|
||||||
|
@ -116,6 +119,9 @@ export default {
|
||||||
isXmind() {
|
isXmind() {
|
||||||
return this.name === 'xmind';
|
return this.name === 'xmind';
|
||||||
},
|
},
|
||||||
|
projectId() {
|
||||||
|
return getCurrentProjectID();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
init() {
|
init() {
|
||||||
|
@ -164,38 +170,34 @@ export default {
|
||||||
handleRemove(file, fileList) {
|
handleRemove(file, fileList) {
|
||||||
this.lastFile = null;
|
this.lastFile = null;
|
||||||
},
|
},
|
||||||
upload() {
|
upload(isIgnore) {
|
||||||
this.isLoading = false;
|
this.isLoading = false;
|
||||||
let user = JSON.parse(localStorage.getItem(TokenKey));
|
let param = {
|
||||||
this.result = this.$fileUpload('/test/case/import/' + getCurrentProjectID() + '/' + user.id + '/' + this.importType,
|
projectId: getCurrentProjectID(),
|
||||||
this.lastFile, null, {}, response => {
|
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;
|
let res = response.data;
|
||||||
if (res.success) {
|
if (isIgnore) {
|
||||||
this.$success(this.$t('test_track.case.import.success'));
|
this.$success(this.$t('test_track.case.import.success'));
|
||||||
this.dialogVisible = false;
|
this.$emit("close", res.isUpdated);
|
||||||
this.$emit("fresh");
|
|
||||||
} else {
|
} else {
|
||||||
this.errList = res.errList;
|
if (res.success) {
|
||||||
this.isUpdated = res.isUpdated;
|
this.$success(this.$t('test_track.case.import.success'));
|
||||||
this.showContinueBtn = true;
|
this.$emit("close", res.isUpdated);
|
||||||
|
} else {
|
||||||
|
this.errList = res.errList;
|
||||||
|
this.showContinueBtn = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, erro => {
|
|
||||||
this.fileList = [];
|
|
||||||
this.lastFile = null;
|
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
uploadContinue() {
|
changeVersion(data) {
|
||||||
this.isLoading = false;
|
this.version = data;
|
||||||
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;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,20 +4,16 @@
|
||||||
|
|
||||||
<el-tab-pane :label="$t('test_track.case.import.excel_title')" name="excelImport">
|
<el-tab-pane :label="$t('test_track.case.import.excel_title')" name="excelImport">
|
||||||
<test-case-common-import
|
<test-case-common-import
|
||||||
:is-updated="isUpdated"
|
|
||||||
name="excel"
|
name="excel"
|
||||||
tab-name="excelImport"
|
tab-name="excelImport"
|
||||||
@fresh="$emit('refreshAll')"
|
|
||||||
@close="close"
|
@close="close"
|
||||||
ref="excelImport"/>
|
ref="excelImport"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
|
||||||
<el-tab-pane :label="$t('test_track.case.import.xmind_title')" name="xmindImport">
|
<el-tab-pane :label="$t('test_track.case.import.xmind_title')" name="xmindImport">
|
||||||
<test-case-common-import
|
<test-case-common-import
|
||||||
:is-updated="isUpdated"
|
|
||||||
name="xmind"
|
name="xmind"
|
||||||
tab-name="xmindImport"
|
tab-name="xmindImport"
|
||||||
@fresh="$emit('refreshAll')"
|
|
||||||
@close="close"
|
@close="close"
|
||||||
ref="xmindImport"/>
|
ref="xmindImport"/>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
|
@ -38,8 +34,7 @@
|
||||||
return {
|
return {
|
||||||
activeName: 'excelImport',
|
activeName: 'excelImport',
|
||||||
dialogVisible: false,
|
dialogVisible: false,
|
||||||
isLoading: false,
|
isLoading: false
|
||||||
isUpdated: false,
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
|
@ -57,13 +52,12 @@
|
||||||
this.$refs.xmindImport.init();
|
this.$refs.xmindImport.init();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
close() {
|
close(isUpdated) {
|
||||||
removeGoBackListener(this.close);
|
removeGoBackListener(this.close);
|
||||||
this.dialogVisible = false;
|
this.dialogVisible = false;
|
||||||
//通过excel导入更新过数据的话就刷新页面
|
if (isUpdated) {
|
||||||
if (this.isUpdated === true) {
|
//通过excel导入更新过数据的话就刷新页面
|
||||||
this.$emit("refreshAll");
|
this.$emit("refreshAll");
|
||||||
this.isUpdated = false;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue