|
|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
package org.dromara.workflow.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.convert.Convert;
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
|
|
@ -8,24 +9,26 @@ import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.dromara.common.core.domain.dto.UserDTO;
|
|
|
|
|
import org.dromara.common.core.service.DeptService;
|
|
|
|
|
import org.dromara.common.core.service.DictService;
|
|
|
|
|
import org.dromara.common.core.service.UserService;
|
|
|
|
|
import org.dromara.common.core.utils.DateUtils;
|
|
|
|
|
import org.dromara.common.core.utils.ServletUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StreamUtils;
|
|
|
|
|
import org.dromara.common.core.utils.StringUtils;
|
|
|
|
|
import org.dromara.warm.flow.core.dto.DefJson;
|
|
|
|
|
import org.dromara.warm.flow.core.dto.NodeJson;
|
|
|
|
|
import org.dromara.warm.flow.core.dto.PromptContent;
|
|
|
|
|
import org.dromara.warm.flow.core.enums.NodeType;
|
|
|
|
|
import org.dromara.warm.flow.core.utils.MapUtil;
|
|
|
|
|
import org.dromara.warm.flow.orm.entity.FlowHisTask;
|
|
|
|
|
import org.dromara.warm.flow.orm.mapper.FlowHisTaskMapper;
|
|
|
|
|
import org.dromara.warm.flow.ui.service.ChartExtService;
|
|
|
|
|
import org.dromara.workflow.common.ConditionalOnEnable;
|
|
|
|
|
import org.dromara.workflow.common.constant.FlowConstant;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 流程图提示信息
|
|
|
|
|
@ -41,6 +44,7 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
private final UserService userService;
|
|
|
|
|
private final DeptService deptService;
|
|
|
|
|
private final FlowHisTaskMapper flowHisTaskMapper;
|
|
|
|
|
private final DictService dictService;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置流程图提示信息
|
|
|
|
|
@ -51,7 +55,7 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
public void execute(DefJson defJson) {
|
|
|
|
|
// 临时修复 后续版本将通过defjson获取流程实例ID
|
|
|
|
|
String[] parts = ServletUtils.getRequest().getRequestURI().split("/");
|
|
|
|
|
Long instanceId = Long.valueOf(parts[parts.length - 1]);
|
|
|
|
|
Long instanceId = Convert.toLong(parts[parts.length - 1]);
|
|
|
|
|
|
|
|
|
|
// 根据流程实例ID查询所有相关的历史任务列表
|
|
|
|
|
List<FlowHisTask> flowHisTasks = this.getHisTaskGroupedByNode(instanceId);
|
|
|
|
|
@ -60,28 +64,25 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 按节点编号(nodeCode)对历史任务进行分组
|
|
|
|
|
Map<String, List<FlowHisTask>> groupedByNode = flowHisTasks.stream()
|
|
|
|
|
.collect(Collectors.groupingBy(FlowHisTask::getNodeCode));
|
|
|
|
|
Map<String, List<FlowHisTask>> groupedByNode = StreamUtils.groupByKey(flowHisTasks, FlowHisTask::getNodeCode);
|
|
|
|
|
|
|
|
|
|
// 批量查询所有审批人的用户信息
|
|
|
|
|
List<UserDTO> userDTOList = userService.selectListByIds(
|
|
|
|
|
flowHisTasks.stream()
|
|
|
|
|
.map(task -> Long.valueOf(task.getApprover()))
|
|
|
|
|
.distinct()
|
|
|
|
|
.collect(Collectors.toList())
|
|
|
|
|
);
|
|
|
|
|
List<UserDTO> userDTOList = userService.selectListByIds(StreamUtils.toList(flowHisTasks, e -> Convert.toLong(e.getApprover())));
|
|
|
|
|
|
|
|
|
|
// 将查询到的用户列表转换为以用户ID为key的映射
|
|
|
|
|
Map<Long, UserDTO> userMap = userDTOList.stream()
|
|
|
|
|
.collect(Collectors.toMap(UserDTO::getUserId, user -> user));
|
|
|
|
|
Map<Long, UserDTO> userMap = StreamUtils.toIdentityMap(userDTOList, UserDTO::getUserId);
|
|
|
|
|
|
|
|
|
|
Map<String, String> dictType = dictService.getAllDictByDictType(FlowConstant.WF_TASK_STATUS);
|
|
|
|
|
|
|
|
|
|
// 遍历流程定义中的每个节点,调用处理方法,将对应节点的任务列表及用户信息传入,生成扩展提示内容
|
|
|
|
|
for (NodeJson nodeJson : defJson.getNodeList()) {
|
|
|
|
|
// 获取当前节点对应的历史任务列表,如果没有则返回空列表避免空指针
|
|
|
|
|
List<FlowHisTask> taskList = groupedByNode.getOrDefault(nodeJson.getNodeCode(), Collections.emptyList());
|
|
|
|
|
|
|
|
|
|
List<FlowHisTask> taskList = groupedByNode.get(nodeJson.getNodeCode());
|
|
|
|
|
if (CollUtil.isEmpty(taskList)) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 处理当前节点的扩展信息,包括构建审批人提示内容等
|
|
|
|
|
this.processNodeExtInfo(nodeJson, taskList, userMap);
|
|
|
|
|
this.processNodeExtInfo(nodeJson, taskList, userMap, dictType);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -92,29 +93,49 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void initPromptContent(DefJson defJson) {
|
|
|
|
|
ChartExtService.super.initPromptContent(defJson);
|
|
|
|
|
// 为每个节点设置统一的提示框样式
|
|
|
|
|
defJson.getNodeList().forEach(nodeJson ->
|
|
|
|
|
nodeJson.getPromptContent()
|
|
|
|
|
.setDialogStyle(
|
|
|
|
|
Map.ofEntries(
|
|
|
|
|
Map.entry("position", "absolute"),
|
|
|
|
|
Map.entry("backgroundColor", "#fff"),
|
|
|
|
|
Map.entry("border", "1px solid #ccc"),
|
|
|
|
|
Map.entry("borderRadius", "4px"),
|
|
|
|
|
Map.entry("boxShadow", "0 2px 8px rgba(0, 0, 0, 0.15)"),
|
|
|
|
|
Map.entry("padding", "8px 12px"),
|
|
|
|
|
Map.entry("fontSize", "14px"),
|
|
|
|
|
Map.entry("zIndex", 1000),
|
|
|
|
|
Map.entry("maxWidth", "500px"),
|
|
|
|
|
Map.entry("overflowY", "visible"),
|
|
|
|
|
Map.entry("overflowX", "hidden"),
|
|
|
|
|
Map.entry("color", "#333"),
|
|
|
|
|
Map.entry("pointerEvents", "auto"),
|
|
|
|
|
Map.entry("scrollbarWidth", "thin")
|
|
|
|
|
defJson.setTopText("流程名称: " + defJson.getFlowName());
|
|
|
|
|
defJson.getNodeList().forEach(nodeJson -> {
|
|
|
|
|
nodeJson.setPromptContent(
|
|
|
|
|
new PromptContent()
|
|
|
|
|
// 提示信息
|
|
|
|
|
.setInfo(
|
|
|
|
|
CollUtil.newArrayList(
|
|
|
|
|
new PromptContent.InfoItem()
|
|
|
|
|
.setPrefix("任务名称: ")
|
|
|
|
|
.setContent(nodeJson.getNodeName())
|
|
|
|
|
.setContentStyle(Map.of(
|
|
|
|
|
"border", "1px solid #d1e9ff",
|
|
|
|
|
"backgroundColor", "#e8f4ff",
|
|
|
|
|
"padding", "4px 8px",
|
|
|
|
|
"borderRadius", "4px"
|
|
|
|
|
))
|
|
|
|
|
.setRowStyle(Map.of(
|
|
|
|
|
"fontWeight", "bold",
|
|
|
|
|
"margin", "0 0 6px 0",
|
|
|
|
|
"padding", "0 0 8px 0",
|
|
|
|
|
"borderBottom", "1px solid #ccc"
|
|
|
|
|
))
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
// 弹窗样式
|
|
|
|
|
.setDialogStyle(MapUtil.mergeAll(
|
|
|
|
|
"position", "absolute",
|
|
|
|
|
"backgroundColor", "#fff",
|
|
|
|
|
"border", "1px solid #ccc",
|
|
|
|
|
"borderRadius", "4px",
|
|
|
|
|
"boxShadow", "0 2px 8px rgba(0, 0, 0, 0.15)",
|
|
|
|
|
"padding", "8px 12px",
|
|
|
|
|
"fontSize", "14px",
|
|
|
|
|
"zIndex", "1000",
|
|
|
|
|
"maxWidth", "500px",
|
|
|
|
|
"overflowY", "visible",
|
|
|
|
|
"overflowX", "hidden",
|
|
|
|
|
"color", "#333",
|
|
|
|
|
"pointerEvents", "auto",
|
|
|
|
|
"scrollbarWidth", "thin"
|
|
|
|
|
))
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -123,23 +144,20 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
* @param nodeJson 当前节点对象
|
|
|
|
|
* @param taskList 当前节点对应的历史审批任务列表
|
|
|
|
|
*/
|
|
|
|
|
private void processNodeExtInfo(NodeJson nodeJson, List<FlowHisTask> taskList, Map<Long, UserDTO> userMap) {
|
|
|
|
|
if (CollUtil.isEmpty(taskList)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
private void processNodeExtInfo(NodeJson nodeJson, List<FlowHisTask> taskList, Map<Long, UserDTO> userMap, Map<String, String> dictType) {
|
|
|
|
|
|
|
|
|
|
// 获取节点提示内容对象中的 info 列表,用于追加提示项
|
|
|
|
|
List<PromptContent.InfoItem> info = nodeJson.getPromptContent().getInfo();
|
|
|
|
|
|
|
|
|
|
// 遍历所有任务记录,构建提示内容
|
|
|
|
|
for (FlowHisTask task : taskList) {
|
|
|
|
|
UserDTO userDTO = userMap.get(Long.valueOf(task.getApprover()));
|
|
|
|
|
UserDTO userDTO = userMap.get(Convert.toLong(task.getApprover()));
|
|
|
|
|
if (ObjectUtil.isEmpty(userDTO)) {
|
|
|
|
|
return;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 查询用户所属部门名称
|
|
|
|
|
String deptName = deptService.selectDeptNameByIds(String.valueOf(userDTO.getDeptId()));
|
|
|
|
|
String deptName = deptService.selectDeptNameByIds(Convert.toStr(userDTO.getDeptId()));
|
|
|
|
|
|
|
|
|
|
// 添加标题项,如:👤 张三(市场部)
|
|
|
|
|
info.add(new PromptContent.InfoItem()
|
|
|
|
|
@ -157,6 +175,7 @@ public class FlwChartExtServiceImpl implements ChartExtService {
|
|
|
|
|
|
|
|
|
|
// 添加具体信息项:账号、耗时、时间
|
|
|
|
|
info.add(buildInfoItem("用户账号", userDTO.getUserName()));
|
|
|
|
|
info.add(buildInfoItem("审批状态", dictType.get(task.getFlowStatus())));
|
|
|
|
|
info.add(buildInfoItem("审批耗时", DateUtils.getTimeDifference(task.getUpdateTime(), task.getCreateTime())));
|
|
|
|
|
info.add(buildInfoItem("办理时间", DateUtils.formatDateTime(task.getUpdateTime())));
|
|
|
|
|
}
|
|
|
|
|
|