fix: 复制测试计划报错

This commit is contained in:
chenjianxing 2021-09-18 12:57:52 +08:00 committed by jianxing
parent 33cd145d14
commit fddaebdef6
1 changed files with 66 additions and 45 deletions

View File

@ -1263,9 +1263,12 @@ public class TestPlanService {
TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample(); TestPlanTestCaseExample testPlanTestCaseExample = new TestPlanTestCaseExample();
testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId); testPlanTestCaseExample.createCriteria().andPlanIdEqualTo(sourcePlanId);
List<TestPlanTestCase> testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample); List<TestPlanTestCase> testPlanTestCases = testPlanTestCaseMapper.selectByExample(testPlanTestCaseExample);
try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) { try (SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH)) {
TestPlanTestCaseMapper testCaseMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class); TestPlanTestCaseMapper testCaseMapper = sqlSession.getMapper(TestPlanTestCaseMapper.class);
testPlanTestCases.forEach(testCase -> { if (!CollectionUtils.isEmpty(testPlanTestCases)) {
Long nextTestCaseOrder = ServiceUtils.getNextOrder(targetPlanId, extTestPlanTestCaseMapper::getLastOrder);
for (TestPlanTestCase testCase : testPlanTestCases) {
TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs(); TestPlanTestCaseWithBLOBs testPlanTestCase = new TestPlanTestCaseWithBLOBs();
testPlanTestCase.setId(UUID.randomUUID().toString()); testPlanTestCase.setId(UUID.randomUUID().toString());
testPlanTestCase.setPlanId(targetPlanId); testPlanTestCase.setPlanId(targetPlanId);
@ -1276,15 +1279,20 @@ public class TestPlanService {
testPlanTestCase.setUpdateTime(System.currentTimeMillis()); testPlanTestCase.setUpdateTime(System.currentTimeMillis());
testPlanTestCase.setCreateUser(SessionUtils.getUserId()); testPlanTestCase.setCreateUser(SessionUtils.getUserId());
testPlanTestCase.setRemark(testCase.getRemark()); testPlanTestCase.setRemark(testCase.getRemark());
testPlanTestCase.setOrder(nextTestCaseOrder);
nextTestCaseOrder += 5000;
testCaseMapper.insert(testPlanTestCase); testCaseMapper.insert(testPlanTestCase);
}); }
}
sqlSession.flushStatements(); sqlSession.flushStatements();
TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample(); TestPlanApiCaseExample testPlanApiCaseExample = new TestPlanApiCaseExample();
testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId); testPlanApiCaseExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample); List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(testPlanApiCaseExample);
TestPlanApiCaseMapper apiCaseMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class); TestPlanApiCaseMapper apiCaseMapper = sqlSession.getMapper(TestPlanApiCaseMapper.class);
testPlanApiCases.forEach(apiCase -> { if (!CollectionUtils.isEmpty(testPlanApiCases)) {
Long nextApiOrder = ServiceUtils.getNextOrder(targetPlanId, extTestPlanApiCaseMapper::getLastOrder);
for (TestPlanApiCase apiCase : testPlanApiCases) {
TestPlanApiCase api = new TestPlanApiCase(); TestPlanApiCase api = new TestPlanApiCase();
api.setId(UUID.randomUUID().toString()); api.setId(UUID.randomUUID().toString());
api.setTestPlanId(targetPlanId); api.setTestPlanId(targetPlanId);
@ -1293,15 +1301,20 @@ public class TestPlanService {
api.setCreateTime(System.currentTimeMillis()); api.setCreateTime(System.currentTimeMillis());
api.setUpdateTime(System.currentTimeMillis()); api.setUpdateTime(System.currentTimeMillis());
api.setCreateUser(SessionUtils.getUserId()); api.setCreateUser(SessionUtils.getUserId());
api.setOrder(nextApiOrder);
nextApiOrder += 5000;
apiCaseMapper.insert(api); apiCaseMapper.insert(api);
}); }
}
sqlSession.flushStatements(); sqlSession.flushStatements();
TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample(); TestPlanApiScenarioExample testPlanApiScenarioExample = new TestPlanApiScenarioExample();
testPlanApiScenarioExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId); testPlanApiScenarioExample.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
List<TestPlanApiScenario> apiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(testPlanApiScenarioExample); List<TestPlanApiScenario> apiScenarios = testPlanApiScenarioMapper.selectByExampleWithBLOBs(testPlanApiScenarioExample);
TestPlanApiScenarioMapper apiScenarioMapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class); TestPlanApiScenarioMapper apiScenarioMapper = sqlSession.getMapper(TestPlanApiScenarioMapper.class);
apiScenarios.forEach(apiScenario -> { if (!CollectionUtils.isEmpty(apiScenarios)) {
Long nextScenarioOrder = ServiceUtils.getNextOrder(targetPlanId, extTestPlanScenarioCaseMapper::getLastOrder);
for (TestPlanApiScenario apiScenario : apiScenarios) {
TestPlanApiScenario planScenario = new TestPlanApiScenario(); TestPlanApiScenario planScenario = new TestPlanApiScenario();
planScenario.setId(UUID.randomUUID().toString()); planScenario.setId(UUID.randomUUID().toString());
planScenario.setTestPlanId(targetPlanId); planScenario.setTestPlanId(targetPlanId);
@ -1310,15 +1323,20 @@ public class TestPlanService {
planScenario.setCreateTime(System.currentTimeMillis()); planScenario.setCreateTime(System.currentTimeMillis());
planScenario.setUpdateTime(System.currentTimeMillis()); planScenario.setUpdateTime(System.currentTimeMillis());
planScenario.setCreateUser(SessionUtils.getUserId()); planScenario.setCreateUser(SessionUtils.getUserId());
planScenario.setOrder(nextScenarioOrder);
nextScenarioOrder += 5000;
apiScenarioMapper.insert(planScenario); apiScenarioMapper.insert(planScenario);
}); }
}
sqlSession.flushStatements(); sqlSession.flushStatements();
TestPlanLoadCaseExample example = new TestPlanLoadCaseExample(); TestPlanLoadCaseExample example = new TestPlanLoadCaseExample();
example.createCriteria().andTestPlanIdEqualTo(sourcePlanId); example.createCriteria().andTestPlanIdEqualTo(sourcePlanId);
List<TestPlanLoadCase> loadCases = testPlanLoadCaseMapper.selectByExample(example); List<TestPlanLoadCase> loadCases = testPlanLoadCaseMapper.selectByExample(example);
TestPlanLoadCaseMapper mapper = sqlSession.getMapper(TestPlanLoadCaseMapper.class); TestPlanLoadCaseMapper mapper = sqlSession.getMapper(TestPlanLoadCaseMapper.class);
loadCases.forEach(loadCase -> { if (!CollectionUtils.isEmpty(loadCases)) {
Long nextLoadOrder = ServiceUtils.getNextOrder(targetPlanId, extTestPlanLoadCaseMapper::getLastOrder);
for (TestPlanLoadCase loadCase : loadCases) {
TestPlanLoadCase load = new TestPlanLoadCase(); TestPlanLoadCase load = new TestPlanLoadCase();
load.setId(UUID.randomUUID().toString()); load.setId(UUID.randomUUID().toString());
load.setTestPlanId(targetPlanId); load.setTestPlanId(targetPlanId);
@ -1326,8 +1344,11 @@ public class TestPlanService {
load.setCreateTime(System.currentTimeMillis()); load.setCreateTime(System.currentTimeMillis());
load.setUpdateTime(System.currentTimeMillis()); load.setUpdateTime(System.currentTimeMillis());
load.setCreateUser(SessionUtils.getUserId()); load.setCreateUser(SessionUtils.getUserId());
load.setOrder(nextLoadOrder);
mapper.insert(load); mapper.insert(load);
}); nextLoadOrder += 5000;
}
}
sqlSession.flushStatements(); sqlSession.flushStatements();
} }
} }