1. 本章任务
上一章已经实现了学生奖学金的申请功能,本篇来实现下班主任、学院管理员、学校管理员审批的功能。
2. 查看当前待审批的申请
各级管理员需要登录后,分页查询待审批的记录列表。由于我们在生成flow表记录时,currentUserId字段即为保存的当前审批节点人员的id,所以我们按currentUserId查询即可。
首先开发前端表格:
<table id="mainTable" title="待审批申请列表" class="easyui-datagrid" url="CoreServlet?method=getAuditPage" pagination="true" singleSelect="true" fitColumns="true"> <thead> <tr> <th data-options="field:'id',width:50">申请序号</th> <th data-options="field:'studentName',width:50">申请人</th> <th data-options="field:'projectName',width:50">申请项目名称</th> <th data-options="field:'content',width:100">申请说明</th> <th data-options="field:'classAdvice',width:100">班主任审核意见</th> <th data-options="field:'collegeAdvice',width:100">学院审核意见</th> <th data-options="field:'schoolAdvice',width:100">学校审核意见</th> <th data-options="field:'currentNode',width:100" formatter="formatCurrentNode">进度</th> </tr> </thead> </table> 然后开发对应的后端方法: // 获取待审批记录 else if (method.equals("getAuditPage")) { FlowDao flowDao = new FlowDao(); total = flowDao.getCountByCurrentUserId(loginUser.getId()); result.setTotal(total); result.setRows(flowDao.getPageByCurrentUserId(page, rows, loginUser.getId())); } 最后完成FlowDao数据操作类的开发: /** * 获取数量 */ public int getCountByCurrentUserId(String userId) throws Exception { Connection conn = ConnectionUtils.getConnection(); String sql = "select count(id) from flow where currentUserId=?"; QueryRunner runner = new QueryRunner(); Object[] params = { userId }; Number number = (Number) runner.query(conn, sql, new ScalarHandler(), params); int value = number.intValue(); ConnectionUtils.releaseConnection(conn); return value; } /** * 分页查询 */ public List<Flow> getPageByCurrentUserId(int page, int rows, String userId) throws Exception { Connection conn = ConnectionUtils.getConnection(); String sql = "select * from flow where currentUserId=? limit ?,?"; QueryRunner runner = new QueryRunner(); Object[] params = { userId, (page - 1) * rows, rows }; List<Flow> flows = runner.query(conn, sql, new BeanListHandler<Flow>(Flow.class), params); ConnectionUtils.releaseConnection(conn); return flows; } 3. 审批功能的开发 当管理员选择一条待审批记录后,可以点击审批按钮,此时弹窗显示申请信息,管理员填入审批意见后可以选择通过或者驳回申请。如果是通过申请,则修改currentUserId为下一个审批人的id,currentNode修改为对应的审批节点标志。 好的,先添加审批按钮: <div class="tool-box"> <a id="btn" onclick="btnEditClick()" href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'">审批</a> </div> 1 2 3 点击按钮后弹窗: // 开始审批 function btnEditClick() { // 获取当前选中行 var row = $('#mainTable').datagrid('getSelected'); if (row == null) { alert("请选择要审批的申请"); return; } // 将选中行信息设置到弹窗 $("#edit-id").textbox("setValue", row.id); $("#edit-content").textbox("setValue", row.content); $('#dialog-edit').dialog('open'); } 点击提交按钮后,将数据提交给后端方法: // 审批 function btnAudit(state) { var param = { id: $("#edit-id").val(), state: state, advice: $("#edit-advice").val(), } $.ajax({ url: "CoreServlet?method=audit", type: "post", dataType: "json", data: param, success: function(res) { console.log(res); if (res.code == 0) { //成功则刷新表格 $('#mainTable').datagrid('reload'); $('#dialog-edit').dialog('close'); } else { //提示错误信息 alert(res.msg); } }, }); 后端收到后进行处理,注意要根据当前登录人的信息,来修改当前申请对应的currentUserId和currentNode值。 // 审批 else if (method.equals("audit")) { FlowDao flowDao = new FlowDao(); String flowId = request.getParameter("id"); String state = request.getParameter("state"); String advice = request.getParameter("advice"); Flow flow = flowDao.getById(flowId); // 填入意见 if (loginUser.getRole().equals("classmaster")) { flow.setClassAdvice(advice); } else if (loginUser.getRole().equals("collegemaster")) { flow.setCollegeAdvice(advice); } else if (loginUser.getRole().equals("schoolmaster")) { flow.setSchoolAdvice(advice); } // 失败 if (state.equals("fail")) { flow.setCurrentUserId(flow.getStudentId()); flow.setCurrentNode("fail"); } else { if (loginUser.getRole().equals("classmaster")) { flow.setCurrentUserId(flow.getCollegeUserId()); flow.setCurrentNode("college"); } else if (loginUser.getRole().equals("collegemaster")) { flow.setCurrentUserId(flow.getSchoolUserId()); flow.setCurrentNode("school"); } else if (loginUser.getRole().equals("schoolmaster")) { flow.setCurrentUserId(flow.getStudentId()); flow.setCurrentNode("success"); } } flowDao.update(flow); result.setCode(0); result.setMsg("操作成功"); } 4. 总结 至此我们开发完成了本系统的所有功能,非常华丽!