Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
1891cb2e
提交
1891cb2e
编写于
5月 08, 2020
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
field 处理 clumnname
上级
7cb3106c
变更
6
显示空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
727 行增加
和
73 行删除
+727
-73
%DE%.java.ftl
...ava/%SYS_PKGPATH%/core/%MOD_PKGPATH%/domain/%DE%.java.ftl
+9
-0
DEField.java.ftl
.../main/java/%SYS_PKGPATH%/util/annotation/DEField.java.ftl
+5
-0
EntityBase.java.ftl
...c/main/java/%SYS_PKGPATH%/util/domain/EntityBase.java.ftl
+13
-13
QueryWrapperContext.java.ftl
...va/%SYS_PKGPATH%/util/filter/QueryWrapperContext.java.ftl
+7
-2
DEFieldCacheMap.java.ftl
...n/java/%SYS_PKGPATH%/util/helper/DEFieldCacheMap.java.ftl
+96
-58
DataObject.java.ftl
...c/main/java/%SYS_PKGPATH%/util/helper/DataObject.java.ftl
+597
-0
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/domain/%DE%.java.ftl
浏览文件 @
1891cb2e
...
@@ -48,6 +48,9 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
...
@@ -48,6 +48,9 @@ public class ${item.getCodeName()} extends EntityMP implements Serializable {
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
assign
tablefieldano
=
"value =
\"
"
+
columnname
+
"
\"
"
>
<#
assign
tablefieldano
=
"value =
\"
"
+
columnname
+
"
\"
"
>
<#
assign
defieldano
=
""
>
<#
assign
defieldano
=
""
>
<#
if
prvateCodeName
?
lower_case
!= columnname>
<#
assign
defieldano
=
"name =
\"
"
+
columnname
+
"
\"
"
>
</#
if
>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
</#
if
>
</#
if
>
...
@@ -237,6 +240,9 @@ public class ${item.getCodeName()} extends EntityMongo implements Serializable {
...
@@ -237,6 +240,9 @@ public class ${item.getCodeName()} extends EntityMongo implements Serializable {
<#
assign
publicCodeName
=
prvateCodeName
?
cap_first
>
<#
assign
publicCodeName
=
prvateCodeName
?
cap_first
>
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
assign
defieldano
=
""
>
<#
assign
defieldano
=
""
>
<#
if
prvateCodeName
?
lower_case
!= columnname>
<#
assign
defieldano
=
"name =
\"
"
+
columnname
+
"
\"
"
>
</#
if
>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
</#
if
>
</#
if
>
...
@@ -378,6 +384,9 @@ public class ${item.getCodeName()} extends EntityClient implements Serializable
...
@@ -378,6 +384,9 @@ public class ${item.getCodeName()} extends EntityClient implements Serializable
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
assign
jsonfield
=
defield
.
getCodeName
()?
lower_case
>
<#
if
de
.
getStorageMode
()==
0
><#
assign
jsonfield
=
defield
.
getCodeName
()?
uncap_first
></#
if
>
<#
if
de
.
getStorageMode
()==
0
><#
assign
jsonfield
=
defield
.
getCodeName
()?
uncap_first
></#
if
>
<#
assign
defieldano
=
""
>
<#
assign
defieldano
=
""
>
<#
if
prvateCodeName
?
lower_case
!= columnname>
<#
assign
defieldano
=
"name =
\"
"
+
columnname
+
"
\"
"
>
</#
if
>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
if
defield
.
getDefaultValue
()??
&&
defield
.
getDefaultValue
()
!=''>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
<#
assign
defieldano
=
"defaultValue =
\"
"
+
defield
.
getDefaultValue
()+
"
\"
"
>
</#
if
>
</#
if
>
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/annotation/DEField.java.ftl
浏览文件 @
1891cb2e
...
@@ -14,6 +14,11 @@ import java.lang.annotation.Target;
...
@@ -14,6 +14,11 @@ import java.lang.annotation.Target;
@
Target
({
ElementType
.
FIELD
})
@
Target
({
ElementType
.
FIELD
})
public
@
interface
DEField
public
@
interface
DEField
{
{
/**
*
属性名称
*
@
return
*/
String
name
()
default
""
;
/**
/**
*
是否为数据主键
*
是否为数据主键
*
@
return
*
@
return
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/domain/EntityBase.java.ftl
浏览文件 @
1891cb2e
...
@@ -13,6 +13,7 @@ import org.springframework.cglib.beans.BeanMap;
...
@@ -13,6 +13,7 @@ import org.springframework.cglib.beans.BeanMap;
import
org
.
springframework
.
data
.
annotation
.
Transient
;
import
org
.
springframework
.
data
.
annotation
.
Transient
;
import
org
.
springframework
.
util
.
AlternativeJdkIdGenerator
;
import
org
.
springframework
.
util
.
AlternativeJdkIdGenerator
;
import
java
.
io
.
Serializable
;
import
java
.
io
.
Serializable
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
util
.*;
import
java
.
util
.*;
public
class
EntityBase
implements
Serializable
{
public
class
EntityBase
implements
Serializable
{
...
@@ -71,14 +72,11 @@ public class EntityBase implements Serializable {
...
@@ -71,14 +72,11 @@ public class EntityBase implements Serializable {
public
Object
get
(
String
field
)
{
public
Object
get
(
String
field
)
{
field
=
field
.
toLowerCase
();
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
Hashtable
<
String
,
String
>
keys
=
DEFieldCacheMap
.
getFieldKeys
(
this
.
getClass
().
getName
());
if
(
!StringUtils.isEmpty(fieldRealName))
if
(
keys
.
containsKey
(
field
))
return
getMap
().
get
(
fieldRealName
);
return
getMap
().
get
(
keys
.
get
(
field
));
else
if
(
keys
.
containsKey
(
field
.
replace
(
"_"
,
""
)))
return
getMap
().
get
(
keys
.
get
(
field
.
replace
(
"_"
,
""
)));
else
else
return
this
.
extensionparams
.
get
(
field
);
return
this
.
extensionparams
.
get
(
field
.
toLowerCase
()
);
}
}
...
@@ -90,13 +88,15 @@ public class EntityBase implements Serializable {
...
@@ -90,13 +88,15 @@ public class EntityBase implements Serializable {
@
JsonAnySetter
@
JsonAnySetter
public
void
set
(
String
field
,
Object
value
)
{
public
void
set
(
String
field
,
Object
value
)
{
field
=
field
.
toLowerCase
();
field
=
field
.
toLowerCase
();
Hashtable
<
String
,
String
>
keys
=
DEFieldCacheMap
.
getFieldKeys
(
this
.
getClass
().
getName
());
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
this
.
getClass
(),
field
);
if
(
keys
.
containsKey
(
field
))
if
(
!StringUtils.isEmpty(fieldRealName)) {
getMap
().
put
(
keys
.
get
(
field
),
value
);
if
(
value
==
null
)
else
if
(
keys
.
containsKey
(
field
.
replace
(
"_"
,
""
)))
getMap
().
put
(
fieldRealName
,
null
);
getMap
().
put
(
keys
.
get
(
field
.
replace
(
"_"
,
""
)),
value
);
else
getMap
().
put
(
fieldRealName
,
DEFieldCacheMap
.
fieldValueOf
(
this
.
getClass
(),
fieldRealName
,
value
));
}
else
else
this
.
extensionparams
.
put
(
field
,
value
);
this
.
extensionparams
.
put
(
field
.
toLowerCase
()
,
value
);
}
}
}
}
\ No newline at end of file
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/filter/QueryWrapperContext.java.ftl
浏览文件 @
1891cb2e
...
@@ -3,6 +3,7 @@ TARGET=PSSYSTEM
...
@@ -3,6 +3,7 @@ TARGET=PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
util
.
filter
;
package
${
pub
.
getPKGCodeName
()}.
util
.
filter
;
import
${
pub
.
getPKGCodeName
()}.
util
.
helper
.
DEFieldCacheMap
;
import
com
.
alibaba
.
fastjson
.
annotation
.
JSONField
;
import
com
.
alibaba
.
fastjson
.
annotation
.
JSONField
;
import
com
.
baomidou
.
mybatisplus
.
core
.
conditions
.
query
.
QueryWrapper
;
import
com
.
baomidou
.
mybatisplus
.
core
.
conditions
.
query
.
QueryWrapper
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
;
import
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
;
...
@@ -12,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
...
@@ -12,6 +13,8 @@ import lombok.extern.slf4j.Slf4j;
import
org
.
springframework
.
data
.
domain
.
Sort
;
import
org
.
springframework
.
data
.
domain
.
Sort
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
ObjectUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
lang
.
reflect
.
ParameterizedType
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Iterator
;
import
java
.
util
.
Iterator
;
import
java
.
util
.
List
;
import
java
.
util
.
List
;
...
@@ -51,13 +54,15 @@ public class QueryWrapperContext<T> extends SearchContextBase implements ISearch
...
@@ -51,13 +54,15 @@ public class QueryWrapperContext<T> extends SearchContextBase implements ISearch
if
(
ObjectUtils
.
isEmpty
(
it_sort
))
if
(
ObjectUtils
.
isEmpty
(
it_sort
))
return
page
;
return
page
;
ParameterizedType
parameterizedType
=
(
ParameterizedType
)
getClass
().
getGenericSuperclass
();
Class
<
T
>
type
=
(
Class
<
T
>)
parameterizedType
.
getActualTypeArguments
()[
0
];
while
(
it_sort
.
hasNext
())
{
while
(
it_sort
.
hasNext
())
{
Sort
.
Order
sort_order
=
it_sort
.
next
();
Sort
.
Order
sort_order
=
it_sort
.
next
();
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
ASC
){
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
ASC
){
asc_fieldList
.
add
(
sort_order
.
getProperty
(
));
asc_fieldList
.
add
(
DEFieldCacheMap
.
getFieldColumnName
(
type
,
sort_order
.
getProperty
()
));
}
}
else
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
DESC
){
else
if
(
sort_order
.
getDirection
()==
Sort
.
Direction
.
DESC
){
desc_fieldList
.
add
(
sort_order
.
getProperty
(
));
desc_fieldList
.
add
(
DEFieldCacheMap
.
getFieldColumnName
(
type
,
sort_order
.
getProperty
()
));
}
}
}
}
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/helper/DEFieldCacheMap.java.ftl
浏览文件 @
1891cb2e
...
@@ -3,10 +3,13 @@ TARGET=PSSYSTEM
...
@@ -3,10 +3,13 @@ TARGET=PSSYSTEM
</#
ibiztemplate
>
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
util
.
helper
;
package
${
pub
.
getPKGCodeName
()}.
util
.
helper
;
import
${
pub
.
getPKGCodeName
()}.
util
.
annotation
.
DEField
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
lang
.
reflect
.
Field
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
ArrayList
;
import
java
.
util
.
Hashtable
;
import
java
.
util
.
Hashtable
;
import
java
.
util
.
Iterator
;
import
java
.
util
.
List
;
import
java
.
util
.
List
;
/**
/**
...
@@ -20,103 +23,138 @@ public class DEFieldCacheMap {
...
@@ -20,103 +23,138 @@ public class DEFieldCacheMap {
private
static
Hashtable
<
String
,
Hashtable
<
String
,
String
>>
cacheKey
=
new
Hashtable
<>();
private
static
Hashtable
<
String
,
Hashtable
<
String
,
String
>>
cacheKey
=
new
Hashtable
<>();
private
static
Object
objLock1
=
new
Object
();
private
static
Object
objLock1
=
new
Object
();
private
static
Object
objLock2
=
new
Object
();
private
static
Object
objLock3
=
new
Object
();
/**
/**
*
将实体对象中的属性存入缓存中
*
将实体对象中的属性存入缓存中
*
@
param
className
*
@
param
*
@
return
*
@
return
*/
*/
public
static
Hashtable
<
String
,
Field
>
getFieldMap
(
String
className
)
{
public
static
<
T
>
Hashtable
<
String
,
Field
>
getFieldMap
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheMap
.
containsKey
(
className
))
if
(
cacheMap
.
containsKey
(
className
))
return
cacheMap
.
get
(
className
);
return
cacheMap
.
get
(
className
);
synchronized
(
objLock1
)
{
synchronized
(
objLock1
)
{
if
(
cacheMap
.
containsKey
(
className
))
if
(
cacheMap
.
containsKey
(
className
))
return
cacheMap
.
get
(
className
);
return
cacheMap
.
get
(
className
);
Hashtable
<
String
,
Field
>
result
=
new
Hashtable
<
String
,
Field
>();
List
<
Field
>
list
=
new
ArrayList
<
Field
>();
Hashtable
<
String
,
String
>
keys
=
new
Hashtable
<
String
,
String
>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
){
result
.
put
(
field
.
getName
(),
field
);
list
.
add
(
field
);
keys
.
put
(
field
.
getName
().
toLowerCase
(),
field
.
getName
());
}
cacheMap
.
put
(
className
,
result
);
cacheList
.
put
(
className
,
list
);
cacheKey
.
put
(
className
,
keys
);
return
result
;
}
}
public
static
Hashtable
<
String
,
Field
>
getFieldMap
(
String
className
)
{
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheMap
.
containsKey
(
className
))
return
cacheMap
.
get
(
className
);
Class
clazz
=
null
;
Class
clazz
=
null
;
try
{
try
{
clazz
=
Class
.
forName
(
className
);
clazz
=
Class
.
forName
(
className
);
return
getFieldMap
(
clazz
);
}
}
catch
(
Exception
ex
)
{
catch
(
Exception
ex
)
{
cacheMap
.
put
(
className
,
new
Hashtable
<
String
,
Field
>());
cacheMap
.
put
(
className
,
new
Hashtable
<
String
,
Field
>());
return
cacheMap
.
get
(
className
);
return
cacheMap
.
get
(
className
);
}
}
Hashtable
<
String
,
Field
>
result
=
cacheMap
.
get
(
className
);
if
(
result
==
null
)
{
result
=
new
Hashtable
<
String
,
Field
>();
Field
[]
fields
=
clazz
.
getDeclaredFields
();
for
(
Field
field
:
fields
){
result
.
put
(
field
.
getName
(),
field
);
}
cacheMap
.
put
(
className
,
result
);
}
return
result
;
}
}
}
/**
/**
*
从缓存中查询实体对象属性列表
*
从缓存中查询实体对象属性列表
*
@
param
className
*
@
param
*
@
return
*
@
return
*/
*/
public
static
List
<
Field
>
getFields
(
String
className
)
{
public
static
<
T
>
List
<
Field
>
getFields
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheList
.
containsKey
(
className
))
if
(
cacheList
.
containsKey
(
className
))
return
cacheList
.
get
(
className
);
return
cacheList
.
get
(
className
);
else
{
synchronized
(
objLock2
)
{
DEFieldCacheMap
.
getFieldMap
(
clazz
);
if
(
cacheList
.
containsKey
(
className
))
return
cacheList
.
get
(
className
);
return
cacheList
.
get
(
className
);
Hashtable
<
String
,
Field
>
fieldmap
=
DEFieldCacheMap
.
getFieldMap
(
className
);
Iterator
it
=
fieldmap
.
keySet
().
iterator
();
List
<
Field
>
list
=
new
ArrayList
<
Field
>();
while
(
it
.
hasNext
())
{
Object
key
=
it
.
next
();
if
(
fieldmap
.
get
(
key
.
toString
())
!=null)
list
.
add
(
fieldmap
.
get
(
key
.
toString
()));
}
}
cacheList
.
put
(
className
,
list
);
}
return
list
;
public
static
List
<
Field
>
getFields
(
String
className
)
{
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheList
.
containsKey
(
className
))
return
cacheList
.
get
(
className
);
else
{
DEFieldCacheMap
.
getFieldMap
(
className
);
return
cacheList
.
get
(
className
);
}
}
}
}
/**
/**
*
从缓存中查询实体对象属性列表
*
从缓存中查询实体对象属性列表
*
@
param
className
*
@
param
*
@
return
*
@
return
*/
*/
public
static
Hashtable
<
String
,
String
>
getFieldKeys
(
String
className
)
{
public
static
<
T
>
Hashtable
<
String
,
String
>
getFieldKeys
(
Class
<
T
>
clazz
)
{
String
className
=
clazz
.
getName
();
if
(
className
.
indexOf
(
"_$"
)>
0
)
if
(
className
.
indexOf
(
"_$"
)>
0
)
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
className
=
className
.
substring
(
0
,
className
.
lastIndexOf
(
"_$"
));
if
(
cacheKey
.
containsKey
(
className
))
if
(
cacheKey
.
containsKey
(
className
))
return
cacheKey
.
get
(
className
);
return
cacheKey
.
get
(
className
);
else
{
synchronized
(
objLock3
)
{
DEFieldCacheMap
.
getFieldMap
(
clazz
);
if
(
cacheKey
.
containsKey
(
className
))
return
cacheKey
.
get
(
className
);
return
cacheKey
.
get
(
className
);
Hashtable
<
String
,
Field
>
fieldmap
=
DEFieldCacheMap
.
getFieldMap
(
className
);
Iterator
it
=
fieldmap
.
keySet
().
iterator
();
Hashtable
<
String
,
String
>
list
=
new
Hashtable
<
String
,
String
>();
while
(
it
.
hasNext
())
{
Object
key
=
it
.
next
();
list
.
put
(
key
.
toString
().
toLowerCase
(),
key
.
toString
());
}
}
cacheKey
.
put
(
className
,
list
);
return
list
;
}
}
public
static
<
T
>
String
getFieldRealName
(
Class
<
T
>
clazz
,
String
fieldname
)
{
fieldname
=
fieldname
.
toLowerCase
();
Hashtable
<
String
,
String
>
keys
=
DEFieldCacheMap
.
getFieldKeys
(
clazz
);
if
(
keys
.
containsKey
(
fieldname
))
return
keys
.
get
(
fieldname
);
else
if
(
keys
.
containsKey
(
fieldname
.
replace
(
"_"
,
""
)))
return
keys
.
get
(
fieldname
.
replace
(
"_"
,
""
));
else
return
""
;
}
public
static
<
T
>
Field
getField
(
Class
<
T
>
clazz
,
String
fieldname
)
{
String
fieldRealName
=
DEFieldCacheMap
.
getFieldRealName
(
clazz
,
fieldname
);
if
(
!StringUtils.isEmpty(fieldRealName))
return
DEFieldCacheMap
.
getFieldMap
(
clazz
).
get
(
fieldRealName
);
else
return
null
;
}
public
static
<
T
>
String
getFieldColumnName
(
Class
<
T
>
clazz
,
String
fieldname
)
{
Field
field
=
DEFieldCacheMap
.
getField
(
clazz
,
fieldname
);
if
(
field
!=null) {
DEField
deField
=
field
.
getAnnotation
(
DEField
.
class
);
if
(
deField
!=null&&deField.name()!=null)
return
deField
.
name
();
}
return
fieldname
;
}
}
public
static
<
T
>
Object
fieldValueOf
(
Class
<
T
>
clazz
,
String
fieldname
,
Object
fieldValue
)
{
if
(
fieldValue
==
null
)
return
null
;
Object
resultValue
=
fieldValue
;
Field
field
=
DEFieldCacheMap
.
getField
(
clazz
,
fieldname
);
if
(
field
!=null) {
Class
<?>
type
=
field
.
getType
();
resultValue
=
DataObject
.
objectValueOf
(
type
,
fieldValue
);
}
return
resultValue
;
}
}
}
\ No newline at end of file
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/helper/DataObject.java.ftl
0 → 100644
浏览文件 @
1891cb2e
<#
ibiztemplate
>
TARGET
=
PSSYSTEM
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
util
.
helper
;
import
com
.
alibaba
.
fastjson
.
JSONArray
;
import
com
.
alibaba
.
fastjson
.
JSONObject
;
import
org
.
springframework
.
util
.
StringUtils
;
import
java
.
math
.
BigDecimal
;
import
java
.
math
.
BigInteger
;
import
java
.
sql
.
Timestamp
;
import
java
.
text
.
DateFormat
;
import
java
.
text
.
ParseException
;
import
java
.
text
.
SimpleDateFormat
;
import
java
.
util
.*;
public
class
DataObject
{
final
static
public
DateFormat
datetimeFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
final
static
public
DateFormat
datetimeFormat2
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
final
static
public
DateFormat
dayFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
final
static
public
String
getStringValue
(
Object
objValue
,
String
strDefault
)
{
if
(
objValue
==
null
)
return
strDefault
;
if
(
objValue
instanceof
String
)
return
(
String
)
objValue
;
if
(
objValue
instanceof
java
.
sql
.
Timestamp
||
objValue
instanceof
java
.
sql
.
Date
||
objValue
instanceof
java
.
util
.
Date
)
{
String
rt
=
datetimeFormat
.
format
(
objValue
);
if
(
rt
.
endsWith
(
" 00:00:00"
))
rt
=
dayFormat
.
format
(
objValue
);
else
if
(
rt
.
endsWith
(
":00"
))
rt
=
datetimeFormat2
.
format
(
objValue
);
return
rt
;
}
return
objValue
.
toString
();
}
public
static
<
T
>
Object
objectValueOf
(
Class
<
T
>
type
,
Object
fieldValue
)
{
if
(
fieldValue
==
null
)
return
null
;
Object
resultValue
=
fieldValue
;
String
targetType
=
type
.
getSimpleName
();
if
(
targetType
.
equalsIgnoreCase
(
fieldValue
.
getClass
().
getSimpleName
()))
return
resultValue
;
if
(
targetType
.
equals
(
"Boolean"
)){
resultValue
=
getBooleanValue
(
fieldValue
,
false
);
}
else
if
(
targetType
.
equals
(
"Character"
)){
resultValue
=
getCharacterValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Byte"
)){
resultValue
=
getBinaryValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Short"
)){
resultValue
=
Short
.
valueOf
(
fieldValue
.
toString
());
}
else
if
(
targetType
.
equals
(
"Integer"
)){
resultValue
=
getIntegerValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Long"
)){
resultValue
=
getLongValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Float"
)){
resultValue
=
getFloatValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Double"
)){
resultValue
=
getDoubleValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"BigDecimal"
)){
resultValue
=
getBigDecimalValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"BigInteger"
)){
resultValue
=
getBigIntegerValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"Timestamp"
)){
resultValue
=
getTimestampValue
(
fieldValue
,
null
);
}
else
if
(
targetType
.
equals
(
"String"
))
{
resultValue
=
getStringValue
(
fieldValue
,
null
);
}
if
(
resultValue
==
null
)
return
null
;
return
resultValue
;
}
public
static
<
T
>
T
valueOf
(
Class
<
T
>
type
,
Object
fieldValue
)
{
return
(
T
)
objectValueOf
(
type
,
fieldValue
);
}
final
static
public
JSONObject
getJSONObjectValue
(
Object
objValue
,
JSONObject
jDefault
)
{
if
(
objValue
==
null
)
{
return
jDefault
;
}
if
(
objValue
instanceof
JSONObject
)
return
(
JSONObject
)
objValue
;
String
strValue
=
objValue
.
toString
();
try
{
return
JSONObject
.
parseObject
(
strValue
);
}
catch
(
Exception
ex
)
{
return
jDefault
;
}
}
final
static
public
JSONArray
getJSONArrayValue
(
Object
objValue
,
JSONArray
jDefault
)
{
if
(
objValue
==
null
)
{
return
jDefault
;
}
if
(
objValue
instanceof
JSONArray
)
return
(
JSONArray
)
objValue
;
String
strValue
=
objValue
.
toString
();
try
{
return
JSONArray
.
parseArray
(
strValue
);
}
catch
(
Exception
ex
)
{
return
jDefault
;
}
}
final
static
public
List
<
String
>
getListValue
(
Object
objValue
)
{
if
(
objValue
==
null
)
{
return
new
ArrayList
<
String
>();
}
JSONArray
arr
=(
getJSONArrayValue
(
objValue
,
null
));
if
(
arr
!=null)
{
List
<
String
>
chk1
=
new
ArrayList
<>();
for
(
int
i
=
0
;
i
<
arr
.
size
();
i
++)
{
if
(
arr
.
get
(
i
)
instanceof
String
)
chk1
.
add
(
arr
.
getString
(
i
));
}
return
chk1
;
}
else
{
return
new
ArrayList
<
String
>();
}
}
final
static
public
Boolean
getBooleanValue
(
Object
objValue
,
Boolean
bDefault
)
{
if
(
objValue
==
null
)
return
bDefault
;
if
(
objValue
instanceof
Boolean
)
{
return
(
Boolean
)
objValue
;
}
return
objValue
.
toString
().
equalsIgnoreCase
(
"true"
)||
objValue
.
toString
().
equals
(
"1"
)||
objValue
.
toString
().
equals
(
"y"
);
}
final
static
public
char
[]
getCharacterValue
(
Object
objValue
,
char
[]
cDefault
)
{
if
(
objValue
==
null
)
return
cDefault
;
return
objValue
.
toString
().
toCharArray
();
}
final
static
public
Double
getDoubleValue
(
Object
objValue
,
Double
dDefault
)
{
if
(
objValue
==
null
)
return
dDefault
;
if
(
objValue
instanceof
Double
)
{
return
(
Double
)
objValue
;
}
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
null
;
strValue
=
strValue
.
replace
(
","
,
""
);
return
Double
.
parseDouble
(
strValue
);
}
final
static
public
int
getIntegerValue
(
Object
objValue
,
Integer
nDefault
)
{
if
(
objValue
==
null
)
{
return
nDefault
;
}
if
(
objValue
instanceof
Integer
)
return
(
Integer
)
objValue
;
if
(
objValue
instanceof
Double
)
{
return
((
Double
)
objValue
).
intValue
();
}
if
(
objValue
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
objValue
).
intValue
();
}
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
nDefault
;
strValue
=
strValue
.
replace
(
","
,
""
);
return
Integer
.
parseInt
(
strValue
);
}
final
static
public
Float
getFloatValue
(
Object
objValue
,
Float
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
Float
)
return
(
Float
)
objValue
;
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
fDefault
;
strValue
=
strValue
.
replace
(
","
,
""
);
return
Float
.
parseFloat
(
strValue
);
}
catch
(
Exception
ex
)
{
return
fDefault
;
}
}
final
static
public
BigDecimal
getBigDecimalValue
(
Object
objValue
,
BigDecimal
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
BigDecimal
){
return
(
BigDecimal
)(
objValue
);
}
if
(
objValue
instanceof
Double
){
return
BigDecimal
.
valueOf
((
Double
)
objValue
);
}
if
(
objValue
instanceof
Long
){
return
BigDecimal
.
valueOf
((
Long
)
objValue
);
}
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
fDefault
;
strValue
=
strValue
.
replace
(
","
,
""
);
return
BigDecimal
.
valueOf
(
Double
.
parseDouble
(
strValue
));
}
catch
(
Exception
ex
)
{
return
fDefault
;
}
}
final
static
public
BigInteger
getBigIntegerValue
(
Object
objValue
,
BigInteger
fDefault
)
{
if
(
objValue
==
null
)
{
return
fDefault
;
}
try
{
if
(
objValue
instanceof
BigInteger
){
return
(
BigInteger
)(
objValue
);
}
else
{
Long
l
=
getLongValue
(
objValue
,
null
);
if
(
l
!=null)
return
BigInteger
.
valueOf
(
l
);
}
}
catch
(
Exception
ex
)
{
}
return
fDefault
;
}
final
static
public
Long
getLongValue
(
Object
objValue
,
Long
nDefault
)
{
if
(
objValue
==
null
)
{
return
nDefault
;
}
try
{
if
(
objValue
instanceof
Long
)
return
(
Long
)
objValue
;
if
(
objValue
instanceof
Integer
)
{
return
((
Integer
)
objValue
).
longValue
();
}
if
(
objValue
instanceof
Double
)
{
return
((
Double
)
objValue
).
longValue
();
}
if
(
objValue
instanceof
BigDecimal
)
{
return
((
BigDecimal
)
objValue
).
longValue
();
}
String
strValue
=
objValue
.
toString
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
nDefault
;
strValue
=
strValue
.
replace
(
","
,
""
);
return
Long
.
parseLong
(
strValue
);
}
catch
(
Exception
ex
)
{
return
nDefault
;
}
}
final
static
public
byte
[]
getBinaryValue
(
Object
objValue
,
byte
[]
def
)
{
if
(
objValue
==
null
)
return
def
;
if
(
objValue
instanceof
byte
[]){
return
(
byte
[])
objValue
;
}
if
(
objValue
instanceof
String
){
return
Base64
.
getDecoder
().
decode
((
String
)
objValue
);
}
return
def
;
}
/**
*
转换对象值到时间值
*
*
@
param
objValue
*
@
return
*
@
*/
final
static
public
java
.
sql
.
Timestamp
getTimestampValue
(
Object
objValue
,
java
.
sql
.
Timestamp
tDefault
)
{
if
(
objValue
==
null
)
return
tDefault
;
if
(
objValue
instanceof
java
.
sql
.
Timestamp
)
{
java
.
sql
.
Timestamp
ti
=
(
java
.
sql
.
Timestamp
)
objValue
;
return
ti
;
}
if
(
objValue
instanceof
java
.
sql
.
Date
)
{
java
.
sql
.
Date
date
=
(
java
.
sql
.
Date
)
objValue
;
return
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
}
if
(
objValue
instanceof
java
.
util
.
Date
)
{
java
.
util
.
Date
date
=
(
java
.
util
.
Date
)
objValue
;
return
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
}
if
(
objValue
instanceof
String
)
{
String
strValue
=
(
String
)
objValue
;
strValue
=
strValue
.
trim
();
if
(
StringUtils
.
isEmpty
(
strValue
))
return
null
;
try
{
java
.
util
.
Date
date
=
parse
((
String
)
objValue
);
return
new
java
.
sql
.
Timestamp
(
date
.
getTime
());
}
catch
(
Exception
ex
)
{
return
tDefault
;
}
}
if
(
objValue
instanceof
Long
)
{
Long
lValue
=
(
Long
)
objValue
;
return
new
java
.
sql
.
Timestamp
(
lValue
);
}
if
(
objValue
instanceof
Integer
)
{
int
lValue
=
(
int
)
objValue
;
return
new
java
.
sql
.
Timestamp
(
lValue
);
}
return
tDefault
;
}
public
static
Object
testDateTime
(
String
strInput
)
throws
Exception
{
return
testDateTime
(
strInput
,
null
);
}
/**
*
转换文本值到日期时间
*
*
@
param
strInput
*
@
param
timeZone
*
@
return
*
@
*/
public
static
Object
testDateTime
(
String
strInput
,
TimeZone
timeZone
)
throws
Exception
{
if
(
StringUtils
.
isEmpty
(
strInput
))
return
null
;
Date
dtDate
=
parse
(
strInput
,
timeZone
);
java
.
sql
.
Timestamp
retDate
=
new
java
.
sql
.
Timestamp
(
dtDate
.
getTime
());
return
retDate
;
}
/**
*
转换字符串到时间对象
*
*
@
param
strTimeString
*
@
return
*
@
throws
ParseException
*
@
*/
public
static
Date
parse
(
String
strTimeString
)
throws
ParseException
,
Exception
{
return
parse
(
strTimeString
,
null
);
}
/**
*
分析时间串
*
*
@
param
strTimeString
MM
/
dd
/
yy
yy
-
MM
-
dd
HH
:
mm
:
ss
格式
*
@
param
timeZone
*
@
return
*
@
throws
ParseException
*
@
*/
public
static
Date
parse
(
String
strTimeString
,
TimeZone
timeZone
)
throws
ParseException
,
Exception
{
strTimeString
=
strTimeString
.
trim
();
if
(
StringUtils
.
isEmpty
(
strTimeString
)){
throw
new
Exception
(
"unknown date(time) string"
);
}
if
(
strTimeString
.
indexOf
(
"Z"
)
!=-1){
//
有时区
String
[]
parts
=
strTimeString
.
split
(
"[Z]"
);
if
(
parts
.
length
>=
1
){
strTimeString
=
parts
[
0
];
}
if
(
parts
.
length
>=
2
){
if
(
timeZone
==
null
){
if
(
!StringUtils.isEmpty(parts[1])){
timeZone
=
TimeZone
.
getTimeZone
(
parts
[
1
]);
}
}
}
}
//
判断是长数据还是短数据
String
strPart
[]
=
null
;
if
(
strTimeString
.
indexOf
(
"T"
)
!=-1){
strPart
=
strTimeString
.
split
(
"[T]"
);
}
else
strPart
=
strTimeString
.
split
(
" "
);
if
(
strPart
.
length
==
2
)
{
//
两个部分
String
strDate
=
""
;
String
strTime
=
""
;
if
(
strPart
[
0
].
indexOf
(
":"
)
!= -1) {
strTime
=
strPart
[
0
];
strDate
=
strPart
[
1
];
}
else
{
strTime
=
strPart
[
1
];
strDate
=
strPart
[
0
];
}
strDate
=
strDate
.
trim
();
strTime
=
strTime
.
trim
();
strDate
=
getFormatDateString
(
strDate
);
strTime
=
getFormatTimeString
(
strTime
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm:ss"
);
if
(
timeZone
!= null) {
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strDate
+
" "
+
strTime
);
}
else
{
//
一个部分
if
(
strTimeString
.
indexOf
(
":"
)
!= -1) {
//
时间
strTimeString
=
getFormatTimeString
(
strTimeString
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"HH:mm:ss"
);
if
(
timeZone
!= null) {
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strTimeString
);
}
else
{
//
作为日期处理
strTimeString
=
getFormatDateString
(
strTimeString
);
DateFormat
dtFormat
=
new
SimpleDateFormat
(
"yyyy-MM-dd"
);
if
(
timeZone
!= null) {
dtFormat
.
setTimeZone
(
timeZone
);
}
return
dtFormat
.
parse
(
strTimeString
);
}
}
}
/**
*
获取时间格式化串
*
*
@
param
strOrigin
*
@
return
*/
private
static
String
getFormatTimeString
(
String
strOrigin
)
{
int
nDotPos
=
strOrigin
.
indexOf
(
"."
);
if
(
nDotPos
!= -1) {
strOrigin
=
strOrigin
.
substring
(
0
,
nDotPos
);
}
Object
Time
[]
=
new
Object
[
3
];
Time
[
0
]
=
0
;
Time
[
1
]
=
0
;
Time
[
2
]
=
0
;
String
timepart
[]
=
strOrigin
.
split
(
":"
);
int
nTimePartLength
=
timepart
.
length
;
if
(
nTimePartLength
>
3
)
{
nTimePartLength
=
3
;
}
for
(
int
i
=
0
;
i
<
nTimePartLength
;
i
++)
{
Time
[
i
]
=
Integer
.
parseInt
(
timepart
[
i
]);
}
return
String
.
format
(
"%1$02d:%2$02d:%3$02d"
,
Time
);
}
/**
*
获取时日期格式化串
*
*
@
param
strOrigin
*
@
return
*
@
*/
private
static
String
getFormatDateString
(
String
strOrigin
)
throws
Exception
{
return
getFormatDateString
(
strOrigin
,
true
);
}
/**
*
获取时日期格式化串
*
*
@
param
strOrigin
*
@
param
bAdv
*
@
return
*
@
*/
private
static
String
getFormatDateString
(
String
strOrigin
,
boolean
bAdv
)
throws
Exception
{
Object
Date
[]
=
new
Object
[
3
];
Date
[
0
]
=
1970
;
Date
[
1
]
=
1
;
Date
[
2
]
=
1
;
if
(
strOrigin
.
indexOf
(
"-"
)
!= -1) {
String
datePart
[]
=
strOrigin
.
split
(
"-"
);
if
(
datePart
.
length
>=
1
)
{
Date
[
0
]
=
Integer
.
parseInt
(
datePart
[
0
]);
}
if
(
datePart
.
length
>=
2
)
{
Date
[
1
]
=
Integer
.
parseInt
(
datePart
[
1
]);
}
if
(
datePart
.
length
>=
3
)
{
Date
[
2
]
=
Integer
.
parseInt
(
datePart
[
2
]);
}
}
else
if
(
strOrigin
.
indexOf
(
"/"
)
!= -1) {
String
datePart
[]
=
strOrigin
.
split
(
"/"
);
if
(
datePart
.
length
>=
1
)
{
Date
[
1
]
=
Integer
.
parseInt
(
datePart
[
0
]);
}
if
(
datePart
.
length
>=
2
)
{
Date
[
2
]
=
Integer
.
parseInt
(
datePart
[
1
]);
}
if
(
datePart
.
length
>=
3
)
{
Date
[
0
]
=
Integer
.
parseInt
(
datePart
[
2
]);
}
}
else
{
if
(
bAdv
)
{
strOrigin
=
strOrigin
.
replace
(
"."
,
"-"
);
strOrigin
=
strOrigin
.
replace
(
"日"
,
""
);
strOrigin
=
strOrigin
.
replace
(
"天"
,
""
);
strOrigin
=
strOrigin
.
replace
(
"年"
,
"-"
);
strOrigin
=
strOrigin
.
replace
(
"月"
,
"-"
);
return
getFormatDateString
(
strOrigin
,
false
);
}
else
throw
new
Exception
(
"无法识别的时间字符串,"
+
strOrigin
);
}
return
String
.
format
(
"%1$04d-%2$02d-%3$02d"
,
Date
);
}
public
static
Timestamp
getBeginDate
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
cl
.
set
(
1900
,
1
,
1
);
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
public
static
Timestamp
getEndDate
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
cl
.
set
(
2100
,
12
,
31
,
23
,
59
,
59
);
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
public
static
Timestamp
getNow
()
{
Calendar
cl
=
Calendar
.
getInstance
(
TimeZone
.
getTimeZone
(
"GMT+8"
));
return
new
Timestamp
(
cl
.
getTime
().
getTime
());
}
}
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录