Skip to content

Commit

Permalink
Merge pull request #352 from caofengbin/feature/correlation_table_fix
Browse files Browse the repository at this point in the history
fix:删除项目时,有三个关联表的记录未处理,存在脏数据
  • Loading branch information
ZhouYixun authored May 14, 2023
2 parents 41b88bd + cda3f6f commit b3751b5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ public List<Steps> listStepsByElementsId(int elementsId) {

@Override
public boolean deleteByProjectId(int projectId) {
// 先删除steps_elements表中,属于该projectId下的"步骤-元素"关联记录
List<Steps> allSteps = stepsMapper.selectList(new LambdaQueryWrapper<Steps>().eq(Steps::getProjectId, projectId));
for (Steps curStep : allSteps) {
stepsElementsMapper.delete(new LambdaQueryWrapper<StepsElements>().eq(StepsElements::getStepsId, curStep.getId()));
}
// 再删除指定projectId的Step
return baseMapper.delete(new LambdaQueryWrapper<Steps>().eq(Steps::getProjectId, projectId)) > 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,11 @@ public JSONObject handleSteps(StepsDTO steps) {

@Override
public boolean delete(int id) {
// 先删除 test_suites_test_cases 以及 test_suites_devices 两表中的记录
testSuitesTestCasesMapper.delete(new LambdaQueryWrapper<TestSuitesTestCases>()
.eq(TestSuitesTestCases::getTestSuitesId, id));
testSuitesDevicesMapper.delete(new LambdaQueryWrapper<TestSuitesDevices>()
.eq(TestSuitesDevices::getTestSuitesId, id));
return baseMapper.deleteById(id) > 0;
}

Expand Down Expand Up @@ -436,7 +441,17 @@ public List<TestSuitesDTO> findByProjectId(int projectId) {

@Override
public boolean deleteByProjectId(int projectId) {
return baseMapper.delete(new LambdaQueryWrapper<TestSuites>().eq(TestSuites::getProjectId, projectId)) > 0;
List<TestSuites> testSuitesList = baseMapper.selectList(
new LambdaQueryWrapper<TestSuites>().eq(TestSuites::getProjectId, projectId));
if (testSuitesList != null && !testSuitesList.isEmpty()) {
return testSuitesList.stream()
.map(TestSuites::getId)
.map(this::delete)
.reduce(true, Boolean::logicalAnd);
} else {
// 如果查询到的list不会null,但是数量为0,说明本身不存在测试套件,直接返回true。
return testSuitesList != null;
}
}

@Override
Expand Down

0 comments on commit b3751b5

Please sign in to comment.