mirror of
				https://github.com/dromara/RuoYi-Vue-Plus.git
				synced 2025-11-04 08:13:44 +08:00 
			
		
		
		
	update 优化类型转换逻辑、删除冗余代码
This commit is contained in:
		@@ -52,14 +52,6 @@ public interface UserService {
 | 
			
		||||
     */
 | 
			
		||||
    String selectEmailById(Long userId);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过用户ID查询用户详细信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户id
 | 
			
		||||
     * @return 用户详细信息
 | 
			
		||||
     */
 | 
			
		||||
    UserDTO selectUserDtoById(Long userId);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过用户ID查询用户列表
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -623,23 +623,6 @@ public class SysUserServiceImpl implements ISysUserService, UserService {
 | 
			
		||||
        return ObjectUtils.notNullGetter(sysUser, SysUser::getEmail);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过用户ID查询用户详细信息
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户id
 | 
			
		||||
     * @return 用户详细信息
 | 
			
		||||
     */
 | 
			
		||||
    @Override
 | 
			
		||||
    public UserDTO selectUserDtoById(Long userId) {
 | 
			
		||||
        SysUser sysUser = baseMapper.selectOne(new LambdaQueryWrapper<SysUser>()
 | 
			
		||||
            .select(SysUser::getUserId, SysUser::getDeptId, SysUser::getUserName,
 | 
			
		||||
                SysUser::getNickName, SysUser::getUserType, SysUser::getEmail,
 | 
			
		||||
                SysUser::getPhonenumber, SysUser::getSex, SysUser::getStatus,
 | 
			
		||||
                SysUser::getCreateTime)
 | 
			
		||||
            .eq(SysUser::getUserId, userId));
 | 
			
		||||
        return BeanUtil.toBean(sysUser, UserDTO.class);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 通过用户ID查询用户列表
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -73,4 +73,9 @@ public interface FlowConstant {
 | 
			
		||||
     */
 | 
			
		||||
    String MESSAGE_NOTICE = "messageNotice";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 任务状态
 | 
			
		||||
     */
 | 
			
		||||
    String WF_TASK_STATUS = "wf_task_status";
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -35,7 +35,6 @@ public interface IFlwDefinitionService {
 | 
			
		||||
     */
 | 
			
		||||
    TableDataInfo<FlowDefinitionVo> unPublishList(FlowDefinition flowDefinition, PageQuery pageQuery);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 发布流程定义
 | 
			
		||||
     *
 | 
			
		||||
 
 | 
			
		||||
@@ -26,12 +26,6 @@ public class CategoryNameTranslationImpl implements TranslationInterface<String>
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public String translation(Object key, String other) {
 | 
			
		||||
        Long id = null;
 | 
			
		||||
        if (key instanceof String categoryId) {
 | 
			
		||||
            id = Convert.toLong(categoryId);
 | 
			
		||||
        } else if (key instanceof Long categoryId) {
 | 
			
		||||
            id = categoryId;
 | 
			
		||||
        }
 | 
			
		||||
        return flwCategoryService.selectCategoryNameById(id);
 | 
			
		||||
        return flwCategoryService.selectCategoryNameById(Convert.toLong(key));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -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())));
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@ package org.dromara.workflow.service.impl;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.bean.BeanUtil;
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.convert.Convert;
 | 
			
		||||
import cn.hutool.core.lang.Pair;
 | 
			
		||||
import cn.hutool.core.util.StrUtil;
 | 
			
		||||
import lombok.RequiredArgsConstructor;
 | 
			
		||||
@@ -239,10 +240,10 @@ public class FlwTaskAssigneeServiceImpl implements IFlwTaskAssigneeService, Hand
 | 
			
		||||
        try {
 | 
			
		||||
            String[] parts = storageId.split(StrUtil.COLON, 2);
 | 
			
		||||
            if (parts.length < 2) {
 | 
			
		||||
                return Pair.of(TaskAssigneeEnum.USER, Long.valueOf(parts[0]));
 | 
			
		||||
                return Pair.of(TaskAssigneeEnum.USER, Convert.toLong(parts[0]));
 | 
			
		||||
            } else {
 | 
			
		||||
                TaskAssigneeEnum type = TaskAssigneeEnum.fromCode(parts[0] + StrUtil.COLON);
 | 
			
		||||
                return Pair.of(type, Long.valueOf(parts[1]));
 | 
			
		||||
                return Pair.of(type, Convert.toLong(parts[1]));
 | 
			
		||||
            }
 | 
			
		||||
        } catch (Exception e) {
 | 
			
		||||
            log.warn("解析 storageId 失败,格式非法:{},错误信息:{}", storageId, e.getMessage());
 | 
			
		||||
 
 | 
			
		||||
@@ -717,7 +717,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
 | 
			
		||||
        for (Map.Entry<Long, List<User>> entry : listMap.entrySet()) {
 | 
			
		||||
            List<User> value = entry.getValue();
 | 
			
		||||
            if (CollUtil.isNotEmpty(value)) {
 | 
			
		||||
                List<UserDTO> userDtoList = userService.selectListByIds(StreamUtils.toList(value, e -> Long.valueOf(e.getProcessedBy())));
 | 
			
		||||
                List<UserDTO> userDtoList = userService.selectListByIds(StreamUtils.toList(value, e -> Convert.toLong(e.getProcessedBy())));
 | 
			
		||||
                map.put(entry.getKey(), userDtoList);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
@@ -736,7 +736,7 @@ public class FlwTaskServiceImpl implements IFlwTaskService {
 | 
			
		||||
        if (CollUtil.isEmpty(userList)) {
 | 
			
		||||
            return Collections.emptyList();
 | 
			
		||||
        }
 | 
			
		||||
        return userService.selectListByIds(StreamUtils.toList(userList, e -> Long.valueOf(e.getProcessedBy())));
 | 
			
		||||
        return userService.selectListByIds(StreamUtils.toList(userList, e -> Convert.toLong(e.getProcessedBy())));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -145,7 +145,7 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
 | 
			
		||||
    @EventListener(condition = "#processEvent.flowCode.startsWith('leave')")
 | 
			
		||||
    public void processHandler(ProcessEvent processEvent) {
 | 
			
		||||
        log.info("当前任务执行了{}", processEvent.toString());
 | 
			
		||||
        TestLeave testLeave = baseMapper.selectById(Long.valueOf(processEvent.getBusinessId()));
 | 
			
		||||
        TestLeave testLeave = baseMapper.selectById(Convert.toLong(processEvent.getBusinessId()));
 | 
			
		||||
        testLeave.setStatus(processEvent.getStatus());
 | 
			
		||||
        // 用于例如审批附件 审批意见等 存储到业务表内 自行根据业务实现存储流程
 | 
			
		||||
        Map<String, Object> params = processEvent.getParams();
 | 
			
		||||
@@ -188,7 +188,7 @@ public class TestLeaveServiceImpl implements ITestLeaveService {
 | 
			
		||||
    @EventListener(condition = "#processDeleteEvent.flowCode.startsWith('leave')")
 | 
			
		||||
    public void processDeleteHandler(ProcessDeleteEvent processDeleteEvent) {
 | 
			
		||||
        log.info("监听删除流程事件,当前任务执行了{}", processDeleteEvent.toString());
 | 
			
		||||
        TestLeave testLeave = baseMapper.selectById(Long.valueOf(processDeleteEvent.getBusinessId()));
 | 
			
		||||
        TestLeave testLeave = baseMapper.selectById(Convert.toLong(processDeleteEvent.getBusinessId()));
 | 
			
		||||
        if (ObjectUtil.isNull(testLeave)) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user