diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TestResourcePoolDTO.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TestResourcePoolDTO.java index b0d73972aa..71060fc249 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TestResourcePoolDTO.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/TestResourcePoolDTO.java @@ -6,4 +6,7 @@ import lombok.Data; @Data public class TestResourcePoolDTO extends TestResourcePool { private TestResourceDTO testResourceDTO; + + private Boolean inUsed; + } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java index 3b716e6817..4eabcc2914 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/service/TestResourcePoolService.java @@ -7,10 +7,7 @@ import io.metersphere.sdk.dto.TestResourceDTO; import io.metersphere.sdk.dto.TestResourcePoolDTO; import io.metersphere.sdk.exception.MSException; import io.metersphere.sdk.util.*; -import io.metersphere.system.domain.TestResourcePool; -import io.metersphere.system.domain.TestResourcePoolBlob; -import io.metersphere.system.domain.TestResourcePoolExample; -import io.metersphere.system.domain.TestResourcePoolOrganization; +import io.metersphere.system.domain.*; import io.metersphere.system.mapper.TestResourcePoolBlobMapper; import io.metersphere.system.mapper.TestResourcePoolMapper; import io.metersphere.system.mapper.TestResourcePoolOrganizationMapper; @@ -38,6 +35,8 @@ public class TestResourcePoolService { @Resource private TestResourcePoolBlobMapper testResourcePoolBlobMapper; @Resource + private TestResourcePoolOrganizationMapper testResourcePoolOrganizationMapper; + @Resource private SqlSessionFactory sqlSessionFactory; @@ -154,12 +153,20 @@ public class TestResourcePoolService { if (testResourcePool == null) { throw new MSException(Translator.get("test_resource_pool_not_exists")); } + //删除与组织的关系 + deleteOrgRelation(testResourcePoolId); testResourcePool.setUpdateTime(System.currentTimeMillis()); testResourcePool.setEnable(false); testResourcePool.setDeleted(true); testResourcePoolMapper.updateByPrimaryKeySelective(testResourcePool); } + private void deleteOrgRelation(String testResourcePoolId) { + TestResourcePoolOrganizationExample testResourcePoolOrganizationExample = new TestResourcePoolOrganizationExample(); + testResourcePoolOrganizationExample.createCriteria().andTestResourcePoolIdEqualTo(testResourcePoolId); + testResourcePoolOrganizationMapper.deleteByExample(testResourcePoolOrganizationExample); + } + public void updateTestResourcePool(TestResourcePoolDTO testResourcePool) { checkTestResourcePool(testResourcePool); testResourcePool.setUpdateTime(System.currentTimeMillis()); @@ -192,6 +199,12 @@ public class TestResourcePoolService { TestResourcePoolDTO testResourcePoolDTO = new TestResourcePoolDTO(); BeanUtils.copyBean(testResourcePoolDTO, pool); testResourcePoolDTO.setTestResourceDTO(testResourceDTO); + TestResourcePoolOrganizationExample testResourcePoolOrganizationExample = new TestResourcePoolOrganizationExample(); + testResourcePoolOrganizationExample.createCriteria().andTestResourcePoolIdEqualTo(pool.getId()); + List testResourcePoolOrganizations = testResourcePoolOrganizationMapper.selectByExample(testResourcePoolOrganizationExample); + if (pool.getAllOrg() || CollectionUtils.isNotEmpty(testResourcePoolOrganizations)) { + testResourcePoolDTO.setInUsed(true); + } testResourcePoolDTOS.add(testResourcePoolDTO); }); return testResourcePoolDTOS;