Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
874d7ea6
提交
874d7ea6
编写于
11月 26, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
补充值规则异常信息
上级
98677386
变更
4
隐藏空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
92 行增加
和
20 行删除
+92
-20
%ITEM%DTO.java.ftl
...ava/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/dto/%ITEM%DTO.java.ftl
+4
-4
DTOBase.java.ftl
.../src/main/java/%SYS_PKGPATH%/util/domain/DTOBase.java.ftl
+43
-4
ValueRule.java.ftl
...rc/main/java/%SYS_PKGPATH%/util/domain/ValueRule.java.ftl
+24
-0
ValueRuleValidator.java.ftl
...va/%SYS_PKGPATH%/util/service/ValueRuleValidator.java.ftl
+21
-12
未找到文件。
SLN/%PUBPRJ%-provider/%PUBPRJ%-provider-%SYSAPI_PKGPATH%/src/main/java/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/dto/%ITEM%DTO.java.ftl
浏览文件 @
874d7ea6
...
@@ -185,11 +185,11 @@ public class ${item.getCodeName()}DTO extends ${dtoBase} implements Serializable
...
@@ -185,11 +185,11 @@ public class ${item.getCodeName()}DTO extends ${dtoBase} implements Serializable
<#
list
de
.
getAllPSDEFValueRules
()
as
deRule
>
<#
list
de
.
getAllPSDEFValueRules
()
as
deRule
>
<#
if
deRule
.
codeName
!='Default'>
<#
if
deRule
.
codeName
!='Default'>
<#
if
deRule
.
getPSDEFVRGroupCondition
()??>
<#
if
deRule
.
getPSDEFVRGroupCondition
()??>
<#
assign
ruleName
=
de
.
codeName
+
"_"
+
deRule
.
getPSDEField
().
codeName
+
"_"
+
deRule
.
codeNam
e
>
<#
assign
ruleName
=
(
de
.
codeName
+
"_"
+
deRule
.
getPSDEField
().
codeName
+
"_"
+
deRule
.
codeName
)?
lower_cas
e
>
<#
assign
ruleField
=
deRule
.
getPSDEField
().
codeNam
e
>
<#
assign
ruleField
=
(
deRule
.
getPSDEField
().
codeName
)?
lower_cas
e
>
<#
assign
group
=
deRule
.
getPSDEFVRGroupCondition
()>
<#
assign
group
=
deRule
.
getPSDEFVRGroupCondition
()>
<#
assign
ruleMsg
=
getGroupCond
(
group
)>
<#
assign
ruleMsg
=
getGroupCond
(
group
)>
@
ValueRuleCheck
(
field
=
"${ruleField}"
,
rule
=
"${ruleName}"
,
message
=
"${ruleMsg}"
),
@
ValueRuleCheck
(
field
=
"${ruleField}"
,
rule
=
"${ruleName}"
),
</#
if
>
</#
if
>
</#
if
>
</#
if
>
</#
list
>
</#
list
>
...
@@ -222,7 +222,7 @@ public class ${item.getCodeName()}DTO extends ${dtoBase} implements Serializable
...
@@ -222,7 +222,7 @@ public class ${item.getCodeName()}DTO extends ${dtoBase} implements Serializable
<#
function
getFieldCond
fieldRule
>
<#
function
getFieldCond
fieldRule
>
<#
assign
fieldCond
=
""
>
<#
assign
fieldCond
=
""
>
<#
if
fieldRule
.
getRuleInfo
??
&&
fieldRule
.
getRuleInfo
()??>
<#
if
fieldRule
.
getRuleInfo
??
&&
fieldRule
.
getRuleInfo
()??>
<#
assign
fieldCond
=
"("
+
fieldRule
.
getRuleInfo
()+
")"
>
<#
assign
fieldCond
=
fieldRule
.
getRuleInfo
()
>
</#
if
>
</#
if
>
<#
return
fieldCond
/>
<#
return
fieldCond
/>
</#
function
>
</#
function
>
\ No newline at end of file
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/domain/DTOBase.java.ftl
浏览文件 @
874d7ea6
...
@@ -3,16 +3,20 @@ TARGET=PSSYSTEM
...
@@ -3,16 +3,20 @@ TARGET=PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
util
.
domain
;
package
${
pub
.
getPKGCodeName
()}.
util
.
domain
;
import
com
.
alibaba
.
fastjson
.
annotation
.
JSONField
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonAnyGetter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonAnyGetter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonAnySetter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonAnySetter
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonIgnore
;
import
com
.
fasterxml
.
jackson
.
annotation
.
JsonIgnore
;
import
com
.
alibaba
.
fastjson
.
annotation
.
JSONField
;
import
lombok
.
Data
;
import
${
pub
.
getPKGCodeName
()}.
util
.
helper
.
DEFieldCacheMap
;
import
org
.
springframework
.
cglib
.
beans
.
BeanMap
;
import
org
.
springframework
.
data
.
annotation
.
Transient
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
io
.
Serializable
;
import
java
.
io
.
Serializable
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
Map
;
import
java
.
util
.
Map
;
import
java
.
util
.
Set
;
import
java
.
util
.
Set
;
import
lombok
.
Data
;
@
Data
@
Data
public
class
DTOBase
implements
Serializable
{
public
class
DTOBase
implements
Serializable
{
...
@@ -76,9 +80,44 @@ public class DTOBase implements Serializable {
...
@@ -76,9 +80,44 @@ public class DTOBase implements Serializable {
return
extensionparams
;
return
extensionparams
;
}
}
@
JsonIgnore
@
JSONField
(
serialize
=
false
)
@
Transient
private
BeanMap
map
;
private
BeanMap
getMap
()
{
if
(
map
==
null
)
{
map
=
BeanMap
.
create
(
this
);
}
return
map
;
}
public
Object
get
(
String
field
)
{
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(
!StringUtils.isEmpty(fieldRealName)) {
return
getMap
().
get
(
fieldRealName
);
}
else
{
return
this
.
extensionparams
.
get
(
field
.
toLowerCase
());
}
}
@
JsonAnySetter
@
JsonAnySetter
public
void
set
(
String
name
,
Object
value
)
{
public
void
set
(
String
field
,
Object
value
)
{
extensionparams
.
put
(
name
.
toLowerCase
(),
value
);
field
=
field
.
toLowerCase
();
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(
!StringUtils.isEmpty(fieldRealName)) {
if
(
value
==
null
)
{
getMap
().
put
(
fieldRealName
,
null
);
}
else
{
getMap
().
put
(
fieldRealName
,
DEFieldCacheMap
.
fieldValueOf
(
this
.
getClass
(),
fieldRealName
,
value
));
}
}
else
{
this
.
extensionparams
.
put
(
field
.
toLowerCase
(),
value
);
}
}
}
}
}
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/domain/ValueRule.java.ftl
0 → 100644
浏览文件 @
874d7ea6
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
<#
if
sys
.
codeName
==
'Sample'
>
package
${
pub
.
getPKGCodeName
()}.
util
.
domain
;
import
lombok
.
Data
;
/**
*
属性值规则实体对象
*/
@
Data
public
class
ValueRule
{
public
String
cond
;
public
String
message
;
public
ValueRule
(
String
cond
,
String
message
)
{
this
.
cond
=
cond
;
this
.
message
=
message
;
}
}
</#
if
>
\ No newline at end of file
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/service/ValueRuleValidator.java.ftl
浏览文件 @
874d7ea6
...
@@ -6,13 +6,13 @@ package ${pub.getPKGCodeName()}.util.service;
...
@@ -6,13 +6,13 @@ package ${pub.getPKGCodeName()}.util.service;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
ValueRuleCheck
;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
ValueRuleCheck
;
import
${
pub
.
getPKGCodeName
()}.
util
.
domain
.
DTOBase
;
import
${
pub
.
getPKGCodeName
()}.
util
.
domain
.
DTOBase
;
import
${
pub
.
getPKGCodeName
()}.
util
.
domain
.
ValueRule
;
import
org
.
springframework
.
expression
.
EvaluationContext
;
import
org
.
springframework
.
expression
.
EvaluationContext
;
import
org
.
springframework
.
expression
.
Expression
;
import
org
.
springframework
.
expression
.
Expression
;
import
org
.
springframework
.
expression
.
ExpressionParser
;
import
org
.
springframework
.
expression
.
ExpressionParser
;
import
org
.
springframework
.
expression
.
spel
.
standard
.
SpelExpressionParser
;
import
org
.
springframework
.
expression
.
spel
.
standard
.
SpelExpressionParser
;
import
org
.
springframework
.
expression
.
spel
.
support
.
StandardEvaluationContext
;
import
org
.
springframework
.
expression
.
spel
.
support
.
StandardEvaluationContext
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
javax
.
validation
.
ConstraintValidator
;
import
javax
.
validation
.
ConstraintValidator
;
import
javax
.
validation
.
ConstraintValidatorContext
;
import
javax
.
validation
.
ConstraintValidatorContext
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
HashMap
;
...
@@ -20,29 +20,38 @@ import java.util.Map;
...
@@ -20,29 +20,38 @@ import java.util.Map;
public
class
ValueRuleValidator
implements
ConstraintValidator
<
ValueRuleCheck
,
DTOBase
>
{
public
class
ValueRuleValidator
implements
ConstraintValidator
<
ValueRuleCheck
,
DTOBase
>
{
private
static
Map
<
String
,
String
>
sysRule
=
new
HashMap
<>();
private
static
Map
<
String
,
ValueRule
>
sysRule
=
new
HashMap
<>();
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
private
final
ExpressionParser
parser
=
new
SpelExpressionParser
();
private
String
field
;
private
String
field
;
private
String
rule
;
private
String
rule
Name
;
@
Override
@
Override
public
void
initialize
(
ValueRuleCheck
constraintAnnotation
)
{
public
void
initialize
(
ValueRuleCheck
constraintAnnotation
)
{
this
.
field
=
constraintAnnotation
.
field
();
this
.
field
=
constraintAnnotation
.
field
();
this
.
rule
=
constraintAnnotation
.
rule
();
this
.
rule
Name
=
constraintAnnotation
.
rule
();
}
}
@
Override
@
Override
public
boolean
isValid
(
DTOBase
dto
,
ConstraintValidatorContext
constraintContext
)
{
public
boolean
isValid
(
DTOBase
dto
,
ConstraintValidatorContext
context
)
{
if
(
ObjectUtils
.
isEmpty
(
dto
)
||
ObjectUtils
.
isEmpty
(
rule
)
||
ObjectUtils
.
isEmpty
(
sysRule
.
get
(
rule
)))
{
if
(
!ObjectUtils.isEmpty(dto) && !ObjectUtils.isEmpty(ruleName) && !ObjectUtils.isEmpty(sysRule.get(ruleName)) && !ObjectUtils.isEmpty(dto.get(field))) {
return
true
;
ValueRule
rule
=
sysRule
.
get
(
ruleName
);
String
ruleCond
=
rule
.
getCond
();
String
ruleMessage
=
rule
.
getMessage
();
EvaluationContext
searchContextCtx
=
new
StandardEvaluationContext
();
searchContextCtx
.
setVariable
(
"dto"
,
dto
);
Expression
searchContextExp
=
parser
.
parseExpression
(
ruleCond
);
boolean
isValid
=
searchContextExp
.
getValue
(
searchContextCtx
,
Boolean
.
class
);
if
(
!isValid) {
context
.
disableDefaultConstraintViolation
();
context
.
buildConstraintViolationWithTemplate
(
String
.
format
(
"执行[%s]属性[%s]值规则发生异常,%s"
,
field
,
ruleName
,
ruleMessage
))
.
addConstraintViolation
();
return
false
;
}
}
}
EvaluationContext
searchContextCtx
=
new
StandardEvaluationContext
();
return
true
;
searchContextCtx
.
setVariable
(
"dto"
,
dto
);
Expression
searchContextExp
=
parser
.
parseExpression
(
sysRule
.
get
(
rule
));
return
searchContextExp
.
getValue
(
searchContextCtx
,
Boolean
.
class
);
}
}
static
{
static
{
...
@@ -53,7 +62,7 @@ public class ValueRuleValidator implements ConstraintValidator<ValueRuleCheck, D
...
@@ -53,7 +62,7 @@ public class ValueRuleValidator implements ConstraintValidator<ValueRuleCheck, D
<#
if
deRule
.
codeName
!='Default'>
<#
if
deRule
.
codeName
!='Default'>
<#
if
deRule
.
getPSDEFVRGroupCondition
()??>
<#
if
deRule
.
getPSDEFVRGroupCondition
()??>
<#
assign
group
=
deRule
.
getPSDEFVRGroupCondition
()>
<#
assign
group
=
deRule
.
getPSDEFVRGroupCondition
()>
<#
assign
ruleName
=
de
.
codeName
+
"_"
+
deRule
.
getPSDEField
().
codeName
+
"_"
+
deRule
.
codeNam
e
>
<#
assign
ruleName
=
(
de
.
codeName
+
"_"
+
deRule
.
getPSDEField
().
codeName
+
"_"
+
deRule
.
codeName
)?
lower_cas
e
>
<#
assign
ruleCond
=
getGroupCond
(
group
)>
<#
assign
ruleCond
=
getGroupCond
(
group
)>
sysRule
.
put
(
"${ruleName}"
,
"${ruleCond}"
);
sysRule
.
put
(
"${ruleName}"
,
"${ruleCond}"
);
</#
if
>
</#
if
>
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录