3
3
import com .github .pagehelper .PageInfo ;
4
4
import com .lmxdawn .api .admin .annotation .AuthRuleAnnotation ;
5
5
import com .lmxdawn .api .admin .entity .auth .AuthAdmin ;
6
+ import com .lmxdawn .api .admin .entity .auth .AuthRole ;
6
7
import com .lmxdawn .api .admin .entity .auth .AuthRoleAdmin ;
7
8
import com .lmxdawn .api .admin .enums .ResultEnum ;
8
- import com .lmxdawn .api .admin .form .admin .auth .AuthAdminForm ;
9
+ import com .lmxdawn .api .admin .form .auth .AuthAdminSaveForm ;
10
+ import com .lmxdawn .api .admin .form .auth .AuthAdminQueryForm ;
9
11
import com .lmxdawn .api .admin .service .auth .AuthAdminService ;
10
12
import com .lmxdawn .api .admin .service .auth .AuthRoleAdminService ;
11
13
import com .lmxdawn .api .admin .service .auth .AuthRoleService ;
14
+ import com .lmxdawn .api .admin .vo .auth .AuthAdminRoleVO ;
12
15
import com .lmxdawn .api .common .utils .ResultVOUtils ;
13
16
import com .lmxdawn .api .admin .vo .PageSimpleVO ;
14
17
import com .lmxdawn .api .admin .vo .ResultVO ;
@@ -42,44 +45,40 @@ public class AuthAdminController {
42
45
*/
43
46
@ AuthRuleAnnotation ("/admin/auth/admin/index" )
44
47
@ GetMapping ("/admin/auth/admin/index" )
45
- public ResultVO index (@ RequestParam (value = "page" ,defaultValue = "1" ) Integer page ,
46
- @ RequestParam (value = "limit" ,defaultValue = "20" ) Integer limit ,
47
- @ RequestParam (value = "status" , required = false ) Integer status ,
48
- @ RequestParam (value = "username" , required = false ) String username ,
49
- @ RequestParam (value = "roleId" , required = false ) Long roleId ) {
50
-
51
- Map <String , Object > map = new HashMap <>();
52
- map .put ("status" , status );
53
- map .put ("username" , username );
54
-
55
- if (roleId != null ) {
56
- List <AuthRoleAdmin > authRoleAdmins = authRoleAdminService .listByRoleId (roleId );
48
+ public ResultVO index (@ Valid AuthAdminQueryForm authAdminQueryForm ,
49
+ BindingResult bindingResult ) {
50
+
51
+ if (bindingResult .hasErrors ()) {
52
+ return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , bindingResult .getFieldError ().getDefaultMessage ());
53
+ }
54
+
55
+ if (authAdminQueryForm .getRoleId () != null ) {
56
+ List <AuthRoleAdmin > authRoleAdmins = authRoleAdminService .listByRoleId (authAdminQueryForm .getRoleId ());
57
57
List <Long > ids = new ArrayList <>();
58
58
if (authRoleAdmins != null && !authRoleAdmins .isEmpty ()) {
59
59
ids = authRoleAdmins .stream ().map (AuthRoleAdmin ::getAdminId ).collect (Collectors .toList ());
60
60
}
61
- map . put ( "ids" , ids );
61
+ authAdminQueryForm . setIds ( ids );
62
62
}
63
+ List <AuthAdmin > authAdminList = authAdminService .listAdminPage (authAdminQueryForm );
63
64
64
- PageInfo < AuthAdmin > authAdminPageInfo = authAdminService . listAdminPage ( page , limit , map );
65
- List <Long > adminIds = authAdminPageInfo . getList () .stream ().map (AuthAdmin ::getId ).collect (Collectors .toList ());
65
+ // 查询所有的权限
66
+ List <Long > adminIds = authAdminList .stream ().map (AuthAdmin ::getId ).collect (Collectors .toList ());
66
67
List <AuthRoleAdmin > authRoleAdminList = authRoleAdminService .listByAdminIdIn (adminIds );
67
68
68
69
// 视图列表
69
- List <AuthAdminVo > authAdminVoList = new ArrayList <>();
70
- authAdminPageInfo .getList ().forEach (v -> {
70
+ List <AuthAdminVo > authAdminVoList = authAdminList .stream ().map (item -> {
71
71
AuthAdminVo authAdminVo = new AuthAdminVo ();
72
- BeanUtils .copyProperties (v , authAdminVo );
73
- List <Long > roles = new ArrayList <>();
74
- authRoleAdminList .forEach (authRoleAdmin -> {
75
- if (v .getId ().equals (authRoleAdmin .getAdminId ())) {
76
- roles .add (authRoleAdmin .getRoleId ());
77
- }
78
- });
72
+ BeanUtils .copyProperties (item , authAdminVo );
73
+ List <Long > roles = authRoleAdminList .stream ()
74
+ .filter (authRoleAdmin -> authAdminVo .getId ().equals (authRoleAdmin .getAdminId ()))
75
+ .map (AuthRoleAdmin ::getRoleId )
76
+ .collect (Collectors .toList ());
79
77
authAdminVo .setRoles (roles );
80
- authAdminVoList . add ( authAdminVo ) ;
81
- });
78
+ return authAdminVo ;
79
+ }). collect ( Collectors . toList ()) ;
82
80
81
+ PageInfo <AuthAdmin > authAdminPageInfo = new PageInfo <>(authAdminList );
83
82
PageSimpleVO <AuthAdminVo > authAdminPageSimpleVO = new PageSimpleVO <>();
84
83
authAdminPageSimpleVO .setTotal (authAdminPageInfo .getTotal ());
85
84
authAdminPageSimpleVO .setList (authAdminVoList );
@@ -89,81 +88,116 @@ public ResultVO index(@RequestParam(value = "page",defaultValue = "1") Integer p
89
88
}
90
89
91
90
92
-
93
91
/**
94
92
* 获取角色列表
95
93
*/
96
94
@ AuthRuleAnnotation ("/admin/auth/admin/roleList" )
97
95
@ GetMapping ("/admin/auth/admin/roleList" )
98
- public ResultVO roleList (@ RequestParam (value = "page" ,defaultValue = "1" ) Integer page ,
99
- @ RequestParam (value = "limit" ,defaultValue = "50" ) Integer limit ,
100
- Map <String , Object > map ) {
101
-
102
- return ResultVOUtils .success (authRoleService .listAuthAdminRolePage (page , limit , map ));
96
+ public ResultVO roleList (@ RequestParam (value = "page" , defaultValue = "1" ) Integer page ,
97
+ @ RequestParam (value = "limit" , defaultValue = "50" ) Integer limit ) {
98
+
99
+ List <AuthRole > authRoleList = authRoleService .listAuthAdminRolePage (page , limit , null );
100
+ PageInfo <AuthRole > pageInfo = new PageInfo <>(authRoleList );
101
+ PageSimpleVO <AuthAdminRoleVO > pageSimpleVO = new PageSimpleVO <>();
102
+ pageSimpleVO .setTotal (pageInfo .getTotal ());
103
+ List <AuthAdminRoleVO > authAdminRoleVOS = authRoleList .stream ().map (e -> {
104
+ AuthAdminRoleVO authAdminRoleVO = new AuthAdminRoleVO ();
105
+ BeanUtils .copyProperties (e , authAdminRoleVO );
106
+ return authAdminRoleVO ;
107
+ }).collect (Collectors .toList ());
108
+ pageSimpleVO .setList (authAdminRoleVOS );
109
+
110
+ return ResultVOUtils .success (pageSimpleVO );
103
111
104
112
}
105
113
106
114
107
115
/**
108
116
* 新增
117
+ *
109
118
* @return
110
119
*/
111
120
@ AuthRuleAnnotation ("/admin/auth/admin/save" )
112
121
@ PostMapping ("/admin/auth/admin/save" )
113
- public ResultVO save (@ RequestBody @ Valid AuthAdminForm authAdminForm ,
122
+ public ResultVO save (@ RequestBody @ Valid AuthAdminSaveForm authAdminSaveForm ,
114
123
BindingResult bindingResult ) {
115
124
116
125
if (bindingResult .hasErrors ()) {
117
126
return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , bindingResult .getFieldError ().getDefaultMessage ());
118
127
}
119
128
129
+ // 检查是否存在相同名称的管理员
130
+ AuthAdmin byUserName = authAdminService .findByUserName (authAdminSaveForm .getUsername ());
131
+ if (byUserName != null ) {
132
+ return ResultVOUtils .error (ResultEnum .DATA_REPEAT , "当前管理员已存在" );
133
+ }
120
134
121
- AuthAdmin authAdmin = authAdminService .insertAuthAdminForm (authAdminForm );
135
+ AuthAdmin authAdmin = new AuthAdmin ();
136
+ BeanUtils .copyProperties (authAdminSaveForm , authAdmin );
137
+
138
+ boolean b = authAdminService .insertAuthAdmin (authAdmin );
139
+
140
+ if (!b ) {
141
+ return ResultVOUtils .error (ResultEnum .NOT_NETWORK );
142
+ }
122
143
123
144
AuthAdminVo authAdminVo = new AuthAdminVo ();
124
145
BeanUtils .copyProperties (authAdmin , authAdminVo );
125
- authAdminVo .setRoles (authAdminForm .getRoles ());
146
+ authAdminVo .setRoles (authAdminSaveForm .getRoles ());
126
147
127
148
return ResultVOUtils .success (authAdminVo );
128
149
}
129
150
130
151
/**
131
152
* 修改
153
+ *
132
154
* @return
133
155
*/
134
156
@ AuthRuleAnnotation ("/admin/auth/admin/edit" )
135
157
@ PostMapping ("/admin/auth/admin/edit" )
136
- public ResultVO edit (@ RequestBody @ Valid AuthAdminForm authAdminForm ,
158
+ public ResultVO edit (@ RequestBody @ Valid AuthAdminSaveForm authAdminSaveForm ,
137
159
BindingResult bindingResult ) {
138
160
139
161
if (bindingResult .hasErrors ()) {
140
162
return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , bindingResult .getFieldError ().getDefaultMessage ());
141
163
}
142
164
143
- if (authAdminForm .getId () == null ) {
165
+ if (authAdminSaveForm .getId () == null ) {
144
166
return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , "参数错误!" );
145
167
}
146
168
147
- boolean b = authAdminService .updateAuthAdminForm (authAdminForm );
169
+ // 检查是否存在除了当前管理员的其它名称的管理员
170
+ AuthAdmin byUserName = authAdminService .findByUserName (authAdminSaveForm .getUsername ());
171
+ if (byUserName != null && !authAdminSaveForm .getId ().equals (byUserName .getId ())) {
172
+ return ResultVOUtils .error (ResultEnum .DATA_REPEAT , "当前管理员已存在" );
173
+ }
174
+
175
+ AuthAdmin authAdmin = new AuthAdmin ();
176
+ BeanUtils .copyProperties (authAdminSaveForm , authAdmin );
177
+
178
+ boolean b = authAdminService .updateAuthAdmin (authAdmin );
179
+
148
180
if (!b ) {
149
- return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , "网络错误!" );
181
+ return ResultVOUtils .error (ResultEnum .NOT_NETWORK );
150
182
}
183
+
151
184
return ResultVOUtils .success ();
152
185
}
153
186
154
187
/**
155
188
* 删除
189
+ *
156
190
* @return
157
191
*/
158
192
@ AuthRuleAnnotation ("/admin/auth/admin/delete" )
159
193
@ PostMapping ("/admin/auth/admin/delete" )
160
- public ResultVO delete (@ RequestBody AuthAdminForm authAdminForm ) {
194
+ public ResultVO delete (@ RequestBody AuthAdminSaveForm authAdminSaveForm ) {
161
195
162
- if (authAdminForm .getId () == null ) {
196
+ if (authAdminSaveForm .getId () == null ) {
163
197
return ResultVOUtils .error (ResultEnum .PARAM_VERIFY_FALL , "参数错误!" );
164
198
}
165
199
166
- boolean b = authAdminService .deleteById (authAdminForm .getId ());
200
+ boolean b = authAdminService .deleteById (authAdminSaveForm .getId ());
167
201
if (!b ) {
168
202
return ResultVOUtils .error (ResultEnum .NOT_NETWORK );
169
203
}
0 commit comments