Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
99c555fc
提交
99c555fc
编写于
5月 08, 2020
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
默认值
上级
1891cb2e
变更
2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
167 行增加
和
219 行删除
+167
-219
DEFieldDefaultValueAspect.java.ftl
...S_PKGPATH%/util/aspect/DEFieldDefaultValueAspect.java.ftl
+118
-218
DEFieldCacheMap.java.ftl
...n/java/%SYS_PKGPATH%/util/helper/DEFieldCacheMap.java.ftl
+49
-1
未找到文件。
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/DEFieldDefaultValueAspect.java.ftl
浏览文件 @
99c555fc
...
...
@@ -4,6 +4,7 @@ TARGET=PSSYSTEM
package
${
pub
.
getPKGCodeName
()}.
util
.
aspect
;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
DEField
;
import
${
pub
.
getPKGCodeName
()}.
util
.
domain
.
EntityBase
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEFieldDefaultValueType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
enums
.
DEPredefinedFieldType
;
import
${
pub
.
getPKGCodeName
()}.
util
.
helper
.
DEFieldCacheMap
;
...
...
@@ -11,18 +12,13 @@ import ${pub.getPKGCodeName()}.util.security.AuthenticationUser;
import
org
.
aspectj
.
lang
.
JoinPoint
;
import
org
.
aspectj
.
lang
.
annotation
.
Aspect
;
import
org
.
aspectj
.
lang
.
annotation
.
Before
;
import
org
.
springframework
.
cglib
.
beans
.
BeanMap
;
import
org
.
springframework
.
core
.
annotation
.
Order
;
import
org
.
springframework
.
stereotype
.
Component
;
import
org
.
springframework
.
util
.
AlternativeJdkIdGenerator
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
beans
.
PropertyDescriptor
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
lang
.
reflect
.
Method
;
import
java
.
sql
.
Timestamp
;
import
java
.
util
.
Date
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
List
;
import
java
.
util
.
Map
;
...
...
@@ -39,80 +35,41 @@ public class DEFieldDefaultValueAspect
*
@
param
point
*
@
throws
Exception
*/
@
Before
(
value
=
"execution(*
${pub.getPKGCodeName()}
.core.*.service.*.create(..))"
)
@
Before
(
value
=
"execution(*
com.cntmtech.support
.core.*.service.*.create(..))"
)
public
void
BeforeCreate
(
JoinPoint
point
)
throws
Exception
{
fillDEFieldDefaultValue
(
point
);
}
@
Before
(
value
=
"execution(* com.cntmtech.support.core.*.service.*.createBatch(..))"
)
public
void
BeforeCreateBatch
(
JoinPoint
point
)
throws
Exception
{
fillDEFieldDefaultValue
(
point
);
}
/**
*
更新数据切入点
*
@
param
point
*
@
throws
Exception
*/
@
Before
(
value
=
"execution(*
${pub.getPKGCodeName()}
.core.*.service.*.update(..))"
)
@
Before
(
value
=
"execution(*
com.cntmtech.support
.core.*.service.*.update(..))"
)
public
void
BeforeUpdate
(
JoinPoint
point
)
throws
Exception
{
fillDEFieldDefaultValue
(
point
);
}
@
Before
(
value
=
"execution(* com.cntmtech.support.core.*.service.*.updateBatch(..))"
)
public
void
BeforeUpdateBatch
(
JoinPoint
point
)
throws
Exception
{
fillDEFieldDefaultValue
(
point
);
}
/**
*
保存数据切入点
*
@
param
point
*
@
throws
Exception
*/
@
Before
(
value
=
"execution(*
${pub.getPKGCodeName()}
.core.*.service.*.save(..))"
)
@
Before
(
value
=
"execution(*
com.cntmtech.support
.core.*.service.*.save(..))"
)
public
void
BeforeSave
(
JoinPoint
point
)
throws
Exception
{
checkAction
(
point
);
}
/**
*
判断当前是否为新建操作,若为新建,则填充属性默认值
*
@
param
joinPoint
*
@
throws
Exception
*/
private
void
checkAction
(
JoinPoint
joinPoint
)
throws
Exception
{
Object
[]
args
=
joinPoint
.
getArgs
();
if
(
args
.
length
>
0
)
{
Object
obj
=
args
[
0
];
String
className
=
obj
.
getClass
().
getName
();
//
获取当前
do
对象中的属性
DEFieldCacheMap
.
getFieldMap
(
className
);
//
从属性列表中过滤出主键属性
Field
keyPSDEField
=
this
.
getKeyPSDEField
(
className
);
if
(
ObjectUtils
.
isEmpty
(
keyPSDEField
))
return
;
String
filename
=
keyPSDEField
.
getName
();
PropertyDescriptor
field
=
new
PropertyDescriptor
(
filename
,
obj
.
getClass
());
Method
fieldGetMethod
=
field
.
getReadMethod
();
//
获取主键值
Object
fieldValue
=
fieldGetMethod
.
invoke
(
obj
);
//
实体数据主键为空,则为新建操作,填充属性默认值
if
(
ObjectUtils
.
isEmpty
(
fieldValue
)){
fillDEFieldDefaultValue
(
joinPoint
);
}
}
fillDEFieldDefaultValue
(
point
);
}
/**
*
获取主键属性
*
@
param
className
实体类名
*
@
return
主键属性
*/
private
Field
getKeyPSDEField
(
String
className
){
Field
keyField
=
null
;
List
<
Field
>
fields
=
DEFieldCacheMap
.
getFields
(
className
);
for
(
Field
field
:
fields
){
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
!ObjectUtils.isEmpty(deField) && deField.isKeyField()) {
return
field
;
}
}
return
keyField
;
@
Before
(
value
=
"execution(* com.cntmtech.support.core.*.service.*.saveBatch(..))"
)
public
void
BeforeSaveBatch
(
JoinPoint
point
)
throws
Exception
{
fillDEFieldDefaultValue
(
point
);
}
/**
...
...
@@ -122,53 +79,56 @@ public class DEFieldDefaultValueAspect
*
@
throws
Exception
*/
public
Object
fillDEFieldDefaultValue
(
JoinPoint
joinPoint
)
throws
Exception
{
Object
[]
args
=
joinPoint
.
getArgs
();
if
(
args
.
length
>
0
)
{
Object
obj
=
args
[
0
];
String
className
=
obj
.
getClass
().
getName
();
//
获取当前
po
对象中的属性
DEFieldCacheMap
.
getFieldMap
(
className
);
//
从属性列表中过滤出预置属性
Map
<
Field
,
DEField
>
deFields
=
this
.
SearchDEField
(
className
);
//
填充预置属性
fillDEField
(
obj
,
deFields
,
joinPoint
);
return
true
;
String
actionName
=
joinPoint
.
getSignature
().
getName
();
if
(
obj
instanceof
EntityBase
)
{
Map
<
String
,
DEField
>
deFields
=
DEFieldCacheMap
.
getDEFields
(
obj
.
getClass
());
AuthenticationUser
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
String
keyField
=
DEFieldCacheMap
.
getDEKeyField
(
obj
.
getClass
());
if
(
StringUtils
.
isEmpty
(
keyField
))
return
true
;
fillDEField
((
EntityBase
)
obj
,
deFields
,
actionName
,
curUser
,
keyField
);
}
else
if
(
obj
instanceof
List
)
{
Map
<
String
,
DEField
>
deFields
=
null
;
AuthenticationUser
curUser
=
null
;
String
keyField
=
""
;
for
(
Object
item
:(
List
)
obj
)
{
if
(
item
instanceof
EntityBase
)
{
if
(
deFields
==
null
)
{
deFields
=
DEFieldCacheMap
.
getDEFields
(
obj
.
getClass
());
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
keyField
=
DEFieldCacheMap
.
getDEKeyField
(
obj
.
getClass
());
if
(
StringUtils
.
isEmpty
(
keyField
))
return
true
;
}
fillDEField
((
EntityBase
)
item
,
deFields
,
actionName
,
curUser
,
keyField
);
}
}
}
}
return
true
;
}
/**
*
获取含有
@
DEField
注解的实体属性
*
@
param
className
do
对象类名
*
@
return
*/
private
Map
<
Field
,
DEField
>
SearchDEField
(
String
className
){
List
<
Field
>
fields
=
DEFieldCacheMap
.
getFields
(
className
);
Map
<
Field
,
DEField
>
deFieldMap
=
new
HashMap
<>();
for
(
Field
field
:
fields
){
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
!ObjectUtils.isEmpty(deField)) {
deFieldMap
.
put
(
field
,
deField
);
}
}
return
deFieldMap
;
}
/**
*
填充系统预置属性
*
@
param
et
当前实体对象
*/
private
void
fillDEField
(
Object
et
,
Map
<
Field
,
DEField
>
deFields
,
JoinPoint
joinPoint
)
throws
Exception
{
private
void
fillDEField
(
EntityBase
et
,
Map
<
String
,
DEField
>
deFields
,
String
actionName
,
AuthenticationUser
curUser
,
String
keyField
)
throws
Exception
{
if
(
deFields
.
size
()==
0
)
return
;
for
(
Map
.
Entry
<
Field
,
DEField
>
entry
:
deFields
.
entrySet
())
{
if
(
actionName
.
toLowerCase
().
startsWith
(
"save"
))
{
if
(
ObjectUtils
.
isEmpty
(
et
.
get
(
keyField
)))
actionName
=
"create"
;
}
Field
deField
=
entry
.
getKey
();
String
fi
leName
=
deField
.
getName
();
for
(
Map
.
Entry
<
String
,
DEField
>
entry
:
deFields
.
entrySet
())
{
String
fi
eldname
=
entry
.
getKey
();
//
获取注解
DEField
fieldAnnotation
=
entry
.
getValue
();
//
获取默认值类型
...
...
@@ -179,43 +139,35 @@ public class DEFieldDefaultValueAspect
DEPredefinedFieldType
predefinedFieldType
=
fieldAnnotation
.
preType
();
//
填充系统默认值
if
(
deFieldType
!= DEFieldDefaultValueType.NONE || (!StringUtils.isEmpty(deFieldDefaultValue))
){
fillFieldDefaultValue
(
fi
leName
,
deFieldType
,
deFieldDefaultValue
,
et
,
fieldAnnotation
)
;
if
(
actionName
.
toLowerCase
().
startsWith
(
"create"
)
&&
(
deFieldType
!= DEFieldDefaultValueType.NONE || (!StringUtils.isEmpty(deFieldDefaultValue)) )
){
fillFieldDefaultValue
(
fi
eldname
,
deFieldType
,
deFieldDefaultValue
,
et
,
curUser
)
;
}
//
填充系统预置属性
if
(
predefinedFieldType
!= DEPredefinedFieldType.NONE){
fillPreFieldValue
(
fi
leName
,
predefinedFieldType
,
et
,
joinPoint
,
fieldAnnotation
);
fillPreFieldValue
(
fi
eldname
,
predefinedFieldType
,
et
,
actionName
,
fieldAnnotation
.
logicval
(),
curUser
);
}
}
}
/**
*
填充属性默认值
*
@
param
fi
leN
ame
实体属性名
*
@
param
fi
eldn
ame
实体属性名
*
@
param
deFieldType
默认值类型
*
@
param
deFieldDefaultValue
默认值
*
@
param
et
当前实体对象
*
@
throws
Exception
*/
private
void
fillFieldDefaultValue
(
String
fileName
,
DEFieldDefaultValueType
deFieldType
,
String
deFieldDefaultValue
,
Object
et
,
DEField
fieldAnnotation
)
throws
Exception
{
AuthenticationUser
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
BeanMap
beanMap
=
BeanMap
.
create
(
et
);
Object
fieldValue
=
beanMap
.
get
(
fileName
);
//
获取当前所需填充属性的
get
、
set
方法及字段值
PropertyDescriptor
field
=
new
PropertyDescriptor
(
fileName
,
et
.
getClass
());
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
)){
private
void
fillFieldDefaultValue
(
String
fieldname
,
DEFieldDefaultValueType
deFieldType
,
String
deFieldDefaultValue
,
EntityBase
et
,
AuthenticationUser
curUser
)
throws
Exception
{
Object
fieldValue
=
et
.
get
(
fieldname
);
if
(
org
.
springframework
.
util
.
ObjectUtils
.
isEmpty
(
fieldValue
)){
//
填充直接值及其余默认值类型
if
(
(
deFieldType
==
DEFieldDefaultValueType
.
NONE
&&
!StringUtils.isEmpty(deFieldDefaultValue)) || (deFieldType != DEFieldDefaultValueType.NONE) ){
switch
(
deFieldType
){
case
SESSION
:
String
sessionField
=
fieldAnnotation
.
defaultValue
();
if
(
!StringUtils.isEmpty(sessionField)){
Object
sessionFieldValue
=
curUser
.
getSessionParams
().
get
(
sessionField
);
if
(
!StringUtils.isEmpty(deFieldDefaultValue)){
Object
sessionFieldValue
=
curUser
.
getSessionParams
().
get
(
deFieldDefaultValue
.
toLowerCase
());
if
(
!ObjectUtils.isEmpty(sessionFieldValue)){
beanMap
.
put
(
fileN
ame
,
sessionFieldValue
);
et
.
set
(
fieldn
ame
,
sessionFieldValue
);
}
}
break
;
...
...
@@ -223,146 +175,94 @@ public class DEFieldDefaultValueAspect
//
暂未实现
break
;
case
UNIQUEID
:
String
uuid
=(
new
AlternativeJdkIdGenerator
()).
generateId
().
toString
();
Object
objUuId
=
fieldValueConvert
(
uuid
,
field
);
beanMap
.
put
(
fileName
,
objUuId
);
et
.
set
(
fieldname
,(
new
AlternativeJdkIdGenerator
()).
generateId
().
toString
().
replace
(
"-"
,
""
));
break
;
case
CONTEXT
:
//
暂未实现
if
(
!StringUtils.isEmpty(deFieldDefaultValue)){
Object
paramFieldValue
=
et
.
get
(
deFieldDefaultValue
);
if
(
!ObjectUtils.isEmpty(paramFieldValue)){
et
.
set
(
fieldname
,
paramFieldValue
);
}
}
break
;
case
PARAM
:
String
paramField
=
fieldAnnotation
.
defaultValue
();
if
(
!StringUtils.isEmpty(paramField)){
Object
paramFieldValue
=
beanMap
.
get
(
paramField
);
if
(
!StringUtils.isEmpty(deFieldDefaultValue)){
Object
paramFieldValue
=
et
.
get
(
deFieldDefaultValue
);
if
(
!ObjectUtils.isEmpty(paramFieldValue)){
beanMap
.
put
(
fileN
ame
,
paramFieldValue
);
et
.
set
(
fieldn
ame
,
paramFieldValue
);
}
}
break
;
case
OPERATOR
:
beanMap
.
put
(
fileN
ame
,
curUser
.
getUserid
());
et
.
set
(
fieldn
ame
,
curUser
.
getUserid
());
break
;
case
OPERATORNAME
:
beanMap
.
put
(
fileN
ame
,
curUser
.
getPersonname
());
et
.
set
(
fieldn
ame
,
curUser
.
getPersonname
());
break
;
case
CURTIME
:
beanMap
.
put
(
fileN
ame
,
new
Timestamp
(
new
Date
().
getTime
()));
et
.
set
(
fieldn
ame
,
new
Timestamp
(
new
Date
().
getTime
()));
break
;
case
APPDATA
:
//
暂未实现
break
;
case
NONE
:
Object
deFieldDefaultValueObj
=
fieldValueConvert
(
deFieldDefaultValue
,
field
);
beanMap
.
put
(
fileName
,
deFieldDefaultValueObj
);
et
.
set
(
fieldname
,
deFieldDefaultValue
);
break
;
}
}
}
}
/**
*
填充系统预置属性
*
@
param
fileName
实体属性名
*
@
param
preFieldType
预置类型
*
@
param
et
当前实体对象
*
@
param
joinPoint
切点
*
@
param
fieldAnnotation
属性注解
*
@
throws
Exception
*/
private
void
fillPreFieldValue
(
String
fileName
,
DEPredefinedFieldType
preFieldType
,
Object
et
,
JoinPoint
joinPoint
,
DEField
fieldAnnotation
)
throws
Exception
{
AuthenticationUser
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
BeanMap
beanMap
=
BeanMap
.
create
(
et
);
//
当前操作行为
String
actionName
=
joinPoint
.
getSignature
().
getName
();
Object
fieldValue
=
beanMap
.
get
(
fileName
);
//
获取当前所需填充属性的
get
、
set
方法及字段值
PropertyDescriptor
field
=
new
PropertyDescriptor
(
fileName
,
et
.
getClass
());
private
void
fillPreFieldValue
(
String
fieldname
,
DEPredefinedFieldType
preFieldType
,
EntityBase
et
,
String
actionName
,
String
logicValue
,
AuthenticationUser
curUser
)
throws
Exception
{
Object
fieldValue
=
et
.
get
(
fieldname
);
//
为预置属性进行赋值
if
(
(
actionName
.
equalsIgnoreCase
(
"create"
)
&&
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
)
)||
if
(
actionName
.
equalsIgnoreCase
(
"create"
)||
preFieldType
==
DEPredefinedFieldType
.
UPDATEDATE
||
preFieldType
==
DEPredefinedFieldType
.
UPDATEMAN
||
preFieldType
==
DEPredefinedFieldType
.
UPDATEMANNAME
){
switch
(
preFieldType
){//
根据注解给预置属性填充值
case
CREATEMAN
:
beanMap
.
put
(
fileName
,
curUser
.
getUserid
());
break
;
case
CREATEMANNAME
:
beanMap
.
put
(
fileName
,
curUser
.
getPersonname
());
break
;
case
UPDATEMAN
:
beanMap
.
put
(
fileName
,
curUser
.
getUserid
());
break
;
case
UPDATEMANNAME
:
beanMap
.
put
(
fileName
,
curUser
.
getPersonname
());
break
;
case
CREATEDATE
:
beanMap
.
put
(
fileName
,
new
Timestamp
(
new
Date
().
getTime
()));
break
;
case
UPDATEDATE
:
beanMap
.
put
(
fileName
,
new
Timestamp
(
new
Date
().
getTime
()));
break
;
case
ORGID
:
beanMap
.
put
(
fileName
,
curUser
.
getOrgid
());
break
;
case
ORGNAME
:
beanMap
.
put
(
fileName
,
curUser
.
getOrgname
());
break
;
case
ORGSECTORID
:
beanMap
.
put
(
fileName
,
curUser
.
getMdeptid
());
break
;
case
ORGSECTORNAME
:
beanMap
.
put
(
fileName
,
curUser
.
getMdeptname
());
break
;
case
LOGICVALID
:
String
logicValue
=
fieldAnnotation
.
logicval
();
Object
objLogicValue
=
fieldValueConvert
(
logicValue
,
field
);
if
(
!StringUtils.isEmpty(objLogicValue)){
beanMap
.
put
(
fileName
,
objLogicValue
);
}
break
;
}
switch
(
preFieldType
){//
根据注解给预置属性填充值
case
CREATEMAN
:
et
.
set
(
fieldname
,
curUser
.
getUserid
());
break
;
case
CREATEMANNAME
:
et
.
set
(
fieldname
,
curUser
.
getPersonname
());
break
;
case
UPDATEMAN
:
et
.
set
(
fieldname
,
curUser
.
getUserid
());
break
;
case
UPDATEMANNAME
:
et
.
set
(
fieldname
,
curUser
.
getPersonname
());
break
;
case
CREATEDATE
:
et
.
set
(
fieldname
,
new
Timestamp
(
new
Date
().
getTime
()));
break
;
case
UPDATEDATE
:
et
.
set
(
fieldname
,
new
Timestamp
(
new
Date
().
getTime
()));
break
;
case
ORGID
:
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
))
et
.
set
(
fieldname
,
curUser
.
getOrgid
());
break
;
case
ORGNAME
:
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
))
et
.
set
(
fieldname
,
curUser
.
getOrgname
());
break
;
case
ORGSECTORID
:
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
))
et
.
set
(
fieldname
,
curUser
.
getMdeptid
());
break
;
case
ORGSECTORNAME
:
if
(
org
.
springframework
.
util
.
StringUtils
.
isEmpty
(
fieldValue
))
et
.
set
(
fieldname
,
curUser
.
getMdeptname
());
break
;
case
LOGICVALID
:
if
(
!StringUtils.isEmpty(logicValue)){
logicValue
=
"1"
;
}
et
.
set
(
fieldname
,
logicValue
);
break
;
}
}
}
/**
*
值类型转换
*
@
param
fieldValue
*
@
param
field
*/
private
Object
fieldValueConvert
(
String
fieldValue
,
PropertyDescriptor
field
){
Object
resultValue
=
fieldValue
;
String
targetType
=
field
.
getPropertyType
().
getSimpleName
();
if
(
targetType
.
equals
(
"Boolean"
)){
resultValue
=
Boolean
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Character"
)){
resultValue
=
fieldValue
.
toCharArray
();
}
else
if
(
targetType
.
equals
(
"Byte"
)){
resultValue
=
Byte
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Short"
)){
resultValue
=
Short
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Integer"
)){
resultValue
=
Integer
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Long"
)){
resultValue
=
Long
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Float"
)){
resultValue
=
Float
.
valueOf
(
fieldValue
);
}
else
if
(
targetType
.
equals
(
"Double"
)){
resultValue
=
Double
.
valueOf
(
fieldValue
);
}
return
resultValue
;
}
}
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/helper/DEFieldCacheMap.java.ftl
浏览文件 @
99c555fc
...
...
@@ -5,8 +5,8 @@ package ${pub.getPKGCodeName()}.util.helper;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
DEField
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Hashtable
;
...
...
@@ -23,6 +23,10 @@ public class DEFieldCacheMap {
private
static
Hashtable
<
String
,
Hashtable
<
String
,
String
>>
cacheKey
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
Hashtable
<
String
,
DEField
>>
cacheDEField
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
String
>
cacheDEKeyField
=
new
Hashtable
<>();
private
static
Object
objLock1
=
new
Object
();
/**
...
...
@@ -42,15 +46,24 @@ public class DEFieldCacheMap {
Hashtable
<
String
,
Field
>
result
=
new
Hashtable
<
String
,
Field
>();
List
<
Field
>
list
=
new
ArrayList
<
Field
>();
Hashtable
<
String
,
String
>
keys
=
new
Hashtable
<
String
,
String
>();
Hashtable
<
String
,
DEField
>
defields
=
new
Hashtable
<>();
Hashtable
<
String
,
String
>
dekeyfields
=
new
Hashtable
<>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
){
result
.
put
(
field
.
getName
(),
field
);
list
.
add
(
field
);
keys
.
put
(
field
.
getName
().
toLowerCase
(),
field
.
getName
());
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
!ObjectUtils.isEmpty(deField)) {
defields
.
put
(
field
.
getName
(),
deField
);
if
(
deField
.
isKeyField
())
cacheDEKeyField
.
put
(
className
,
field
.
getName
());
}
}
cacheMap
.
put
(
className
,
result
);
cacheList
.
put
(
className
,
list
);
cacheKey
.
put
(
className
,
keys
);
cacheDEField
.
put
(
className
,
defields
);
return
result
;
}
}
...
...
@@ -70,6 +83,41 @@ public class DEFieldCacheMap {
}
}
/**
*
从缓存中查询实体对象属性集合
*
@
param
*
@
return
*/
public
static
<
T
>
Hashtable
<
String
,
DEField
>
getDEFields
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheDEField
.
containsKey
(
className
))
return
cacheDEField
.
get
(
className
);
else
{
DEFieldCacheMap
.
getFieldMap
(
clazz
);
return
cacheDEField
.
get
(
className
);
}
}
/**
*
从缓存中查询实体对象主键
*
@
param
*
@
return
*/
public
static
<
T
>
String
getDEKeyField
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheDEKeyField
.
containsKey
(
className
))
return
cacheDEKeyField
.
get
(
className
);
else
{
DEFieldCacheMap
.
getFieldMap
(
clazz
);
return
cacheDEKeyField
.
get
(
className
);
}
}
/**
*
从缓存中查询实体对象属性列表
*
@
param
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录