公文流转系统开发流程

1、项目需求:

河北金力集团是我省机械加工的龙头企业,主要从事矿山机械制造及各种机械零部件加工。企业有3个厂区,主厂区位于省高新技术开发区,3个分厂分别在保定、邢台和唐山。为增加企业的核心竞争力和加强管理的科学程度,近期企业将在全集团实行ERP管理,建立网页版公文流转系统。具体部门:主厂区、一分厂、二分厂、三分厂、销售部门、财务部门、办公室;领导:三位副厂长(分别管理生产、销售、财务)、一位厂长。

公文流转的流程:

 

2. 板块功能需求

(1)、页面要求

① 能适应800*600或1024*768分辨率;

② 布局合理、结构清晰、页面完整;

③ 有效页面数在8页以上;

④ 分页与主页风格统一;

⑤ 首页(登录页):用户登录页(共有十位用户帐号,帐号、密码可预设)。不同用户登录后,进入的功能页不相同,要求密码在数据库中加密。

⑥ 部门(不含办公室)功能页:有公文拟制、签收公文、浏览公文(已签收的公文)三个模块

⑦ 办公室功能页:有修改公文、公文流转、删除公文、公文发送等功能。

⑧ 副厂长功能页:有审核公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。

⑨ 厂长功能页:有审签公文(修改并签意见)、浏览已发所有公文、查询公文三个模块。

⑩ 系统管理功能页:有用户管理、角色管理、公文流转流程管理。

(2)、功能设计:

  1. 公文拟制:创建新的电子公文,对创建的电子公文进行上传操作。
  2. 签收公文:当接收方接收公文后,会给发送方发回执信息,确认公文已经收到。
  3. 浏览公文(已签收的公文):

1) 选择日期段。

2) 通过“查询”功能,显示该时间段内已通过审签的正式公文。

3) 点击公文标题,将会显示出该公文的具体信息。

  1. 修改公文:对拟制好的的电子公文进行格式化处理操作,套用公文样例。
  2. 公文流转:按照公文流转流程设定公文接收用户。
  3. 删除公文:如果该公文没有通过审核或审签,需要删除可以利用“删除”功能。确定后,系统提示公文删除成功,删除的公文将在“被删除公文”模块中的显示。
  4. 公文发送:操作员要根据单位管理员选择的公文的流程进行公文的流转发送,实现待发公文和已发送公文的管理
  5. 审核公文(修改并签意见):签署审核意见和修改意见,并将退回办公室。
  6. 有审签公文(修改并签意见):签署审前意见和修改意见,若同意,则生成正式公文并交由办公室转发。
  7. 浏览已发所有公文:按日期查看所有已发公文,点击标题可查看具体信息。
  8. 公文查询:是查询由公文交换系统处理过的公文,并且建立或检查公文详尽的索引信息。可以根据发送机构、接收机构、公文种类和其它开放信息进行公文数据查询。
  9. 系统管理:

a)  角色配置管理

  1. 用户权限维护功能:实现对用户的角色管理。
  2. 角色维护功能:实现对角色权限的管理,主要有编辑、增加和删除操作。

b) 用户管理:查看用户、新开用户、暂停用户、用户信息修改、删除用户

c) 单位管理员设置功能:每个单位的操作员实现修改密码、修改个人信息。

数据库设计思路如下:

(1)首先根据用户的角色及相应权限设计用户表

(2)根据用户父权限ID建立用户权限表

 

(3)根据公文流转状态建立公文数据表

前端主要设计思路:

(1)登录界面:包含两个按钮,使用其click事件利用ajax向不同servlet发送登录请求控制登录页面的不同跳转

   主要js代码如下

 1 function login()
 2     {
 3         var username=$("#username").val();
 4         var password=$("#password").val();
 5         if(username==""||password=="")
 6             alert("请将信息填写完整!");
 7         else
 8         {
 9             $.post(
10                 "login_do",
11                 {username:username,
12                     password:password},
13                 function(data){
14                     if(data=="yes")
15                     {
16                         alert("成功登陆!");
17                         window.location="mainpage.jsp";
18                     }
19                     else
20                         alert("用户名或密码错误!或用户已被暂停使用!");
21                 },
22                 "text"
23             );
24         }
25     }
26     function entermang()
27     {
28         var username=$("#username").val();
29         var password=$("#password").val();
30         if(username==""||password=="")
31             alert("请将信息填写完整!");
32         else
33         {
34             $.post(
35                 "login_do",
36                 {username:username,
37                     password:password},
38                 function(data){
39                     if(data=="yes")
40                     {
41                         alert("成功登陆!");
42                         window.location="backmainpage.jsp";
43                     }
44                     else
45                         alert("用户名或密码错误!或用户已被暂停使用!");
46                 },
47                 "text"
48             );
49         }
50     }
View Code

   主要servlet代码如下:

 1 package com.official.servlet;
 2 
 3 import java.io.IOException;
 4 
 5 import javax.servlet.ServletException;
 6 import javax.servlet.annotation.WebServlet;
 7 import javax.servlet.http.Cookie;
 8 import javax.servlet.http.HttpServlet;
 9 import javax.servlet.http.HttpServletRequest;
10 import javax.servlet.http.HttpServletResponse;
11 
12 import com.official.bean.Users;
13 import com.official.util.DBUtil;
14 
15 /**
16  * Servlet implementation class login_do
17  */
18 @WebServlet("/login_do")
19 public class login_do extends HttpServlet {
20     private static final long serialVersionUID = 1L;
21        
22     
23     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
24         // TODO Auto-generated method stub
25         response.getWriter().append("Served at: ").append(request.getContextPath());
26     }
27 
28     /**
29      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
30      */
31     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
32         // TODO Auto-generated method stub
33         String username=request.getParameter("username");
34         String password=request.getParameter("password");
35         Users user=new Users();
36         user.setUsername(username);
37         user.setPassword(password);
38         if(DBUtil.log_isExist(user))
39         {
40             Cookie cookie=new Cookie("username", username);
41             cookie.setPath("/");
42             //设置存活时间
43             cookie.setMaxAge(60*60*24);
44             response.addCookie(cookie);
45             Users users=DBUtil.getUserByUsername(user);
46             int pid=users.getPermissionId();
47             Cookie cookie2=new Cookie("pid", Integer.toString(pid));
48             cookie2.setPath("/");
49             cookie2.setMaxAge(60*60*24);
50             response.addCookie(cookie2);
51             response.getWriter().write("yes");
52         }
53         else
54         {
55             response.getWriter().write("no");
56         }
57     }
58 
59 }
View Code

(2)主界面:通过获取权限id来控制导航栏显示的内容

     jsp代码如下:

  1 <%@page import="com.official.util.DBUtil"%>
  2 <%@page import="com.official.bean.Permission"%>
  3 <%@page import="org.apache.jasper.tagplugins.jstl.core.ForEach"%>
  4 <%@page import="java.util.ArrayList"%>
  5 <%@ page language="java" contentType="text/html; charset=utf-8"
  6     pageEncoding="utf-8"%>
  7 <!DOCTYPE html>
  8 <html>
  9 <head>
 10 <meta name="viewport" content="width=device-width, initial-scale=1">
 11  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
 12  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
 13  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
 14  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
 15 <title>Insert title here</title>
 16 <style type="text/css">
 17 *{
 18 padding:0px;
 19 margin:0px;
 20 }
 21 .header{
 22 100%;
 23 height:120px;
 24 background-color:brown;
 25 text-align:center;
 26 position:relative;
 27 }
 28 .contain{
 29 100%;
 30 height:780px;
 31 position:relative;
 32 background-color:blue;
 33 }
 34 .list-group{
 35 15%;
 36 float:left;
 37 }
 38 a{
 39 text-decoration:none;
 40 100%;
 41 }
 42 .list-group a:hover{
 43 font-size:18px;
 44 font-weight:bold;
 45 }
 46 .operation{
 47 85%;
 48 height:780px;
 49 float:right;
 50 }
 51 iframe{
 52 border:0px;
 53 }
 54 .loginfoshow{
 55 position:absolute;
 56 auto;
 57 text-align:right;
 58 bottom:5px;
 59 right:5px;
 60 }
 61 .loginfoshow a
 62 {
 63 color:#D8D8D8;
 64 cursor:pointer;
 65 }
 66 .loginfoshow a:hover
 67 {
 68 color:white;
 69 }
 70 .loginfoshow p{
 71 float:left;
 72 color:white;
 73 }
 74 
 75 </style>
 76 <script>
 77 function onload()
 78 {
 79     <%
 80     Cookie[] cookies=request.getCookies();
 81     String value="";
 82     ArrayList<Permission> list=new ArrayList<>();
 83     if(cookies!=null){
 84         System.out.println("cookie的长度为:"+cookies.length);
 85         for(int i=0;i<cookies.length;i++)
 86         {
 87             if(cookies[i].getName().equals("username"))
 88             {
 89                 value=cookies[i].getValue();
 90             }
 91             if(cookies[i].getName().equals("pid"))
 92             {
 93                 Permission permission=new Permission();
 94                 permission.setId(Integer.parseInt(cookies[i].getValue()));
 95                 list=DBUtil.getPermission(permission);
 96             }
 97         }
 98     }
 99     %>
100     $("#informationshow").text("当前登录账户:<%=value %>");
101 }
102 function exitlog(event)
103 {
104     var msg = "您确定要注销吗?"; 
105     if (confirm(msg)==true){ 
106         event.href="http://localhost:8080/official-document/index.jsp";
107     }
108     else{
109         alert("操作取消!");
110     }
111 }
112 </script>
113 </head>
114 <body onload="onload()">
115     <div class="header">
116         <h2>河北金力集团公文流转系统</h2>
117         <div class="loginfoshow" id="userinfor">
118             <p id="informationshow"></p>
119             &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
120             <a href="" onclick="exitlog(this)">[注销]</a>
121         </div>
122     </div>
123     <div class="contain">
124         <div class="list-group">
125             <%for(Permission s:list)
126             {
127             if(s.getPermission()==1){%>
128             <a id="1" href="writedoc.jsp?user=<%=value %>" class="list-group-item list-group-item-aciton" target="operation">公文拟制</a>
129             <%}else if(s.getPermission()==2){ %>
130             <a id="2" href="getReceivedorNot?user=<%=value %>&type=received" class="list-group-item list-group-item-aciton" target="operation">签收公文</a>
131             <%}else if(s.getPermission()==3){  %>
132             <a id="3" href="showAll" class="list-group-item list-group-item-aciton" target="operation">浏览公文</a>
133             <%}else if(s.getPermission()==5){  %>
134             <a id="5" href="getDoc?type=receive" class="list-group-item list-group-item-aciton" target="operation">公文流转</a>
135             <%}else if(s.getPermission()==6){  %>
136             <a id="6" href="queryDoc?type=all" class="list-group-item list-group-item-aciton" target="operation">公文查询</a>
137             <%}else if(s.getPermission()==7){  %>
138             <a id="7" href="checkDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">审核公文</a>
139             <%}else if(s.getPermission()==8){  %>
140             <a id="8" href="fcheckDoc?type=notchecked" class="list-group-item list-group-item-aciton" target="operation">审签公文</a>
141             <%}} %>
142         </div>
143         <div class="operation">
144             <iframe name="operation" src="" width="100%" height="100%" style="background-color: gray;"></iframe>
145         </div>
146     </div>
147     <div class="footer"></div>
148 </body>
149 </html>
View Code

(3)拟制公文:通过cookie记录的用户名,以及前端输入的标题和内容,将填入的公文内容及标题传到servlet,通过txt文件保存到服务器的文件夹

 1 package com.official.servlet;
 2 
 3 import java.io.File;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 import java.text.SimpleDateFormat;
 8 import java.util.Date;
 9 
10 import javax.servlet.ServletException;
11 import javax.servlet.annotation.WebServlet;
12 import javax.servlet.http.HttpServlet;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15 
16 import com.official.bean.Doc;
17 import com.official.util.DBUtil;
18 
19 /**
20  * Servlet implementation class writedoc_do
21  */
22 @WebServlet("/writedoc_do")
23 public class writedoc_do extends HttpServlet {
24     private static final long serialVersionUID = 1L;
25        
26     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27         // TODO Auto-generated method stub
28         response.getWriter().append("Served at: ").append(request.getContextPath());
29     }
30 
31     /**
32      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
33      */
34     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35         // TODO Auto-generated method stub
36         String text=request.getParameter("text");
37         String user=request.getParameter("user");
38         String title=request.getParameter("title");
39         System.out.println(text);
40         Date date = new Date();
41         SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
42         String time=dateFormat.format(date).toString();
43         String path="E:\work_space\official-document\WebContent\text\"+title+"_"+user+"_"+time.split(":| ")[0]+time.split(":| ")[1]+time.split(":| ")[2]+time.split(":| ")[3]+".txt";
44         System.out.println(path);
45         File file = new File(path);
46         FileOutputStream fileOutputStream;
47         
48         Doc doc=new Doc();
49         doc.setTitle(title);
50         doc.setOwner(user);
51         doc.setReceiver("办公室");
52         doc.setTime(time);
53         doc.setStatus(-1);
54         doc.setResult(0);
55         doc.setPlace(path);
56         if(DBUtil.add_doc(doc))
57         {
58             try {
59                 fileOutputStream = new FileOutputStream(file);
60                  try {
61                     fileOutputStream.write((text).getBytes());
62                     fileOutputStream.close();
63                     response.getWriter().write("yes");
64                     
65                 } catch (IOException e) {
66                     // TODO 自动生成的 catch 块
67                     response.getWriter().write("no");
68                     e.printStackTrace();
69                 }
70                 
71             } catch (FileNotFoundException e) {
72                 // TODO 自动生成的 catch 块
73                 response.getWriter().write("no");
74                 e.printStackTrace();
75             }
76         }
77         else
78         {
79             response.getWriter().write("no");
80         }
81     }
82 
83 }
View Code

(4)公文流转:通过dao层内置switch语句控制公文在办公室的流转,根据公文的不同当前状态修改公文流转后的状态

  jsp代码如下:

  1 <%@page import="com.official.util.DBUtil"%>
  2 <%@page import="com.official.bean.Doc"%>
  3 <%@page import="java.util.ArrayList"%>
  4 <%@ page language="java" contentType="text/html; charset=utf-8"
  5     pageEncoding="utf-8"%>
  6 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
  7 <!DOCTYPE html>
  8 <html>
  9 <head>
 10 <meta name="viewport" content="width=device-width, initial-scale=1">
 11  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
 12  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
 13  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
 14  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
 15 <title>Insert title here</title>
 16 </head>
 17 <body>
 18     <div>
 19         <nav class="navbar navbar-expand-sm bg-light">
 20             <ul class="navbar-nav">
 21                 <li class="nav-item">
 22                     <a class="nav-link" href="getDoc?type=receive">待发公文</a>
 23                 </li>
 24                 <li class="nav-item">
 25                     <a class="nav-link" href="getDoc?type=send">已发公文</a>
 26                 </li>
 27                 <li class="nav-item">
 28                     <a class="nav-link" href="getDoc?type=delete">已删除公文</a>
 29                 </li>
 30                 <li class="nav-item">
 31                     <a class="nav-link" href="showCall">消息提醒</a>
 32                 </li>
 33             </ul>
 34         </nav>
 35     </div>
 36     <div>
 37         <table class="table table-hover table-striped table-bordered table-sm" id="table">
 38             <tr>
 39                 <th>公文编号</th>
 40                 <th>公文标题</th>
 41                 <th>发送时间</th>
 42                 <th>发送机构</th>
 43                 <th>公文状态</th>
 44                 <th>审核结果</th>
 45                 <th>流转状态</th>
 46                 <th>保存状态</th>
 47                 <th>格式化公文</th>
 48                 <th>发送操作</th>
 49                 <th>删除操作</th>
 50             </tr>
 51             <%ArrayList<Doc> list=(ArrayList<Doc>)request.getAttribute("list");%>
 52             <c:forEach var="l" items="<%=list %>" varStatus="i">
 53                 <tr>
 54                     <td id="id${i.index+1 }">${l.getId() }</td>
 55                     <td>${l.getTitle() }</td>
 56                     <td>${l.getTime() }</td>
 57                     <td>${l.getOwner() }</td>
 58                     <td id="status${i.index+1 }">${l.getStatus() }</td>
 59                     <td>${l.getResult() }</td>
 60                     <td>${l.getReceiver() }</td>
 61                     <td id="delete${i.index+1 }">${l.getDeletestatus() }</td>
 62                     <td><a href="#" onclick="revise(${i.index+1})">格式化</a></td>
 63                     <td><a href="#" onclick="send(${i.index+1})">发送</a></td>
 64                     <td><a href="#" onclick="deletedoc(${i.index+1})">删除</a></td>
 65                 </tr>
 66             </c:forEach>
 67         </table>
 68     </div>
 69 </body>
 70 <script>
 71     function send(i)
 72     {
 73         
 74         var status=$("#status"+i).text();
 75         if(status=="-1")
 76             alert("请先格式化该公文!");
 77         else if(status==1||status==4||status==5||status==8||status==9||status==10)
 78             alert("该公文已流转到相应部门,不具备发送权限!");
 79         else
 80         {
 81             var id=$("#id"+i).text();
 82             $.post(
 83                 "sendDoc",
 84                 {id:id},
 85                 function(data){
 86                     if(data=="yes")
 87                     {
 88                         alert("发送成功!");
 89                         window.location="getDoc?type=receive";
 90                     }
 91                     else
 92                         alert("发送失败!");
 93                 },
 94                 "text"
 95             );
 96         }
 97     }
 98         function revise(i)
 99         {
100             var status=$("#status"+i).text();
101             if(status!=-1)
102                 alert("该公文已经格式化!");
103             else
104             {
105                 var id=$("#id"+i).text();
106                 $.post(
107                     "formatDoc",
108                     {id:id,
109                         status:status},
110                     function(data){
111                         if(data=="yes")
112                         {
113                             alert("格式化成功!");
114                             window.location="getDoc?type=receive";
115                         }
116                         else
117                             alert("格式化失败!");
118                     },
119                     "text"
120                 );
121             }
122         }
123         
124         function deletedoc(i)
125         {
126             var deletestatus=$("#delete"+i).text();
127             if(deletestatus=="1")
128             {
129                 alert("该公文已删除!");
130             }
131             else{
132                 var msg = "确定删除?"; 
133                 if (confirm(msg)==true){
134                     var status=$("#status"+i).text();
135                     if(status==2||status==5||status==6||status==8)
136                         alert("该公文审核或审签已通过,不能删除!")
137                     else if(status!=10)
138                         alert("该公文还为被有关部门签收,不能删除!");
139                     else{
140                         var id=$("#id"+i).text();
141                         $.post(
142                             "deleteDoc",
143                             {id:id},
144                             function(data){
145                                 if(data=="yes")
146                                 {
147                                     alert("删除成功!");
148                                     window.location="getDoc?type=delete";
149                                 }
150                                 else
151                                     alert("删除失败!");
152                             },
153                             "text"
154                         );
155                     }
156                 }
157                 else{
158                     alert("操作取消!");
159                 }
160             }    
161         }
162         
163     
164 </script>
165 </html>
View Code

      servlet代码如下:

 1 package com.official.servlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 import com.official.util.DBUtil;
11 
12 /**
13  * Servlet implementation class sendDoc
14  */
15 @WebServlet("/sendDoc")
16 public class sendDoc extends HttpServlet {
17     private static final long serialVersionUID = 1L;
18        
19     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
20         // TODO Auto-generated method stub
21         response.getWriter().append("Served at: ").append(request.getContextPath());
22     }
23 
24     /**
25      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
26      */
27     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
28         // TODO Auto-generated method stub
29         int id=Integer.parseInt(request.getParameter("id"));
30         if(DBUtil.sendDoc(id))
31         {
32             response.getWriter().write("yes");
33         }
34         else
35         {
36             response.getWriter().write("no");
37         }
38     }
39 
40 }
View Code

(5)公文审核和审签:通过读入公文.txt文件达到浏览公文的目的,并将副厂长或厂长填写的意见保存到相应文件夹,方便有关部门查看

  jsp代码如下:

  1 <%@page import="java.io.FileNotFoundException"%>
  2 <%@page import="java.io.IOException"%>
  3 <%@page import="java.io.InputStreamReader"%>
  4 <%@page import="java.io.BufferedReader"%>
  5 <%@page import="java.io.FileInputStream"%>
  6 <%@page import="com.official.bean.Doc"%>
  7 <%@page import="java.util.ArrayList"%>
  8 <%@ page language="java" contentType="text/html; charset=utf-8"
  9     pageEncoding="utf-8"%>
 10 <!DOCTYPE html>
 11 <html>
 12 <head>
 13 <meta name="viewport" content="width=device-width, initial-scale=1">
 14  <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
 15  <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>
 16  <script src="https://cdn.staticfile.org/popper.js/1.15.0/umd/popper.min.js"></script>
 17  <script src="https://cdn.staticfile.org/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
 18 <title>Insert title here</title>
 19 <style type="text/css">
 20 .contain{
 21 width:100%;
 22 position:relative;
 23 margin-top:40px;
 24 border:1px solid black;
 25 height:400px;
 26 overflow-y:auto;
 27 }
 28 .title{
 29 width:100%;
 30 text-align:center;
 31 margin-top:20px;
 32 }
 33 .underline{
 34 width:100%;
 35 text-align:center;
 36 }
 37 .tip{
 38 width:100%;
 39 text-align:center;
 40 }
 41 .doctitle{
 42 width:100%;
 43 text-align:center;
 44 }
 45 .content{
 46 margin-left:10px;
 47 margin-right:10px;
 48 margin-top:10px;
 49 }
 50 .time{
 51 position:absolute;
 52 bottom:20px;
 53 right:10px;
 54 }
 55 .suggestion{
 56 width:100%;
 57 height:180px;
 58 }
 59 .writesuggest{
 60 width:100%;
 61 height:200px;
 62 text-align:center;
 63 }
 64 .btn{
 65 width:150px;
 66 height:40px;
 67 border:0px;
 68 border-radius:5px;
 69 background-color:orange;
 70 color:black;
 71 margin-left:auto;
 72 margin-top:10px
 73 }
 74 </style>
 75 </head>
 76 <body>
 77     <%Doc doc=(Doc)request.getAttribute("doc"); %>
 78     <div>公文来源:<%=doc.getOwner() %>&nbsp;&nbsp;&nbsp;&nbsp;发送日期:<%=doc.getTime() %></div>
 79     <div class="contain">
 80         <div class="title"><h2>河北金立集团文件</h2></div>
 81         <%if(doc.getOwner().equals("salespart")){ %>
 82         <div class="tip">厂[售] [2019] *号</div>
 83         <%}else if(doc.getOwner().equals("financepart")){ %>
 84         <div class="tip">厂[财] [2019] *号</div>
 85         <%}else{ %>
 86         <div class="tip">厂[产] [2019] *号</div>
 87         <%} 
 88         FileInputStream fileInputStream;
 89         String text="";
 90         try {
 91             fileInputStream = new FileInputStream(doc.getPlace());
 92             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(fileInputStream));
 93             String line = null;
 94             try {
 95                 while ((line = bufferedReader.readLine()) != null) {
 96                     text+=line;
 97                 }
 98             } catch (IOException e) {
 99                 // TODO 自动生成的 catch 块
100                 e.printStackTrace();
101             }
102 
103             fileInputStream.close();
104         } catch (FileNotFoundException e1) {
105             // TODO 自动生成的 catch 块
106             e1.printStackTrace();
107         } catch (IOException e) {
108             // TODO 自动生成的 catch 块
109             e.printStackTrace();
110         }
111         if(text.equals("")!=true){
112         %>
113         <div class="underline">-------------------------------------------------</div>
114         <div class="doctitle"><%=doc.getTitle() %></div>
115         <div class="content"><%=text %></div>
116         <%}else{ %>
117         <div class="underline">-------------------------------------------------</div>
118         <div class="doctitle"><%=doc.getTitle() %></div>
119         <div class="content">公文内容读取失败!</div>
120         <%} 
121         String time=doc.getTime();
122         String[] date=time.split("-");
123         %>
124         <div class="time"><%=date[0] %><%=date[1] %><%=date[2] %></div>
125     </div>
126     <div class="writesuggest">
127         <div><h4>请在下方输入审核意见和修改意见:</h4></div>
128         <textarea rows="20" cols="20" class="suggestion" id="suggestion"></textarea>
129         <div class="radio">
130             <label>是否同意该公文:</label>
131             <label class="radio-inline"><input type="radio" name="result" value="1">同意</label>
132             <label class="radio-inline"><input type="radio" name="result" value="0">不同意</label>
133         </div>
134         <input type="button" value="确认修改" class="btn" onclick="writesug()">
135     </div>
136 </body>
137 <script>
138         function writesug()
139         {
140             var val=$('input:radio[name="result"]:checked').val();
141             var id=<%=doc.getId()%>;
142             var tip=$("#suggestion").val();
143             if(val==null)
144             {
145                 alert("请勾选是否同意该公文选项!");
146             }
147             else{
148                 $.post(
149                     "checked_change",
150                     {
151                         id:id,
152                         result:val,
153                         tip:tip
154                     },
155                     function(data)
156                     {
157                         if(data=="yes")
158                         {
159                             alert("操作成功!");
160                             window.location="checkDoc?type=notchecked";
161                         }
162                         else
163                             alert("操作失败!");
164                     
165                     },
166                     "text"
167                 );
168             }
169         }
170 </script>
171 </html>
View Code

  servlet代码如下:

 1 package com.official.servlet;
 2 
 3 import java.io.File;
 4 import java.io.FileNotFoundException;
 5 import java.io.FileOutputStream;
 6 import java.io.IOException;
 7 import java.text.SimpleDateFormat;
 8 import java.util.Date;
 9 
10 import javax.servlet.ServletException;
11 import javax.servlet.annotation.WebServlet;
12 import javax.servlet.http.HttpServlet;
13 import javax.servlet.http.HttpServletRequest;
14 import javax.servlet.http.HttpServletResponse;
15 
16 import com.official.bean.Doc;
17 import com.official.util.DBUtil;
18 
19 /**
20  * Servlet implementation class checked_change
21  */
22 @WebServlet("/checked_change")
23 public class checked_change extends HttpServlet {
24     private static final long serialVersionUID = 1L;
25        
26     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
27         // TODO Auto-generated method stub
28         response.getWriter().append("Served at: ").append(request.getContextPath());
29     }
30 
31     /**
32      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
33      */
34     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
35         // TODO Auto-generated method stub
36         int id=Integer.parseInt(request.getParameter("id"));
37         int result=Integer.parseInt(request.getParameter("result"));
38         String tip=request.getParameter("tip");
39         Date date = new Date();
40         SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd-hh-mm-ss");
41         String time=dateFormat.format(date).toString();
42         String path="E:\work_space\official-document\WebContent\tip\"+id+"_"+time+"_tip.txt";
43         File file = new File(path);
44         FileOutputStream fileOutputStream;
45         
46         int status;
47         if(result==0)
48             status=3;
49         else
50             status=2;
51         Doc doc=new Doc();
52         doc.setId(id);
53         doc.setResult(result);
54         doc.setStatus(status);
55         doc.setReceiver("办公室");
56         doc.setTipplace(path);
57         if(DBUtil.checked_change(doc))
58         {
59             try {
60                 fileOutputStream = new FileOutputStream(file);
61                  try {
62                     fileOutputStream.write((tip).getBytes());
63                     fileOutputStream.close();
64                     response.getWriter().write("yes");
65                     
66                 } catch (IOException e) {
67                     // TODO 自动生成的 catch 块
68                     response.getWriter().write("no");
69                     e.printStackTrace();
70                 }
71                 
72             } catch (FileNotFoundException e) {
73                 // TODO 自动生成的 catch 块
74                 response.getWriter().write("no");
75                 e.printStackTrace();
76             }
77         }
78         else
79             response.getWriter().write("no");
80         
81     }
82 
83 }
View Code

(6)公文的签收:通过接收对应公文的状态码判断是否达到签收条件,点击签收,更改公文最终状态为签收

  servlet代码如下:

 1 package com.official.servlet;
 2 
 3 import java.io.IOException;
 4 import javax.servlet.ServletException;
 5 import javax.servlet.annotation.WebServlet;
 6 import javax.servlet.http.HttpServlet;
 7 import javax.servlet.http.HttpServletRequest;
 8 import javax.servlet.http.HttpServletResponse;
 9 
10 import com.official.bean.Doc;
11 import com.official.util.DBUtil;
12 
13 /**
14  * Servlet implementation class doReceived
15  */
16 @WebServlet("/doReceived")
17 public class doReceived extends HttpServlet {
18     private static final long serialVersionUID = 1L;
19        
20     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
21         // TODO Auto-generated method stub
22         response.getWriter().append("Served at: ").append(request.getContextPath());
23     }
24 
25     /**
26      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
27      */
28     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
29         // TODO Auto-generated method stub
30         int id=Integer.parseInt(request.getParameter("id"));
31         System.out.println(id);
32         Doc doc=new Doc();
33         doc.setId(id);
34         if(DBUtil.ReceiveDoc(doc))
35             response.getWriter().write("yes");
36         else
37             response.getWriter().write("no");
38     }
39 
40 }
View Code

下面附上dao层数据库操作代码:

  1 package com.official.util;
  2 
  3 import java.sql.Connection;
  4 import java.sql.DriverManager;
  5 import java.sql.PreparedStatement;
  6 import java.sql.ResultSet;
  7 import java.sql.SQLException;
  8 import java.util.ArrayList;
  9 
 10 import org.apache.catalina.User;
 11 
 12 import com.official.bean.Doc;
 13 import com.official.bean.Permission;
 14 import com.official.bean.Users;
 15 
 16 
 17 public class DBUtil {
 18     //数据库URL和账号密码
 19     private static final String connectionURL="jdbc:mysql://127.0.0.1:3306/doc_system?useUnicode=true&characterEncoding=GB18030&useSSL=false&serverTimezone=GMT&allowPublicKeyRetrieval=true";
 20     private static final String username="root";
 21     private static final String password="010218";
 22     
 23     //数据库连接
 24     public static Connection getConnection()
 25     {
 26         try {
 27             Class.forName("com.mysql.cj.jdbc.Driver");
 28             return DriverManager.getConnection(connectionURL,username,password);
 29         } catch (Exception e) {
 30             // TODO: handle exception
 31             System.out.println("数据库连接失败");
 32             e.printStackTrace();
 33             return null;
 34         }
 35     }
 36     public static void closeAll(Connection connection,PreparedStatement statement,ResultSet rSet)
 37     {
 38         try {
 39             if(connection!=null)
 40                 connection.close();
 41         } catch (SQLException e) {
 42             // TODO 自动生成的 catch 块
 43             e.printStackTrace();
 44         }
 45     
 46         try {
 47             if(statement!=null)
 48                 statement.close();
 49         } catch (SQLException e) {
 50             // TODO 自动生成的 catch 块
 51             e.printStackTrace();
 52         }
 53     
 54         try {
 55             if(rSet!=null)
 56                 rSet.close();
 57         } catch (SQLException e) {
 58             // TODO 自动生成的 catch 块
 59             e.printStackTrace();
 60         }
 61     }
 62         
 63     //关闭connection和preparedstatement
 64     public static void closePart(Connection connection,PreparedStatement statement)
 65     {
 66         try {
 67             if(connection!=null)
 68                 connection.close();
 69         } catch (SQLException e) {
 70             // TODO 自动生成的 catch 块
 71             e.printStackTrace();
 72         }
 73     
 74         try {
 75             if(statement!=null)
 76                 statement.close();
 77         } catch (SQLException e) {
 78             // TODO 自动生成的 catch 块
 79             e.printStackTrace();
 80         }
 81     }
 82         
 83     //某表的增删改查
 84     public static ArrayList<Doc> getDoces(String type)
 85     {
 86         Connection connection=null;
 87         PreparedStatement preparedStatement=null;
 88         ResultSet rSet=null;
 89         try {
 90             connection=getConnection();
 91             String sql;
 92             System.out.println(type);
 93             if(type.equals("receive"))
 94             {
 95                 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";
 96             }
 97             else if(type.equals("send"))
 98             {
 99                 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";
100             }
101             else if(type.equals("delete"))
102             {
103                 sql="select * from doc_list where deletestatus=1";
104             }
105             else {
106                 sql="select * from doc_list";
107             }
108             preparedStatement=connection.prepareStatement(sql);
109             rSet=preparedStatement.executeQuery();
110             ArrayList<Doc> list=new ArrayList<>();
111             while(rSet.next())
112             {
113                 Doc doc=new Doc();
114                 doc.setId(rSet.getInt("id"));
115                 doc.setTitle(rSet.getString("title"));
116                 doc.setOwner(rSet.getString("owner"));
117                 doc.setTime(rSet.getString("time"));
118                 doc.setReceiver(rSet.getString("receiver"));
119                 doc.setStatus(rSet.getInt("status"));
120                 doc.setResult(rSet.getInt("result"));
121                 doc.setPlace(rSet.getString("place"));
122                 doc.setDeletestatus(rSet.getInt("deletestatus"));
123                 list.add(doc);
124             }
125             return list;
126         } catch (SQLException e) {
127             // TODO: handle exception
128             e.printStackTrace();
129         }
130         finally {
131             closeAll(connection, preparedStatement, rSet);
132         }
133         return null;
134     }
135     
136     //登录时验证数据库中账户是否存在
137     public static boolean log_isExist(Users user)
138     {
139         Connection con=null;
140         PreparedStatement pstmt=null;
141         ResultSet rs=null;
142         try {
143             con=getConnection();
144             String sql_query="select * from users where username = '"+user.getUsername()+"' and password = '"+user.getPassword()+"' and status != 0";
145             System.out.println(sql_query);
146             pstmt=con.prepareStatement(sql_query);
147             rs=pstmt.executeQuery();
148             if(rs.next()==false)
149             {
150                 System.out.println("用户名或密码错误");
151                 return false;
152             }
153             else
154             {
155                 System.out.println("用户名及密码正确");
156                 return true;
157             }
158         }
159         catch (SQLException e) {
160             System.out.println("未连接");
161             e.printStackTrace();
162         }
163         finally {
164             closeAll(con, pstmt, rs);
165         }
166         return false;
167     }
168     
169     //增加公文
170     public static boolean add_doc(Doc doc)
171     {
172         Connection con=null;
173         PreparedStatement pstmt=null;
174         ResultSet rs=null;
175         try {
176             con=getConnection();
177             String sql="insert into doc_list(title,owner,receiver,time,status,result,place,deletestatus,callback) values(?,?,?,?,?,?,?,?,?)";
178             pstmt=con.prepareStatement(sql);
179             pstmt.setString(1, doc.getTitle());
180             pstmt.setString(2, doc.getOwner());
181             pstmt.setString(3, doc.getReceiver());
182             pstmt.setString(4, doc.getTime());
183             pstmt.setInt(5, doc.getStatus());
184             pstmt.setInt(6, doc.getResult());
185             pstmt.setString(7, doc.getPlace());
186             pstmt.setInt(8, 0);
187             pstmt.setInt(9, 0);
188             pstmt.executeUpdate();
189             return true;
190         }
191         catch (SQLException e) {
192             System.out.println("注册失败");
193             e.printStackTrace();
194         }
195         finally {
196             closeAll(con, pstmt, rs);
197         }
198         return false;
199     }
200     
201     
202     //删除数据
203     public static boolean delete_user(Users user)
204     {
205         Connection con=null;
206         PreparedStatement pstmt=null;
207         try {
208             con=getConnection();
209             String sql="delete from users where id="+user.getId();
210             System.out.println(sql);
211             pstmt=con.prepareStatement(sql);
212             pstmt.executeUpdate();
213             return true;
214         }
215         catch(SQLException e)
216         {
217             e.printStackTrace();
218         }
219         finally {
220             closePart(con, pstmt);
221         }
222         return false;
223     }
224     
225     public static boolean update_userstatus(Users user)
226     {
227         Connection con=null;
228         PreparedStatement pstmt=null;
229         try {
230             con=getConnection();
231             String sql="update users set status = ? where id = ?";
232             pstmt=con.prepareStatement(sql);
233             pstmt.setInt(1, user.getStatus());
234             pstmt.setInt(2, user.getId());
235             pstmt.executeUpdate();
236             return true;
237         }
238         catch(SQLException e)
239         {
240             e.printStackTrace();
241         }
242         finally {
243             closePart(con, pstmt);
244         }
245         return false;
246     }
247     
248     public static boolean update_user(Users user)
249     {
250         Connection con=null;
251         PreparedStatement pstmt=null;
252         try {
253             con=getConnection();
254             String sql="update users set username=?,password=?,job=? where id = "+user.getId();
255             pstmt=con.prepareStatement(sql);
256             pstmt.setString(1, user.getUsername());
257             pstmt.setString(2, user.getPassword());
258             pstmt.setString(3, user.getJob());
259             pstmt.executeUpdate();
260             return true;
261         }
262         catch(SQLException e)
263         {
264             e.printStackTrace();
265         }
266         finally {
267             closePart(con, pstmt);
268         }
269         return false;
270     }
271     
272     @SuppressWarnings("resource")
273     public static boolean sendDoc(int id)
274     {
275         Connection con=null;
276         PreparedStatement pstmt=null;
277         ResultSet rSet=null;
278         int status=-1;
279         int newstatus=-1;
280         String receiver="";
281         try {
282             con=DBUtil.getConnection();
283             String sql_query="select * from doc_list where id="+id;
284             pstmt=con.prepareStatement(sql_query);
285             rSet=pstmt.executeQuery();
286             if(rSet.next())
287             {
288                 status=rSet.getInt("status");
289             }
290             switch (status) {
291             case 0:
292                 newstatus=1;
293                 receiver="副厂长";
294                 break;
295             case 2:
296                 newstatus=5;
297                 receiver="厂长";
298                 break;
299             case 3:
300                 newstatus=4;
301                 receiver="部门";
302                 break;
303             case 6:
304                 newstatus=8;
305                 receiver="部门和副厂长";
306                 break;
307             case 7:
308                 newstatus=9;
309                 receiver="部门和副厂长";
310                 break;
311             case 8:
312                 newstatus=10;
313                 receiver="部门";
314                 break;
315             default:
316                 System.out.println("公文状态有误!");
317                 break;
318             }
319             String sql_update="update doc_list set status = ? where id = ?";
320             pstmt=con.prepareStatement(sql_update);
321             pstmt.setInt(1, newstatus);
322             pstmt.setInt(2, id);
323             pstmt.executeUpdate();
324             return true;
325         }
326         catch (SQLException e) {
327             System.out.println("数据库信息更新失败");
328             e.printStackTrace();
329         }
330         finally {
331             closePart(con, pstmt);
332         }
333         return false;
334     }
335     
336     public static ArrayList<Doc> getDocesByCase(String type,String value)
337     {
338         Connection connection=null;
339         PreparedStatement preparedStatement=null;
340         ResultSet rSet=null;
341         try {
342             connection=getConnection();
343             String sql="";
344             System.out.println(type);
345             if(type.equals("title"))
346             {
347                 sql="select * from doc_list where title='"+value+"'";
348             }
349             else if(type.equals("owner"))
350             {
351                 sql="select * from doc_list where owner='"+value+"'";
352             }
353             else if(type.equals("receiver"))
354             {
355                 sql="select * from doc_list where receiver='"+value+"'";
356             }
357             else if(type.equals("result"))
358             {
359                 sql="select * from doc_list where result='"+value+"'";
360             }
361             preparedStatement=connection.prepareStatement(sql);
362             rSet=preparedStatement.executeQuery();
363             ArrayList<Doc> list=new ArrayList<>();
364             while(rSet.next())
365             {
366                 Doc doc=new Doc();
367                 doc.setId(rSet.getInt("id"));
368                 doc.setTitle(rSet.getString("title"));
369                 doc.setOwner(rSet.getString("owner"));
370                 doc.setTime(rSet.getString("time"));
371                 doc.setReceiver(rSet.getString("receiver"));
372                 doc.setStatus(rSet.getInt("status"));
373                 doc.setResult(rSet.getInt("result"));
374                 doc.setPlace(rSet.getString("place"));
375                 list.add(doc);
376             }
377             return list;
378         } catch (SQLException e) {
379             // TODO: handle exception
380             e.printStackTrace();
381         }
382         finally {
383             closeAll(connection, preparedStatement, rSet);
384         }
385         return null;
386     }
387     
388     public static ArrayList<Doc> getCheckedorNot(String type)
389     {
390         Connection connection=null;
391         PreparedStatement preparedStatement=null;
392         ResultSet rSet=null;
393         try {
394             connection=getConnection();
395             String sql="";
396             System.out.println(type);
397             if(type.equals("notchecked"))
398             {
399                 sql="select * from doc_list where status=1";
400             }
401             else
402             {
403                 sql="select * from doc_list where status!=1 and status!=0 and status!=-1";
404             }
405             preparedStatement=connection.prepareStatement(sql);
406             rSet=preparedStatement.executeQuery();
407             ArrayList<Doc> list=new ArrayList<>();
408             while(rSet.next())
409             {
410                 Doc doc=new Doc();
411                 doc.setId(rSet.getInt("id"));
412                 doc.setTitle(rSet.getString("title"));
413                 doc.setOwner(rSet.getString("owner"));
414                 doc.setTime(rSet.getString("time"));
415                 doc.setReceiver(rSet.getString("receiver"));
416                 doc.setStatus(rSet.getInt("status"));
417                 doc.setResult(rSet.getInt("result"));
418                 doc.setPlace(rSet.getString("place"));
419                 list.add(doc);
420             }
421             return list;
422         } catch (SQLException e) {
423             // TODO: handle exception
424             e.printStackTrace();
425         }
426         finally {
427             closeAll(connection, preparedStatement, rSet);
428         }
429         return null;
430     }
431     
432     public static ArrayList<Doc> getFcheckedorNot(String type)
433     {
434         Connection connection=null;
435         PreparedStatement preparedStatement=null;
436         ResultSet rSet=null;
437         try {
438             connection=getConnection();
439             String sql="";
440             if(type.equals("checked"))
441             {
442                 sql="select * from doc_list where status=6 or status=7";
443             }
444             else
445             {
446                 sql="select * from doc_list where status=5";
447             }
448             preparedStatement=connection.prepareStatement(sql);
449             rSet=preparedStatement.executeQuery();
450             ArrayList<Doc> list=new ArrayList<>();
451             while(rSet.next())
452             {
453                 Doc doc=new Doc();
454                 doc.setId(rSet.getInt("id"));
455                 doc.setTitle(rSet.getString("title"));
456                 doc.setOwner(rSet.getString("owner"));
457                 doc.setTime(rSet.getString("time"));
458                 doc.setReceiver(rSet.getString("receiver"));
459                 doc.setStatus(rSet.getInt("status"));
460                 doc.setResult(rSet.getInt("result"));
461                 doc.setPlace(rSet.getString("place"));
462                 list.add(doc);
463             }
464             return list;
465         } catch (SQLException e) {
466             // TODO: handle exception
467             e.printStackTrace();
468         }
469         finally {
470             closeAll(connection, preparedStatement, rSet);
471         }
472         return null;
473     }
474     
475     
476     public static ArrayList<Doc> getReceivedByUser(String type,Users user)
477     {
478         Connection connection=null;
479         PreparedStatement preparedStatement=null;
480         ResultSet rSet=null;
481         try {
482             connection=getConnection();
483             String sql="";
484             if(type.equals("received"))
485             {
486                 sql="select * from doc_list where owner=? and status=10";
487             }
488             else
489             {
490                 sql="select * from doc_list where owner=? and status!=10";
491             }
492             preparedStatement=connection.prepareStatement(sql);
493             preparedStatement.setString(1, user.getUsername());
494             rSet=preparedStatement.executeQuery();
495             ArrayList<Doc> list=new ArrayList<>();
496             while(rSet.next())
497             {
498                 Doc doc=new Doc();
499                 doc.setId(rSet.getInt("id"));
500                 doc.setTitle(rSet.getString("title"));
501                 doc.setTime(rSet.getString("time"));
502                 doc.setStatus(rSet.getInt("status"));
503                 doc.setResult(rSet.getInt("result"));
504                 list.add(doc);
505             }
506             return list;
507         } catch (SQLException e) {
508             // TODO: handle exception
509             e.printStackTrace();
510         }
511         finally {
512             closeAll(connection, preparedStatement, rSet);
513         }
514         return null;
515     }
516     
517     public static Doc getDocById(Doc doc)
518     {
519         Connection connection=null;
520         PreparedStatement preparedStatement=null;
521         ResultSet rSet=null;
522         try {
523             connection=getConnection();
524             String sql="select * from doc_list where id="+doc.getId();
525             preparedStatement=connection.prepareStatement(sql);
526             rSet=preparedStatement.executeQuery();
527             if(rSet.next())
528             {
529                 doc.setTitle(rSet.getString("title"));
530                 doc.setOwner(rSet.getString("owner"));
531                 doc.setTime(rSet.getString("time"));
532                 doc.setReceiver(rSet.getString("receiver"));
533                 doc.setStatus(rSet.getInt("status"));
534                 doc.setResult(rSet.getInt("result"));
535                 doc.setPlace(rSet.getString("place"));
536                 doc.setTipplace(rSet.getString("tipplace"));
537                 doc.setFtipplace(rSet.getString("tipfplace"));
538                 return doc;
539             }
540         } catch (SQLException e) {
541             // TODO: handle exception
542             e.printStackTrace();
543         }
544         finally {
545             closeAll(connection, preparedStatement, rSet);
546         }
547         return null;
548     }
549     
550     public static boolean checked_change(Doc doc)
551     {
552         Connection connection=null;
553         PreparedStatement preparedStatement=null;
554         String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipplace = ? where id = ?";
555         try {
556             connection=getConnection();
557             preparedStatement=connection.prepareStatement(sql_update);
558             preparedStatement.setInt(1, doc.getStatus());
559             preparedStatement.setInt(2, doc.getResult());
560             preparedStatement.setString(3, doc.getReceiver());
561             preparedStatement.setString(4, doc.getTipplace());
562             preparedStatement.setInt(5, doc.getId());
563             preparedStatement.executeUpdate();
564             return true;
565         } catch (SQLException e) {
566             // TODO 自动生成的 catch 块
567             e.printStackTrace();
568         }
569         finally {
570             closePart(connection, preparedStatement);
571         }
572         return false;
573     }
574     
575     public static boolean fchecked_change(Doc doc)
576     {
577         Connection connection=null;
578         PreparedStatement preparedStatement=null;
579         String sql_update="update doc_list set status = ?,result = ?,receiver = ?,tipfplace = ? where id = ?";
580         try {
581             connection=getConnection();
582             preparedStatement=connection.prepareStatement(sql_update);
583             preparedStatement.setInt(1, doc.getStatus());
584             preparedStatement.setInt(2, doc.getResult());
585             preparedStatement.setString(3, doc.getReceiver());
586             preparedStatement.setString(4, doc.getFtipplace());
587             preparedStatement.setInt(5, doc.getId());
588             preparedStatement.executeUpdate();
589             return true;
590         } catch (SQLException e) {
591             // TODO 自动生成的 catch 块
592             e.printStackTrace();
593         }
594         finally {
595             closePart(connection, preparedStatement);
596         }
597         return false;
598     }
599     
600     public static boolean formatDoc(Doc doc)
601     {
602         Connection connection=null;
603         PreparedStatement preparedStatement=null;
604         String sql_update="update doc_list set status = ? where id = ?";
605         try {
606             connection=getConnection();
607             preparedStatement=connection.prepareStatement(sql_update);
608             preparedStatement.setInt(1, doc.getStatus());
609             preparedStatement.setInt(2, doc.getId());
610             preparedStatement.executeUpdate();
611             return true;
612         } catch (SQLException e) {
613             // TODO 自动生成的 catch 块
614             e.printStackTrace();
615         }
616         finally {
617             closePart(connection, preparedStatement);
618         }
619         return false;
620     }
621     
622     public static boolean ReceiveDoc(Doc doc)
623     {
624         Connection connection=null;
625         PreparedStatement preparedStatement=null;
626         String sql_update="update doc_list set status = ?,callback = 1 where id = ?";
627         try {
628             connection=getConnection();
629             preparedStatement=connection.prepareStatement(sql_update);
630             preparedStatement.setInt(1, 10);
631             preparedStatement.setInt(2, doc.getId());
632             preparedStatement.executeUpdate();
633             return true;
634         } catch (SQLException e) {
635             // TODO 自动生成的 catch 块
636             e.printStackTrace();
637         }
638         finally {
639             closePart(connection, preparedStatement);
640         }
641         return false;
642     }
643     
644     public static ArrayList<Doc> getDocByTime(Doc doc1,Doc doc2)
645     {
646         Connection connection=null;
647         PreparedStatement preparedStatement=null;
648         ResultSet rs=null;
649         String sql="select * from doc_list where time between ? and ?";
650         try {
651             connection=getConnection();
652             preparedStatement=connection.prepareStatement(sql);
653             preparedStatement.setString(1,doc1.getTime());
654             preparedStatement.setString(2, doc2.getTime());
655             rs=preparedStatement.executeQuery();
656             ArrayList<Doc> list=new ArrayList<>();
657             while(rs.next())
658             {
659                 Doc doc=new Doc();
660                 doc.setId(rs.getInt("id"));
661                 doc.setTitle(rs.getString("title"));
662                 doc.setTime(rs.getString("time"));
663                 doc.setOwner(rs.getString("owner"));
664                 list.add(doc);
665             }
666             return list;
667         } catch (SQLException e) {
668             // TODO 自动生成的 catch 块
669             e.printStackTrace();
670         }
671         finally {
672             closePart(connection, preparedStatement);
673         }
674         return null;
675     }
676     
677     public static ArrayList<Doc> getAllDoc()
678     {
679         Connection connection=null;
680         PreparedStatement preparedStatement=null;
681         ResultSet rs=null;
682         String sql="select * from doc_list";
683         try {
684             connection=getConnection();
685             preparedStatement=connection.prepareStatement(sql);
686             rs=preparedStatement.executeQuery();
687             ArrayList<Doc> list=new ArrayList<>();
688             while(rs.next())
689             {
690                 Doc doc=new Doc();
691                 doc.setId(rs.getInt("id"));
692                 doc.setTitle(rs.getString("title"));
693                 doc.setTime(rs.getString("time"));
694                 doc.setOwner(rs.getString("owner"));
695                 list.add(doc);
696             }
697             return list;
698         } catch (SQLException e) {
699             // TODO 自动生成的 catch 块
700             e.printStackTrace();
701         }
702         finally {
703             closePart(connection, preparedStatement);
704         }
705         return null;
706     }
707     
708     public static ArrayList<Users> getAllUser()
709     {
710         Connection connection=null;
711         PreparedStatement preparedStatement=null;
712         ResultSet rs=null;
713         String sql="select * from users";
714         try {
715             connection=getConnection();
716             preparedStatement=connection.prepareStatement(sql);
717             rs=preparedStatement.executeQuery();
718             ArrayList<Users> list=new ArrayList<>();
719             while(rs.next())
720             {
721                 Users user=new Users();
722                 user.setId(rs.getInt("id"));
723                 user.setUsername(rs.getString("username"));
724                 user.setPassword(rs.getString("password"));
725                 user.setPermissionId(rs.getInt("permissionId"));
726                 user.setJob(rs.getString("job"));
727                 user.setStatus(rs.getInt("status"));
728                 list.add(user);
729             }
730             return list;
731         } catch (SQLException e) {
732             // TODO 自动生成的 catch 块
733             e.printStackTrace();
734         }
735         finally {
736             closePart(connection, preparedStatement);
737         }
738         return null;
739     }
740     
741     public static Users getUserById(Users user)
742     {
743         Connection connection=null;
744         PreparedStatement preparedStatement=null;
745         ResultSet rs=null;
746         String sql="select * from users where id="+user.getId();
747         try {
748             connection=getConnection();
749             preparedStatement=connection.prepareStatement(sql);
750             rs=preparedStatement.executeQuery();
751             Users user1=new Users();
752             if(rs.next())
753             {
754                 user1.setId(rs.getInt("id"));
755                 user1.setUsername(rs.getString("username"));
756                 user1.setPassword(rs.getString("password"));
757                 user1.setPermissionId(rs.getInt("permissionId"));
758                 user1.setStatus(rs.getInt("status"));
759                 user1.setJob(rs.getString("job"));
760             }
761             return user1;
762         } catch (SQLException e) {
763             // TODO 自动生成的 catch 块
764             e.printStackTrace();
765         }
766         finally {
767             closePart(connection, preparedStatement);
768         }
769         return null;
770     }
771     
772     public static ArrayList<Permission> getPermission(Permission permission)
773     {
774         Connection connection=null;
775         PreparedStatement preparedStatement=null;
776         ResultSet rs=null;
777         String sql="select * from permission where id="+permission.getId();
778         try {
779             connection=getConnection();
780             preparedStatement=connection.prepareStatement(sql);
781             rs=preparedStatement.executeQuery();
782             ArrayList<Permission> list=new ArrayList<>();
783             while(rs.next())
784             {
785                 Permission permission1=new Permission();
786                 permission1.setId(rs.getInt("id"));
787                 permission1.setPermission(rs.getInt("permission"));
788                 list.add(permission1);
789             }
790             return list;
791         } catch (SQLException e) {
792             // TODO 自动生成的 catch 块
793             e.printStackTrace();
794         }
795         finally {
796             closePart(connection, preparedStatement);
797         }
798         return null;
799     }
800     
801     public static boolean deletePermission(Permission permission)
802     {
803         Connection con=null;
804         PreparedStatement pstmt=null;
805         try {
806             con=getConnection();
807             String sql="delete from permission where id="+permission.getId();
808             System.out.println(sql);
809             pstmt=con.prepareStatement(sql);
810             pstmt.executeUpdate();
811             return true;
812         }
813         catch(SQLException e)
814         {
815             e.printStackTrace();
816         }
817         finally {
818             closePart(con, pstmt);
819         }
820         return false;
821     }
822     
823     public static boolean updatePermission(Permission permission1,Permission permission2)
824     {
825         Connection con=null;
826         PreparedStatement pstmt=null;
827         try {
828             con=getConnection();
829             String sql="update permission set permission = ? where id = ? and permission = ?";
830             pstmt=con.prepareStatement(sql);
831             pstmt.setInt(1, permission2.getPermission());
832             pstmt.setInt(2, permission1.getId());
833             pstmt.setInt(3, permission1.getPermission());
834             pstmt.executeUpdate();
835             return true;
836         }
837         catch(SQLException e)
838         {
839             e.printStackTrace();
840         }
841         finally {
842             closePart(con, pstmt);
843         }
844         return false;
845     }
846     
847     public static boolean updatePwd(Users user)
848     {
849         Connection con=null;
850         PreparedStatement pstmt=null;
851         try {
852             con=getConnection();
853             String sql="update users set password = ? where username = ?";
854             pstmt=con.prepareStatement(sql);
855             pstmt.setString(1, user.getPassword());
856             pstmt.setString(2, user.getUsername());
857             pstmt.executeUpdate();
858             return true;
859         }
860         catch(SQLException e)
861         {
862             e.printStackTrace();
863         }
864         finally {
865             closePart(con, pstmt);
866         }
867         return false;
868     }
869     
870     public static Users getUserByUsername(Users user)
871     {
872         Connection connection=null;
873         PreparedStatement preparedStatement=null;
874         ResultSet rs=null;
875         String sql="select * from users where username='"+user.getUsername()+"'";
876         try {
877             connection=getConnection();
878             preparedStatement=connection.prepareStatement(sql);
879             rs=preparedStatement.executeQuery();
880             Users user1=new Users();
881             if(rs.next())
882             {
883                 user1.setId(rs.getInt("id"));
884                 user1.setPermissionId(rs.getInt("permissionId"));
885                 System.out.println(user1.getPermissionId());
886             }
887             return user1;
888         } catch (SQLException e) {
889             // TODO 自动生成的 catch 块
890             e.printStackTrace();
891         }
892         finally {
893             closePart(connection, preparedStatement);
894         }
895         return null;
896     }
897     
898     public static boolean deleteDoc(Doc doc)
899     {
900         Connection con=null;
901         PreparedStatement pstmt=null;
902         try {
903             con=getConnection();
904             String sql="update doc_list set deletestatus = ? where id = ?";
905             pstmt=con.prepareStatement(sql);
906             pstmt.setInt(1, doc.getDeletestatus());
907             pstmt.setInt(2, doc.getId());
908             pstmt.executeUpdate();
909             return true;
910         }
911         catch(SQLException e)
912         {
913             e.printStackTrace();
914         }
915         finally {
916             closePart(con, pstmt);
917         }
918         return false;
919     }
920     
921     public static ArrayList<Doc> getCall()
922     {
923         Connection connection=null;
924         PreparedStatement preparedStatement=null;
925         ResultSet rSet=null;
926         try {
927             connection=getConnection();
928             String sql="select * from doc_list where callback=1";
929             preparedStatement=connection.prepareStatement(sql);
930             rSet=preparedStatement.executeQuery();
931             ArrayList<Doc> list=new ArrayList<>();
932             while(rSet.next())
933             {
934                 Doc doc=new Doc();
935                 doc.setId(rSet.getInt("id"));
936                 doc.setTitle(rSet.getString("title"));
937                 doc.setOwner(rSet.getString("owner"));
938                 doc.setTime(rSet.getString("time"));
939                 doc.setReceiver(rSet.getString("receiver"));
940                 doc.setStatus(rSet.getInt("status"));
941                 doc.setResult(rSet.getInt("result"));
942                 doc.setPlace(rSet.getString("place"));
943                 doc.setDeletestatus(rSet.getInt("deletestatus"));
944                 doc.setCallback(rSet.getInt("callback"));
945                 list.add(doc);
946             }
947             return list;
948         } catch (SQLException e) {
949             // TODO: handle exception
950             e.printStackTrace();
951         }
952         finally {
953             closeAll(connection, preparedStatement, rSet);
954         }
955         return null;
956     }
957     
958     public static boolean setCallOver(Doc doc)
959     {
960         Connection con=null;
961         PreparedStatement pstmt=null;
962         try {
963             con=getConnection();
964             String sql="update doc_list set callback = ? where id = ?";
965             pstmt=con.prepareStatement(sql);
966             pstmt.setInt(1, 0);
967             pstmt.setInt(2, doc.getId());
968             pstmt.executeUpdate();
969             return true;
970         }
971         catch(SQLException e)
972         {
973             e.printStackTrace();
974         }
975         finally {
976             closePart(con, pstmt);
977         }
978         return false;
979     }
980 
981     public static void main(String[] args) {
982         //getConnection();
983         
984     }
985 }
View Code

以上是该系统所有关键代码,其余代码大多是简单的数据库增删改查,不再附上。

下面是系统使用的部分截图:

    

   

    

原文地址:https://www.cnblogs.com/zdm-code/p/12011098.html