Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdst
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
1
议题
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdst
提交
603928d6
提交
603928d6
编写于
3月 05, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
entity
上级
14e35bc0
变更
8
显示空白字符变更
内嵌
并排
正在显示
8 个修改的文件
包含
250 行增加
和
4 行删除
+250
-4
DbEntityMapper.java
...ava/cn/ibizlab/core/extensions/mapper/DbEntityMapper.java
+17
-0
EntityModel.java
...a/cn/ibizlab/core/lite/extensions/domain/EntityModel.java
+97
-0
FieldModel.java
...va/cn/ibizlab/core/lite/extensions/domain/FieldModel.java
+7
-0
CommonEntityService.java
...lab/core/lite/extensions/service/CommonEntityService.java
+4
-0
DbEntityService.java
...ibizlab/core/lite/extensions/service/DbEntityService.java
+56
-0
LiteDataService.java
...ibizlab/core/lite/extensions/service/LiteDataService.java
+25
-0
MongoEntityService.java
...zlab/core/lite/extensions/service/MongoEntityService.java
+14
-0
DstCoreResource.java
.../java/cn/ibizlab/api/rest/extensions/DstCoreResource.java
+30
-4
未找到文件。
ibzdst-core/src/main/java/cn/ibizlab/core/extensions/mapper/DbEntityMapper.java
浏览文件 @
603928d6
package
cn
.
ibizlab
.
core
.
extensions
.
mapper
;
package
cn
.
ibizlab
.
core
.
extensions
.
mapper
;
import
cn.ibizlab.core.lite.extensions.domain.EntityModel
;
import
cn.ibizlab.core.lite.extensions.domain.EntityObj
;
import
cn.ibizlab.core.lite.extensions.domain.EntityObj
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.conditions.Wrapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
com.baomidou.mybatisplus.core.mapper.BaseMapper
;
import
org.apache.ibatis.annotations.Insert
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
java.util.List
;
import
java.util.List
;
...
@@ -12,4 +14,19 @@ public interface DbEntityMapper extends BaseMapper<EntityObj>{
...
@@ -12,4 +14,19 @@ public interface DbEntityMapper extends BaseMapper<EntityObj>{
List
<
EntityObj
>
search
(
@Param
(
"sql"
)
String
sql
,
@Param
(
"ew"
)
Wrapper
<
EntityObj
>
wrapper
);
List
<
EntityObj
>
search
(
@Param
(
"sql"
)
String
sql
,
@Param
(
"ew"
)
Wrapper
<
EntityObj
>
wrapper
);
Integer
searchCount
(
@Param
(
"sql"
)
String
sql
,
@Param
(
"ew"
)
Wrapper
<
EntityObj
>
wrapper
);
Integer
searchCount
(
@Param
(
"sql"
)
String
sql
,
@Param
(
"ew"
)
Wrapper
<
EntityObj
>
wrapper
);
@Insert
({
"<script> "
+
" MERGE INTO ${model.tableName} T1\n"
+
" USING (\n"
+
"<foreach collection=\"list\" item=\"item\" index=\"index\" separator=\"UNION ALL\">\n"
+
" SELECT ${model.mergeColumnSegment} FROM dual\n"
+
"</foreach>\n"
+
" ) T2 \n ${model.mergeSegment}"
+
"</script>"
})
boolean
saveBatch
(
@Param
(
"model"
)
EntityModel
model
,
@Param
(
"list"
)
List
<
EntityObj
>
list
);
@Insert
({
"<script> "
+
" MERGE INTO ${model.tableName} T1\n"
+
" USING (\n"
+
" SELECT ${model.mergeColumnSegment} FROM dual\n"
+
" ) T2 \n ${model.mergeSegment}"
+
"</script>"
})
boolean
save
(
@Param
(
"model"
)
EntityModel
model
,
@Param
(
"entity"
)
EntityObj
entity
);
}
}
\ No newline at end of file
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/domain/EntityModel.java
浏览文件 @
603928d6
...
@@ -200,6 +200,18 @@ public class EntityModel {
...
@@ -200,6 +200,18 @@ public class EntityModel {
return
unionKeyFields
;
return
unionKeyFields
;
}
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
List
<
FieldModel
>
getKeyFields
()
{
if
(
this
.
getKeyField
()!=
null
&&
this
.
getKeyField
().
isPhysicalField
())
{
List
<
FieldModel
>
keyFields
=
new
ArrayList
<>();
keyFields
.
add
(
getKeyField
());
return
keyFields
;
}
else
return
getUnionKeyFields
();
}
public
FieldModel
getField
(
String
name
)
public
FieldModel
getField
(
String
name
)
{
{
if
(
StringUtils
.
isEmpty
(
name
))
if
(
StringUtils
.
isEmpty
(
name
))
...
@@ -257,6 +269,91 @@ public class EntityModel {
...
@@ -257,6 +269,91 @@ public class EntityModel {
return
""
;
return
""
;
}
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getMergeColumnSegment
()
{
String
sql
=
""
;
boolean
first
=
true
;
for
(
FieldModel
fieldModel:
this
.
getFields
())
{
if
(!
fieldModel
.
isPhysicalField
())
continue
;
if
(
first
)
first
=
false
;
else
sql
+=
","
;
sql
+=(
"#{item."
+
fieldModel
.
getColumnName
().
toUpperCase
()+
"} "
+
fieldModel
.
getColumnName
().
toUpperCase
());
}
return
sql
;
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
String
getMergeSegment
()
{
String
sql
=
""
;
sql
+=
" ON ("
;
boolean
first
=
true
;
for
(
FieldModel
fieldModel:
this
.
getKeyFields
())
{
if
(!
fieldModel
.
isPhysicalField
())
continue
;
if
(
first
)
first
=
false
;
else
sql
+=
" and "
;
sql
+=(
"T1."
+
fieldModel
.
getColumnName
().
toUpperCase
()+
"=T2."
+
fieldModel
.
getColumnName
().
toUpperCase
());
}
sql
+=
")\n"
+
" WHEN NOT MATCHED THEN INSERT("
;
first
=
true
;
for
(
FieldModel
fieldModel:
this
.
getFields
())
{
if
(!
fieldModel
.
isPhysicalField
())
continue
;
if
(
first
)
first
=
false
;
else
sql
+=
","
;
sql
+=(
fieldModel
.
getColumnName
().
toUpperCase
());
}
sql
+=
") VALUES ("
;
first
=
true
;
for
(
FieldModel
fieldModel:
this
.
getFields
())
{
if
(!
fieldModel
.
isPhysicalField
())
continue
;
if
(
first
)
first
=
false
;
else
sql
+=
","
;
sql
+=(
"T2."
+
fieldModel
.
getColumnName
().
toUpperCase
());
}
sql
+=
")\n"
+
" WHEN MATCHED THEN UPDATE SET "
;
first
=
true
;
for
(
FieldModel
fieldModel:
this
.
getFields
())
{
if
(!
fieldModel
.
isPhysicalField
())
continue
;
if
(
fieldModel
.
isKeyField
())
continue
;
if
(
fieldModel
.
isUnionKeyField
())
continue
;
if
(
first
)
first
=
false
;
else
sql
+=
","
;
sql
+=(
"T1."
+
fieldModel
.
getColumnName
().
toUpperCase
()+
"=T2."
+
fieldModel
.
getColumnName
().
toUpperCase
());
}
return
sql
;
}
@JsonIgnore
@JsonIgnore
@JSONField
(
serialize
=
false
)
@JSONField
(
serialize
=
false
)
public
String
getDsName
()
public
String
getDsName
()
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/domain/FieldModel.java
浏览文件 @
603928d6
...
@@ -72,6 +72,13 @@ public class FieldModel {
...
@@ -72,6 +72,13 @@ public class FieldModel {
return
"UPDATEDATE"
.
equals
(
this
.
getField
().
getPredefined
());
return
"UPDATEDATE"
.
equals
(
this
.
getField
().
getPredefined
());
}
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
boolean
isCreateTimeField
()
{
return
"CREATEDATE"
.
equals
(
this
.
getField
().
getPredefined
());
}
@JsonIgnore
@JsonIgnore
@JSONField
(
serialize
=
false
)
@JSONField
(
serialize
=
false
)
public
boolean
isUnionKeyField
()
public
boolean
isUnionKeyField
()
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/CommonEntityService.java
浏览文件 @
603928d6
...
@@ -18,6 +18,10 @@ public interface CommonEntityService {
...
@@ -18,6 +18,10 @@ public interface CommonEntityService {
List
<
EntityObj
>
search
(
String
dsName
,
String
sql
,
QueryFilter
filter
);
List
<
EntityObj
>
search
(
String
dsName
,
String
sql
,
QueryFilter
filter
);
boolean
saveBatch
(
EntityModel
entityModel
,
List
<
EntityObj
>
list
);
boolean
save
(
EntityModel
entityModel
,
EntityObj
entityObj
);
EntityObj
get
(
EntityModel
entityModel
,
EntityObj
entityObj
);
void
processList
(
DataModel
dataModel
,
Timestamp
lastModify
,
LiteDataCallback
callback
);
void
processList
(
DataModel
dataModel
,
Timestamp
lastModify
,
LiteDataCallback
callback
);
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/DbEntityService.java
浏览文件 @
603928d6
...
@@ -146,9 +146,65 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
...
@@ -146,9 +146,65 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
}
}
}
}
@Override
public
boolean
saveBatch
(
EntityModel
entityModel
,
List
<
EntityObj
>
list
)
{
try
{
dstDataSourceService
.
initDataSource
(
entityModel
.
getDsName
());
DynamicDataSourceContextHolder
.
push
(
entityModel
.
getDsName
());
list
.
forEach
(
entityObj
->
{
entityObj
.
keySet
().
forEach
(
key
->
{
if
(!
key
.
toUpperCase
().
equals
(
key
))
entityObj
.
put
(
key
.
toUpperCase
(),
entityObj
.
get
(
key
));
});
});
return
baseMapper
.
saveBatch
(
entityModel
,
list
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"详细错误信息:"
+
ex
.
getMessage
()
+
", 执行sql:"
+
entityModel
.
getTableName
());
return
false
;
}
finally
{
DynamicDataSourceContextHolder
.
poll
();
}
}
@Override
public
boolean
save
(
EntityModel
entityModel
,
EntityObj
entityObj
)
{
try
{
dstDataSourceService
.
initDataSource
(
entityModel
.
getDsName
());
DynamicDataSourceContextHolder
.
push
(
entityModel
.
getDsName
());
entityObj
.
keySet
().
forEach
(
key
->
{
if
(!
key
.
toUpperCase
().
equals
(
key
))
entityObj
.
put
(
key
.
toUpperCase
(),
entityObj
.
get
(
key
));
});
return
baseMapper
.
save
(
entityModel
,
entityObj
);
}
catch
(
Exception
ex
)
{
log
.
error
(
"详细错误信息:"
+
ex
.
getMessage
()
+
", 执行sql:"
+
entityModel
.
getTableName
());
return
false
;
}
finally
{
DynamicDataSourceContextHolder
.
poll
();
}
}
@Override
public
EntityObj
get
(
EntityModel
entityModel
,
EntityObj
entityObj
)
{
QueryFilter
filter
=
QueryFilter
.
createQuery
();
entityModel
.
getKeyFields
().
forEach
(
item
->{
Object
val
=
entityObj
.
get
(
item
.
getColumnName
());
if
(
val
!=
null
)
{
filter
.
eq
(
item
.
getColumnName
().
toUpperCase
(),
val
);
}
});
List
<
EntityObj
>
list
=
this
.
selectBase
(
entityModel
,
filter
);
if
(
list
.
size
()==
1
)
entityObj
.
putAll
(
list
.
get
(
0
));
return
entityObj
;
}
@Autowired
@Autowired
@Lazy
@Lazy
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/LiteDataService.java
浏览文件 @
603928d6
...
@@ -56,7 +56,32 @@ public class LiteDataService {
...
@@ -56,7 +56,32 @@ public class LiteDataService {
}
}
public
boolean
saveBatch
(
String
systemId
,
String
entityName
,
List
<
EntityObj
>
list
)
{
EntityModel
entityModel
=
liteModelService
.
getEntityModel
(
systemId
,
entityName
);
splitList
(
list
,
500
).
forEach
(
objs
->{
getEntityService
(
entityModel
.
getDsName
()).
saveBatch
(
entityModel
,
objs
);
});
return
true
;
}
public
boolean
save
(
String
systemId
,
String
entityName
,
EntityObj
entityObj
)
{
EntityModel
entityModel
=
liteModelService
.
getEntityModel
(
systemId
,
entityName
);
return
getEntityService
(
entityModel
.
getDsName
()).
save
(
entityModel
,
entityObj
);
}
public
EntityObj
get
(
String
systemId
,
String
entityName
,
EntityObj
entityObj
)
{
EntityModel
entityModel
=
liteModelService
.
getEntityModel
(
systemId
,
entityName
);
return
getEntityService
(
entityModel
.
getDsName
()).
get
(
entityModel
,
entityObj
);
}
public
List
<
EntityObj
>
search
(
String
systemId
,
String
entityName
,
QueryFilter
filter
)
{
return
search
(
systemId
,
entityName
,
"BASE"
,
filter
);
}
public
List
<
EntityObj
>
search
(
String
systemId
,
String
entityName
,
String
dataset
,
QueryFilter
filter
)
{
EntityModel
entityModel
=
liteModelService
.
getEntityModel
(
systemId
,
entityName
);
return
getEntityService
(
entityModel
.
getDsName
()).
search
(
dataset
,
entityModel
,
filter
);
}
public
void
processDataModel
(
String
metaModelId
,
Timestamp
lastModify
,
LiteDataCallback
callback
)
public
void
processDataModel
(
String
metaModelId
,
Timestamp
lastModify
,
LiteDataCallback
callback
)
...
...
ibzdst-core/src/main/java/cn/ibizlab/core/lite/extensions/service/MongoEntityService.java
浏览文件 @
603928d6
...
@@ -39,6 +39,20 @@ public class MongoEntityService implements CommonEntityService{
...
@@ -39,6 +39,20 @@ public class MongoEntityService implements CommonEntityService{
return
null
;
return
null
;
}
}
@Override
public
boolean
saveBatch
(
EntityModel
entityModel
,
List
<
EntityObj
>
list
)
{
return
false
;
}
@Override
public
boolean
save
(
EntityModel
entityModel
,
EntityObj
entityObj
)
{
return
false
;
}
@Override
public
EntityObj
get
(
EntityModel
entityModel
,
EntityObj
entityObj
)
{
return
null
;
}
@Override
@Override
...
...
ibzdst-provider/ibzdst-provider-api/src/main/java/cn/ibizlab/api/rest/extensions/DstCoreResource.java
浏览文件 @
603928d6
...
@@ -13,6 +13,7 @@ import cn.ibizlab.util.dict.CodeItem;
...
@@ -13,6 +13,7 @@ import cn.ibizlab.util.dict.CodeItem;
import
cn.ibizlab.util.dict.CodeList
;
import
cn.ibizlab.util.dict.CodeList
;
import
cn.ibizlab.util.dict.Option
;
import
cn.ibizlab.util.dict.Option
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.filter.QueryFilter
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.helper.DataObject
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper
;
...
@@ -27,8 +28,10 @@ import org.springframework.http.ResponseEntity;
...
@@ -27,8 +28,10 @@ import org.springframework.http.ResponseEntity;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.bind.annotation.*
;
import
javax.servlet.http.HttpServletRequest
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
@Slf4j
@Slf4j
@Api
(
tags
=
{
"接口"
})
@Api
(
tags
=
{
"接口"
})
...
@@ -42,11 +45,9 @@ public class DstCoreResource {
...
@@ -42,11 +45,9 @@ public class DstCoreResource {
@Autowired
@Autowired
private
LiteDataService
liteDataService
;
private
LiteDataService
liteDataService
;
@Autowired
private
DbEntityService
dbEntityService
;
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dst/
test
/{modelid}/data/{key}"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dst/
datamodels
/{modelid}/data/{key}"
)
public
ResponseEntity
<
ModelObj
>
get
str
(
@PathVariable
(
name
=
"modelid"
,
required
=
false
)
String
modelid
,
@PathVariable
(
name
=
"key"
,
required
=
false
)
String
key
)
public
ResponseEntity
<
ModelObj
>
get
ModelObj
(
@PathVariable
(
name
=
"modelid"
,
required
=
false
)
String
modelid
,
@PathVariable
(
name
=
"key"
,
required
=
false
)
String
key
)
{
{
if
(
StringUtils
.
isEmpty
(
modelid
))
if
(
StringUtils
.
isEmpty
(
modelid
))
...
@@ -178,7 +179,32 @@ public class DstCoreResource {
...
@@ -178,7 +179,32 @@ public class DstCoreResource {
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteModelService
.
getEntityModel
(
system
,
entity
).
getNesteds
());
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteModelService
.
getEntityModel
(
system
,
entity
).
getNesteds
());
}
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/{system}/entitys/{entity}/get"
)
public
ResponseEntity
<
EntityObj
>
getEntity
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"entity"
)
String
entity
,
HttpServletRequest
request
)
{
Map
<
String
,
String
[]>
params
=
request
.
getParameterMap
();
EntityObj
entityObj
=
new
EntityObj
();
for
(
String
key
:
params
.
keySet
())
{
entityObj
.
set
(
key
.
toUpperCase
(),
params
.
get
(
key
)[
0
]);
}
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteDataService
.
get
(
system
,
entity
,
entityObj
));
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/{system}/entitys/{entity}/search{dataset}"
)
public
ResponseEntity
<
List
<
EntityObj
>>
searchEntity
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"entity"
)
String
entity
,
@PathVariable
(
value
=
"dataset"
,
required
=
false
)
String
dataset
,
@RequestBody
QueryFilter
filter
)
{
if
(
StringUtils
.
isEmpty
(
dataset
))
dataset
=
"BASE"
;
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteDataService
.
search
(
system
,
entity
,
filter
));
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/{system}/entitys/{entity}/save"
)
public
ResponseEntity
<
Boolean
>
saveEntity
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"entity"
)
String
entity
,
@RequestBody
EntityObj
entityObj
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteDataService
.
save
(
system
,
entity
,
entityObj
));
}
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/dst/{system}/entitys/{entity}/batch"
)
public
ResponseEntity
<
Boolean
>
saveEntity
(
@PathVariable
(
"system"
)
String
system
,
@PathVariable
(
"entity"
)
String
entity
,
@RequestBody
List
<
EntityObj
>
list
)
{
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
liteDataService
.
saveBatch
(
system
,
entity
,
list
));
}
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dst/sysapps"
)
@RequestMapping
(
method
=
RequestMethod
.
GET
,
value
=
"/dst/sysapps"
)
public
ResponseEntity
<
List
<
DstSystem
>>
getSysApps
()
{
public
ResponseEntity
<
List
<
DstSystem
>>
getSysApps
()
{
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录