返回顶部

一缕半夏微光

温柔半两,从容一生

导航

公文流转系统⑤|副厂长功能页

一、效果如下:

二、代码如下:

(1)viceFactory.jsp

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6 <meta charset="UTF-8">
 7 <title>副厂长功能页</title>
 8 <link rel="stylesheet" href=".//layui/css/layui.css" media="all">
 9 <script src=".//layui/layui.all.js"></script>
10 <script src=".//layui/layui.js"></script>
11 <script type="text/javascript">
12     //JavaScript代码区域
13     layui.use('element', function(){
14       var element = layui.element;
15     });
16 </script>
17 </head>
18 <body class="layui-layout-body">
19     <div class="layui-layout layui-layout-admin">
20         <div class="layui-header">
21             <div class="layui-logo">
22             <%
23                 String department=(String)session.getAttribute("department");
24                 out.print(department);
25             %>
26             功能页欢迎
27             <%
28                 String username=(String)session.getAttribute("username");
29                 out.print(username);
30             %>
31             </div>
32             <!-- 水平导航 -->
33              <ul class="layui-nav layui-layout-right">
34                  <li class="layui-nav-item "><a href="index.jsp">退出</a></li>
35              </ul>
36         </div>
37 
38         <div class="layui-side layui-bg-black">
39             <div class="layui-side-scroll">
40                 <!-- 左侧导航 -->
41                 <ul class="layui-nav layui-nav-tree" >
42                     <li class="layui-nav-item"><a href="ViceFactoryServlet?method=review_papers" target="frame">审核公文</a></li>
43                 </ul>
44             </div>
45         </div>
46         <div class="layui-body">
47             <!-- 内容主体区域 -->
48             <iframe name="frame" width="100%" height="100%"
49                 style="border: 1px solid #CCC;"></iframe>
50         </div>
51         <div>
52         <div>
53         <input type="text" id="date" />
54         </div>
55         </div>
56     </div>
57 
58 </body>
59 </html>

(2)viceFactory_review_papers.jsp

 1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 4 <!DOCTYPE html>
 5 <html>
 6 <head>
 7 <meta charset="UTF-8">
 8 <title>审核公文</title>
 9 <link rel="stylesheet" href=".//layui/css/layui.css" media="all">
10 <script src=".//layui/layui.all.js"></script>
11 <script src=".//layui/layui.js"></script>
12 </head>
13 <body>
14     <table class="layui-table">
15         <colgroup>
16             <col width="150">
17             <col width="200">
18             <col>
19         </colgroup>
20         <thead>
21             <tr>
22                 <th>id</th>
23                 <th>公文标题</th>
24                 <th>公文内容</th>
25                 <th>时间</th>
26                 <th>创建人</th>
27                 <th>操作</th>
28             </tr>
29         </thead>
30         <tbody>
31             <c:forEach items="${list}" var="document" varStatus="status">
32                 <tr>
33                     <td>${ status.index + 1}</td>
34                     <td>${document.title}</td>
35                     <td>${document.content}</td>
36                     <td>${document.time}</td>
37                     <td>${document.createPeople}</td>
38                     <td><button class="layui-btn layui-btn-normal"
39                             onclick="window.location.href='ViceFactoryServlet?method=check&title=${document.title}'">审核</button></td>
40                 </tr>
41             </c:forEach>
42         </tbody>
43     </table>
44 </body>
45 </html>

(3)viceFactory_check.jsp

 1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 4 <!DOCTYPE html>
 5 <html>
 6 <head>
 7 <meta charset="UTF-8">
 8 <title>审核公文</title>
 9 <link rel="stylesheet" href=".//layui/css/layui.css" media="all">
10 <script src=".//layui/layui.all.js"></script>
11 <script src=".//layui/layui.js"></script>
12 </head>
13 <body>
14     <form class="layui-form" action="ViceFactoryServlet?method=checkResult"
15         method="post">
16         <c:forEach items="${list}" var="document">
17             <div class="layui-form-item">
18                 <label class="layui-form-label">公文标题</label>
19                 <div class="layui-input-inline">
20                     <input type="text" name="title" required lay-verify="required"
21                         placeholder="请输入公文标题" autocomplete="off" class="layui-input"
22                         value="${document.title}"> <input type="hidden"
23                         name="judgetitle" required lay-verify="required"
24                         placeholder="请输入公文标题" autocomplete="off" class="layui-input"
25                         value="${document.title}">
26                 </div>
27                 <div class="layui-form-mid layui-word-aux">(标题不能修改喔)</div>
28             </div>
29             <div class="layui-form-item layui-form-text">
30                 <label class="layui-form-label">公文内容</label>
31                 <div class="layui-input-block">${document.content}</div>
32             </div>
33             <div class="layui-form-item">
34                 <label class="layui-form-label">时间</label>
35                 <div class="layui-inline">${document.time}</div>
36             </div>
37             <div class="layui-form-item">
38                 <label class="layui-form-label">创建人</label>
39                 <div class="layui-input-block">${document.createPeople}</div>
40             </div>
41             <div class="layui-form-item">
42                 <label class="layui-form-label">是否同意</label>
43                 <div class="layui-input-block">
44                     <input type="radio" name="viceFactoryAgree" value="同意" title="同意"
45                         checked> <input type="radio" name="viceFactoryAgree"
46                         value="不同意" title="不同意">
47                 </div>
48             </div>
49             <div class="layui-form-item layui-form-text">
50                 <label class="layui-form-label">意见</label>
51                 <div class="layui-input-block">
52                     <textarea name="viceFactoryOpinion" placeholder="请输入您的意见"
53                         class="layui-textarea"></textarea>
54                 </div>
55             </div>
56             <div class="layui-form-item">
57                 <div class="layui-input-block">
58                     <button class="layui-btn" lay-submit>提交</button>
59                     <button type="reset" class="layui-btn layui-btn-primary">重置</button>
60                 </div>
61             </div>
62         </c:forEach>
63     </form>
64 </body>
65 </html>

(4)ViceFactoryServlet.java

  1 package servlet;
  2 
  3 import java.io.IOException;
  4 import java.util.List;
  5 
  6 import javax.servlet.ServletException;
  7 import javax.servlet.annotation.WebServlet;
  8 import javax.servlet.http.HttpServlet;
  9 import javax.servlet.http.HttpServletRequest;
 10 import javax.servlet.http.HttpServletResponse;
 11 import javax.servlet.http.HttpSession;
 12 
 13 import dao.ViceFactoryDao;
 14 import util.Document;
 15 
 16 /**
 17  * Servlet implementation class ViceFactoryServlet
 18  */
 19 @WebServlet("/ViceFactoryServlet")
 20 public class ViceFactoryServlet extends HttpServlet {
 21     private static final long serialVersionUID = 1L;
 22        
 23     /**
 24      * @see HttpServlet#HttpServlet()
 25      */
 26     public ViceFactoryServlet() {
 27         super();
 28         // TODO Auto-generated constructor stub
 29     }
 30     
 31     ViceFactoryDao dao=new ViceFactoryDao();
 32 
 33     /**
 34      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 35      */
 36     protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 37         // TODO Auto-generated method stub
 38         //response.getWriter().append("Served at: ").append(request.getContextPath());
 39         doPost(request,response);
 40     }
 41 
 42     /**
 43      * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 44      */
 45     protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 46         // TODO Auto-generated method stub
 47         //doGet(request, response);
 48         
 49         request.setCharacterEncoding("utf-8");
 50         response.setCharacterEncoding("utf-8");
 51 
 52         System.out.println("进入ViceFactoryServlet");
 53         String method = request.getParameter("method");
 54           System.out.println(method);
 55           if("review_papers".equals(method)) {
 56               review_papers(request,response);
 57           }else if("check".equals(method)) {
 58               check(request,response);
 59           }else if("checkResult".equals(method)) {
 60               checkResult(request,response);
 61           }
 62           
 63     }
 64     public void review_papers(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 65         response.setCharacterEncoding("UTF-8");
 66         request.setCharacterEncoding("UTF-8");
 67         
 68         System.out.println("进入review_papers");
 69         
 70         // 使用request对象的getSession()获取session,如果session不存在则创建一个
 71         HttpSession session = request.getSession();
 72         // 将数据取出
 73         String name = (String) session.getAttribute("username");
 74         // 输出数据
 75         System.out.println("session name;" + name);
 76         
 77         List<Document> list=dao.review_papers(name);
 78         request.setAttribute("list", list);
 79         request.getRequestDispatcher("viceFactory_review_papers.jsp").forward(request,response);
 80         
 81     }
 82     public void check(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 83         response.setCharacterEncoding("UTF-8");
 84         request.setCharacterEncoding("UTF-8");
 85         
 86         String title=request.getParameter("title");
 87         List<Document> list=dao.check(title);
 88         request.setAttribute("list", list);
 89         request.getRequestDispatcher("viceFactory_check.jsp").forward(request,response);
 90         
 91     }
 92     public void checkResult(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
 93         response.setCharacterEncoding("UTF-8");
 94         request.setCharacterEncoding("UTF-8");
 95         
 96         String title=request.getParameter("judgetitle");
 97         String viceFactoryAgree=request.getParameter("viceFactoryAgree");
 98         String viceFactoryOpinion=request.getParameter("viceFactoryOpinion");
 99         System.out.println(title+":"+viceFactoryAgree+":"+viceFactoryOpinion);
100         
101         Document document=new Document(title,viceFactoryAgree,viceFactoryOpinion);
102         
103         if(dao.checkResult(document)){
104             request.getRequestDispatcher("ViceFactoryServlet?method=review_papers").forward(request,response);
105         }else {
106             request.getRequestDispatcher("TestFail.jsp").forward(request,response);
107         }
108         
109     }
110 
111 }

(5)ViceFactoryDao.java

  1 package dao;
  2 
  3 import java.sql.Connection;
  4 import java.sql.PreparedStatement;
  5 import java.sql.ResultSet;
  6 import java.util.ArrayList;
  7 import java.util.List;
  8 
  9 import database.Database;
 10 import util.Document;
 11 
 12 public class ViceFactoryDao {
 13     public List<Document> review_papers(String name) {
 14         List<Document> list = new ArrayList<>();
 15         Connection conn = null;
 16         ResultSet rs = null;
 17         ResultSet rs1 = null;
 18         PreparedStatement pstm = null;
 19         PreparedStatement pstm1 = null;
 20         Document document = null;
 21         String department = "null";
 22         try {
 23             conn = Database.getConnection();
 24             String sql = "select department from user where name=?";
 25             pstm = conn.prepareStatement(sql);
 26             pstm.setString(1, name);
 27             rs = pstm.executeQuery();
 28             while (rs.next()) {
 29                 department = rs.getString("department");
 30             }
 31             System.out.println(department);
 32 
 33             if (department.equals("副厂长-销售部")) {
 34                 String sql1 = "select * from document where receiver=?";
 35                 pstm1 = conn.prepareStatement(sql1);
 36                 pstm1.setString(1, "副厂长-销售部待同意");
 37             } else if (department.equals("副厂长-财务部")) {
 38                 String sql1 = "select * from document where receiver=?";
 39                 pstm1 = conn.prepareStatement(sql1);
 40                 pstm1.setString(1, "副厂长-财务部待同意");
 41             } else if (department.equals("副厂长-生产部")) {
 42                 String sql1 = "select * from document where receiver=?";
 43                 pstm1 = conn.prepareStatement(sql1);
 44                 pstm1.setString(1, "副厂长-生产部待同意");
 45             }
 46             rs1 = pstm1.executeQuery();
 47             while (rs1.next()) {
 48                 String title = rs1.getString("title");
 49                 String content = rs1.getString("content");
 50                 String time = rs1.getString("time");
 51                 String createPeople = rs1.getString("createPeople");
 52                 document = new Document(title, content, time, createPeople);
 53                 System.out.println(title+","+content+","+time+","+createPeople);
 54                 list.add(document);
 55             }
 56             
 57         } catch (Exception e) {
 58             e.printStackTrace();
 59         } finally {
 60             Database.close(conn, pstm, rs);
 61         }
 62         return list;
 63     }
 64 
 65     public List<Document> check(String title) {
 66         List<Document> list = new ArrayList<>();
 67         Connection conn = null;
 68         ResultSet rs = null;
 69         PreparedStatement pstm = null;
 70         Document document = null;
 71         try {
 72             conn = Database.getConnection();
 73             String sql = "select * from document where title=?";
 74             pstm = conn.prepareStatement(sql);
 75             pstm.setString(1, title);
 76             rs = pstm.executeQuery();
 77             while (rs.next()) {
 78                 String titlee = rs.getString("title");
 79                 String content = rs.getString("content");
 80                 String time = rs.getString("time");
 81                 String createPeople = rs.getString("createPeople");
 82                 document = new Document(titlee, content, time, createPeople);
 83                 list.add(document);
 84             }
 85         } catch (Exception e) {
 86             e.printStackTrace();
 87         } finally {
 88             Database.close(conn, pstm, rs);
 89         }
 90         return list;
 91     }
 92 
 93     public boolean checkResult(Document document) {
 94         Connection conn = null;
 95         PreparedStatement pstm = null;
 96         boolean judge = false;
 97         String receiver = "副厂长审核完毕";
 98         try {
 99             conn = Database.getConnection();
100             String sql = "update document set viceFactoryAgree=?,viceFactoryOpinion=?,receiver=? where title=?";
101             pstm = conn.prepareStatement(sql);
102             pstm.setString(1, document.getViceFactoryAgree());
103             pstm.setString(2, document.getViceFactoryOpinion());
104             pstm.setString(3, receiver);
105             pstm.setString(4, document.getTitle());
106             // 执行插入操作
107             int num = pstm.executeUpdate();
108             if (num > 0) {
109                 System.out.println("审核成功");
110                 judge = true;
111             } else {
112                 System.out.println("审核失败");
113                 judge = false;
114             }
115         } catch (Exception e) {
116             e.printStackTrace();
117         } finally {
118             // SQL执行完成后释放相关资源
119             Database.close(conn, pstm);
120         }
121         return judge;
122     }
123 }

 

posted on 2021-09-24 17:08  一缕半夏微光  阅读(44)  评论(0编辑  收藏  举报