diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java index 06b8eacf1b..9241df6d71 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectServiceImpl.java @@ -24,6 +24,7 @@ import org.apache.dolphinscheduler.api.service.ProjectService; import org.apache.dolphinscheduler.api.utils.PageInfo; import org.apache.dolphinscheduler.common.Constants; import org.apache.dolphinscheduler.common.enums.UserType; +import org.apache.dolphinscheduler.common.utils.CollectionUtils; import org.apache.dolphinscheduler.dao.entity.ProcessDefinition; import org.apache.dolphinscheduler.dao.entity.Project; import org.apache.dolphinscheduler.dao.entity.ProjectUser; @@ -442,21 +443,13 @@ public class ProjectServiceImpl extends BaseService implements ProjectService { */ public Map queryAllProjectList() { Map result = new HashMap<>(); - List projects = projectMapper.selectList(null); - List processDefinitions = processDefinitionMapper.selectList(null); - if (projects != null) { - Set set = new HashSet<>(); - for (ProcessDefinition processDefinition : processDefinitions) { - set.add(processDefinition.getProjectId()); - } - List tempDeletelist = new ArrayList<>(); - for (Project project : projects) { - if (!set.contains(project.getId())) { - tempDeletelist.add(project); - } - } - projects.removeAll(tempDeletelist); + List projects = new ArrayList<>(); + + List projectIds = processDefinitionMapper.listProjectIds(); + if (CollectionUtils.isNotEmpty(projectIds)) { + projects = projectMapper.selectBatchIds(projectIds); } + result.put(Constants.DATA_LIST, projects); putMsg(result, Status.SUCCESS); return result; diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java index cc39925aa5..076eb59b27 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProjectServiceTest.java @@ -32,6 +32,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ProjectUserMapper; import java.util.ArrayList; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -319,9 +320,8 @@ public class ProjectServiceTest { @Test public void testQueryAllProjectList() { - - Mockito.when(projectMapper.selectList(null)).thenReturn(getList()); - Mockito.when(processDefinitionMapper.selectList(null)).thenReturn(getProcessDefinitions()); + Mockito.when(processDefinitionMapper.listProjectIds()).thenReturn(getProjectIds()); + Mockito.when(projectMapper.selectBatchIds(getProjectIds())).thenReturn(getList()); Map result = projectService.queryAllProjectList(); logger.info(result.toString()); @@ -387,6 +387,11 @@ public class ProjectServiceTest { return list; } + private List getProjectIds() { + return Collections.singletonList(1); + } + + private String getDesc() { return "projectUserMapper.deleteProjectRelation(projectId,userId)projectUserMappe" + ".deleteProjectRelation(projectId,userId)projectUserMappe" diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java index 621ec43c27..36c988776f 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.java @@ -138,4 +138,10 @@ public interface ProcessDefinitionMapper extends BaseMapper { * @param version version */ void updateVersionByProcessDefinitionId(@Param("processDefinitionId") int processDefinitionId, @Param("version") long version); + + /** + * list all project ids + * @return project ids list + */ + List listProjectIds(); } diff --git a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml index 6a9165f076..a24fd294a7 100644 --- a/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml +++ b/dolphinscheduler-dao/src/main/resources/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapper.xml @@ -128,6 +128,12 @@ WHERE user_id = #{userId} and release_state = 1 and resource_ids is not null and resource_ids != '' + + + update t_ds_process_definition set version = #{version} diff --git a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java index 2046735221..02b5f12321 100644 --- a/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java +++ b/dolphinscheduler-dao/src/test/java/org/apache/dolphinscheduler/dao/mapper/ProcessDefinitionMapperTest.java @@ -366,4 +366,12 @@ public class ProcessDefinitionMapperTest { ProcessDefinition processDefinition1 = processDefinitionMapper.selectById(processDefinition.getId()); Assert.assertEquals(expectedVersion, processDefinition1.getVersion()); } + + @Test + public void listProjectIds() { + ProcessDefinition processDefinition = insertOne(); + List projectIds = processDefinitionMapper.listProjectIds(); + Assert.assertNotNull(projectIds); + } + }