基于javaweb+mysql的springboot宿舍寝室维修上报管理系统(java+springboot+freemarker+mysql+maven)
私信源码获取及调试交流
运行环境
Java≥8、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
基于javaweb的SpringBoot宿舍寝室维修上报管理系统(java+springboot+freemarker+mysql+maven)
管理员:校园管理(楼栋管理、宿舍管理)、师生管理(学生管理、辅导员管理)、维修管理(维修工管理、维修进度管理)、阅览室管理(座位生成等)、学生信用积分管理、座位预约统计管理等。
学生:登录、修改个人信息、上报宿舍维修信息、查看维修进度、完成维修进度等。
维修工:登录、查看分配给自己的维修任务、标记自己的维修进度等。
运行环境:windows/Linux均可、jdk1.8、mysql5.7、idea/eclipse均可。
Dormitory dormitory = dormitoryService.find(repairsDormitory.getId());
Long id = dormitory.getBuilding().getId();
int code = repairs.getEmpType().getCode();
List<Repairs> empType = repairsService.findByDormitoryIdAndEmpTypeAndStatus(dormitory.getId(), EmpType.getEmpByCode(code), 0);
if (!CollectionUtils.isEmpty(empType)) {
return Result.error(CodeMsg.ADMIN_REPAIRS_ERROR);
}
/**
* 有id是修改需要判断
* 无id是增加无需判断
*/
CodeMsg validate = ValidateEntityUtil.validate(repairs);
if (validate.getCode() != CodeMsg.SUCCESS.getCode()) {
return Result.error(validate);
}
if (repairs.getStudent().getStudentNo().equals("") || repairs.getStudent().getStudentNo() == null || repairs.getStudent().getStudentName().equals("") || repairs.getStudent().getStudentName() == null) {
return Result.error(CodeMsg.DATA_ERROR);
}
Student studentNo = studentService.findByStudentNo(repairs.getStudent().getStudentNo());
if (studentNo == null) {
return Result.error(CodeMsg.ADMIN_STUDENT_STUDENTNO);
}
if (repairs.getStudent().getStudentName() == null || !studentNo.getStudentName().equals(repairs.getStudent().getStudentName())) {
return Result.error(CodeMsg.ADMIN_STUDENT_EMPTY);
}
repairs.setStudent(studentNo);
Long freeEmp = repairsService.findFreeEmpByBuildingAndEmpType(id, code);//查出匹配的空闲的师傅
Long leastEmp = null;
if (Objects.isNull(freeEmp)) {//若没查出空闲的师傅,则查匹配的任务量少的师傅
leastEmp = repairsService.findEmpByBuildingAndEmpType(id, code);
}
if (repairs.getId() != null) {
//用统一验证实体方法验证是否合法
//到这说明一切符合条件,进行数据库保存
Repairs byID = repairsService.findByID(repairs.getId());
//讲提交的用户信息指定字段复制到已存在的user对象中,该方法会覆盖新字段内容
System.out.println(byID + "---------------" + byID.getCreateTime());
BeanUtils.copyProperties(repairs, byID, "id", "createTime", "updateTime");
Emp emp = new Emp();
if (Objects.nonNull(freeEmp)) { //如果查到有空闲的维修师傅
emp.setId(freeEmp);
@Service
public class StudentService {
@Autowired
private StudentDao studentDao ;
public Student findByID(Long id){
/**
* 使用jpa自带的方法
* studentDao.getOne();当我查询一个不存在的id数据时,直接抛出异常,因为它返回的是一个引用,简单点说就是一个代理对象
* studentDao.findOne() 当我查询一个不存在的id数据时,返回的值是null.
* studentDao.findById(id) ; .findById(id).get()使用时,如果数据库中查询无符合条件的记录便会抛出异常
*/
Optional<Student> byId = studentDao.findById(id);
return byId.isPresent()?byId.get():null;
}
public List<Student> findAll(){
return studentDao.findAll();
}
public void delete(long id ){
studentDao.deleteById(id);
}
public Student save(Student student){
return studentDao.save(student);
}
/**
* 分页按角色名称搜索角色列表
* @param student
* @param pageBean
* @return
*/
public PageBean<Student> findByName(Student student, PageBean<Student> pageBean){
ExampleMatcher withMatcher = ExampleMatcher.matching().withMatcher("studentName", ExampleMatcher.GenericPropertyMatchers.contains());
withMatcher = withMatcher.withIgnorePaths("studentSex","counsellorId","dormitoryId");
Example<Student> example = Example.of(student, withMatcher);
Pageable pageable = PageRequest.of(pageBean.getCurrentPage()-1, pageBean.getPageSize());
Page<Student> findAll = studentDao.findAll(example, pageable);
pageBean.setContent(findAll.getContent());
pageBean.setTotal(findAll.getTotalElements());
pageBean.setTotalPage(findAll.getTotalPages());
return pageBean;
}
for (int i = 0; i < 100; i++) {
System.err.println("发送完成邮件给学生!!!");
}
}
}
return Result.success(true);
}
}
@Service
public class StudentService {
@Autowired
private StudentDao studentDao ;
public Student findByID(Long id){
/**
* 使用jpa自带的方法
* studentDao.getOne();当我查询一个不存在的id数据时,直接抛出异常,因为它返回的是一个引用,简单点说就是一个代理对象
* studentDao.findOne() 当我查询一个不存在的id数据时,返回的值是null.
* studentDao.findById(id) ; .findById(id).get()使用时,如果数据库中查询无符合条件的记录便会抛出异常
*/
Optional<Student> byId = studentDao.findById(id);
if(!MenuUtil.isExistUrl(requestURI, authorities)){
//进入这里,表示权限不存在,首先判断是否是ajax请求
if(StringUtil.isAjax(request)){
//表示是ajax请求
try {
log.info("该请求无权限,已ajax方式返回提示,url=" + requestURI);
response.setCharacterEncoding("UTF-8");
response.getWriter().write(JSON.toJSONString(CodeMsg.ADMIN_NO_RIGHT));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
//说明是普通的请求,可直接重定向到无权限提示页面
try {
log.info("该请求无权限,重定向到无权限提示页面,url=" + requestURI);
response.sendRedirect("/system/no_right");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}
log.info("该请求符合权限要求,放行" + requestURI);
return true;
}
}
}
}
System.out.println(repairsSave.getId() + "打印Id");
}
return Result.success(true);
}
/**
* 订单修改
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(Model model, @RequestParam(name = "id") Long id) {
Repairs repairs = repairsService.findByID(id);
Dormitory repairsDormitory = repairs.getDormitory();
Dormitory dormitory = dormitoryService.find(repairsDormitory.getId());
List<Emp> emps = empService.findByBuilding(dormitory.getBuilding());
List<EmpType> empTypes = emps.stream().map(o -> o.getEmpType()).distinct().collect(Collectors.toList());
//查出所有的宿舍
List<Dormitory> all = dormitoryService.findAll();
//查出所有修理类型
model.addAttribute("empTypes", EmpType.values());
model.addAttribute("dormitorys", all);
model.addAttribute("repairs", repairsService.findByID(id));
return "admin/repairs/edit";
}
/**
* 编辑分配页面
*
* @param
* @return
*/
@RequestMapping(value = "/repairs", method = RequestMethod.GET)
public String editAllot(Model model, @RequestParam(name = "id") Long id) {
//查出所有的宿舍
List<Dormitory> all = dormitoryService.findAll();
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断辅导员名是否存在
if(coachService.isExistname(coach.getName(), 0l)){
return Result.error(CodeMsg.COACH_ADD_EXIST_ERROR);
}
//到这说明一切符合条件,进行数据库新增
if(coachService.save(coach) == null){
return Result.error(CodeMsg.COACH_ADD_ERROR);
}
operaterLogService.add("添加辅导员,辅导员名:" + coach.getName());
return Result.success(true);
}
/**
* 辅导员编辑页面
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
Coach coach = coachService.find(id);
model.addAttribute("coach", coachService.find(id));
return "admin/coach/edit";
}
/**
* 编辑辅导员信息表单提交处理
* @param coach
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Coach coach){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(coach);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(coach.getId() == null || coach.getId().longValue() <= 0){
@RequestMapping("/stu")
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@Autowired
private DormitoryService dormitoryService;
@Autowired
CoachDao coachDao;
@Autowired
private RoleService roleService;
@RequestMapping(value = "/list")
public String list(Model model, Student student, PageBean<Student> pageBean) {
model.addAttribute("title", "学生列表");
model.addAttribute("name", student.getStudentName());
model.addAttribute("pageBean", studentService.findByName(student, pageBean));
return "admin/student/list";
}
/**
* 学生修改
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(Model model, @RequestParam(name = "id") Long id) {
Student byID = studentService.findByID(id);
List<Building> all2 = buildingService.findAll();
List<Dormitory> byBuilding_id = dormitoryService.findByBuilding_Id(byID.getDormitory().getBuilding().getId());
List<Coach> all1 = coachDao.findAll();
model.addAttribute("coachs", all1);
model.addAttribute("dormitorys", byBuilding_id);
model.addAttribute("buildings", all2);
model.addAttribute("student", byID);
return "admin/student/edit";
}
@Autowired
private BuildingService buildingService;
/**
* 角色添加页面
*
* @param
* @return
*/
model.addAttribute("roles", roleService.findAll());
return "admin/user/add";
}
/**
* 用户添加表单提交处理
* @param user
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(User user){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(user);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(user.getRole() == null || user.getRole().getId() == null){
return Result.error(CodeMsg.ADMIN_USER_ROLE_EMPTY);
}
//判断用户名是否存在
if(userService.isExistUsername(user.getUsername(), 0l)){
return Result.error(CodeMsg.ADMIN_USERNAME_EXIST);
}
//到这说明一切符合条件,进行数据库新增
if(userService.save(user) == null){
return Result.error(CodeMsg.ADMIN_USE_ADD_ERROR);
}
operaterLogService.add("添加用户,用户名:" + user.getUsername());
return Result.success(true);
}
/**
* 用户编辑页面
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(Model model,@RequestParam(name="id",required=true)Long id){
model.addAttribute("roles", roleService.findAll());
model.addAttribute("user", userService.find(id));
return "admin/user/edit";
}
}
/**
* 根据学号查询
* @param no
* @return
*/
public Student findByStudentNo(String no){
return studentDao.findByStudentNo(no);
}
/**
* 根据名字查查询
* @param StuName
* @return
*/
public Student findByStudentName(String StuName){
return studentDao.findByStudentName(StuName);
}
/**
* 返回用户总数
* @return
*/
public long total(){
return studentDao.count();
}
}
@Autowired
private CoachDao coachDao;
@Autowired
private OperaterLogService operaterLogService;
/*
* 跳转查询页面
* */
@RequestMapping(value = "/list")
public String findlist(Model model , Coach coach, PageBean<Coach> pageBean){
model.addAttribute("title","辅导员列表");
model.addAttribute("pageBean",coachService.findlist(coach,pageBean));
return "admin/coach/list";
}
/**
* 新增辅导员跳转页面
* @param model
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.GET)
public String add(Model model){
return "admin/coach/add";
}
/**
* 辅导员添加表单提交处理
* @param coach
* @return
*/
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Coach coach){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(coach);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
//判断辅导员名是否存在
if(coachService.isExistname(coach.getName(), 0l)){
return Result.error(CodeMsg.COACH_ADD_EXIST_ERROR);
}
//到这说明一切符合条件,进行数据库新增
if(coachService.save(coach) == null){
return Result.error(CodeMsg.COACH_ADD_ERROR);
}
operaterLogService.add("添加辅导员,辅导员名:" + coach.getName());
return Result.success(true);
}
/**
* 辅导员编辑页面
}
//更新session里的值
SessionUtil.set(SessionConstant.SESSION_USER_LOGIN_KEY, loginedUser);
return "redirect:update_userinfo";
}
/**
* 修改密码页面
*
* @return
*/
@RequestMapping(value = "/update_pwd", method = RequestMethod.GET)
public String updatePwd() {
return "admin/system/update_pwd";
}
/**
* 修改密码表单提交
*
* @param oldPwd
* @param newPwd
* @return
*/
@RequestMapping(value = "/update_pwd", method = RequestMethod.POST)
@ResponseBody
public Result<Boolean> updatePwd(@RequestParam(name = "oldPwd", required = true) String oldPwd,
@RequestParam(name = "newPwd", required = true) String newPwd
) {
if (newPwd.length() < 4 || newPwd == null) {
return Result.error(CodeMsg.ADMIN_UPDATE_PWD_ERROR);
}
User loginedUser = SessionUtil.getLoginedUser();
Role role = loginedUser.getRole();
if (!loginedUser.getPassword().equals(oldPwd)) {
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_ERROR);
}
if (StringUtils.isEmpty(newPwd)) {
return Result.error(CodeMsg.ADMIN_USER_UPDATE_PWD_EMPTY);
}
loginedUser.setPassword(newPwd);
if (role.getRoleType() == RoleType.ELECTRICIAN) {
Emp emp = empService.find(loginedUser.getId());
emp.setPassword(newPwd);
return sdf.format(date);
}
/**
* 判断请求是否是ajax
*
* @param request
* @return
*/
public static boolean isAjax(HttpServletRequest request) {
String header = request.getHeader("X-Requested-With");
if ("XMLHttpRequest".equals(header)) return true;
return false;
}
/**
* 从流读取字符串
*
* @param inputStream
* @return
*/
public static String getStringFromInputStream(InputStream inputStream) {
String string = "";
try {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, "GB2312"));
String buf = null;
try {
while ((buf = bufferedReader.readLine()) != null) {
string += buf;
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
bufferedReader.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
filePath = new File(uploadPhotoPath + "/" + StringUtil.getFormatterDate(new Date(), "yyyyMMdd"));
//判断当天日期的文件夹是否存在,若不存在,则创建
if(!filePath.exists()){
//若不存在文件夹,则创建一个文件夹
filePath.mkdir();
}
String filename = StringUtil.getFormatterDate(new Date(), "yyyyMMdd") + "/" + System.currentTimeMillis() + suffix;
try {
photo.transferTo(new File(uploadPhotoPath+"/"+filename));
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
log.info("图片上传成功,保存位置:" + uploadPhotoPath + filename);
return Result.success(filename);
}
}
@RequestMapping(value="/add",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> add(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
if(roleService.save(role) == null){
return Result.error(CodeMsg.ADMIN_ROLE_ADD_ERROR);
}
log.info("添加角色【"+role+"】");
operaterLogService.add("添加角色【"+role.getName()+"】");
return Result.success(true);
}
/**
* 角色编辑页面
* @param id
* @param model
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.GET)
public String edit(@RequestParam(name="id",required=true)Long id,Model model){
List<Menu> findAll = menuService.findAll();
model.addAttribute("topMenus",MenuUtil.getTopMenus(findAll));
model.addAttribute("secondMenus",MenuUtil.getSecondMenus(findAll));
model.addAttribute("thirdMenus",MenuUtil.getThirdMenus(findAll));
Role role = roleService.find(id);
model.addAttribute("role", role);
model.addAttribute("authorities",JSONArray.toJSON(role.getAuthorities()).toString());
return "admin/role/edit";
}
/**
* 角色修改表单提交处理
* @param request
* @param role
* @return
*/
@RequestMapping(value="/edit",method=RequestMethod.POST)
@ResponseBody
public Result<Boolean> edit(Role role){
//用统一验证实体方法验证是否合法
CodeMsg validate = ValidateEntityUtil.validate(role);
if(validate.getCode() != CodeMsg.SUCCESS.getCode()){
return Result.error(validate);
}
Role existRole = roleService.find(role.getId());
if(existRole == null){
return Result.error(CodeMsg.ADMIN_ROLE_NO_EXIST);
*/
@RequestMapping(value = "/maintenance",method = RequestMethod.POST)
@ResponseBody
public Result<Boolean> editMte(@RequestParam(name = "id")Long id){
System.out.println("-----------------"+id);
//根据ID查出Repairs对象
Repairs repairs = repairsService.findByID(id);
//判断是否已完成
if(repairs.getStatus()==1){
return Result.error(CodeMsg.ADMIN_MAINTENANCE_EXIST);
}
if(repairs.getStatus()==0){
//定义已完成
repairs.setStatus(1);
//收件人的邮箱 主题完成 内容完成任务
//获取收件人
Student byStudentNo = studentService.findByStudentNo(repairs.getStudent().getStudentNo());
String email = byStudentNo.getEmail();
//证明状态是对的,进行修改数据库
repairsService.save(repairs);
//定义主题内容
final String subject="任务完成!";
final String context="任务完成!请查收";
try {
mailService.send(email,subject,context);
} catch (Exception e) {
for (int i = 0; i < 100; i++) {
System.err.println("发送完成邮件给学生!!!");
}
}
}
return Result.success(true);
}
}
/**
* 权限统一管理拦截器
*
*/
@Component
public class AuthorityInterceptor implements HandlerInterceptor{
private Logger log = LoggerFactory.getLogger(AuthorityInterceptor.class);
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
String requestURI = request.getRequestURI();
User loginedUser = SessionUtil.getLoginedUser();
log.info("进入权限控制拦截器" + requestURI);
List<Menu> authorities = loginedUser.getRole().getAuthorities();
//authorities.stream().forEach(System.out::println);
if(!MenuUtil.isExistUrl(requestURI, authorities)){
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(Model model, @RequestParam(name = "id") Long id) {
Student byID = studentService.findByID(id);
List<Building> all2 = buildingService.findAll();
List<Dormitory> byBuilding_id = dormitoryService.findByBuilding_Id(byID.getDormitory().getBuilding().getId());
List<Coach> all1 = coachDao.findAll();
model.addAttribute("coachs", all1);
model.addAttribute("dormitorys", byBuilding_id);
model.addAttribute("buildings", all2);
model.addAttribute("student", byID);
return "admin/student/edit";
}
@Autowired
private BuildingService buildingService;
/**
* 角色添加页面
*
* @param
* @return
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Model model) {
//查出所有的宿舍
List<Dormitory> all = dormitoryService.findAll();
//查出所有辅导员
List<Building> all2 = buildingService.findAll();
List<Coach> all1 = coachDao.findAll();
//model.addAttribute("dormitorys",all);
model.addAttribute("coachs", all1);
model.addAttribute("buildings", all2);
return "admin/student/add";
}
@RequestMapping(value = "delete", method = RequestMethod.POST)
@ResponseBody
public Result delete(long id) {
try {
studentService.delete(id);
} catch (Exception e) {
return Result.error(CodeMsg.ADMIN_ROLE_DELETE_ERROR);
}
return Result.success(true);
@RequestMapping("/stu")
@Controller
public class StudentController {
@Autowired
private StudentService studentService;
@Autowired
private DormitoryService dormitoryService;
@Autowired
CoachDao coachDao;
@Autowired
private RoleService roleService;
@RequestMapping(value = "/list")
public String list(Model model, Student student, PageBean<Student> pageBean) {
model.addAttribute("title", "学生列表");
model.addAttribute("name", student.getStudentName());
model.addAttribute("pageBean", studentService.findByName(student, pageBean));
return "admin/student/list";
}
/**
* 学生修改
*
* @param model
* @param id
* @return
*/
@RequestMapping(value = "/edit", method = RequestMethod.GET)
public String edit(Model model, @RequestParam(name = "id") Long id) {
Student byID = studentService.findByID(id);
List<Building> all2 = buildingService.findAll();
List<Dormitory> byBuilding_id = dormitoryService.findByBuilding_Id(byID.getDormitory().getBuilding().getId());
List<Coach> all1 = coachDao.findAll();
model.addAttribute("coachs", all1);
model.addAttribute("dormitorys", byBuilding_id);
model.addAttribute("buildings", all2);
model.addAttribute("student", byID);
return "admin/student/edit";
}
@Autowired
private BuildingService buildingService;