工作流绑定项目模块-2

原创
06/28 18:23
阅读数 68

1.增加模块定义

在ProcessUtils类中增加模块定义

/**
 * describe: 流程监控模块定义
 * current user Maochao.zhu
 * current system 2020/6/23
 */
public class ProcessUtils {
    /**
     *  信息审核
     */
    public static final int MODULE_TYPE_INFO = 1;
    public static final String MODULE_NAME_INFO = "信息审核";
    public static final String MODULE_TABLE_INFO="information";
}

2.初始化模块流程

//绑定流程
if(null!=information.getId()){
	//根据栏目id获取流程Id
	Programa programa = programaService.getProgramaById(information.getProgramaId());
	if(null!=programa.getProcessId()){
		//根据流程ID和模块ID进行初始化流程
		processControlService.initProcessControl(programa.getProcessId(),
				ProcessUtils.MODULE_TYPE_INFO,information.getId(),ProcessUtils.MODULE_NAME_INFO,ProcessUtils.MODULE_TABLE_INFO);
	}
}

3.html页面绑定流程审核

查看页面

<div class="layui-tab">
    <ul class="layui-tab-title">
        <li class="layui-this">基本信息</li>
        <li>审批节点</li> 
    </ul>
    <div class="layui-tab-content">
        <div class="layui-tab-item layui-show">
            
        </div>
        <!-- 增加流程审批节点页面引入 -->
        <div class="layui-tab-item">
            <iframe style="display: inline;margin-top: 21px;"  width="99%" height="400px;"  th:src="@{/processControl/goModuleSeeNote(moduleId=${information.id},moduleType=${moduleType})}"></iframe>
        </div>
    </div>
</div>

审核页面

<div class="layui-form-item">
	<label class="layui-form-label">信息审核</label>
	<div class="layui-input-block">
			<input type="radio" name="isCheck" value="1" title="审核"  th:checked="${information.isCheck eq 1}">
			<input type="radio" name="isCheck" value="2" title="驳回" th:checked="${information.isCheck eq 2}">
			<input type="radio" name="isCheck" value="3" title="流程审核 - 同意" th:checked="${information.isCheck eq 3}">
			<input type="radio" name="isCheck" value="4" title="流程审核 - 驳回" th:checked="${information.isCheck eq 4}">
	</div>
</div>
<div class="layui-form-item layui-hide">
	<input type="button" lay-submit lay-filter="ZX_iframe_submit" id="ZX_iframe_submit" value="确认">
</div>

审核页面js

//弹出并审核
layer.open({
	type: 2,
	title: '审核信息',
	content: '../information/goAduit?id='+obj.data.id,
	area: ['90%', '90%'],
	btnAlign: 'c',
	btn: ['确定', '取消'],
	yes: function(index, layero){
		var iframeWindow = window['layui-layer-iframe'+ index],
			submitID = 'ZX_iframe_submit',
			submit = layero.find('iframe').contents().find('#'+ submitID);
		//监听提交
		iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
			var mark = iframeWindow.UE.getEditor('editor').getContent();
			data.field.content =mark;
			//通过流程审核通过
			if(data.field.isCheck==3){
				var passload = layer.load(2);
				data.field.moduleType=1;
				data.field.moduleId=data.field.id;
				data.field.approvalOpinion = "审核通过";
				$.ajax({
					type: "POST",
					url: '../processControl/passProcessNote',
					data: data.field,
					dataType: "json",
					success: function(processData){
						if(processData.code==0){
							layer.close(passload);
							layer.msg(processData.msg);
							table.reload('ZX_table_list');
							layer.close(index);
						}else if(processData.code == 3){
							//更新模块审核状态
							data.field.isCheck =1;
							$.ajax({
								type: "POST",
								url: '../information/updateCheckEdit',
								data: data.field,
								dataType: "json",
								success: function(data){
									layer.close(passload);
									if(data.code==0){
										layer.msg(data.msg);
										table.reload('ZX_table_list');
										layer.close(index);
									}else{
										layer.msg(data.msg);
									}
								}
							});
						}else if(processData.code == 4){
							//更新模块审核状态
							data.field.isCheck =3;
							$.ajax({
								type: "POST",
								url: '../information/updateCheckEdit',
								data: data.field,
								dataType: "json",
								success: function(data){
									layer.close(passload);
									if(data.code==0){
										layer.msg(data.msg);
										table.reload('ZX_table_list');
										layer.close(index);
									}else{
										layer.msg(data.msg);
									}
								}
							});
						}else{
							layer.msg(processData.msg);
							layer.close(passload);
						}
						layer.close(passload);
					}
				});
			}else if(data.field.isCheck==4){//  驳回-流程审核
				data.field.moduleType=1;
				data.field.moduleId=data.field.id;
				data.field.approvalOpinion = "审核被驳回";
				var reject_load = layer.load(2);
				$.ajax({
					type: "POST",
					url: '../processControl/rejectProcessNote',
					data: data.field,
					dataType: "json",
					success: function(processData){
						if(processData.code==0){
							layer.close(reject_load);
							layer.msg(processData.msg);
							table.reload('ZX_table_list');
							layer.close(index);
						}else if(processData.code == 3){
							//更新模块审核状态
							data.field.isCheck =2;
							$.ajax({
								type: "POST",
								url: '../information/updateCheckEdit',
								data: data.field,
								dataType: "json",
								success: function(data){
									layer.close(reject_load);
									if(data.code==0){
										layer.msg(data.msg);
										table.reload('ZX_table_list');
										layer.close(index);
									}else{
										layer.msg(data.msg);
									}
								}
							});
						}else{
							layer.close(reject_load);
							layer.msg(processData.msg);
						}
						layer.close(reject_load);
					}
				});
			}else{
				$.ajax({
					type: "POST",
					url: '../information/updateCheckEdit',
					data: data.field,
					dataType: "json",
					success: function(data){
						if(data.code==0){
							layer.msg(data.msg);
							table.reload('ZX_table_list');
							layer.close(index);
						}else{
							layer.msg(data.msg);
						}
					}
				});
			}
		});
		submit.trigger('click');
	}
});

相关代码片段

流程初始化

    /**
     *  初始化流程开始
     *
     * @param processId  流程 ID
     * @param moduleType 流程对应的模块类型
     * @param moduleId   流程模块对应的 模块ID
     * @param moduleName 流程模块名称
     * @return
     */
    @Override
    @Transactional
    @Async
    public void initProcessControl(Integer processId, Integer moduleType, Integer moduleId, String moduleName, String moduleTable) {
        //流程ID
        if (null != processId) {
            //获取流程开始节点
            ProcessNote processNote = processNoteDao.getProcessNoteStart(processId);
            String processName = processDao.getProcessNameById(processId);
            if (null != processNote) {
                ProcessControl processControl = new ProcessControl();
                processControl.setProcessId(processId);
                processControl.setProcessName(processName);
                //模块相关
                processControl.setModuleType(moduleType);
                processControl.setModuleId(moduleId);
                processControl.setModuleName(moduleName);
                processControl.setModuleTable(moduleTable);
                //默认申请人
                User user = UserUtils.getLoginUser();
                if (null != user) {
                    processControl.setApplyUserId(user.getId());
                    processControl.setApplyUserName(user.getTname() != null ? user.getTname() : user.getUname());
                }
                //默认申请状态:审批中...
                processControl.setStatus(control_status_approval);
                //保存审批信息
                processControlDao.insertControl(processControl);
                //根据开始节点获取下一步流程走向
                List<String> toNoteCodeList = processNoteDao.getProcessToNoteCode(processId, processNote.getNoteCode());
                for (String toNoteCode : toNoteCodeList) {
                     //初始化流程
                    if(null!=processNote){
                        processControl.setNoteId(processNote.getId());
                        processControl.setNoteName(processNote.getNoteName());
                        processControl.setNoteCode(processNote.getNoteCode());
                    }
                    //增加初始化日志信息
                    //增加审核人信息
                    processControl.setApprovalUserId(processControl.getApplyUserId());
                    processControl.setApprovalUserName(processControl.getApplyUserName());
                    processControl.setApprovalOpinion("流程初始化");

                    insertControlUserLog(processControl,control_user_status_pass);

                    //下一节点:根据流程节点code,获取code对应的节点ID和名称
                    ProcessNote tempNote = processNoteDao.getNoteByCode(processId, toNoteCode);
                    if (null != tempNote) {
                        processControl.setNoteId(tempNote.getId());
                        processControl.setNoteName(tempNote.getNoteName());
                        processControl.setNoteCode(tempNote.getNoteCode());
                    }
                    //增加下一节点审核人
                    insertNextConrolNoteUser(processControl);
                }
            }
        }
    }

通过

    /**
     * 审核通过
     * @param processControlTemp 流程控制类
     */
    @Transactional
    public Integer passProcessNote(ProcessControl processControlTemp){
        //流程结束标识
        int end_flag = 0;
        //获取当前审核节点- 出现多节点-需要处理
        List<ProcessControlNote> processControlNoteList =  processControlDao.getNowControlNoteList(processControlTemp.getId());
        for (ProcessControlNote controlNote:processControlNoteList){
            //初始化节点
            processControlTemp.setNoteId(controlNote.getId());
            processControlTemp.setNoteName(controlNote.getNoteName());
            processControlTemp.setNoteCode(controlNote.getNoteCode());
            //根据当前节点获取来向节点
            processControlTemp = getProcessFromCode(processControlTemp);
            //获取当前审批人审批状态
            ProcessControlUser controlUser =  processControlDao.getProcessControlUserByNote(processControlTemp.getId(),controlNote.getNoteCode(),processControlTemp.getApprovalUserId());
            if(null!=controlUser){
                //修改审核状态
                controlUser.setStatus(control_user_status_pass);
                //审核意见
                controlUser.setApprovalOpinion(processControlTemp.getApprovalOpinion());
                processControlDao.updateProcessControlUserStatus(controlUser);
                //修改流程监控更新时间
                processControlDao.updateProcessControlStatus(processControlTemp.getId(),null);
                //增加审核日志
                insertControlUserLog(processControlTemp,controlUser.getStatus());
                //判断审核条件 审批类型:1串联、2并联
                Integer approvalType =  processNoteDao.getApprovalTypeByNoteCode(processControlTemp.getProcessId(),processControlTemp.getNoteCode());
                //获取流程节点下的所有审核人
                List<ProcessControlUser> controlUserList =  processControlDao.getProcessControlUserByNoteList(processControlTemp.getId(),processControlTemp.getNoteCode());
                boolean all_pass_falg = false;
                if(null!=approvalType && approvalType==1){
                    //串联
                    for(ProcessControlUser processControlUser :controlUserList){
                        if(processControlUser.getStatus() != control_user_status_pass){
                            System.out.println("############# 返回中止执行 ############");
                            return end_flag;//返回中止执行
                        }
                    }
                    System.out.println("############# method's passProcessNote --串联---all_pass_falg-------"+all_pass_falg);
                    all_pass_falg = true;
                }else if (null!=approvalType && approvalType==2){
                    //并联,一个通过全部通过
                    //修改其他人的任务状态为“通过”
                    for(ProcessControlUser processControlUser :controlUserList){
                        if(processControlUser.getStatus() != control_user_status_pass){
                            processControlUser.setStatus(control_user_status_pass);
                            processControlUser.setApprovalOpinion(processControlTemp.getApprovalOpinion());
                        }
                        processControlDao.updateProcessControlUserStatus(processControlUser);
                    }
                    all_pass_falg = true;
                }

                //通过,进行行下一步
                if(all_pass_falg){
                    //清除上一步节点信息
                    processControlDao.deleteControlNoteByNoteCode(processControlTemp.getId(),processControlTemp.getNoteCode());
                    //根据当前节点获取下一步流程走向
                    List<String> toNoteCodeList = processNoteDao.getProcessToNoteCode(processControlTemp.getProcessId(), processControlTemp.getNoteCode());
                    for (String toNoteCode : toNoteCodeList) {
                        //下一节点:根据流程节点code,获取code对应的节点ID和名称
                        ProcessNote tempNote = processNoteDao.getNoteByCode(processControlTemp.getProcessId(), toNoteCode);
                        if (null != tempNote) {
                            processControlTemp.setNoteId(tempNote.getId());
                            processControlTemp.setNoteName(tempNote.getNoteName());
                            processControlTemp.setNoteCode(toNoteCode);
                        }
                        //判断下一节点是否为结束节点
                        Integer endCodeCount =  processNoteDao.getProcessNoteEndCountByCode(processControlTemp.getProcessId(),processControlTemp.getNoteCode());
                        if(null!=endCodeCount && endCodeCount>0){
                            //是结束节点,结束流程
                            processControlTemp.setApprovalOpinion("流程结束");
                            processControlTemp =getProcessFromCode(processControlTemp);
                            insertControlUserLog(processControlTemp,control_status_end);
                            //修改流程监控状态为:已结束
                            processControlDao.updateProcessControlStatus(processControlTemp.getId(),control_status_end);
                            //清空其他待办节点
                            processControlDao.deleteControlNoteByNoteCode(processControlTemp.getId(),null);
                            //修改绑定模块
                            end_flag =3;//返回审核状态3为,流程结束,通过
                            break;
                        }else {
                            //修改流程监控为审批中
                            processControlDao.updateProcessControlStatus(processControlTemp.getId(),control_user_status_pass);
                            end_flag =4;//返回审核状态4为:流程局部审核通过,还没有完全结束
                        }
                        //增加下一节点审核人
                        insertNextConrolNoteUser(processControlTemp);
                    }
                }
            }
        }
        return  end_flag;
    }


驳回

    /**
     * 驳回
     * @param processControlTemp 流程控制类
     */
    @Transactional
    public Integer rejectProcessNote(ProcessControl processControlTemp){
        //流程结束标识
        int end_flag = 0;
        //根据当前节点获取来向节点
        processControlTemp = getProcessFromCode(processControlTemp);
        //获取当前审核节点- 出现多节点-需要处理
        List<ProcessControlNote> processControlNoteList =  processControlDao.getNowControlNoteList(processControlTemp.getId());
        for (ProcessControlNote controlNote:processControlNoteList){
            //初始化节点
            processControlTemp.setNoteId(controlNote.getId());
            processControlTemp.setNoteName(controlNote.getNoteName());
            processControlTemp.setNoteCode(controlNote.getNoteCode());
            //获取当前审批人审批状态
            ProcessControlUser controlUser =  processControlDao.getProcessControlUserByNote(processControlTemp.getId(),controlNote.getNoteCode(),processControlTemp.getApprovalUserId());
            //根据当前节点获取来向节点
            processControlTemp = getProcessFromCode(processControlTemp);
            if(null!=controlUser){
                //修改审核状态
                controlUser.setStatus(control_user_status_reject);
                //审核意见
                controlUser.setApprovalOpinion(processControlTemp.getApprovalOpinion());
                processControlDao.updateProcessControlUserStatus(controlUser);
                //增加审核日志
                insertControlUserLog(processControlTemp,controlUser.getStatus());
                //判断审核条件 审批类型:1串联、2并联
                Integer approvalType =  processNoteDao.getApprovalTypeByNoteCode(processControlTemp.getProcessId(),processControlTemp.getNoteCode());
                //获取流程节点下的所有审核人
                List<ProcessControlUser> controlUserList =  processControlDao.getProcessControlUserByNoteList(processControlTemp.getId(),processControlTemp.getNoteCode());
                boolean all_pass_falg = false;
                if(null!=approvalType && approvalType==1){
                    for(ProcessControlUser processControlUser :controlUserList){
                        if(processControlUser.getStatus() != control_user_status_reject){
                            System.out.println("############# 返回中止执行 ############");
                            return end_flag;//返回中止执行
                        }
                    }
                    all_pass_falg = true;
                    //串联:全部驳回才能驳回
                    System.out.println("############# method's passProcessNote --串联---all_pass_falg-------"+all_pass_falg);
                }else if (null!=approvalType && approvalType==2){
                    //并联,一个驳回全部驳回
                    //修改其他人的任务状态为“驳回”
                    for(ProcessControlUser processControlUser :controlUserList){
                        if(processControlUser.getStatus() != control_user_status_reject){
                            processControlUser.setStatus(control_user_status_reject);
                            processControlUser.setApprovalOpinion(processControlTemp.getApprovalOpinion());
                        }
                        processControlDao.updateProcessControlUserStatus(processControlUser);
                    }
                    all_pass_falg = true;
                }

                //驳回,上一步操作
                if(all_pass_falg){
                    //清除当前节点信息
                    processControlDao.deleteControlNoteByNoteCode(processControlTemp.getId(),processControlTemp.getNoteCode());
                    //根据当前节点获取上一步
                    List<String> fromNoteCodeList = processNoteDao.getProcessToBackCode(processControlTemp.getProcessId(), processControlTemp.getNoteCode());
                    for (String fromNoteCode : fromNoteCodeList) {
                        //上一节点:根据流程节点code,获取code对应的节点ID和名称
                        ProcessNote tempNote = processNoteDao.getNoteByCode(processControlTemp.getProcessId(), fromNoteCode);
                        //如果上一步是开始节点,则不进行上一步操作
                        ProcessNote processNote_start =  processNoteDao.getProcessNoteStart(processControlTemp.getProcessId());
                        if(!tempNote.getNoteCode().equals(processNote_start.getNoteCode())){
                            if (null != tempNote) {
                                processControlTemp.setNoteId(tempNote.getId());
                                processControlTemp.setNoteName(tempNote.getNoteName());
                                processControlTemp.setNoteCode(fromNoteCode);
                            }
                        }
                        //增加下一节点审核人
                        insertNextConrolNoteUser(processControlTemp);
                    }
                    //修改流程监为 ”已驳回“,控更新时间
                    processControlDao.updateProcessControlStatus(processControlTemp.getId(),control_status_reject);
                    end_flag = 3;
                }
            }
        }
        return end_flag;
    }

流转

/**
 * 流转
 * @param processControlTemp 流程控制类
 */
@Transactional
public Integer circleProcessNote(ProcessControl processControlTemp){
	//流程结束标识
	int end_flag = 0;
	//获取当前审核节点- 出现多节点-需要处理
	List<ProcessControlNote> processControlNoteList =  processControlDao.getNowControlNoteList(processControlTemp.getId());
	for (ProcessControlNote controlNote:processControlNoteList){
		//初始化节点
		processControlTemp.setNoteId(controlNote.getId());
		processControlTemp.setNoteName(controlNote.getNoteName());
		processControlTemp.setNoteCode(controlNote.getNoteCode());
		//获取当前审批人审批状态
		ProcessControlUser controlUser =  processControlDao.getProcessControlUserByNote(processControlTemp.getId(),controlNote.getNoteCode(),processControlTemp.getApprovalUserId());
		if(null!=controlUser){
			//增加审核人
			insertControlUser(processControlTemp,processControlTemp.getApprovalUserId(),processControlTemp.getApprovalUserName());
		}
		//来向节点等于去向节点
		processControlTemp.setFromNoteId(processControlTemp.getNoteId()+"");
		processControlTemp.setFromNoteCode(processControlTemp.getNoteCode());
		processControlTemp.setFromNoteName(processControlTemp.getNoteName());
		//增加审核日志
		insertControlUserLog(processControlTemp,control_user_status_circle);
	}
	return end_flag;
}
展开阅读全文
打赏
0
0 收藏
分享
加载中
更多评论
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部