Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
3ee5c2c7
提交
3ee5c2c7
编写于
10月 14, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
支持es,修复相关bug
上级
9fcd6ac8
变更
5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
69 行增加
和
46 行删除
+69
-46
%DE%.java.ftl
.../src/main/java/%SYS_PKGPATH%/core/es/domain/%DE%.java.ftl
+1
-1
%DE%ESServiceImpl.java.ftl
..._PKGPATH%/core/es/service/impl/%DE%ESServiceImpl.java.ftl
+2
-2
%ITEM%Resource.java.ftl
...YS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
+2
-2
AuditAspect.java.ftl
.../main/java/%SYS_PKGPATH%/util/aspect/AuditAspect.java.ftl
+44
-33
ESAspect.java.ftl
...src/main/java/%SYS_PKGPATH%/util/aspect/ESAspect.java.ftl
+20
-8
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/es/domain/%DE%.java.ftl
浏览文件 @
3ee5c2c7
...
...
@@ -14,7 +14,7 @@ import java.sql.Timestamp;
import
lombok
.
Data
;
@
Data
@
Document
(
indexName
=
"${sys.codeName
}"
,
type
=
"${item.codeNam
e}"
,
shards
=
5
,
replicas
=
1
)
@
Document
(
indexName
=
"${sys.codeName
?lower_case}"
,
type
=
"${item.codeName?lower_cas
e}"
,
shards
=
5
,
replicas
=
1
)
public
class
${
item
.
codeName
}
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
...
...
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/es/service/impl/%DE%ESServiceImpl.java.ftl
浏览文件 @
3ee5c2c7
...
...
@@ -16,13 +16,13 @@ import org.springframework.data.domain.Page;
import
org
.
springframework
.
data
.
domain
.
PageImpl
;
import
java
.
util
.
List
;
import
java
.
util
.
Optional
;
import
lombok
.
extern
.
slf4j
.
Slf4j
;
import
org
.
springframework
.
stereotype
.
Service
;
import
java
.
util
.
Collection
;
/**
*
实体
[${
item
.
getLogicName
()}]
服务对象接口实现
*/
@
S
lf4j
@
S
ervice
public
class
${
item
.
getCodeName
()}
ESServiceImpl
implements
I
${
de
.
getCodeName
()}
ESService
{
@
Autowired
...
...
SLN/%PUBPRJ%-provider/%PUBPRJ%-provider-%SYSAPI_PKGPATH%/src/main/java/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
浏览文件 @
3ee5c2c7
...
...
@@ -317,7 +317,7 @@ public class ${itemCodeName}Resource {
<@
DataQuerySecurityAnnotation
deds
/>
@
ApiOperation
(
value
=
"获取${deds.getLogicName()}"
,
tags
=
{
"${deLogicName}"
}
,
notes
=
"获取${deds.getLogicName()}"
)
@
RequestMapping
(
method
=
RequestMethod
.${
reqMtd
}
,
value
=
"${fullPath}/fetch<#if (deds.getName()=='DEFAULT')>${deds.getCodeName()?lower_case}<#else>${deds.getCodeName()?lower_case}</#if>/es"
)
public
ResponseEntity
<
List
<${
itemCodeName
}
DTO
>>
ES
Fetch
<#
if
(
deds
.
getName
()==
'DEFAULT'
)>${
deds
.
getCodeName
()}<#
else
>${
deds
.
getCodeName
()}</#
if
>(${
deCodeName
}
SearchContext
context
)
{
public
ResponseEntity
<
List
<${
itemCodeName
}
DTO
>>
es
Fetch
<#
if
(
deds
.
getName
()==
'DEFAULT'
)>${
deds
.
getCodeName
()}<#
else
>${
deds
.
getCodeName
()}</#
if
>(${
deCodeName
}
SearchContext
context
)
{
Page
<${
pub
.
getPKGCodeName
()}.
core
.
es
.
domain
.${
item
.
codeName
}>
domains
=
esService
.
search
${
deds
.
getCodeName
()}(
context
)
;
List
<${
itemCodeName
}
DTO
>
list
=
${
itemCodeNameLC
}
Mapping
.
toDto
(
esMapping
.
toDomain
(
domains
.
getContent
()));
return
ResponseEntity
.
status
(${
statusCode
})
...
...
@@ -345,7 +345,7 @@ public class ${itemCodeName}Resource {
<@
SecurityAnnotation
deaction
/>
@
ApiOperation
(
value
=
"获取${deLogicName}"
,
tags
=
{
"${deLogicName}"
},
notes
=
"获取${deLogicName}"
)
@
RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"${fullPath}/{${itemCodeNameLC + keyCNLC}}/es"
)
public
ResponseEntity
<${
itemCodeName
}
DTO
>
ES
Get
(${
idParams
})
{
public
ResponseEntity
<${
itemCodeName
}
DTO
>
es
Get
(${
idParams
})
{
${
pub
.
getPKGCodeName
()}.
core
.
es
.
domain
.${
item
.
codeName
}
domain
=
esService
.
get
(${
itemCodeNameLC
+
keyCNLC
});
${
itemCodeName
}
DTO
dto
=
${
itemCodeNameLC
}
Mapping
.
toDto
(
esMapping
.
toDomain
(
domain
));
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
dto
);
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/AuditAspect.java.ftl
浏览文件 @
3ee5c2c7
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
<#
assign
hasESEntity
=
false
>
<#
list
sys
.
getAllPSDataEntities
()
as
dataEntity
>
<#
if
dataEntity
.
getUserTag
()??
&&
dataEntity
.
getUserTag
()==
'elasticsearch'
>
<#
assign
hasESEntity
=
true
>
<#
break
>
</#
if
>
</#
list
>
package
${
pub
.
getPKGCodeName
()}.
util
.
aspect
;
import
lombok
.
SneakyThrows
;
...
...
@@ -44,7 +51,7 @@ public class AuditAspect
*
实体数据建立切面,在成功创建数据后将新增数据内容记录审计日志内(审计明细【
AuditInfo
】中只记录审计属性变化情况,审计属性在平台属性中配置)
*
@
param
point
*/
@
AfterReturning
(
value
=
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.create(..))"
)
@
AfterReturning
(
value
=
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.create(..))
<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..))</#if>
"
)
@
SneakyThrows
public
void
create
(
JoinPoint
point
){
HttpServletRequest
request
=
null
;
...
...
@@ -57,19 +64,20 @@ public class AuditAspect
return
;
Object
serviceParam
=
args
[
0
];
EntityBase
entity
=(
EntityBase
)
serviceParam
;//
创建数据
Map
<
String
,
Audit
>
auditFields
=
DEFieldCacheMap
.
getAuditFields
(
entity
.
getClass
());
if
(
auditFields
.
size
()==
0
)//
是否有审计属性
return
;
if
(
serviceParam
instanceof
EntityBase
){
EntityBase
entity
=(
EntityBase
)
serviceParam
;//
创建数据
Map
<
String
,
Audit
>
auditFields
=
DEFieldCacheMap
.
getAuditFields
(
entity
.
getClass
());
if
(
auditFields
.
size
()==
0
)//
是否有审计属性
return
;
String
idField
=
DEFieldCacheMap
.
getDEKeyField
(
entity
.
getClass
());
Object
idValue
=
""
;
if
(
!StringUtils.isEmpty(idField)){
idValue
=
entity
.
get
(
idField
);
String
idField
=
DEFieldCacheMap
.
getDEKeyField
(
entity
.
getClass
());
Object
idValue
=
""
;
if
(
!StringUtils.isEmpty(idField)){
idValue
=
entity
.
get
(
idField
);
}
//
记录审计日志
dataAuditService
.
createAudit
(
request
,
entity
,
idValue
,
auditFields
);
}
//
记录审计日志
dataAuditService
.
createAudit
(
request
,
entity
,
idValue
,
auditFields
);
return
;
}
/**
...
...
@@ -77,7 +85,7 @@ public class AuditAspect
*
使用环切【
@
Around
】获取到更新前后的实体数据并进行差异比较,并将差异内容记入审计日志内
*
@
param
point
*/
@
Around
(
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.update(..))"
)
@
Around
(
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.update(..))
<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..))</#if>
"
)
public
Object
update
(
ProceedingJoinPoint
point
)
throws
Throwable
{
HttpServletRequest
request
=
null
;
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
...
...
@@ -91,27 +99,30 @@ public class AuditAspect
return
point
.
proceed
();
Object
arg
=
args
[
0
];
EntityBase
entity
=
(
EntityBase
)
arg
;
Map
<
String
,
Audit
>
auditFields
=
DEFieldCacheMap
.
getAuditFields
(
entity
.
getClass
());
if
(
arg
instanceof
EntityBase
){
EntityBase
entity
=
(
EntityBase
)
arg
;
Map
<
String
,
Audit
>
auditFields
=
DEFieldCacheMap
.
getAuditFields
(
entity
.
getClass
());
//
是否有审计属性
if
(
auditFields
.
size
()==
0
)
return
point
.
proceed
();
String
idField
=
DEFieldCacheMap
.
getDEKeyField
(
entity
.
getClass
());
Object
idValue
=
""
;
if
(
!StringUtils.isEmpty(idField)){
idValue
=
entity
.
get
(
idField
);
}
if
(
ObjectUtils
.
isEmpty
(
idValue
))
return
point
.
proceed
();
//
是否有审计属性
if
(
auditFields
.
size
()==
0
)
return
point
.
proceed
();
String
idField
=
DEFieldCacheMap
.
getDEKeyField
(
entity
.
getClass
());
Object
idValue
=
""
;
if
(
!StringUtils.isEmpty(idField)){
idValue
=
entity
.
get
(
idField
);
}
if
(
ObjectUtils
.
isEmpty
(
idValue
))
return
point
.
proceed
();
//
获取更新前实体
EntityBase
beforeEntity
=
getEntity
(
serviceObj
,
idValue
);
//
执行更新操作
point
.
proceed
();
//
记录审计日志
dataAuditService
.
updateAudit
(
request
,
beforeEntity
,
serviceObj
,
idValue
,
auditFields
);
return
true
;
//
获取更新前实体
EntityBase
beforeEntity
=
getEntity
(
serviceObj
,
idValue
);
//
执行更新操作
point
.
proceed
();
//
记录审计日志
dataAuditService
.
updateAudit
(
request
,
beforeEntity
,
serviceObj
,
idValue
,
auditFields
);
return
true
;
}
return
point
.
proceed
();
}
/**
...
...
@@ -121,7 +132,7 @@ public class AuditAspect
*
@
return
*
@
throws
Throwable
*/
@
Around
(
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.remove(..))"
)
@
Around
(
"execution(* ${pub.getPKGCodeName()}.core.*.service.*.remove(..))
<#if hasESEntity>&& !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remove*(..))</#if>
"
)
public
Object
remove
(
ProceedingJoinPoint
point
)
throws
Throwable
{
HttpServletRequest
request
=
null
;
RequestAttributes
requestAttributes
=
RequestContextHolder
.
getRequestAttributes
();
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/ESAspect.java.ftl
浏览文件 @
3ee5c2c7
...
...
@@ -44,7 +44,7 @@ public class ESAspect
*
实体
[${
dataEntity
.
codeName
}]
es
切面
*
@
param
point
*/
@
AfterReturning
(
value
=
"(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..))
) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.sa
ve*(..))"
)
@
AfterReturning
(
value
=
"(execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.create*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.update*(..))||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.save*(..))
||execution(* ${pub.getPKGCodeName()}.core.*.service.*${dataEntity.codeName}*.remove*(..))) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.create*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.update*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.save*(..)) && !execution(* ${pub.getPKGCodeName()}.core.es.service.*.remo
ve*(..))"
)
@
Async
public
void
Sync
${
dataEntity
.
codeName
?
lower_case
?
cap_first
}(
JoinPoint
point
){
syncSaveESData
(
point
,
"${dataEntity.codeName}"
);
...
...
@@ -87,16 +87,28 @@ public class ESAspect
exDomainCtx
.
setVariable
(
"arg"
,
arg
);
Expression
esDomainExp
=
parser
.
parseExpression
(
"#mapping.toESDomain(#arg)"
);
arg
=
esDomainExp
.
getValue
(
exDomainCtx
);
EvaluationContext
esContext
=
new
StandardEvaluationContext
();
esContext
.
setVariable
(
"exService"
,
exService
);
esContext
.
setVariable
(
"arg"
,
arg
);
Expression
exExp
=
parser
.
parseExpression
(
String
.
format
(
"#exService.%s(#arg)"
,
action
));
exExp
.
getValue
(
esContext
);
executeESMethod
(
exService
,
action
,
arg
);
}
else
if
(
"remove"
.
equals
(
action
)
||
"removeBatch"
.
equals
(
action
)){
executeESMethod
(
exService
,
action
,
arg
);
}
}
catch
(
Exception
e
)
{
log
.
error
(
"
保存
[{}]实体全文检索数据失败,{}"
,
deName
,
e
);
log
.
error
(
"
同步
[{}]实体全文检索数据失败,{}"
,
deName
,
e
);
}
}
/**
*
执行
es
方法
*
@
param
exService
*
@
param
action
*
@
param
arg
*/
private
void
executeESMethod
(
Object
exService
,
Object
action
,
Object
arg
){
EvaluationContext
esContext
=
new
StandardEvaluationContext
();
esContext
.
setVariable
(
"exService"
,
exService
);
esContext
.
setVariable
(
"arg"
,
arg
);
Expression
exExp
=
parser
.
parseExpression
(
String
.
format
(
"#exService.%s(#arg)"
,
action
));
exExp
.
getValue
(
esContext
);
}
}
</#
if
>
\ No newline at end of file
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录