系统采用 B/S 架构,后端基于 Java 语言和 SpringBoot 框架的方式进行了开发,前端则是使用 Layui 框架,结合 HTML、JQuery、Ajax 等技术进行开发,并使用 MySQL 5.7数据库对所有相关的信息进行了存储。系统主要包括基本信息管理、离返校管理、宿舍分配管理、宿日常管理、综合查询管理等五大功能模块,并根据学生、辅导员、宿舍管理员的使用需求对这些功能进行了细化和实现。
高校宿舍作为大学生活的一部分,起着举足轻重的作用。如何高效地管理这些宿舍资源,在保证学生生活品质的基础上优化管理流程,是国内外高校所关注的问题。因此,建立一套高校宿舍管理系统成为了必然趋势。
首先,高校宿舍管理系统有利于提高资源的利用效率。一般来说,不同年级、专业和性别的学生需要居住在不同的宿舍楼或宿舍区,而每个宿舍楼又分为不同的房间或床位。如果采用传统的管理方式,仅靠人工计算和安排,难免会有漏洞,影响学生的合理分配。而通过建立高校宿舍管理系统,可以实现对宿舍信息、学生信息等多方面的集中管理,避免信息不对称的情况出现,从而更加科学地规划、调配宿舍资源,保证各方的利益得到最大化的满足。
其次,高校宿舍管理系统能够提高管理效率。传统的手工管理方式,需要学校人员进行大量的文件整理、数据更新和查询、物资配送等工作,容易出现管理混乱、数据错误等情况。而有了高校宿舍管理系统,学校可以通过信息化手段实现各项管理任务的自动化,提高管理效率,减轻管理员工作负担,使其更加专注于维护宿舍的安全和学生的权益。
第三,高校宿舍管理系统还可以提高宿舍管理服务质量。通过该系统,学校可以及时了解到宿舍信息、维修情况、毛巾、卫生纸等日常用品的库存量等信息,对相关问题进行快速响应和处理,规范管理流程,优化服务流程,增强宿舍管理服务的质量和效率,为广大学生提供一个良好的住宿环境。
最后,高校宿舍管理系统具有推广和普及的广阔前景。随着高校教育的普及和发展,建立高校宿舍管理系统也将不断完善和优化,成为高校数字化管理的重要组成部分之一。在未来,如果能将该系统有效地推广到其他领域,如企事业单位、社区居委会等,将会大大提高公共资源的利用效率,提高服务质量,助力社会管理。
总之,高校宿舍管理系统在日益发展的大数据时代具有重要的研究背景和深远的意义。通过科技手段对高校宿舍进行精细化、信息化管理,不仅有利于提高高校宿舍资源的利用效率、增强宿舍管理服务质量和提高管理效率,而且还将为构建数字化、智慧化的学校管理模式作出积极的贡献。
本文从高校宿舍管理工作的实际情形出发,对系统开展了需求分析,为相关业务建立用例模型和行为模型。接着在需求分析的基础上,对系统的体系结构、功能模块以及数据库进行设计并实现。最后对系统的各个功能进行简单的功能测试,验证
系统功能实现的正确性和可操作性。
宿舍是大学生日常生活中的重要休息地点和活动场所,集齐了学习、生活、交往等多种重要功能于一体,是高校管理工作的重要组成部分。随着高校的不断扩张,学生的数量急剧增加,传统的管理模式存在许多不足,难以满足现今高校的管理需求。本系统的建设目标就是开发出一个科学、合理、高效的宿舍管理系统,解决传统管理方式中存在的问题,满足高校宿舍日常管理的需要,减轻宿管人员的负担,提高宿舍管理的水平,争取为学生提供更高质量的服务。
系统遵照 MVC 设计架构理念和工作模式,采用了三层体系结构,分别为表现层、业务逻辑层以及数据访问层
package com.usc.ms.doms.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.usc.ms.doms.entity.*;
import com.usc.ms.doms.entity.BuildRoomInfo;
import com.usc.ms.doms.entity.RepairInfo;
import com.usc.ms.doms.entity.StayInfo;
import com.usc.ms.doms.service.DorMService;
import com.usc.ms.doms.utils.MyStringUtil;
import com.usc.ms.doms.utils.DataGridViewResult;
import com.usc.ms.doms.utils.ExcelUtils;
import com.usc.ms.doms.vo.*;
import com.usc.ms.doms.entity.AllocationInfo;
import com.usc.ms.doms.entity.CleanInfo;
import com.usc.ms.doms.entity.MessageBoard;
import com.usc.ms.doms.entity.StudentInfo;
import com.usc.ms.doms.vo.AllocationInfoVo;
import com.usc.ms.doms.vo.BuildRoomInfoVo;
import com.usc.ms.doms.vo.CleanInfoVo;
import com.usc.ms.doms.vo.MessageBoardVo;
import com.usc.ms.doms.vo.RepairInfoVo;
import com.usc.ms.doms.vo.StayInfoVo;
import com.usc.ms.doms.vo.StudentInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSON;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.*;
@Controller
@RequestMapping("/dm")
public class DorMController {
@Resource
private DorMService dormService;
/**
* 卫生检查列表
*
* @return
*/
@RequestMapping(value = "/cleanList")
public String cleanList() {
return "/dm/clean-list";
}
/**
* 查看卫生检查情况
*
* @param ciVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/clean/list")
public DataGridViewResult findCleanInfoList(CleanInfoVo ciVo, HttpServletRequest request) {
// 获取宿管员管理的宿舍区和楼栋号,拼接成brcode
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
String brcode = MyStringUtil.getBrcode(brarea, brbid, "");
if (StringUtils.isNotBlank(brcode)) {
ciVo.setBrcode(brcode);
}
System.out.println(ciVo);
// 设置分页信息
PageHelper.startPage(ciVo.getPage(), ciVo.getLimit());
// 查询
List<CleanInfo> list = dormService.findCleanInfoListByPage(ciVo);
// 创建分页对象
PageInfo<CleanInfo> pageInfo = new PageInfo<CleanInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 更改卫生检查信息
*
* @param ci
* @return
*/
@ResponseBody
@RequestMapping(value = "/clean/update")
public String updateCleanInfo(CleanInfo ci) {
System.out.println(ci);
HashMap<String, Object> map = new HashMap<>();
int result = dormService.updateCleanInfo(ci);
if (result > 0) {
map.put("success", true);
map.put("msg", "更改成功!");
} else {
map.put("success", false);
map.put("msg", "更改失败!");
}
return JSON.toJSONString(map);
}
/**
* 删除卫生检查记录
*
* @param id
* @return
*/
@ResponseBody
@RequestMapping(value = "/clean/delete")
public String deleteCleanInfo(String id) {
System.out.println(id);
HashMap<String, Object> map = new HashMap<>();
int result = dormService.deleteCleanInfo(id);
if (result > 0) {
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
return JSON.toJSONString(map);
}
/**
* 返回添加卫生检查记录页面
*
* @return
*/
@RequestMapping(value = "/clean/add.html")
public String addCleanInfo() {
return "/dm/clean-add";
}
/**
* 批量添加卫生检查记录
*
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/clean/add")
public String batchAddCleanInfo(HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String params = request.getParameter("params");
String checker = (String) request.getSession().getAttribute("uname");
try {
boolean result = dormService.batchInsertCleanInfo(params, checker);
if (result) {
map.put("success", true);
map.put("msg", "添加成功!");
} else {
map.put("success", false);
map.put("msg", "添加失败!");
}
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("msg", "添加失败!");
}
return JSON.toJSONString(map);
}
/**
* 学生报修列表
*
* @return
*/
@RequestMapping(value = "/repairList")
public String viewRepairList() {
return "/dm/repair-list";
}
/**
* 查找该宿管员负责的楼栋下的报修信息
*
* @param riVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/repair/list")
public DataGridViewResult findRepairInfoList(RepairInfoVo riVo, HttpServletRequest request) {
// 拼接brcode
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
if (StringUtils.isBlank(brarea)) {
brarea = riVo.getBrarea();
}
if (StringUtils.isBlank(brbid)) {
brbid = riVo.getBrbid();
}
String brcode = MyStringUtil.getBrcode(brarea, brbid, "");
if (StringUtils.isNotBlank(brcode)) {
riVo.setBrcode(brcode);
}
System.out.println(riVo);
// 设置分页信息
PageHelper.startPage(riVo.getPage(), riVo.getLimit());
// 查询
List<RepairInfo> list = dormService.findRepairInfoListByPage(riVo);
// 创建分页对象
PageInfo<RepairInfo> pageInfo = new PageInfo<RepairInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 查看报修详情
*
* @return
*/
@RequestMapping(value = "/repair/detail.html")
public String repairDetail() {
return "/dm/repair-detail";
}
/**
* 导出报修数据
*
* @param request
* @param response
*/
@ResponseBody
@RequestMapping(value = "/repair/export.action")
public void exportToExcel(HttpServletRequest request, HttpServletResponse response) {
HashMap<String, Object> map = new HashMap<>();
response.reset();// 清除缓存
// 获取宿管员管理的宿舍区和楼栋号,拼接成brcode
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
String brcode = MyStringUtil.getBrcode(brarea, brbid, "");
String status = request.getParameter("status");
System.out.println("status" + status);
System.out.println("brcode" + brcode);
// 根据条件查找报修列表
List<RepairInfo> list = dormService.exportRepairInfo(brcode, status);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(brcode)) {
filenamebuffer.append(brcode);
filenamebuffer.append("-");
}
filenamebuffer.append("报修表");
String filename = filenamebuffer.toString();
try {
ExcelUtils.writeExcel(filename, response, list, RepairInfo.class);
map.put("success", true);
map.put("msg", "导出成功!");
System.out.println(JSON.toJSONString(map));
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("msg", "导出失败!");
}
// return JSON.toJSONString(map);
}
/**
* 批量更改报修状态
*
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/repair/edit")
public String editRepairStatus(HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String params = request.getParameter("params");
if (StringUtils.isNotBlank(params)) {
boolean result = dormService.batchEditRepairStatus(params);
if (result) {
map.put("success", true);
map.put("msg", "更改成功!");
return JSON.toJSONString(map);
} else {
map.put("success", false);
map.put("msg", "更改失败!");
return JSON.toJSONString(map);
}
}
map.put("success", false);
map.put("msg", "更改失败!请选择要更改的行。");
return JSON.toJSONString(map);
}
/**
* 学生报修列表
*
* @return
*/
@RequestMapping(value = "/buildroomList")
public String viewBuildRoomList() {
return "/dm/buildroom-list";
}
/**
* 查看宿舍信息
*
* @param biVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/buildroom/list")
public DataGridViewResult findBuildRoomInfo(BuildRoomInfoVo biVo, HttpServletRequest request) {
// 拼接brcode
String brarea = (String) request.getSession().getAttribute("brarea");
if (StringUtils.isBlank(brarea)) {
brarea = biVo.getBrarea();
}
/*
* 如果管理员负责具体的一栋楼,则只能查询本栋楼有关的宿舍信息;
* 如果是负责一个区,则可以查询这个区下所有楼的宿舍信息
* session中没有brbid说明是负责一个区的,此时按照用户输入的楼栋数来进行查询
*/
String brbid = (String) request.getSession().getAttribute("brbid");
if (StringUtils.isBlank(brbid)) {
brbid = biVo.getBrbid();
}
String brrid = biVo.getBrrid();
String brcode = MyStringUtil.getBrcode(brarea, brbid, brrid);
if (StringUtils.isNotBlank(brcode)) {
biVo.setBrcode(brcode);
}
System.out.println(biVo);
// 设置分页信息
PageHelper.startPage(biVo.getPage(), biVo.getLimit());
// 查询
List<RepairInfo> list = dormService.findBuildRoomInfoListByPage(biVo);
// 创建分页对象
PageInfo<RepairInfo> pageInfo = new PageInfo<RepairInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 单个添加宿舍信息
*
* @param bi
* @return
*/
@ResponseBody
@RequestMapping(value = "/buildroom/add")
public String addBuildRoomInfo(BuildRoomInfo bi) {
HashMap<String, Object> map = new HashMap<>();
// 拼接brcode,如果brcode是空,说明宿舍信息错误了
String brarea = bi.getBrarea();
String brbid = bi.getBrbid();
String brrid = bi.getBrrid();
String brcode = MyStringUtil.getBrcode(brarea, brbid, brrid);
if (StringUtils.isBlank(brcode)) {
map.put("success", false);
map.put("msg", "添加失败!宿舍信息错误!");
return JSON.toJSONString(map);
}
// 计算空余数
Integer free = bi.getVolume() - bi.getPeople();
if (free < 0) {
map.put("success", false);
map.put("msg", "添加失败!入住数不能大于床位数!");
return JSON.toJSONString(map);
}
bi.setBrcode(brcode);
bi.setFree(free);
System.out.println(bi);
List<BuildRoomInfo> list = new ArrayList<>();
list.add(bi);
boolean result = dormService.addBuildRoomInfo(list);
if (result) {
map.put("success", true);
map.put("msg", "添加成功!");
} else {
map.put("success", false);
map.put("msg", "添加失败!");
}
return JSON.toJSONString(map);
}
/**
* 导入宿舍信息
*
* @param file excel表格
* @return
*/
@ResponseBody
@RequestMapping(value = "/buildroom/import.action")
public String importExcel(@RequestParam("file") MultipartFile file) {
HashMap<String, Object> map = new HashMap<>();
try {
List<BuildRoomInfo> list = ExcelUtils.readExcel("", BuildRoomInfo.class, file);
// 拼接brcode和计算空余数
for (int i = 0; i < list.size(); i++) {
String brarea = list.get(i).getBrarea();
String brbid = list.get(i).getBrbid();
String brrid = list.get(i).getBrrid();
String brcode = MyStringUtil.getBrcode(brarea, brbid, brrid);
Integer free = list.get(i).getVolume() - list.get(i).getPeople();
list.get(i).setBrcode(brcode);
list.get(i).setFree(free);
}
boolean result = dormService.addBuildRoomInfo(list);
if (result) {
map.put("code", 200);
map.put("msg", "导入成功!");
map.put("data", null);
} else {
map.put("code", 500);
map.put("msg", "导入失败!");
map.put("data", null);
}
} catch (Exception e) {
e.printStackTrace();
map.put("code", 500);
map.put("msg", "导入失败!");
map.put("data", null);
}
return JSON.toJSONString(map);
}
/**
* 更改宿舍信息
*
* @param bi
* @return
*/
@ResponseBody
@RequestMapping(value = "/buildroom/update")
public String updateBuildRoomInfo(BuildRoomInfo bi) {
HashMap<String, Object> map = new HashMap<>();
try {
// 如果入住数小于等于床位数,则执行更新操作,否则返回提示
Integer free = bi.getVolume() - bi.getPeople();
if (free >= 0) {
bi.setFree(free);
System.out.println(bi);
int result = dormService.updateBuildRoomInfo(bi);
// 返回值大于0表示成功执行了更改操作,小于0表示发生了异常
if (result > 0) {
map.put("success", true);
map.put("msg", "更改成功!");
return JSON.toJSONString(map);
} else {
map.put("success", false);
map.put("msg", "更改失败!");
return JSON.toJSONString(map);
}
} else {
map.put("success", false);
map.put("msg", "更改失败!入住数不能大于床位数!");
return JSON.toJSONString(map);
}
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("msg", "更改失败!");
return JSON.toJSONString(map);
}
}
/**
* 删除宿舍信息
*
* @param brcode
* @return
*/
@ResponseBody
@RequestMapping(value = "/buildroom/delete")
public String deleteBuildRoomInfo(String brcode) {
System.out.println(brcode);
HashMap<String, Object> map = new HashMap<>();
int result = dormService.deleteBuildRoomInfo(brcode);
if (result > 0) {
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
return JSON.toJSONString(map);
}
@RequestMapping(value = "/messageList")
public String viewMessageBoard() {
return "/dm/message-list";
}
/**
* 公告管理、失物招领
*
* @param mbVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/message/list")
public DataGridViewResult findMessageList(MessageBoardVo mbVo, HttpServletRequest request) {
// 获取当前管理员的管理区域
// 如果管理员负责众多楼栋,则按查询条件的宿舍区和楼栋来查,否则只能查他所负责的楼栋的公告信息
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
if (StringUtils.isBlank(brarea)) {
brarea = mbVo.getBrarea();
}
if (StringUtils.isBlank(brbid)) {
brbid = mbVo.getBrbid();
}
String brcode = MyStringUtil.getBrcode(brarea, brbid, "");
mbVo.setBrcode(brcode);
System.out.println(mbVo);
// 设置分页信息
PageHelper.startPage(mbVo.getPage(), mbVo.getLimit());
// 查询
List<MessageBoard> list = dormService.findMessageListByPage(mbVo);
// 创建分页对象
PageInfo<MessageBoard> pageInfo = new PageInfo<MessageBoard>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 添加公告/失物招领信息
*
* @param mb
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/message/add")
public String addMessage(MessageBoard mb, HttpServletRequest request) {
// announcer是管理员的uname
String uname = (String) request.getSession().getAttribute("uname");
mb.setAnnouncer(uname);
HashMap<String, Object> map = new HashMap<>();
int result = dormService.addMessage(mb);
if (result > 0) {
map.put("success", true);
map.put("msg", "添加成功!");
} else {
map.put("success", false);
map.put("msg", "添加失败!");
}
return JSON.toJSONString(map);
}
/**
* 更新公告/失物招领
*
* @param mb
* @return
*/
@ResponseBody
@RequestMapping(value = "/message/update")
public String updateMessage(MessageBoard mb) {
// 拼接brcode
String brcode = MyStringUtil.getBrcode(mb.getBrarea(), mb.getBrbid(), "");
mb.setBrcode(brcode);
System.out.println(mb);
HashMap<String, Object> map = new HashMap<>();
int result = dormService.updateMessage(mb);
if (result > 0) {
map.put("success", true);
map.put("msg", "更改成功!");
} else {
map.put("success", false);
map.put("msg", "更改失败!");
}
return JSON.toJSONString(map);
}
/**
* 批量删除公告/失物招领信息
*
* @param request 获取前端传来的id数组
* @return
*/
@ResponseBody
@RequestMapping(value = "/message/delete")
public String deleteMessage(HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String params = request.getParameter("params");
System.out.println(params);
try {
if (StringUtils.isNotBlank(params)) {
// 获取id数组
JSONArray jsonArray = JSONArray.parseArray(params);
List<Integer> list = new ArrayList<>();
for (int i = 0; i < jsonArray.size(); i++) {
JSONObject obj = jsonArray.getJSONObject(i);
Integer id = (Integer) obj.get("id");
System.out.println(id);
list.add(id);
}
boolean result = dormService.deleteMessage(list);
if (result) {
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
}
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("msg", "删除失败!");
}
return JSON.toJSONString(map);
}
/**
* 留校信息列表
*
* @return
*/
@RequestMapping(value = "/stayinList")
public String viewStayInfoList() {
return "/dm/stayin-list";
}
/**
* 查找留校信息列表
*
* @param stVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/list")
public DataGridViewResult findStayInfoListByPage(StayInfoVo stVo, HttpServletRequest request) {
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
if (StringUtils.isNotBlank(brarea)) {
stVo.setBrarea(brarea);
}
if (StringUtils.isNotBlank(brbid)) {
stVo.setBrbid(brbid);
}
System.out.println(stVo);
// 设置分页信息
PageHelper.startPage(stVo.getPage(), stVo.getLimit());
// 查询
List<StayInfo> list = dormService.findStayInfoListByPage(stVo);
// 创建分页对象
PageInfo<StayInfo> pageInfo = new PageInfo<StayInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 导出学生留校信息
*
* @param request
* @param response
*/
@ResponseBody
@RequestMapping(value = "/stayin/export.action")
public void exportStayInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
response.reset();// 清除缓存
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
// 查找学生登记信息
List<StayInfo> list = dormService.exportStayInfo(brarea, brbid);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(brarea)) {
filenamebuffer.append(brarea);
filenamebuffer.append("-");
}
if (StringUtils.isNotBlank(brbid)) {
filenamebuffer.append(brbid);
filenamebuffer.append("栋-");
}
filenamebuffer.append("学生留校信息");
String filename = filenamebuffer.toString();
try {
ExcelUtils.writeExcel(filename, response, list, StayInfo.class);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 获取留校申请中的统计数据
*
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/echartsData")
public String getStayInfoEchartsData(HttpServletRequest request) {
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
JSONObject data = dormService.getStayInfoEchartsData(brarea, brbid);
System.out.println(JSON.toJSONString(data));
return JSON.toJSONString(data);
}
/**
* 预分配宿舍界面
*
* @return
*/
@RequestMapping(value = "/allocation/pre")
public String preAllocateDorm() {
return "/dm/pre-allocate";
}
/**
* 查找空余寝室
*
* @param biVo
* @return
*/
@ResponseBody
@RequestMapping(value = "/room/list")
public DataGridViewResult getFreeRoomList(BuildRoomInfoVo biVo) {
System.out.println(biVo);
// 设置分页信息
PageHelper.startPage(biVo.getPage(), biVo.getLimit());
// 查询
List<BuildRoomInfo> list = dormService.findFreeRoomListByPage(biVo);
// 创建分页对象
PageInfo<BuildRoomInfo> pageInfo = new PageInfo<BuildRoomInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 查找未分配寝室的学生
*
* @param siVo
* @return
*/
@ResponseBody
@RequestMapping(value = "/student/list")
public DataGridViewResult getNotAllocateStudentList(StudentInfoVo siVo) {
System.out.println(siVo);
// 设置分页信息
PageHelper.startPage(siVo.getPage(), siVo.getLimit());
// 查询
List<StudentInfo> list = dormService.findNotAllocateStudentListByPage(siVo);
// 创建分页对象
PageInfo<StudentInfo> pageInfo = new PageInfo<StudentInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
@ResponseBody
@RequestMapping(value = "/allocation/doAllocate")
public String doAllocate(HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String room = request.getParameter("room");
String student = request.getParameter("student");
System.out.println(room);
System.out.println(student);
map.put("msg", "接受到数据");
return JSON.toJSONString(map);
}
/**
* 判断床位数够不够
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/allocation/isEnough")
public String judgeIsEnough() {
HashMap<String, Object> map = new HashMap<>();
boolean enough = dormService.judgeIsEnough();
if (enough) {
map.put("success", true);
} else {
map.put("success", false);
map.put("msg", "床位数不够,请先添加空余宿舍信息!");
}
return JSON.toJSONString(map);
}
/**
* 全部分配
*
* @return
*/
@ResponseBody
@RequestMapping(value = "/allocation/assignAll")
public String assignAll() {
HashMap<String, Object> map = new HashMap<>();
boolean success = dormService.doAssignAll();
if (success) {
map.put("success", true);
map.put("msg", "分配完毕,分配结果显示在当前页面下方。");
} else {
map.put("success", false);
map.put("msg", "分配失败!");
}
return JSON.toJSONString(map);
}
/**
* 显示分配结果
*
* @param aiVo
* @return
*/
@ResponseBody
@RequestMapping(value = "/allocation/result")
public DataGridViewResult viewAllocateResult(AllocationInfoVo aiVo) {
// 设置分页信息
PageHelper.startPage(aiVo.getPage(), aiVo.getLimit());
// 查询
List<AllocationInfo> list = dormService.viewAllocateResult(aiVo);
// 创建分页对象
PageInfo<AllocationInfo> pageInfo = new PageInfo<AllocationInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 宿舍分配列表
*
* @return
*/
@RequestMapping(value = "/allocation/list")
public String allocationList() {
return "/dm/allocation-list";
}
/**
* 查询宿舍分配信息
* 查询条件:专业/年级
*
* @param aiVo
* @return
*/
@ResponseBody
@RequestMapping(value = "/allocation/info")
public DataGridViewResult findAllocationInfoList(AllocationInfoVo aiVo, HttpServletRequest request) {
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
if (StringUtils.isNotBlank(brarea)) {
aiVo.setBrarea(brarea);
}
if (StringUtils.isNotBlank(brbid)) {
aiVo.setBrbid(brbid);
}
System.out.println(aiVo);
// 设置分页信息
PageHelper.startPage(aiVo.getPage(), aiVo.getLimit());
// 查询
List<AllocationInfo> list = dormService.findAllocationInfoListByPage(aiVo);
// 创建分页对象
PageInfo<AllocationInfo> pageInfo = new PageInfo<AllocationInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 导出学生宿舍分配信息
*
* @param request
* @param response
*/
@ResponseBody
@RequestMapping(value = "/allocation/export.action")
public void exportAllocationInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
response.reset();// 清除缓存
String brarea = (String) request.getSession().getAttribute("brarea");
String brbid = (String) request.getSession().getAttribute("brbid");
// 查找宿舍分配信息
List<AllocationInfo> list = dormService.exportAllocationInfo(brarea, brbid);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(brarea)) {
filenamebuffer.append(brarea);
filenamebuffer.append("-");
}
if (StringUtils.isNotBlank(brbid)) {
filenamebuffer.append(brbid);
filenamebuffer.append("栋-");
}
filenamebuffer.append("学生宿舍分配名单");
String filename = filenamebuffer.toString();
try {
ExcelUtils.writeExcel(filename, response, list, AllocationInfo.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
package com.usc.ms.doms.controller;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.usc.ms.doms.entity.Users;
import com.usc.ms.doms.service.IndexService;
import com.usc.ms.doms.service.MenuService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;
@Controller
@RequestMapping("/")
public class IndexController {
@Resource
private IndexService indexService;
@Resource
private MenuService menuService;
public String index() {
return "index";
}
@RequestMapping(value = "/login.html")
public String toLogin() {
return "/login";
}
@RequestMapping(value = "/home.html")
public String home() {
return "/home";
}
/**
* 验证登录
*
* @param re 前端返回的参数
* @param session 将用户信息添加到session中
* @return
*/
@ResponseBody
@RequestMapping(value = "/login.action")
public String loginAction(@RequestBody Map<String, String> re, HttpSession session) {
String uid = re.get("username");
String upwd = re.get("password");
Integer utype = Integer.parseInt(re.get("type"));
System.out.println(utype);
Users user = indexService.findUserByuId(uid, upwd, utype);
Map<String, Object> map = new HashMap<>();
if (user != null) {
session.setAttribute("uid", uid);
session.setAttribute("uname", user.getUname());
session.setAttribute("utype", utype);
// 如果是教师或宿管员,还要把他们负责的部门(专业年级/宿舍楼)记下
if (utype == 1) {
session.setAttribute("dept", user.getDept());
session.setAttribute("grade", user.getGrade());
} else if (utype == 2) {
session.setAttribute("brarea", user.getBrarea());
session.setAttribute("brbid", user.getBrbid());
}
map.put("type", "success");
} else {
map.put("type", "error");
}
return JSON.toJSONString(map);
}
/**
* 退出登录
*
* @param session
* @return 返回到登录界面
*/
@RequestMapping(value = "/logout.action")
public String logout(HttpSession session) {
// 清空session中的属性
session.removeAttribute("uid");
session.removeAttribute("uname");
session.removeAttribute("utype");
//让session无效
session.invalidate();
return "redirect:/login";
}
@ResponseBody
@RequestMapping(value = "/api/loadMenuList")
public String loadMenuList(HttpSession session) {
Integer utype = (Integer) session.getAttribute("utype");
String initJson = menuService.loadMenuList(utype);
System.out.println(initJson);
return initJson;
}
/**
* 基本资料
*
* @param session
* @return
*/
@RequestMapping(value = "/basic-info.html")
public String setBasicInfo(HttpSession session) {
Integer utype = (Integer) session.getAttribute("utype");
// 是学生则返回学生的界面
if (utype == 0) {
return "/student/basic-info";
} else {
return "/basic-info";
}
}
/**
* 修改密码
*
* @return
*/
@RequestMapping(value = "/password-setting.html")
public String setPassword() {
return "/password-setting";
}
@ResponseBody
@RequestMapping(value = "/updatePassword.action")
public String updatePassword(HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String uid = (String) request.getSession().getAttribute("uid");
Integer utype = (Integer) request.getSession().getAttribute("utype");
String param = request.getParameter("param");
System.out.println(param);
try {
if (StringUtils.isNotBlank(param)) {
JSONObject obj = JSONObject.parseObject(param);
String old_password = (String) obj.get("old_password");
String new_password = (String) obj.get("new_password");
int result = indexService.updatePassword(uid, utype, old_password, new_password);
switch (result) {
case -1:
map.put("success", false);
map.put("msg", "系统出错,修改失败!");
break;
case 0:
map.put("success", false);
map.put("msg", "旧密码不正确!");
break;
case 1:
map.put("success", true);
map.put("msg", "修改成功!");
}
return JSON.toJSONString(map);
}
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("msg", "系统出错,修改失败!");
}
return JSON.toJSONString(map);
}
}
package com.usc.ms.doms.interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* 拦截器配置
* 配置拦截的路径
*/
@Configuration
public class LoginConfiguration implements WebMvcConfigurer {
@Autowired
private LoginInterceptor loginInterceptor;
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 拦截一切路径
// 除了index、login和静态资源文件
registry.addInterceptor(loginInterceptor).addPathPatterns("/**").excludePathPatterns("/login.*").excludePathPatterns("/", "/index").excludePathPatterns("/layui/**", "/css/**", "/images/**", "/lib/**");
}
}
package com.usc.ms.doms.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.usc.ms.doms.entity.*;
import com.usc.ms.doms.entity.BuildRoomInfo;
import com.usc.ms.doms.entity.RepairInfo;
import com.usc.ms.doms.entity.StayInfo;
import com.usc.ms.doms.mapper.DorMMapper;
import com.usc.ms.doms.service.DorMService;
import com.usc.ms.doms.utils.MyStringUtil;
import com.usc.ms.doms.vo.*;
import com.usc.ms.doms.entity.AllocationInfo;
import com.usc.ms.doms.entity.CleanInfo;
import com.usc.ms.doms.entity.MessageBoard;
import com.usc.ms.doms.entity.StudentInfo;
import com.usc.ms.doms.vo.AllocationInfoVo;
import com.usc.ms.doms.vo.BuildRoomInfoVo;
import com.usc.ms.doms.vo.CleanInfoVo;
import com.usc.ms.doms.vo.MessageBoardVo;
import com.usc.ms.doms.vo.RepairInfoVo;
import com.usc.ms.doms.vo.StayInfoVo;
import com.usc.ms.doms.vo.StudentInfoVo;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class DorMServiceImpl implements DorMService {
@Resource
private DorMMapper dormMapper;
@Autowired
private SqlSessionTemplate sqlSessionTemplate;
/**
* 查找报修信息
*
* @param riVo 分页查询的参数,负责的楼栋编号
* @return
*/
@Override
public List<RepairInfo> findRepairInfoListByPage(RepairInfoVo riVo) {
List<RepairInfo> list = dormMapper.findRepairInfoListByPage(riVo);
return dealString(list);
}
// 解析brcode填充brarea/brbid/brrid和格式化日期字符串
private List<RepairInfo> dealString(List<RepairInfo> list) {
for (int i = 0; i < list.size(); i++) {
String brcode = list.get(i).getBrcode().trim();
String subtime = list.get(i).getSubtime();
// 截取空格前的字符串,使日期格式为yy-MM-dd
String date = MyStringUtil.timeTodate(subtime);
list.get(i).setSubtime(date);
String[] brArr = brcode.split("#");
list.get(i).setBrarea(MyStringUtil.getBrarea(brArr[0]));
list.get(i).setBrbid(brArr[1]);
list.get(i).setBrrid(brArr[2]);
}
return list;
}
/**
* 导出报修信息
*
* @param brcode 宿舍楼编号
* @param statusCode 报修状态
* @return
*/
public List<RepairInfo> exportRepairInfo(String brcode, String statusCode) {
String status = transStatusCode(statusCode);
List<RepairInfo> list = dormMapper.exportRepairInfo(brcode, status);
return dealString(list);
}
// 转换statusCode为数据库中的status
private String transStatusCode(String status) {
if (status != null && !status.equals("")) {
Integer statusCode = Integer.parseInt(status.trim());
switch (statusCode) {
case 1:
status = "已处理";
break;
case 2:
status = "未处理";
break;
case 3:
status = "正在处理";
break;
}
} else {
status = "";
}
return status;
}
/**
* 批量更改报修状态
*
* @param params ids和status
*/
@Override
public boolean batchEditRepairStatus(String params) {
try {
// 将前端json数据解析出来
JSONArray jsonArray = JSONArray.parseArray(params);
JSONObject jsonObject = jsonArray.getJSONObject(0);
String statusCode = (String) jsonObject.get("status");
String status = transStatusCode(statusCode);
// ids为要更新状态的报修单编号
String ids = jsonObject.get("ids").toString();
// 去掉两边的[]
ids = ids.substring(1, ids.length() - 1);
// 转为String字符串
String[] idsArray = ids.split(",");
// 字符数组转为int数组
int[] array = Arrays.stream(idsArray).mapToInt(Integer::parseInt).toArray();
// int数组转为List,装箱
List<Integer> list = Arrays.stream(array).boxed().collect(Collectors.toList());
dormMapper.batchEditRepairStatus(list, status);
return true;
} catch (Exception e) {
return false;
}
}
/**
* 查询卫生检查信息
*
* @param ciVo
* @return
*/
@Override
public List<CleanInfo> findCleanInfoListByPage(CleanInfoVo ciVo) {
List<CleanInfo> list = dormMapper.findCleanInfoListByPage(ciVo);
for (int i = 0; i < list.size(); i++) {
String brcode = list.get(i).getBrcode().trim();
String time = list.get(i).getTime();
// 截取空格前的字符串,使日期格式为yy-MM-dd
String date = MyStringUtil.timeTodate(time);
list.get(i).setTime(date);
String[] brArr = brcode.split("#");
list.get(i).setBrarea(MyStringUtil.getBrarea(brArr[0]));
list.get(i).setBrbid(brArr[1]);
list.get(i).setBrrid(brArr[2]);
}
return list;
}
/**
* 更改卫生检查信息
*
* @param ci
* @return
*/
@Override
public int updateCleanInfo(CleanInfo ci) {
try {
// 如果宿舍号改了
// String brcode = ci.getBrcode();
// if (StringUtils.isNotBlank(brcode)){
// String brrid = brcode.split("#")[2];
// ci.setBrbid(brrid);
// }
int result = dormMapper.updateCleanInfo(ci);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 删除卫生检查记录
*
* @param id
* @return
*/
@Override
public int deleteCleanInfo(String id) {
try {
int actualId = Integer.parseInt(id);
int result = dormMapper.deleteCleanInfo(actualId);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 批量添加卫生检查记录
*
* @param params 卫生检查信息的json数据
* @param checker 检查人
* @return
*/
@Override
public boolean batchInsertCleanInfo(String params, String checker) {
String classPath = "mapper.com.usc.ms.doms.DorMMapper.batchInsertCleanInfo";
// 获取mysql的session并且关闭自动提交
SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
try {
List<CleanInfo> list = dealCleanInfoAddParams(params, checker);
// 插入
sqlSession.insert(classPath, list);
// 提交
sqlSession.commit();
// 防止内存崩溃
sqlSession.clearCache();
} catch (Exception e) {
e.printStackTrace();
// 回滚
sqlSession.rollback();
return false;
} finally {
// 关闭
sqlSession.close();
}
return true;
}
private List<CleanInfo> dealCleanInfoAddParams(String params, String checker) throws Exception {
List<CleanInfo> list = new ArrayList<>();
if (StringUtils.isNotBlank(params)) {
// json数据转为JSONArray对象
JSONArray jsonArray = JSONArray.parseArray(params);
// 遍历json数组,将json对象转为CleanInfo对象并且存到list中
for (int i = 0; i < jsonArray.size(); i++) {
CleanInfo ci = new CleanInfo();
JSONObject obj = jsonArray.getJSONObject(i);
String brarea = obj.get("brarea").toString().trim();
String brbid = obj.get("brbid").toString().trim();
String brrid = obj.get("brrid").toString().trim();
String brcode = MyStringUtil.getBrcode(brarea, brbid, brrid);
ci.setBrarea(brarea);
ci.setBrbid(brbid);
ci.setBrrid(brrid);
ci.setBrcode(brcode);
ci.setTime(obj.get("time").toString().trim());
String grade = obj.get("grade").toString().trim();
if (StringUtils.isNotBlank(grade)) {
ci.setGrade(Integer.parseInt(grade));
}
ci.setContent(obj.get("content").toString().trim());
ci.setChecker(checker);
list.add(ci);
}
}
return list;
}
/**
* 查找宿舍信息
*
* @param biVo
* @return
*/
@Override
public List<RepairInfo> findBuildRoomInfoListByPage(BuildRoomInfoVo biVo) {
List<RepairInfo> list = dormMapper.findBuildRoomInfoListByPage(biVo);
return list;
}
/**
* 修改宿舍信息
*
* @param bi
* @return
*/
@Override
public int updateBuildRoomInfo(BuildRoomInfo bi) {
try {
int result = dormMapper.updateBuildRoomInfo(bi);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 删除宿舍信息
*
* @param brcode 宿舍编号
* @return
*/
@Override
public int deleteBuildRoomInfo(String brcode) {
try {
int result = dormMapper.deleteBuildRoomInfo(brcode);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 添加宿舍信息
*
* @param list
* @return
*/
@Override
public boolean addBuildRoomInfo(List<BuildRoomInfo> list) {
String classPath = "mapper.com.usc.ms.doms.DorMMapper.addBuildRoomInfo";
// 获取mysql的session并且关闭自动提交
SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
try {
// 插入
sqlSession.insert(classPath, list);
// 提交
sqlSession.commit();
// 防止内存崩溃
sqlSession.clearCache();
} catch (Exception e) {
e.printStackTrace();
// 回滚
sqlSession.rollback();
return false;
} finally {
// 关闭
sqlSession.close();
}
return true;
}
/**
* 查看自己发布的公告/失物招领信息
*
* @param mbVo
* @return
*/
@Override
public List<MessageBoard> findMessageListByPage(MessageBoardVo mbVo) {
System.out.println(mbVo.getType());
List<MessageBoard> list = dormMapper.findMessageListByPage(mbVo);
for (int i = 0; i < list.size(); i++) {
// 截取日期
String time = list.get(i).getTime();
String date = MyStringUtil.timeTodate(time);
list.get(i).setTime(date);
// 解析type
Integer type = list.get(i).getType();
list.get(i).setTypeValue(MyStringUtil.mbTypeToValue(type));
// 解析brcode
String brcode = list.get(i).getBrcode();
System.out.println(brcode);
if (StringUtils.isNotBlank(brcode)) {
String[] split = brcode.split("#");
switch (split.length) {
case 1:
list.get(i).setBrarea(MyStringUtil.getBrarea(split[0]));
break;
case 2:
case 3:
list.get(i).setBrarea(MyStringUtil.getBrarea(split[0]));
list.get(i).setBrbid(split[1]);
break;
}
}
}
return list;
}
/**
* 添加公告信息
*
* @param mb
* @return
*/
@Override
public int addMessage(MessageBoard mb) {
try {
// time是当前时间
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
mb.setTime(sdf.format(date));
// 拼接brcode
String brcode = MyStringUtil.getBrcode(mb.getBrarea(), mb.getBrbid(), "");
mb.setBrcode(brcode);
System.out.println(mb);
int result = dormMapper.addMessage(mb);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 修改公告信息
*
* @param mb
* @return
*/
@Override
public int updateMessage(MessageBoard mb) {
try {
int result = dormMapper.updateMessage(mb);
return result;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
/**
* 批量删除公告/失物招领信息
*
* @param list id数组
* @return
*/
@Override
public boolean deleteMessage(List<Integer> list) {
try {
dormMapper.deleteMessage(list);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 查找留校信息列表
*
* @param stVo
* @return
*/
@Override
public List<StayInfo> findStayInfoListByPage(StayInfoVo stVo) {
stVo.setApprovetype(1);
List<StayInfo> list = dormMapper.findStayInfoListByPage(stVo);
return list;
}
/**
* 导出学生留校信息
*
* @param brarea
* @param brbid
* @return
*/
@Override
public List<StayInfo> exportStayInfo(String brarea, String brbid) {
StayInfoVo stVo = new StayInfoVo();
stVo.setBrbid(brbid);
stVo.setBrarea(brarea);
stVo.setApprovetype(1);
List<StayInfo> list = dormMapper.findStayInfoListByPage(stVo);
return list;
}
/**
* 获取留校学生的统计数据
*
* @param brarea
* @param brbid
* @return
*/
@Override
public JSONObject getStayInfoEchartsData(String brarea, String brbid) {
// 最后返回的数据
JSONObject data = new JSONObject();
// 宿舍区
JSONArray bsArray = new JSONArray();
// 宿舍区及人数
JSONArray countArray = new JSONArray();
List<String> brareas = new ArrayList<>();
if (StringUtils.isNotBlank(brarea)) {
brareas.add(brarea);
} else {
brareas = dormMapper.getStayInfoBrareas();
}
for (String item : brareas) {
bsArray.add(item);
Integer count = dormMapper.getStayInfoOnBrareaCount(item, brbid, 1);
JSONObject obj = new JSONObject();
obj.put("name", item);
obj.put("value", count);
countArray.add(obj);
}
data.put("data", bsArray);
data.put("series", countArray);
return data;
}
/**
* 查找宿舍分配信息
*
* @param aiVo 按专业、班级、宿舍区、楼栋进行查找
* @return
*/
@Override
public List<AllocationInfo> findAllocationInfoListByPage(AllocationInfoVo aiVo) {
List<AllocationInfo> list = dormMapper.findAllocationInfoListByPage(aiVo);
return list;
}
/**
* 导出宿舍分配信息
*
* @param brarea
* @param brbid
* @return
*/
public List<AllocationInfo> exportAllocationInfo(String brarea, String brbid) {
List<AllocationInfo> list = dormMapper.exportAllocationInfo(brarea, brbid);
return list;
}
/**
* 查找空余寝室
*
* @param biVo
* @return
*/
public List<BuildRoomInfo> findFreeRoomListByPage(BuildRoomInfoVo biVo) {
return dormMapper.findFreeRoomListByPage(biVo);
}
/**
* 查找未分配寝室的学生
*
* @param siVo
* @return
*/
public List<StudentInfo> findNotAllocateStudentListByPage(StudentInfoVo siVo) {
return dormMapper.findNotAllocateStudentListByPage(siVo);
}
private List<StudentInfo> MsiList = null;//男生
private List<StudentInfo> FsiList = null;//女生
private List<BuildRoomInfo> MbiList = null;//男生寝室
private List<BuildRoomInfo> FbiList = null;//女生寝室
private List<AllocationInfo> aiList = new ArrayList<>();
private List<BuildRoomInfo> updateList = new ArrayList<>();
/**
* 判断床位够不够
*
* @return
*/
public boolean judgeIsEnough() {
initList();//初始化列表
int mbed = 0;//男寝床位
int fbed = 0;//女寝床位
for (int i = 0; i < MbiList.size(); i++) {
mbed += MbiList.get(i).getFree();
}
for (int i = 0; i < FbiList.size(); i++) {
fbed += FbiList.get(i).getFree();
}
int mstucount = MsiList.size();//男生人数
int fstucount = FsiList.size();//女生人数
System.out.println(mbed + "--" + mstucount);
System.out.println(fbed + "--" + fstucount);
if (mbed >= mstucount && fbed >= fstucount) {
return true;
}
return false;
}
/**
* 初始化列表
*/
private void initList() {
StudentInfoVo msi = new StudentInfoVo();
msi.setStusex("男");
StudentInfoVo fsi = new StudentInfoVo();
fsi.setStusex("女");
MsiList = dormMapper.findNotAllocateStudentListByPage(msi);
FsiList = dormMapper.findNotAllocateStudentListByPage(fsi);
BuildRoomInfoVo mbi = new BuildRoomInfoVo();
mbi.setSex("男");
BuildRoomInfoVo fbi = new BuildRoomInfoVo();
fbi.setSex("女");
MbiList = dormMapper.findFreeRoomListByPage(mbi);
FbiList = dormMapper.findFreeRoomListByPage(fbi);
}
/**
* 分配宿舍(全部分配)
*
* @return
*/
@Override
public boolean doAssignAll() {
try {
clearList();
initList();
AllocateRoomToStudent(MbiList, MsiList);//分配女寝
AllocateRoomToStudent(FbiList, FsiList);//分配男寝
if (aiList.size() != 0) {
boolean result = batchInsertAllocationInfo(aiList);// 批量插入宿舍分配信息
// 插入失败,抛异常
if (!result) {
throw new Exception();
}
dormMapper.batchUpdateBuildRoomInfo(updateList);
updateList.clear();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
* 分配宿舍给学生
*
* @param biList 宿舍列表
* @param siList 学生列表
*/
public void AllocateRoomToStudent(List<BuildRoomInfo> biList, List<StudentInfo> siList) {
int index = 0;//第几个学生
int biLen = biList.size();
int siLen = siList.size();
//遍历宿舍,若宿舍或学生已分配完,退出循环
for (int i = 0; i < biLen && index < siLen; i++) {
BuildRoomInfo room = biList.get(i);//取一间宿舍
int free = room.getFree();//获取它的容量
String brcode = room.getBrcode();
int j = 1;
for (; j <= free && index < siLen; j++) {
StudentInfo si = siList.get(index);
index++;
String stuid = si.getStuid();
AllocationInfo ai = new AllocationInfo();
ai.setBrcode(brcode);
ai.setStuid(stuid);
aiList.add(ai);
System.out.println(ai);
}
//为更新空宿舍表做准备
updateList.add(new BuildRoomInfo(brcode, free - j + 1));
}
}
/**
* 显示分配结果
*
* @param aiVo
* @return
*/
@Override
public List<AllocationInfo> viewAllocateResult(AllocationInfoVo aiVo) {
// int page = aiVo.getPage();
// int row = aiVo.getLimit();
// int start = (page - 1) * row;
if (aiList == null || aiList.size() == 0) {
return null;
}
return dormMapper.viewAllocateResult(aiList);
// return dormMapper.viewAllocateResult(aiList, start, row);
}
/**
* 批量插入宿舍分配信息
*
* @param list
* @return
*/
public boolean batchInsertAllocationInfo(List<AllocationInfo> list) {
String classPath = "mapper.com.usc.ms.doms.DorMMapper.batchInsertAllocationInfo";
// 获取mysql的session并且关闭自动提交
SqlSession sqlSession = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH, false);
try {
// 插入
sqlSession.insert(classPath, list);
// 提交
sqlSession.commit();
// 防止内存崩溃
sqlSession.clearCache();
} catch (Exception e) {
e.printStackTrace();
// 回滚
sqlSession.rollback();
return false;
} finally {
// 关闭
sqlSession.close();
}
return true;
}
/**
* 清空列表
*/
private void clearList() {
if (updateList != null) {
updateList.clear();
}
if (MbiList != null) {
MbiList.clear();
}
if (FbiList != null) {
FbiList.clear();
}
if (MsiList != null) {
MsiList.clear();
}
if (FsiList != null) {
FsiList.clear();
}
if (aiList != null) {
aiList.clear();
}
}
}
package com.usc.ms.doms.service.impl;
import com.usc.ms.doms.entity.Users;
import com.usc.ms.doms.mapper.IndexMapper;
import com.usc.ms.doms.service.IndexService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@Service
public class IndexServiceImpl implements IndexService {
@Resource
private IndexMapper indexMapper;
/**
* 查询用户信息,判断是否存在该用户
*
* @param uid 用户id
* @param upwd 用户名
* @param utype 用户类型
* @return
*/
@Override
public Users findUserByuId(String uid, String upwd, Integer utype) {
// 根据用户类型去到对应的表里查找用户
Users user = null;
if (utype == 0) {
user = indexMapper.findStudentUserByUid(uid);
} else {
user = indexMapper.findOtherUserByUid(uid);
}
System.out.println(user);
// 如果存在该用户,判断密码对不对
if (user != null) {
String pwd = user.getUpwd();
Integer type = user.getUtype();
if (upwd.equals(pwd) && utype == type) {
return user;
}
}
return null;
}
/**
* 修改用户密码
*
* @param uid 用户的id
* @param utype 用户的类型
* @param oldPassword 旧密码
* @param newPassword 新密码
* @return 0表示不存在用户,无法更新;1表示更新完成;-1表示更新失败
*/
@Override
public int updatePassword(String uid, Integer utype, String oldPassword, String newPassword) {
/*
先找对应表里存不存在uid和uname的用户
如果存在,再更新密码
*/
try {
// 学生用户
if (utype == 0) {
int isExist = indexMapper.isExistSUserForUidAndPwd(uid, oldPassword);
if (isExist == 1) {
int result = indexMapper.updateSUserPassword(uid, newPassword);
return result;
} else {
return 0;
}
} else {
// 管理员(宿管/教师)用户
int isExist = indexMapper.isExistDUserForUidAndPwd(uid, oldPassword, utype);
if (isExist == 1) {
int result = indexMapper.updateDUserPassword(uid, newPassword);
return result;
} else {
return 0;
}
}
} catch (Exception e) {
e.printStackTrace();
return -1;
}
}
}
package com.usc.ms.doms.service;
import com.alibaba.fastjson.JSONObject;
import com.usc.ms.doms.entity.*;
import com.usc.ms.doms.vo.*;
import com.usc.ms.doms.entity.AllocationInfo;
import com.usc.ms.doms.entity.BuildRoomInfo;
import com.usc.ms.doms.entity.CleanInfo;
import com.usc.ms.doms.entity.MessageBoard;
import com.usc.ms.doms.entity.RepairInfo;
import com.usc.ms.doms.entity.StayInfo;
import com.usc.ms.doms.entity.StudentInfo;
import com.usc.ms.doms.vo.AllocationInfoVo;
import com.usc.ms.doms.vo.BuildRoomInfoVo;
import com.usc.ms.doms.vo.CleanInfoVo;
import com.usc.ms.doms.vo.MessageBoardVo;
import com.usc.ms.doms.vo.RepairInfoVo;
import com.usc.ms.doms.vo.StayInfoVo;
import com.usc.ms.doms.vo.StudentInfoVo;
import java.util.List;
public interface DorMService {
/**
* 查找报修信息
*
* @param riVo 分页查询的参数,负责的楼栋编号
* @return
*/
public List<RepairInfo> findRepairInfoListByPage(RepairInfoVo riVo);
/**
* 导出报修信息
*
* @param brcode 宿舍楼编号
* @param status 报修状态
* @return
*/
public List<RepairInfo> exportRepairInfo(String brcode, String status);
/**
* 批量更改报修状态
*
* @param params ids和status
*/
public boolean batchEditRepairStatus(String params);
/**
* 查询卫生检查信息
*
* @param ciVo
* @return
*/
public List<CleanInfo> findCleanInfoListByPage(CleanInfoVo ciVo);
/**
* 更改卫生检查信息
*
* @param ci
* @return
*/
public int updateCleanInfo(CleanInfo ci);
/**
* 删除卫生检查记录
*
* @param id
* @return
*/
public int deleteCleanInfo(String id);
/**
* 批量添加卫生检查记录
*
* @param params 卫生检查信息的json数据
* @param checker 检查人
* @return
*/
public boolean batchInsertCleanInfo(String params, String checker);
/**
* 查找宿舍信息
*
* @param biVo
* @return
*/
public List<RepairInfo> findBuildRoomInfoListByPage(BuildRoomInfoVo biVo);
/**
* 修改宿舍信息
*
* @param bi
* @return
*/
public int updateBuildRoomInfo(BuildRoomInfo bi);
/**
* 删除宿舍信息
*
* @param brcode 宿舍编号
* @return
*/
public int deleteBuildRoomInfo(String brcode);
/**
* 添加宿舍信息
*
* @param list
* @return
*/
public boolean addBuildRoomInfo(List<BuildRoomInfo> list);
/**
* 查看自己发布的公告信息
*
* @param mbVo
* @return
*/
public List<MessageBoard> findMessageListByPage(MessageBoardVo mbVo);
/**
* 添加公告信息
*
* @param mb
* @return
*/
public int addMessage(MessageBoard mb);
/**
* 修改公告信息
*
* @param mb
* @return
*/
public int updateMessage(MessageBoard mb);
/**
* 批量删除公告/失物招领信息
*
* @param list id数组
* @return
*/
public boolean deleteMessage(List<Integer> list);
/**
* 查找留校信息列表
*
* @param stVo
* @return
*/
public List<StayInfo> findStayInfoListByPage(StayInfoVo stVo);
/**
* 导出学生留校信息
*
* @param brarea
* @param brbid
* @return
*/
public List<StayInfo> exportStayInfo(String brarea, String brbid);
/**
* 获取留校学生的统计数据
*
* @param brarea
* @param brbid
* @return
*/
public JSONObject getStayInfoEchartsData(String brarea, String brbid);
/**
* 查找宿舍分配信息
*
* @param aiVo 按专业、班级、宿舍区、楼栋进行查找
* @return
*/
public List<AllocationInfo> findAllocationInfoListByPage(AllocationInfoVo aiVo);
/**
* 导出宿舍分配信息
*
* @param brarea
* @param brbid
* @return
*/
public List<AllocationInfo> exportAllocationInfo(String brarea, String brbid);
/**
* 查找空余寝室
*
* @param biVo
* @return
*/
public List<BuildRoomInfo> findFreeRoomListByPage(BuildRoomInfoVo biVo);
/**
* 查找未分配寝室的学生
*
* @param siVo
* @return
*/
public List<StudentInfo> findNotAllocateStudentListByPage(StudentInfoVo siVo);
/**
* 判断床位够不够
*
* @return
*/
public boolean judgeIsEnough();
/**
* 分配宿舍(全部分配)
*
* @return
*/
public boolean doAssignAll();
/**
* 显示分配结果
*
* @param aiVo
* @return
*/
public List<AllocationInfo> viewAllocateResult(AllocationInfoVo aiVo);
}
获取加我微信(远程帮装环境,协助运行项目)
点赞!!!!
收藏!!!!