基于javaweb+mysql的springboot高校宿舍管理系统(java+springboot+layui+html+thymeleaf+mysql)
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb+mysql的SpringBoot高校宿舍管理系统(java+springboot+layui+html+thymeleaf+mysql)
项目介绍
本项目有学生、教师、宿管员三种角色;
系统的功能主要有: (1)基本信息管理 基本信息分为学生信息和宿舍信息两部分,其功能是负责维护这些信息,对它们进行增删查改等操作。 (2)宿舍分配管理 根据给定的宿舍信息与学生信息,按照一定的规则自动地给还未分配宿舍的学生分配宿舍,学生可在该宿舍内自选床位,最终的宿舍分配信息可以以文件形式(如 Excel 表格)导出。 (3)宿舍日常管理 主要包括卫生管理、报修管理、留言管理等。 卫生管理:记录并维护卫生检查信息。 报修管理:添加、查看、修改报修单信息。 留言管理:包括发布公告、失物招领、普通留言以及对这些信息的维护。 (4)离返校管理 对节假日学生的去向、寒暑假学生的留校以及返校登记信息进行统计及管理,并以图表形式呈现统计信息。 (5)综合查询管理 包括查找学生信息、各楼栋/专业的学生宿舍分配情况、卫生检查情况、学生离返校及留校信息、指定类型的留言、查看宿舍成员等。
环境需要
1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可 4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 5.数据库:MySql 8.0/5.7版本; 6.是否Maven项目:是;
技术栈
HTML+CSS+JavaScript+mysql+SpringBoot+LayUI
使用说明
- 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application.properties配置文件中的数据库配置改为自己的配置; 4. 运行项目,在浏览器中输入http://localhost:xxx 访问
}
}
}
} finally {
if (workbook != null) {
workbook.close();
}
}
return dataList;
}
private static <T> void handleField(T t, String value, Field field) throws Exception {
Class<?> type = field.getType();
if (type == null || type == void.class || StringUtils.isBlank(value)) {
return;
}
if (type == Object.class) {
field.set(t, value);
//数字类型
} else if (type.getSuperclass() == null || type.getSuperclass() == Number.class) {
if (type == int.class || type == Integer.class) {
field.set(t, NumberUtils.toInt(value));
} else if (type == long.class || type == Long.class) {
field.set(t, NumberUtils.toLong(value));
} else if (type == byte.class || type == Byte.class) {
field.set(t, NumberUtils.toByte(value));
} else if (type == short.class || type == Short.class) {
field.set(t, NumberUtils.toShort(value));
} else if (type == double.class || type == Double.class) {
field.set(t, NumberUtils.toDouble(value));
} else if (type == float.class || type == Float.class) {
field.set(t, NumberUtils.toFloat(value));
} else if (type == char.class || type == Character.class) {
field.set(t, CharUtils.toChar(value));
} else if (type == boolean.class) {
field.set(t, BooleanUtils.toBoolean(value));
} else if (type == BigDecimal.class) {
field.set(t, new BigDecimal(value));
}
} else if (type == Boolean.class) {
field.set(t, BooleanUtils.toBoolean(value));
} else if (type == Date.class) {
field.set(t, value);
} else if (type == String.class) {
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 审批学生留校申请
*
* @param si
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/approve")
public String approveStayInfo(StayInfo si) {
HashMap<String, Object> map = new HashMap<>();
System.out.println(si);
int result = teacherService.approveStayInfo(si);
if (result > 0) {
map.put("success", true);
map.put("msg", "审批成功");
} else {
map.put("success", false);
map.put("msg", "审批失败,请稍后再试!");
}
return JSON.toJSONString(map);
}
/**
* 导出学生留校申请信息
*
* @param request
* @param response
*/
@ResponseBody
@RequestMapping(value = "/stayin/export.action")
public void exportStayInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
response.reset();// 清除缓存
String studept = (String) request.getSession().getAttribute("dept");
String stugrade = (String) request.getSession().getAttribute("grade");
// 查找学生登记信息
List<StayInfo> list = teacherService.exportStayInfo(studept, stugrade);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(studept)) {
filenamebuffer.append(studept);
filenamebuffer.append("-");
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")
System.out.println(siVo);
// 设置分页信息
PageHelper.startPage(siVo.getPage(), siVo.getLimit());
// 查询
List<StayInfo> list = teacherService.findStayInfoListByPage(siVo);
// 创建分页对象
PageInfo<StayInfo> pageInfo = new PageInfo<StayInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 审批学生留校申请
*
* @param si
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/approve")
public String approveStayInfo(StayInfo si) {
HashMap<String, Object> map = new HashMap<>();
System.out.println(si);
int result = teacherService.approveStayInfo(si);
if (result > 0) {
map.put("success", true);
map.put("msg", "审批成功");
} else {
map.put("success", false);
map.put("msg", "审批失败,请稍后再试!");
}
return JSON.toJSONString(map);
}
/**
* 导出学生留校申请信息
*
* @param request
* @param response
*/
@ResponseBody
@RequestMapping(value = "/stayin/export.action")
public void exportStayInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
response.reset();// 清除缓存
String studept = (String) request.getSession().getAttribute("dept");
String stugrade = (String) request.getSession().getAttribute("grade");
// 查找学生登记信息
List<StayInfo> list = teacherService.exportStayInfo(studept, stugrade);
// 拼接excel表名
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) {
System.out.println(result);
return result;
}
/**
* 留校管理
*
* @return
*/
@RequestMapping(value = "/stayinManage")
public String stayinManege() {
return "/teacher/stayin-manage";
}
/**
* 留校申请列表
*
* @param siVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/list")
public DataGridViewResult findStayInfoListByPage(StayInfoVo siVo, HttpServletRequest request) {
String studept = (String) request.getSession().getAttribute("dept");
String stugrade = (String) request.getSession().getAttribute("grade");
if (StringUtils.isNotBlank(studept)) {
siVo.setStudept(studept);
}
if (StringUtils.isNotBlank(stugrade)) {
siVo.setStugrade(stugrade);
}
System.out.println(siVo);
// 设置分页信息
PageHelper.startPage(siVo.getPage(), siVo.getLimit());
// 查询
List<StayInfo> list = teacherService.findStayInfoListByPage(siVo);
// 创建分页对象
* 查看自己的留校申请
*
* @param siVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/list")
public DataGridViewResult findMyStayInfoListByPage(StayInfoVo siVo, HttpServletRequest request) {
String stuid = (String) request.getSession().getAttribute("uid");
siVo.setStuid(stuid);
System.out.println(siVo);
// 设置分页信息
PageHelper.startPage(siVo.getPage(), siVo.getLimit());
// 查询
List<StayInfo> list = studentService.findMyStayInfoListByPage(siVo);
// 创建分页对象
PageInfo<StayInfo> pageInfo = new PageInfo<StayInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 上传图片
*
* @param file
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/uploadImage")
public String uploadOpinionImage(MultipartFile file, HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
HashMap<String, Object> data = new HashMap<>();
try {
if (file != null) {
String stuid = (String) request.getSession().getAttribute("uid");
String originalFilename = file.getOriginalFilename();
Date date = new Date();
String fileName = date.getTime() + "-" + originalFilename;
// 类路径
field.set(t, NumberUtils.toShort(value));
} else if (type == double.class || type == Double.class) {
field.set(t, NumberUtils.toDouble(value));
} else if (type == float.class || type == Float.class) {
field.set(t, NumberUtils.toFloat(value));
} else if (type == char.class || type == Character.class) {
field.set(t, CharUtils.toChar(value));
} else if (type == boolean.class) {
field.set(t, BooleanUtils.toBoolean(value));
} else if (type == BigDecimal.class) {
field.set(t, new BigDecimal(value));
}
} else if (type == Boolean.class) {
field.set(t, BooleanUtils.toBoolean(value));
} else if (type == Date.class) {
field.set(t, value);
} else if (type == String.class) {
field.set(t, value);
} else {
Constructor<?> constructor = type.getConstructor(String.class);
field.set(t, constructor.newInstance(value));
}
}
private static String getCellValue(Cell cell) {
if (cell == null) {
return "";
}
if (cell.getCellType() == Cell.CELL_TYPE_NUMERIC) {
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return HSSFDateUtil.getJavaDate(cell.getNumericCellValue()).toString();
} else {
return new BigDecimal(cell.getNumericCellValue()).toString();
}
} else if (cell.getCellType() == Cell.CELL_TYPE_STRING) {
return StringUtils.trimToEmpty(cell.getStringCellValue());
} else if (cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
return StringUtils.trimToEmpty(cell.getCellFormula());
} else if (cell.getCellType() == Cell.CELL_TYPE_BLANK) {
return "";
} else if (cell.getCellType() == Cell.CELL_TYPE_BOOLEAN) {
return String.valueOf(cell.getBooleanCellValue());
} else if (cell.getCellType() == Cell.CELL_TYPE_ERROR) {
return "ERROR";
} else {
return cell.toString().trim();
}
}
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
@ResponseBody
@RequestMapping(value = "/student/update")
public String updateStudentInfo(StudentInfo si) {
HashMap<String, Object> map = new HashMap<>();
int result = teacherService.updateStudentInfo(si);
if (result > 0) {
map.put("success", true);
map.put("msg", "更改成功!");
} else {
map.put("success", false);
map.put("msg", "更改失败!");
}
return JSON.toJSONString(map);
}
/**
* 删除学生信息
*
* @param stuid
* @return
*/
@ResponseBody
@RequestMapping(value = "/student/delete")
public String deleteaddStudentInfo(String stuid) {
HashMap<String, Object> map = new HashMap<>();
int result = teacherService.deleteStudentInfo(stuid);
if (result > 0) {
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 = "/student/import.action")
public String importExcel(@RequestParam("file") MultipartFile file) {
HashMap<String, Object> map = new HashMap<>();
try {
List<StudentInfo> list = ExcelUtils.readExcel("", StudentInfo.class, file);
for (int i = 0; i < list.size(); i++) {
String grade = list.get(i).getStuid().substring(0, 4);
String fileName = date.getTime() + "-" + originalFilename;
// 类路径
// String classPath = ResourceUtils.getURL("classpath:").getPath();
// windows系统设置
String classPath = "D:/file";
// Mac系统设置
// String classPath = "/Users/hanmeng/Desktop/upload";
// 父路径
String src = "/upload/stayin/"; // + stuid + "/";
File directory = new File(classPath, src);
if (!directory.exists()) {
directory.mkdir();
}
// 文件名
String imagePath = directory.getPath() + "/" + fileName;
System.out.println(imagePath);
file.transferTo(new File(imagePath));
data.put("src", src + fileName);
map.put("code", 0);
map.put("msg", "上传成功!");
map.put("data", data);
return JSON.toJSONString(map);
} else {
map.put("code", -1);
map.put("msg", "请选择图片!");
return JSON.toJSONString(map);
}
} catch (Exception e) {
e.printStackTrace();
map.put("code", -1);
map.put("msg", "上传失败,请稍后重试!");
return JSON.toJSONString(map);
}
}
/**
* 提交留校申请
*
* @param si
* @param request
* @return
* 第一行标题
*/
{
// 产生表格标题行
Row row = sheet.createRow(ai.getAndIncrement());
AtomicInteger aj = new AtomicInteger();
//写入头部
fieldList.forEach(field -> {
ExcelColumn annotation = field.getAnnotation(ExcelColumn.class);
String columnName = "";
if (annotation != null) {
columnName = annotation.value();
}
Cell cell = row.createCell(aj.getAndIncrement());
// 单元格样式
CellStyle cellStyle = wb.createCellStyle();
cellStyle.setFillForegroundColor(IndexedColors.WHITE.getIndex());
cellStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
cellStyle.setAlignment(CellStyle.ALIGN_CENTER);
//设置列宽(列号数-1,宽)
int width = columnName.getBytes().length * 600 + 300;
sheet.setColumnWidth(aj.get() - 1, width);
//字体设置
Font font = wb.createFont();
font.setBoldweight(Font.BOLDWEIGHT_NORMAL);
font.setColor(Font.COLOR_NORMAL);
font.setFontName("Arail narrow");
// 把字体应用到当前的样式
cellStyle.setFont(font);
cell.setCellStyle(cellStyle);
cell.setCellValue(columnName);
});
}
/**
* 内容设置
*/
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
return JSON.toJSONString(map);
}
/**
* 导出宿舍分配信息列表(excel格式)
*
* @param request 用来获取缓存中的attribute
* @param response 输出文件流
*/
@ResponseBody
@RequestMapping(value = "/allocation/export.action")
public void exportAllocationInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
HashMap<String, Object> map = new HashMap<>();
response.reset();// 清除缓存
String studept = (String) request.getSession().getAttribute("dept");
String grade = (String) request.getSession().getAttribute("grade");
System.out.println("studept" + studept);
System.out.println("grade" + grade);
// 查找宿舍分配信息列表
List<AllocationInfo> list = teacherService.exportByDept(studept, grade);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(studept)) {
filenamebuffer.append(studept);
filenamebuffer.append("-");
}
if (StringUtils.isNotBlank(grade)) {
filenamebuffer.append(grade);
filenamebuffer.append("-");
}
filenamebuffer.append("宿舍分配表");
String filename = filenamebuffer.toString();
try {
ExcelUtils.writeExcel(filename, response, list, AllocationInfo.class);
map.put("success", true);
map.put("mag", "导出成功!");
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("mag", "导出失败!");
}
// return JSON.toJSONString(map);
}
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);
}
map.put("success", true);
map.put("msg", "登记成功!");
} else {
map.put("success", false);
map.put("msg", "登记失败,请稍后再试!");
}
return JSON.toJSONString(map);
}
/**
* 修改离校登记记录
*
* @param li
* @return
*/
@ResponseBody
@RequestMapping(value = "/leave/update")
public String updateMyLeaveInfo(LeaveInfo li) {
HashMap<String, Object> map = new HashMap<>();
System.out.println(li);
int result = studentService.updateMyLeaveInfo(li);
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 = "/stayin/apply")
public String myStayInfo() {
return "/student/stayin-apply";
}
/**
* 查看自己的留校申请
*
* @param siVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/list")
@Controller
@RequestMapping("/student")
public class StudentController {
@Resource
private StudentService studentService;
/**
* 我的卫生检查记录界面
*
* @return
*/
@RequestMapping(value = "/viewMyCleanInfo")
public String viewMyCleanInfo() {
return "/student/clean-list";
}
/**
* 查询我的宿舍卫生检查记录
*
* @param ciVo 分页信息
* @param request 用于获取session中的uid
* @return
*/
@ResponseBody
@RequestMapping(value = "/clean/list")
public DataGridViewResult findMyCleanInfoListByPage(CleanInfoVo ciVo, HttpServletRequest request) {
// 获取学号
String uid = (String) request.getSession().getAttribute("uid");
ciVo.setStuid(uid);
// 设置分页信息
PageHelper.startPage(ciVo.getPage(), ciVo.getLimit());
// 查询
List<CleanInfo> list = studentService.findMyCleanInfoListByPage(ciVo);
// 创建分页对象
PageInfo<CleanInfo> pageInfo = new PageInfo<CleanInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
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);
}
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");
list.add(id);
}
boolean result = studentService.deleteMessage(list);
if (result) {
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
}
} catch (Exception e) {
System.out.println(si);
int result = studentService.updateMyStayInfo(si);
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 = "/viewMyBackInfo")
public String viewMyBackToScInfo() {
return "/student/back-info";
}
/**
* 查找我的返校登记记录
*
* @param bsVo
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/back/list")
public DataGridViewResult findMyBackInfoByPage(BackToScInfoVo bsVo, HttpServletRequest request) {
String stuid = (String) request.getSession().getAttribute("uid");
bsVo.setStuid(stuid);
System.out.println(bsVo);
// 设置分页信息
PageHelper.startPage(bsVo.getPage(), bsVo.getLimit());
// 查询
List<BackToScInfo> list = studentService.findMyBackInfoByPage(bsVo);
// 创建分页对象
PageInfo<BackToScInfo> pageInfo = new PageInfo<BackToScInfo>(list);
// 按接口要求返回数据
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);
}
/**
* 导入宿舍信息
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(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("-");
int result = teacherService.deleteAllocationInfo(stuid);
if (result > 0) {
map.put("success", true);
map.put("msg", "删除成功!");
} else {
map.put("success", false);
map.put("msg", "删除失败!");
}
return JSON.toJSONString(map);
}
/**
* 导出宿舍分配信息列表(excel格式)
*
* @param request 用来获取缓存中的attribute
* @param response 输出文件流
*/
@ResponseBody
@RequestMapping(value = "/allocation/export.action")
public void exportAllocationInfoToExcel(HttpServletRequest request, HttpServletResponse response) {
HashMap<String, Object> map = new HashMap<>();
response.reset();// 清除缓存
String studept = (String) request.getSession().getAttribute("dept");
String grade = (String) request.getSession().getAttribute("grade");
System.out.println("studept" + studept);
System.out.println("grade" + grade);
// 查找宿舍分配信息列表
List<AllocationInfo> list = teacherService.exportByDept(studept, grade);
// 拼接excel表名
StringBuffer filenamebuffer = new StringBuffer();
if (StringUtils.isNotBlank(studept)) {
filenamebuffer.append(studept);
filenamebuffer.append("-");
}
if (StringUtils.isNotBlank(grade)) {
filenamebuffer.append(grade);
filenamebuffer.append("-");
}
filenamebuffer.append("宿舍分配表");
String filename = filenamebuffer.toString();
try {
ExcelUtils.writeExcel(filename, response, list, AllocationInfo.class);
map.put("success", true);
map.put("mag", "导出成功!");
} catch (Exception e) {
e.printStackTrace();
map.put("success", false);
map.put("mag", "导出失败!");
}
// return JSON.toJSONString(map);
}
PageInfo<BackToScInfo> pageInfo = new PageInfo<BackToScInfo>(list);
// 按接口要求返回数据
DataGridViewResult data = new DataGridViewResult(pageInfo.getTotal(), pageInfo.getList());
return data;
}
/**
* 添加返校登记记录
*
* @param bs
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/back/add")
public String addMyBackInfo(BackToScInfo bs, HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String stuid = (String) request.getSession().getAttribute("uid");
bs.setStuid(stuid);
System.out.println(bs);
int result = studentService.addMyBackInfo(bs);
if (result > 0) {
map.put("success", true);
map.put("msg", "提交成功!");
} else {
map.put("success", false);
map.put("msg", "提交失败,请稍后再试!");
}
return JSON.toJSONString(map);
}
/**
* 修改返校登记记录
*
* @param bs
* @return
*/
@ResponseBody
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)) {
file.transferTo(new File(imagePath));
data.put("src", src + fileName);
map.put("code", 0);
map.put("msg", "上传成功!");
map.put("data", data);
return JSON.toJSONString(map);
} else {
map.put("code", -1);
map.put("msg", "请选择图片!");
return JSON.toJSONString(map);
}
} catch (Exception e) {
e.printStackTrace();
map.put("code", -1);
map.put("msg", "上传失败,请稍后重试!");
return JSON.toJSONString(map);
}
}
/**
* 提交留校申请
*
* @param si
* @param request
* @return
*/
@ResponseBody
@RequestMapping(value = "/stayin/add")
public String addStayInfo(StayInfo si, HttpServletRequest request) {
HashMap<String, Object> map = new HashMap<>();
String stuid = (String) request.getSession().getAttribute("uid");
si.setStuid(stuid);
System.out.println(si);
int result = studentService.addMyStayInfo(si);
if (result > 0) {
map.put("success", true);
map.put("msg", "提交申请成功");
} else {
map.put("success", false);
map.put("msg", "提交申请失败,请稍后重试!");
}
return JSON.toJSONString(map);
}