feat : 部门重构完成
This commit is contained in:
@@ -66,6 +66,10 @@
|
||||
<version>${guava.version}</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,67 @@
|
||||
package cn.fateverse.common.core.bo;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Data
|
||||
public abstract class BaseQueryBO {
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private DateIntervalBO createTimeInterval;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private DateIntervalBO updateTimeInterval;
|
||||
|
||||
/**
|
||||
* 创建用户名称
|
||||
*/
|
||||
private String createUserName;
|
||||
|
||||
/**
|
||||
* 更新用户名称
|
||||
*/
|
||||
private String updateUserName;
|
||||
|
||||
/**
|
||||
* 获取创建时间间隔
|
||||
*
|
||||
* @return 基准日期间隔
|
||||
*/
|
||||
public DateIntervalBO getCreateTimeInterval() {
|
||||
return Optional.ofNullable(createTimeInterval).orElse(new DateIntervalBO());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取更新时间间隔
|
||||
*
|
||||
* @return 基准日期间隔
|
||||
*/
|
||||
public DateIntervalBO getUpdateTimeInterval() {
|
||||
return Optional.ofNullable(updateTimeInterval).orElse(new DateIntervalBO());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建时间 区间非空校验
|
||||
*
|
||||
* @return boolean true = 起止非空
|
||||
*/
|
||||
public boolean createTimeBetweenIsNotEmpty() {
|
||||
return Optional.ofNullable(createTimeInterval).map(item -> ObjectUtil.isAllNotEmpty(item.getStartTime(), item.getEndTime())).orElse(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新时间 区间非空校验
|
||||
*
|
||||
* @return boolean true = 起止非空
|
||||
*/
|
||||
public boolean updateTimeBetweenIsNotEmpty() {
|
||||
return Optional.ofNullable(updateTimeInterval).map(item -> ObjectUtil.isAllNotEmpty(item.getStartTime(), item.getEndTime())).orElse(false);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.fateverse.common.core.bo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 基准日期间隔
|
||||
*
|
||||
* @author ZhangQiang
|
||||
* @date 2024/09/26
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class DateIntervalBO {
|
||||
|
||||
/**
|
||||
* 开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 结束时间
|
||||
*/
|
||||
private LocalDateTime endTime;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package cn.fateverse.common.core.constant;
|
||||
|
||||
public interface BaseConstant {
|
||||
|
||||
Long ZERO = 0L;
|
||||
}
|
||||
@@ -5,24 +5,24 @@ package cn.fateverse.common.core.constant;
|
||||
* @author Clay
|
||||
* @date 2022/11/9
|
||||
*/
|
||||
public class CacheConstants {
|
||||
public interface CacheConstants {
|
||||
|
||||
/**
|
||||
* 验证码 redis key
|
||||
*/
|
||||
public static final String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
String CAPTCHA_CODE_KEY = "captcha_codes:";
|
||||
/**
|
||||
* 路由缓存地址
|
||||
*/
|
||||
public static final String ROUTE_CACHE_KEY = "router:key:";
|
||||
String ROUTE_CACHE_KEY = "router:key:";
|
||||
/**
|
||||
* 登录用户 redis key
|
||||
*/
|
||||
public static final String LOGIN_TOKEN_KEY = "login_info:";
|
||||
String LOGIN_TOKEN_KEY = "login_info:";
|
||||
/**
|
||||
* 字典类型 redis key
|
||||
*/
|
||||
public static final String DICT_KEY = "dict:";
|
||||
String DICT_KEY = "dict:";
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -5,34 +5,34 @@ package cn.fateverse.common.core.constant;
|
||||
*
|
||||
* @author Clay
|
||||
*/
|
||||
public class Constants {
|
||||
public interface Constants {
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String TOKEN_PREFIX = "Bearer ";
|
||||
String TOKEN_PREFIX = "Bearer ";
|
||||
/**
|
||||
* http请求
|
||||
*/
|
||||
public static final String HTTP = "http://";
|
||||
String HTTP = "http://";
|
||||
|
||||
/**
|
||||
* https请求
|
||||
*/
|
||||
public static final String HTTPS = "https://";
|
||||
String HTTPS = "https://";
|
||||
|
||||
|
||||
/**
|
||||
* 令牌前缀
|
||||
*/
|
||||
public static final String LOGIN_USER_KEY = "login_user_key";
|
||||
String LOGIN_USER_KEY = "login_user_key";
|
||||
|
||||
/**
|
||||
* 验证码有效期(分钟)
|
||||
*/
|
||||
public static final long CAPTCHA_EXPIRATION = 2;
|
||||
long CAPTCHA_EXPIRATION = 2;
|
||||
|
||||
|
||||
public static final String UTF8 = "UTF-8";
|
||||
String UTF8 = "UTF-8";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -4,17 +4,17 @@ package cn.fateverse.common.core.constant;
|
||||
* @author Clay
|
||||
* @date 2023-05-25
|
||||
*/
|
||||
public class DateConstants {
|
||||
public interface DateConstants {
|
||||
|
||||
public static String YYYY = "yyyy";
|
||||
String YYYY = "yyyy";
|
||||
|
||||
public static String YYYY_MM = "yyyy-MM";
|
||||
String YYYY_MM = "yyyy-MM";
|
||||
|
||||
public static String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
String YYYY_MM_DD = "yyyy-MM-dd";
|
||||
|
||||
public static String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
String YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
|
||||
|
||||
public static String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
String YYYY_MM_DD_HH_MM_SS = "yyyy-MM-dd HH:mm:ss";
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,44 +5,44 @@ package cn.fateverse.common.core.constant;
|
||||
*
|
||||
* @author Clay
|
||||
*/
|
||||
public class UserConstants {
|
||||
public interface UserConstants {
|
||||
|
||||
/**
|
||||
* 平台内系统用户的唯一标志
|
||||
*/
|
||||
public static final String SYS_USER = "SYS_USER";
|
||||
String SYS_USER = "SYS_USER";
|
||||
|
||||
/**
|
||||
* 匿名用户
|
||||
*/
|
||||
public static final String ANONYMOUS_USER = "anonymousUser";
|
||||
String ANONYMOUS_USER = "anonymousUser";
|
||||
|
||||
/**
|
||||
* 正常状态
|
||||
*/
|
||||
public static final String NORMAL = "0";
|
||||
String NORMAL = "0";
|
||||
|
||||
/**
|
||||
* 异常状态
|
||||
*/
|
||||
public static final String EXCEPTION = "1";
|
||||
String EXCEPTION = "1";
|
||||
|
||||
|
||||
/**
|
||||
* 部门停用状态
|
||||
*/
|
||||
public static final String DEPT_DISABLE = "1";
|
||||
String DEPT_DISABLE = "1";
|
||||
|
||||
|
||||
/**
|
||||
* Layout组件标识
|
||||
*/
|
||||
public final static String LAYOUT = "Layout";
|
||||
String LAYOUT = "Layout";
|
||||
|
||||
/**
|
||||
* 校验返回结果码
|
||||
*/
|
||||
public final static String UNIQUE = "0";
|
||||
String UNIQUE = "0";
|
||||
|
||||
public final static String NOT_UNIQUE = "1";
|
||||
String NOT_UNIQUE = "1";
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
package cn.fateverse.common.core.convert;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 基本转换定义
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2024/09/29
|
||||
*/
|
||||
public interface BaseConvertDefine<DTO, Entity, VO> {
|
||||
|
||||
/**
|
||||
* 实体到视图对象
|
||||
*
|
||||
* @param entity 实体
|
||||
* @return {@link VO}
|
||||
*/
|
||||
VO entityToVo(Entity entity);
|
||||
|
||||
/**
|
||||
* 业务对象到实体
|
||||
*
|
||||
* @param DTO 业务对象
|
||||
* @return {@link Entity}
|
||||
*/
|
||||
Entity dtoToEntity(DTO DTO);
|
||||
|
||||
/**
|
||||
* 从实体到视图对象
|
||||
*
|
||||
* @param list 列表
|
||||
* @return {@link List}<{@link VO}>
|
||||
*/
|
||||
default List<VO> entityToVOList(List<Entity> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return list.stream().map(this::entityToVo).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 业务对象到实体列表
|
||||
*
|
||||
* @param list 列表
|
||||
* @return {@link List}<{@link Entity}>
|
||||
*/
|
||||
default List<Entity> dtoToEntityList(List<DTO> list) {
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
return list.stream().map(this::dtoToEntity).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -4,15 +4,17 @@ import cn.fateverse.common.core.annotaion.AutoTime;
|
||||
import cn.fateverse.common.core.annotaion.AutoUser;
|
||||
import cn.fateverse.common.core.enums.MethodEnum;
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
public class BaseEntity implements Serializable {
|
||||
@Data
|
||||
public abstract class BaseEntity implements Serializable {
|
||||
|
||||
/**
|
||||
* 创建者
|
||||
@@ -25,7 +27,7 @@ public class BaseEntity implements Serializable {
|
||||
*/
|
||||
@AutoTime(method = MethodEnum.INSERT)
|
||||
@JsonFormat(locale = "zh",timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
private Date createTime;
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新者
|
||||
@@ -38,7 +40,7 @@ public class BaseEntity implements Serializable {
|
||||
*/
|
||||
@AutoTime(method = MethodEnum.UPDATE)
|
||||
@JsonFormat(locale = "zh",timezone = "GMT+8",pattern = "yyyy-MM-dd")
|
||||
private Date updateTime;
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
|
||||
/**
|
||||
@@ -46,44 +48,4 @@ public class BaseEntity implements Serializable {
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
|
||||
public Object getCreateBy() {
|
||||
return createBy;
|
||||
}
|
||||
|
||||
public void setCreateBy(Object createBy) {
|
||||
this.createBy = createBy;
|
||||
}
|
||||
|
||||
public Date getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(Date createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public Object getUpdateBy() {
|
||||
return updateBy;
|
||||
}
|
||||
|
||||
public void setUpdateBy(Object updateBy) {
|
||||
this.updateBy = updateBy;
|
||||
}
|
||||
|
||||
public Date getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(Date updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public String getRemark() {
|
||||
return remark;
|
||||
}
|
||||
|
||||
public void setRemark(String remark) {
|
||||
this.remark = remark;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
package cn.fateverse.common.core.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.validation.constraints.Email;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
/**
|
||||
* 部门表 sys_dept
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EnableAutoField
|
||||
public class Dept extends BaseEntity {
|
||||
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 父部门ID
|
||||
*/
|
||||
private Long parentId;
|
||||
|
||||
/**
|
||||
* 祖级列表
|
||||
*/
|
||||
private String ancestors;
|
||||
|
||||
/**
|
||||
* 部门名称
|
||||
*/
|
||||
@NotBlank(message = "部门名称不能为空!")
|
||||
private String deptName;
|
||||
|
||||
/**
|
||||
* 显示顺序
|
||||
*/
|
||||
@NotNull(message = "显示顺序不能为空!")
|
||||
private Integer orderNum;
|
||||
|
||||
/**
|
||||
* 负责人
|
||||
*/
|
||||
@NotBlank(message = "负责人不能为空!")
|
||||
private String leader;
|
||||
|
||||
/**
|
||||
* 负责人id
|
||||
*/
|
||||
@NotNull(message = "负责人id不能为空!")
|
||||
private Long leaderId;
|
||||
|
||||
/**
|
||||
* 联系电话
|
||||
*/
|
||||
@Pattern(message = "手机号格式错误!",regexp = "^1[0-9]{10}$")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Email(message = "邮箱格式错误!")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 部门状态:1正常,0停用
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
private String delFlag;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package cn.fateverse.common.security.entity;
|
||||
package cn.fateverse.common.core.entity;
|
||||
|
||||
import cn.fateverse.admin.entity.User;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
@@ -29,7 +29,6 @@ public class LoginUser implements UserDetails {
|
||||
*/
|
||||
private Long loginTime;
|
||||
|
||||
|
||||
/**
|
||||
* 过期时间
|
||||
*/
|
||||
@@ -119,6 +118,7 @@ public class LoginUser implements UserDetails {
|
||||
public boolean isCredentialsNonExpired() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可用 ,禁用的用户不能身份验证
|
||||
*
|
||||
@@ -0,0 +1,76 @@
|
||||
package cn.fateverse.common.core.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Clay
|
||||
* @date 2022/10/30
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EnableAutoField
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Role extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 角色ID
|
||||
*/
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 角色名称
|
||||
*/
|
||||
private String roleName;
|
||||
|
||||
/**
|
||||
* 角色关键词
|
||||
*/
|
||||
private String roleKey;
|
||||
|
||||
/**
|
||||
* 角色排序
|
||||
*/
|
||||
private Integer roleSort;
|
||||
|
||||
/**
|
||||
* 数据范围(1:所有数据权限;2:自定义数据权限;3:本部门数据权限;4:本部门及以下数据权限)
|
||||
*/
|
||||
private String dataScope;
|
||||
|
||||
/**
|
||||
* 角色状态(1正常 0停用)
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 1代表删除)
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String delFlag;
|
||||
|
||||
private Integer roleType = 0;
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isAdmin() {
|
||||
return isAdmin(this.roleId);
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public static boolean isAdmin(Long roleId) {
|
||||
return roleId != null && 1L == roleId;
|
||||
}
|
||||
|
||||
public Role(Long roleId) {
|
||||
this.roleId = roleId;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package cn.fateverse.common.core.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/10/27
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class User extends UserBase {
|
||||
|
||||
|
||||
/**
|
||||
* 部门对象
|
||||
*/
|
||||
private Dept dept;
|
||||
|
||||
/**
|
||||
* 角色对象
|
||||
*/
|
||||
private List<Role> roles;
|
||||
|
||||
|
||||
@JsonIgnore
|
||||
public boolean isAdmin() {
|
||||
return isAdmin(super.getUserId());
|
||||
}
|
||||
|
||||
@JsonIgnore
|
||||
public static boolean isAdmin(Long userId) {
|
||||
return userId != null && 1L == userId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
package cn.fateverse.common.core.entity;
|
||||
|
||||
import cn.fateverse.common.core.annotaion.EnableAutoField;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.*;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2022/11/7
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@EnableAutoField
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class UserBase extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 部门ID
|
||||
*/
|
||||
private Long deptId;
|
||||
|
||||
/**
|
||||
* 用户账号
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 用户昵称
|
||||
*/
|
||||
private String nickName;
|
||||
|
||||
/**
|
||||
* 用户邮箱
|
||||
*/
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 手机号码
|
||||
*/
|
||||
private String phoneNumber;
|
||||
|
||||
/**
|
||||
* 用户性别
|
||||
*/
|
||||
private String sex;
|
||||
|
||||
/**
|
||||
* 用户头像
|
||||
*/
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 盐加密
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 帐号状态(1正常 0停用)
|
||||
*/
|
||||
private String state;
|
||||
|
||||
/**
|
||||
* 删除标志(0代表存在 2代表删除)
|
||||
*/
|
||||
@JsonIgnore
|
||||
private String delFlag;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 一个微信开放平台帐号下的应用,同一用户的 union
|
||||
*/
|
||||
private String unionId;
|
||||
/**
|
||||
* 用户唯一标识
|
||||
*/
|
||||
private String openId;
|
||||
/**
|
||||
* 城市
|
||||
*/
|
||||
private String city;
|
||||
|
||||
/**
|
||||
* 最后登录IP
|
||||
*/
|
||||
private String loginIp;
|
||||
|
||||
/**
|
||||
* 最后登录时间
|
||||
*/
|
||||
private Date loginDate;
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.fateverse.common.core.utils;
|
||||
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
|
||||
public class AssertUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 断定为 true. 非 true 时抛出异常.
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param message 异常枚举
|
||||
* @param args 需要 format 的参数
|
||||
*/
|
||||
public static void isTrue(boolean condition, String message, Object... args) {
|
||||
if (!condition) {
|
||||
throw new CustomException(StrUtil.format(message, args));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 断定为 false. 非 false 时抛出异常.
|
||||
*
|
||||
* @param condition 条件
|
||||
* @param message 异常枚举
|
||||
* @param args arg游戏
|
||||
*/
|
||||
public static void isFalse(boolean condition, String message, Object... args) {
|
||||
if (condition) {
|
||||
throw new CustomException(StrUtil.format(message, args));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,29 +6,36 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import com.baomidou.mybatisplus.core.incrementer.DefaultIdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-05-25
|
||||
*/
|
||||
@MapperScan("${mybatis.mapperPackage}")
|
||||
public class MybatisPlusAutoConfiguration {
|
||||
|
||||
@Bean
|
||||
@ConditionalOnMissingBean(MybatisPlusInterceptor.class)
|
||||
public MybatisPlusInterceptor mybatisPlusInterceptor() {
|
||||
MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
|
||||
// 分页插件
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor());
|
||||
// 配置分页拦截器
|
||||
PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor();
|
||||
paginationInnerInterceptor.setOptimizeJoin(false);
|
||||
paginationInnerInterceptor.setMaxLimit(500L);
|
||||
paginationInnerInterceptor.setOverflow(false);
|
||||
interceptor.addInnerInterceptor(paginationInnerInterceptor);
|
||||
// 乐观锁插件
|
||||
interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor());
|
||||
// 添加防止全表更新与删除插件
|
||||
interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 分页插件,自动识别数据库类型
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package cn.fateverse.common.mybatisplus.enums;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IEnum;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
public interface BaseEnum<T extends Enum<T>> extends IEnum<Integer> {
|
||||
|
||||
/**
|
||||
* 获取编码
|
||||
*
|
||||
* @return {@link Integer}
|
||||
*/
|
||||
Integer getCode();
|
||||
|
||||
/**
|
||||
* 获取名称
|
||||
*
|
||||
* @return {@link String}
|
||||
*/
|
||||
String getName();
|
||||
|
||||
/**
|
||||
* 获取value值
|
||||
*
|
||||
* @return {@link Integer}
|
||||
*/
|
||||
@Override
|
||||
default Integer getValue() {
|
||||
return getCode();
|
||||
}
|
||||
/**
|
||||
* 解析通过编码
|
||||
*
|
||||
* @param enumClass 枚举班
|
||||
* @param code 编码
|
||||
* @return {@link E}
|
||||
*/
|
||||
static <E extends Enum<E> & BaseEnum<E>> E parseByCode(Class<E> enumClass, Integer code) {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.filter(e -> e.getCode().equals(code))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 按名称解析
|
||||
*
|
||||
* @param enumClass 枚举班
|
||||
* @param name 名称
|
||||
* @return {@link E}
|
||||
*/
|
||||
static <E extends Enum<E> & BaseEnum<E>> E parseByName(Class<E> enumClass, String name) {
|
||||
return Arrays.stream(enumClass.getEnumConstants())
|
||||
.filter(e -> e.getName().equals(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
|
||||
import org.apache.ibatis.reflection.MetaObject;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -27,6 +28,9 @@ public class AutoSetMetaObjectHandler implements MetaObjectHandler {
|
||||
@Override
|
||||
public void updateFill(MetaObject metaObject) {
|
||||
autoSetValue(metaObject, MethodEnum.UPDATE);
|
||||
this.strictUpdateFill(metaObject, "updateTime", LocalDateTime.class, LocalDateTime.now());
|
||||
this.strictUpdateFill(metaObject, "updateBy", Long.class, SecurityUtils.getUserId());
|
||||
this.strictUpdateFill(metaObject, "updateUserName", String.class, SecurityUtils.getUsername());
|
||||
}
|
||||
|
||||
private void autoSetValue(MetaObject metaObject, MethodEnum method) {
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
package cn.fateverse.common.mybatisplus.utils;
|
||||
|
||||
import cn.fateverse.common.core.entity.PageInfo;
|
||||
import cn.fateverse.common.core.result.page.TableDataInfo;
|
||||
import cn.fateverse.common.core.utils.TableSupport;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author Clay
|
||||
* @date 2023-05-25
|
||||
*/
|
||||
public class PageConditionUtil {
|
||||
|
||||
|
||||
/**
|
||||
* 转换为TableDataInfo对象
|
||||
*
|
||||
* @param page 源对象
|
||||
* @param map 转换方法
|
||||
* @param <T> 转换后的对象类型
|
||||
* @param <R> 需要转换的对象类型
|
||||
* @return 转换后的对象
|
||||
*/
|
||||
public static <T, R> TableDataInfo<T> convertDataTable(Page<R> page, Function<R, T> map) {
|
||||
List<T> convertList = page.getRecords().stream().map(map).collect(Collectors.toList());
|
||||
return convertDataTable(convertList, page.getTotal());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 转换为TableDataInfo对象
|
||||
*
|
||||
* @param list
|
||||
* @param count
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> TableDataInfo<T> convertDataTable(List<T> list, Long count) {
|
||||
if (null == list) {
|
||||
return new TableDataInfo<>(new ArrayList<>(), 0);
|
||||
}
|
||||
TableDataInfo<T> tableDataInfo = new TableDataInfo<>();
|
||||
tableDataInfo.setRows(list);
|
||||
tableDataInfo.setTotal(count);
|
||||
return tableDataInfo;
|
||||
}
|
||||
|
||||
public static <T> Page<T> getPage(){
|
||||
PageInfo pageInfo = TableSupport.getPageInfo();
|
||||
return new Page<>(pageInfo.getPageNum(), pageInfo.getPageSize());
|
||||
}
|
||||
}
|
||||
@@ -48,9 +48,5 @@
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>common-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.fateverse</groupId>
|
||||
<artifactId>admin-api</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -1,7 +1,7 @@
|
||||
package cn.fateverse.common.security.filter;
|
||||
|
||||
import cn.fateverse.common.security.service.TokenService;
|
||||
import cn.fateverse.common.security.entity.LoginUser;
|
||||
import cn.fateverse.common.core.entity.LoginUser;
|
||||
import cn.fateverse.common.security.utils.SecurityUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||
|
||||
@@ -6,12 +6,11 @@ import cn.fateverse.common.core.constant.Constants;
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.utils.HttpServletUtils;
|
||||
import cn.fateverse.common.core.utils.ObjectUtils;
|
||||
import cn.fateverse.common.security.entity.LoginUser;
|
||||
import cn.fateverse.common.core.entity.LoginUser;
|
||||
import io.jsonwebtoken.Claims;
|
||||
import io.jsonwebtoken.Jwts;
|
||||
import io.jsonwebtoken.SignatureAlgorithm;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.context.config.annotation.RefreshScope;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
|
||||
@@ -2,7 +2,7 @@ package cn.fateverse.common.security.utils;
|
||||
|
||||
import cn.fateverse.common.core.exception.CustomException;
|
||||
import cn.fateverse.common.core.utils.HttpServletUtils;
|
||||
import cn.fateverse.common.security.entity.LoginUser;
|
||||
import cn.fateverse.common.core.entity.LoginUser;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
<bitwalker.version>1.19</bitwalker.version>
|
||||
<spring-boot.mybatis>2.2.2</spring-boot.mybatis>
|
||||
<pagehelper.boot.version>1.4.5</pagehelper.boot.version>
|
||||
<mapstruct.version>1.6.2</mapstruct.version>
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
@@ -81,6 +82,11 @@
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mapstruct</groupId>
|
||||
<artifactId>mapstruct</artifactId>
|
||||
<version>${mapstruct.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user