@ -17,8 +17,6 @@
package org.apache.dolphinscheduler.api.service ;
package org.apache.dolphinscheduler.api.service ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.utils.PageInfo ;
import org.apache.dolphinscheduler.api.utils.PageInfo ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.Constants ;
@ -32,11 +30,20 @@ import org.apache.dolphinscheduler.dao.entity.User;
import org.apache.dolphinscheduler.dao.mapper.ProjectMapper ;
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.text.MessageFormat ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.HashSet ;
import java.util.List ;
import java.util.Map ;
import java.util.Set ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import org.springframework.stereotype.Service ;
import java.text.MessageFormat ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import java.util.* ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
/ * *
/ * *
* task instance service
* task instance service
@ -79,10 +86,10 @@ public class TaskInstanceService extends BaseService {
* @param pageSize page size
* @param pageSize page size
* @return task list page
* @return task list page
* /
* /
public Map < String , Object > queryTaskListPaging ( User loginUser , String projectName ,
public Map < String , Object > queryTaskListPaging ( User loginUser , String projectName ,
Integer processInstanceId , String taskName , String executorName , String startDate ,
Integer processInstanceId , String taskName , String executorName , String startDate ,
String endDate , String searchVal , ExecutionStatus stateType , String host ,
String endDate , String searchVal , ExecutionStatus stateType , String host ,
Integer pageNo , Integer pageSize ) {
Integer pageNo , Integer pageSize ) {
Map < String , Object > result = new HashMap < > ( ) ;
Map < String , Object > result = new HashMap < > ( ) ;
Project project = projectMapper . queryByName ( projectName ) ;
Project project = projectMapper . queryByName ( projectName ) ;
@ -93,23 +100,23 @@ public class TaskInstanceService extends BaseService {
}
}
int [ ] statusArray = null ;
int [ ] statusArray = null ;
if ( stateType ! = null ) {
if ( stateType ! = null ) {
statusArray = new int [ ] { stateType . ordinal ( ) } ;
statusArray = new int [ ] { stateType . ordinal ( ) } ;
}
}
Date start = null ;
Date start = null ;
Date end = null ;
Date end = null ;
try {
if ( StringUtils . isNotEmpty ( startDate ) ) {
if ( StringUtils . isNotEmpty ( startDate ) ) {
start = DateUtils . getScheduleDate ( startDate ) ;
start = DateUtils . getScheduleDate ( startDate ) ;
if ( start = = null ) {
return generateInvalidParamRes ( result , "startDate" ) ;
}
}
if ( StringUtils . isNotEmpty ( endDate ) ) {
}
end = DateUtils . getScheduleDate ( endDate ) ;
if ( StringUtils . isNotEmpty ( endDate ) ) {
end = DateUtils . getScheduleDate ( endDate ) ;
if ( end = = null ) {
return generateInvalidParamRes ( result , "endDate" ) ;
}
}
} catch ( Exception e ) {
result . put ( Constants . STATUS , Status . REQUEST_PARAMS_NOT_VALID_ERROR ) ;
result . put ( Constants . MSG , MessageFormat . format ( Status . REQUEST_PARAMS_NOT_VALID_ERROR . getMsg ( ) , "startDate,endDate" ) ) ;
return result ;
}
}
Page < TaskInstance > page = new Page ( pageNo , pageSize ) ;
Page < TaskInstance > page = new Page ( pageNo , pageSize ) ;
@ -124,18 +131,30 @@ public class TaskInstanceService extends BaseService {
exclusionSet . add ( "taskJson" ) ;
exclusionSet . add ( "taskJson" ) ;
List < TaskInstance > taskInstanceList = taskInstanceIPage . getRecords ( ) ;
List < TaskInstance > taskInstanceList = taskInstanceIPage . getRecords ( ) ;
for ( TaskInstance taskInstance : taskInstanceList ) {
for ( TaskInstance taskInstance : taskInstanceList ) {
taskInstance . setDuration ( DateUtils . differSec ( taskInstance . getStartTime ( ) , taskInstance . getEndTime ( ) ) ) ;
taskInstance . setDuration ( DateUtils . differSec ( taskInstance . getStartTime ( ) , taskInstance . getEndTime ( ) ) ) ;
User executor = usersService . queryUser ( taskInstance . getExecutorId ( ) ) ;
User executor = usersService . queryUser ( taskInstance . getExecutorId ( ) ) ;
if ( null ! = executor ) {
if ( null ! = executor ) {
taskInstance . setExecutorName ( executor . getUserName ( ) ) ;
taskInstance . setExecutorName ( executor . getUserName ( ) ) ;
}
}
}
}
pageInfo . setTotalCount ( ( int ) taskInstanceIPage . getTotal ( ) ) ;
pageInfo . setTotalCount ( ( int ) taskInstanceIPage . getTotal ( ) ) ;
pageInfo . setLists ( CollectionUtils . getListByExclusion ( taskInstanceIPage . getRecords ( ) , exclusionSet ) ) ;
pageInfo . setLists ( CollectionUtils . getListByExclusion ( taskInstanceIPage . getRecords ( ) , exclusionSet ) ) ;
result . put ( Constants . DATA_LIST , pageInfo ) ;
result . put ( Constants . DATA_LIST , pageInfo ) ;
putMsg ( result , Status . SUCCESS ) ;
putMsg ( result , Status . SUCCESS ) ;
return result ;
return result ;
}
}
/ * * *
* generate { @link org . apache . dolphinscheduler . api . enums . Status # REQUEST_PARAMS_NOT_VALID_ERROR } res with param name
* @param result exist result map
* @param params invalid params name
* @return update result map
* /
private Map < String , Object > generateInvalidParamRes ( Map < String , Object > result , String params ) {
result . put ( Constants . STATUS , Status . REQUEST_PARAMS_NOT_VALID_ERROR ) ;
result . put ( Constants . MSG , MessageFormat . format ( Status . REQUEST_PARAMS_NOT_VALID_ERROR . getMsg ( ) , params ) ) ;
return result ;
}
}
}