jeesite中工作流activity使用详解

jeesite中使用activity使用详解。

  • 常规业务实现
  • 业务结合activity代码过程整理

常规业务整合

1.实体类中继承ACT业务流程实体类

业务结合activity代码过程整理

1.启动流程

保存业务表单时、启动工作流

//保存业务表单时、启动工作流
@Transactional(readOnly = false)
    public void save(OaNotify oaNotify, Map variables) {
        //判断是否是新增数据
        if (oaNotify.getIsNewRecord()) {
            super.save(oaNotify);
            // 更新发送接受人记录
            oaNotifyRecordDao.deleteByOaNotifyId(oaNotify.getId());
            if (oaNotify.getOaNotifyRecordList().size() > 0) {
                oaNotifyRecordDao.insertAll(oaNotify.getOaNotifyRecordList());
            }
            /*********启动流程**************/
            // 用来设置启动流程的人员ID,引擎会自动把用户ID保存到activiti:initiator中
            identityService.setAuthenticatedUserId(oaNotify.getCurrentUser().getLoginName());   
            // 启动流程
            String businessKey = oaNotify.getId().toString();
            //设置参数(在流程图中设置的${变量},在这里赋值)
            variables.put("type", "oaNotify");
            variables.put("busId", businessKey);
            variables.put("deptLeader", "sd_jsb");
            ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("notice", "oa_notify:"+businessKey, variables);
            //更新公告表中的流程节点
            oaNotify.setProcessInstanceId(processInstance.getId());
            dao.updateProcessInstanceId(oaNotify);

        } 
    }

2.待办列表

在流程启动中会配置下一个节点的审核人员。流程启动后,该人员登录系统在待办任务中会看到待办事项,待办事项的实现代码如下所示:

//查询通知公告代办列表
public Page find(Page page, OaNotify oaNotify) {
        //设置数据权限
            oaNotify.getSqlMap().put("dsf", dataScopeFilter(oaNotify.getCurrentUser(), "o", "u"));
            oaNotify.setPage(page);
            page.setList(dao.findList(oaNotify));
            List list=new ArrayList();
            //循环遍历公告内容
            for(OaNotify item : page.getList()) {
                //获取流程实例ID
                String processInstanceId = item.getProcessInstanceId();
                //根据流程实例id获取当前任务节点
                Task task = taskService.createTaskQuery().processInstanceId(processInstanceId).active().singleResult();
                item.getAct().setTask(task);
                //获取该流程的历史实例信息
                HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();
                if(historicProcessInstance!=null) {                        
                    item.getAct().setHisProIns(historicProcessInstance);
                    item.getAct().setProcDef(repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult());
                } else {
                    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId).active().singleResult();
                    if (processInstance != null){
                        item.getAct().setProcIns(processInstance);
                        item.getAct().setProcDef(repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId()).singleResult());
                    }
                }
                list.add(item);
            }
            page.setList(list);
            return page;
        }
    "oa:oaNotify:edit">
        "${ctx}/act/task/form?taskId=${oaNotify.act.task.id}&taskName=${fns:urlEncode(oaNotify.act.task.name)}&taskDefKey=${oaNotify.act.task.taskDefinitionKey}&procInsId=${oaNotify.act.task.processInstanceId}&procDefId=${oaNotify.act.task.processDefinitionId}&status=${status}">任务办理
        "_blank" href="${ctx}/act/task/trace/photo/${oaNotify.act.task.processDefinitionId}/${oaNotify.act.task.executionId}">跟踪
        "_blank" href="${pageContext.request.contextPath}/act/diagram-viewer?processDefinitionId=${oaNotify.act.task.processDefinitionId}&processInstanceId=${oaNotify.act.task.processInstanceId}">跟踪
                                  
                        

3.通过任务办理进行业务表单页面

审核用户通过代办列表中的任务办理按钮,进入审批页面。审批页面需要获取流程相关信息和展示流程节点信息,代码如下:

<form:form id="inputForm" modelAttribute="oaNotify" action="${ctx}/oa/oaNotify/subApprove" method="post" class="form-horizontal">
        <form:hidden path="id"/>
        <form:hidden path="act.flag" id="flag"/>
        
        <form:hidden path="act.taskId"/>
        
        <form:hidden path="act.taskName"/>
        
        <form:hidden path="act.taskDefKey"/>
        
        <form:hidden path="act.procInsId"/>
        
        <form:hidden path="act.procDefId"/>
        ...其他表单信息展示
        <div class="control-group">
                <label class="control-label">审批意见:label>
                <div class="controls">
                    <form:textarea path="act.comment"/>
                    <span class="help-inline"><font color="red">*font> span>
                div>
            div>
            <shiro:hasPermission name="oa:Leave:edit">
                <input id="btnSubmit" class="btn btn-primary" type="submit" value="通过" onclick="javascript:$('#flag').val('yes');"/> 
                <input id="btnSubmit2" class="btn btn-inverse" type="submit" value="驳回" onclick="javascript:$('#flag').val('no');"/> 
            shiro:hasPermission>
            <input id="btnCancel" class="btn" type="button" value="返 回" onclick="history.go(-1)"/>
        div>
        <c:if test="${not empty oaNotify.id}">
            //展示流程节点信息
            <act:histoicFlow procInsId="${oaNotify.act.procInsId}" />
        c:if>
    form:form>

4.提交审批意见

在审批页面录入审批意见后点击通过或驳回就完成审批。后台代码如下:

    /***
     * 提交审核
     * @param oaNotify
     * @param model
     * @return
     */
    @RequestMapping(value = "subApprove")
    public String subApprove(OaNotify oaNotify, Model model) {
    //  oaNotify.preUpdate();
        oaNotifyService.save(oaNotify);
        oaNotify.getAct().setComment(("yes".equals(oaNotify.getAct().getFlag())?"[重申] ":"[销毁] ")+oaNotify.getAct().getComment());
        // 完成流程任务
        Map vars = Maps.newHashMap();
        //vars中的参数用于流程设计器中配置的${变量名}赋值
        vars.put("result", "yes".equals(oaNotify.getAct().getFlag())? "1" : "0");
        vars.put("xxzxLeader", "sd_zhb");
        actTaskService.complete(oaNotify.getAct().getTaskId(), oaNotify.getAct().getProcInsId(), oaNotify.getAct().getComment(), oaNotify.getTitle(), vars);
        return "modules/oa/notifyForm";
    }

你可能感兴趣的:(java)