feat: 功能用例支持批量复制
This commit is contained in:
parent
6340b78658
commit
8819e14212
|
@ -2049,7 +2049,7 @@ public class ApiAutomationService {
|
|||
testPlanApiScenario.setEnvironment(environmentJson);
|
||||
}
|
||||
testPlanApiScenario.setOrder(nextOrder);
|
||||
nextOrder += 5000;
|
||||
nextOrder += ServiceUtils.ORDER_STEP;
|
||||
testPlanApiScenarioMapper.insert(testPlanApiScenario);
|
||||
}
|
||||
}
|
||||
|
@ -2339,7 +2339,7 @@ public class ApiAutomationService {
|
|||
if (order == null) {
|
||||
order = ServiceUtils.getNextOrder(projectId, extApiScenarioMapper::getLastOrder);
|
||||
}
|
||||
order = (order == null ? 0 : order) + 5000;
|
||||
order = (order == null ? 0 : order) + ServiceUtils.ORDER_STEP;
|
||||
currentScenarioOrder.set(order);
|
||||
return order;
|
||||
}
|
||||
|
|
|
@ -654,7 +654,7 @@ public class ApiDefinitionService {
|
|||
if (order == null) {
|
||||
order = ServiceUtils.getNextOrder(projectId, extApiDefinitionMapper::getLastOrder);
|
||||
}
|
||||
order = (order == null ? 0 : order) + 5000;
|
||||
order = (order == null ? 0 : order) + ServiceUtils.ORDER_STEP;
|
||||
currentApiOrder.set(order);
|
||||
return order;
|
||||
}
|
||||
|
@ -664,7 +664,7 @@ public class ApiDefinitionService {
|
|||
if (order == null) {
|
||||
order = ServiceUtils.getNextOrder(projectId, extApiTestCaseMapper::getLastOrder);
|
||||
}
|
||||
order = (order == null ? 0 : order) + 5000;
|
||||
order = (order == null ? 0 : order) + ServiceUtils.ORDER_STEP;
|
||||
currentApiCaseOrder.set(order);
|
||||
return order;
|
||||
}
|
||||
|
|
|
@ -555,7 +555,7 @@ public class ApiTestCaseService {
|
|||
testPlanApiCase.setCreateTime(System.currentTimeMillis());
|
||||
testPlanApiCase.setUpdateTime(System.currentTimeMillis());
|
||||
testPlanApiCase.setOrder(nextOrder);
|
||||
nextOrder += 5000;
|
||||
nextOrder += ServiceUtils.ORDER_STEP;
|
||||
if (testPlanService.isAllowedRepeatCase(request.getPlanId())) {
|
||||
batchBaseMapper.insert(testPlanApiCase);
|
||||
} else {
|
||||
|
|
|
@ -28,6 +28,8 @@ import java.util.stream.Collectors;
|
|||
|
||||
public class ServiceUtils {
|
||||
|
||||
public static final int ORDER_STEP = 5000;
|
||||
|
||||
public static List<OrderRequest> getDefaultOrder(List<OrderRequest> orders) {
|
||||
return getDefaultOrder(null, orders);
|
||||
}
|
||||
|
@ -154,7 +156,7 @@ public class ServiceUtils {
|
|||
T item = clazz.newInstance();
|
||||
setId.invoke(item, id);
|
||||
setOrder.invoke(item, order);
|
||||
order += 5000;
|
||||
order += ServiceUtils.ORDER_STEP;
|
||||
Method updateByPrimaryKeySelectiveFunc = mapper.getClass().getMethod("updateByPrimaryKeySelective", clazz);
|
||||
updateByPrimaryKeySelectiveFunc.invoke(mapper, item);
|
||||
}
|
||||
|
@ -184,8 +186,8 @@ public class ServiceUtils {
|
|||
BiFunction<String, Long, Long> getPreOrderFunc,
|
||||
BiFunction<String, Long, Long> getLastOrderFunc,
|
||||
Consumer<T> updateByPrimaryKeySelectiveFuc) {
|
||||
Long order = null;
|
||||
Long lastOrPreOrder = null;
|
||||
Long order;
|
||||
Long lastOrPreOrder;
|
||||
try {
|
||||
Method getOrder = clazz.getMethod("getOrder");
|
||||
Method setId = clazz.getMethod("setId", String.class);
|
||||
|
@ -197,12 +199,12 @@ public class ServiceUtils {
|
|||
|
||||
if (request.getMoveMode().equals(ResetOrderRequest.MoveMode.AFTER.name())) {
|
||||
// 追加到参考对象的之后
|
||||
order = targetOrder - 5000;
|
||||
order = targetOrder - ServiceUtils.ORDER_STEP;
|
||||
// ,因为是降序排,则查找比目标 order 小的一个order
|
||||
lastOrPreOrder = getPreOrderFunc.apply(request.getGroupId(), targetOrder);
|
||||
} else {
|
||||
// 追加到前面
|
||||
order = targetOrder + 5000;
|
||||
order = targetOrder + ServiceUtils.ORDER_STEP;
|
||||
// 因为是降序排,则查找比目标 order 更大的一个order
|
||||
lastOrPreOrder = getLastOrderFunc.apply(request.getGroupId(), targetOrder);
|
||||
}
|
||||
|
@ -230,7 +232,7 @@ public class ServiceUtils {
|
|||
*/
|
||||
public static Long getNextOrder(String groupId, BiFunction<String, Long, Long> getLastOrderFunc) {
|
||||
Long lastOrder = getLastOrderFunc.apply(groupId, null);
|
||||
return (lastOrder == null ? 0 : lastOrder) + 5000;
|
||||
return (lastOrder == null ? 0 : lastOrder) + ServiceUtils.ORDER_STEP;
|
||||
}
|
||||
|
||||
public static SqlSession getBatchSqlSession() {
|
||||
|
|
|
@ -288,6 +288,15 @@ public class TestCaseController {
|
|||
testCaseService.editTestCaseBath(request);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/copy")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_EDIT)
|
||||
@MsAuditLog(module = "track_test_case", type = OperLogConstants.BATCH_ADD, beforeEvent = "#msClass.getLogDetails(#request.ids)", content = "#msClass.getLogDetails(#request.ids)", msClass = TestCaseService.class)
|
||||
@SendNotice(taskType = NoticeConstants.TaskType.TRACK_TEST_CASE_TASK, target = "#targetClass.findByBatchRequest(#request)", targetClass = TestCaseService.class,
|
||||
event = NoticeConstants.Event.CREATE, mailTemplate = "track/TestCaseUpdate", subject = "测试用例通知")
|
||||
public void copyTestCaseBath(@RequestBody TestCaseBatchRequest request) {
|
||||
testCaseService.copyTestCaseBath(request);
|
||||
}
|
||||
|
||||
@PostMapping("/batch/delete")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_TRACK_CASE_READ_DELETE)
|
||||
@MsAuditLog(module = "track_test_case", type = OperLogConstants.BATCH_DEL, beforeEvent = "#msClass.getLogDetails(#request.ids)", msClass = TestCaseService.class)
|
||||
|
|
|
@ -385,7 +385,7 @@ public class TestCaseReviewService {
|
|||
caseReview.setStatus(TestCaseReviewStatus.Prepare.name());
|
||||
caseReview.setOrder(nextOrder);
|
||||
batchMapper.insert(caseReview);
|
||||
nextOrder += 5000;
|
||||
nextOrder += ServiceUtils.ORDER_STEP;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -650,32 +650,33 @@ public class TestCaseService {
|
|||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
Project project = projectService.getProjectById(projectId);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
Long nextOrder = ServiceUtils.getNextOrder(projectId, extTestCaseMapper::getLastOrder);
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
AtomicInteger num = new AtomicInteger();
|
||||
num.set(getNextNum(projectId) + testCases.size());
|
||||
for (TestCaseWithBLOBs testcase: testCases) {
|
||||
testcase.setId(UUID.randomUUID().toString());
|
||||
testcase.setCreateUser(SessionUtils.getUserId());
|
||||
testcase.setCreateTime(System.currentTimeMillis());
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
int number = num.incrementAndGet();
|
||||
testcase.setNum(number);
|
||||
if (project.getCustomNum() && StringUtils.isBlank(testcase.getCustomNum())) {
|
||||
testcase.setCustomNum(String.valueOf(number));
|
||||
try {
|
||||
Long nextOrder = ServiceUtils.getNextOrder(projectId, extTestCaseMapper::getLastOrder);
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
AtomicInteger num = new AtomicInteger();
|
||||
num.set(getNextNum(projectId) + testCases.size());
|
||||
for (TestCaseWithBLOBs testcase: testCases) {
|
||||
testcase.setId(UUID.randomUUID().toString());
|
||||
testcase.setCreateUser(SessionUtils.getUserId());
|
||||
testcase.setCreateTime(System.currentTimeMillis());
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
int number = num.incrementAndGet();
|
||||
testcase.setNum(number);
|
||||
if (project.getCustomNum() && StringUtils.isBlank(testcase.getCustomNum())) {
|
||||
testcase.setCustomNum(String.valueOf(number));
|
||||
}
|
||||
testcase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setOrder(nextOrder);
|
||||
mapper.insert(testcase);
|
||||
nextOrder += ServiceUtils.ORDER_STEP;
|
||||
}
|
||||
testcase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setOrder(nextOrder);
|
||||
mapper.insert(testcase);
|
||||
nextOrder += 5000;
|
||||
}
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
sqlSession.flushStatements();
|
||||
} finally {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
@ -684,26 +685,27 @@ public class TestCaseService {
|
|||
Map<String, String> nodePathMap = testCaseNodeService.createNodeByTestCases(testCases, projectId);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
AtomicInteger num = new AtomicInteger();
|
||||
num.set(getNextNum(projectId) + testCases.size());
|
||||
testCases.forEach(testcase -> {
|
||||
TestCaseWithBLOBs oldCase = testCaseMapper.selectByPrimaryKey(testcase.getId());
|
||||
String customFieldStr = this.updateCustomField(oldCase.getCustomFields(),testcase.getPriority());
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
if (testcase.getNum() == null) {
|
||||
testcase.setNum(num.decrementAndGet());
|
||||
}
|
||||
testcase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setCustomFields(customFieldStr);
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
try {
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
AtomicInteger num = new AtomicInteger();
|
||||
num.set(getNextNum(projectId) + testCases.size());
|
||||
testCases.forEach(testcase -> {
|
||||
TestCaseWithBLOBs oldCase = testCaseMapper.selectByPrimaryKey(testcase.getId());
|
||||
String customFieldStr = this.updateCustomField(oldCase.getCustomFields(),testcase.getPriority());
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
if (testcase.getNum() == null) {
|
||||
testcase.setNum(num.decrementAndGet());
|
||||
}
|
||||
testcase.setReviewStatus(TestCaseReviewStatus.Prepare.name());
|
||||
testcase.setCustomFields(customFieldStr);
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
} finally {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
@ -735,8 +737,6 @@ public class TestCaseService {
|
|||
*/
|
||||
public void updateImportDataCarryId(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||
Map<String, String> nodePathMap = testCaseNodeService.createNodeByTestCases(testCases, projectId);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
|
||||
/*
|
||||
获取用例的“网页上所显示id”与“数据库ID”映射。
|
||||
|
@ -751,19 +751,21 @@ public class TestCaseService {
|
|||
Map<Integer, String> numIdMap = testCasesList.stream()
|
||||
.collect(Collectors.toMap(TestCase::getNum, TestCase::getId));
|
||||
|
||||
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
testCases.forEach(testcase -> {
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
testcase.setId(numIdMap.get(testcase.getNum()));
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
try {
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
testCases.forEach(testcase -> {
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
testcase.setId(numIdMap.get(testcase.getNum()));
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
} finally {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
@ -777,8 +779,6 @@ public class TestCaseService {
|
|||
*/
|
||||
public void updateImportDataCustomId(List<TestCaseWithBLOBs> testCases, String projectId) {
|
||||
Map<String, String> nodePathMap = testCaseNodeService.createNodeByTestCases(testCases, projectId);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
|
||||
/*
|
||||
获取用例的“网页上所显示id”与“数据库ID”映射。
|
||||
|
@ -793,19 +793,21 @@ public class TestCaseService {
|
|||
Map<String, String> customIdMap = testCasesList.stream()
|
||||
.collect(Collectors.toMap(TestCase::getCustomNum, TestCase::getId, (k1,k2) -> k1));
|
||||
|
||||
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
testCases.forEach(testcase -> {
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
testcase.setId(customIdMap.get(testcase.getCustomNum()));
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
try {
|
||||
if (!testCases.isEmpty()) {
|
||||
AtomicInteger sort = new AtomicInteger();
|
||||
testCases.forEach(testcase -> {
|
||||
testcase.setUpdateTime(System.currentTimeMillis());
|
||||
testcase.setNodeId(nodePathMap.get(testcase.getNodePath()));
|
||||
testcase.setSort(sort.getAndIncrement());
|
||||
testcase.setId(customIdMap.get(testcase.getCustomNum()));
|
||||
mapper.updateByPrimaryKeySelective(testcase);
|
||||
});
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
} finally {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
@ -2125,4 +2127,38 @@ public class TestCaseService {
|
|||
List<TestCaseFollow> follows = testCaseFollowMapper.selectByExample(example);
|
||||
return follows.stream().map(TestCaseFollow::getFollowId).distinct().collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<TestCaseWithBLOBs> getTestCasesWithBLOBs(List<String> ids) {
|
||||
TestCaseExample example = new TestCaseExample();
|
||||
example.createCriteria().andIdIn(ids);
|
||||
return testCaseMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
|
||||
public void copyTestCaseBath(TestCaseBatchRequest request) {
|
||||
ServiceUtils.getSelectAllIds(request, request.getCondition(),
|
||||
(query) -> extTestCaseMapper.selectIds(query));
|
||||
List<String> ids = request.getIds();
|
||||
if (CollectionUtils.isEmpty(ids)) return;
|
||||
List<TestCaseWithBLOBs> testCases = getTestCasesWithBLOBs(ids);
|
||||
SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH);
|
||||
TestCaseMapper mapper = sqlSession.getMapper(TestCaseMapper.class);
|
||||
Long nextOrder = ServiceUtils.getNextOrder(request.getProjectId(), extTestCaseMapper::getLastOrder);
|
||||
|
||||
try {
|
||||
for (int i = 0; i < testCases.size(); i++) {
|
||||
TestCaseWithBLOBs testCase = testCases.get(i);
|
||||
testCase.setId(UUID.randomUUID().toString());
|
||||
testCase.setName(testCase.getName() + "_" + testCase.getId().substring(0, 5));
|
||||
testCase.setNodeId(request.getNodeId());
|
||||
testCase.setNodePath(request.getNodePath());
|
||||
testCase.setOrder(nextOrder += ServiceUtils.ORDER_STEP);
|
||||
mapper.insert(testCase);
|
||||
if (i % 50 == 0)
|
||||
sqlSession.flushStatements();
|
||||
}
|
||||
sqlSession.flushStatements();
|
||||
} finally {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ public class TestPlanLoadCaseService {
|
|||
t.setLoadConfiguration(loadTest.getLoadConfiguration());
|
||||
t.setAdvancedConfiguration(loadTest.getAdvancedConfiguration());
|
||||
}
|
||||
nextOrder += 5000;
|
||||
nextOrder += ServiceUtils.ORDER_STEP;
|
||||
testPlanLoadCaseMapper.insert(t);
|
||||
}
|
||||
|
||||
|
|
|
@ -286,6 +286,7 @@ export default {
|
|||
tableLabel: [],
|
||||
deletePath: "/test/case/delete",
|
||||
enableOrderDrag: true,
|
||||
isMoveBatch: true,
|
||||
condition: {
|
||||
components: TEST_CASE_CONFIGS,
|
||||
filters: {}
|
||||
|
@ -322,11 +323,18 @@ export default {
|
|||
name: this.$t('test_track.case.batch_edit_case'),
|
||||
handleClick: this.handleBatchEdit,
|
||||
permissions: ['PROJECT_TRACK_CASE:READ+EDIT']
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: this.$t('test_track.case.batch_move_case'),
|
||||
handleClick: this.handleBatchMove,
|
||||
permissions: ['PROJECT_TRACK_CASE:READ+EDIT']
|
||||
}, {
|
||||
},
|
||||
{
|
||||
name: this.$t('api_test.batch_copy'),
|
||||
handleClick: this.handleBatchCopy,
|
||||
permissions: ['PROJECT_TRACK_CASE:READ+EDIT']
|
||||
},
|
||||
{
|
||||
name: this.$t('test_track.case.batch_delete_case'),
|
||||
handleClick: this.handleDeleteBatchToGc,
|
||||
permissions: ['PROJECT_TRACK_CASE:READ+DELETE']
|
||||
|
@ -884,6 +892,11 @@ export default {
|
|||
this.$refs.batchEdit.open(this.$refs.table.selectRows.size);
|
||||
},
|
||||
handleBatchMove() {
|
||||
this.isMoveBatch = true;
|
||||
this.$refs.testBatchMove.open(this.treeNodes, this.$refs.table.selectIds, this.moduleOptions);
|
||||
},
|
||||
handleBatchCopy() {
|
||||
this.isMoveBatch = false;
|
||||
this.$refs.testBatchMove.open(this.treeNodes, this.$refs.table.selectIds, this.moduleOptions);
|
||||
},
|
||||
getMaintainerOptions() {
|
||||
|
@ -893,7 +906,10 @@ export default {
|
|||
},
|
||||
moveSave(param) {
|
||||
param.condition = this.condition;
|
||||
this.page.result = this.$post('/test/case/batch/edit', param, () => {
|
||||
let url = '/test/case/batch/edit';
|
||||
if (!this.isMoveBatch)
|
||||
url = '/test/case/batch/copy';
|
||||
this.page.result = this.$post(url, param, () => {
|
||||
this.$success(this.$t('commons.save_success'));
|
||||
this.$refs.testBatchMove.close();
|
||||
this.refresh();
|
||||
|
|
Loading…
Reference in New Issue