1、项目需求:
河北金力集团是我省机械加工的龙头企业,主要从事矿山机械制造及各种机械零部件加工。企业有3个厂区,主厂区位于省高新技术开发区,3个分厂分别在保定、邢台和唐山。为增加企业的核心竞争力和加强管理的科学程度,近期企业将在全集团实行ERP管理,建立网页版公文流转系统。具体部门:主厂区、一分厂、二分厂、三分厂、销售部门、财务部门、办公室;领导:三位副厂长(分别管理生产、销售、财务)、一位厂长。
2. 板块功能需求
(1)、页面要求
① 能适应800*600或1024*768分辨率;
② 布局合理、结构清晰、页面完整;
③ 有效页面数在8页以上;
④ 分页与主页风格统一;
⑤ 首页(登录页):用户登录页(共有十位用户帐号,帐号、密码可预设)。不同用户登录后,进入的功能页不相同,要求密码在数据库中加密。
⑥ 部门(不含办公室)功能页:有公文拟制、签收公文、浏览公文(已签收的公文)三个模块
⑦ 办公室功能页:有修改公文、公文流转、删除公文、公文发送等功能。
⑧ 副厂长功能页:有审核公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。
⑨ 厂长功能页:有审签公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。
⑩ 系统管理功能页:有用户管理、角色管理、公文流转流程管理。
(2)、功能设计:
- 公文拟制:创建新的电子公文,对创建的电子公文进行上传操作。
- 签收公文:当接收方接收公文后,会给发送方发回执信息,确认公文已经收到。
- 浏览公文(已签收的公文):
1) 选择日期段。
2) 通过“查询”功能,显示该时间段内已通过审签的正式公文。
3) 点击公文标题,将会显示出该公文的具体信息。
- 修改公文:对拟制好的的电子公文进行格式化处理操作,套用公文样例。
- 公文流转:按照公文流转流程设定公文接收用户。
- 删除公文:如果该公文没有通过审核或审签,需要删除可以利用“删除”功能。确定后,系统提示公文删除成功,删除的公文将在“被删除公文”模块中的显示。
- 公文发送:操作员要根据单位管理员选择的公文的流程进行公文的流转发送,实现待发公文和已发送公文的管理
- 审核公文(修改并签意见):签署审核意见和修改意见,并将退回办公室。
- 有审签公文(修改并签意见):签署审前意见和修改意见,若同意,则生成正式公文并交由办公室转发。
- 浏览已发所有公文:按日期查看所有已发公文,点击标题可查看具体信息。
- 公文查询:是查询由公文交换系统处理过的公文,并且建立或检查公文详尽的索引信息。可以根据发送机构、接收机构、公文种类和其它开放信息进行公文数据查询。
- 系统管理:
a) 角色配置管理
- 用户权限维护功能:实现对用户的角色管理。
- 角色维护功能:实现对角色权限的管理,主要有编辑、增加和删除操作。
b) 用户管理:查看用户、新开用户、暂停用户、用户信息修改、删除用户
c) 单位管理员设置功能:每个单位的操作员实现修改密码、修改个人信息。
系统架构分析:
1.完成用户登录系统的设计,其中有关后台管理系统默认用户登录信息,需连接数据库并自定义表进行录入;
2.根据项目功能要求及其参与者种类可以将每个角色的功能分页进行,然后严格按照公文流转流程进行整合;
3.对公文流转过程进行细化,严格遵循流转流程实现各用户交互功能;
4.优化系统设计
a)添加用户信息管理功能即后台系统管理员可对用户的登录信息进行增删改查;
b)以公文文件为主体可以添加相关增删改查功能,以便进行后台综合管理
源代码:
JSP界面代码:
主界面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <title>登录</title> <link rel="stylesheet" type="text/css" href="mycss/index.css"/> <style type="text/css"> .header{ width:100%; height:120px; text-align:center; } .container{ width:100%; height:780px; position:center; } .login{ width:500px; height:auto; position:absolute; top:200px; left:500px; border-radius:8px; } label{ float:left; width:100px; margin-top:7px; margin-right:5px; } .form-control{ width:60%; } .logtip{ padding-top:30px; padding-bottom:30px; border-bottom:2px solid red; text-align:center; } .form-group{ margin-left:40px; margin-top:40px; } .btn{ height:50px; width:100px; float:left; border-radius:10px; } .logbtn{ margin-right:20px; } .btnbag{ margin-left:140px; margin-right:140px; height:50px; margin-top:30px; margin-bottom:40px; } </style> </head> <body> <div class="header"><h2>河北金力集团公文流转系统</h2></div> <div class="container"> <div class="login"> <h2 class="logtip">登录</h2> <form action="login_do" method="post"> <div class="form-group"> <label for="username">用户名</label> <input type="text" class="form-control" id="username" name="username"> </div> <div class="form-group"> <label for="password">密码</label> <input type="password" class="form-control" id="password" name="password"> </div> <div class="btnbag"> <input type="button" class="btn btn-primary logbtn" onclick="login()" value="登录"> <input type="button" class="btn btn-primary mangbtn" onclick="entermang()" value="进入管理"> </div> </form> </div> </div> <div class="footer"></div> </body> <script> function login() { var username=$("#username").val(); var password=$("#password").val(); if(username==""||password=="") alert("请将信息填写完整!"); else { $.post( "login_do", {username:username, password:password}, function(data){ if(data=="yes") { alert("成功登陆!"); window.location="mainpage.jsp"; } else alert("用户名或密码错误!或用户已被暂停使用!"); }, "text" ); } } function entermang() { var username=$("#username").val(); var password=$("#password").val(); if(username==""||password=="") alert("请将信息填写完整!"); else { $.post( "login_do", {username:username, password:password}, function(data){ if(data=="yes") { alert("成功登陆!"); window.location="backmainpage.jsp"; } else alert("用户名或密码错误!或用户已被暂停使用!"); }, "text" ); } } </body> </html>
各角色功能页:
厂长:
<%@page import="com.official.bean.Doc"%> <%@page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <title>厂长申签公文页面</title> </head> <body> <div> <nav class="navbar navbar-expand-sm bg-light"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="#" onclick="shownotChecked()">待审签公文</a> </li> <li class="nav-item"> <a class="nav-link" href="#" onclick="showChecked()">已审签公文</a> </li> </ul> </nav> </div> <div> <table class="table table-hover table-striped table-bordered table-sm"> <tr> <th>公文编号</th> <th>公文标题</th> <th>发送时间</th> <th>发送机构</th> <th>公文状态</th> <th>审核结果</th> <th>操作</th> </tr> <%ArrayList<Doc> list=(ArrayList<Doc>)request.getAttribute("list"); %> <c:forEach var="l" items="<%=list %>" varStatus="i"> <tr> <td id="id${i.index+1 }">${l.getId() }</td> <td>${l.getTitle() }</td> <td>${l.getTime() }</td> <td>${l.getOwner() }</td> <td id="status${i.index+1 }">${l.getStatus() }</td> <td>${l.getResult() }</td> <td><a href="#" onclick="docheck(${i.index+1})">审签</a></td> </tr> </c:forEach> </table> </div> </body> <script> function shownotChecked() { window.location="fcheckDoc?type=notchecked"; } function showChecked() { window.location="fcheckDoc?type=checked" } function docheck(index) { var status=$("#status"+index).text(); if(status==5) { var id=$("#id"+index).text(); window.location="dofCheck?id="+id; } else alert("不具备权限!"); } </script> </html>
副厂长:
<%@page import="com.official.bean.Doc"%> <%@page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <title>副厂长审核公文页面</title> </head> <body> <div> <nav class="navbar navbar-expand-sm bg-light"> <ul class="navbar-nav"> <li class="nav-item"> <a class="nav-link" href="#" onclick="shownotChecked()">待审签公文</a> </li> <li class="nav-item"> <a class="nav-link" href="#" onclick="showChecked()">已审签公文</a> </li> </ul> </nav> </div> <div> <table class="table table-hover table-striped table-bordered table-sm"> <tr> <th>公文编号</th> <th>公文标题</th> <th>发送时间</th> <th>发送机构</th> <th>公文状态</th> <th>审核结果</th> <th>操作</th> </tr> <%ArrayList<Doc> list=(ArrayList<Doc>)request.getAttribute("list"); %> <c:forEach var="l" items="<%=list %>" varStatus="i"> <tr> <td id="id${i.index+1 }">${l.getId() }</td> <td>${l.getTitle() }</td> <td>${l.getTime() }</td> <td>${l.getOwner() }</td> <td id="status${i.index+1 }">${l.getStatus() }</td> <td>${l.getResult() }</td> <td><a href="#" onclick="docheck(${i.index+1})">审签</a></td> </tr> </c:forEach> </table> </div> </body> <script> function shownotChecked() { window.location="fcheckDoc?type=notchecked"; } function showChecked() { window.location="fcheckDoc?type=checked" } function docheck(index) { var status=$("#status"+index).text(); if(status==5) { var id=$("#id"+index).text(); window.location="dofCheck?id="+id; } else alert("不具备权限!"); } </script> </html>
办公室:
<%@page import="com.official.util.DBUtil"%> <%@page import="com.official.bean.Permission"%> <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%> <%@page import="java.util.ArrayList"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <title></title> <link rel="stylesheet" type="text/css" href="mycss/Department.css"/> <style type="text/css"> *{ padding:0px; margin:0px; } .header{ width:100%; height:120px; text-align:center; position:relative; } .contain{ width:100%; height:780px; position:relative; } .list-group{ width:15%; float:left; } a{ text-decoration:none; width:100%; } .list-group a:hover{ font-size:18px; font-weight:bold; } .operation{ width:85%; height:780px; float:right; } iframe{ border:0px; } .loginfoshow{ position:absolute; width:auto; text-align:right; bottom:5px; right:5px; } .loginfoshow a { color:white; cursor:pointer; } .loginfoshow a:hover { color:white; } .loginfoshow p{ float:left; color:white; } </style> <script> function onl oad() { <% Cookie[] cookies=request.getCookies(); String value=""; ArrayList<Permission> list=new ArrayList<>(); if(cookies!=null){ System.out.println("cookie的长度为:"+cookies.length); for(int i=0;i<cookies.length;i++) { if(cookies[i].getName().equals("username")) { value=cookies[i].getValue(); } if(cookies[i].getName().equals("pid")) { Permission permission=new Permission(); permission.setId(Integer.parseInt(cookies[i].getValue())); list=DBUtil.getPermission(permission); } } } %> $("#informationshow").text("当前登录账户:<%=value %>"); } function exitlog(event) { var msg = "您确定要注销吗?"; if (confirm(msg)==true){ event.href="http://localhost:8080/OA/index.jsp"; } else{ alert("操作取消!"); } } </script> </head> <body onl oad="onload()"> <div class="header"> <h2>河北金力集团公文流转系统</h2> <div class="loginfoshow" id="userinfor"> <p id="informationshow"></p> <a href="" onclick="exitlog(this)">[注销]</a> </div> </div> <div class="contain"> <div class="list-group"> <%for(Permission s:list) { if(s.getPermission()==1){%> <a id="1" href="writedoc.jsp?user=<%=value %>" class="list-group-item list-group-item-aciton" target="operation">公文拟制</a> <%}else if(s.getPermission()==2){ %> <a id="2" href="getReceivedorNot?user=<%=value %>&type=received" class="list-group-item list-group-item-aciton" target="operation">签收公文</a> <%}else if(s.getPermission()==3){ %> <a id="3" href="showAll" class="list-group-item list-group-item-aciton" target="operation">浏览公文</a> <%}else if(s.getPermission()==5){ %> <a id="5" href="getDoc?type=receive" class="list-group-item list-group-item-aciton" target="operation">公文流转</a> <%}else if(s.getPermission()==6){ %> <a id="6" href="queryDoc?type=all" class="list-group-item list-group-item-aciton" target="operation">公文查询</a> <%}else if(s.getPermission()==7){ %> <a id="7" href="checkDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">审核公文</a> <%}else if(s.getPermission()==8){ %> <a id="8" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">审签公文</a> <%}} %> </div> <div class="operation"> <iframe name="operation" src="" width="100%" height="100%" style="background-color: gray;"></iframe> </div> </div> <div class="footer"></div> </body> </html>
系统管理员:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script> <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script> <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script> <title>系统管理</title> <link rel="stylesheet" type="text/css" href="mycss/Department.css"/> <style type="text/css"> *{ padding:0px; margin:0px; } .header{ width:100%; height:120px; text-align:center; position:relative; } .contain{ width:100%; height:780px; position:relative; } .list-group{ width:15%; float:left; } a{ text-decoration:none; width:100%; } .list-group a:hover{ font-size:18px; font-weight:bold; } .operation{ width:85%; height:780px; float:right; } iframe{ border:0px; } .loginfoshow{ position:absolute; width:auto; text-align:right; bottom:5px; right:5px; } .loginfoshow a { color:#D8D8D8; cursor:pointer; } .loginfoshow a:hover { color:white; } .loginfoshow p{ float:left; color:white; } </style> <script> function onl oad() { <% Cookie[] cookies=request.getCookies(); String value=""; if(cookies!=null){ System.out.println("cookie的长度为:"+cookies.length); for(int i=0;i<cookies.length;i++) { if(cookies[i].getName().equals("username")) { value=cookies[i].getValue(); break; } } } %> $("#informationshow").text("当前登录账户:"+"<%=value%>"); } function exitlog(event) { var msg = "您确定要注销吗?"; if (confirm(msg)==true){ event.href="http://localhost:8080/OA/index.jsp"; } else{ alert("操作取消!"); } } </script> </head> <body onl oad="onload()"> <div class="header"> <h2>河北金力集团后台管理系统</h2> <div class="loginfoshow" id="userinfor"> <p id="informationshow"></p> <a href="" onclick="exitlog(this)">[注销]</a> </div> </div> <div class="contain"> <div class="list-group"> <%if(value.equals("admit")){ %> <a id="1" href="getAllUser" class="list-group-item list-group-item-aciton" target="operation">用户管理</a> <%} %> <a id="2" href="" class="list-group-item list-group-item-aciton" onclick="updatepwd()">修改密码</a> </div> <div class="operation"> <iframe name="operation" src="" width="100%" height="100%" style="background-color: gray;"></iframe> </div> </div> <div class="footer"></div> </body> <script> function updatepwd() { var username="<%=value%>"; var password=prompt("请输入修改后的密码:"); if(password!=""&&password!=null) { $.post( "updateSelf", { username:username, password:password }, function(data) { if(data=="yes") alert("修改成功!"); else alert("修改失败!"); }, "text" ); } } </script> </html>
功能代码:
package com.official.bean; public class Doc { private int id; private String tipplace; private String ftipplace; private int deletestatus; private int callback; public int getCallback() { return callback; } public void setCallback(int callback) { this.callback = callback; } public int getDeletestatus() { return deletestatus; } public void setDeletestatus(int deletestatus) { this.deletestatus = deletestatus; } public String getFtipplace() { return ftipplace; } public void setFtipplace(String ftipplace) { this.ftipplace = ftipplace; } public String getTipplace() { return tipplace; } public void setTipplace(String tipplace) { this.tipplace = tipplace; } public int getId() { return id; } public void setId(int id) { this.id = id; } private String title; private String owner; private String time; private String receiver; private int status; private int result; private String place; public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getOwner() { return owner; } public void setOwner(String owner) { this.owner = owner; } public String getTime() { return time; } public void setTime(String time) { this.time = time; } public String getReceiver() { return receiver; } public void setReceiver(String receiver) { this.receiver = receiver; } public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public int getResult() { return result; } public void setResult(int result) { this.result = result; } public String getPlace() { return place; } public void setPlace(String place) { this.place = place; } }
package com.official.bean; public class Permission { private int id; private int permission; public int getId() { return id; } public void setId(int id) { this.id = id; } public int getPermission() { return permission; } public void setPermission(int permission) { this.permission = permission; } }
package com.official.bean; public class Users { private int id; private String username; private String password; private int permissionId; private int status; public int getStatus() { return status; } public void setStatus(int status) { this.status = status; } public int getId() { return id; } public void setId(int id) { this.id = id; } private String job; public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public int getPermissionId() { return permissionId; } public void setPermissionId(int permissionId) { this.permissionId = permissionId; } public String getJob() { return job; } public void setJob(String job) { this.job = job; } }package com.official.util;
//数据库连接
import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import org.apache.catalina.User; import com.official.bean.Doc; import com.official.bean.Permission; import com.official.bean.Users; public class DBUtil { //数据库URL和账号密码 private static final String connectionURL="jdbc:mysql://localhost:3306/doc_system?useUnicode=true&characterEncoding=GB18030&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true"; private static final String username="root"; private static final String password="root"; //数据库连接 public static Connection getConnection() { try { Class.forName("com.mysql.cj.jdbc.Driver"); return DriverManager.getConnection(connectionURL,username,password); } catch (Exception e) { // TODO: handle exception System.out.println("数据库连接失败"); e.printStackTrace(); return null; } } public static void closeAll(Connection connection,PreparedStatement statement,ResultSet rSet) { try { if(connection!=null) connection.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } try { if(statement!=null) statement.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } try { if(rSet!=null) rSet.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } //关闭connection和preparedstatement public static void closePart(Connection connection,PreparedStatement statement) { try { if(connection!=null) connection.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } try { if(statement!=null) statement.close(); } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } } //某表的增删改查 public static ArrayList<Doc> getDoces(String type) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql; System.out.println(type); if(type.equals("receive")) { sql="select * from doc_list where status=0 or status=2 or status=3 or status=6 or status=7 or status=-1 and deletestatus=0"; } else if(type.equals("send")) { sql="select * from doc_list where status=1 or status=4 or status=5 or status=8 or status=9 or status=10 and deletestatus=0"; } else if(type.equals("delete")) { sql="select * from doc_list where deletestatus=1"; } else { sql="select * from doc_list"; } preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); doc.setDeletestatus(rSet.getInt("deletestatus")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } //登录时验证数据库中账户是否存在 public static boolean log_isExist(Users user) { Connection con=null; PreparedStatement pstmt=null; ResultSet rs=null; try { con=getConnection(); String sql_query="select * from users where username = '"+user.getUsername()+"' and password = '"+user.getPassword()+"' and status != 0"; System.out.println(sql_query); pstmt=con.prepareStatement(sql_query); rs=pstmt.executeQuery(); if(rs.next()==false) { System.out.println("用户名或密码错误"); return false; } else { System.out.println("用户名及密码正确"); return true; } } catch (SQLException e) { System.out.println("未连接"); e.printStackTrace(); } finally { closeAll(con, pstmt, rs); } return false; } //增加公文 public static boolean add_doc(Doc doc) { Connection con=null; PreparedStatement pstmt=null; ResultSet rs=null; try { con=getConnection(); String sql="insert into doc_list(title,owner,receiver,time,status,result,place,deletestatus,callback) values(?,?,?,?,?,?,?,?,?)"; pstmt=con.prepareStatement(sql); pstmt.setString(1, doc.getTitle()); pstmt.setString(2, doc.getOwner()); pstmt.setString(3, doc.getReceiver()); pstmt.setString(4, doc.getTime()); pstmt.setInt(5, doc.getStatus()); pstmt.setInt(6, doc.getResult()); pstmt.setString(7, doc.getPlace()); pstmt.setInt(8, 0); pstmt.setInt(9, 0); pstmt.executeUpdate(); return true; } catch (SQLException e) { System.out.println("注册失败"); e.printStackTrace(); } finally { closeAll(con, pstmt, rs); } return false; } //删除数据 public static boolean delete_user(Users user) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="delete from users where id="+user.getId(); System.out.println(sql); pstmt=con.prepareStatement(sql); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static boolean update_userstatus(Users user) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update users set status = ? where id = ?"; pstmt=con.prepareStatement(sql); pstmt.setInt(1, user.getStatus()); pstmt.setInt(2, user.getId()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static boolean update_user(Users user) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update users set username=?,password=?,job=? where id = "+user.getId(); pstmt=con.prepareStatement(sql); pstmt.setString(1, user.getUsername()); pstmt.setString(2, user.getPassword()); pstmt.setString(3, user.getJob()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } @SuppressWarnings("resource") public static boolean sendDoc(int id) { Connection con=null; PreparedStatement pstmt=null; ResultSet rSet=null; int status=-1; int newstatus=-1; String receiver=""; try { con=DBUtil.getConnection(); String sql_query="select * from doc_list where id="+id; pstmt=con.prepareStatement(sql_query); rSet=pstmt.executeQuery(); if(rSet.next()) { status=rSet.getInt("status"); } switch (status) { case 0: newstatus=1; receiver="副厂长"; break; case 2: newstatus=5; receiver="厂长"; break; case 3: newstatus=4; receiver="部门"; break; case 6: newstatus=8; receiver="部门和副厂长"; break; case 7: newstatus=9; receiver="部门和副厂长"; break; case 8: newstatus=10; receiver="部门"; break; default: System.out.println("公文状态有误!"); break; } String sql_update="update doc_list set status = ? where id = ?"; pstmt=con.prepareStatement(sql_update); pstmt.setInt(1, newstatus); pstmt.setInt(2, id); pstmt.executeUpdate(); return true; } catch (SQLException e) { System.out.println("数据库信息更新失败"); e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static ArrayList<Doc> getDocesByCase(String type,String value) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql=""; System.out.println(type); if(type.equals("title")) { sql="select * from doc_list where title='"+value+"'"; } else if(type.equals("owner")) { sql="select * from doc_list where owner='"+value+"'"; } else if(type.equals("receiver")) { sql="select * from doc_list where receiver='"+value+"'"; } else if(type.equals("result")) { sql="select * from doc_list where result='"+value+"'"; } preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static ArrayList<Doc> getCheckedorNot(String type) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql=""; System.out.println(type); if(type.equals("notchecked")) { sql="select * from doc_list where status=1"; } else { sql="select * from doc_list where status!=1 and status!=0 and status!=-1"; } preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static ArrayList<Doc> getFcheckedorNot(String type) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql=""; if(type.equals("checked")) { sql="select * from doc_list where status=6 or status=7"; } else { sql="select * from doc_list where status=5"; } preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static ArrayList<Doc> getReceivedByUser(String type,Users user) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql=""; if(type.equals("received")) { sql="select * from doc_list where owner=? and status=10"; } else { sql="select * from doc_list where owner=? and status!=10"; } preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1, user.getUsername()); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setTime(rSet.getString("time")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static Doc getDocById(Doc doc) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql="select * from doc_list where id="+doc.getId(); preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); if(rSet.next()) { doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); doc.setTipplace(rSet.getString("tipplace")); doc.setFtipplace(rSet.getString("tipfplace")); return doc; } } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static boolean checked_change(Doc doc) { Connection connection=null; PreparedStatement preparedStatement=null; String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipplace = ? where id = ?"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql_update); preparedStatement.setInt(1, doc.getStatus()); preparedStatement.setInt(2, doc.getResult()); preparedStatement.setString(3, doc.getReceiver()); preparedStatement.setString(4, doc.getTipplace()); preparedStatement.setInt(5, doc.getId()); preparedStatement.executeUpdate(); return true; } catch (SQLException e) {
// TODO 自动生成的 catch 块
e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return false; } public static boolean fchecked_change(Doc doc) { Connection connection=null; PreparedStatement preparedStatement=null; String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipfplace = ? where id = ?"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql_update); preparedStatement.setInt(1, doc.getStatus()); preparedStatement.setInt(2, doc.getResult()); preparedStatement.setString(3, doc.getReceiver()); preparedStatement.setString(4, doc.getFtipplace()); preparedStatement.setInt(5, doc.getId()); preparedStatement.executeUpdate(); return true; } catch (SQLException e) { // TODO 自动生成的 catch 块
e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return false; } public static boolean formatDoc(Doc doc) { Connection connection=null; PreparedStatement preparedStatement=null; String sql_update="update doc_list set status = ? where id = ?"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql_update); preparedStatement.setInt(1, doc.getStatus()); preparedStatement.setInt(2, doc.getId()); preparedStatement.executeUpdate(); return true; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return false; } public static boolean ReceiveDoc(Doc doc) { Connection connection=null; PreparedStatement preparedStatement=null; String sql_update="update doc_list set status = ?,callback = 1 where id = ?"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql_update); preparedStatement.setInt(1, 10); preparedStatement.setInt(2, doc.getId()); preparedStatement.executeUpdate(); return true; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return false; } public static ArrayList<Doc> getDocByTime(Doc doc1,Doc doc2) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from doc_list where time between ? and ?"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); preparedStatement.setString(1,doc1.getTime()); preparedStatement.setString(2, doc2.getTime()); rs=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rs.next()) { Doc doc=new Doc(); doc.setId(rs.getInt("id")); doc.setTitle(rs.getString("title")); doc.setTime(rs.getString("time")); doc.setOwner(rs.getString("owner")); list.add(doc); } return list; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static ArrayList<Doc> getAllDoc() { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from doc_list"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rs.next()) { Doc doc=new Doc(); doc.setId(rs.getInt("id")); doc.setTitle(rs.getString("title")); doc.setTime(rs.getString("time")); doc.setOwner(rs.getString("owner")); list.add(doc); } return list; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static ArrayList<Users> getAllUser() { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from users"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); ArrayList<Users> list=new ArrayList<>(); while(rs.next()) { Users user=new Users(); user.setId(rs.getInt("id")); user.setUsername(rs.getString("username")); user.setPassword(rs.getString("password")); user.setPermissionId(rs.getInt("permissionId")); user.setJob(rs.getString("job")); user.setStatus(rs.getInt("status")); list.add(user); } return list; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static Users getUserById(Users user) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from users where id="+user.getId(); try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); Users user1=new Users(); if(rs.next()) { user1.setId(rs.getInt("id")); user1.setUsername(rs.getString("username")); user1.setPassword(rs.getString("password")); user1.setPermissionId(rs.getInt("permissionId")); user1.setStatus(rs.getInt("status")); user1.setJob(rs.getString("job")); } return user1; } catch (SQLException e) { // TODO �Զ����ɵ� catch �� e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static ArrayList<Permission> getPermission(Permission permission) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from permission where id="+permission.getId(); try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); ArrayList<Permission> list=new ArrayList<>(); while(rs.next()) { Permission permission1=new Permission(); permission1.setId(rs.getInt("id")); permission1.setPermission(rs.getInt("permission")); list.add(permission1); } return list; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static boolean deletePermission(Permission permission) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="delete from permission where id="+permission.getId(); System.out.println(sql); pstmt=con.prepareStatement(sql); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static boolean updatePermission(Permission permission1,Permission permission2) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update permission set permission = ? where id = ? and permission = ?"; pstmt=con.prepareStatement(sql); pstmt.setInt(1, permission2.getPermission()); pstmt.setInt(2, permission1.getId()); pstmt.setInt(3, permission1.getPermission()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static boolean updatePwd(Users user) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update users set password = ? where username = ?"; pstmt=con.prepareStatement(sql); pstmt.setString(1, user.getPassword()); pstmt.setString(2, user.getUsername()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static Users getUserByUsername(Users user) { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rs=null; String sql="select * from users where username='"+user.getUsername()+"'"; try { connection=getConnection(); preparedStatement=connection.prepareStatement(sql); rs=preparedStatement.executeQuery(); Users user1=new Users(); if(rs.next()) { user1.setId(rs.getInt("id")); user1.setPermissionId(rs.getInt("permissionId")); System.out.println(user1.getPermissionId()); } return user1; } catch (SQLException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } finally { closePart(connection, preparedStatement); } return null; } public static boolean deleteDoc(Doc doc) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update doc_list set deletestatus = ? where id = ?"; pstmt=con.prepareStatement(sql); pstmt.setInt(1, doc.getDeletestatus()); pstmt.setInt(2, doc.getId()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static ArrayList<Doc> getCall() { Connection connection=null; PreparedStatement preparedStatement=null; ResultSet rSet=null; try { connection=getConnection(); String sql="select * from doc_list where callback=1"; preparedStatement=connection.prepareStatement(sql); rSet=preparedStatement.executeQuery(); ArrayList<Doc> list=new ArrayList<>(); while(rSet.next()) { Doc doc=new Doc(); doc.setId(rSet.getInt("id")); doc.setTitle(rSet.getString("title")); doc.setOwner(rSet.getString("owner")); doc.setTime(rSet.getString("time")); doc.setReceiver(rSet.getString("receiver")); doc.setStatus(rSet.getInt("status")); doc.setResult(rSet.getInt("result")); doc.setPlace(rSet.getString("place")); doc.setDeletestatus(rSet.getInt("deletestatus")); doc.setCallback(rSet.getInt("callback")); list.add(doc); } return list; } catch (SQLException e) { // TODO: handle exception e.printStackTrace(); } finally { closeAll(connection, preparedStatement, rSet); } return null; } public static boolean setCallOver(Doc doc) { Connection con=null; PreparedStatement pstmt=null; try { con=getConnection(); String sql="update doc_list set callback = ? where id = ?"; pstmt=con.prepareStatement(sql); pstmt.setInt(1, 0); pstmt.setInt(2, doc.getId()); pstmt.executeUpdate(); return true; } catch(SQLException e) { e.printStackTrace(); } finally { closePart(con, pstmt); } return false; } public static void main(String[] args) { //getConnection(); } }
com.official.servlet