修改项目、计划、用例时判断名称重复

This commit is contained in:
chenjianxing 2020-05-29 13:47:40 +08:00
parent 9f7baf6dfb
commit 146a5cc385
3 changed files with 36 additions and 0 deletions

View File

@ -125,9 +125,21 @@ public class ProjectService {
public void updateProject(Project project) {
project.setCreateTime(null);
project.setUpdateTime(System.currentTimeMillis());
checkProjectExist(project);
projectMapper.updateByPrimaryKeySelective(project);
}
private void checkProjectExist (Project project) {
ProjectExample example = new ProjectExample();
example.createCriteria()
.andNameEqualTo(project.getName())
.andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
.andIdNotEqualTo(project.getId());
if (projectMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("project_name_already_exists"));
}
}
public List<Project> listAll() {
return projectMapper.selectByExample(null);
}

View File

@ -92,9 +92,21 @@ public class TestCaseService {
public int editTestCase(TestCaseWithBLOBs testCase) {
testCase.setUpdateTime(System.currentTimeMillis());
checkTestCaseExist(testCase);
return testCaseMapper.updateByPrimaryKeySelective(testCase);
}
private void checkTestCaseExist (TestCaseWithBLOBs testCase) {
TestCaseExample example = new TestCaseExample();
example.createCriteria()
.andNameEqualTo(testCase.getName())
.andProjectIdEqualTo(testCase.getProjectId())
.andIdNotEqualTo(testCase.getId());
if (testCaseMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("test_case_already_exists"));
}
}
public int deleteTestCase(String testCaseId) {
TestPlanTestCaseExample example = new TestPlanTestCaseExample();
example.createCriteria().andCaseIdEqualTo(testCaseId);

View File

@ -90,9 +90,21 @@ public class TestPlanService {
public int editTestPlan(TestPlan testPlan) {
testPlan.setUpdateTime(System.currentTimeMillis());
checkTestPlanExist(testPlan);
return testPlanMapper.updateByPrimaryKeySelective(testPlan);
}
private void checkTestPlanExist (TestPlan testPlan) {
TestPlanExample example = new TestPlanExample();
example.createCriteria()
.andNameEqualTo(testPlan.getName())
.andWorkspaceIdEqualTo(SessionUtils.getCurrentWorkspaceId())
.andIdNotEqualTo(testPlan.getId());
if (testPlanMapper.selectByExample(example).size() > 0) {
MSException.throwException(Translator.get("plan_name_already_exists"));
}
}
public int deleteTestPlan(String planId) {
deleteTestCaseByPlanId(planId);
return testPlanMapper.deleteByPrimaryKey(planId);