@ -43,13 +43,14 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper ;
import org.apache.dolphinscheduler.dao.mapper.TaskInstanceMapper ;
import org.apache.dolphinscheduler.service.process.ProcessService ;
import org.apache.dolphinscheduler.service.process.ProcessService ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Arrays ;
import java.util.Date ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.List ;
import java.util.List ;
import java.util.Map ;
import java.util.Map ;
import java.util.Objects ;
import java.util.Objects ;
import java.util.Set ;
import java.util.stream.Collectors ;
import java.util.stream.Collectors ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
@ -148,8 +149,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
}
}
}
}
Project project = projectMapper . selectById ( projectId ) ;
Long [ ] projectCodeArray = projectId = = 0 ? getProjectCodesArrays ( loginUser )
Long [ ] projectCodeArray = getProjectCodesArrays ( loginUser , project . getCode ( ) ) ;
: new Long [ ] { projectMapper . selectById ( projectId ) . getCode ( ) } ;
List < ExecuteStatusCount > processInstanceStateCounts =
List < ExecuteStatusCount > processInstanceStateCounts =
instanceStateCounter . apply ( start , end , projectCodeArray ) ;
instanceStateCounter . apply ( start , end , projectCodeArray ) ;
@ -172,9 +173,12 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
@Override
@Override
public Map < String , Object > countDefinitionByUser ( User loginUser , int projectId ) {
public Map < String , Object > countDefinitionByUser ( User loginUser , int projectId ) {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
boolean checkProject = checkProject ( loginUser , projectId , result ) ;
Project project = projectMapper . selectById ( projectId ) ;
if ( ! checkProject ) {
Long [ ] projectCodeArray = getProjectCodesArrays ( loginUser , project . getCode ( ) ) ;
return result ;
}
Long [ ] projectCodeArray = projectId = = 0 ? getProjectCodesArrays ( loginUser )
: new Long [ ] { projectMapper . selectById ( projectId ) . getCode ( ) } ;
List < DefinitionGroupByUser > defineGroupByUsers = processDefinitionMapper . countDefinitionGroupByUser (
List < DefinitionGroupByUser > defineGroupByUsers = processDefinitionMapper . countDefinitionGroupByUser (
loginUser . getId ( ) , projectCodeArray , isAdmin ( loginUser ) ) ;
loginUser . getId ( ) , projectCodeArray , isAdmin ( loginUser ) ) ;
@ -203,8 +207,6 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return result ;
return result ;
}
}
Project project = projectMapper . selectById ( projectId ) ;
/ * *
/ * *
* find all the task lists in the project under the user
* find all the task lists in the project under the user
* statistics based on task status execution , failure , completion , wait , total
* statistics based on task status execution , failure , completion , wait , total
@ -226,7 +228,8 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
}
}
}
}
Long [ ] projectCodeArray = getProjectCodesArrays ( loginUser , project . getCode ( ) ) ;
Long [ ] projectCodeArray = projectId = = 0 ? getProjectCodesArrays ( loginUser )
: new Long [ ] { projectMapper . selectById ( projectId ) . getCode ( ) } ;
// count normal command state
// count normal command state
Map < CommandType , Integer > normalCountCommandCounts = commandMapper . countCommandState ( loginUser . getId ( ) , start , end , projectCodeArray )
Map < CommandType , Integer > normalCountCommandCounts = commandMapper . countCommandState ( loginUser . getId ( ) , start , end , projectCodeArray )
. stream ( )
. stream ( )
@ -249,15 +252,14 @@ public class DataAnalysisServiceImpl extends BaseServiceImpl implements DataAnal
return result ;
return result ;
}
}
private Long [ ] getProjectCodesArrays ( User loginUser , Long projectCode ) {
private Long [ ] getProjectCodesArrays ( User loginUser ) {
List < Long > projectCodes = new ArrayList < > ( ) ;
List < Project > projectList = projectMapper . queryRelationProjectListByUserId (
if ( projectCode ! = 0 ) {
loginUser . getUserType ( ) = = UserType . ADMIN_USER ? 0 : loginUser . getId ( ) ) ;
projectCodes . add ( projectCode ) ;
Set < Long > projectCodes = new HashSet < > ( ) ;
} else if ( loginUser . getUserType ( ) = = UserType . GENERAL_USER ) {
projectList . forEach ( project - > projectCodes . add ( project . getCode ( ) ) ) ;
projectCodes = processService . getProjectIdListHavePerm ( loginUser . getId ( ) ) ;
if ( loginUser . getUserType ( ) = = UserType . GENERAL_USER ) {
if ( projectCodes . isEmpty ( ) ) {
List < Project > createProjects = projectMapper . queryProjectCreatedByUser ( loginUser . getId ( ) ) ;
projectCodes . add ( 0L ) ;
createProjects . forEach ( project - > projectCodes . add ( project . getCode ( ) ) ) ;
}
}
}
return projectCodes . toArray ( new Long [ 0 ] ) ;
return projectCodes . toArray ( new Long [ 0 ] ) ;
}
}