上一章已经实现了学生奖学金的申请功能,本篇来实现下班主任、学院管理员、学校管理员审批的功能。
2. 查看当前待审批的申请各级管理员需要登录后,分页查询待审批的记录列表。由于我们在生成flow表记录时,currentUserId字段即为保存的当前审批节点人员的id,所以我们按currentUserId查询即可。
首先开发前端表格:
申请序号
申请人
申请项目名称
申请说明
班主任审核意见
学院审核意见
学校审核意见
进度
然后开发对应的后端方法:
// 获取待审批记录
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 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 flows = runner.query(conn, sql, new BeanListHandler(Flow.class), params);
ConnectionUtils.releaseConnection(conn);
return flows;
}
3. 审批功能的开发
当管理员选择一条待审批记录后,可以点击审批按钮,此时弹窗显示申请信息,管理员填入审批意见后可以选择通过或者驳回申请。如果是通过申请,则修改currentUserId为下一个审批人的id,currentNode修改为对应的审批节点标志。
好的,先添加审批按钮:
点击按钮后弹窗:
// 开始审批
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. 总结
至此我们开发完成了本系统的所有功能,非常华丽!


![EasyUI+JavaWeb奖助学金管理系统[19]-奖助学金审批功能开发 EasyUI+JavaWeb奖助学金管理系统[19]-奖助学金审批功能开发](http://www.mshxw.com/aiimages/31/236868.png)
