Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
brandkbs2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shenjunjie
brandkbs2
Commits
431f1904
Commit
431f1904
authored
Jul 22, 2024
by
陈健智
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
用户管理新增系统管理员对所有用户调整页面
parent
08539bc8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
225 additions
and
9 deletions
+225
-9
src/main/java/com/zhiwei/brandkbs2/controller/admin/UserController.java
+45
-4
src/main/java/com/zhiwei/brandkbs2/dao/UserDao.java
+2
-1
src/main/java/com/zhiwei/brandkbs2/dao/impl/UserDaoImpl.java
+6
-0
src/main/java/com/zhiwei/brandkbs2/service/UserService.java
+40
-4
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
+132
-0
No files found.
src/main/java/com/zhiwei/brandkbs2/controller/admin/UserController.java
View file @
431f1904
package
com
.
zhiwei
.
brandkbs2
.
controller
.
admin
;
package
com
.
zhiwei
.
brandkbs2
.
controller
.
admin
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.auth.Auth
;
import
com.zhiwei.brandkbs2.auth.Auth
;
import
com.zhiwei.brandkbs2.controller.BaseController
;
import
com.zhiwei.brandkbs2.controller.BaseController
;
import
com.zhiwei.brandkbs2.enmus.RoleEnum
;
import
com.zhiwei.brandkbs2.enmus.RoleEnum
;
...
@@ -7,10 +8,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
...
@@ -7,10 +8,7 @@ import com.zhiwei.brandkbs2.model.ResponseResult;
import
com.zhiwei.brandkbs2.pojo.dto.UserDTO
;
import
com.zhiwei.brandkbs2.pojo.dto.UserDTO
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.brandkbs2.service.UserService
;
import
com.zhiwei.middleware.auth.pojo.CenterUser
;
import
com.zhiwei.middleware.auth.pojo.CenterUser
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.*
;
import
io.swagger.annotations.ApiImplicitParam
;
import
io.swagger.annotations.ApiImplicitParams
;
import
io.swagger.annotations.ApiOperation
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
...
@@ -124,4 +122,46 @@ public class UserController extends BaseController {
...
@@ -124,4 +122,46 @@ public class UserController extends BaseController {
return
ResponseResult
.
success
();
return
ResponseResult
.
success
();
}
}
@ApiOperation
(
"分页查询所有用户列表"
)
@GetMapping
(
"/all-user/list"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
findAllUserList
(
@RequestParam
(
value
=
"page"
,
defaultValue
=
"1"
)
int
page
,
@RequestParam
(
value
=
"size"
,
defaultValue
=
"10"
)
int
size
,
@RequestParam
(
value
=
"keyword"
,
defaultValue
=
""
)
String
keyword
)
{
return
ResponseResult
.
success
(
userService
.
findAllUserList
(
keyword
,
page
,
size
));
}
@ApiOperation
(
"根据用户名或手机号查询用户项目权限"
)
@GetMapping
(
"/all-user/find"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
getUserByNickNameOrPhone
(
@RequestParam
(
value
=
"nickname"
,
required
=
false
)
String
nickname
,
@RequestParam
(
value
=
"phoneNumber"
,
required
=
false
)
String
phoneNumber
)
{
return
userService
.
getUserByNickNameOrPhone
(
nickname
,
phoneNumber
);
}
@ApiOperation
(
"编辑单条项目权限"
)
@PostMapping
(
"/all-user/single-update"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
updateOneUserRoles
(
@ApiParam
(
name
=
"json"
,
value
=
"json:{id:用户id,nickname:用户名,roleId:权限,expiredTime:过期时间,exportAmount:舆情导出数量,projectId:权限项目id,key:唯一key原封不动传回来即可}"
,
required
=
true
)
@RequestBody
JSONObject
json
)
{
return
userService
.
updateOneUserRoles
(
json
);
}
@ApiOperation
(
"批量编辑项目权限"
)
@PostMapping
(
"/all-user/batch-update"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
updateBatchUserRoles
(
@ApiParam
(
name
=
"json"
,
value
=
"json:{id:用户id,roles:[{projectId:权限项目id,roleId:权限},{},...]}"
,
required
=
true
)
@RequestBody
JSONObject
json
)
{
return
userService
.
updateBatchUserRoles
(
json
);
}
@ApiOperation
(
"删除用户权限"
)
@DeleteMapping
(
"/all-user/delete"
)
@Auth
(
role
=
RoleEnum
.
SUPER_ADMIN
)
public
ResponseResult
deleteUserRole
(
@RequestParam
(
value
=
"id"
)
String
id
,
@RequestParam
(
value
=
"key"
)
String
key
)
{
return
userService
.
deleteUserRole
(
id
,
key
);
}
}
}
\ No newline at end of file
src/main/java/com/zhiwei/brandkbs2/dao/UserDao.java
View file @
431f1904
package
com
.
zhiwei
.
brandkbs2
.
dao
;
package
com
.
zhiwei
.
brandkbs2
.
dao
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
org.springframework.data.mongodb.core.query.Query
;
/**
/**
* @ClassName: UserDao
* @ClassName: UserDao
...
@@ -9,5 +10,5 @@ import com.zhiwei.brandkbs2.pojo.User;
...
@@ -9,5 +10,5 @@ import com.zhiwei.brandkbs2.pojo.User;
* @date: 2022-04-28 18:10
* @date: 2022-04-28 18:10
*/
*/
public
interface
UserDao
extends
BaseMongoDao
<
User
>{
public
interface
UserDao
extends
BaseMongoDao
<
User
>{
User
findOne
(
Query
query
);
}
}
src/main/java/com/zhiwei/brandkbs2/dao/impl/UserDaoImpl.java
View file @
431f1904
...
@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.dao.impl;
...
@@ -2,6 +2,7 @@ package com.zhiwei.brandkbs2.dao.impl;
import
com.zhiwei.brandkbs2.dao.UserDao
;
import
com.zhiwei.brandkbs2.dao.UserDao
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
org.springframework.data.mongodb.core.query.Query
;
import
org.springframework.stereotype.Component
;
import
org.springframework.stereotype.Component
;
/**
/**
...
@@ -18,4 +19,9 @@ public class UserDaoImpl extends BaseMongoDaoImpl<User> implements UserDao {
...
@@ -18,4 +19,9 @@ public class UserDaoImpl extends BaseMongoDaoImpl<User> implements UserDao {
public
UserDaoImpl
()
{
public
UserDaoImpl
()
{
super
(
COLLECTION_NAME
);
super
(
COLLECTION_NAME
);
}
}
@Override
public
User
findOne
(
Query
query
)
{
return
mongoTemplate
.
findOne
(
query
,
User
.
class
,
COLLECTION_NAME
);
}
}
}
src/main/java/com/zhiwei/brandkbs2/service/UserService.java
View file @
431f1904
...
@@ -42,7 +42,7 @@ public interface UserService {
...
@@ -42,7 +42,7 @@ public interface UserService {
UserInfo
queryUserInfo
(
String
userId
,
String
pid
);
UserInfo
queryUserInfo
(
String
userId
,
String
pid
);
/**
/**
* 分页查询所有用户
* 分页查询所有用户
(当前项目的用户)
*
*
* @param page 页码
* @param page 页码
* @param size 大小
* @param size 大小
...
@@ -55,14 +55,14 @@ public interface UserService {
...
@@ -55,14 +55,14 @@ public interface UserService {
PageVO
<
JSONObject
>
findUserList
(
int
page
,
int
size
,
String
keyword
,
String
pid
,
int
role
,
String
sorter
);
PageVO
<
JSONObject
>
findUserList
(
int
page
,
int
size
,
String
keyword
,
String
pid
,
int
role
,
String
sorter
);
/**
/**
* 添加用户
* 添加用户
(当前项目的用户)
*
*
* @param userDTO
* @param userDTO
*/
*/
ResponseResult
addUser
(
UserDTO
userDTO
);
ResponseResult
addUser
(
UserDTO
userDTO
);
/**
/**
* 删除用户
* 删除用户
(当前项目的用户)
*
*
* @param userId
* @param userId
* @param pid
* @param pid
...
@@ -70,7 +70,7 @@ public interface UserService {
...
@@ -70,7 +70,7 @@ public interface UserService {
void
deleteUser
(
String
userId
,
String
pid
);
void
deleteUser
(
String
userId
,
String
pid
);
/**
/**
* 编辑用户
* 编辑用户
(当前项目的用户)
*
*
* @param userDTO
* @param userDTO
*/
*/
...
@@ -135,4 +135,40 @@ public interface UserService {
...
@@ -135,4 +135,40 @@ public interface UserService {
*/
*/
ResponseResult
mobileCutLogin
(
String
userId
,
String
projectId
);
ResponseResult
mobileCutLogin
(
String
userId
,
String
projectId
);
/**
* 项目管理员-所有项目用户权限列表
* @param page
* @param pageSize
* @return
*/
PageVO
<
JSONObject
>
findAllUserList
(
String
keyword
,
int
page
,
int
pageSize
);
/**
* 项目管理员-所有项目用户权限列表-通过用户名或手机号查询品见用户项目权限
* @param nickName
* @param phoneNumber
* @return
*/
ResponseResult
getUserByNickNameOrPhone
(
String
nickName
,
String
phoneNumber
);
/**
* 项目管理员-所有项目用户权限列表-编辑单条项目权限
*
* @param json
*/
ResponseResult
updateOneUserRoles
(
JSONObject
json
);
/**
* 项目管理员-所有项目用户权限列表-批量编辑项目权限
*
* @param json
*/
ResponseResult
updateBatchUserRoles
(
JSONObject
json
);
/**
* 项目管理员-所有项目用户列表-删除用户权限
* @param id
* @return
*/
ResponseResult
deleteUserRole
(
String
id
,
String
key
);
}
}
src/main/java/com/zhiwei/brandkbs2/service/impl/UserServiceImpl.java
View file @
431f1904
...
@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.service.impl;
...
@@ -3,6 +3,7 @@ package com.zhiwei.brandkbs2.service.impl;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSONObject
;
import
com.alibaba.fastjson.JSONObject
;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.auth.UserThreadLocal
;
import
com.zhiwei.brandkbs2.common.GlobalPojo
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.config.Constant
;
import
com.zhiwei.brandkbs2.dao.ProjectDao
;
import
com.zhiwei.brandkbs2.dao.ProjectDao
;
import
com.zhiwei.brandkbs2.dao.UserDao
;
import
com.zhiwei.brandkbs2.dao.UserDao
;
...
@@ -13,6 +14,7 @@ import com.zhiwei.brandkbs2.enmus.response.LoginCodeEnum;
...
@@ -13,6 +14,7 @@ import com.zhiwei.brandkbs2.enmus.response.LoginCodeEnum;
import
com.zhiwei.brandkbs2.exception.ExceptionCast
;
import
com.zhiwei.brandkbs2.exception.ExceptionCast
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.CommonCodeEnum
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.model.ResponseResult
;
import
com.zhiwei.brandkbs2.pojo.Project
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
com.zhiwei.brandkbs2.pojo.User
;
import
com.zhiwei.brandkbs2.pojo.UserInfo
;
import
com.zhiwei.brandkbs2.pojo.UserInfo
;
import
com.zhiwei.brandkbs2.pojo.UserRole
;
import
com.zhiwei.brandkbs2.pojo.UserRole
;
...
@@ -418,6 +420,136 @@ public class UserServiceImpl implements UserService {
...
@@ -418,6 +420,136 @@ public class UserServiceImpl implements UserService {
}
}
@Override
@Override
public
PageVO
<
JSONObject
>
findAllUserList
(
String
keyword
,
int
page
,
int
pageSize
)
{
Query
query
=
new
Query
(
Criteria
.
where
(
"superAdmin"
).
is
(
false
));
userDao
.
addKeywordFuzz
(
query
,
keyword
,
"nickname"
);
userDao
.
addSort
(
query
,
"{\"cTime\":\"descend\"}"
);
// roles总量
List
<
User
>
list
=
userDao
.
findList
(
new
Query
(
Criteria
.
where
(
"superAdmin"
).
is
(
false
)));
long
count
=
list
.
stream
().
map
(
User:
:
getRoles
).
filter
(
Objects:
:
nonNull
).
mapToLong
(
Collection:
:
size
).
sum
();
List
<
User
>
userList
=
userDao
.
findList
(
query
);
Map
<
User
,
List
<
UserRole
>>
userRolesMap
=
userList
.
stream
().
collect
(
Collectors
.
toMap
(
o
->
o
,
User:
:
getRoles
));
List
<
JSONObject
>
resList
=
new
ArrayList
<>();
for
(
Map
.
Entry
<
User
,
List
<
UserRole
>>
entry
:
userRolesMap
.
entrySet
())
{
User
user
=
entry
.
getKey
();
List
<
UserRole
>
roles
=
entry
.
getValue
();
for
(
UserRole
role
:
roles
)
{
String
projectId
=
role
.
getProjectId
();
Project
project
=
GlobalPojo
.
PROJECT_MAP
.
get
(
projectId
);
if
(
Objects
.
isNull
(
project
))
{
project
=
projectDao
.
findOneById
(
projectId
);
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"projectId"
,
projectId
);
jsonObject
.
put
(
"projectName"
,
Objects
.
isNull
(
project
)
?
"已删除的项目"
:
project
.
getProjectName
());
jsonObject
.
put
(
"id"
,
user
.
getId
());
jsonObject
.
put
(
"nickname"
,
user
.
getNickname
());
jsonObject
.
put
(
"username"
,
user
.
getUsername
());
jsonObject
.
put
(
"cTime"
,
user
.
getCTime
());
jsonObject
.
put
(
"phoneNumber"
,
user
.
getPhoneNumber
());
jsonObject
.
put
(
"submitter"
,
user
.
getSubmitter
());
jsonObject
.
put
(
"roleId"
,
role
.
getRoleId
());
jsonObject
.
put
(
"expiredTime"
,
role
.
getExpiredTime
());
jsonObject
.
put
(
"exportAmount"
,
role
.
getExportAmount
());
jsonObject
.
put
(
"key"
,
role
.
getKey
());
resList
.
add
(
jsonObject
);
}
}
return
PageVO
.
createPageVo
(
count
,
page
,
pageSize
,
resList
.
stream
().
skip
((
long
)
(
page
-
1
)
*
pageSize
).
limit
(
pageSize
).
collect
(
Collectors
.
toList
()));
}
@Override
public
ResponseResult
updateOneUserRoles
(
JSONObject
json
)
{
String
id
=
json
.
getString
(
"id"
);
String
nickname
=
json
.
getString
(
"nickname"
);
int
roleId
=
json
.
getIntValue
(
"roleId"
);
long
expiredTime
=
json
.
getLongValue
(
"expiredTime"
);
int
exportAmount
=
json
.
getIntValue
(
"exportAmount"
);
String
projectId
=
json
.
getString
(
"projectId"
);
String
key
=
json
.
getString
(
"key"
);
User
user
=
userDao
.
findOneById
(
id
);
List
<
UserRole
>
roles
=
user
.
getRoles
();
if
(
CollectionUtils
.
isNotEmpty
(
roles
)){
List
<
String
>
existProject
=
roles
.
stream
().
filter
(
r
->
!
Objects
.
equals
(
r
.
getKey
(),
key
)).
map
(
UserRole:
:
getProjectId
).
collect
(
Collectors
.
toList
());
if
(
existProject
.
contains
(
projectId
)){
return
ResponseResult
.
failure
(
"用户已拥有此项目的权限"
);
}
}
user
.
getRoles
().
stream
().
filter
(
userRoles
->
userRoles
.
getKey
().
equals
(
key
)).
findAny
().
ifPresent
(
userRole
->
{
// 更新原userRole
userRole
.
setRoleId
(
roleId
);
userRole
.
setProjectId
(
projectId
);
userRole
.
setKey
(
Tools
.
concat
(
projectId
,
roleId
));
// 权限用户以上则清空过期时间
if
(
roleId
<
RoleEnum
.
CUSTOMER
.
getState
())
{
userRole
.
setExpiredTime
(
null
);
}
else
{
OptionalLong
.
of
(
expiredTime
).
ifPresent
(
userRole:
:
setExpiredTime
);
}
OptionalInt
.
of
(
exportAmount
).
ifPresent
(
userRole:
:
setExportAmount
);
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
roles
));
});
Optional
.
of
(
nickname
).
ifPresent
(
nickName
->
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"nickname"
,
nickName
)));
return
ResponseResult
.
success
();
}
@Override
public
ResponseResult
getUserByNickNameOrPhone
(
String
nickName
,
String
phoneNumber
)
{
Query
query
=
new
Query
();
if
(
Objects
.
isNull
(
nickName
)
&&
Objects
.
isNull
(
phoneNumber
)){
return
ResponseResult
.
failure
(
"用户名和手机号为空"
);
}
if
(
Objects
.
nonNull
(
nickName
)){
query
.
addCriteria
(
Criteria
.
where
(
"nickname"
).
is
(
nickName
));
}
if
(
Objects
.
nonNull
(
phoneNumber
)){
query
.
addCriteria
(
Criteria
.
where
(
"phoneNumber"
).
is
(
Long
.
parseLong
(
phoneNumber
)));
}
query
.
addCriteria
(
Criteria
.
where
(
"superAdmin"
).
is
(
false
));
User
user
=
userDao
.
findOne
(
query
);
if
(
Objects
.
isNull
(
user
)){
return
ResponseResult
.
failure
(
"不存在此项目用户"
);
}
JSONObject
jsonObject
=
new
JSONObject
();
jsonObject
.
put
(
"id"
,
user
.
getId
());
jsonObject
.
put
(
"nickname"
,
user
.
getNickname
());
jsonObject
.
put
(
"phoneNumber"
,
user
.
getPhoneNumber
());
List
<
JSONObject
>
roles
=
user
.
getRoles
().
stream
().
map
(
role
->
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
"key"
,
role
.
getKey
());
json
.
put
(
"projectId"
,
role
.
getProjectId
());
json
.
put
(
"roleId"
,
role
.
getRoleId
());
return
json
;
}).
collect
(
Collectors
.
toList
());
jsonObject
.
put
(
"roles"
,
roles
);
return
ResponseResult
.
success
(
jsonObject
);
}
@Override
public
ResponseResult
updateBatchUserRoles
(
JSONObject
json
)
{
String
id
=
json
.
getString
(
"id"
);
List
<
UserRole
>
roles
=
json
.
getJSONArray
(
"roles"
).
toJavaList
(
UserRole
.
class
);
for
(
UserRole
role
:
roles
)
{
role
.
setExportAmount
(
1000
);
role
.
setKey
(
Tools
.
concat
(
role
.
getProjectId
(),
role
.
getRoleId
()));
role
.
setExpiredTime
(
null
);
}
userDao
.
updateOneByIdWithField
(
id
,
new
Update
().
set
(
"roles"
,
roles
));
return
ResponseResult
.
success
();
}
@Override
public
ResponseResult
deleteUserRole
(
String
id
,
String
key
)
{
User
user
=
userDao
.
findOneById
(
id
);
List
<
UserRole
>
roles
=
user
.
getRoles
().
stream
().
filter
(
userRole
->
!
userRole
.
getKey
().
equals
(
key
)).
collect
(
Collectors
.
toList
());
Update
update
=
new
Update
();
update
.
set
(
"roles"
,
roles
);
update
.
set
(
"submitter"
,
UserThreadLocal
.
getNickname
());
userDao
.
updateOneByIdWithField
(
id
,
update
);
return
ResponseResult
.
success
();
}
@Override
public
Map
<
String
,
Object
>
getLoginInfo
()
{
public
Map
<
String
,
Object
>
getLoginInfo
()
{
// String userId = UserThreadLocal.getUserId();
// String userId = UserThreadLocal.getUserId();
// String projectId = UserThreadLocal.getProjectId();
// String projectId = UserThreadLocal.getProjectId();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment