RBAC数据库操作单元测试完成
This commit is contained in:
@@ -0,0 +1,8 @@
|
|||||||
|
package top.fjy8018.fileupload.constant;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 存储全局变量
|
||||||
|
*/
|
||||||
|
public class GlobalConstant {
|
||||||
|
public static final String USER_SESSION_KEY = "USER_SESSION";
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package top.fjy8018.fileupload.controller;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Controller;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
import org.springframework.web.multipart.MultipartHttpServletRequest;
|
||||||
|
import top.fjy8018.fileupload.config.ServerPropertiesConfig;
|
||||||
|
import top.fjy8018.fileupload.dataobject.es.EsFileInfo;
|
||||||
|
import top.fjy8018.fileupload.service.FileService;
|
||||||
|
import top.fjy8018.fileupload.util.TimeUtil;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 09:16
|
||||||
|
*/
|
||||||
|
@Controller
|
||||||
|
public class UploadController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private FileService fileService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ServerPropertiesConfig serverPropertiesConfig;
|
||||||
|
|
||||||
|
public String moreUpload(HttpServletRequest request,
|
||||||
|
@RequestParam(value = "fileName") String fileName) {
|
||||||
|
MultipartHttpServletRequest multipartHttpServletRequest = (MultipartHttpServletRequest) request;
|
||||||
|
Map<String, MultipartFile> files = multipartHttpServletRequest.getFileMap();
|
||||||
|
|
||||||
|
EsFileInfo fileInfo = new EsFileInfo();
|
||||||
|
fileInfo.setFileName(fileName);
|
||||||
|
fileInfo.setFilePath(serverPropertiesConfig.getFilePath());
|
||||||
|
/*fileInfo.setFileSize();
|
||||||
|
fileInfo.setUserId();*/
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
package top.fjy8018.fileupload.dataobject;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author F嘉阳
|
|
||||||
* @date 2018-06-22 10:49
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@DynamicUpdate
|
|
||||||
public class AdminInfo {
|
|
||||||
@Id
|
|
||||||
private String adminId;
|
|
||||||
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private String createTime;
|
|
||||||
|
|
||||||
private String updateTime;
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
package top.fjy8018.fileupload.dataobject;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
|
||||||
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 文件表
|
|
||||||
* @author F嘉阳
|
|
||||||
* @date 2018-06-22 10:43
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
/*@Entity*/
|
|
||||||
@DynamicUpdate
|
|
||||||
public class FileInfo {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private String fileId;
|
|
||||||
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
private String fileName;
|
|
||||||
|
|
||||||
private String fileSize;
|
|
||||||
|
|
||||||
private String filePath;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
package top.fjy8018.fileupload.dataobject;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import top.fjy8018.fileupload.enums.PermissionStatusEnum;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 10:20
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table(name = "sys_permission")
|
||||||
|
@Entity
|
||||||
|
public class Permission {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private String url;
|
||||||
|
|
||||||
|
private String percode;
|
||||||
|
|
||||||
|
private Integer parentid;
|
||||||
|
|
||||||
|
private String parentids;
|
||||||
|
|
||||||
|
private String sortstring;
|
||||||
|
|
||||||
|
private Integer available = PermissionStatusEnum.AVAILABLE.getCode();
|
||||||
|
|
||||||
|
}
|
||||||
27
src/main/java/top/fjy8018/fileupload/dataobject/Role.java
Normal file
27
src/main/java/top/fjy8018/fileupload/dataobject/Role.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
package top.fjy8018.fileupload.dataobject;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import top.fjy8018.fileupload.enums.RoleStatusEnum;
|
||||||
|
import top.fjy8018.fileupload.util.KeyUtil;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 10:17
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table(name = "sys_role")
|
||||||
|
@Entity
|
||||||
|
public class Role {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String id = KeyUtil.genUniqueKey();
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
private Integer available = RoleStatusEnum.AVAILABLE.getCode();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package top.fjy8018.fileupload.dataobject;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 10:22
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table(name = "sys_role_permission")
|
||||||
|
@Entity
|
||||||
|
public class RolePermission {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String sysRoleId;
|
||||||
|
|
||||||
|
private Integer sysPermissionId;
|
||||||
|
|
||||||
|
}
|
||||||
40
src/main/java/top/fjy8018/fileupload/dataobject/User.java
Normal file
40
src/main/java/top/fjy8018/fileupload/dataobject/User.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
package top.fjy8018.fileupload.dataobject;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.hibernate.annotations.DynamicInsert;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
import top.fjy8018.fileupload.enums.UserStatusEnum;
|
||||||
|
import top.fjy8018.fileupload.util.KeyUtil;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 10:10
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Entity
|
||||||
|
@Table(name = "sys_user")
|
||||||
|
@DynamicInsert
|
||||||
|
@DynamicUpdate
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
private String id = KeyUtil.genUniqueKey();
|
||||||
|
|
||||||
|
private String usercode;
|
||||||
|
|
||||||
|
private String username;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
private Integer locked = UserStatusEnum.LOCKED.getCode();
|
||||||
|
|
||||||
|
private Date createTime;
|
||||||
|
|
||||||
|
private Date updateTime;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
package top.fjy8018.fileupload.dataobject;
|
|
||||||
|
|
||||||
import lombok.Data;
|
|
||||||
import org.hibernate.annotations.DynamicUpdate;
|
|
||||||
|
|
||||||
import javax.persistence.Entity;
|
|
||||||
import javax.persistence.Id;
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 系统A用户表
|
|
||||||
* @author F嘉阳
|
|
||||||
* @date 2018-06-22 10:46
|
|
||||||
*/
|
|
||||||
@Data
|
|
||||||
@Entity
|
|
||||||
@DynamicUpdate
|
|
||||||
public class UserInfo {
|
|
||||||
|
|
||||||
@Id
|
|
||||||
private String userId;
|
|
||||||
|
|
||||||
private String username;
|
|
||||||
|
|
||||||
private String password;
|
|
||||||
|
|
||||||
private Date createTime;
|
|
||||||
|
|
||||||
private Date updateTime;
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package top.fjy8018.fileupload.dataobject;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 10:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
@Table(name = "sys_user_role")
|
||||||
|
@Entity
|
||||||
|
public class UserRole {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
private String sysUserId;
|
||||||
|
|
||||||
|
private String sysRoleId;
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,6 +3,9 @@ package top.fjy8018.fileupload.dataobject.es;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.springframework.data.annotation.Id;
|
import org.springframework.data.annotation.Id;
|
||||||
import org.springframework.data.elasticsearch.annotations.Document;
|
import org.springframework.data.elasticsearch.annotations.Document;
|
||||||
|
import top.fjy8018.fileupload.enums.FileStatusEnum;
|
||||||
|
import top.fjy8018.fileupload.util.KeyUtil;
|
||||||
|
import top.fjy8018.fileupload.util.TimeUtil;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -14,17 +17,17 @@ import java.util.concurrent.TimeUnit;
|
|||||||
* @date 2018-06-22 11:34
|
* @date 2018-06-22 11:34
|
||||||
*/
|
*/
|
||||||
@Data
|
@Data
|
||||||
@Document(indexName = "file",type = "file")
|
@Document(indexName = "fileInfo",type = "file")
|
||||||
public class EsFileInfo implements Serializable {
|
public class EsFileInfo implements Serializable {
|
||||||
|
|
||||||
private static final long serialVersionUID = 3216398036847369019L;
|
private static final long serialVersionUID = 3216398036847369019L;
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
private String fileId;
|
private String fileId = KeyUtil.genUniqueKey();
|
||||||
|
|
||||||
private String userId;
|
private String userId;
|
||||||
|
|
||||||
private String createTime = currentTimeString();
|
private String createTime = TimeUtil.currentTimeString();
|
||||||
|
|
||||||
private String fileName;
|
private String fileName;
|
||||||
|
|
||||||
@@ -32,7 +35,12 @@ public class EsFileInfo implements Serializable {
|
|||||||
|
|
||||||
private String filePath;
|
private String filePath;
|
||||||
|
|
||||||
protected EsFileInfo() {
|
/**
|
||||||
|
* 当前文件状态,默认可用状态
|
||||||
|
*/
|
||||||
|
private Integer deleteFlag = FileStatusEnum.FILE_AVAILABLE.getCode();
|
||||||
|
|
||||||
|
public EsFileInfo() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EsFileInfo(String userId, String fileName, String fileSize, String filePath) {
|
public EsFileInfo(String userId, String fileName, String fileSize, String filePath) {
|
||||||
@@ -41,10 +49,4 @@ public class EsFileInfo implements Serializable {
|
|||||||
this.fileSize = fileSize;
|
this.fileSize = fileSize;
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String currentTimeString(){
|
|
||||||
Date date = new Date();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
return sdf.format(date);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package top.fjy8018.fileupload.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum FileStatusEnum implements CodeEnum{
|
||||||
|
FILE_DELETED(1,"文件已删除"),
|
||||||
|
FILE_AVAILABLE(0,"文件存在并可用"),
|
||||||
|
;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
FileStatusEnum(Integer code, String status) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = status;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package top.fjy8018.fileupload.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum PermissionStatusEnum implements CodeEnum {
|
||||||
|
LOCKED(0,"权限不可用"),
|
||||||
|
AVAILABLE(1,"权限可用")
|
||||||
|
;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
PermissionStatusEnum(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package top.fjy8018.fileupload.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum RoleStatusEnum implements CodeEnum {
|
||||||
|
LOCKED(1,"角色不可用"),
|
||||||
|
AVAILABLE(0,"角色可用")
|
||||||
|
;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
RoleStatusEnum(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package top.fjy8018.fileupload.enums;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public enum UserStatusEnum implements CodeEnum {
|
||||||
|
LOCKED(1,"用户已锁定"),
|
||||||
|
AVAILABLE(0,"用户可用")
|
||||||
|
;
|
||||||
|
|
||||||
|
private Integer code;
|
||||||
|
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
UserStatusEnum(Integer code, String msg) {
|
||||||
|
this.code = code;
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
||||||
16
src/main/java/top/fjy8018/fileupload/form/LoginForm.java
Normal file
16
src/main/java/top/fjy8018/fileupload/form/LoginForm.java
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package top.fjy8018.fileupload.form;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 用于前端上传参数传递和表单验证
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 09:18
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class LoginForm {
|
||||||
|
|
||||||
|
private String userName;
|
||||||
|
|
||||||
|
private String password;
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package top.fjy8018.fileupload.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import top.fjy8018.fileupload.dataobject.AdminInfo;
|
|
||||||
|
|
||||||
public interface AdminInfoRepository extends JpaRepository<AdminInfo,String> {
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
|
|
||||||
package top.fjy8018.fileupload.repository;
|
|
||||||
/*
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import top.fjy8018.fileupload.dataobject.FileInfo;
|
|
||||||
|
|
||||||
public interface FileInfoRepository extends JpaRepository<FileInfo,String> {
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
public interface FileInfoRepository {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import top.fjy8018.fileupload.dataobject.Permission;
|
||||||
|
|
||||||
|
public interface PermissionRepository extends JpaRepository<Permission,Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import top.fjy8018.fileupload.dataobject.RolePermission;
|
||||||
|
|
||||||
|
public interface RolePermissionRepository extends JpaRepository<RolePermission,Integer> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import top.fjy8018.fileupload.dataobject.Role;
|
||||||
|
|
||||||
|
public interface RoleRepository extends JpaRepository <Role,String> {
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package top.fjy8018.fileupload.repository;
|
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
|
||||||
import top.fjy8018.fileupload.dataobject.UserInfo;
|
|
||||||
|
|
||||||
public interface UserInfoRepository extends JpaRepository<UserInfo,String> {
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import top.fjy8018.fileupload.dataobject.User;
|
||||||
|
|
||||||
|
public interface UserRepository extends JpaRepository<User,String> {
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import top.fjy8018.fileupload.dataobject.UserRole;
|
||||||
|
|
||||||
|
public interface UserRoleRepository extends JpaRepository<UserRole,Integer> {
|
||||||
|
}
|
||||||
@@ -13,7 +13,7 @@ public interface EsFileInfoRepository extends ElasticsearchRepository<EsFileInfo
|
|||||||
* @param fileName
|
* @param fileName
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
Page<EsFileInfo> findDistinctByFileNameContains(Pageable pageable, String fileName);
|
Page<EsFileInfo> findByFileName(Pageable pageable, String fileName);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 通过用户号查询,并去除重复
|
* 通过用户号查询,并去除重复
|
||||||
@@ -23,5 +23,5 @@ public interface EsFileInfoRepository extends ElasticsearchRepository<EsFileInfo
|
|||||||
*/
|
*/
|
||||||
Page<EsFileInfo> findDistinctByUserId(Pageable pageable, String userId);
|
Page<EsFileInfo> findDistinctByUserId(Pageable pageable, String userId);
|
||||||
|
|
||||||
Page<EsFileInfo> findByFileName(Pageable pageable, String fileName);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
package top.fjy8018.fileupload.service;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import top.fjy8018.fileupload.dataobject.es.EsFileInfo;
|
||||||
|
|
||||||
|
public interface FileService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过文件名查找,并去除重复
|
||||||
|
* @param pageable
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<EsFileInfo> findByFileName(Pageable pageable, String fileName);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户号查询,并去除重复
|
||||||
|
* @param pageable
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
Page<EsFileInfo> findDistinctByUserId(Pageable pageable, String userId);
|
||||||
|
|
||||||
|
EsFileInfo saveFile(EsFileInfo fileInfo);
|
||||||
|
|
||||||
|
void deleteFile(EsFileInfo fileInfo);
|
||||||
|
|
||||||
|
void deleteById(String fileId);
|
||||||
|
|
||||||
|
void deleteAll();
|
||||||
|
}
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
package top.fjy8018.fileupload.service.impl;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.data.domain.Page;
|
||||||
|
import org.springframework.data.domain.Pageable;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import top.fjy8018.fileupload.dataobject.es.EsFileInfo;
|
||||||
|
import top.fjy8018.fileupload.repository.es.EsFileInfoRepository;
|
||||||
|
import top.fjy8018.fileupload.service.FileService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author F嘉阳
|
||||||
|
* @date 2018-06-23 09:12
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class FileServiceImpl implements FileService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private EsFileInfoRepository fileInfoRepository;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过文件名查找,并去除重复
|
||||||
|
*
|
||||||
|
* @param pageable
|
||||||
|
* @param fileName
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<EsFileInfo> findByFileName(Pageable pageable, String fileName) {
|
||||||
|
return fileInfoRepository.findByFileName(pageable,fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 通过用户号查询,并去除重复
|
||||||
|
*
|
||||||
|
* @param pageable
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Page<EsFileInfo> findDistinctByUserId(Pageable pageable, String userId) {
|
||||||
|
return fileInfoRepository.findDistinctByUserId(pageable,userId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public EsFileInfo saveFile(EsFileInfo fileInfo) {
|
||||||
|
return fileInfoRepository.save(fileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteFile(EsFileInfo fileInfo) {
|
||||||
|
fileInfoRepository.delete(fileInfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteById(String fileId) {
|
||||||
|
fileInfoRepository.deleteById(fileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteAll() {
|
||||||
|
fileInfoRepository.deleteAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ spring:
|
|||||||
max-request-size: 100Mb
|
max-request-size: 100Mb
|
||||||
datasource:
|
datasource:
|
||||||
driver-class-name: com.mysql.jdbc.Driver
|
driver-class-name: com.mysql.jdbc.Driver
|
||||||
url: jdbc:mysql://localhost:3306/db_sysdemo1?useUnicode=true&characterEncoding=utf-8&useSSL=true
|
url: jdbc:mysql://localhost:3306/db_sysrbacdemo?useUnicode=true&characterEncoding=utf-8&useSSL=true
|
||||||
username: trs
|
username: trs
|
||||||
password: fileupload
|
password: fileupload
|
||||||
jpa:
|
jpa:
|
||||||
|
|||||||
@@ -0,0 +1,70 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.fjy8018.fileupload.EstestApplicationTests;
|
||||||
|
import top.fjy8018.fileupload.dataobject.Permission;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class PermissionRepositoryTest extends EstestApplicationTests{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PermissionRepository repository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init(){
|
||||||
|
Permission permission3 = new Permission();
|
||||||
|
permission3.setName("权限");
|
||||||
|
permission3.setParentid(0);
|
||||||
|
permission3.setParentids("0/");
|
||||||
|
permission3.setPercode(null);
|
||||||
|
permission3.setSortstring("0");
|
||||||
|
permission3.setType("");
|
||||||
|
permission3.setUrl("");
|
||||||
|
|
||||||
|
Permission permission = new Permission();
|
||||||
|
permission.setName("文件管理");
|
||||||
|
permission.setParentid(1);
|
||||||
|
permission.setParentids("0/1");
|
||||||
|
permission.setPercode(null);
|
||||||
|
permission.setSortstring("1.");
|
||||||
|
permission.setType("menu");
|
||||||
|
permission.setUrl("/fileupload/upload");
|
||||||
|
|
||||||
|
Permission permission2 = new Permission();
|
||||||
|
permission2.setName("文件上传");
|
||||||
|
permission2.setParentid(11);
|
||||||
|
permission2.setParentids("0/1/11");
|
||||||
|
permission2.setPercode("file:upload");
|
||||||
|
permission2.setSortstring("");
|
||||||
|
permission2.setType("permission");
|
||||||
|
permission2.setUrl("/fileupload/upload/addfile");
|
||||||
|
|
||||||
|
repository.save(permission);
|
||||||
|
repository.save(permission2);
|
||||||
|
|
||||||
|
repository.save(permission3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void addOne(){
|
||||||
|
Permission permission = new Permission();
|
||||||
|
permission.setName("用户管理");
|
||||||
|
permission.setParentid(1);
|
||||||
|
permission.setParentids("0/1");
|
||||||
|
permission.setPercode(null);
|
||||||
|
permission.setSortstring("1.");
|
||||||
|
permission.setType("menu");
|
||||||
|
permission.setUrl("/fileupload/upload");
|
||||||
|
|
||||||
|
Permission res = repository.save(permission);
|
||||||
|
Assert.assertNotNull(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.fjy8018.fileupload.EstestApplicationTests;
|
||||||
|
import top.fjy8018.fileupload.dataobject.RolePermission;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RolePermissionRepositoryTest extends EstestApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RolePermissionRepository repository;
|
||||||
|
|
||||||
|
private static final String ROLE_ID = "1529723184401294213";
|
||||||
|
|
||||||
|
private static final Integer PERMISSION_ID = 3;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addOne(){
|
||||||
|
RolePermission rolePermission = new RolePermission();
|
||||||
|
rolePermission.setSysPermissionId(PERMISSION_ID);
|
||||||
|
rolePermission.setSysRoleId(ROLE_ID);
|
||||||
|
|
||||||
|
Assert.assertNotNull(repository.save(rolePermission));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.fjy8018.fileupload.EstestApplicationTests;
|
||||||
|
import top.fjy8018.fileupload.dataobject.Role;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class RoleRepositoryTest extends EstestApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RoleRepository roleRepository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init(){
|
||||||
|
Role role1 = new Role();
|
||||||
|
role1.setName("文件管理员");
|
||||||
|
|
||||||
|
Role role2 = new Role();
|
||||||
|
role2.setName("普通用户");
|
||||||
|
|
||||||
|
roleRepository.save(role1);
|
||||||
|
roleRepository.save(role2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void addOne(){
|
||||||
|
Role role = new Role();
|
||||||
|
role.setName("用户管理员");
|
||||||
|
|
||||||
|
Role res = roleRepository.save(role);
|
||||||
|
Assert.assertNotNull(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.fjy8018.fileupload.EstestApplicationTests;
|
||||||
|
import top.fjy8018.fileupload.dataobject.User;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class UserRepositoryTest extends EstestApplicationTests{
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository repository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void init(){
|
||||||
|
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername("admin");
|
||||||
|
user.setPassword("trs");
|
||||||
|
user.setUsercode("admin");
|
||||||
|
|
||||||
|
repository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Transactional
|
||||||
|
public void addOne(){
|
||||||
|
User user = new User();
|
||||||
|
user.setUsername("fjy");
|
||||||
|
user.setPassword("trs");
|
||||||
|
user.setUsercode("admin");
|
||||||
|
|
||||||
|
User res = repository.save(user);
|
||||||
|
|
||||||
|
Assert.assertNotNull(res);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package top.fjy8018.fileupload.repository;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import top.fjy8018.fileupload.EstestApplicationTests;
|
||||||
|
import top.fjy8018.fileupload.dataobject.UserRole;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@Component
|
||||||
|
public class UserRoleRepositoryTest extends EstestApplicationTests {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRoleRepository repository;
|
||||||
|
|
||||||
|
private static final String ROLE_ID = "1529723184401294213";
|
||||||
|
|
||||||
|
private static final String USER_ID = "1529723171835369380";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void addOne(){
|
||||||
|
UserRole userRole = new UserRole();
|
||||||
|
userRole.setSysRoleId(ROLE_ID);
|
||||||
|
userRole.setSysUserId(USER_ID);
|
||||||
|
|
||||||
|
Assert.assertNotNull(repository.save(userRole));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user