0
点赞
收藏
分享

微信扫一扫

SSM框架整合项目管理系统+mysql实现图书馆预约占座管理系统(角色权限分离、功能:登录、菜单信息、班级信息、学生信息管理、角色管理、空余座位、帖子管理、通知信息、违规统计、选座、阅览室类型等)

邯唐情感 2022-05-11 阅读 48

@TOC

SSM图书馆预约占座管理系统

本系统为了解决图书馆占座难题,通过将图书馆阅览室、座位、图书等资源与学生教师关联,通过管理员端座位管理、违规、通知等管理,比较合理的给占座提供了透明的解决方案。

实现功能截图

登录
在这里插入图片描述
菜单管理
在这里插入图片描述
空余座位
在这里插入图片描述
通知
在这里插入图片描述
违规统计
在这里插入图片描述
信用积分
在这里插入图片描述
选座
在这里插入图片描述
用户管理
在这里插入图片描述
日志管理
在这里插入图片描述
书籍推荐
在这里插入图片描述
帖子管理
在这里插入图片描述
阅览室管理
请添加图片描述
请添加图片描述

系统功能

本图书馆预约占座管理系统实现了以下功能:
1、注册登录
2、空余座位管理
3、通知
4、阅览室管理
5、选座
6、帖子管理
7、书籍推荐
8、违规统计
9、信用积分
10、用户管理
11、菜单管理等

使用技术

数据库:mysql
开发工具:Eclipse(Myeclispe、Idea也可以)
知识点:SSM

代码

实体类
Book.java

package dingzhen.entity;

// 书籍管理

public class Book extends BaseEntity{

    private Integer id;
    private String name;  //书名
    private String author; //作者
    private String publish; //出版社
    private String cover;   //封面。地址
    private String remarks;  //简介
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getAuthor() {
        return author;
    }
    public void setAuthor(String author) {
        this.author = author;
    }
    public String getPublish() {
        return publish;
    }
    public void setPublish(String publish) {
        this.publish = publish;
    }
    public String getCover() {
        return cover;
    }
    public void setCover(String cover) {
        this.cover = cover;
    }
    public String getRemarks() {
        return remarks;
    }
    public void setRemarks(String remarks) {
        this.remarks = remarks;
    }
}

Seat.java

package dingzhen.entity;

// 座位信息
public class Seat extends BaseEntity{

    private Integer id;
    private Integer roomid;     //教室
    private String  roomname;
    private String studentno;  //学生
    private String studentname;
    private Integer col;   //列位置
    private Integer row;   // 行位置
    private String time;   //时间段
    private String date;
    private String keyword;     //由roomid,date,time,row,col组成

    public String getKeyword() {
        return keyword;
    }
    public void setKeyword(String keyword) {
        this.keyword = keyword;
    }
    public String getDate() {
        return date;
    }
    public void setDate(String date) {
        this.date = date;
    }
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getRoomid() {
        return roomid;
    }
    public void setRoomid(Integer roomid) {
        this.roomid = roomid;
    }
    public String getRoomname() {
        return roomname;
    }
    public void setRoomname(String roomname) {
        this.roomname = roomname;
    }
    public String getStudentno() {
        return studentno;
    }
    public void setStudentno(String studentno) {
        this.studentno = studentno;
    }
    public String getStudentname() {
        return studentname;
    }
    public void setStudentname(String studentname) {
        this.studentname = studentname;
    }
    public Integer getCol() {
        return col;
    }
    public void setCol(Integer col) {
        this.col = col;
    }
    public Integer getRow() {
        return row;
    }
    public void setRow(Integer row) {
        this.row = row;
    }
    public String getTime() {
        return time;
    }
    public void setTime(String time) {
        this.time = time;
    }

}

dao层
BookDao.java

package dingzhen.dao;

import java.util.List;

import org.mybatis.spring.annotation.Mapper;

@Mapper("bookDao")
public interface BookDao<T> {
    // 查询所有
    public abstract List<T> findBook(T t) throws Exception;

    // 数量
    public abstract int countBook(T t) throws Exception;

    // 新增
    public abstract void addBook(T t) throws Exception;

    // 修改
    public abstract void updateBook(T t) throws Exception;

    // 删除
    public abstract void deleteBook(Integer id) throws Exception;

    public abstract T findOneBook(int id) throws Exception;

}

SeatDao.java

package dingzhen.dao;

import java.util.List;

import org.mybatis.spring.annotation.Mapper;

@Mapper("seatDao")
public interface SeatDao<T> {
    // 查询所有
    public abstract List<T> findSeat(T t) throws Exception;

    // 数量
    public abstract int countSeat(T t) throws Exception;

    // 新增
    public abstract void insertSeat(T t) throws Exception;

    // 修改
    public abstract void modifySeat(T t) throws Exception;

    // 删除
    public abstract void deleteSeat(Integer id) throws Exception;

    // 占座
    public abstract void occupySeat(T t) throws Exception;

    // 取消占座
    public abstract void cancelSeat(String keyword) throws Exception;

    //查询余座
    public abstract int findBlock(T t) throws Exception;

}

service层
BookServiceImpl.java

package dingzhen.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dingzhen.dao.BookDao;
import dingzhen.service.BookService;

@Service("bookService")
public class BookServiceImpl<T> implements BookService<T>{

    @Autowired
    private BookDao<T> dao;

    public List<T> findBook(T t) throws Exception {
        return dao.findBook(t);
    }

    public int countBook(T t) throws Exception {
        return dao.countBook(t);
    }

    public void addBook(T t) throws Exception {
        dao.addBook(t);
    }

    public void updateBook(T t) throws Exception {
        dao.updateBook(t);
    }

    public void deleteBook(Integer id) throws Exception {
        dao.deleteBook(id);
    }

    public T findOneBook(int id) throws Exception {
        return dao.findOneBook(id);
    }

}

SeatServiceImpl.java

package dingzhen.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import dingzhen.dao.SeatDao;
import dingzhen.service.SeatService;

@Service("seatService")
public class SeatServiceImpl<T> implements SeatService<T>{

    @Autowired
    private SeatDao<T> dao;

    public List<T> findSeat(T t) throws Exception {
        return dao.findSeat(t);
    }

    public int countSeat(T t) throws Exception {
        return dao.countSeat(t);
    }

    public void insertSeat(T t) throws Exception {
        dao.insertSeat(t);
    }

    public void modifySeat(T t) throws Exception {
        dao.modifySeat(t);
    }

    public void deleteSeat(Integer id) throws Exception {
        dao.deleteSeat(id);
    }

    public void occupySeat(T t) throws Exception {
        dao.occupySeat(t);
    }

    public void cancelSeat(String keyword) throws Exception {
        dao.cancelSeat(keyword);
    }

    public int findBlock(T t) throws Exception {
        return dao.findBlock(t);
    }
}

Controller层
BookController.java

package dingzhen.controller;

// 书籍管理控制器
import java.io.File;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import dingzhen.entity.Book;
import dingzhen.entity.User;
import dingzhen.service.BookService;
import dingzhen.util.StringUtil;
import dingzhen.util.WriterUtil;

@Controller
@RequestMapping("book")
public class BookController {

    private int page;
    private int rows;
    @Autowired
    private BookService<Book> bookService;
    private Book book;

    @RequestMapping("bookIndex")
    public String index(HttpServletRequest request){
        User currentUser = (User)request.getSession().getAttribute("currentUser");
        if(currentUser.getRoleId()==1){
            return "tuijian/bookIndexForAdmin";
        } else {
            return "tuijian/bookIndex";
        }
    }

    @RequestMapping("bookList")
    public void bookList(HttpServletRequest request,HttpServletResponse response) {
        try {
            page = Integer.parseInt(request.getParameter("page"));
            rows = Integer.parseInt(request.getParameter("rows"));
            book = new Book();
            book.setPage((page-1)*rows);
            book.setRows(rows);
            List<Book> list = bookService.findBook(book);
            int total = bookService.countBook(book);
            JSONObject jsonObj = new JSONObject();//new一个JSON
            jsonObj.put("total",total );//total代表一共有多少数据
            jsonObj.put("rows", list);//row是代表显示的页的数据
            WriterUtil.write(response,jsonObj.toString()); //将上述Json输出,前台ajax接收
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @RequestMapping("reserveBook")
    public void reserveBook(HttpServletRequest request,HttpServletResponse response,Book book) {
        String id = request.getParameter("id");
        JSONObject result = new JSONObject();
        result.put("success", true);
        try {
            if(StringUtil.isNotEmpty(id)){
                book.setId(Integer.parseInt(id));
                bookService.updateBook(book);
            } else {
                bookService.addBook(book);
            }
        } catch (Exception e) {
            e.printStackTrace();
            result.put("errorMsg", "对不起!保存失败");
        }
        WriterUtil.write(response, result.toString());
    }

    @RequestMapping("deleteBook")
    public void delete(HttpServletRequest request,HttpServletResponse response){
        JSONObject result=new JSONObject();
        try {
            String[] ids=request.getParameter("ids").split(",");
            for (int i=0;i<ids.length;i++) {
                bookService.deleteBook(Integer.parseInt(ids[i]));
            }
            result.put("success", true);
            result.put("delNums", ids.length);
        } catch (Exception e) {
            e.printStackTrace();
            result.put("errorMsg", "对不起,删除失败");
        }
        WriterUtil.write(response, result.toString());
    }

    @RequestMapping("uploadCover")
    public void uploadPhoto(HttpServletRequest request,HttpServletResponse response,@RequestParam MultipartFile cover){
        String now = System.currentTimeMillis()+"";
        if (!cover.isEmpty()) {
            String filePath = request.getSession().getServletContext().getRealPath("/")+ "upload/book/" + now + ".jpg";
            try {
                cover.transferTo(new File(filePath));
                book.setCover("upload/book/" + now + ".jpg");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        WriterUtil.write(response, "upload/book/" + now + ".jpg");
    }

}

SeatController.java

package dingzhen.controller;

// 座位管理
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.sun.org.apache.bcel.internal.generic.NEW;

import dingzhen.entity.Choice;
import dingzhen.entity.ComboValue;
import dingzhen.entity.Room;
import dingzhen.entity.Score;
import dingzhen.entity.Seat;
import dingzhen.entity.User;
import dingzhen.service.ChoiceService;
import dingzhen.service.RoomService;
import dingzhen.service.ScoreService;
import dingzhen.service.SeatService;
import dingzhen.util.WriterUtil;
@Controller
@RequestMapping("seat")
public class SeatController {

    private int page;
    private int rows;
    @Autowired
    private SeatService<Seat> seatService;
    private Seat seat;
    @Autowired
    private RoomService<Room> roomService;
    @Autowired
    private ChoiceService<Choice> choiceService;
    private Choice choice;
    @Autowired
    private ScoreService<Score> scoreService;
    private Score score;

    @RequestMapping("seatIndex")
    public String index(){
        return "seat/selectSeat";
    }

    @RequestMapping("combolist")
    public void seatList(HttpServletRequest request,HttpServletResponse response) {
        try {
            seat = new Seat();
            String date = request.getParameter("date");
            if(date==null || date.length()==0){
                seat.setDate(new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            }else {
                seat.setDate(date);
            }
            if(request.getParameter("roomid")!=null && request.getParameter("roomid").length() > 0){
                seat.setRoomid(Integer.parseInt(request.getParameter("roomid")));
            } else {
                seat.setRoomid(1);
            }
            String time = request.getParameter("time");
            if(time == null || time.length()==0){
                seat.setTime("08点-12点");
            }else {
                seat.setTime(time);
            }
            List<Seat> list = seatService.findSeat(seat);
            JSONArray array = new JSONArray();
            array.addAll(list);
            WriterUtil.write(response, array.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 今天和明天
    @RequestMapping("dateCombo")
    public void dateCombo(HttpServletRequest request,HttpServletResponse response){
        try {
            // 获取今明两天时间的String值。格式是yyyy-MM-dd
            Date todayDate = new Date();
            Date tomorrowDate = getNextDay(todayDate);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String today = sdf.format(todayDate);
            String tomorrow = sdf.format(tomorrowDate);

            List<ComboValue> list = new ArrayList<ComboValue>();
            ComboValue cv = new ComboValue(today, "今天  "+today);
            list.add(cv);
            ComboValue cv2 = new ComboValue(tomorrow, "明天  "+tomorrow);
            list.add(cv2);

            JSONArray array = new JSONArray();
            array.addAll(list);
            WriterUtil.write(response, array.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    // 获取明天日期
    public static Date getNextDay(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, 1);
        date = calendar.getTime();
        return date;
    }

    // 3个时间段
    @RequestMapping("timeCombo")
    public void timeCombo(HttpServletRequest request,HttpServletResponse response) {
        try {
            List<ComboValue> list = new ArrayList<ComboValue>();
            ComboValue cv =  new ComboValue("08点-12点","08点-12点");
            list.add(cv);
            ComboValue cv2 = new ComboValue("14点-18点","14点-18点");
            list.add(cv2);
            ComboValue cv3 = new ComboValue("18点-22点","18点-22点");
            list.add(cv3);
            JSONArray array = new JSONArray();
            array.addAll(list);
            WriterUtil.write(response, array.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 阅览室
    @RequestMapping("roomCombo")
    public void roomCombo(HttpServletRequest request,HttpServletResponse response){
        try {
            List<Room> list = roomService.findRoom(new Room());
            JSONArray array = new JSONArray();
            array.addAll(list);
            WriterUtil.write(response, array.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //查找自己的作为
    @RequestMapping("myselfSeat")
    public void myselfSeat(HttpServletRequest request,HttpServletResponse response){
        User currentUser = (User)request.getSession().getAttribute("currentUser");
        try {
            String date = request.getParameter("date");
            if(date==null || date.length()==0){
                date = (new SimpleDateFormat("yyyy-MM-dd").format(new Date()));
            }
            String roomid = request.getParameter("roomid");
            if(roomid==null || roomid.length()==0){
                roomid = "1";
            } 
            String time = request.getParameter("time");
            if(time == null || time.length()==0){
                time = "08点-12点";
            }
            Choice c = new Choice();
            c.setSeatkeyword(date + "-" +time + "-" +roomid);
            c.setStudentno(currentUser.getUserName());
            choice = choiceService.findOneChoice(c);
            if(choice == null){
                WriterUtil.write(response, "no");
            } else {
                WriterUtil.write(response, choice.getSeatkeyword());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 保存选中座位
    @RequestMapping("saveSeat")
    public void saveSeat(HttpServletRequest request,HttpServletResponse response) {
        String keyword = request.getParameter("keyword");
        System.out.println("key---"+keyword);
        User currentUser = (User)request.getSession().getAttribute("currentUser");
        if(currentUser.getRoleId() == 1  || currentUser.getRoleId()==2){  //超管和教师不能选座
            WriterUtil.write(response, "对不起,该阅览室选座只对学生开放");
            return;
        }
        String studentno = currentUser.getUserName();
        String nowDateHour = new SimpleDateFormat("yyyy-MM-dd-HH").format(new Date());  //当前小时数
        String selectedDate = keyword.substring(0,13);  
        try {
            //判断信用积分
            score = scoreService.findOneScore(studentno);
            int myScore = score.getTotal();     //该学生分数

            int roomid = Integer.parseInt(keyword.substring(19,20));
            int needScore = roomService.findScoreByRoomid(roomid);
            if(needScore >= myScore){
                WriterUtil.write(response, "预约失败!您的信用积分不允许在该阅览室选座");return;
            }
            String flag = "1";
            Choice c = new Choice();
            c.setStudentno(studentno);
            c.setStatus("0");
            List<Choice> list = choiceService.findChoice(c);
            if(list==null || list.size()==0){
                // 无预约 OK的
            } else if(list.size()>3){
                // 限预约3次
                flag = "3";
            }else {
                for(Choice choice : list){
                    if(choice.getSeatkeyword().substring(0,17).equals(keyword.substring(0,17))){
                        //重复了
                        flag = "2";
                        break;
                    }
                }

            }
            if("3".equals(flag)){
                WriterUtil.write(response, "预约失败!24小时之类已经预约3次了");return;
            } else if ("2".equals(flag)) {
                WriterUtil.write(response, "预约失败!这个时间段已经预约过其他阅览室了");return;
            } else {
                choice = new Choice();
                choice.setSeatkeyword(keyword);
                choice.setStudentno(studentno);
                choice.setTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
                choiceService.addChoice(choice);

                seat = new Seat();
                seat.setKeyword(keyword);
                seat.setStudentno(studentno);
                seatService.occupySeat(seat);

                WriterUtil.write(response, "ok");
            }
        } catch (Exception e) {
            e.printStackTrace();
            WriterUtil.write(response, "对不起!系统错误,选座失败!");
        }
    }

    //取消
    @RequestMapping("cancelSeat")
    public void cancelSeat(HttpServletRequest request,HttpServletResponse response){
        User currentUser = (User)request.getSession().getAttribute("currentUser");
        try {
            // 删除choice表中的记录
            String keyword = request.getParameter("seatkeyword");
            Choice choice = new Choice();
            choice.setSeatkeyword(keyword.substring(0, 20));
            choice.setStudentno(currentUser.getUserName());
            choiceService.cancelChoice(choice);

            // 将seat表中该条记录学号变成1
            seatService.cancelSeat(keyword); //

            WriterUtil.write(response, "ok");
        } catch (Exception e) {
            e.printStackTrace();
            WriterUtil.write(response, "对不起!取消失败");
        }
    }

}

写在最后

如果运行代码中遇到问题,或者需要完整源码和报告,可以博主私信交流

觉得有用,记得一键三连哦!

举报

相关推荐

0 条评论