Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
0b048555
提交
0b048555
编写于
11月 02, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充实体属性值检查
上级
54a25bd2
变更
6
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
235 行增加
和
1 行删除
+235
-1
%DE%.java.ftl
...ava/%SYS_PKGPATH%/core/%MOD_PKGPATH%/domain/%DE%.java.ftl
+9
-0
%DE%ServiceImpl.java.ftl
.../core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
+37
-0
DEField.java.ftl
.../main/java/%SYS_PKGPATH%/util/annotation/DEField.java.ftl
+10
-0
DupCheckAspect.java.ftl
...in/java/%SYS_PKGPATH%/util/aspect/DupCheckAspect.java.ftl
+152
-0
ESAspect.java.ftl
...src/main/java/%SYS_PKGPATH%/util/aspect/ESAspect.java.ftl
+1
-1
DupCheck.java.ftl
.../src/main/java/%SYS_PKGPATH%/util/enums/DupCheck.java.ftl
+26
-0
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/domain/%DE%.java.ftl
浏览文件 @
0b048555
...
...
@@ -23,6 +23,7 @@ import ${pub.getPKGCodeName()}.util.annotation.DEField;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEPredefinedFieldType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEFieldDefaultValueType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
helper
.
DataObject
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DupCheck
;
import
java
.
io
.
Serializable
;
import
lombok
.*;
import
org
.
springframework
.
data
.
annotation
.
Transient
;
...
...
@@ -113,6 +114,14 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
<#
assign
defieldano
=
defieldano
+
",fieldType=
\"
DATETIME
\"
,format=
\"
yyyy-MM-dd HH:mm:ss
\"
"
>
</#
if
>
</#
if
>
<#
if
defield
.
getDupCheckMode
??
&&
defield
.
getDupCheckMode
()??
&&
defield
.
getDupCheckMode
()==
'ALL'
>
<#
if
defield
.
getDupCheckPSDEField
??
&&
defield
.
getDupCheckPSDEField
()??>
<#
assign
dupCheckField
=
srfcaseformat
(
defield
.
getDupCheckPSDEField
().
getCodeName
(),
'l_u2lC'
)
>
<#
assign
defieldano
=
defieldano
+
",dupCheck = DupCheck.ALL , dupCheckField=
\"
"
+
dupCheckField
+
"
\"
"
>
<#
else
>
<#
assign
defieldano
=
defieldano
+
",dupCheck = DupCheck.ALL"
>
</#
if
>
</#
if
>
</#
if
>
/**
*
${
defield
.
getLogicName
()}
...
...
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
浏览文件 @
0b048555
...
...
@@ -66,6 +66,7 @@ TARGET=PSDATAENTITY
<#
break
>
</#
list
>
</#
if
>
<#
assign
isDupCheck
=
isDupCheckEntity
(
de
)>
package
${
pub
.
getPKGCodeName
()}.
core
.${
item
.
getPSSystemModule
().
getCodeName
()?
lower_case
}.
service
.
impl
;
import
java
.
io
.
Serializable
;
...
...
@@ -962,6 +963,9 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
<#
comment
>
发布
es
服务对象
</#
comment
>
<@
esAnno
/>
<#
comment
>
重复值检查
-
searchContext
</#
comment
>
<@
outputSearchContext
/>
}
<#
comment
>
NOSQL
存储
</#
comment
>
...
...
@@ -1455,6 +1459,9 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
<#
comment
>
发布
es
服务对象
</#
comment
>
<@
esAnno
/>
<#
comment
>
重复值检查
-
SearchContext
</#
comment
>
<@
outputSearchContext
/>
}
...
...
@@ -1965,6 +1972,9 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
<#
comment
>
实体数据导入
</#
comment
>
<@
deImportData
/>
<#
comment
>
重复值检查
-
SearchContext
</#
comment
>
<@
outputSearchContext
/>
}
<#
comment
>
无存储
</#
comment
>
...
...
@@ -2955,4 +2965,31 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
</#
macro
>
<#
comment
>
输出
SearchContext
,用于属性重复值检查
</#
comment
>
<#
macro
outputSearchContext
>
<#
if
isDupCheck
>
/**
*
获取
searchContext
*
@
return
*/
public
${
de
.
codeName
}
SearchContext
getSearchContext
(){
return
new
${
de
.
codeName
}
SearchContext
();
}
</#
if
>
</#
macro
>
<#
comment
>
判断属性是否配置了重复值检查
</#
comment
>
<#
function
isDupCheckEntity
dataEntity
>
<#
assign
dupCheck
=
false
>
<#
if
dataEntity
.
getAllPSDEFields
()??>
<#
list
dataEntity
.
getAllPSDEFields
()
as
defield
>
<#
if
defield
.
getDupCheckMode
??
&&
defield
.
getDupCheckMode
()??
&&
defield
.
getDupCheckMode
()==
'ALL'
>
<#
assign
dupCheck
=
true
>
<#
break
>
</#
if
>
</#
list
>
</#
if
>
<#
return
dupCheck
>
</#
function
>
</#
if
>
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/annotation/DEField.java.ftl
浏览文件 @
0b048555
...
...
@@ -5,6 +5,7 @@ package ${pub.getPKGCodeName()}.util.annotation;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEFieldDefaultValueType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEPredefinedFieldType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DupCheck
;
import
java
.
lang
.
annotation
.
ElementType
;
import
java
.
lang
.
annotation
.
Retention
;
import
java
.
lang
.
annotation
.
RetentionPolicy
;
...
...
@@ -69,5 +70,14 @@ public @interface DEField
*
@
return
*/
String
format
()
default
""
;
/**
*
重复性检查
*
@
return
*/
DupCheck
dupCheck
()
default
DupCheck
.
NONE
;
/**
*
范围属性
*/
String
dupCheckField
()
default
""
;
}
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/DupCheckAspect.java.ftl
0 → 100644
浏览文件 @
0b048555
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
<#
assign
hasDupCheckEntity
=
false
>
<#
list
sys
.
getAllPSDataEntities
()
as
dataEntity
>
<#
assign
isDupCheck
=
isDupCheckEntity
(
dataEntity
)>
<#
if
isDupCheck
>
<#
assign
hasDupCheckEntity
=
true
>
<#
break
>
</#
if
>
</#
list
>
<#
if
hasDupCheckEntity
>
package
${
pub
.
getPKGCodeName
()}.
util
.
aspect
;
import
lombok
.
extern
.
slf4j
.
Slf4j
;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
DEField
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DupCheck
;
import
${
pub
.
getPKGCodeName
()}.
util
.
errors
.
BadRequestAlertException
;
import
${
pub
.
getPKGCodeName
()}.
util
.
filter
.
QueryFilter
;
import
${
pub
.
getPKGCodeName
()}.
util
.
filter
.
SearchContextBase
;
import
${
pub
.
getPKGCodeName
()}.
util
.
helper
.
DEFieldCacheMap
;
import
org
.
aspectj
.
lang
.
JoinPoint
;
import
org
.
aspectj
.
lang
.
annotation
.
AfterReturning
;
import
org
.
aspectj
.
lang
.
annotation
.
Aspect
;
import
org
.
springframework
.
data
.
domain
.
Page
;
import
org
.
springframework
.
expression
.
EvaluationContext
;
import
org
.
springframework
.
expression
.
Expression
;
import
org
.
springframework
.
expression
.
ExpressionParser
;
import
org
.
springframework
.
expression
.
spel
.
standard
.
SpelExpressionParser
;
import
org
.
springframework
.
expression
.
spel
.
support
.
StandardEvaluationContext
;
import
org
.
springframework
.
stereotype
.
Component
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
util
.
Map
;
@
Aspect
@
Component
@
Slf4j
public
class
DupCheckAspect
{
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
<#
list
sys
.
getAllPSDataEntities
()
as
dataEntity
>
<#
assign
isDupCheck
=
isDupCheckEntity
(
dataEntity
)>
<#
assign
hasDefaultDS
=
hasDefaultDS
(
dataEntity
)>
<#
if
isDupCheck
&&
hasDefaultDS
>
/**
*
实体
[${
dataEntity
.
codeName
}]
*
*
@
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.*.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.*.remove*(..))"
)
public
void
check
${
dataEntity
.
codeName
?
lower_case
?
cap_first
}(
JoinPoint
point
)
{
check
(
point
,
"search${dataEntity.getDefaultPSDEDataSet().codeName}"
);
}
</#
if
>
</#
list
>
/**
*
实体属性重复值检查
*
@
param
point
切点
*
@
param
defaultDS
实体默认数据集名称
*/
private
void
check
(
JoinPoint
point
,
String
defaultDS
)
{
Object
[]
args
=
point
.
getArgs
();
if
(
args
.
length
>
0
)
{
Object
entity
=
args
[
0
];
Object
service
=
point
.
getTarget
();
Map
<
String
,
DEField
>
deFields
=
DEFieldCacheMap
.
getDEFields
(
entity
.
getClass
());
for
(
Map
.
Entry
<
String
,
DEField
>
deField
:
deFields
.
entrySet
())
{
String
fieldName
=
deField
.
getKey
();
try
{
DEField
fieldAnnotation
=
deField
.
getValue
();
DupCheck
dupCheck
=
fieldAnnotation
.
dupCheck
();
String
dupCheckField
=
fieldAnnotation
.
dupCheckField
();
if
(
dupCheck
==
DupCheck
.
ALL
)
{
Object
newValue
=
getDEFieldValue
(
entity
,
fieldName
);
//
获取
searchContext
EvaluationContext
searchContextCtx
=
new
StandardEvaluationContext
();
searchContextCtx
.
setVariable
(
"service"
,
service
);
Expression
searchContextExp
=
parser
.
parseExpression
(
"#service.getSearchContext()"
);
SearchContextBase
searchContext
=
searchContextExp
.
getValue
(
searchContextCtx
,
SearchContextBase
.
class
);
//
设置检查属性值
QueryFilter
filter
=
new
QueryFilter
();
filter
.
eq
(
DEFieldCacheMap
.
getFieldColumnName
(
entity
.
getClass
(),
fieldName
),
newValue
);
searchContext
.
setFilter
(
filter
);
//
设定重复值检查范围
if
(
!StringUtils.isEmpty(dupCheckField)){
Object
dupFieldValue
=
getDEFieldValue
(
entity
,
dupCheckField
);
filter
.
eq
(
DEFieldCacheMap
.
getFieldColumnName
(
entity
.
getClass
(),
dupCheckField
),
dupFieldValue
);
}
//
使用当前值到数据库中进行查询,判断是否重复
EvaluationContext
oldValueMappingCtx
=
new
StandardEvaluationContext
();
oldValueMappingCtx
.
setVariable
(
"service"
,
service
);
oldValueMappingCtx
.
setVariable
(
"searchContext"
,
searchContext
);
Expression
oldValueMappingExp
=
parser
.
parseExpression
(
String
.
format
(
"#service.%s(#searchContext)"
,
defaultDS
));
Page
oldData
=
oldValueMappingExp
.
getValue
(
oldValueMappingCtx
,
Page
.
class
);
if
(
!ObjectUtils.isEmpty(oldData) && !ObjectUtils.isEmpty(oldData.getContent()) && oldData.getContent().size() > 1) {
throw
new
BadRequestAlertException
(
String
.
format
(
"属性[%s]已存在[%s]值!"
,
fieldName
,
newValue
),
"ValueRuleAspect"
,
"repeatCheck"
);
}
}
}
catch
(
Exception
e
)
{
throw
new
BadRequestAlertException
(
String
.
format
(
"实体属性[%s]重复值检查失败,%s"
,
fieldName
,
e
),
"ValueRuleAspect"
,
"repeatCheck"
);
}
}
}
}
/**
*
获取实体属性值
*
@
param
entity
*
@
param
fieldName
*
@
return
*/
private
Object
getDEFieldValue
(
Object
entity
,
String
fieldName
){
EvaluationContext
exMappingCtx
=
new
StandardEvaluationContext
();
exMappingCtx
.
setVariable
(
"entity"
,
entity
);
Expression
esMappingExp
=
parser
.
parseExpression
(
String
.
format
(
"#entity.get(
\"
%s
\"
)"
,
fieldName
));
return
esMappingExp
.
getValue
(
exMappingCtx
);
}
}
</#
if
>
<#
comment
>
判断属性是否配置了重复值检查
</#
comment
>
<#
function
isDupCheckEntity
dataEntity
>
<#
assign
dupCheck
=
false
>
<#
if
dataEntity
.
getAllPSDEFields
()??>
<#
list
dataEntity
.
getAllPSDEFields
()
as
defield
>
<#
if
defield
.
getDupCheckMode
??
&&
defield
.
getDupCheckMode
()??
&&
defield
.
getDupCheckMode
()==
'ALL'
>
<#
assign
dupCheck
=
true
>
<#
break
>
</#
if
>
</#
list
>
</#
if
>
<#
return
dupCheck
>
</#
function
>
<#
comment
>
判断实体中是否配置了默认数据集
</#
comment
>
<#
function
hasDefaultDS
dataEntity
>
<#
assign
defaultDS
=
false
>
<#
if
dataEntity
.
getDefaultPSDEDataSet
??
&&
dataEntity
.
getDefaultPSDEDataSet
()??
&&
dataEntity
.
getDefaultPSDEDataSet
().
getPSDEDataQueries
()??>
<#
list
dataEntity
.
getDefaultPSDEDataSet
().
getPSDEDataQueries
()
as
dq
>
<#
assign
defaultDS
=
true
>
<#
break
>
</#
list
>
</#
if
>
<#
return
defaultDS
>
</#
function
>
\ No newline at end of file
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/ESAspect.java.ftl
浏览文件 @
0b048555
<#
ibiztemplate
>
TARGET
=
PS
DATAENTITY
TARGET
=
PS
SYSTEM
</#
ibiztemplate
>
<#
assign
hasESEntity
=
false
>
<#
list
sys
.
getAllPSDataEntities
()
as
dataEntity
>
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/enums/DupCheck.java.ftl
0 → 100644
浏览文件 @
0b048555
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
util
.
enums
;
/**
*
属性重复值检查
*/
public
enum
DupCheck
{
/**
*
不检查
*/
NONE
,
/**
*
全部检查
*/
ALL
,
/**
*
非空检查
*/
NOTNULL
,
/**
*
指定范围检查
*/
RANGE
,
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录