基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)

简介: 基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题(续)

更多ruoyi-nbcio功能请看演示系统

gitee源代码地址

前后端代码: https://gitee.com/nbacheng/ruoyi-nbcio

演示地址:RuoYi-Nbcio后台管理系统

更多nbcio-boot功能请看演示系统

gitee源代码地址

后端代码: https://gitee.com/nbacheng/nbcio-boot

前端代码:https://gitee.com/nbacheng/nbcio-vue.git

在线演示(包括H5) : http://218.75.87.38:9888

之前主要是发送消息的标题处理,今天就待办的任务标题也做一个处理。

1、在获取待办的时候动态进行处理

分页获取待办列表的方法修改如下:

@Override
    public TableDataInfo<WfTaskVo> selectPageTodoProcessList(ProcessQuery processQuery, PageQuery pageQuery) {
      Page<WfTaskVo> page = new Page<>();
        TaskQuery taskQuery = taskService.createTaskQuery()
            .active()
            .includeProcessVariables()
            .taskCandidateOrAssigned(TaskUtils.getUserName())
            .taskCandidateGroupIn(TaskUtils.getCandidateGroup())
            .orderByTaskCreateTime().desc();
        // 构建搜索条件
        ProcessUtils.buildProcessSearch(taskQuery, processQuery);
        page.setTotal(taskQuery.count());
        int offset = pageQuery.getPageSize() * (pageQuery.getPageNum() - 1);
        List<Task> taskList = taskQuery.listPage(offset, pageQuery.getPageSize());
        List<WfTaskVo> flowList = new ArrayList<>();
        for (Task task : taskList) {
            WfTaskVo flowTask = new WfTaskVo();
            // 当前流程信息
            flowTask.setTaskId(task.getId());
            flowTask.setTaskDefKey(task.getTaskDefinitionKey());
            flowTask.setCreateTime(task.getCreateTime());
            flowTask.setProcDefId(task.getProcessDefinitionId());
            //下面主要是获取全局动态任务标题变量
            Map<String, Object> processVariables = task.getProcessVariables();
            String taskTitle ="";
            if(ObjectUtils.isNotEmpty(processVariables) && ObjectUtils.isNotEmpty(processVariables.get("taskTitle"))) {
              taskTitle = processVariables.get("taskTitle").toString();
            }
            if(StringUtils.isNotEmpty(taskTitle)) {
              flowTask.setTaskName(task.getName()+"("+taskTitle+")");
            }
            else {
              flowTask.setTaskName(task.getName());
            }
            // 流程定义信息
            ProcessDefinition pd = repositoryService.createProcessDefinitionQuery()
                .processDefinitionId(task.getProcessDefinitionId())
                .singleResult();
            flowTask.setDeployId(pd.getDeploymentId());
            flowTask.setProcDefName(pd.getName());
            flowTask.setProcDefVersion(pd.getVersion());
            flowTask.setProcInsId(task.getProcessInstanceId());
            // 流程发起人信息
            HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery()
                .processInstanceId(task.getProcessInstanceId())
                .singleResult();
            String userId = historicProcessInstance.getStartUserId();
            String nickName = sysUserService.selectUserByUserName(userId).getNickName();
            flowTask.setStartUserId(userId);
            flowTask.setStartUserName(nickName);
            // 流程变量
            flowTask.setProcVars(task.getProcessVariables());
            flowList.add(flowTask);
        }
        page.setRecords(flowList);
        return TableDataInfo.build(page);
    }

注意在流程启动的时候也要进行处理。

2、流程启动修改部分

if(StringUtils.isNotEmpty(dataId)) {//自定义业务表单
          //设置自定义表单dataid的数据 
            WfMyBusiness flowmybusiness = wfMyBusinessServiceImpl.getByDataId(variables.get("dataId").toString());
            String serviceImplName = flowmybusiness.getServiceImplName();
            WfCallBackServiceI flowCallBackService = (WfCallBackServiceI) SpringContextUtils.getBean(serviceImplName);
            if (flowCallBackService!=null){
              Object businessDataById = flowCallBackService.getBusinessDataById(variables.get("dataId").toString());
              variables.put("formData",businessDataById);
              //作为动态根据Document表达式来处理任务标题用变量
              variables.put("taskTitle","发起人"); 
            }
        }

3、任务完成也要做修改处理

@Transactional(rollbackFor = Exception.class)
    @Override
    public void complete(WfTaskBo taskBo) {
        Task task = taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
        TaskEntity taskEntity = (TaskEntity) taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
        if (Objects.isNull(task)) {
            throw new ServiceException("任务不存在");
        }
        //获取流程当前节点设置的扩展属性值,需要的时候可以使用
        //Map<String, Object> flowProperties = getFlowProperties(taskBo.getProcInsId());
        
        // 获取 bpmn 模型
        BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
        if (DelegationState.PENDING.equals(task.getDelegationState())) {
            taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.DELEGATE.getType(), taskBo.getComment());
            taskService.resolveTask(taskBo.getTaskId());
        } else {
            taskService.addComment(taskBo.getTaskId(), taskBo.getProcInsId(), FlowComment.NORMAL.getType(), taskBo.getComment());
            taskService.setAssignee(taskBo.getTaskId(), TaskUtils.getUserName());
            if (ObjectUtil.isNotEmpty(taskBo.getVariables())) {
                // 获取模型信息
                String localScopeValue = ModelUtils.getUserTaskAttributeValue(bpmnModel, task.getTaskDefinitionKey(), ProcessConstants.PROCESS_FORM_LOCAL_SCOPE);
                boolean localScope = Convert.toBool(localScopeValue, false);
                taskService.complete(taskBo.getTaskId(), taskBo.getVariables(), localScope);
            } else {
              String field = task.getDescription();
              if(StringUtils.isNotEmpty(field)) {
                field = field.substring(field.lastIndexOf("{") + 1, field.lastIndexOf("}"));
              }
          if(StringUtils.isNotEmpty(field)) {//获取动态的任务标题,同时放入全局变量里
            String taskTitle = commonService.getTaskTitle(taskBo.getDataId(), field);
            Map<String, Object> variables = new HashMap<String, Object>();
            variables.put("taskTitle", taskTitle);
            taskService.complete(taskBo.getTaskId(),variables,false);
          }
          else {
            taskService.complete(taskBo.getTaskId());
          }   
            }
        }
        // 设置任务节点名称
        taskBo.setTaskName(task.getName());
        
        // 处理下一级审批人
        if (StringUtils.isNotBlank(taskBo.getNextUserIds())) {
            this.assignNextUsers(bpmnModel, taskBo.getProcInsId(), taskBo.getNextUserIds());
        }
        
        //加签处理
        addSignForComplete(taskBo,taskEntity);
        
        // 处理抄送用户
        if (!copyService.makeCopy(taskBo)) {
            throw new RuntimeException("抄送任务失败");
        }
    }

4、效果图如下:


相关文章
|
19天前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务流程出现多个时相应的流程选择问题(二)
基于若依的ruoyi-nbcio流程管理系统自定义业务流程出现多个时相应的流程选择问题(二)
22 3
|
19天前
|
XML JSON 数据格式
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(五)
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(五)
21 2
|
19天前
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(三)
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(三)
19 0
|
19天前
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(七)
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(七)
18 1
基于若依的ruoyi-nbcio流程管理系统增加仿钉钉流程设计(七)
|
19天前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求
基于若依的ruoyi-nbcio流程管理系统自定义业务实现一种简单的动态任务标题需求
19 1
|
19天前
|
前端开发
基于若依的ruoyi-nbcio流程管理系统增加流程设计器支持自定义表单的选择与处理
基于若依的ruoyi-nbcio流程管理系统增加流程设计器支持自定义表单的选择与处理
15 0
|
19天前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(二)
18 2
|
19天前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(一)
基于若依的ruoyi-nbcio流程管理系统自定义业务回写状态的一种新方法(一)
17 1
|
19天前
|
移动开发 前端开发
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(五)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(五)
16 0
|
19天前
|
移动开发 前端开发 数据库
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(一)
基于若依的ruoyi-nbcio流程管理系统一种简单的动态表单模拟测试实现(一)
14 1