diff --git a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java index f6c331d249..741224039b 100644 --- a/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java +++ b/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProcessDefinitionServiceImpl.java @@ -162,6 +162,7 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.fasterxml.jackson.databind.JsonNode; @@ -593,12 +594,15 @@ public class ProcessDefinitionServiceImpl extends BaseServiceImpl implements Pro .stream() .collect(Collectors.toMap(Schedule::getProcessDefinitionCode, Function.identity())); + Map userMap = userMapper.selectList(new QueryWrapper<>()).stream() + .collect(Collectors.toMap(User::getId, User::getUserName)); + for (ProcessDefinition pd : processDefinitions) { // todo: use batch query ProcessDefinitionLog processDefinitionLog = processDefinitionLogMapper.queryByDefinitionCodeAndVersion(pd.getCode(), pd.getVersion()); - User user = userMapper.selectById(processDefinitionLog.getOperator()); - pd.setModifyBy(user.getUserName()); + pd.setModifyBy(userMap.get(processDefinitionLog.getOperator())); + pd.setUserName(userMap.get(pd.getUserId())); Schedule schedule = scheduleMap.get(pd.getCode()); pd.setScheduleReleaseState(schedule == null ? null : schedule.getReleaseState()); } diff --git a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java index 5ada289227..558bbdf39d 100644 --- a/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java +++ b/dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/service/ProcessDefinitionServiceTest.java @@ -67,6 +67,7 @@ import org.apache.dolphinscheduler.dao.mapper.ProjectMapper; import org.apache.dolphinscheduler.dao.mapper.ScheduleMapper; import org.apache.dolphinscheduler.dao.mapper.TaskDefinitionMapper; import org.apache.dolphinscheduler.dao.mapper.TenantMapper; +import org.apache.dolphinscheduler.dao.mapper.UserMapper; import org.apache.dolphinscheduler.dao.model.PageListingResult; import org.apache.dolphinscheduler.dao.repository.ProcessDefinitionDao; import org.apache.dolphinscheduler.dao.repository.TaskDefinitionLogDao; @@ -171,6 +172,9 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Mock private WorkFlowLineageService workFlowLineageService; + @Mock + private UserMapper userMapper; + protected User user; protected Exception exception; protected final static long projectCode = 1L; @@ -224,6 +228,7 @@ public class ProcessDefinitionServiceTest extends BaseServiceTestTool { @Test public void testQueryProcessDefinitionListPaging() { Mockito.when(projectMapper.queryByCode(projectCode)).thenReturn(getProject(projectCode)); + Mockito.when(userMapper.selectList(Mockito.any())).thenReturn(Lists.newArrayList()); Project project = getProject(projectCode); diff --git a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java index 27df7bd573..9304662342 100644 --- a/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java +++ b/dolphinscheduler-dao/src/main/java/org/apache/dolphinscheduler/dao/entity/ProcessDefinition.java @@ -121,7 +121,7 @@ public class ProcessDefinition { private int userId; /** - * user name + * create user name */ @TableField(exist = false) private String userName;