基于springboot,vue企业网盘系统

开发工具:IDEA

服务器:Tomcat9.0, jdk1.8

项目构建:maven

数据库:mysql5.7

系统分前后台,采用前后端分离

前端技术:vue+elementUI等框架实现

服务端技术:springboot+jpa

项目功能描述:

1.登录、注册、首页

2.用户管理:添加用户、修改用户、删除用户、查询用户、分配角色等功能

3.权限管理:

(1)角色列表:添加、修改、删除、分配权限

(2)权限列表

4.文件管理

(1)文件上传

(2)文件列表:分享文件、详情、下载文件、删除文件

5.个人中心:修改个人信息和修改密码

6.退出登录

 

基于springboot,vue企业网盘系统_第1张图片 

基于springboot,vue企业网盘系统_第2张图片 

基于springboot,vue企业网盘系统_第3张图片 

基于springboot,vue企业网盘系统_第4张图片 

基于springboot,vue企业网盘系统_第5张图片 

基于springboot,vue企业网盘系统_第6张图片 

基于springboot,vue企业网盘系统_第7张图片 

基于springboot,vue企业网盘系统_第8张图片 

 

package com.kcqnly.application.controller;

import cn.hutool.core.util.StrUtil;
import com.kcqnly.application.common.Result;
import com.kcqnly.application.entity.Role;
import com.kcqnly.application.entity.User;
import com.kcqnly.application.model.UserInfo;
import com.kcqnly.application.model.UserList;
import com.kcqnly.application.model.UserParam;
import com.kcqnly.application.service.RoleService;
import com.kcqnly.application.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;


@RestController
public class UserController {

    @Autowired
    private UserService userService;
    @Autowired
    private RoleService roleService;
    @Autowired
    private BCryptPasswordEncoder bCryptPasswordEncoder;

    @PreAuthorize("hasAuthority('用户列表')")
    @GetMapping("/users")
    public Result getUserList(String query, int pageNum, int pageSize) {

        if (StrUtil.isEmpty(query) || StrUtil.isBlank(query)) {
            List userParams = new ArrayList<>();
            List userList = userService.findAll(pageNum - 1, pageSize);
            for (User user : userList) {
                userParams.add(new UserParam(user));
            }
            UserList res = new UserList(userService.getTotal(), pageNum, userParams);
            return Result.ok("获取用户列表成功", res);
        } else {
            List userParams = new ArrayList<>();
            List userList = userService.findByUsernameLike(query);
            for (User user : userList) {
                userParams.add(new UserParam(user));
            }
            UserList res = new UserList(userParams.size(), pageNum, userParams);
            return Result.ok("查询成功", res);
        }


    }

//    @PreAuthorize("hasAuthority('添加用户')")
    @PostMapping("/users")
    public Result addUser(@RequestBody User user) {
        if (userService.findByUsername(user.getUsername()) != null) {
            return Result.error("用户名已存在");
        }
        String rawPassword = user.getPassword();
        user.setState(true);
        user.setRole(roleService.findById(1));
        user.setPassword(new BCryptPasswordEncoder().encode(rawPassword));
        user.setUseSize(0f);
        user.setSurplusSize(user.getMaxSize());
        user.setCreateTime(new Date());
        user.setUpdateTime(new Date());
        userService.save(user);
        return Result.ok("添加成功", new UserParam(user));
    }

    @PreAuthorize("hasAuthority('设置用户状态')")
    @PostMapping("/users/{id}/state/{state}")
    public Result changeState(@PathVariable("id") int id, @PathVariable("state") boolean state) {
        UserParam userParam = new UserParam(userService.updateState(id, state));
        return Result.ok("更新成功", userParam);
    }

    /**
     * 编辑用户信息时,弹框内的用户数据
     *
     */
    @PreAuthorize("hasAuthority('用户列表')")
    @GetMapping("/users/{id}")
    public Result search(@PathVariable("id") int id) {
        User user =userService.findById(id);
        if (user!=null) {
            UserParam userParam = new UserParam(user);
            return Result.ok("搜索成功", userParam);
        }
        return Result.error("用户id不存在");
    }

    @PreAuthorize("hasAuthority('删除用户')")
    @DeleteMapping("/users/{id}")
    public Result deleteUser(@PathVariable("id") int id) {
        userService.deleteById(id);
        return Result.ok("删除成功", null);
    }

    @PreAuthorize("hasAuthority('获取用户详情')")
    @PutMapping("/users/{id}")
    public Result changeInformation(@PathVariable("id") int id, @RequestBody UserParam req) {
        UserParam userParam = new UserParam(userService.updateInformation(id, req.getMobile(), req.getEmail(),req.getMaxSize()));
        return Result.ok("更新成功", userParam);
    }

    @PreAuthorize("hasAuthority('分配用户角色')")
    @PutMapping("/users/{id}/role")
    public Result changeRole(@PathVariable("id") int id, @RequestBody Role role) {
        UserParam userParam = new UserParam(userService.updateRole(id, role.getId()));
        return Result.ok("成功", userParam);
    }

    /**
     * 用户个人设置
     *
     */
    @GetMapping("/users/info")
    public Result getCurrentUser(Authentication authentication) {

        User user = (User) authentication.getPrincipal();
        UserInfo userInfo = new UserInfo(user);
        return Result.ok(userInfo);
    }

    @PostMapping("/users/checkPass")
    public Result checkPassword(Authentication authentication, String password) {
        User user = (User) authentication.getPrincipal();
        if (bCryptPasswordEncoder.matches(password, user.getPassword())) {
            return Result.ok(null);
        } else {
            return Result.error("原密码错误");
        }
    }

    @PostMapping("/users/updatePassword")
    public Result updatePassword(Authentication authentication,String password)
    {
        User user = (User) authentication.getPrincipal();
        user.setPassword(bCryptPasswordEncoder.encode(password));
        userService.save(user);
        return Result.ok("更新密码成功",null);
    }
}
package com.kcqnly.application.controller;

import cn.hutool.core.util.StrUtil;
import com.kcqnly.application.common.GoFastDfsApi;
import com.kcqnly.application.common.Result;
import com.kcqnly.application.utils.FileUtil;
import com.kcqnly.application.utils.SecurityUtil;
import com.kcqnly.application.utils.UploadUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


@RestController
public class UploadController {
    @Value("${upload.temp.path}")
    private String tempPath;

    @Value("${fileServer.url}")
    private String serverUrl;

    @Value("fileServer.showUrl")
    private String showUrl;

    @PostMapping("/file/upload/")
    @PreAuthorize("hasAuthority('文件列表')")
    public Result moreFileUpload(@RequestBody MultipartFile file,  String path) {
        String scene = path;
        if (file.isEmpty()) {
            return Result.error("请选择文件");
        }
        //判断是否超过剩余空间
        if (!FileUtil.isUpload(file.getSize())){
            return Result.error("文件超出剩余空间");
        }

        if (path.contains("/")) {
            scene = path.substring(0, path.lastIndexOf("/"));
        }
        //加上用户名前缀,区分是哪个用户的
        path= SecurityUtil.getLoginUsername()+"/"+path;
        //path="img/壁纸" scene="img"
        return UploadUtil.upload(tempPath, serverUrl + GoFastDfsApi.UPLOAD, path, scene, file, showUrl);
    }
}

你可能感兴趣的:(毕设源码,vue,IDEA,vue.js,spring,boot,springboot网盘系统)