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
a3d658f6
Commit
a3d658f6
authored
Sep 25, 2019
by
trumansdo
Browse files
完成结果集映射。
待完善:结果集中间处理结果应该进行缓存,实现可重复利用 待提交:结果集映射的设计思路文档 Signed-off-by:
trumansdo
<
1012243881@qq.com
>
parent
6499375c
Changes
3
Hide whitespace changes
Inline
Side-by-side
plus-admin/admin-console/src/main/resources/btsql-ext.properties
View file @
a3d658f6
DELIMITER_PLACEHOLDER_START
=
#
DELIMITER_PLACEHOLDER_START
=
#
DELIMITER_PLACEHOLDER_END=#
DELIMITER_PLACEHOLDER_END=#
DELIMITER_STATEMENT_START
=
--:
DELIMITER_STATEMENT_START
=
--:
DELIMITER_STATEMENT_END
=
--
DELIMITER_STATEMENT_END
=
#\u51FD\u6570\u6CE8\u518C
#\u51FD\u6570\u6CE8\u518C
FN.isEmpty
=
org.beetl.ext.fn.EmptyExpressionFunction
FN.isEmpty
=
org.beetl.ext.fn.EmptyExpressionFunction
FN.isNotEmpty
=
org.beetl.ext.fn.IsNotEmptyExpressionFunction
FN.isNotEmpty
=
org.beetl.ext.fn.IsNotEmptyExpressionFunction
...
...
plus-admin/admin-core/src/main/java/com/ibeetl/admin/core/util/beetl/MappingFunction.java
View file @
a3d658f6
package
com.ibeetl.admin.core.util.beetl
;
package
com.ibeetl.admin.core.util.beetl
;
import
cn.hutool.core.map.MapUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.ObjectUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.core.util.StrUtil
;
import
cn.hutool.json.JSONUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.ibeetl.admin.core.util.CacheUtil
;
import
com.ibeetl.admin.core.util.CacheUtil
;
import
java.io.IOException
;
import
java.io.StringWriter
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
import
org.beetl.core.Context
;
import
org.beetl.core.Context
;
import
org.beetl.core.Function
;
import
org.beetl.core.Function
;
import
org.beetl.core.GroupTemplate
;
import
org.beetl.core.ResourceLoader
;
import
org.beetl.core.resource.StringTemplateResourceLoader
;
import
org.beetl.sql.core.SQLManager
;
import
org.beetl.sql.core.SQLResult
;
public
class
MappingFunction
implements
Function
{
public
class
MappingFunction
implements
Function
{
private
static
final
StringWriter
STRING_WRITER
=
new
StringWriter
();
private
static
final
StringTemplateResourceLoader
STRING_TEMPLATE_RESOURCE_LOADER
=
new
StringTemplateResourceLoader
();
@Override
@Override
public
Object
call
(
Object
[]
paras
,
Context
ctx
)
{
public
Object
call
(
Object
[]
paras
,
Context
ctx
)
{
Object
sqlid
=
ctx
.
getGlobal
(
"_id"
);
String
sqlSegmentId
=
(
String
)
paras
[
0
];
if
(
ObjectUtil
.
isNull
(
CacheUtil
.
get
(
sqlid
))){
Map
inputParas
=
ctx
.
globalVar
;
throw
new
RuntimeException
(
StrUtil
.
format
(
"【{}】只能存在唯一一个映射"
,
sqlid
));
if
(
paras
.
length
==
2
)
{
Map
map
=
(
Map
)
paras
[
1
];
map
.
putAll
(
inputParas
);
inputParas
=
map
;
}
SQLManager
sm
=
(
SQLManager
)
ctx
.
getGlobal
(
"_manager"
);
// 保留,免得被覆盖
List
list
=
(
List
)
ctx
.
getGlobal
(
"_paras"
);
/*获取参数指定的sqlid所在的md文件名*/
String
file
=
this
.
getParentId
(
ctx
);
SQLResult
result
;
if
(
sqlSegmentId
.
indexOf
(
"."
)==-
1
){
/*证明是同一个md文件的sql段*/
result
=
sm
.
getSQLResult
(
file
+
"."
+
sqlSegmentId
,
inputParas
,
ctx
);
}
else
{
/*另一个md文件的sql段*/
result
=
sm
.
getSQLResult
(
sqlSegmentId
,
inputParas
,
ctx
);
}
}
Map
json
=
JSONUtil
.
parseObj
(
paras
[
0
]);
CacheUtil
.
put
(
sqlid
,
json
);
// 追加参数
list
.
addAll
(
result
.
jdbcPara
);
ctx
.
set
(
"_paras"
,
list
);
GroupTemplate
groupTemplate
=
sm
.
getBeetl
().
getGroupTemplate
();
Map
rsMap
=
groupTemplate
.
runScript
(
result
.
jdbcSql
,
inputParas
,
STRING_WRITER
,
STRING_TEMPLATE_RESOURCE_LOADER
);
if
(
MapUtil
.
isNotEmpty
(
rsMap
))
{
String
currentSqlId
=
ctx
.
getGlobal
(
"_id"
).
toString
();
CacheUtil
.
put
(
currentSqlId
,
rsMap
.
values
().
stream
().
findFirst
().
get
());
}
return
StrUtil
.
EMPTY
;
return
StrUtil
.
EMPTY
;
}
}
private
String
getParentId
(
Context
ctx
)
{
String
id
=
(
String
)
ctx
.
getGlobal
(
"_id"
);
int
index
=
id
.
lastIndexOf
(
"."
);
String
file
=
id
.
substring
(
0
,
index
);
return
file
;
}
}
}
plus-admin/admin-core/src/main/resources/sql/core/coreFunction.md
View file @
a3d658f6
getAllRoutes
getAllRoutes
===
===
select router.id,
router.PARENT_ID,
```
sql
ifnull(router.ACCESS_URL, '/error/404') path,
select
router
.
id
,
router.NAME,
router
.
PARENT_ID
,
menu.NAME title,
ifnull
(
router
.
ACCESS_URL
,
'/error/404'
)
path
,
menu.ICON,
router
.
NAME
,
ifnull(menu.SEQ, 999999) seq,
menu
.
NAME
title
,
crm.ROLE_ID
menu
.
ICON
,
from core_function router
ifnull
(
menu
.
SEQ
,
999999
)
seq
,
left join core_menu menu on menu.FUNCTION_ID = router.ID
crm
.
ROLE_ID
left join core_role_menu crm on crm.MENU_ID = menu.id
from
core_function
router
order by router.ID
left
join
core_menu
menu
on
menu
.
FUNCTION_ID
=
router
.
ID
--:
left
join
core_role_menu
crm
on
crm
.
MENU_ID
=
menu
.
id
var route_mapping={
order
by
router
.
ID
#
text
(
mapping
(
"RouteMapping"
))
#
```
RouteMapping
===
```
javascript
var
route_mapping_var
=
{
"
mapping
"
:
{
"
mapping
"
:
{
"
path
"
:
"
path
"
,
"
path
"
:
"
path
"
,
"
meta
"
:
{
"
meta
"
:
{
...
@@ -35,6 +41,7 @@ var route_mapping={
...
@@ -35,6 +41,7 @@ var route_mapping={
},
},
"
id
"
:
"
core_route_map
"
"
id
"
:
"
core_route_map
"
};
};
mapping(route_mapping);
```
--
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