diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java index afacbd8ee4..5b159e717e 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiCaseService.java @@ -572,6 +572,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { * @param testPlanApiCaseList */ private void buildTestPlanApiCase(TestPlan testPlan, List apiTestCases, String collectionId, SessionUser user, List testPlanApiCaseList, List logDTOS) { + AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId)); apiTestCases.forEach(apiTestCase -> { TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); testPlanApiCase.setId(IDGenerator.nextStr()); @@ -581,7 +582,7 @@ public class TestPlanApiCaseService extends TestPlanResourceService { testPlanApiCase.setEnvironmentId(apiTestCase.getEnvironmentId()); testPlanApiCase.setCreateTime(System.currentTimeMillis()); testPlanApiCase.setCreateUser(user.getId()); - testPlanApiCase.setPos(getNextOrder(collectionId)); + testPlanApiCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS)); testPlanApiCase.setExecuteUser(apiTestCase.getCreateUser()); testPlanApiCaseList.add(testPlanApiCase); buildLog(logDTOS, testPlan, user, apiTestCase); @@ -741,9 +742,8 @@ public class TestPlanApiCaseService extends TestPlanResourceService { ids.forEach(id -> { TestPlanApiCase testPlanApiCase = new TestPlanApiCase(); testPlanApiCase.setId(id); - testPlanApiCase.setPos(nextOrder.get()); + testPlanApiCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS)); testPlanApiCase.setTestPlanCollectionId(targetCollectionId); - nextOrder.addAndGet(DEFAULT_NODE_INTERVAL_POS); testPlanApiCaseMapper.updateByPrimaryKeySelective(testPlanApiCase); }); sqlSession.flushStatements(); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java index e724e4fe89..a9c2648387 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanApiScenarioService.java @@ -210,6 +210,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { * @param testPlanApiScenarioList */ private void buildTestPlanApiScenario(TestPlan testPlan, List scenarios, String collectionId, SessionUser user, List testPlanApiScenarioList, List logDTOS) { + AtomicLong nextOrder = new AtomicLong(getNextOrder(collectionId)); scenarios.forEach(scenario -> { TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario(); testPlanApiScenario.setId(IDGenerator.nextStr()); @@ -220,7 +221,7 @@ public class TestPlanApiScenarioService extends TestPlanResourceService { testPlanApiScenario.setEnvironmentId(scenario.getEnvironmentId()); testPlanApiScenario.setCreateTime(System.currentTimeMillis()); testPlanApiScenario.setCreateUser(user.getId()); - testPlanApiScenario.setPos(getNextOrder(collectionId)); + testPlanApiScenario.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS)); testPlanApiScenario.setExecuteUser(scenario.getCreateUser()); testPlanApiScenarioList.add(testPlanApiScenario); buildLog(logDTOS, testPlan, user, scenario); diff --git a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java index a280555338..6b94b06b23 100644 --- a/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java +++ b/backend/services/test-plan/src/main/java/io/metersphere/plan/service/TestPlanFunctionalCaseService.java @@ -163,7 +163,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { public long getNextOrder(String collectionId) { Long maxPos = extTestPlanFunctionalCaseMapper.getMaxPosByCollectionId(collectionId); if (maxPos == null) { - return 0; + return DEFAULT_NODE_INTERVAL_POS; } else { return maxPos + DEFAULT_NODE_INTERVAL_POS; } @@ -762,6 +762,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { FunctionalCaseExample example = new FunctionalCaseExample(); example.createCriteria().andIdIn(functionalIds); List functionalCases = functionalCaseMapper.selectByExample(example); + AtomicLong nextOrder = new AtomicLong(getNextOrder(functional.getCollectionId())); Map collect = functionalCases.stream().collect(Collectors.toMap(FunctionalCase::getId, functionalCase -> functionalCase)); functionalIds.forEach(functionalId -> { FunctionalCase functionalCase = collect.get(functionalId); @@ -772,7 +773,7 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { testPlanFunctionalCase.setFunctionalCaseId(functionalId); testPlanFunctionalCase.setCreateUser(user.getId()); testPlanFunctionalCase.setCreateTime(System.currentTimeMillis()); - testPlanFunctionalCase.setPos(getNextOrder(functional.getCollectionId())); + testPlanFunctionalCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS)); testPlanFunctionalCase.setExecuteUser(functionalCase.getCreateUser()); testPlanFunctionalCase.setLastExecResult(ExecStatus.PENDING.name()); testPlanFunctionalCaseList.add(testPlanFunctionalCase); @@ -830,9 +831,8 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService { ids.forEach(id -> { TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase(); testPlanFunctionalCase.setId(id); - testPlanFunctionalCase.setPos(nextOrder.get()); + testPlanFunctionalCase.setPos(nextOrder.getAndAdd(DEFAULT_NODE_INTERVAL_POS)); testPlanFunctionalCase.setTestPlanCollectionId(targetCollectionId); - nextOrder.addAndGet(DEFAULT_NODE_INTERVAL_POS); functionalBatchMapper.updateByPrimaryKeySelective(testPlanFunctionalCase); }); sqlSession.flushStatements();