基于javaweb+mysql的springboot校园宿舍管理系统(java+springboot+vue+maven+redis+mysql)

基于javaweb+mysql的springboot校园宿舍管理系统(java+springboot+vue+maven+redis+mysql)

运行环境

Java≥8、MySQL≥5.7、Node.js≥10

开发工具

后端:eclipse/idea/myeclipse/sts等均可配置运行

前端:WebStorm/VSCode/HBuilderX等均可

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb+mysql的SpringBoot校园宿舍管理系统(java+springboot+vue+maven+redis+mysql)

项目介绍

这个项目是一个基于SpringBoot+Vue的校园宿舍管理系统,前后端分离。 主要有超级管理员和宿舍管理员两种角色;

超级管理员权限包括: 首页; 学生宿舍管理:宿舍管理、学生管理、班级管理、宿舍楼管理; 记录:维修记录、晚归记录、请假记录; 系统管理:用户管理、角色管理、菜单管理、日志管理等。

宿舍管理员权限包括: 首页; 学生宿舍管理:宿舍管理、学生管理、班级管理; 记录:维修记录、晚归记录、请假记录;

环境需要

1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。 2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA; 3.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 4.数据库:MySql 5.7/8.0版本均可; 5.是否Maven项目:是;

技术栈

1.后端:SpringBoot+Mysql+redis 2.前端:Vue

使用说明

后端项目运行: 1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件; 2. 使用IDEA/Eclipse/MyEclipse导入项目,导入成功后请执行maven clean;maven install命令,然后运行; 3. 将项目中application-dev.yaml配置文件中的数据库配置改为自己的配置; 4. 运行项目,控制台提示运行成功后再去运行前端项目;

前端项目运行:

  1. 安装好node环境 2. 在dms目录下运行 npm install 安装所需要的包 3. 在dms目录下运行 npm run dev 4. 运行成功后,在浏览器中访问http://localhost:8087,登录账号即可

    @Autowired
    private SystemLogService systemLogService;

    @PostMapping("/list")
    @RequirePermission(permissions = {"system:log:list"})
    public Result<PageInfo<SystemLog>> list(@RequestBody ListQuery<SystemLog> listQuery) {
        PageHelper.startPage(listQuery.getPage(), listQuery.getRows());
        List<SystemLog> systemLogList = systemLogService.list(listQuery.getEntity());
        PageInfo<SystemLog> pageInfo = new PageInfo<>(systemLogList);
        return Result.<PageInfo<SystemLog>>ok().add(pageInfo);
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"system:log:query"})
    public Result<SystemLog> query(@RequestParam("id") Long id) {
        SystemLog systemLog = systemLogService.query(id);
        return Result.<SystemLog>ok().add(systemLog);
    }
}

/**
 * 登录拦截器
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {
    private final RedisUtil redisUtil;

    public LoginInterceptor(RedisUtil redisUtil) {
        this.redisUtil = redisUtil;

/**
 */
@RestController
@RequestMapping("/faculty")
public class FacultyController {
    @Autowired
    private FacultyService facultyService;

    @GetMapping("/list")
    @RequirePermission(permissions = {"faculty:list"})
    public Result<List<Faculty>> list() {
        List<Faculty> list = facultyService.list();
        return Result.<List<Faculty>>ok().add(list);
    }

    @GetMapping("/listAll")
    @RequirePermission(permissions = {"faculty:list"})
    public Result<List<Faculty>> listAll() {
        List<Faculty> list = facultyService.listAll();
        return Result.<List<Faculty>>ok().add(list);
    }

    @PostMapping("/saveOrUpdate")
    @RequirePermission(permissions = {"faculty:save", "faculty:update"})
    @Log("添加或更新学院")
    public Result<?> saveOrUpdate(@RequestBody @Validated Faculty faculty) {
        if (faculty.getId() == null) {
            facultyService.insert(faculty);
        } else {
            if (faculty.getId().equals(faculty.getParentId())) {
                throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
            }
            facultyService.update(faculty);
        }
        return Result.ok("操作成功");
    }
        this.systemRoleService = systemRoleService;
        this.noticeService = noticeService;
        this.departApplicationService = departApplicationService;
        this.imageService = imageService;
    }

    /**
     * 获取登录用户权限,头像,名称,菜单信息
     *
     * @param token token
     * @return
     */
    @GetMapping("/info")
    public Result<SystemUser> info(@RequestHeader(HEADER_TOKEN) String token) {
        SystemUser user = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "没有该用户"));
        List<SystemRole> systemRoles = systemRoleService.listByUserId(user.getId());
        Set<String> permissions;
        if (systemRoles.size() == 0) {
            permissions = new HashSet<>();
        } else {
            permissions = systemFunctionService.getPermission(systemRoles);
        }
        user.setPermissions(permissions);
        List<SystemFunction> functionList = systemFunctionService.listFunctionByParentIdAndIds(null, user.getUserRoleId());
        user.setFunctions(functionList);
        return Result.<SystemUser>ok().add(user);
    }

    /**
     * 获取登录用户基本信息
     *
     * @param token 用于获取请求头中的token
     * @return
     */
    @GetMapping("/userinfo")
    public Result<SystemUser> userInfo(@RequestHeader(HEADER_TOKEN) String token) {
        Long id = redisUtil.get(token);
        SystemUser user = systemUserService.info(id).get();
        return Result.<SystemUser>ok().add(user);
    }
    /**
     * 上传图片
     *
     * @param file  图片
     * @param token token
     * @return
    public Result<?> delete(@RequestParam("id") Long id) {
        facultyService.delete(id);
        return Result.ok("删除成功");
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"faculty:query"})
    public Result<Faculty> query(@RequestParam("id") Long id) {
        Faculty faculty = facultyService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "没有该数据"));
        return Result.<Faculty>ok().add(faculty);
    }

}

/**
 */
@RestController
@RequestMapping("/repair")
public class RepairController {
    @Autowired
    private RepairService repairService;
    @Autowired
    private RedisUtil redisUtil;

    @PostMapping("/saveOrUpdate")
    @RequirePermission(permissions = {"repair:update", "repair:save"})
    @Log
    public Result<?> save(@RequestBody @Validated Repair repair) {
        if (repair.getId() == null) {
            repairService.save(repair);
        } else {
            repairService.update(repair);
        }
        return Result.ok("添加成功");
    }


/**
 */
@Aspect
@Component
@Log4j
public class LogAop {

    private final RedisUtil redisUtil;
    private final SystemLogService systemLogService;

    public LogAop(RedisUtil redisUtil, SystemLogService systemLogService) {
        this.redisUtil = redisUtil;
        this.systemLogService = systemLogService;
    }

    @Pointcut("execution(* com.hzvtc.myproject.controller.*.*(..))")
    public void pointcut1() {
    }

    /**
     * 记录系统日志
     * @param jp 。
     */
    @Around(value = "pointcut1()")
    public Object after(ProceedingJoinPoint jp) throws Throwable {
        MethodSignature signature = (MethodSignature)jp.getSignature();
        Method targetMethod = signature.getMethod();
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody DepartApplicationUser departApplicationUser,
                         @RequestHeader(Constant.HEADER_TOKEN) String token) {
        String msg = "成功,";
        SystemUser user = redisUtil.exchange(token).get();
        DepartApplicationUser applicationUser =
                departApplicationService
                        .getApplicationUser(departApplicationUser.getId());
        if (!user.getId().equals(applicationUser.getOperateUserId())) {
            throw new HttpException(HttpCode.FAILED, "无法审核");
        }
        if (applicationUser.getIsAgree() != null) {
            throw new HttpException(HttpCode.FAILED, "已审核过,无法修改");
        }
        departApplicationService.update(departApplicationUser);
        DepartApplication application =
                departApplicationService
                        .getByDepartApplicationUserId(departApplicationUser.getId());

        if (departApplicationUser.getIsAgree()) {
            if (user.getLeaderId() == null) {
                studentService.delete(application.getStudentId());
                msg += "该学生已成功退宿";
            } else {
                departApplicationService.saveApplication(user.getLeaderId(), application.getId());
                WebSocket.sendMessage(user.getLeaderId(),
                        new Message().setTitle("新的退宿申请").setType(2).setMessageBody(application.getReason()),
                        systemUserService);
                msg += "等待上一级审核";
            }
        } else {
            msg += "审核未通过";
        }

        return Result.ok(msg);
    }

    @GetMapping("delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        departApplicationService.deleteApplication(id);
        return Result.ok("撤销成功");

/**
 */
@RestController
@RequestMapping("/login")
public class LoginController {
    private final RedisUtil redisUtil;
    private final SystemUserService systemUserService;

    public LoginController(RedisUtil redisUtil, SystemUserService systemUserService) {
        this.redisUtil = redisUtil;
        this.systemUserService = systemUserService;
    }

    @PostMapping("/login")
    public Result<String> login(SystemUser user, @RequestParam(value = "redirectUrl") String redirectUrl) {
        List<SystemUser> userList = systemUserService.listUserByLoginName(user.getLoginName());
        if (userList.size() == 0) {
            throw new HttpException(HttpCode.LOGIN_FAILED, "没有此用户");
        } else if (userList.size() > 1) {
            throw new HttpException(HttpCode.LOGIN_FAILED, "存在多个登录名,请联系管理员");
        } else {
            SystemUser systemUser = userList.get(0);
            if (systemUser.getPassword().equals(MD5Util.md5(user.getPassword()))) {
                String token = UUID.randomUUID().toString();
                redisUtil.put(token, systemUser.getId());
                return Result.<String>ok().add(redirectUrl + "#/token=" + token);
            } else {
                throw new HttpException(HttpCode.LOGIN_FAILED, "登陆失败,密码错误");
            }
        }
            return Result.ok("退宿申请已提交,等待上一级审核");
        }

    }
}

/**
 */
@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private RedisUtil redisUtil;

    @RequirePermission(permissions = {"room:list"})
    @PostMapping("/list")
    public Result<PageInfo<Room>> list(@RequestBody ListQuery<Room> listQuery, @RequestHeader(Constant.HEADER_TOKEN) String token) {
        SystemUser systemUser = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "登录用户不存在"));
        PageInfo<Room> pageInfo = roomService.list(listQuery, systemUser.getBuildingId());
        return Result.ok("删除成功");
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"manage:building:query"})
    public Result<Building> query(@RequestParam("id") Long id) {
        Building building = buildingService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "该数据不存在"));
        return Result.<Building>ok().add(building);
    }

    @PostMapping("/saveOrUpdate")
    @RequirePermission(permissions = {"manage:building:save","manage:building:update"})
    @Log
    public Result<?> saveOrUpdate(@RequestBody @Validated Building building) {
        if (building.getId() == null) {
            buildingService.save(building);
        } else {
            if (building.getId().equals(building.getParentId())) {
                throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
            }
            buildingService.update(building);
        }
        return Result.ok("操作成功");
    }
}

/**
 */
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {
    @Autowired
        }
        return Result.ok("添加成功");
    }

    @GetMapping("/updateStatus/{id}")
    @RequirePermission(permissions = {"repair:update"})
    @Log
    public Result<?> updateStatus(@PathVariable Long id) {
        repairService.updateStatus(id);
        return Result.ok("修改成功");
    }

    @PostMapping("/list")
    @RequirePermission(permissions = {"repair:list"})
    public Result<PageInfo<Repair>> list(@RequestBody ListQuery<Repair> listQuery, @RequestHeader(Constant.HEADER_TOKEN) String token) {
        SystemUser user = redisUtil.exchange(token).get();
        PageInfo<Repair> pageInfo = repairService.list(listQuery, user.getBuildingId());
        return Result.<PageInfo<Repair>>ok().add(pageInfo);
    }

    @GetMapping("/query/{id}")
    @RequirePermission(permissions = {"repair:query"})
    public Result<Repair> query(@PathVariable Long id) {
        Repair repair = repairService.query(id);
        return Result.<Repair>ok().add(repair);
    }

    @GetMapping("/delete/{id}")
    @RequirePermission(permissions = {"repair:delete"})
    @Log
    public Result<?> delete(@PathVariable Long id) {
        repairService.delete(id);
        return Result.ok("删除成功");
    }
}


/**
 */
@RestController
@RequestMapping("/room")
public class RoomController {
    @Autowired
    private RoomService roomService;

    @Autowired
    private StudentService studentService;

    @Autowired
    private RedisUtil redisUtil;

    @RequirePermission(permissions = {"room:list"})
    @PostMapping("/list")
    public Result<PageInfo<Room>> list(@RequestBody ListQuery<Room> listQuery, @RequestHeader(Constant.HEADER_TOKEN) String token) {
        SystemUser systemUser = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "登录用户不存在"));
        PageInfo<Room> pageInfo = roomService.list(listQuery, systemUser.getBuildingId());
        return Result.<PageInfo<Room>>ok().add(pageInfo);
    }

    @RequirePermission(permissions = {"room:list"})
    @GetMapping("/listAll")
    public Result<List<Room>> list(@RequestHeader(Constant.HEADER_TOKEN) String token) {
        SystemUser systemUser = redisUtil.exchange(token).orElseThrow(() -> new HttpException(HttpCode.FAILED, "登录用户不存在"));
        List<Room> list = roomService.list(systemUser.getBuildingId());
        return Result.<List<Room>>ok().add(list);
    }

    @GetMapping("/query/{id}")

/**
 */
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Autowired
    private BuildingService buildingService;
    @Autowired
    private RoomService roomService;

    @GetMapping("/listAll")
    @RequirePermission(permissions = {"manage:building:list"})
    public Result<List<Building>> listAll() {
        List<Building> list = buildingService.listAll();
        return Result.<List<Building>>ok().add(list);
    }

    @GetMapping("/list")
    @RequirePermission(permissions = {"manage:building:list"})
    public Result<List<Building>> list() {
        List<Building> list = buildingService.list();
        return Result.<List<Building>>ok().add(list);
    }

    @GetMapping("delete")
    @RequirePermission(permissions = {"manage:building:delete"})
    @Log("删除building")
    public Result<?> delete(@RequestParam("id") Long id) {
        List<Room> list = roomService.listByBuildingId(id);
        if (list.size() > 0) {
            throw new HttpException(HttpCode.FAILED, "该节点下或子节点还有寝室,无法删除");
        }
        buildingService.delete(id);
        return Result.ok("删除成功");
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"manage:building:query"})
    public Result<Building> query(@RequestParam("id") Long id) {
        Building building = buildingService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "该数据不存在"));
        return Result.<Building>ok().add(building);
    }

    @PostMapping("/saveOrUpdate")

/**
 */
@RestController
@RequestMapping("/system/role")
public class SystemRoleController {
    @Autowired
    private SystemRoleService systemRoleService;

    @Autowired
    private SystemFunctionService systemFunctionService;

    @GetMapping("/listInSelect")
    @RequirePermission(permissions = {"system:role:list"})
    public Result<List<SystemRole>> listInSelect() {
        return Result.<List<SystemRole>>ok().add(systemRoleService.listAll(new SystemRole()));
    }

    @PostMapping("/saveOrUpdate")
    @RequirePermission(permissions = {"system:role:save", "system:role:update"})
    @Log("添加修改角色")
    public Result<?> saveOrUpdate(@RequestBody @Validated SystemRole role) {
        systemRoleService.saveOrUpdate(role);
        return Result.ok("操作成功");
    }

    @PostMapping("/list")
    @RequirePermission(permissions = {"system:role:list"})
    public Result<PageInfo<SystemRole>> list(@RequestBody ListQuery<SystemRole> query) {
        PageHelper.startPage(query.getPage(), query.getRows());
        List<SystemRole> list = systemRoleService.listAll(query.getEntity());
        PageInfo<SystemRole> pageInfo = new PageInfo<>(list);
        return Result.<PageInfo<SystemRole>>ok().add(pageInfo);
    }

    @GetMapping("/delete")
    @RequirePermission(permissions = {"system:role:delete"})
    @Log("删除角色")
    public Result<?> delete(@RequestParam("id") Long id) {
        systemRoleService.delete(id);
        return Result.ok("操作成功");
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"system:role:query"})
    public Result<SystemRole> query(@RequestParam("id") Long id) {
        SystemRole role = systemRoleService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "角色不存在"));
    @Log("删除功能")
    public Result<?> delete(@RequestParam("id") Long id) {
        systemFunctionService.delete(id);
        return Result.ok("删除成功");
    }

    @PostMapping("/saveOrUpdate")
    @RequirePermission(permissions = {"system:function:save", "system:function:update"})
    @Log("添加修改功能")
    public Result<?> saveOrUpdate(@RequestBody @Validated SystemFunction function) {
        if (function.getId() == null) {
            systemFunctionService.save(function);
        } else {
            if (function.getId().equals(function.getParentId())) {
                throw new HttpException(HttpCode.FAILED, "父节点不能为自己");
            }
            systemFunctionService.update(function);
        }
        return Result.ok("操作成功");
    }

    @GetMapping("/query")
    @RequirePermission(permissions = {"system:function:query"})
    public Result<SystemFunction> query(@RequestParam("id") Long id) {
        SystemFunction function = systemFunctionService.query(id).orElseThrow(() -> new HttpException(HttpCode.FAILED, "菜单不存在"));
        return Result.<SystemFunction>ok().add(function);
    }
}

/**
 */
@RestController
@RequestMapping("/leave")
    }

    @GetMapping("delete/{id}")
    public Result<?> delete(@PathVariable Long id) {
        departApplicationService.deleteApplication(id);
        return Result.ok("撤销成功");
    }

    @GetMapping("/query/{id}")
    public Result<DepartApplication> query(@PathVariable Long id) {
        DepartApplication data = departApplicationService.getApplication(id);
        return Result.<DepartApplication>ok().add(data);
    }

}

        });
        VALIDATE_MAP.put(Match.HAS_ALL, (userPermission, methodPermission) -> {
            int vote = 0;
            for (String up : userPermission) {
                for (String mp : methodPermission) {
                    if (up.equalsIgnoreCase(mp)) {
                        vote++;
                    }
                }
            }
            return vote == methodPermission.length;
        });
    }

    public SecurityInterceptor(RedisUtil redisUtil, SystemFunctionService systemFunctionService, SystemRoleService systemRoleService) {
        this.redisUtil = redisUtil;
        this.systemFunctionService = systemFunctionService;
        this.systemRoleService = systemRoleService;
    }

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
        //获取请求的方法
        HandlerMethod handlerMethod;
        if (handler instanceof HandlerMethod) {
            handlerMethod = (HandlerMethod) handler;
        } else {
            //404
            return true;
        }
        Method method = handlerMethod.getMethod();
        //获取请求方法所需的权限
        String[] requiredPermissions;
        Match match;
        if (method.isAnnotationPresent(RequirePermission.class)) {
            RequirePermission hasPermission = method.getAnnotation(RequirePermission.class);
            requiredPermissions = hasPermission.permissions();
            match = hasPermission.matchType();
        } else {
            //方法不需要权限(无 RequirePermission 注解)
            return true;
        }

        String token = request.getHeader(Constant.HEADER_TOKEN);

        Long id = redisUtil.get(token);

        //获取该用户的权限
        List<SystemRole> roleList = systemRoleService.listByUserId(id);
        Set<String> permissions;
        if (roleList.size() == 0) {
        }
        Long id = redisUtil.get(token);
        Boolean bool = systemUserService.validatePassword(password.getOldPassword(), id);
        if (bool) {
            systemUserService.changePassword(password.getCurrent1(), id);

            //移除token
            redisUtil.deleteToken(token);
            return Result.ok("密码修改成功,请重新登录");
        } else {
            throw new HttpException(HttpCode.FAILED, "原密码不正确");
        }
    }

    /**
     * 修改登录用户信息
     *
     * @param systemUser 修改的用户
     * @return 修改成功后将修改后的用户返回
     */
    @PostMapping("/update")
    public Result<SystemUser> update(@RequestBody SystemUser systemUser, @RequestHeader(HEADER_TOKEN) String token) {
        systemUser.setId(redisUtil.get(token));
        systemUserService.saveOrUpdate(systemUser);
        return Result.<SystemUser>ok("修改成功").add(systemUser);
    }

    @GetMapping("/changeIcon/{icon}")
    public Result<?> changeIcon(@PathVariable String icon , @RequestHeader(HEADER_TOKEN) String token) {
        systemUserService.changeIcon(icon, redisUtil.get(token));
        return Result.ok("修改成功");
    }
}

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值