|
@@ -1,28 +1,32 @@
|
|
|
package cn.iocoder.yudao.module.bpm.convert.task;
|
|
|
|
|
|
-import cn.hutool.core.date.LocalDateTimeUtil;
|
|
|
+import cn.hutool.core.map.MapUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
|
|
-import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskDonePageItemRespVO;
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
|
|
|
-import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskTodoPageItemRespVO;
|
|
|
-import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
|
|
|
+import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
|
|
+import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
|
|
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
-import org.flowable.common.engine.impl.db.SuspensionState;
|
|
|
import org.flowable.engine.history.HistoricProcessInstance;
|
|
|
import org.flowable.engine.runtime.ProcessInstance;
|
|
|
import org.flowable.task.api.Task;
|
|
|
import org.flowable.task.api.history.HistoricTaskInstance;
|
|
|
-import org.mapstruct.*;
|
|
|
+import org.flowable.task.service.impl.persistence.entity.TaskEntityImpl;
|
|
|
+import org.mapstruct.Mapper;
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
|
|
|
-import java.util.Collections;
|
|
|
+import java.util.Date;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
|
|
|
|
|
/**
|
|
|
* Bpm 任务 Convert
|
|
@@ -34,138 +38,139 @@ public interface BpmTaskConvert {
|
|
|
|
|
|
BpmTaskConvert INSTANCE = Mappers.getMapper(BpmTaskConvert.class);
|
|
|
|
|
|
- /**
|
|
|
- * 复制对象
|
|
|
- *
|
|
|
- * @param source 源 要复制的对象
|
|
|
- * @param target 目标 复制到此对象
|
|
|
- * @param <T>
|
|
|
- *
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static <T> T copy(Object source, Class<T> target) {
|
|
|
- if (source == null || target == null) {
|
|
|
- return null;
|
|
|
- }
|
|
|
- try {
|
|
|
- T newInstance = target.getDeclaredConstructor().newInstance();
|
|
|
- BeanUtils.copyProperties(source, newInstance);
|
|
|
- return newInstance;
|
|
|
- } catch (Exception e) {
|
|
|
- throw new RuntimeException(e);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- default <T, K> List<K> copyList(List<T> source, Class<K> target) {
|
|
|
- if (null == source || source.isEmpty()) {
|
|
|
- return Collections.emptyList();
|
|
|
- }
|
|
|
- return source.stream().map(e -> copy(e, target)).collect(Collectors.toList());
|
|
|
- }
|
|
|
-
|
|
|
- default List<BpmTaskTodoPageItemRespVO> convertList1(List<Task> tasks,
|
|
|
- Map<String, ProcessInstance> processInstanceMap, Map<Long, AdminUserRespDTO> userMap) {
|
|
|
- return CollectionUtils.convertList(tasks, task -> {
|
|
|
- BpmTaskTodoPageItemRespVO respVO = convert1(task);
|
|
|
- ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId());
|
|
|
- if (processInstance != null) {
|
|
|
- AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
|
|
|
- respVO.setProcessInstance(convert(processInstance, startUser));
|
|
|
+ default PageResult<BpmTaskRespVO> buildTodoTaskPage(PageResult<Task> pageResult,
|
|
|
+ Map<String, ProcessInstance> processInstanceMap,
|
|
|
+ Map<Long, AdminUserRespDTO> userMap) {
|
|
|
+ return BeanUtils.toBean(pageResult, BpmTaskRespVO.class, taskVO -> {
|
|
|
+ ProcessInstance processInstance = processInstanceMap.get(taskVO.getProcessInstanceId());
|
|
|
+ if (processInstance == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
- return respVO;
|
|
|
+ taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class));
|
|
|
+ AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
|
|
|
+ taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, BpmProcessInstanceRespVO.User.class));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- @Mapping(source = "suspended", target = "suspensionState", qualifiedByName = "convertSuspendedToSuspensionState")
|
|
|
- @Mapping(target = "claimTime", expression = "java(bean.getClaimTime()==null?null: LocalDateTime.ofInstant(bean.getClaimTime().toInstant(),ZoneId.systemDefault()))")
|
|
|
- @Mapping(target = "createTime", expression = "java(bean.getCreateTime()==null?null:LocalDateTime.ofInstant(bean.getCreateTime().toInstant(),ZoneId.systemDefault()))")
|
|
|
- BpmTaskTodoPageItemRespVO convert1(Task bean);
|
|
|
-
|
|
|
- @Named("convertSuspendedToSuspensionState")
|
|
|
- default Integer convertSuspendedToSuspensionState(boolean suspended) {
|
|
|
- return suspended ? SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode();
|
|
|
- }
|
|
|
-
|
|
|
- default List<BpmTaskDonePageItemRespVO> convertList2(List<HistoricTaskInstance> tasks,
|
|
|
- Map<String, BpmTaskExtDO> bpmTaskExtDOMap, Map<String, HistoricProcessInstance> historicProcessInstanceMap,
|
|
|
- Map<Long, AdminUserRespDTO> userMap) {
|
|
|
- return CollectionUtils.convertList(tasks, task -> {
|
|
|
- BpmTaskDonePageItemRespVO respVO = convert2(task);
|
|
|
- BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId());
|
|
|
- copyTo(taskExtDO, respVO);
|
|
|
- HistoricProcessInstance processInstance = historicProcessInstanceMap.get(task.getProcessInstanceId());
|
|
|
+ default PageResult<BpmTaskRespVO> buildTaskPage(PageResult<HistoricTaskInstance> pageResult,
|
|
|
+ Map<String, HistoricProcessInstance> processInstanceMap,
|
|
|
+ Map<Long, AdminUserRespDTO> userMap,
|
|
|
+ Map<Long, DeptRespDTO> deptMap) {
|
|
|
+ List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(pageResult.getList(), task -> {
|
|
|
+ BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class);
|
|
|
+ taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task));
|
|
|
+ // 用户信息
|
|
|
+ AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(task.getAssignee()));
|
|
|
+ if (assignUser != null) {
|
|
|
+ taskVO.setAssigneeUser(BeanUtils.toBean(assignUser, BpmProcessInstanceRespVO.User.class));
|
|
|
+ findAndThen(deptMap, assignUser.getDeptId(), dept -> taskVO.getAssigneeUser().setDeptName(dept.getName()));
|
|
|
+ }
|
|
|
+ // 流程实例
|
|
|
+ HistoricProcessInstance processInstance = processInstanceMap.get(taskVO.getProcessInstanceId());
|
|
|
if (processInstance != null) {
|
|
|
AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
|
|
|
- respVO.setProcessInstance(convert(processInstance, startUser));
|
|
|
+ taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class));
|
|
|
+ taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, BpmProcessInstanceRespVO.User.class));
|
|
|
}
|
|
|
- return respVO;
|
|
|
+ return taskVO;
|
|
|
});
|
|
|
+ return new PageResult<>(taskVOList, pageResult.getTotal());
|
|
|
}
|
|
|
|
|
|
- BpmTaskDonePageItemRespVO convert2(HistoricTaskInstance bean);
|
|
|
+ default List<BpmTaskRespVO> buildTaskListByProcessInstanceId(List<HistoricTaskInstance> taskList,
|
|
|
+ HistoricProcessInstance processInstance,
|
|
|
+ Map<Long, BpmFormDO> formMap,
|
|
|
+ Map<Long, AdminUserRespDTO> userMap,
|
|
|
+ Map<Long, DeptRespDTO> deptMap) {
|
|
|
+ List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(taskList, task -> {
|
|
|
+ BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class);
|
|
|
+ taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task));
|
|
|
+ // 流程实例
|
|
|
+ AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
|
|
|
+ taskVO.setProcessInstance(BeanUtils.toBean(processInstance, BpmTaskRespVO.ProcessInstance.class));
|
|
|
+ taskVO.getProcessInstance().setStartUser(BeanUtils.toBean(startUser, BpmProcessInstanceRespVO.User.class));
|
|
|
+ // 表单信息
|
|
|
+ BpmFormDO form = MapUtil.get(formMap, NumberUtils.parseLong(task.getFormKey()), BpmFormDO.class);
|
|
|
+ if (form != null) {
|
|
|
+ taskVO.setFormId(form.getId()).setFormName(form.getName()).setFormConf(form.getConf())
|
|
|
+ .setFormFields(form.getFields()).setFormVariables(FlowableUtils.getTaskFormVariable(task));
|
|
|
+ }
|
|
|
+ // 用户信息
|
|
|
+ AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(task.getAssignee()));
|
|
|
+ if (assignUser != null) {
|
|
|
+ taskVO.setAssigneeUser(BeanUtils.toBean(assignUser, BpmProcessInstanceRespVO.User.class));
|
|
|
+ findAndThen(deptMap, assignUser.getDeptId(), dept -> taskVO.getAssigneeUser().setDeptName(dept.getName()));
|
|
|
+ }
|
|
|
+ AdminUserRespDTO ownerUser = userMap.get(NumberUtils.parseLong(task.getOwner()));
|
|
|
+ if (ownerUser != null) {
|
|
|
+ taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class));
|
|
|
+ findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName()));
|
|
|
+ }
|
|
|
+ return taskVO;
|
|
|
+ });
|
|
|
|
|
|
- @Mappings({@Mapping(source = "processInstance.id", target = "id"),
|
|
|
- @Mapping(source = "processInstance.name", target = "name"),
|
|
|
- @Mapping(source = "processInstance.startUserId", target = "startUserId"),
|
|
|
- @Mapping(source = "processInstance.processDefinitionId", target = "processDefinitionId"),
|
|
|
- @Mapping(source = "startUser.nickname", target = "startUserNickname")})
|
|
|
- BpmTaskTodoPageItemRespVO.ProcessInstance convert(ProcessInstance processInstance, AdminUserRespDTO startUser);
|
|
|
+ // 拼接父子关系
|
|
|
+ Map<String, List<BpmTaskRespVO>> childrenTaskMap = convertMultiMap(
|
|
|
+ filterList(taskVOList, r -> StrUtil.isNotEmpty(r.getParentTaskId())),
|
|
|
+ BpmTaskRespVO::getParentTaskId);
|
|
|
+ for (BpmTaskRespVO taskVO : taskVOList) {
|
|
|
+ taskVO.setChildren(childrenTaskMap.get(taskVO.getId()));
|
|
|
+ }
|
|
|
+ return filterList(taskVOList, r -> StrUtil.isEmpty(r.getParentTaskId()));
|
|
|
+ }
|
|
|
|
|
|
- default List<BpmTaskRespVO> convertList3(List<HistoricTaskInstance> tasks,
|
|
|
- Map<String, BpmTaskExtDO> bpmTaskExtDOMap, HistoricProcessInstance processInstance,
|
|
|
- Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
|
|
|
- return CollectionUtils.convertList(tasks, task -> {
|
|
|
- BpmTaskRespVO respVO = convert3(task);
|
|
|
- BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId());
|
|
|
- copyTo(taskExtDO, respVO);
|
|
|
- if (processInstance != null) {
|
|
|
- AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
|
|
|
- respVO.setProcessInstance(convert(processInstance, startUser));
|
|
|
- }
|
|
|
+ default List<BpmTaskRespVO> buildTaskListByParentTaskId(List<Task> taskList,
|
|
|
+ Map<Long, AdminUserRespDTO> userMap,
|
|
|
+ Map<Long, DeptRespDTO> deptMap) {
|
|
|
+ return convertList(taskList, task -> BeanUtils.toBean(task, BpmTaskRespVO.class, taskVO -> {
|
|
|
AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(task.getAssignee()));
|
|
|
if (assignUser != null) {
|
|
|
- respVO.setAssigneeUser(convert3(assignUser));
|
|
|
+ taskVO.setAssigneeUser(BeanUtils.toBean(assignUser, BpmProcessInstanceRespVO.User.class));
|
|
|
DeptRespDTO dept = deptMap.get(assignUser.getDeptId());
|
|
|
if (dept != null) {
|
|
|
- respVO.getAssigneeUser().setDeptName(dept.getName());
|
|
|
+ taskVO.getAssigneeUser().setDeptName(dept.getName());
|
|
|
}
|
|
|
}
|
|
|
- return respVO;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- @Mapping(source = "taskDefinitionKey", target = "definitionKey")
|
|
|
- BpmTaskRespVO convert3(HistoricTaskInstance bean);
|
|
|
-
|
|
|
- BpmTaskRespVO.User convert3(AdminUserRespDTO bean);
|
|
|
-
|
|
|
- @Mapping(target = "id", ignore = true)
|
|
|
- void copyTo(BpmTaskExtDO from, @MappingTarget BpmTaskDonePageItemRespVO to);
|
|
|
-
|
|
|
- @Mappings({@Mapping(source = "processInstance.id", target = "id"),
|
|
|
- @Mapping(source = "processInstance.name", target = "name"),
|
|
|
- @Mapping(source = "processInstance.startUserId", target = "startUserId"),
|
|
|
- @Mapping(source = "processInstance.processDefinitionId", target = "processDefinitionId"),
|
|
|
- @Mapping(source = "startUser.nickname", target = "startUserNickname")})
|
|
|
- BpmTaskTodoPageItemRespVO.ProcessInstance convert(HistoricProcessInstance processInstance,
|
|
|
- AdminUserRespDTO startUser);
|
|
|
-
|
|
|
- default BpmTaskExtDO convert2TaskExt(Task task) {
|
|
|
- BpmTaskExtDO taskExtDO = new BpmTaskExtDO().setTaskId(task.getId())
|
|
|
- .setAssigneeUserId(NumberUtils.parseLong(task.getAssignee())).setName(task.getName())
|
|
|
- .setProcessDefinitionId(task.getProcessDefinitionId()).setProcessInstanceId(task.getProcessInstanceId());
|
|
|
- taskExtDO.setCreateTime(LocalDateTimeUtil.of(task.getCreateTime()));
|
|
|
- return taskExtDO;
|
|
|
+ AdminUserRespDTO ownerUser = userMap.get(NumberUtils.parseLong(task.getOwner()));
|
|
|
+ if (ownerUser != null) {
|
|
|
+ taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class));
|
|
|
+ findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName()));
|
|
|
+ }
|
|
|
+ }));
|
|
|
}
|
|
|
|
|
|
default BpmMessageSendWhenTaskCreatedReqDTO convert(ProcessInstance processInstance, AdminUserRespDTO startUser,
|
|
|
- Task task) {
|
|
|
+ Task task) {
|
|
|
BpmMessageSendWhenTaskCreatedReqDTO reqDTO = new BpmMessageSendWhenTaskCreatedReqDTO();
|
|
|
reqDTO.setProcessInstanceId(processInstance.getProcessInstanceId())
|
|
|
- .setProcessInstanceName(processInstance.getName()).setStartUserId(startUser.getId())
|
|
|
- .setStartUserNickname(startUser.getNickname()).setTaskId(task.getId()).setTaskName(task.getName())
|
|
|
- .setAssigneeUserId(NumberUtils.parseLong(task.getAssignee()));
|
|
|
+ .setProcessInstanceName(processInstance.getName()).setStartUserId(startUser.getId())
|
|
|
+ .setStartUserNickname(startUser.getNickname()).setTaskId(task.getId()).setTaskName(task.getName())
|
|
|
+ .setAssigneeUserId(NumberUtils.parseLong(task.getAssignee()));
|
|
|
return reqDTO;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 将父任务的属性,拷贝到子任务(加签任务)
|
|
|
+ *
|
|
|
+ * 为什么不使用 mapstruct 映射?因为 TaskEntityImpl 还有很多其他属性,这里我们只设置我们需要的。
|
|
|
+ * 使用 mapstruct 会将里面嵌套的各个属性值都设置进去,会出现意想不到的问题。
|
|
|
+ *
|
|
|
+ * @param parentTask 父任务
|
|
|
+ * @param childTask 加签任务
|
|
|
+ */
|
|
|
+ default void copyTo(TaskEntityImpl parentTask, TaskEntityImpl childTask) {
|
|
|
+ childTask.setName(parentTask.getName());
|
|
|
+ childTask.setDescription(parentTask.getDescription());
|
|
|
+ childTask.setCategory(parentTask.getCategory());
|
|
|
+ childTask.setParentTaskId(parentTask.getId());
|
|
|
+ childTask.setProcessDefinitionId(parentTask.getProcessDefinitionId());
|
|
|
+ childTask.setProcessInstanceId(parentTask.getProcessInstanceId());
|
|
|
+// childTask.setExecutionId(parentTask.getExecutionId()); // TODO 芋艿:新加的,不太确定;尴尬,不加时,子任务不通过会失败(报错);加了,子任务审批通过会失败(报错)
|
|
|
+ childTask.setTaskDefinitionKey(parentTask.getTaskDefinitionKey());
|
|
|
+ childTask.setTaskDefinitionId(parentTask.getTaskDefinitionId());
|
|
|
+ childTask.setPriority(parentTask.getPriority());
|
|
|
+ childTask.setCreateTime(new Date());
|
|
|
+ childTask.setTenantId(parentTask.getTenantId());
|
|
|
+ }
|
|
|
+
|
|
|
}
|