Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
B
basic-api-boot
概览
概览
详情
活动
周期分析
版本库
存储库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
Basic
basic-api-boot
Commits
df5fab6e
提交
df5fab6e
authored
7月 15, 2022
作者:
方治民
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 针对 User/Role/Permission 添加 hibernate 逻辑删除的相关实现
上级
f393c586
显示空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
69 行增加
和
20 行删除
+69
-20
Permission.java
...in/java/com/yiring/auth/domain/permission/Permission.java
+23
-5
Role.java
...-auth/src/main/java/com/yiring/auth/domain/role/Role.java
+17
-1
User.java
...-auth/src/main/java/com/yiring/auth/domain/user/User.java
+18
-8
AuthController.java
...rc/main/java/com/yiring/auth/web/auth/AuthController.java
+1
-2
BasicEntity.java
...e/src/main/java/com/yiring/common/domain/BasicEntity.java
+10
-4
没有找到文件。
basic-auth/src/main/java/com/yiring/auth/domain/permission/Permission.java
浏览文件 @
df5fab6e
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
auth
.
domain
.
permission
;
import
static
com
.
yiring
.
auth
.
domain
.
permission
.
Permission
.
DELETE_SQL
;
import
static
com
.
yiring
.
auth
.
domain
.
permission
.
Permission
.
TABLE_NAME
;
import
com.alibaba.fastjson.JSONObject
;
import
com.vladmihalcea.hibernate.type.json.JsonType
;
import
com.yiring.common.domain.BasicEntity
;
import
java.io.Serial
;
import
java.io.Serializable
;
import
javax.persistence.*
;
import
javax.persistence.Entity
;
import
javax.persistence.Index
;
import
javax.persistence.Table
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.TypeDef
;
import
org.hibernate.annotations.*
;
/**
* 权限
...
...
@@ -29,19 +34,31 @@ import org.hibernate.annotations.TypeDef;
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@SQLDelete
(
sql
=
DELETE_SQL
)
@SQLDeleteAll
(
sql
=
DELETE_SQL
)
@Where
(
clause
=
BasicEntity
.
Where
.
EXIST
)
@Entity
@TypeDef
(
name
=
"json"
,
typeClass
=
JsonType
.
class
)
@Table
(
name
=
"SYS_PERMISSION"
,
indexes
=
{
@Index
(
columnList
=
"type"
),
@Index
(
columnList
=
"pid"
),
@Index
(
columnList
=
"tree"
)
}
name
=
TABLE_NAME
,
indexes
=
{
@Index
(
columnList
=
"deleteTime"
),
@Index
(
columnList
=
"type"
),
@Index
(
columnList
=
"pid"
),
@Index
(
columnList
=
"tree"
),
}
)
@Comment
(
"系统权限"
)
public
class
Permission
extends
BasicEntity
implements
Serializable
{
public
static
final
String
TABLE_NAME
=
"SYS_PERMISSION"
;
public
static
final
String
DELETE_SQL
=
"update "
+
TABLE_NAME
+
BasicEntity
.
Where
.
DELETE_SET
;
@Serial
private
static
final
long
serialVersionUID
=
-
2001221843529000953L
;
@Comment
(
"类型(MENU: 菜单, BUTTON: 按钮)"
)
@Column
(
nullable
=
false
)
@Enumerated
(
EnumType
.
STRING
)
Type
type
;
...
...
@@ -49,10 +66,11 @@ public class Permission extends BasicEntity implements Serializable {
Integer
serial
;
@Comment
(
"标识"
)
@Column
(
unique
=
true
,
nullable
=
false
)
@Column
(
nullable
=
false
)
String
uid
;
@Comment
(
"名称"
)
@Column
(
nullable
=
false
)
String
name
;
@Comment
(
"路径"
)
...
...
basic-auth/src/main/java/com/yiring/auth/domain/role/Role.java
浏览文件 @
df5fab6e
/* (C) 2022 YiRing, Inc. */
package
com
.
yiring
.
auth
.
domain
.
role
;
import
static
com
.
yiring
.
auth
.
domain
.
role
.
Role
.
DELETE_SQL
;
import
static
com
.
yiring
.
auth
.
domain
.
role
.
Role
.
TABLE_NAME
;
import
com.fasterxml.jackson.annotation.JsonIgnore
;
import
com.yiring.auth.domain.permission.Permission
;
import
com.yiring.auth.domain.user.User
;
...
...
@@ -15,6 +18,9 @@ import lombok.experimental.FieldDefaults;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDeleteAll
;
import
org.hibernate.annotations.Where
;
/**
* 角色
...
...
@@ -31,11 +37,20 @@ import org.hibernate.annotations.Comment;
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@SQLDelete
(
sql
=
DELETE_SQL
)
@SQLDeleteAll
(
sql
=
DELETE_SQL
)
@Where
(
clause
=
BasicEntity
.
Where
.
EXIST
)
@Entity
@Table
(
name
=
TABLE_NAME
,
indexes
=
{
@Index
(
columnList
=
"deleteTime"
),
@Index
(
columnList
=
"uid,deleteTime"
,
unique
=
true
)
}
)
@Comment
(
"系统角色"
)
@Table
(
name
=
"SYS_ROLE"
,
indexes
=
{
@Index
(
columnList
=
"uid"
,
unique
=
true
)
})
public
class
Role
extends
BasicEntity
implements
Serializable
{
public
static
final
String
TABLE_NAME
=
"SYS_ROLE"
;
public
static
final
String
DELETE_SQL
=
"update "
+
TABLE_NAME
+
BasicEntity
.
Where
.
DELETE_SET
;
@Serial
private
static
final
long
serialVersionUID
=
910404402503275957L
;
...
...
@@ -44,6 +59,7 @@ public class Role extends BasicEntity implements Serializable {
String
uid
;
@Comment
(
"名称"
)
@Column
(
nullable
=
false
)
String
name
;
@JsonIgnore
...
...
basic-auth/src/main/java/com/yiring/auth/domain/user/User.java
浏览文件 @
df5fab6e
...
...
@@ -15,6 +15,8 @@ import lombok.experimental.FieldDefaults;
import
lombok.experimental.FieldNameConstants
;
import
lombok.experimental.SuperBuilder
;
import
org.hibernate.annotations.Comment
;
import
org.hibernate.annotations.SQLDelete
;
import
org.hibernate.annotations.SQLDeleteAll
;
import
org.hibernate.annotations.Where
;
/**
...
...
@@ -32,12 +34,26 @@ import org.hibernate.annotations.Where;
@AllArgsConstructor
@FieldNameConstants
@FieldDefaults
(
level
=
AccessLevel
.
PRIVATE
)
@Where
(
clause
=
"deleted = false"
)
@SQLDelete
(
sql
=
User
.
DELETE_SQL
)
@SQLDeleteAll
(
sql
=
User
.
DELETE_SQL
)
@Where
(
clause
=
User
.
Where
.
EXIST
)
@Entity
@Table
(
name
=
"SYS_USER"
,
indexes
=
{
@Index
(
columnList
=
"enabled"
),
@Index
(
columnList
=
"deleted"
)
})
@Table
(
name
=
User
.
TABLE_NAME
,
indexes
=
{
@Index
(
columnList
=
"enabled"
),
@Index
(
columnList
=
"deleteTime"
),
@Index
(
columnList
=
"username,deleteTime"
,
unique
=
true
),
@Index
(
columnList
=
"mobile,deleteTime"
,
unique
=
true
),
@Index
(
columnList
=
"email,deleteTime"
,
unique
=
true
),
}
)
@Comment
(
"系统用户"
)
public
class
User
extends
BasicEntity
implements
Serializable
{
public
static
final
String
TABLE_NAME
=
"SYS_USER"
;
public
static
final
String
DELETE_SQL
=
"update "
+
TABLE_NAME
+
BasicEntity
.
Where
.
DELETE_SET
;
@Serial
private
static
final
long
serialVersionUID
=
-
5787847701210907511L
;
...
...
@@ -45,15 +61,12 @@ public class User extends BasicEntity implements Serializable {
String
realName
;
@Comment
(
"用户名"
)
@Column
(
unique
=
true
)
String
username
;
@Comment
(
"手机号"
)
@Column
(
unique
=
true
)
String
mobile
;
@Comment
(
"邮箱"
)
@Column
(
unique
=
true
)
String
email
;
@Comment
(
"密码"
)
...
...
@@ -68,9 +81,6 @@ public class User extends BasicEntity implements Serializable {
@Comment
(
"是否启用"
)
Boolean
enabled
;
@Comment
(
"是否删除"
)
Boolean
deleted
;
@JsonIgnore
@Builder
.
Default
@Comment
(
"角色集合"
)
...
...
basic-auth/src/main/java/com/yiring/auth/web/auth/AuthController.java
浏览文件 @
df5fab6e
...
...
@@ -80,7 +80,6 @@ public class AuthController {
.
username
(
param
.
getUsername
())
.
password
(
SaSecureUtil
.
sha256
(
param
.
getPassword
()))
.
enabled
(
param
.
getEnable
())
.
deleted
(
Boolean
.
FALSE
)
.
createTime
(
LocalDateTime
.
now
())
.
build
();
userRepository
.
saveAndFlush
(
user
);
...
...
@@ -105,7 +104,7 @@ public class AuthController {
}
// 检查用户是否已被删除
if
(
!
Boolean
.
FALSE
.
equals
(
user
.
getDeleted
())
)
{
if
(
user
.
getDeleteTime
()
!=
null
)
{
return
Result
.
no
(
Status
.
FORBIDDEN
,
"用户被禁用, 请联系管理员"
);
}
...
...
basic-common/core/src/main/java/com/yiring/common/domain/BasicEntity.java
浏览文件 @
df5fab6e
...
...
@@ -2,10 +2,7 @@
package
com
.
yiring
.
common
.
domain
;
import
java.time.LocalDateTime
;
import
javax.persistence.Column
;
import
javax.persistence.GeneratedValue
;
import
javax.persistence.Id
;
import
javax.persistence.MappedSuperclass
;
import
javax.persistence.*
;
import
lombok.*
;
import
lombok.experimental.FieldDefaults
;
import
lombok.experimental.FieldNameConstants
;
...
...
@@ -50,4 +47,13 @@ public abstract class BasicEntity {
@Column
(
nullable
=
false
)
@UpdateTimestamp
LocalDateTime
updateTime
;
@Comment
(
"删除时间"
)
LocalDateTime
deleteTime
;
public
interface
Where
{
String
EXIST
=
" delete_time is null "
;
String
DELETE_SET
=
" set delete_time = now() where id = ? "
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论