Skip to content

Commit 5e70240

Browse files
Jokky6colorful3
authored andcommitted
refactor:修改group中level的类 型,并且通过MybatisTypeHandler做类型转换
1 parent 9fab534 commit 5e70240

7 files changed

Lines changed: 38 additions & 26 deletions

File tree

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,40 @@
11
package io.github.talelin.latticy.common.enumeration;
22

3+
import com.baomidou.mybatisplus.annotation.EnumValue;
4+
35
/**
46
* @author colorful@TaleLin
57
*/
68
public enum GroupLevelEnum {
79
/**
810
* 超级管理员
911
*/
10-
ROOT("root"),
12+
ROOT(1,"root"),
1113
/**
1214
* 游客
1315
*/
14-
GUEST("guest"),
16+
GUEST(2,"guest"),
1517
/**
1618
* 普通用户
1719
*/
18-
USER("user")
20+
USER(3,"user")
1921
;
2022

23+
@EnumValue
24+
private Integer code;
25+
2126
private String value;
2227

23-
GroupLevelEnum(String value) {
28+
GroupLevelEnum(Integer code , String value) {
29+
this.code = code;
2430
this.value = value;
2531
}
2632

27-
public String getValue() {
28-
return value;
33+
public Integer getCode() {
34+
return code;
2935
}
3036

31-
public void setValue(String value) {
32-
this.value = value;
37+
public void setCode(Integer code) {
38+
this.code = code;
3339
}
3440
}

src/main/java/io/github/talelin/latticy/controller/cms/AdminController.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ public PageResponseVO getGroups(
123123
}
124124

125125
@GetMapping("/group/all")
126-
@AdminRequired
127126
@PermissionMeta(value = "查询所有权限组", mount = false)
128127
public List<GroupDO> getAllGroup() {
129128
List<GroupDO> groups = adminService.getAllGroups();

src/main/java/io/github/talelin/latticy/model/GroupDO.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
package io.github.talelin.latticy.model;
22

3+
import com.baomidou.mybatisplus.annotation.EnumValue;
34
import com.baomidou.mybatisplus.annotation.TableField;
45
import com.baomidou.mybatisplus.annotation.TableName;
6+
import com.baomidou.mybatisplus.extension.handlers.MybatisEnumTypeHandler;
7+
import io.github.talelin.latticy.common.enumeration.GroupLevelEnum;
58
import lombok.*;
69

710
import java.io.Serializable;
811

912
/**
1013
* @author pedro@TaleLin
1114
* @author Juzi@TaleLin
15+
* @author Jokky@TaleLin
1216
*/
1317
@Data
1418
@Builder
1519
@NoArgsConstructor
1620
@AllArgsConstructor
17-
@TableName("lin_group")
21+
@TableName(value = "lin_group",autoResultMap = true)
1822
@EqualsAndHashCode(callSuper = true)
1923
public class GroupDO extends BaseModel implements Serializable {
2024

@@ -33,7 +37,8 @@ public class GroupDO extends BaseModel implements Serializable {
3337
/**
3438
* 分组级别(root、guest、user,其中 root、guest 分组只能存在一个)
3539
*/
36-
@TableField(value = "`level`")
37-
private String level;
40+
@TableField(value = "`level`", typeHandler = MybatisEnumTypeHandler.class)
41+
@EnumValue
42+
private GroupLevelEnum level;
3843

3944
}

src/main/java/io/github/talelin/latticy/service/impl/GroupServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ public List<Integer> getGroupUserIds(Integer id) {
117117

118118
@Override
119119
public GroupDO getParticularGroupByLevel(GroupLevelEnum level) {
120-
if (GroupLevelEnum.USER.getValue().equals(level.getValue())) {
120+
if (GroupLevelEnum.USER.getCode().equals(level.getCode())) {
121121
return null;
122122
} else {
123123
QueryWrapper<GroupDO> wrapper = new QueryWrapper<>();

src/main/resources/application-test.yml

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,16 @@ logging:
1212
spring:
1313
# h2 内存数据库配置,供测试使用,其它环境勿用
1414
datasource:
15-
continue-on-error: false
16-
driver-class-name: org.h2.Driver
17-
password: ''
18-
platform: h2
19-
schema: classpath:/h2-test.sql
20-
url: jdbc:h2:mem:testdbsa;MODE=MYSQL;DB_CLOSE_DELAY=-1;DATABASE_TO_UPPER=false
21-
username: sa
22-
h2:
23-
console:
24-
enabled: true
25-
path: /h2
15+
driver-class-name: com.mysql.cj.jdbc.Driver
16+
password: '17605259250'
17+
url: jdbc:mysql://jokky.fun:3306/lin-cms?useSSL=false&serverTimezone=UTC&characterEncoding=UTF8
18+
username: root
19+
20+
# 开启权限拦截
21+
auth:
22+
enabled: true
23+
24+
25+
# 开启http请求日志记录
26+
request-log:
27+
enabled: true

src/main/resources/application.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
spring:
44
# 激活环境配置
55
profiles:
6-
active: dev
6+
active: test
77
# 文件编码 UTF8
88
mandatory-file-encoding: UTF-8
99
mvc:

src/main/resources/schema.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ CREATE TABLE lin_group
7272
id int(10) unsigned NOT NULL AUTO_INCREMENT,
7373
name varchar(60) NOT NULL COMMENT '分组名称,例如:搬砖者',
7474
info varchar(255) DEFAULT NULL COMMENT '分组信息:例如:搬砖的人',
75-
level ENUM('root', 'guest', 'user') DEFAULT 'user' COMMENT '分组级别(root、guest分组只能存在一个',
75+
level smallint(1) NOT NULL DEFAULT 3 COMMENT '分组级别 1:root 2:guest 3:user root(root、guest分组只能存在一个)',
7676
create_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
7777
update_time datetime(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
7878
delete_time datetime(3) DEFAULT NULL,

0 commit comments

Comments
 (0)