diff --git a/backend/src/main/java/io/metersphere/service/ProjectService.java b/backend/src/main/java/io/metersphere/service/ProjectService.java index 9bcee0e33a..95b64a776b 100644 --- a/backend/src/main/java/io/metersphere/service/ProjectService.java +++ b/backend/src/main/java/io/metersphere/service/ProjectService.java @@ -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 listAll() { return projectMapper.selectByExample(null); } diff --git a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java index 1edf70ce46..a2ff41200d 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestCaseService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestCaseService.java @@ -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); diff --git a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java index 2a92a3d023..ed18d8fa9b 100644 --- a/backend/src/main/java/io/metersphere/track/service/TestPlanService.java +++ b/backend/src/main/java/io/metersphere/track/service/TestPlanService.java @@ -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);