Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
jinli gu
Springboot Plus
Commits
94ebe838
Commit
94ebe838
authored
Sep 20, 2019
by
zengchao
Browse files
-
parent
2c1d735a
Changes
9
Hide whitespace changes
Inline
Side-by-side
plus-admin/admin-console/src/test/java/CustomBeanProcessorTest.java
View file @
94ebe838
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.http.HttpUtil
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONArray
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONObject
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
...
@@ -7,6 +9,7 @@ import com.ibeetl.admin.core.conf.handler.ZonedDateTimeTypeHandler;
...
@@ -7,6 +9,7 @@ import com.ibeetl.admin.core.conf.handler.ZonedDateTimeTypeHandler;
import
com.ibeetl.admin.core.dao.CoreFunctionDao
;
import
com.ibeetl.admin.core.dao.CoreFunctionDao
;
import
com.ibeetl.admin.core.entity.CoreRoute
;
import
com.ibeetl.admin.core.entity.CoreRoute
;
import
com.ibeetl.admin.core.entity.CoreRouteMeta
;
import
com.ibeetl.admin.core.entity.CoreRouteMeta
;
import
com.ibeetl.admin.core.util.CacheUtil
;
import
java.time.ZonedDateTime
;
import
java.time.ZonedDateTime
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -89,15 +92,13 @@ public class CustomBeanProcessorTest {
...
@@ -89,15 +92,13 @@ public class CustomBeanProcessorTest {
@Test
@Test
public
void
maptest
()
{
public
void
maptest
()
{
List
<
CoreRoute
>
routesList
=
coreFunctionDao
.
getAllRoutes
();
System
.
out
.
println
(
routesList
);
System
.
out
.
println
(
JSONUtil
.
toJsonPrettyStr
(
resultMappping
));
GridMapping
gridMapping
=
new
GridMapping
(
resultMappping
);
GridMapping
gridMapping
=
new
GridMapping
(
resultMappping
);
GridHeader
gridHeader
=
gridMapping
.
getHeader
();
CacheUtil
.
put
(
"Route_Mapping"
,
gridMapping
);
System
.
out
.
println
(
gridHeader
);
GridRow
gridRow
=
GridRow
.
generateRowInnerBox
(
gridHeader
);
List
<
CoreRoute
>
routesList
=
coreFunctionDao
.
getAllRoutes
();
System
.
out
.
println
(
gridRow
);
System
.
out
.
println
(
routesList
);
System
.
out
.
println
(
JSONUtil
.
toJsonPrettyStr
(
resultMappping
));
}
}
}
}
plus-admin/admin-console/src/test/java/processor/JsonBeanProcessor.java
View file @
94ebe838
package
processor
;
package
processor
;
import
com.ibeetl.admin.core.util.CacheUtil
;
import
java.beans.PropertyDescriptor
;
import
java.lang.reflect.Method
;
import
java.sql.ResultSet
;
import
java.sql.ResultSetMetaData
;
import
java.sql.SQLException
;
import
org.beetl.sql.core.BeetlSQLException
;
import
org.beetl.sql.core.SQLManager
;
import
org.beetl.sql.core.SQLManager
;
import
org.beetl.sql.core.Tail
;
import
org.beetl.sql.core.annotatoin.builder.AttributeBuilderHolder
;
import
org.beetl.sql.core.annotatoin.builder.AttributeSelectBuilder
;
import
org.beetl.sql.core.db.ClassAnnotation
;
import
org.beetl.sql.core.db.DBStyle
;
import
org.beetl.sql.core.kit.BeanKit
;
import
org.beetl.sql.core.mapping.BeanProcessor
;
import
org.beetl.sql.core.mapping.BeanProcessor
;
import
org.beetl.sql.core.mapping.type.JavaSqlTypeHandler
;
import
org.beetl.sql.core.mapping.type.TypeParameter
;
import
resultmap.GridMapping
;
public
class
JsonBeanProcessor
extends
BeanProcessor
{
public
class
JsonBeanProcessor
extends
BeanProcessor
{
public
JsonBeanProcessor
(
SQLManager
sm
)
{
public
JsonBeanProcessor
(
SQLManager
sm
)
{
super
(
sm
);
super
(
sm
);
}
}
/** 创建 一个新的对象,并从ResultSet初始化 */
@Override
protected
<
T
>
T
createBean
(
String
sqlId
,
ResultSet
rs
,
Class
<
T
>
type
,
PropertyDescriptor
[]
props
,
int
[]
columnToProperty
)
throws
SQLException
{
GridMapping
gridMapping
=
(
GridMapping
)
CacheUtil
.
get
(
"Route_Mapping"
);
T
bean
=
this
.
newInstance
(
type
);
ResultSetMetaData
meta
=
rs
.
getMetaData
();
TypeParameter
tp
=
new
TypeParameter
(
sqlId
,
this
.
dbName
,
type
,
rs
,
meta
,
1
);
for
(
int
i
=
1
;
i
<
columnToProperty
.
length
;
i
++)
{
// Array.fill数组为-1 ,-1则无对应name
tp
.
setIndex
(
i
);
if
(
columnToProperty
[
i
]
==
PROPERTY_NOT_FOUND
)
{
String
key
=
rs
.
getMetaData
().
getColumnLabel
(
i
);
if
((
dbType
==
DBStyle
.
DB_ORACLE
||
dbType
==
DBStyle
.
DB_SQLSERVER
)
&&
key
.
equalsIgnoreCase
(
"beetl_rn"
))
{
// sql server 特殊处理,sql'server的翻页使用了额外列作为翻页参数,需要过滤
continue
;
}
if
(
bean
instanceof
Tail
)
{
Tail
bean2
=
(
Tail
)
bean
;
Object
value
=
noMappingValue
(
tp
);
key
=
this
.
nc
.
getPropertyName
(
type
,
key
);
bean2
.
set
(
key
,
value
);
}
else
{
Method
m
=
BeanKit
.
getTailMethod
(
type
);
// 使用指定方法赋值
if
(
m
!=
null
)
{
Object
value
=
noMappingValue
(
tp
);
key
=
this
.
nc
.
getPropertyName
(
type
,
key
);
try
{
m
.
invoke
(
bean
,
key
,
value
);
}
catch
(
Exception
ex
)
{
throw
new
BeetlSQLException
(
BeetlSQLException
.
TAIL_CALL_ERROR
,
ex
);
}
}
else
{
// 忽略这个结果集
}
}
continue
;
}
// columnToProperty[i]取出对应的在PropertyDescriptor[]中的下标
PropertyDescriptor
prop
=
props
[
columnToProperty
[
i
]];
Class
<?>
propType
=
prop
.
getPropertyType
();
tp
.
setTarget
(
propType
);
ClassAnnotation
ca
=
ClassAnnotation
.
getClassAnnotation
(
type
);
Object
value
=
null
;
if
(!
ca
.
getColHandlers
().
isEmpty
())
{
AttributeBuilderHolder
holder
=
(
AttributeBuilderHolder
)
ca
.
getColHandlers
().
get
(
prop
.
getName
());
if
(
holder
!=
null
&&
holder
.
supportSelectMapping
())
{
value
=
((
AttributeSelectBuilder
)
holder
.
getInstance
())
.
toObject
(
this
.
sm
,
holder
.
getBeanAnnotaton
(),
sqlId
,
tp
,
prop
);
this
.
callSetter
(
bean
,
prop
,
value
,
propType
);
continue
;
}
}
JavaSqlTypeHandler
handler
=
this
.
handlers
.
get
(
propType
);
if
(
handler
==
null
)
{
handler
=
this
.
defaultHandler
;
}
value
=
handler
.
getValue
(
tp
);
this
.
callSetter
(
bean
,
prop
,
value
,
propType
);
}
return
bean
;
}
}
}
plus-admin/admin-console/src/test/java/resultmap/GridColumn.java
View file @
94ebe838
...
@@ -3,6 +3,7 @@ package resultmap;
...
@@ -3,6 +3,7 @@ package resultmap;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.Map.Entry
;
import
java.util.Map.Entry
;
...
@@ -14,7 +15,7 @@ import java.util.Set;
...
@@ -14,7 +15,7 @@ import java.util.Set;
* 包含:值映射map、映射类型、最关键的obj key<br>
* 包含:值映射map、映射类型、最关键的obj key<br>
* objkey 决定了数据库结果集的多条重复记录会被唯一记录成一个对象。
* objkey 决定了数据库结果集的多条重复记录会被唯一记录成一个对象。
*/
*/
public
class
GridColumn
{
public
class
GridColumn
implements
Serializable
{
/** 对应的属性与数据库中值的映射,用于map to Bean 转换 */
/** 对应的属性与数据库中值的映射,用于map to Bean 转换 */
Map
<
String
,
Object
>
beanMap
;
Map
<
String
,
Object
>
beanMap
;
...
...
plus-admin/admin-console/src/test/java/resultmap/GridContainer.java
deleted
100644 → 0
View file @
2c1d735a
package
resultmap
;
import
cn.hutool.core.collection.CollUtil
;
import
java.util.List
;
/** 网格容器,仅仅存放网格行,也只存放网格行 */
public
class
GridContainer
{
List
<
GridRow
>
gridRows
=
CollUtil
.
newArrayList
();
int
count
;
GridContainer
parentContainer
;
public
List
<
GridRow
>
getGridRows
()
{
return
gridRows
;
}
public
void
setGridRows
(
List
<
GridRow
>
gridRows
)
{
this
.
gridRows
=
gridRows
;
}
public
int
getCount
()
{
return
count
;
}
public
void
setCount
(
int
count
)
{
this
.
count
=
count
;
}
public
GridContainer
getParentContainer
()
{
return
parentContainer
;
}
public
void
setParentContainer
(
GridContainer
parentContainer
)
{
this
.
parentContainer
=
parentContainer
;
}
}
plus-admin/admin-console/src/test/java/resultmap/GridHeader.java
View file @
94ebe838
...
@@ -7,6 +7,7 @@ import static java.util.Optional.ofNullable;
...
@@ -7,6 +7,7 @@ import static java.util.Optional.ofNullable;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.ClassUtil
;
import
cn.hutool.core.util.ClassUtil
;
import
java.io.Serializable
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -17,7 +18,7 @@ import java.util.Set;
...
@@ -17,7 +18,7 @@ import java.util.Set;
* 网格头,保存了属性与列的映射关系,以及映射的java类型。<br>
* 网格头,保存了属性与列的映射关系,以及映射的java类型。<br>
* 内嵌的网格头,内嵌网格头的映射java类型,是否是映射至List集合字段
* 内嵌的网格头,内嵌网格头的映射java类型,是否是映射至List集合字段
*/
*/
public
class
GridHeader
{
public
class
GridHeader
implements
Serializable
{
/** java属性名与数据库列名的对应。顺序:prop:column */
/** java属性名与数据库列名的对应。顺序:prop:column */
Map
<
String
,
String
>
javaToJdbcMap
;
Map
<
String
,
String
>
javaToJdbcMap
;
...
...
plus-admin/admin-console/src/test/java/resultmap/GridMapping.java
View file @
94ebe838
...
@@ -3,14 +3,16 @@ package resultmap;
...
@@ -3,14 +3,16 @@ package resultmap;
import
static
cn
.
hutool
.
core
.
util
.
StrUtil
.
EMPTY
;
import
static
cn
.
hutool
.
core
.
util
.
StrUtil
.
EMPTY
;
import
static
java
.
util
.
Optional
.
ofNullable
;
import
static
java
.
util
.
Optional
.
ofNullable
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.core.lang.Assert
;
import
cn.hutool.json.JSON
;
import
cn.hutool.json.JSON
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
/** 网格映射数据结构: 包含一个网格头 {@link GridHeader} */
/** 网格映射数据结构: 包含一个网格头 {@link GridHeader} */
public
class
GridMapping
{
public
class
GridMapping
implements
Serializable
{
/** 映射id */
/** 映射id */
String
mappingId
;
String
mappingId
;
...
@@ -20,7 +22,7 @@ public class GridMapping {
...
@@ -20,7 +22,7 @@ public class GridMapping {
/** 网格头 */
/** 网格头 */
GridHeader
header
;
GridHeader
header
;
List
<
GridRow
>
nestedRows
;
List
<
GridRow
>
nestedRows
=
CollUtil
.
newArrayList
()
;
public
GridMapping
(
Map
<
String
,
Object
>
resultMapping
)
{
public
GridMapping
(
Map
<
String
,
Object
>
resultMapping
)
{
JSON
parse
=
JSONUtil
.
parse
(
resultMapping
);
JSON
parse
=
JSONUtil
.
parse
(
resultMapping
);
...
@@ -65,4 +67,10 @@ public class GridMapping {
...
@@ -65,4 +67,10 @@ public class GridMapping {
public
void
setNestedRows
(
List
<
GridRow
>
nestedRows
)
{
public
void
setNestedRows
(
List
<
GridRow
>
nestedRows
)
{
this
.
nestedRows
=
nestedRows
;
this
.
nestedRows
=
nestedRows
;
}
}
public
GridRow
nextRow
(){
GridRow
row
=
GridRow
.
generateRowByHeader
(
this
.
header
);
this
.
nestedRows
.
add
(
row
);
return
row
;
}
}
}
plus-admin/admin-console/src/test/java/resultmap/GridRow.java
View file @
94ebe838
package
resultmap
;
package
resultmap
;
import
static
java
.
util
.
Optional
.
ofNullable
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.collection.CollUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Optional
;
import
javax.swing.text.html.Option
;
/**
/**
* 网格行,包含一个个网格列<br>
* 网格行,包含一个个网格列<br>
* 一行一个对象,或者java类中的一个对象字段
* 一行一个对象,或者java类中的一个对象字段
*/
*/
public
class
GridRow
{
public
class
GridRow
implements
Serializable
{
/** 包含的列 */
/** 包含的列 */
List
<
GridColumn
>
nestedColumns
=
CollUtil
.<
GridColumn
>
newArrayList
();
List
<
GridColumn
>
nestedColumns
=
CollUtil
.<
GridColumn
>
newArrayList
();
...
@@ -69,7 +66,7 @@ public class GridRow {
...
@@ -69,7 +66,7 @@ public class GridRow {
*
*
* @return
* @return
*/
*/
public
static
GridRow
generateRow
InnerBox
(
GridHeader
gridHeader
)
{
public
static
GridRow
generateRow
ByHeader
(
GridHeader
gridHeader
)
{
if
(
ObjectUtil
.
isNull
(
gridHeader
))
{
if
(
ObjectUtil
.
isNull
(
gridHeader
))
{
return
null
;
return
null
;
}
}
...
@@ -81,7 +78,7 @@ public class GridRow {
...
@@ -81,7 +78,7 @@ public class GridRow {
List
<
GridHeader
>
headers
=
gridHeader
.
getNestedHeaders
();
List
<
GridHeader
>
headers
=
gridHeader
.
getNestedHeaders
();
for
(
GridHeader
header
:
headers
)
{
for
(
GridHeader
header
:
headers
)
{
GridColumn
containerColumn
=
new
GridColumn
();
GridColumn
containerColumn
=
new
GridColumn
();
GridRow
nestedRow
=
generateRow
InnerBox
(
header
);
GridRow
nestedRow
=
generateRow
ByHeader
(
header
);
containerColumn
.
getNestedRows
().
add
(
nestedRow
);
containerColumn
.
getNestedRows
().
add
(
nestedRow
);
nestedRow
.
setBelongColumn
(
containerColumn
);
nestedRow
.
setBelongColumn
(
containerColumn
);
...
...
plus-admin/admin-core/pom.xml
View file @
94ebe838
...
@@ -133,5 +133,10 @@
...
@@ -133,5 +133,10 @@
<artifactId>
hutool-all
</artifactId>
<artifactId>
hutool-all
</artifactId>
<version>
4.6.4
</version>
<version>
4.6.4
</version>
</dependency>
</dependency>
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
<version>
2.8.0
</version>
</dependency>
</dependencies>
</dependencies>
</project>
</project>
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/CacheUtil.java
0 → 100644
View file @
94ebe838
package
com.ibeetl.admin.core.util
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
public
class
CacheUtil
{
private
static
final
Cache
CACHE
=
Caffeine
.
newBuilder
().
maximumSize
(
1024
).
recordStats
().
build
();
public
static
void
put
(
Object
key
,
Object
value
)
{
CACHE
.
put
(
key
,
value
);
}
public
static
Object
get
(
Object
key
)
{
return
CACHE
.
getIfPresent
(
key
);
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment