Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
5bd82f6a
提交
5bd82f6a
编写于
1月 29, 2021
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
区分本地与远程逻辑
上级
9ecc8dca
变更
1
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
160 行增加
和
133 行删除
+160
-133
DELogicAspect.java.ftl
...ain/java/%SYS_PKGPATH%/util/aspect/DELogicAspect.java.ftl
+160
-133
未找到文件。
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/DELogicAspect.java.ftl
浏览文件 @
5bd82f6a
...
...
@@ -2,6 +2,10 @@
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
<#
if
sys
.
getCodeName
()==
'Sample'
||
sys
.
getCodeName
()==
'EAM'
>
<#
assign
isDynaSys
=
false
>
<#
if
pub
.
isEnableDynaModel
()??
&&
pub
.
isEnableDynaModel
()==
true
>
<#
assign
isDynaSys
=
true
>
</#
if
>
package
${
pub
.
getPKGCodeName
()}.
util
.
aspect
;
import
lombok
.
SneakyThrows
;
...
...
@@ -62,66 +66,19 @@ import java.util.regex.Pattern;
@
Slf4j
public
class
DELogicAspect
{
public
enum
LogicMode
{
/**
*
本地
*/
LOCAL
(
"0"
,
"本地模式"
),
/**
*
远程
*/
REMOTE
(
"1"
,
"远程模式"
);
LogicMode
(
String
value
,
String
text
)
{
this
.
value
=
value
;
this
.
text
=
text
;
}
private
String
value
;
private
String
text
;
}
private
static
BpmnXMLConverter
bpmnXMLConverter
=
new
BpmnXMLConverter
();
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
private
ConcurrentMap
<
String
,
DELogic
>
deLogicMap
=
new
ConcurrentHashMap
<>();
private
final
String
DEFAULT_MODULE_PACKAGE
=
"[
\\
w+
\\
.]
\\
.core.(
\\
w+)
\\
.domain"
;
@
Value
(
"${r'${ibiz.dynamicMode:true}'}"
)
private
boolean
dynamicMode
;
private
static
Map
<
String
,
Object
>
validLogic
=
new
HashMap
<>();
<#
if
isDynaSys
>
@
Value
(
"${r'${ibiz.dynamic.path:/app/file/dynamicmodel/}'}"
)
private
String
dynamicPath
;
@
Value
(
"${r'$'}{ibiz.systemid:${sys.getCodeName()}}"
)
private
String
systemId
;
@
Value
(
"${r'$'}{ibiz.dynainstid:${sys.getCodeName()?lower_case}}"
)
private
String
dynamicId
;
private
static
Map
<
String
,
Object
>
validLogic
=
new
HashMap
<>();
/**
*
执行动态行为
*
@
param
point
*/
@
AfterReturning
(
value
=
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))"
)
public
void
dynamicCall
(
JoinPoint
point
)
{
Object
args
[]
=
point
.
getArgs
();
if
(
!ObjectUtils.isEmpty(args) || args.length == 3) {
Object
id
=
args
[
0
];
String
action
=
String
.
valueOf
(
args
[
1
]);
Object
entity
=
args
[
2
];
if
(
entity
instanceof
EntityBase
)
{
log
.
debug
(
"开始执行实体动态行为[{}:{}]"
,
entity
.
getClass
().
getSimpleName
(),
action
);
EvaluationContext
context
=
new
StandardEvaluationContext
();
context
.
setVariable
(
"service"
,
point
.
getTarget
());
context
.
setVariable
(
"action"
,
action
);
if
(
"remove"
.
equalsIgnoreCase
(
action
)
||
"get"
.
equalsIgnoreCase
(
action
))
{
context
.
setVariable
(
"args"
,
id
);
}
else
{
context
.
setVariable
(
"args"
,
entity
);
}
Expression
oldExp
=
parser
.
parseExpression
(
String
.
format
(
"#service.%s(#args)"
,
action
));
oldExp
.
getValue
(
context
);
log
.
debug
(
"实体动态行为[{}:{}]执行结束"
,
entity
.
getClass
().
getSimpleName
(),
action
);
}
}
}
</#
if
>
/**
*
执行实体行为附加逻辑、实体行为调用处理逻辑
...
...
@@ -157,29 +114,6 @@ public class DELogicAspect {
return
point
.
proceed
();
}
/**
*
获取实体
*
*
@
param
service
*
@
return
*
@
throws
Exception
*/
private
EntityBase
getEntity
(
Object
service
)
throws
Exception
{
Method
[]
methods
=
service
.
getClass
().
getDeclaredMethods
();
for
(
Method
method
:
methods
)
{
for
(
Class
cls
:
method
.
getParameterTypes
())
{
try
{
Object
arg
=
cls
.
newInstance
();
if
(
arg
instanceof
EntityBase
)
{
return
(
EntityBase
)
arg
;
}
}
catch
(
InstantiationException
e
)
{
}
}
}
throw
new
BadRequestAlertException
(
"获取实体信息失败"
,
"DELogicAspect"
,
"getEntity"
);
}
/**
*
前附加逻辑
*
...
...
@@ -188,14 +122,14 @@ public class DELogicAspect {
*/
private
void
executeBeforeLogic
(
EntityBase
entity
,
String
action
)
{
File
bpmnFile
;
if
(
dynamicMode
)
{
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
"before"
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
<#
if
isDynaSys
>
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
BEFORE
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
"before"
);
</#
if
>
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
BEFORE
);
if
(
bpmnFile
!= null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
LOCAL
);
}
...
...
@@ -209,14 +143,14 @@ public class DELogicAspect {
*/
private
void
executeAfterLogic
(
EntityBase
entity
,
String
action
)
{
File
bpmnFile
;
if
(
dynamicMode
)
{
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
"after"
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
<#
if
isDynaSys
>
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
AFTER
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
"after"
);
</#
if
>
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
AFTER
);
if
(
bpmnFile
!= null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
LOCAL
);
}
...
...
@@ -230,14 +164,14 @@ public class DELogicAspect {
*/
private
void
executeLogic
(
EntityBase
entity
,
String
action
)
{
File
bpmnFile
;
if
(
dynamicMode
)
{
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
"exec"
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
<#
if
isDynaSys
>
bpmnFile
=
getRemoteModel
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
EXEC
);
if
(
bpmnFile
.
exists
())
{
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
REMOTE
);
return
;
}
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
"exec"
);
</#
if
>
bpmnFile
=
getLocalModel
(
entity
.
getClass
().
getSimpleName
(),
action
,
LogicExecMode
.
EXEC
);
if
(
bpmnFile
!= null && bpmnFile.exists() && isValid(bpmnFile, entity, action)) {
executeLogic
(
bpmnFile
,
entity
,
action
,
LogicMode
.
LOCAL
);
}
...
...
@@ -369,10 +303,10 @@ public class DELogicAspect {
if
(
item
instanceof
CallActivity
)
{
CallActivity
subBpmn
=
(
CallActivity
)
item
;
String
bpmnFileName
=
subBpmn
.
getName
();
log
.
debug
(
"正在加载
********************BPMN:{}********************"
,
bpmnFileName
);
log
.
debug
(
"正在加载
BPMN{}"
,
bpmnFileName
);
File
subBpmnFile
=
getSubBpmn
(
getDEModule
(
entity
),
entity
.
getClass
().
getSimpleName
(),
bpmnFileName
,
logicMode
);
if
(
!subBpmnFile.exists())
{
log
.
debug
(
"BPMN:{},缺少文件:{} "
,
bpmnFileName
,
subBpmnFile
);
if
(
ObjectUtils
.
isEmpty
(
subBpmnFile
))
{
log
.
debug
(
"BPMN:{},缺少文件:{} "
,
bpmnFileName
,
subBpmnFile
);
}
DELogic
refLogic
=
getDELogic
(
subBpmnFile
,
entity
,
logicMode
);
if
(
refLogic
!= null) {
...
...
@@ -407,6 +341,29 @@ public class DELogicAspect {
return
logic
;
}
/**
*
获取实体
*
*
@
param
service
*
@
return
*
@
throws
Exception
*/
private
EntityBase
getEntity
(
Object
service
)
throws
Exception
{
Method
[]
methods
=
service
.
getClass
().
getDeclaredMethods
();
for
(
Method
method
:
methods
)
{
for
(
Class
cls
:
method
.
getParameterTypes
())
{
try
{
Object
arg
=
cls
.
newInstance
();
if
(
arg
instanceof
EntityBase
)
{
return
(
EntityBase
)
arg
;
}
}
catch
(
InstantiationException
e
)
{
}
}
}
throw
new
BadRequestAlertException
(
"获取实体信息失败"
,
"DELogicAspect"
,
"getEntity"
);
}
/**
*
获取
bpmn
md5
*
...
...
@@ -446,29 +403,31 @@ public class DELogicAspect {
*
*
@
param
entity
*
@
param
action
*
@
param
actionLogic
*
@
param
logicExecMode
*
@
return
*/
private
File
getLocalModel
(
String
entity
,
String
action
,
String
actionLogic
)
{
String
logicName
=
String
.
format
(
"%s.bpmn"
,
actionLogic
);
private
File
getLocalModel
(
String
entity
,
String
action
,
LogicExecMode
logicExecMode
)
{
String
logicName
=
String
.
format
(
"%s.bpmn"
,
logicExecMode
.
value
);
String
filePath
=
File
.
separator
+
"rules"
+
File
.
separator
+
entity
.
toLowerCase
()
+
File
.
separator
+
action
+
File
.
separator
+
logicName
;
URL
url
=
this
.
getClass
().
getResource
(
filePath
.
replace
(
"
\\
"
,
"/"
));
return
ObjectUtils
.
isEmpty
(
url
)
?
null
:
new
File
(
url
.
getPath
());
}
<#
if
isDynaSys
>
/**
*
远程逻辑
*
*
@
param
module
*
@
param
entity
*
@
param
action
*
@
param
actionLogic
*
@
param
logicExecMode
*
@
return
*/
private
File
getRemoteModel
(
String
module
,
String
entity
,
String
action
,
String
actionLogic
)
{
String
logicName
=
String
.
format
(
"psdeaction.json.%s.bpmn"
,
actionLogic
);
private
File
getRemoteModel
(
String
module
,
String
entity
,
String
action
,
LogicExecMode
logicExecMode
)
{
String
logicName
=
String
.
format
(
"psdeaction.json.%s.bpmn"
,
logicExecMode
.
value
);
return
new
File
(
dynamicPath
+
File
.
separator
+
(
systemId
+
File
.
separator
+
dynamicId
+
File
.
separator
+
"psmodules"
+
File
.
separator
+
module
+
File
.
separator
+
"psdataentities"
+
File
.
separator
+
entity
+
File
.
separator
+
"psdeactions"
+
File
.
separator
+
action
+
File
.
separator
+
logicName
).
toLowerCase
());
}
</#
if
>
/**
*
处理逻辑
bpmn
...
...
@@ -479,12 +438,18 @@ public class DELogicAspect {
*
@
return
*/
private
File
getSubBpmn
(
String
module
,
String
entity
,
String
logicName
,
LogicMode
logicMode
)
{
<#
if
isDynaSys
>
if
(
LogicMode
.
REMOTE
.
equals
(
logicMode
))
{
return
new
File
(
dynamicPath
+
File
.
separator
+
(
systemId
+
File
.
separator
+
dynamicId
+
File
.
separator
+
"psmodules"
+
File
.
separator
+
module
+
File
.
separator
+
"psdataentities"
+
File
.
separator
+
entity
+
File
.
separator
+
"psdelogics"
+
File
.
separator
+
logicName
+
File
.
separator
+
"psdelogic.json.bpmn"
).
toLowerCase
());
}
else
{
String
filePath
=
String
.
format
(
"/rules/%s"
,
logicName
);
return
ObjectUtils
.
isEmpty
(
this
.
getClass
().
getResource
(
filePath
))
?
null
:
new
File
(
this
.
getClass
().
getResource
(
filePath
).
getPath
());
}
<#
else
>
String
filePath
=
String
.
format
(
"/rules/%s"
,
logicName
);
return
ObjectUtils
.
isEmpty
(
this
.
getClass
().
getResource
(
filePath
))
?
null
:
new
File
(
this
.
getClass
().
getResource
(
filePath
).
getPath
());
</#
if
>
}
/**
...
...
@@ -494,11 +459,15 @@ public class DELogicAspect {
*
@
return
*/
private
File
getDrl
(
File
bpmn
)
{
<#
if
isDynaSys
>
if
(
bpmn
.
getPath
().
endsWith
(
"RuleFlow.bpmn"
))
{
return
new
File
(
bpmn
.
getPath
().
replace
(
"RuleFlow.bpmn"
,
"Rule.drl"
));
}
else
{
return
new
File
(
bpmn
.
getPath
().
replace
(
".bpmn"
,
".drl"
));
}
<#
else
>
return
new
File
(
bpmn
.
getPath
().
replace
(
"RuleFlow.bpmn"
,
"Rule.drl"
));
</#
if
>
}
/**
...
...
@@ -521,6 +490,37 @@ public class DELogicAspect {
return
strModule
;
}
<#
if
isDynaSys
>
/**
*
执行动态行为
*
*
@
param
point
*/
@
AfterReturning
(
value
=
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.dynamicCall(..))"
)
public
void
dynamicCall
(
JoinPoint
point
)
{
Object
args
[]
=
point
.
getArgs
();
if
(
!ObjectUtils.isEmpty(args) || args.length == 3) {
Object
id
=
args
[
0
];
String
action
=
String
.
valueOf
(
args
[
1
]);
Object
entity
=
args
[
2
];
if
(
entity
instanceof
EntityBase
)
{
log
.
debug
(
"开始执行实体动态行为[{}:{}]"
,
entity
.
getClass
().
getSimpleName
(),
action
);
EvaluationContext
context
=
new
StandardEvaluationContext
();
context
.
setVariable
(
"service"
,
point
.
getTarget
());
context
.
setVariable
(
"action"
,
action
);
if
(
"remove"
.
equalsIgnoreCase
(
action
)
||
"get"
.
equalsIgnoreCase
(
action
))
{
context
.
setVariable
(
"args"
,
id
);
}
else
{
context
.
setVariable
(
"args"
,
entity
);
}
Expression
oldExp
=
parser
.
parseExpression
(
String
.
format
(
"#service.%s(#args)"
,
action
));
oldExp
.
getValue
(
context
);
log
.
debug
(
"实体动态行为[{}:{}]执行结束"
,
entity
.
getClass
().
getSimpleName
(),
action
);
}
}
}
</#
if
>
/**
*
逻辑是否有效
*
...
...
@@ -539,36 +539,63 @@ public class DELogicAspect {
}
static
{
<#
if
sys
.
getAllPSDataEntities
()??>
<#
list
sys
.
getAllPSDataEntities
()
as
dataEntity
>
<#
if
dataEntity
.
getAllPSDEActions
()??>
<#
list
dataEntity
.
getAllPSDEActions
()
as
deaction
>
<#
comment
>
前附加逻辑
</#
comment
>
<#
if
deaction
.
getBeforePSDEActionLogics
()??>
<#
list
deaction
.
getBeforePSDEActionLogics
()
as
beforeLogic
>
<#
if
(
beforeLogic
.
isValid
()==
true
&&
beforeLogic
.
isInternalLogic
()
&&
beforeLogic
.
getPSDELogic
().
isEnableBackend
())
||
(
beforeLogic
.
getDstPSDE
()
!'')!='' && (beforeLogic.getDstPSDEAction()!'')!='' && beforeLogic.getDstPSDEAction().isEnableBackend() >
validLogic
.
put
(
"${(dataEntity.codeName+deaction.codeName)?lower_case}before.bpmn"
,
1
);
</#
if
>
</#
list
>
</#
if
>
<#
comment
>
后附加逻辑
</#
comment
>
<#
if
deaction
.
getAfterPSDEActionLogics
()??>
<#
list
deaction
.
getAfterPSDEActionLogics
()
as
afterLogic
>
<#
if
(
afterLogic
.
isValid
()==
true
&&
afterLogic
.
isInternalLogic
()
&&
afterLogic
.
getPSDELogic
().
isEnableBackend
())
||
(
afterLogic
.
getDstPSDE
()
!'')!='' && (afterLogic.getDstPSDEAction()!'')!='' && afterLogic.getDstPSDEAction().isEnableBackend() >
validLogic
.
put
(
"${(dataEntity.codeName+deaction.codeName)?lower_case}after.bpmn"
,
1
);
</#
if
>
</#
list
>
</#
if
>
<#
comment
>
行为调用逻辑
</#
comment
>
<#
if
deaction
.
getActionType
()
==
'DELOGIC'
&&
deaction
.
getPSDELogic
().
isEnableBackend
()>
validLogic
.
put
(
"${(dataEntity.codeName+deaction.codeName)?lower_case}exec.bpmn"
,
1
);
</#
if
>
</#
list
>
</#
if
>
</#
list
>
</#
if
>
validLogic
.
put
(
"bsentity2checkkeybefore.bpmn"
,
1
);
validLogic
.
put
(
"bsentity2checkkeyafter.bpmn"
,
1
);
validLogic
.
put
(
"citysyncmqdatabefore.bpmn"
,
1
);
validLogic
.
put
(
"citysyncmqdataafter.bpmn"
,
1
);
validLogic
.
put
(
"citysyncmqdataexec.bpmn"
,
1
);
validLogic
.
put
(
"humancreatebefore.bpmn"
,
1
);
validLogic
.
put
(
"humancustom3before.bpmn"
,
1
);
validLogic
.
put
(
"humancustom3after.bpmn"
,
1
);
validLogic
.
put
(
"humancustom3exec.bpmn"
,
1
);
validLogic
.
put
(
"humancustomdeleteexec.bpmn"
,
1
);
validLogic
.
put
(
"humangettaxamountexec.bpmn"
,
1
);
validLogic
.
put
(
"humanlogicexec.bpmn"
,
1
);
validLogic
.
put
(
"humansmileexec.bpmn"
,
1
);
validLogic
.
put
(
"humantaxamountexec.bpmn"
,
1
);
validLogic
.
put
(
"loginaccountsyncsysadminexec.bpmn"
,
1
);
}
public
enum
LogicMode
{
/**
*
本地
*/
LOCAL
(
"0"
,
"本地模式"
),
/**
*
远程
*/
REMOTE
(
"1"
,
"远程模式"
);
LogicMode
(
String
value
,
String
text
)
{
this
.
value
=
value
;
this
.
text
=
text
;
}
private
String
value
;
private
String
text
;
}
public
enum
LogicExecMode
{
/**
*
前附加逻辑
*/
BEFORE
(
"0"
,
"before"
),
/**
*
后附加逻辑
*/
AFTER
(
"1"
,
"after"
),
/**
*
*/
EXEC
(
"2"
,
"exec"
);
LogicExecMode
(
String
value
,
String
text
)
{
this
.
value
=
value
;
this
.
text
=
text
;
}
private
String
value
;
private
String
text
;
}
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录