Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
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
zengtianlai3
ioc_sixiang_license
Commits
5cbf0593
Commit
5cbf0593
authored
Feb 01, 2023
by
ma
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
完善分配权限接口
parent
8f386c27
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
58 additions
and
5 deletions
+58
-5
UserController.java
...n/java/iot/sixiang/license/controller/UserController.java
+1
-1
UserPermissionMapper.java
...java/iot/sixiang/license/mapper/UserPermissionMapper.java
+2
-0
UserPermissionServiceImpl.java
...xiang/license/service/impl/UserPermissionServiceImpl.java
+17
-4
CommonUtil.java
...se/src/main/java/iot/sixiang/license/util/CommonUtil.java
+32
-0
UserPermissionMapper.xml
license/src/main/resources/mapper/UserPermissionMapper.xml
+6
-0
No files found.
license/src/main/java/iot/sixiang/license/controller/UserController.java
View file @
5cbf0593
...
@@ -301,7 +301,7 @@ public class UserController {
...
@@ -301,7 +301,7 @@ public class UserController {
}
}
/**
/**
*
todo 待完善
为用户批量分配权限
* 为用户批量分配权限
*
*
* @param assignUserPermissionDTO
* @param assignUserPermissionDTO
* @return
* @return
...
...
license/src/main/java/iot/sixiang/license/mapper/UserPermissionMapper.java
View file @
5cbf0593
...
@@ -17,4 +17,6 @@ public interface UserPermissionMapper extends BaseMapper<UserPermission> {
...
@@ -17,4 +17,6 @@ public interface UserPermissionMapper extends BaseMapper<UserPermission> {
int
saveBatch
(
List
<
Integer
>
userPermissions
,
int
userId
);
int
saveBatch
(
List
<
Integer
>
userPermissions
,
int
userId
);
void
deleteUserPermission
(
int
parseInt
);
void
deleteUserPermission
(
int
parseInt
);
int
delBatch
(
List
<
Integer
>
permissionDelList
,
Integer
userId
);
}
}
license/src/main/java/iot/sixiang/license/service/impl/UserPermissionServiceImpl.java
View file @
5cbf0593
package
iot
.
sixiang
.
license
.
service
.
impl
;
package
iot
.
sixiang
.
license
.
service
.
impl
;
import
iot.sixiang.license.consts.ResultCode
;
import
iot.sixiang.license.consts.ResultCode
;
import
iot.sixiang.license.entity.Permission
;
import
iot.sixiang.license.entity.UserPermission
;
import
iot.sixiang.license.entity.UserPermission
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.handler.IotLicenseException
;
import
iot.sixiang.license.mapper.PermissionMapper
;
import
iot.sixiang.license.mapper.UserPermissionMapper
;
import
iot.sixiang.license.mapper.UserPermissionMapper
;
import
iot.sixiang.license.model.dto.AssignUserPermissionDTO
;
import
iot.sixiang.license.model.dto.AssignUserPermissionDTO
;
import
iot.sixiang.license.service.PermissionService
;
import
iot.sixiang.license.service.UserPermissionService
;
import
iot.sixiang.license.service.UserPermissionService
;
import
iot.sixiang.license.util.CommonUtil
;
import
org.springframework.stereotype.Service
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.Resource
;
import
javax.annotation.Resource
;
import
java.util.List
;
import
java.util.List
;
import
java.util.stream.Collectors
;
/**
/**
* Created by m33
* Created by m33
...
@@ -39,7 +38,21 @@ public class UserPermissionServiceImpl implements UserPermissionService {
...
@@ -39,7 +38,21 @@ public class UserPermissionServiceImpl implements UserPermissionService {
if
(
userPermissions
.
isEmpty
()
||
userId
<=
0
)
{
if
(
userPermissions
.
isEmpty
()
||
userId
<=
0
)
{
throw
new
IotLicenseException
(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
ResultCode
.
VALIDATE_FAILED
.
getMsg
());
throw
new
IotLicenseException
(
ResultCode
.
VALIDATE_FAILED
.
getCode
(),
ResultCode
.
VALIDATE_FAILED
.
getMsg
());
}
}
return
userPermissionMapper
.
saveBatch
(
userPermissions
,
userId
)
>
0
;
List
<
UserPermission
>
permissionById
=
userPermissionMapper
.
getPermissionById
(
userId
);
// 筛选出已有的权限
List
<
Integer
>
originPermissions
=
permissionById
.
stream
().
map
(
UserPermission:
:
getPermission
).
collect
(
Collectors
.
toList
());
// 新增权限处理,找出 userPermissions 中新增的权限并添加到用户权限表中
List
<
Integer
>
permissionAddList
=
CommonUtil
.
getDiffList
(
userPermissions
,
originPermissions
);
int
res
=
0
;
if
(!
permissionAddList
.
isEmpty
())
{
res
=
userPermissionMapper
.
saveBatch
(
permissionAddList
,
userId
);
}
// 删除权限处理,找出 originPermissions 中多出的权限并从用户权限表中删除
List
<
Integer
>
permissionDelList
=
CommonUtil
.
getDiffList
(
originPermissions
,
userPermissions
);
if
(!
permissionDelList
.
isEmpty
())
{
res
+=
userPermissionMapper
.
delBatch
(
permissionDelList
,
userId
);
}
return
res
>=
0
;
}
}
@Override
@Override
...
...
license/src/main/java/iot/sixiang/license/util/CommonUtil.java
View file @
5cbf0593
...
@@ -17,6 +17,7 @@ import java.text.SimpleDateFormat;
...
@@ -17,6 +17,7 @@ import java.text.SimpleDateFormat;
import
java.util.*
;
import
java.util.*
;
import
java.util.regex.Matcher
;
import
java.util.regex.Matcher
;
import
java.util.regex.Pattern
;
import
java.util.regex.Pattern
;
import
java.util.stream.Collectors
;
@Slf4j
@Slf4j
public
class
CommonUtil
{
public
class
CommonUtil
{
...
@@ -39,6 +40,7 @@ public class CommonUtil {
...
@@ -39,6 +40,7 @@ public class CommonUtil {
/**
/**
* date 转 字符串
* date 转 字符串
*
* @param date
* @param date
* @param pattern
* @param pattern
* @return
* @return
...
@@ -344,6 +346,13 @@ public class CommonUtil {
...
@@ -344,6 +346,13 @@ public class CommonUtil {
return
""
;
return
""
;
}
}
/**
* 检查是否有某个权限
*
* @param userPermissions
* @param permission
* @return
*/
public
static
boolean
checkPermission
(
List
<
UserPermission
>
userPermissions
,
int
permission
)
{
public
static
boolean
checkPermission
(
List
<
UserPermission
>
userPermissions
,
int
permission
)
{
boolean
res
=
false
;
boolean
res
=
false
;
for
(
UserPermission
userPermission
:
userPermissions
)
{
for
(
UserPermission
userPermission
:
userPermissions
)
{
...
@@ -354,4 +363,27 @@ public class CommonUtil {
...
@@ -354,4 +363,27 @@ public class CommonUtil {
}
}
return
res
;
return
res
;
}
}
/**
* 差集计算
*
* @param A 集合A
* @param B 集合B
* @return 筛选出【集合A中存在且集合B中不存在】的元素集合
*/
public
static
<
T
>
List
<
T
>
getDiffList
(
List
<
T
>
A
,
List
<
T
>
B
)
{
if
(
A
==
null
)
{
return
Collections
.
emptyList
();
}
if
(
B
==
null
)
{
return
A
;
}
return
A
.
stream
().
filter
(
a
->
{
if
(
a
==
null
)
{
return
false
;
}
return
B
.
stream
().
noneMatch
(
b
->
b
!=
null
&&
b
.
equals
(
a
));
}
).
collect
(
Collectors
.
toList
());
}
}
}
license/src/main/resources/mapper/UserPermissionMapper.xml
View file @
5cbf0593
...
@@ -10,6 +10,12 @@
...
@@ -10,6 +10,12 @@
<delete
id=
"deleteUserPermission"
>
<delete
id=
"deleteUserPermission"
>
delete from user_permission where user = #{userId}
delete from user_permission where user = #{userId}
</delete>
</delete>
<delete
id=
"delBatch"
>
delete from user_permission where user = #{userId} and permission in
<foreach
collection=
"permissionDelList"
open=
"("
separator=
","
close=
")"
item=
"permission"
>
#{permission}
</foreach>
</delete>
<select
id=
"getPermissionById"
resultType=
"iot.sixiang.license.entity.UserPermission"
>
<select
id=
"getPermissionById"
resultType=
"iot.sixiang.license.entity.UserPermission"
>
SELECT * FROM `user_permission` WHERE user = #{userId} and deleted = 0
SELECT * FROM `user_permission` WHERE user = #{userId} and deleted = 0
...
...
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