Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzuaa
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzuaa
提交
0b38bfaf
提交
0b38bfaf
编写于
7月 01, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
扩展代码迁移
上级
3b054bf3
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
99 行增加
和
142 行删除
+99
-142
SysPSSystemServiceEx.java
...ibizlab/core/extensions.service/SysPSSystemServiceEx.java
+0
-136
SysPSSystemExService.java
...ibizlab/core/extensions/service/SysPSSystemExService.java
+99
-6
未找到文件。
ibzuaa-core/src/main/java/cn/ibizlab/core/extensions.service/SysPSSystemServiceEx.java
已删除
100644 → 0
浏览文件 @
3b054bf3
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.uaa.domain.SysApp
;
import
cn.ibizlab.core.uaa.domain.SysPermission
;
import
cn.ibizlab.core.uaa.extensions.domain.PermissionType
;
import
cn.ibizlab.core.uaa.service.ISysPermissionService
;
import
cn.ibizlab.core.uaa.service.impl.SysPSSystemServiceImpl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
cn.ibizlab.core.uaa.domain.SysPSSystem
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
/**
* 实体[系统] 自定义服务对象
*/
@Slf4j
@Primary
@Service
(
"SysPSSystemServiceEx"
)
public
class
SysPSSystemServiceEx
extends
SysPSSystemServiceImpl
{
@Override
protected
Class
currentModelClass
()
{
return
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
().
getSuperclass
(),
1
);
}
@Autowired
@Lazy
private
ISysPermissionService
sysPermissionService
;
@Override
public
boolean
create
(
SysPSSystem
et
)
{
prepareApps
(
et
);
if
(!
super
.
create
(
et
))
return
false
;
syncPermission
(
et
);
return
true
;
}
@Override
public
boolean
update
(
SysPSSystem
et
)
{
Object
ignoreSyncPermission
=
et
.
get
(
"ignoreSyncPermission"
);
prepareApps
(
et
);
if
(!
super
.
update
(
et
))
return
false
;
if
(
ignoreSyncPermission
==
null
||
ignoreSyncPermission
.
equals
(
false
))
syncPermission
(
et
);
return
true
;
}
/**
* 自定义行为[PrepareApps]用户扩展
* @param system
* @return
*/
@Override
@Transactional
public
SysPSSystem
prepareApps
(
SysPSSystem
system
)
{
if
(
StringUtils
.
isEmpty
(
system
.
getPssystemid
())
||
system
.
getSysstructure
()
==
null
)
return
system
;
Map
<
String
,
SysApp
>
oldApps
=
new
HashMap
<>();
List
<
SysApp
>
newList
=
new
ArrayList
<>();
SysPSSystem
old
=
this
.
getById
(
system
.
getPssystemid
());
if
(
old
!=
null
&&
old
.
getApps
()!=
null
)
old
.
getApps
().
forEach
(
app
->
oldApps
.
put
(
app
.
getId
(),
app
));
system
.
getSysstructure
().
getSysApps
(
true
).
forEach
(
appNode
->
{
if
(
oldApps
.
containsKey
(
appNode
.
getId
()))
newList
.
add
(
oldApps
.
get
(
appNode
.
getId
()));
else
{
appNode
.
setVisabled
(
1
);
newList
.
add
(
appNode
);
}
});
if
(
old
!=
null
&&
old
.
getApps
()!=
null
)
old
.
getApps
().
forEach
(
app
->{
if
(
"THIRD-PARTY"
.
equalsIgnoreCase
(
app
.
getGroup
()))
newList
.
add
(
app
);
});
system
.
setApps
(
newList
);
return
system
;
}
private
Object
lock
=
new
Object
();
/**
* 自定义行为[SyncPermission]用户扩展
* @param system
* @return
*/
@Override
@Transactional
public
SysPSSystem
syncPermission
(
SysPSSystem
system
)
{
if
(
StringUtils
.
isEmpty
(
system
.
getPssystemid
())||
system
.
getSysstructure
()==
null
)
return
system
;
Object
ignoreSyncPermission
=
system
.
get
(
"ignoreSyncPermission"
);
if
(
ignoreSyncPermission
!=
null
&&
ignoreSyncPermission
.
equals
(
true
))
return
system
;
Map
<
String
,
Integer
>
delPermission
=
new
HashMap
<>();
sysPermissionService
.
list
(
new
QueryWrapper
<
SysPermission
>().
select
(
"sys_permissionid"
).
eq
(
"pssystemid"
,
system
.
getPssystemid
())).
forEach
(
sysPermission
->
delPermission
.
put
(
sysPermission
.
getPermissionid
(),
1
));
Set
<
SysPermission
>
list
=
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
OPPRIV
);
list
.
addAll
(
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
APPMENU
));
list
.
addAll
(
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
UNIRES
));
Set
<
String
>
newIds
=
new
HashSet
<>();
list
.
forEach
(
sysPermission
->
{
delPermission
.
remove
(
sysPermission
.
getPermissionid
());
newIds
.
add
(
sysPermission
.
getPermissionid
());
});
//移除无效资源
if
(
delPermission
.
size
()>
0
)
sysPermissionService
.
removeBatch
(
delPermission
.
keySet
());
//将当前系统本次资源enable设为1以避免enable=0时,导致saveOrUpdate无法检测到主键存在,最终插入数据导致主键重复
if
(
newIds
.
size
()>
0
)
sysPermissionService
.
execute
(
String
.
format
(
"update ibzpermission set enable = 1 where sys_permissionid in (%s)"
,
getIds
(
newIds
)),
null
);
//存储或更新资源saveOrUpdate
if
(
list
.
size
()>
0
)
sysPermissionService
.
saveBatch
(
list
);
return
system
;
}
private
String
getIds
(
Set
<
String
>
newIds
)
{
String
[]
strIdArr
=
newIds
.
toArray
(
new
String
[
newIds
.
size
()]);
return
"'"
+
String
.
join
(
"','"
,
strIdArr
)
+
"'"
;
}
}
ibzuaa-core/src/main/java/cn/ibizlab/core/extensions/service/SysPSSystemExService.java
浏览文件 @
0b38bfaf
package
cn
.
ibizlab
.
core
.
extensions
.
service
;
import
cn.ibizlab.core.uaa.domain.SysApp
;
import
cn.ibizlab.core.uaa.domain.SysPermission
;
import
cn.ibizlab.core.uaa.extensions.domain.PermissionType
;
import
cn.ibizlab.core.uaa.service.ISysPermissionService
;
import
cn.ibizlab.core.uaa.service.impl.SysPSSystemServiceImpl
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
lombok.extern.slf4j.Slf4j
;
import
cn.ibizlab.core.uaa.domain.SysPSSystem
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.stereotype.Service
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.util.StringUtils
;
import
java.util.*
;
/**
...
...
@@ -21,25 +30,109 @@ public class SysPSSystemExService extends SysPSSystemServiceImpl {
return
com
.
baomidou
.
mybatisplus
.
core
.
toolkit
.
ReflectionKit
.
getSuperClassGenericType
(
this
.
getClass
().
getSuperclass
(),
1
);
}
@Autowired
@Lazy
private
ISysPermissionService
sysPermissionService
;
@Override
public
boolean
create
(
SysPSSystem
et
)
{
prepareApps
(
et
);
if
(!
super
.
create
(
et
))
return
false
;
syncPermission
(
et
);
return
true
;
}
@Override
public
boolean
update
(
SysPSSystem
et
)
{
Object
ignoreSyncPermission
=
et
.
get
(
"ignoreSyncPermission"
);
prepareApps
(
et
);
if
(!
super
.
update
(
et
))
return
false
;
if
(
ignoreSyncPermission
==
null
||
ignoreSyncPermission
.
equals
(
false
))
syncPermission
(
et
);
return
true
;
}
/**
* 自定义行为[PrepareApps]用户扩展
* @param
et
* @param
system
* @return
*/
@Override
@Transactional
public
SysPSSystem
prepareApps
(
SysPSSystem
et
)
{
return
super
.
prepareApps
(
et
);
public
SysPSSystem
prepareApps
(
SysPSSystem
system
)
{
if
(
StringUtils
.
isEmpty
(
system
.
getPssystemid
())
||
system
.
getSysstructure
()
==
null
)
return
system
;
Map
<
String
,
SysApp
>
oldApps
=
new
HashMap
<>();
List
<
SysApp
>
newList
=
new
ArrayList
<>();
SysPSSystem
old
=
this
.
getById
(
system
.
getPssystemid
());
if
(
old
!=
null
&&
old
.
getApps
()!=
null
)
old
.
getApps
().
forEach
(
app
->
oldApps
.
put
(
app
.
getId
(),
app
));
system
.
getSysstructure
().
getSysApps
(
true
).
forEach
(
appNode
->
{
if
(
oldApps
.
containsKey
(
appNode
.
getId
()))
newList
.
add
(
oldApps
.
get
(
appNode
.
getId
()));
else
{
appNode
.
setVisabled
(
1
);
newList
.
add
(
appNode
);
}
});
if
(
old
!=
null
&&
old
.
getApps
()!=
null
)
old
.
getApps
().
forEach
(
app
->{
if
(
"THIRD-PARTY"
.
equalsIgnoreCase
(
app
.
getGroup
()))
newList
.
add
(
app
);
});
system
.
setApps
(
newList
);
return
system
;
}
private
Object
lock
=
new
Object
();
/**
* 自定义行为[SyncPermission]用户扩展
* @param
et
* @param
system
* @return
*/
@Override
@Transactional
public
SysPSSystem
syncPermission
(
SysPSSystem
et
)
{
return
super
.
syncPermission
(
et
);
public
SysPSSystem
syncPermission
(
SysPSSystem
system
)
{
if
(
StringUtils
.
isEmpty
(
system
.
getPssystemid
())||
system
.
getSysstructure
()==
null
)
return
system
;
Object
ignoreSyncPermission
=
system
.
get
(
"ignoreSyncPermission"
);
if
(
ignoreSyncPermission
!=
null
&&
ignoreSyncPermission
.
equals
(
true
))
return
system
;
Map
<
String
,
Integer
>
delPermission
=
new
HashMap
<>();
sysPermissionService
.
list
(
new
QueryWrapper
<
SysPermission
>().
select
(
"sys_permissionid"
).
eq
(
"pssystemid"
,
system
.
getPssystemid
())).
forEach
(
sysPermission
->
delPermission
.
put
(
sysPermission
.
getPermissionid
(),
1
));
Set
<
SysPermission
>
list
=
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
OPPRIV
);
list
.
addAll
(
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
APPMENU
));
list
.
addAll
(
system
.
getSysstructure
().
getSysPermissions
(
PermissionType
.
UNIRES
));
Set
<
String
>
newIds
=
new
HashSet
<>();
list
.
forEach
(
sysPermission
->
{
delPermission
.
remove
(
sysPermission
.
getPermissionid
());
newIds
.
add
(
sysPermission
.
getPermissionid
());
});
//移除无效资源
if
(
delPermission
.
size
()>
0
)
sysPermissionService
.
removeBatch
(
delPermission
.
keySet
());
//将当前系统本次资源enable设为1以避免enable=0时,导致saveOrUpdate无法检测到主键存在,最终插入数据导致主键重复
if
(
newIds
.
size
()>
0
)
sysPermissionService
.
execute
(
String
.
format
(
"update ibzpermission set enable = 1 where sys_permissionid in (%s)"
,
getIds
(
newIds
)),
null
);
//存储或更新资源saveOrUpdate
if
(
list
.
size
()>
0
)
sysPermissionService
.
saveBatch
(
list
);
return
system
;
}
private
String
getIds
(
Set
<
String
>
newIds
)
{
String
[]
strIdArr
=
newIds
.
toArray
(
new
String
[
newIds
.
size
()]);
return
"'"
+
String
.
join
(
"','"
,
strIdArr
)
+
"'"
;
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录