• 公文流转2


    公文流转2

    2、公文实体:

    package com.me.domain;
    
    
    public class Doc {
        private int id;
        private int status;
        private int deletestatus;
        private String title;
        private String current;
        private String owner;
        private String content;
        private String time;
        private String firstcheck;
        private String secondcheck;
        public String getFirstcheck() {
            return firstcheck;
        }
        public void setFirstcheck(String firstcheck) {
            this.firstcheck = firstcheck;
        }
        public String getSecondcheck() {
            return secondcheck;
        }
        public void setSecondcheck(String secondcheck) {
            this.secondcheck = secondcheck;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public int getStatus() {
            return status;
        }
        public void setStatus(int status) {
            this.status = status;
        }
        public int getDeletestatus() {
            return deletestatus;
        }
        public void setDeletestatus(int deletestatus) {
            this.deletestatus = deletestatus;
        }
        public String getTitle() {
            return title;
        }
        public void setTitle(String title) {
            this.title = title;
        }
        public String getCurrent() {
            return current;
        }
        public void setCurrent(String current) {
            this.current = current;
        }
        public String getOwner() {
            return owner;
        }
        public void setOwner(String owner) {
            this.owner = owner;
        }
        public String getContent() {
            return content;
        }
        public void setContent(String content) {
            this.content = content;
        }
        public String getTime() {
            return time;
        }
        public void setTime(String time) {
            this.time = time;
        }
        @Override
        public String toString() {
            return "Doc [id=" + id + ", status=" + status + ", deletestatus=" + deletestatus + ", title=" + title
                    + ", current=" + current + ", owner=" + owner + ", content=" + content + ", time=" + time
                    + ", firstcheck=" + firstcheck + ", secondcheck=" + secondcheck + "]";
        }
        
        
    }

    权限实体:

    package com.me.domain;
    
    public class Quan {
        private String quan; 
        private int id; 
        private String address;
        public String getQuan() {
            return quan;
        }
        public void setQuan(String quan) {
            this.quan = quan;
        }
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getAddress() {
            return address;
        }
        public void setAddress(String address) {
            this.address = address;
        }
        @Override
        public String toString() {
            return "Quan [quan=" + quan + ", id=" + id + ", address=" + address + "]";
        } 
        
    }

    用户实体:

    package com.me.domain;
    
    public class User {
        private int id;
        private int uid;
        private int tid;
        private int statu;
        private String username;
        private String password;
        private String job;
    
        public int getUid() {
            return uid;
        }
    
        public void setUid(int uid) {
            this.uid = uid;
        }
    
        public int getId() {
            return id;
        }
    
        public void setId(int id) {
            this.id = id;
        }
    
        public int getTid() {
            return tid;
        }
    
        public void setTid(int tid) {
            this.tid = tid;
        }
    
        public int getStatu() {
            return statu;
        }
    
        public void setStatu(int statu) {
            this.statu = statu;
        }
    
        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 String getJob() {
            return job;
        }
    
        public void setJob(String job) {
            this.job = job;
        }
    
        @Override
        public String toString() {
            return "User [id=" + id + ", tid=" + tid + ", statu=" + statu + ", username=" + username + ", password="
                    + password + ", job=" + job + "]";
        }
    
    }

    公文servlet

    package com.me.servlet;
    
    import java.io.IOException;
    import java.sql.SQLException;
    import java.text.SimpleDateFormat;
    import java.util.Date;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.me.dao.DocDao;
    import com.me.domain.Doc;
    import com.me.domain.User;
    
    @WebServlet("/docflow")
    public class DocFlowServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
    
        public DocFlowServlet() {
            super();
        }
        DocDao docdao =new DocDao();
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            String method = request.getParameter("method");
            System.out.println(method);
            if(method.equals("to_office")) {
                try {
                    to_office(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("officelist")) {
                try {
                    officelist(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("to_next")) {
                try {
                    to_next(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("deletedoc")) {
                try {
                    deletedoc(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("firstcheck")) {
                try {
                    firstcheck(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("firstcheck2")) {
                try {
                    firstcheck2(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("firstcheck3")) {
                try {
                    firstcheck3(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("secondcheck")) {
                try {
                    secondcheck(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("secondcheck2")) {
                try {
                    secondcheck2(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("secondcheck3")) {
                try {
                    secondcheck3(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("docinfo")) {
                try {
                    docinfo(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("sent_to_down")) {
                try {
                    sent_to_down(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("sign")) {
                try {
                    sign(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("unsign")) {
                try {
                    unsign(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("audit")) {
                try {
                    audit(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("unaudit")) {
                try {
                    unaudit(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("audit2")) {
                try {
                    audit2(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else  if(method.equals("unaudit2")) {
                try {
                    unaudit2(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        
        private void unaudit2(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.unaudit2();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }
        }
    
        private void audit2(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.audit2();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }
        }
    
        private void unaudit(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.unaudit();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }
        }
    
        private void audit(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.audit();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }
        }
    
        private void unsign(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            User user = (User) request.getSession().getAttribute("who");
            String job = user.getJob();
            List<Doc> doclist = docdao.unsign(job);
            request.setAttribute("doclist", doclist);
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("department.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("department.jsp").forward(request, response);
            }
        }
        private void sign(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            User user = (User) request.getSession().getAttribute("who");
            String job = user.getJob();
            List<Doc> doclist = docdao.sign(job);
            request.setAttribute("doclist", doclist);
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("department.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("department.jsp").forward(request, response);
            }
        }
    
        private void sent_to_down(HttpServletRequest request, HttpServletResponse response) throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            boolean f=docdao.sent_to_down(id);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void docinfo(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            Doc doc=docdao.docinfo(id);
            request.setAttribute("doc", doc);
            if(doc!=null) {
                request.getRequestDispatcher("docinfo.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("docinfo.jsp").forward(request, response);
            }
        }
    
        private void secondcheck3(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            String secondcheck = request.getParameter("secondcheck");
            String check = request.getParameter("check");
            boolean f=false;
            if(check.equals("yes")) {
                f=docdao.secondcheck3(id,secondcheck);
            }else {
                f=docdao.secondcheck4(id,secondcheck);
            }
            //System.out.println(f+"123");
            response.getWriter().write("{"f":"+f+"}");
            
        }
    
        private void secondcheck2(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            Doc doc=docdao.secondcheck2(id);
            request.setAttribute("doc", doc);
            if(doc!=null) {
                request.getRequestDispatcher("secondcheck2.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("secondcheck2.jsp").forward(request, response);
            }
            
        }
    
        private void secondcheck(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.secondcheck();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("secondcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("secondcheck.jsp").forward(request, response);
            }
        }
    
        private void firstcheck3(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            System.out.println(123456);
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            String firstcheck = request.getParameter("firstcheck");
            String check = request.getParameter("check");
            boolean f=false;
            if(check.equals("yes")) {
                f=docdao.firstcheck3(id,firstcheck);
            }else {
                f=docdao.firstcheck4(id,firstcheck);
            }
            System.out.println(f+"123");
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void firstcheck2(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            Doc doc=docdao.firstcheck2(id);
            request.setAttribute("doc", doc);
            if(doc!=null) {
                request.getRequestDispatcher("firstcheck2.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck2.jsp").forward(request, response);
            }
        }
    
        private void firstcheck(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.firstchenk();
            request.setAttribute("doclist", doclist);
            System.out.println(doclist.isEmpty());
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("firstcheck.jsp").forward(request, response);
            }
        }
    
        private void deletedoc(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            boolean f=docdao.deletedoc(id);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void to_next(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            String status_str = request.getParameter("status");
            int status= Integer.parseInt(status_str);
            int status_t=0;
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            String owner = request.getParameter("owner");
            String current="";
            switch (status) {
            case 1:
                if (owner.equals("销售部门")) {
                    current="销售副厂长";
                } else if (owner.equals("财务部门")) {
                    current="财务副厂长";
                } else {
                    current="生产副厂长";
                }
                status_t=2;
                break;
            case 3:
                current="厂长";
                status_t=4;
                break;
            case 5:
                if (owner.equals("销售部门")) {
                    current="销售副厂长";
                } else if (owner.equals("财务部门")) {
                    current="财务副厂长";
                } else {
                    current="生产副厂长";
                }
                status_t=10;
                break;
            case 11:
                current=owner;
                status_t=6;
                break;
            }
            boolean f= docdao.to_fu(id,current,status_t);
            response.getWriter().write("{"f":"+f+"}");
    
        }
    
        private void officelist(HttpServletRequest request, HttpServletResponse response)throws  SQLException, ServletException, IOException {
            List<Doc> doclist =docdao.officelist();
            request.setAttribute("doclist", doclist);
            if(!doclist.isEmpty()) {
                request.getRequestDispatcher("docflow_office.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("docflow_office.jsp").forward(request, response);
            }
        }
    
        private void to_office(HttpServletRequest request, HttpServletResponse response)throws  SQLException, IOException {
            Doc doc=new Doc();
            String current="办公室";
            User user = (User) request.getSession().getAttribute("who");
            String title = request.getParameter("title");
            String content = request.getParameter("content");
            Date date = new Date();
            SimpleDateFormat dateFormat= new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
            String time=dateFormat.format(date).toString();
            doc.setContent(content);
            doc.setTitle(title);
            doc.setTime(time);
            doc.setCurrent(current);
            doc.setStatus(1);
            doc.setOwner(user.getJob());
            doc.setDeletestatus(0);
            boolean f = docdao.create(doc);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            doGet(request, response);
        }
    
    }

    用户servlet

    package com.me.servlet;
    
    import java.io.IOException;
    import java.sql.SQLException;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.me.dao.UserDao;
    import com.me.domain.Quan;
    import com.me.domain.User;
    
    @WebServlet("/user")
    public class UserServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        public UserServlet() {
            super();
        }
        UserDao userdao =new UserDao();
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
            request.setCharacterEncoding("UTF-8");
            String method = request.getParameter("method");
            if(method.equals("login")) {
                try {
                    login(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            } else if(method.equals("function")) {
                try {
                    function(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        private void function(HttpServletRequest request, HttpServletResponse response) throws  SQLException, ServletException, IOException{
            User user = (User) request.getSession().getAttribute("who");
            List<Quan> quan_list = userdao.function(user);
            request.setAttribute("quan_list", quan_list);
            if(!quan_list.isEmpty()) {
                System.out.println(quan_list.isEmpty());
                request.getRequestDispatcher("function.jsp").forward(request, response);;
            }else {
                request.getRequestDispatcher("function.jsp").forward(request, response);;
                
            }
        }
    
        private void login(HttpServletRequest request, HttpServletResponse response) throws IOException, SQLException, ServletException {
            User user= new User();
            String username = request.getParameter("username");
            String password = request.getParameter("password");
            user.setUsername(username);
            user.setPassword(password);
            user=userdao.login(user);
            
            request.getSession().setAttribute("who", user);
            if(user!=null) {
                System.out.println(user.toString());
                request.getRequestDispatcher("user?method=function").forward(request, response);;
            }else {
                request.getRequestDispatcher("index.jsp").forward(request, response);;
            }
        }
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }
    
    }

    管理servlet

    package com.me.servlet;
    
    import java.io.IOException;
    import java.sql.SQLException;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    
    import com.me.dao.UserDao;
    import com.me.domain.Quan;
    import com.me.domain.User;
    
    @WebServlet("/manage")
    public class ManageServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        public ManageServlet() {
            super();
        }
        UserDao userdao =new UserDao();
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            request.setCharacterEncoding("UTF-8");
            String method = request.getParameter("method");
            System.out.println(method);
            if(method.equals("userlist")) {
                try {
                    userlist(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("query")) {
                try {
                    query(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("add")) {
                try {
                    add(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("stop")) {
                try {
                    stop(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("start")) {
                try {
                    start(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("delete")) {
                try {
                    delete(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("change")) {
                try {
                    change(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("change2")) {
                try {
                    change2(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("changepassword")) {
                try {
                    changepassword(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("juelist")) {
                try {
                    juelist(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }else if(method.equals("bianji")) {
                try {
                    bianji(request,response);
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        private void bianji(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            int uid =Integer.parseInt(uid_str);
            User user = userdao.query(uid);
            List<Quan> quanlist = userdao.function(user);
            request.setAttribute("user", user);
            request.setAttribute("quanlist", quanlist);
            if(!quanlist.isEmpty()) {
                request.getRequestDispatcher("quan_bianji.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("index.jsp").forward(request, response);
            }
        }
    
        private void juelist(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            List<User> userlist=userdao.userlist();
            request.setAttribute("userlist", userlist);
            if(!userlist.isEmpty()) {
                request.getRequestDispatcher("juemanage.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("index.jsp").forward(request, response);
            }
        }
    
        private void changepassword(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            User user = (User) request.getSession().getAttribute("who");
            int uid = user.getUid();
            String before = request.getParameter("before");
            String password = request.getParameter("password");
            boolean f= userdao.changepassword(uid,before,password);
            if(f) {
                request.getRequestDispatcher("manage?method=userlist").forward(request, response);
            }else {
                request.getRequestDispatcher("manage?method=userlist").forward(request, response);
            }
        }
    
    
        private void change2(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            User user =new User();
            user.setUsername(request.getParameter("username"));
            user.setPassword(request.getParameter("password"));
            user.setJob(request.getParameter("job"));
            String statu_str = request.getParameter("statu");
            int statu=Integer.parseInt(statu_str);
            user.setStatu(statu);
            boolean f=userdao.change2(user);
            if(f) {
                request.getRequestDispatcher("manage?method=userlist").forward(request, response);
            }else {
                request.getRequestDispatcher("manage?method=userlist").forward(request, response);
            }
        }
    
        private void change(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            //System.out.println(uid_str);
            int uid =Integer.parseInt(uid_str);
            User user = userdao.query(uid);
            List<Quan> quanlist = userdao.function(user);
            request.setAttribute("user", user);
            request.setAttribute("quanlist", quanlist);
            if(!quanlist.isEmpty()) {
                request.getRequestDispatcher("change_user.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("change_user.jsp").forward(request, response);
            }
        }
    
        private void delete(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            int uid=Integer.parseInt(uid_str);
            boolean f=userdao.delete(uid);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void start(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            int uid=Integer.parseInt(uid_str);
            boolean f=userdao.start(uid);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void stop(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            int uid=Integer.parseInt(uid_str);
            boolean f=userdao.stop(uid);
            response.getWriter().write("{"f":"+f+"}");
        }
    
        private void add(HttpServletRequest request, HttpServletResponse response)throws SQLException, ServletException, IOException {
            User user =new User();
            user.setUsername(request.getParameter("username"));
            user.setPassword(request.getParameter("password"));
            user.setJob(request.getParameter("job"));
            String id_str = request.getParameter("id");
            int id=Integer.parseInt(id_str);
            String tid_str = request.getParameter("tid");
            int tid=Integer.parseInt(tid_str);
            user.setId(id);
            user.setTid(tid);
            boolean f=userdao.add(user);
            if(f) {
                request.getRequestDispatcher("create_user.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("create_user.jsp").forward(request, response);
            }
        }
    
        private void query(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
            String uid_str = request.getParameter("uid");
            int uid =Integer.parseInt(uid_str);
            User user = userdao.query(uid);
            List<Quan> quanlist = userdao.function(user);
            request.setAttribute("user", user);
            request.setAttribute("quanlist", quanlist);
            if(!quanlist.isEmpty()) {
                request.getRequestDispatcher("userinfo.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("userinfo.jsp").forward(request, response);
            }
        }
    
        private void userlist(HttpServletRequest request, HttpServletResponse response) throws SQLException, ServletException, IOException {
            List<User> userlist=userdao.userlist();
            request.setAttribute("userlist", userlist);
            if(!userlist.isEmpty()) {
                request.getRequestDispatcher("usermanage.jsp").forward(request, response);
            }else {
                request.getRequestDispatcher("usermanage.jsp").forward(request, response);
            }
        }
        
    
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            doGet(request, response);
        }
    
    }

    公文dao

    package com.me.dao;
    
    import java.sql.SQLException;
    import java.util.List;
    
    
    import org.apache.commons.dbutils.QueryRunner;
    import org.apache.commons.dbutils.handlers.BeanHandler;
    import org.apache.commons.dbutils.handlers.BeanListHandler;
    
    import com.me.domain.Doc;
    import com.me.utils.DBUtils;
    
    public class DocDao {
    
        public boolean create(Doc doc) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "insert into doc_list(title,owner,current,time,status,deletestatus,content) values(?,?,?,?,?,?,?)";
            int update = qr.update(sql,doc.getTitle(),doc.getOwner(),doc.getCurrent(),doc.getTime()
                    ,doc.getStatus(),doc.getDeletestatus(),doc.getContent());
            if(update>0) {
                return true;
            }else {
                return false;
            }
        }
    
        public List<Doc> officelist() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where deletestatus = 0";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
    
        public boolean to_fu(int id,String current,int status_t) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set status=?,current=?  where id=? ";
            int n = qr.update(sql, status_t , current, id);
            //System.out.println(n);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public boolean deletedoc(int id) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set deletestatus=1  where id=? ";
            int n = qr.update(sql, id);
            //System.out.println(n);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public List<Doc> firstchenk() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where ( status=2 or status = 10 ) and deletestatus = 0 ";
    //        String sql = "select * from doc_list where ( status=2 or status = 10 ) and deletestatus = 0 and current = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
    
        public Doc firstcheck2(int id) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status=2 and deletestatus = 0 and id = ?";
            Doc query = qr.query(sql, new BeanHandler<Doc>(Doc.class),id);
            return query;
        }
    
        public boolean firstcheck3(int id, String firstcheck) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set firstcheck=? , status= ? , current=? where id=? ";
            int n = qr.update(sql, firstcheck,3,"办公室",id);
            //System.out.println(n+"aa!");
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
        
        public boolean firstcheck4(int id, String firstcheck) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set firstcheck=? ,status= 8 ,current='办公室' where id=? ";
            int n = qr.update(sql, firstcheck,id);
            //System.out.println(n);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public List<Doc> secondcheck() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status=4 and deletestatus = 0 ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
        public Doc secondcheck2(int id) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status=4 and deletestatus = 0 and id = ?";
            Doc query = qr.query(sql, new BeanHandler<Doc>(Doc.class),id);
            return query;
        }
        public boolean secondcheck3(int id, String secondcheck) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set secondcheck=? , status= ? , current=? where id=? ";
            int n = qr.update(sql,secondcheck,5,"办公室",id);
            //System.out.println(n+"aa!");
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
        
        public boolean secondcheck4(int id, String secondcheck) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set secondcheck=? ,status= 9 ,current='办公室' where id=? ";
            int n = qr.update(sql, secondcheck,id);
            //System.out.println(n);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public Doc docinfo(int id) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where deletestatus = 0 and id = ?";
            Doc query = qr.query(sql, new BeanHandler<Doc>(Doc.class),id);
            return query;
        }
    
        public boolean sent_to_down(int id) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update doc_list set status=?,current=?  where id=? ";
            int n = qr.update(sql, 11 , "办公室", id);
            //System.out.println(n);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public List<Doc> sign(String job) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status=7 and deletestatus = 0 and current = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),job);
            return list;
        }
        public List<Doc> unsign(String job) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status != 7 and deletestatus = 0 and owner = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),job);
            return list;
        }
    
        public List<Doc> unaudit() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where ( status=1 or  status=2 ) and deletestatus = 0 ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
        public List<Doc> audit() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where  status !=1 and  status !=2  and deletestatus = 0 ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
        public List<Doc> unaudit2() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status<5 and status =8 and deletestatus = 0 ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
        public List<Doc> audit2() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status>4 and status !=8 and deletestatus = 0 ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
    
        public List<Doc> lookall() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list ";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class));
            return list;
        }
    
        public List<Doc> querytime(String from, String to) throws SQLException {
            
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where time >= ? and time <= ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),from,to);
            return list;
        }
    
        public List<Doc> querybyowner(String tiaojian) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where owner = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),tiaojian);
            return list;
        }
    
        public List<Doc> querybycurrent(String tiaojian) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where current = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),tiaojian);
            return list;
        }
    
        public List<Doc> querybystatus(String tiaojian) throws SQLException {
            int status =Integer.parseInt(tiaojian);
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where status = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),status);
            return list;
        }
    
        public List<Doc> querybytitle(String tiaojian) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from doc_list where title = ?";
            List<Doc> list = qr.query(sql, new BeanListHandler<Doc>(Doc.class),tiaojian);
            return list;
        }
    
    
    }

    用户dao

    package com.me.dao;
    
    import java.sql.SQLException;
    import java.util.List;
    
    import org.apache.commons.dbutils.QueryRunner;
    import org.apache.commons.dbutils.handlers.BeanHandler;
    import org.apache.commons.dbutils.handlers.BeanListHandler;
    
    import com.me.domain.Quan;
    import com.me.domain.User;
    import com.me.utils.DBUtils;
    
    public class UserDao {
    
        public User login(User user) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from user where username=? and password=? and statu = 1";
            User user01 = qr.query(sql, new BeanHandler<User>(User.class), user.getUsername(), user.getPassword());
            return user01;
        }
    
        public List<Quan> function(User user) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from quan01 where id=?";
            List<Quan> query = qr.query(sql, new BeanListHandler<Quan>(Quan.class), user.getId());
            return query;
        }
    
        public List<User> userlist() throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from user ";
            List<User> query = qr.query(sql, new BeanListHandler<User>(User.class));
            return query;
        }
    
        public User query(int uid ) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "select * from user where uid = ? ";
            User user01 = qr.query(sql, new BeanHandler<User>(User.class), uid);
            return user01;
        }
    
        public boolean add(User user) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "insert into user (id,password,username,tid,statu,job) values(?,?,?,?,?,?)";
            int update = qr.update(sql,user.getId(),user.getPassword(),user.getUsername(),user.getTid(),1,user.getJob());
            if(update>0) {
                return true;
            }else {
                return false;
            }
        }
    
        public boolean stop(int uid) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update user set statu = 0   where uid=? ";
            int n = qr.update(sql,uid);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
        public boolean start(int uid) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update user set statu = 1   where uid=? ";
            int n = qr.update(sql,uid);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public boolean delete(int uid) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="delete from user  where uid=? ";
            int n = qr.update(sql,uid);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public boolean change2(User user) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update user set password = ? , job=? , statu=?   where username=? ";
            int n = qr.update(sql,user.getPassword(),user.getJob(),user.getStatu(),user.getUsername());
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
        public User changepassword(int uid) throws SQLException {
            QueryRunner qr = new QueryRunner(DBUtils.getDataSource());
            String sql = "update user set password = ? where uid = ? ";
            User user01 = qr.query(sql, new BeanHandler<User>(User.class), uid);
            return user01;
        }
    
        public boolean changepassword(int uid, String before, String password) throws SQLException {
            QueryRunner qr =new QueryRunner(DBUtils.getDataSource());
            String sql="update user set password = ? where uid=? and password=?";
            int n = qr.update(sql,password,before,uid);
            if (n > 0) {
                return true;
            } else {
                return false;
            }
        }
    
    }
  • 相关阅读:
    序列号Pickle模块
    随机数Random模块
    selenium保存cookies 实例02
    selenium读取浏览器已有Cookies 实例01
    selenium的简单演示程序
    java连接sftp服务器读取压缩包的文件(例:读取zip中的csv文件返回数组)
    java实现连接sftp服务器并下载文件到本地
    在idea中实现热部署
    java使用IText将数据导出为pdf文件(数据为excel表格样式)
    使用poi解析Excel文件转化数组形式的集合(List<String[] list)
  • 原文地址:https://www.cnblogs.com/20183544-wangzhengshuai/p/12014033.html
Copyright © 2020-2023  润新知