Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
I
ibzdata
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
ibiz4jteam
ibzdata
提交
b0595b0b
提交
b0595b0b
编写于
9月 01, 2021
作者:
sq3536
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
代码分层
上级
e8233e50
变更
16
隐藏空白字符变更
内嵌
并排
正在显示
16 个修改的文件
包含
1526 行增加
和
1063 行删除
+1526
-1063
DOModel.java
...re/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
+13
-8
BaseData.java
...core/src/main/java/cn/ibizlab/core/data/dto/BaseData.java
+41
-0
DefaultValueType.java
...ain/java/cn/ibizlab/core/data/enums/DefaultValueType.java
+63
-0
Predefined.java
.../src/main/java/cn/ibizlab/core/data/enums/Predefined.java
+71
-0
DbDataMapper.java
...c/main/java/cn/ibizlab/core/data/mapper/DbDataMapper.java
+4
-4
PojoOption.java
.../src/main/java/cn/ibizlab/core/data/model/PojoOption.java
+1
-1
PojoSchema.java
.../src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
+137
-16
MongoDataRepository.java
.../cn/ibizlab/core/data/repository/MongoDataRepository.java
+49
-18
IDataService.java
.../main/java/cn/ibizlab/core/data/service/IDataService.java
+155
-73
IPersistentService.java
...java/cn/ibizlab/core/data/service/IPersistentService.java
+180
-0
BaseDataService.java
...va/cn/ibizlab/core/data/service/impl/BaseDataService.java
+205
-97
DbDataServiceImpl.java
.../cn/ibizlab/core/data/service/impl/DbDataServiceImpl.java
+0
-457
DbPersistentServiceImpl.java
...izlab/core/data/service/impl/DbPersistentServiceImpl.java
+350
-0
MongoDataServiceImpl.java
.../ibizlab/core/data/service/impl/MongoDataServiceImpl.java
+0
-388
MongoPersistentServiceImpl.java
...ab/core/data/service/impl/MongoPersistentServiceImpl.java
+256
-0
DbDataMapper.xml
...re/src/main/resources/mapper/data/DbData/DbDataMapper.xml
+1
-1
未找到文件。
ibzdata-core/src/main/java/cn/ibizlab/core/data/domain/DOModel.java
浏览文件 @
b0595b0b
...
@@ -138,7 +138,6 @@ public class DOModel implements Serializable {
...
@@ -138,7 +138,6 @@ public class DOModel implements Serializable {
public
Serializable
getKeyValue
(
BaseData
data
,
boolean
genKeyWhenNotExists
)
public
Serializable
getKeyValue
(
BaseData
data
,
boolean
genKeyWhenNotExists
)
{
{
if
(
this
.
getSchema
()!=
null
)
{
if
(
this
.
getSchema
()!=
null
)
{
this
.
getSchema
().
fillParentKey
(
data
);
return
this
.
getSchema
().
getKeyValue
(
data
,
genKeyWhenNotExists
);
return
this
.
getSchema
().
getKeyValue
(
data
,
genKeyWhenNotExists
);
}
}
return
null
;
return
null
;
...
@@ -147,24 +146,30 @@ public class DOModel implements Serializable {
...
@@ -147,24 +146,30 @@ public class DOModel implements Serializable {
public
BaseData
newData
(
Object
keyValue
)
public
BaseData
newData
(
Object
keyValue
)
{
{
if
(
this
.
getSchema
()!=
null
)
if
(
this
.
getSchema
()!=
null
)
return
this
.
getSchema
().
setKeyValue
(
new
BaseData
(),
keyValue
);
return
this
.
getSchema
().
newData
(
keyValue
);
return
null
;
return
null
;
}
}
public
BaseData
fillParentKey
(
BaseData
data
)
public
DOModel
fillParentKey
(
BaseData
data
)
{
{
if
(
this
.
getSchema
()!=
null
)
if
(
this
.
getSchema
()!=
null
)
return
this
.
getSchema
().
fillParentKey
(
data
);
this
.
getSchema
().
fillParentKey
(
data
);
return
null
;
return
this
;
}
}
public
FilterData
fillParentFilter
(
FilterData
data
)
public
DOModel
fillParentFilter
(
FilterData
data
)
{
{
if
(
this
.
getSchema
()!=
null
)
if
(
this
.
getSchema
()!=
null
)
return
this
.
getSchema
().
fillParentFilter
(
data
);
this
.
getSchema
().
fillParentFilter
(
data
);
return
null
;
return
this
;
}
}
public
DOModel
fillDefaultValue
(
BaseData
data
,
boolean
newFlag
)
{
if
(
this
.
getSchema
()!=
null
)
this
.
getSchema
().
fillDefaultValue
(
data
,
newFlag
);
return
this
;
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/dto/BaseData.java
浏览文件 @
b0595b0b
...
@@ -278,4 +278,45 @@ public class BaseData extends DataObj
...
@@ -278,4 +278,45 @@ public class BaseData extends DataObj
return
null
;
return
null
;
return
new
BaseData
().
setAll
(
map
);
return
new
BaseData
().
setAll
(
map
);
}
}
public
Serializable
getKeyBySchema
(
boolean
genKeyWhenNotExists
)
{
if
(
this
.
getPojoSchema
()!=
null
)
return
this
.
getPojoSchema
().
getKeyValue
(
this
,
genKeyWhenNotExists
);
else
if
(
this
.
getPOSchema
()!=
null
)
return
this
.
getPOSchema
().
getKeyValue
(
this
,
genKeyWhenNotExists
);
return
this
.
getKey
();
}
public
BaseData
setKeyBySchema
(
Object
keyValue
)
{
if
(
this
.
getPojoSchema
()!=
null
)
{
this
.
getPojoSchema
().
setKeyValue
(
this
,
keyValue
);
return
this
;
}
else
if
(
this
.
getPOSchema
()!=
null
){
this
.
getPOSchema
().
setKeyValue
(
this
,
keyValue
);
return
this
;
}
return
this
.
setKey
(
keyValue
);
}
@JsonIgnore
@JSONField
(
serialize
=
false
)
public
BaseData
fillParentKey
()
{
if
(
this
.
getPojoSchema
()!=
null
)
this
.
getPojoSchema
().
fillParentKey
(
this
);
return
this
;
}
public
BaseData
fillDefaultValue
(
boolean
newFlag
)
{
if
(
this
.
getPojoSchema
()!=
null
)
this
.
getPojoSchema
().
fillDefaultValue
(
this
,
newFlag
);
return
this
;
}
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/enums/DefaultValueType.java
0 → 100644
浏览文件 @
b0595b0b
package
cn
.
ibizlab
.
core
.
data
.
enums
;
/**
* 实体属性默认值类型
*/
public
enum
DefaultValueType
{
/**
* 用户全局对象
*/
SESSION
,
/**
* 系统全局对象
*/
APPLICATION
,
/**
* 唯一编码
*/
UNIQUEID
,
/**
* 网页请求
*/
CONTEXT
,
/**
* 数据对象属性
*/
PARAM
,
/**
* 当前时间
*/
CURTIME
,
/**
* 当前操作用户(编号)
*/
OPERATOR
,
/**
* 当前操作用户(名称)
*/
OPERATORNAME
,
/**
* 当前应用数据
*/
APPDATA
,
/**
* 默认值
*/
NONE
,
/**
* 用户自定义
*/
USER
,
/**
* 用户自定义2
*/
USER2
,
/**
* 用户自定义3
*/
USER3
,
/**
* 用户自定义4
*/
USER4
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/enums/Predefined.java
0 → 100644
浏览文件 @
b0595b0b
package
cn
.
ibizlab
.
core
.
data
.
enums
;
/**
* 实体属性预定义类型
*/
public
enum
Predefined
{
/**
* 创建人标识
*/
CREATEMAN
,
/**
* 创建人名称
*/
CREATEMANNAME
,
/**
* 更新人标识
*/
UPDATEMAN
,
/**
* 更新人名称
*/
UPDATEMANNAME
,
/**
* 创建时间
*/
CREATEDATE
,
/**
* 更新时间
*/
UPDATEDATE
,
/**
* 组织机构标识
*/
ORGID
,
/**
* 组织机构名称
*/
ORGNAME
,
/**
* 部门标识
*/
ORGSECTORID
,
/**
* 部门名称
*/
ORGSECTORNAME
,
/**
* 逻辑有效
*/
LOGICVALID
,
/**
* 排序
*/
ORDERVALUE
,
/**
* 不处理
*/
NONE
,
/**
* 动态父类型
*/
PARENTTYPE
,
/**
* 动态父标识
*/
PARENTID
,
/**
* 动态父名称
*/
PARENTNAME
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/mapper/DbDataMapper.java
浏览文件 @
b0595b0b
...
@@ -31,7 +31,7 @@ public interface DbDataMapper {
...
@@ -31,7 +31,7 @@ public interface DbDataMapper {
int
saveBatch
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"list"
)
List
<
BaseData
>
list
);
int
saveBatch
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"list"
)
List
<
BaseData
>
list
);
int
countData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
);
Long
countData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
);
List
<
BaseData
>
getData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
);
List
<
BaseData
>
getData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
);
...
@@ -44,7 +44,7 @@ public interface DbDataMapper {
...
@@ -44,7 +44,7 @@ public interface DbDataMapper {
Page
<
BaseData
>
selectData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
,
IPage
page
);
Page
<
BaseData
>
selectData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
,
IPage
page
);
@Update
(
"${sql}"
)
@Update
(
"${sql}"
)
boolean
executeRaw
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"param"
)
BaseData
param
);
int
executeRaw
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"param"
)
BaseData
param
);
@Select
(
"${sql}"
)
@Select
(
"${sql}"
)
List
<
BaseData
>
queryData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"srf"
)
FilterData
context
,
@Param
(
"ew"
)
QueryWrapper
wrapper
);
List
<
BaseData
>
queryData
(
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"srf"
)
FilterData
context
,
@Param
(
"ew"
)
QueryWrapper
wrapper
);
...
@@ -145,7 +145,7 @@ public interface DbDataMapper {
...
@@ -145,7 +145,7 @@ public interface DbDataMapper {
}
}
}
}
default
int
countData
(
String
ds
,
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
){
default
Long
countData
(
String
ds
,
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"data"
)
BaseData
data
){
try
try
{
{
DynamicDataSourceContextHolder
.
push
(
ds
);
DynamicDataSourceContextHolder
.
push
(
ds
);
...
@@ -212,7 +212,7 @@ public interface DbDataMapper {
...
@@ -212,7 +212,7 @@ public interface DbDataMapper {
}
}
@Update
(
"${sql}"
)
@Update
(
"${sql}"
)
default
boolean
executeRaw
(
String
ds
,
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"param"
)
BaseData
param
){
default
int
executeRaw
(
String
ds
,
@Param
(
"schema"
)
POSchema
schema
,
@Param
(
"sql"
)
String
sql
,
@Param
(
"param"
)
BaseData
param
){
try
try
{
{
DynamicDataSourceContextHolder
.
push
(
ds
);
DynamicDataSourceContextHolder
.
push
(
ds
);
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/PojoOption.java
浏览文件 @
b0595b0b
...
@@ -193,7 +193,7 @@ public class PojoOption extends DataObj
...
@@ -193,7 +193,7 @@ public class PojoOption extends DataObj
}
}
public
Boolean
isPhysicalField
()
{
public
Boolean
isPhysicalField
()
{
return
this
.
getBooleanValue
(
"physical_field"
,
this
.
getBooleanValue
(
"
persis
ent"
,
true
));
return
this
.
getBooleanValue
(
"physical_field"
,
this
.
getBooleanValue
(
"
Persist
ent"
,
true
));
}
}
public
PojoOption
setPhysicalField
(
Boolean
physicalField
)
{
public
PojoOption
setPhysicalField
(
Boolean
physicalField
)
{
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/model/PojoSchema.java
浏览文件 @
b0595b0b
...
@@ -2,6 +2,8 @@ package cn.ibizlab.core.data.model;
...
@@ -2,6 +2,8 @@ package cn.ibizlab.core.data.model;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.enums.DefaultValueType
;
import
cn.ibizlab.core.data.enums.Predefined
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.helper.DataObject
;
import
cn.ibizlab.util.helper.Inflector
;
import
cn.ibizlab.util.helper.Inflector
;
...
@@ -17,6 +19,7 @@ import lombok.Getter;
...
@@ -17,6 +19,7 @@ import lombok.Getter;
import
lombok.NoArgsConstructor
;
import
lombok.NoArgsConstructor
;
import
lombok.Setter
;
import
lombok.Setter
;
import
lombok.experimental.Accessors
;
import
lombok.experimental.Accessors
;
import
org.springframework.util.AlternativeJdkIdGenerator
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.DigestUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
...
@@ -703,27 +706,89 @@ public class PojoSchema {
...
@@ -703,27 +706,89 @@ public class PojoSchema {
curUser
.
setUserid
(
data
.
getStringValue
(
"SRF_PERSONID"
));
curUser
.
setUserid
(
data
.
getStringValue
(
"SRF_PERSONID"
));
curUser
.
setPersonname
(
data
.
getStringValue
(
"SRF_PERSONNAME"
));
curUser
.
setPersonname
(
data
.
getStringValue
(
"SRF_PERSONNAME"
));
}
}
Timestamp
now
=
new
Timestamp
(
System
.
currentTimeMillis
());
getProperties
().
values
().
forEach
(
sub
->
{
getProperties
().
values
().
forEach
(
sub
->
{
if
(
Type
.
array
.
getCode
().
equals
(
sub
.
getType
())
||
Type
.
object
.
getCode
().
equals
(
sub
.
getType
())
||
!
sub
.
getOptions
().
isPhysicalField
()
||
(!
StringUtils
.
isEmpty
(
sub
.
getOptions
().
getDefaultValue
())))
if
(
Type
.
array
.
getCode
().
equals
(
sub
.
getType
())
||
Type
.
object
.
getCode
().
equals
(
sub
.
getType
())
||
!
sub
.
getOptions
().
isPhysicalField
()
||
(
StringUtils
.
isEmpty
(
sub
.
getOptions
().
getDefaultValue
())&&
StringUtils
.
isEmpty
(
sub
.
getOptions
().
getPredefined
())))
return
;
return
;
String
name
=
sub
.
getName
().
toLowerCase
();
if
(
newFlag
&&(!
ObjectUtils
.
isEmpty
(
data
.
get
(
sub
.
getName
().
toLowerCase
()))))
Object
value
=
data
.
get
(
name
);
return
;
if
(!
StringUtils
.
isEmpty
(
sub
.
getOptions
().
getPredefined
()))
String
predefined
=
this
.
getOptions
().
getPredefined
();
if
(!
newFlag
)
{
{
if
(
predefined
.
equals
(
"UPDATEDATE"
))
try
data
.
set
(
sub
.
getName
().
toLowerCase
(),
new
Timestamp
(
System
.
currentTimeMillis
()));
{
else
if
(
predefined
.
equals
(
"UPDATEMAN"
))
Predefined
predefinedType
=
Predefined
.
valueOf
(
sub
.
getOptions
().
getPredefined
());
data
.
set
(
sub
.
getName
().
toLowerCase
(),
curUser
.
getUserid
());
if
(
newFlag
)
else
if
(
predefined
.
equals
(
"UPDATEMANNAME"
))
{
data
.
set
(
sub
.
getName
().
toLowerCase
(),
curUser
.
getPersonname
());
switch
(
predefinedType
)
{
case
CREATEMAN:
data
.
set
(
name
,
curUser
.
getUserid
());
break
;
case
CREATEMANNAME:
data
.
set
(
name
,
curUser
.
getPersonname
());
break
;
case
UPDATEMAN:
data
.
set
(
name
,
curUser
.
getUserid
());
break
;
case
UPDATEMANNAME:
data
.
set
(
name
,
curUser
.
getPersonname
());
break
;
case
CREATEDATE:
data
.
set
(
name
,
now
);
break
;
case
UPDATEDATE:
data
.
set
(
name
,
now
);
break
;
case
ORGID:
if
(
ObjectUtils
.
isEmpty
(
value
))
{
data
.
set
(
name
,
curUser
.
getOrgid
());
}
break
;
case
ORGNAME:
if
(
ObjectUtils
.
isEmpty
(
value
))
{
data
.
set
(
name
,
curUser
.
getOrgname
());
}
break
;
case
ORGSECTORID:
if
(
ObjectUtils
.
isEmpty
(
value
))
{
data
.
set
(
name
,
curUser
.
getMdeptid
());
}
break
;
case
ORGSECTORNAME:
if
(
ObjectUtils
.
isEmpty
(
value
))
{
data
.
set
(
name
,
curUser
.
getMdeptname
());
}
break
;
case
LOGICVALID:
data
.
set
(
name
,
this
.
getOptions
().
getLogicVal
());
break
;
}
}
else
{
{
switch
(
predefinedType
)
{
case
UPDATEMAN:
data
.
set
(
name
,
curUser
.
getUserid
());
break
;
case
UPDATEMANNAME:
data
.
set
(
name
,
curUser
.
getPersonname
());
break
;
case
UPDATEDATE:
data
.
set
(
name
,
now
);
break
;
}
}
}
}
catch
(
Exception
ex
)
{}
return
;
return
;
}
}
if
((!
newFlag
)||
ObjectUtils
.
isEmpty
(
data
.
get
(
name
)))
return
;
String
DV
=
sub
.
getOptions
().
getDefaultValue
();
String
DV
=
sub
.
getOptions
().
getDefaultValue
();
if
(
StringUtils
.
isEmpty
(
DV
))
return
;
String
defaultValueType
=
""
;
String
defaultValueType
=
""
;
String
defaultValue
=
""
;
String
defaultValue
=
""
;
if
(
DV
.
startsWith
(
"$"
))
if
(
DV
.
startsWith
(
"$"
))
...
@@ -733,10 +798,66 @@ public class PojoSchema {
...
@@ -733,10 +798,66 @@ public class PojoSchema {
if
(
dvs
.
length
>=
1
)
if
(
dvs
.
length
>=
1
)
defaultValueType
=
dvs
[
0
];
defaultValueType
=
dvs
[
0
];
if
(
dvs
.
length
>=
2
)
if
(
dvs
.
length
>=
2
)
defaultValue
=
dvs
[
1
];
defaultValue
=
dvs
[
1
]
.
toLowerCase
()
;
}
}
else
else
defaultValue
=
DV
;
defaultValue
=
DV
;
if
(!
StringUtils
.
isEmpty
(
defaultValueType
))
{
try
{
DefaultValueType
dvt
=
DefaultValueType
.
valueOf
(
defaultValueType
);
switch
(
dvt
)
{
case
SESSION:
if
(!
StringUtils
.
isEmpty
(
defaultValue
))
{
Object
sessionFieldValue
=
curUser
.
getSessionParams
().
get
(
defaultValue
);
if
(!
ObjectUtils
.
isEmpty
(
sessionFieldValue
))
{
data
.
set
(
name
,
sessionFieldValue
);
}
}
break
;
case
APPLICATION:
//暂未实现
break
;
case
UNIQUEID:
data
.
set
(
name
,
IdWorker
.
get32UUID
());
break
;
case
CONTEXT:
if
(!
StringUtils
.
isEmpty
(
defaultValue
))
{
Object
paramFieldValue
=
data
.
get
(
defaultValue
);
if
(!
ObjectUtils
.
isEmpty
(
paramFieldValue
))
{
data
.
set
(
name
,
paramFieldValue
);
}
}
break
;
case
PARAM:
if
(!
StringUtils
.
isEmpty
(
defaultValue
))
{
Object
paramFieldValue
=
data
.
get
(
defaultValue
);
if
(!
ObjectUtils
.
isEmpty
(
paramFieldValue
))
{
data
.
set
(
name
,
paramFieldValue
);
}
}
break
;
case
OPERATOR:
data
.
set
(
name
,
curUser
.
getUserid
());
break
;
case
OPERATORNAME:
data
.
set
(
name
,
curUser
.
getPersonname
());
break
;
case
CURTIME:
data
.
set
(
name
,
now
);
break
;
case
APPDATA:
//暂未实现
break
;
case
NONE:
data
.
set
(
name
,
defaultValue
);
break
;
}
}
catch
(
Exception
ex
){}
}
else
if
(!
StringUtils
.
isEmpty
(
defaultValue
))
data
.
set
(
name
,
defaultValue
);
});
});
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/repository/MongoDataRepository.java
浏览文件 @
b0595b0b
...
@@ -7,6 +7,8 @@ import cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder;
...
@@ -7,6 +7,8 @@ import cn.ibizlab.core.data.mongodb.DynamicMongoContextHolder;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.JSON
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.mongodb.BasicDBList
;
import
com.mongodb.BasicDBObject
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Param
;
import
org.apache.ibatis.annotations.Select
;
import
org.apache.ibatis.annotations.Select
;
...
@@ -86,16 +88,16 @@ public class MongoDataRepository {
...
@@ -86,16 +88,16 @@ public class MongoDataRepository {
}
}
public
Query
getKeyQuery
(
POSchema
schema
,
BaseData
data
)
public
Query
getKeyQuery
(
BaseData
data
)
{
{
Query
query
=
new
Query
();
Query
query
=
new
Query
();
if
(!
ObjectUtils
.
isEmpty
(
data
.
getKey
()))
if
(!
ObjectUtils
.
isEmpty
(
data
.
getKey
()))
return
query
.
addCriteria
(
new
Criteria
().
and
(
"_id"
).
is
(
data
.
getKey
()));
return
query
.
addCriteria
(
new
Criteria
().
and
(
"_id"
).
is
(
data
.
getKey
()));
else
else
throw
new
BadRequestAlertException
(
"未找到主键"
,
schema
.
getName
()
,
null
);
throw
new
BadRequestAlertException
(
"未找到主键"
,
"mongo"
,
null
);
}
}
public
Query
getKeyQuery
(
POSchema
schema
,
List
list
)
public
Query
getKeyQuery
(
List
list
)
{
{
Query
query
=
new
Query
();
Query
query
=
new
Query
();
if
(
ObjectUtils
.
isEmpty
(
list
))
if
(
ObjectUtils
.
isEmpty
(
list
))
...
@@ -107,7 +109,7 @@ public class MongoDataRepository {
...
@@ -107,7 +109,7 @@ public class MongoDataRepository {
BaseData
data
=
(
BaseData
)
item
;
BaseData
data
=
(
BaseData
)
item
;
Serializable
key
=
data
.
getKey
();
Serializable
key
=
data
.
getKey
();
if
(
ObjectUtils
.
isEmpty
(
key
))
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
schema
.
getName
()
,
null
);
throw
new
BadRequestAlertException
(
"未找到主键"
,
"mongo"
,
null
);
ids
.
add
(
key
.
toString
());
ids
.
add
(
key
.
toString
());
});
});
...
@@ -146,9 +148,10 @@ public class MongoDataRepository {
...
@@ -146,9 +148,10 @@ public class MongoDataRepository {
public
int
updateData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
int
updateData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
Query
query
=
getKeyQuery
(
data
);
Query
query
=
getKeyQuery
(
schema
,
data
);
Update
update
=
getUpdateByObject
(
data
);
Update
update
=
getUpdateByObject
(
data
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
return
(
int
)
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
}
}
finally
{
finally
{
...
@@ -161,7 +164,7 @@ public class MongoDataRepository {
...
@@ -161,7 +164,7 @@ public class MongoDataRepository {
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
list
.
forEach
(
data
->
{
list
.
forEach
(
data
->
{
Query
query
=
getKeyQuery
(
schema
,
data
);
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
Update
update
=
getUpdateByObject
(
data
);
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
());
this
.
mongoTemplate
.
updateFirst
(
query
,
update
,
schema
.
getName
());
});
});
...
@@ -175,7 +178,7 @@ public class MongoDataRepository {
...
@@ -175,7 +178,7 @@ public class MongoDataRepository {
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
remove
(
getKeyQuery
(
schema
,
data
),
schema
.
getName
()).
getDeletedCount
();
return
(
int
)
this
.
mongoTemplate
.
remove
(
getKeyQuery
(
data
),
schema
.
getName
()).
getDeletedCount
();
}
}
finally
{
finally
{
DynamicMongoContextHolder
.
poll
();
DynamicMongoContextHolder
.
poll
();
...
@@ -186,7 +189,7 @@ public class MongoDataRepository {
...
@@ -186,7 +189,7 @@ public class MongoDataRepository {
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
mongoTemplate
.
remove
(
getKeyQuery
(
schema
,
list
),
schema
.
getName
()).
getDeletedCount
();
return
(
int
)
mongoTemplate
.
remove
(
getKeyQuery
(
list
),
schema
.
getName
()).
getDeletedCount
();
}
}
finally
{
finally
{
DynamicMongoContextHolder
.
poll
();
DynamicMongoContextHolder
.
poll
();
...
@@ -196,9 +199,10 @@ public class MongoDataRepository {
...
@@ -196,9 +199,10 @@ public class MongoDataRepository {
public
int
saveData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
int
saveData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
Query
query
=
getKeyQuery
(
data
);
Query
query
=
getKeyQuery
(
schema
,
data
);
Update
update
=
getUpdateByObject
(
data
);
Update
update
=
getUpdateByObject
(
data
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
this
.
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
return
(
int
)
this
.
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
()).
getModifiedCount
();
}
}
finally
{
finally
{
...
@@ -211,7 +215,7 @@ public class MongoDataRepository {
...
@@ -211,7 +215,7 @@ public class MongoDataRepository {
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
list
.
forEach
(
data
->
{
list
.
forEach
(
data
->
{
Query
query
=
getKeyQuery
(
schema
,
data
);
Query
query
=
getKeyQuery
(
data
);
Update
update
=
getUpdateByObject
(
data
);
Update
update
=
getUpdateByObject
(
data
);
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
());
mongoTemplate
.
upsert
(
query
,
update
,
schema
.
getName
());
});
});
...
@@ -221,11 +225,11 @@ public class MongoDataRepository {
...
@@ -221,11 +225,11 @@ public class MongoDataRepository {
}
}
}
}
public
int
countData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
public
long
countData
(
String
ds
,
POSchema
schema
,
BaseData
data
){
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
return
(
int
)
mongoTemplate
.
count
(
getQueryByObject
(
data
),
schema
.
getName
());
return
mongoTemplate
.
count
(
getQueryByObject
(
data
),
schema
.
getName
());
}
}
finally
{
finally
{
DynamicMongoContextHolder
.
poll
();
DynamicMongoContextHolder
.
poll
();
...
@@ -236,7 +240,7 @@ public class MongoDataRepository {
...
@@ -236,7 +240,7 @@ public class MongoDataRepository {
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
return
mongoTemplate
.
find
(
getKeyQuery
(
schema
,
data
),
getEntityClass
(),
schema
.
getName
());
return
mongoTemplate
.
find
(
getKeyQuery
(
data
),
getEntityClass
(),
schema
.
getName
());
}
}
finally
{
finally
{
DynamicMongoContextHolder
.
poll
();
DynamicMongoContextHolder
.
poll
();
...
@@ -247,7 +251,32 @@ public class MongoDataRepository {
...
@@ -247,7 +251,32 @@ public class MongoDataRepository {
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
DynamicMongoContextHolder
.
push
(
ds
);
return
mongoTemplate
.
find
(
getKeyQuery
(
schema
,
list
),
getEntityClass
(),
schema
.
getName
());
return
mongoTemplate
.
find
(
getKeyQuery
(
list
),
getEntityClass
(),
schema
.
getName
());
}
finally
{
DynamicMongoContextHolder
.
poll
();
}
}
public
List
<
BaseData
>
getBatchKey
(
String
ds
,
POSchema
schema
,
List
<
BaseData
>
list
){
try
{
BasicDBObject
query
=
new
BasicDBObject
();
BasicDBList
values
=
new
BasicDBList
();
list
.
forEach
(
item
->{
Serializable
key
=
item
.
getKey
();
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
"mongo"
,
null
);
values
.
add
(
key
);
});
BasicDBObject
in
=
new
BasicDBObject
(
"$in"
,
values
);
query
.
put
(
"_id"
,
in
);
BasicDBObject
fieldsObject
=
new
BasicDBObject
();
fieldsObject
.
put
(
"_id"
,
true
);
Query
queryIds
=
new
BasicQuery
(
query
.
toJson
(),
fieldsObject
.
toJson
());
DynamicMongoContextHolder
.
push
(
ds
);
return
mongoTemplate
.
find
(
queryIds
,
getEntityClass
(),
schema
.
getName
());
}
}
finally
{
finally
{
DynamicMongoContextHolder
.
poll
();
DynamicMongoContextHolder
.
poll
();
...
@@ -270,10 +299,11 @@ public class MongoDataRepository {
...
@@ -270,10 +299,11 @@ public class MongoDataRepository {
public
Page
<
BaseData
>
selectData
(
String
ds
,
POSchema
schema
,
BaseData
data
,
Pageable
page
){
public
Page
<
BaseData
>
selectData
(
String
ds
,
POSchema
schema
,
BaseData
data
,
Pageable
page
){
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
if
(
page
==
null
)
if
(
page
==
null
)
page
=
PageRequest
.
of
(
0
,
20
,
Sort
.
unsorted
());
page
=
PageRequest
.
of
(
0
,
20
,
Sort
.
unsorted
());
Query
query
=
getQueryByObject
(
data
);
Query
query
=
getQueryByObject
(
data
);
DynamicMongoContextHolder
.
push
(
ds
);
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
...
@@ -298,12 +328,13 @@ public class MongoDataRepository {
...
@@ -298,12 +328,13 @@ public class MongoDataRepository {
public
Page
<
BaseData
>
queryData
(
String
ds
,
POSchema
schema
,
String
sql
,
FilterData
context
,
Pageable
page
){
public
Page
<
BaseData
>
queryData
(
String
ds
,
POSchema
schema
,
String
sql
,
FilterData
context
,
Pageable
page
){
try
try
{
{
DynamicMongoContextHolder
.
push
(
ds
);
if
(
page
==
null
)
if
(
page
==
null
)
page
=
context
.
getPageable
();
page
=
context
.
getPageable
();
else
else
context
.
setPageable
(
page
);
context
.
setPageable
(
page
);
Query
query
=
new
BasicQuery
(
context
.
getQueryBuilder
().
get
().
toString
());
Query
query
=
new
BasicQuery
(
context
.
getQueryBuilder
().
get
().
toString
());
DynamicMongoContextHolder
.
push
(
ds
);
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
long
total
=
mongoTemplate
.
count
(
query
,
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
List
<
BaseData
>
list
=
mongoTemplate
.
find
(
query
.
with
(
page
),
BaseData
.
class
,
schema
.
getName
());
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
return
new
PageImpl
<
BaseData
>(
list
,
page
,
total
);
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/IDataService.java
浏览文件 @
b0595b0b
...
@@ -5,8 +5,10 @@ import cn.ibizlab.core.data.dto.BaseData;
...
@@ -5,8 +5,10 @@ import cn.ibizlab.core.data.dto.BaseData;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.dto.RequestData
;
import
cn.ibizlab.core.data.dto.RequestData
;
import
cn.ibizlab.core.data.dto.ResponseData
;
import
cn.ibizlab.core.data.dto.ResponseData
;
import
cn.ibizlab.core.data.model.DSLink
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.List
;
...
@@ -14,39 +16,39 @@ import java.util.List;
...
@@ -14,39 +16,39 @@ import java.util.List;
public
interface
IDataService
public
interface
IDataService
{
{
ResponseData
call
(
DOModel
model
,
String
scope
,
String
datasource
,
String
method
,
RequestData
requestData
);
ResponseData
call
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
method
,
RequestData
requestData
);
boolean
create
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
BaseData
create
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
void
createBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
);
List
<
BaseData
>
createBatch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
List
<
BaseData
>
list
);
boolean
update
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
BaseData
update
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
void
updateBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
);
List
<
BaseData
>
updateBatch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
List
<
BaseData
>
list
);
boolean
remove
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
);
boolean
remove
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
Serializable
key
);
void
removeBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
);
boolean
removeBatch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
List
<
Serializable
>
idList
);
boolean
removeByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
boolean
removeByMap
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
BaseData
get
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
);
BaseData
get
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
Serializable
key
);
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
);
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
List
<
Serializable
>
idList
);
BaseData
getByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
BaseData
getByMap
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
BaseData
getDraft
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
BaseData
getDraft
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
boolean
checkKey
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
boolean
checkKey
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
boolean
save
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
BaseData
save
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
void
saveBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
);
List
<
BaseData
>
saveBatch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
List
<
BaseData
>
list
);
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
);
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
);
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
,
Pageable
pageable
);
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
BaseData
et
,
Pageable
pageable
);
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
);
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
dataQuery
,
FilterData
context
);
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
);
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
);
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
FilterData
context
);
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
sql
,
FilterData
context
);
boolean
execRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
BaseData
param
);
boolean
execRaw
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
sql
,
BaseData
param
);
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
);
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
dataSet
,
FilterData
context
);
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
);
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
DSLink
dsLink
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
);
...
@@ -60,29 +62,29 @@ public interface IDataService
...
@@ -60,29 +62,29 @@ public interface IDataService
return
call
(
system
,
""
,
entity
,
method
,
""
,
requestData
);
return
call
(
system
,
""
,
entity
,
method
,
""
,
requestData
);
}
}
default
boolean
create
(
String
system
,
String
entity
,
BaseData
et
)
default
BaseData
create
(
String
system
,
String
entity
,
BaseData
et
)
{
{
return
create
(
system
,
""
,
entity
,
""
,
et
);
return
create
(
system
,
""
,
entity
,
""
,
et
);
}
}
default
void
createBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
createBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
{
{
createBatch
(
system
,
""
,
entity
,
""
,
list
);
return
createBatch
(
system
,
""
,
entity
,
""
,
list
);
}
}
default
boolean
update
(
String
system
,
String
entity
,
BaseData
et
)
default
BaseData
update
(
String
system
,
String
entity
,
BaseData
et
)
{
{
return
update
(
system
,
""
,
entity
,
""
,
et
);
return
update
(
system
,
""
,
entity
,
""
,
et
);
}
}
default
void
updateBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
updateBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
{
{
updateBatch
(
system
,
""
,
entity
,
""
,
list
);
return
updateBatch
(
system
,
""
,
entity
,
""
,
list
);
}
}
default
boolean
remove
(
String
system
,
String
entity
,
Serializable
key
)
default
boolean
remove
(
String
system
,
String
entity
,
Serializable
key
)
{
{
return
remove
(
system
,
""
,
entity
,
""
,
key
);
return
remove
(
system
,
""
,
entity
,
""
,
key
);
}
}
default
void
removeBatch
(
String
system
,
String
entity
,
List
<
Serializable
>
idList
)
default
boolean
removeBatch
(
String
system
,
String
entity
,
List
<
Serializable
>
idList
)
{
{
removeBatch
(
system
,
""
,
entity
,
""
,
idList
);
re
turn
re
moveBatch
(
system
,
""
,
entity
,
""
,
idList
);
}
}
default
boolean
removeByMap
(
String
system
,
String
entity
,
BaseData
et
)
default
boolean
removeByMap
(
String
system
,
String
entity
,
BaseData
et
)
{
{
...
@@ -108,13 +110,13 @@ public interface IDataService
...
@@ -108,13 +110,13 @@ public interface IDataService
{
{
return
checkKey
(
system
,
""
,
entity
,
""
,
et
);
return
checkKey
(
system
,
""
,
entity
,
""
,
et
);
}
}
default
boolean
save
(
String
system
,
String
entity
,
BaseData
et
)
default
BaseData
save
(
String
system
,
String
entity
,
BaseData
et
)
{
{
return
save
(
system
,
""
,
entity
,
""
,
et
);
return
save
(
system
,
""
,
entity
,
""
,
et
);
}
}
default
void
saveBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
saveBatch
(
String
system
,
String
entity
,
List
<
BaseData
>
list
)
{
{
saveBatch
(
system
,
""
,
entity
,
""
,
list
);
return
saveBatch
(
system
,
""
,
entity
,
""
,
list
);
}
}
default
List
<
BaseData
>
select
(
String
system
,
String
entity
,
BaseData
et
){
default
List
<
BaseData
>
select
(
String
system
,
String
entity
,
BaseData
et
){
return
select
(
system
,
""
,
entity
,
""
,
et
);
return
select
(
system
,
""
,
entity
,
""
,
et
);
...
@@ -146,91 +148,171 @@ public interface IDataService
...
@@ -146,91 +148,171 @@ public interface IDataService
default
ResponseData
call
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
method
,
RequestData
requestData
)
default
ResponseData
call
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
method
,
RequestData
requestData
)
{
{
requestData
.
setSystem
(
system
).
setScope
(
scope
).
setEntity
(
entity
).
setMethod
(
method
).
setDataSource
(
datasource
);
return
call
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
method
,
requestData
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
requestData
.
setSystem
(
model
.
getSystemId
()).
setScope
(
scope
).
setEntity
(
model
.
getName
()).
setMethod
(
method
).
setDataSource
(
datasource
);
return
call
(
model
,
scope
,
dsLink
,
method
,
requestData
);
}
}
default
boolean
create
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
BaseData
create
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
create
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
create
(
model
,
scope
,
dsLink
,
et
);
}
}
default
void
createBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
createBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
{
{
createBatch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
list
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
createBatch
(
model
,
scope
,
dsLink
,
list
);
}
}
default
boolean
update
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
BaseData
update
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
update
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
update
(
model
,
scope
,
dsLink
,
et
);
}
}
default
void
updateBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
updateBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
{
{
updateBatch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
list
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
updateBatch
(
model
,
scope
,
dsLink
,
list
);
}
}
default
boolean
remove
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
Serializable
key
)
default
boolean
remove
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
Serializable
key
)
{
{
return
remove
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
key
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
remove
(
model
,
scope
,
dsLink
,
key
);
}
}
default
void
removeBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
Serializable
>
idList
)
default
boolean
removeBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
Serializable
>
idList
)
{
{
removeBatch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
idList
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
removeBatch
(
model
,
scope
,
dsLink
,
idList
);
}
}
default
boolean
removeByMap
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
boolean
removeByMap
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
removeByMap
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
removeByMap
(
model
,
scope
,
dsLink
,
et
);
}
}
default
BaseData
get
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
Serializable
key
)
default
BaseData
get
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
Serializable
key
)
{
{
return
get
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
key
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
get
(
model
,
scope
,
dsLink
,
key
);
}
}
default
List
<
BaseData
>
getBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
Serializable
>
idList
)
default
List
<
BaseData
>
getBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
Serializable
>
idList
)
{
{
return
getBatch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
idList
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
getBatch
(
model
,
scope
,
dsLink
,
idList
);
}
}
default
BaseData
getByMap
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
BaseData
getByMap
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
getByMap
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
getByMap
(
model
,
scope
,
dsLink
,
et
);
}
}
default
BaseData
getDraft
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
BaseData
getDraft
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
getDraft
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
getDraft
(
model
,
scope
,
dsLink
,
et
);
}
}
default
boolean
checkKey
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
boolean
checkKey
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
checkKey
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
checkKey
(
model
,
scope
,
dsLink
,
et
);
}
}
default
boolean
save
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
default
BaseData
save
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
{
{
return
save
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
save
(
model
,
scope
,
dsLink
,
et
);
}
}
default
void
saveBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
default
List
<
BaseData
>
saveBatch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
List
<
BaseData
>
list
)
{
{
saveBatch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
list
);
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
saveBatch
(
model
,
scope
,
dsLink
,
list
);
}
}
default
List
<
BaseData
>
select
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
){
default
List
<
BaseData
>
select
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
)
return
select
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
select
(
model
,
scope
,
dsLink
,
et
);
}
}
default
Page
<
BaseData
>
select
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
,
Pageable
pageable
){
default
Page
<
BaseData
>
select
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
BaseData
et
,
Pageable
pageable
)
return
select
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
et
,
pageable
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
select
(
model
,
scope
,
dsLink
,
et
,
pageable
);
}
}
default
List
<
BaseData
>
query
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataQuery
,
FilterData
context
){
default
List
<
BaseData
>
query
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataQuery
,
FilterData
context
)
return
query
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
dataQuery
,
context
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
query
(
model
,
scope
,
dsLink
,
dataQuery
,
context
);
}
}
default
Page
<
BaseData
>
query
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
){
default
Page
<
BaseData
>
query
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
return
query
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
dataQuery
,
context
,
pageable
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
query
(
model
,
scope
,
dsLink
,
dataQuery
,
context
,
pageable
);
}
}
default
List
<
BaseData
>
selectRaw
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
sql
,
FilterData
context
){
default
List
<
BaseData
>
selectRaw
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
sql
,
FilterData
context
)
return
selectRaw
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
sql
,
context
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
selectRaw
(
model
,
scope
,
dsLink
,
sql
,
context
);
}
}
default
boolean
execRaw
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
sql
,
BaseData
param
){
default
boolean
execRaw
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
sql
,
BaseData
param
)
return
execRaw
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
sql
,
param
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
execRaw
(
model
,
scope
,
dsLink
,
sql
,
param
);
}
}
default
List
<
BaseData
>
fetch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataSet
,
FilterData
context
){
default
List
<
BaseData
>
fetch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataSet
,
FilterData
context
)
return
fetch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
dataSet
,
context
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
fetch
(
model
,
scope
,
dsLink
,
dataSet
,
context
);
}
}
default
Page
<
BaseData
>
fetch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
){
default
Page
<
BaseData
>
fetch
(
String
system
,
String
scope
,
String
entity
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
return
fetch
(
getDOModel
(
system
,
entity
),
scope
,
datasource
,
dataSet
,
context
,
pageable
);
{
DOModel
model
=
getDOModel
(
system
,
entity
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
dsLink
=
getDSLink
(
datasource
);
return
fetch
(
model
,
scope
,
dsLink
,
dataSet
,
context
,
pageable
);
}
}
DOModel
getDOModel
(
String
system
,
String
entity
);
DOModel
getDOModel
(
String
system
,
String
entity
);
DSLink
getDSLink
(
String
datasource
);
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/IPersistentService.java
0 → 100644
浏览文件 @
b0595b0b
package
cn
.
ibizlab
.
core
.
data
.
service
;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.dto.RequestData
;
import
cn.ibizlab.core.data.dto.ResponseData
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
java.io.Serializable
;
import
java.util.List
;
public
interface
IPersistentService
{
BaseData
create
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
);
List
<
BaseData
>
createBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
);
BaseData
update
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
);
List
<
BaseData
>
updateBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
);
boolean
remove
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
);
boolean
removeBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
);
boolean
removeByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
);
boolean
removeByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
);
BaseData
get
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
);
List
<
BaseData
>
getBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
);
BaseData
getByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
);
List
<
BaseData
>
getByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
);
List
<
BaseData
>
getBatchKey
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
);
Long
count
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
);
boolean
checkKey
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
);
BaseData
save
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
);
List
<
BaseData
>
saveBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
);
List
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
);
Page
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
Pageable
pageable
);
List
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
);
Page
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
);
List
<
BaseData
>
selectRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
FilterData
context
);
boolean
execRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
BaseData
param
);
List
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
);
Page
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
);
default
BaseData
create
(
String
datasource
,
String
table
,
BaseData
et
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
create
(
link
,
getSchema
(
link
,
table
),
et
,
bGet
);
}
default
List
<
BaseData
>
createBatch
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
createBatch
(
link
,
getSchema
(
link
,
table
),
list
,
bGet
);
}
default
BaseData
update
(
String
datasource
,
String
table
,
BaseData
et
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
update
(
link
,
getSchema
(
link
,
table
),
et
,
bGet
);
}
default
List
<
BaseData
>
updateBatch
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
updateBatch
(
link
,
getSchema
(
link
,
table
),
list
,
bGet
);
}
default
boolean
remove
(
String
datasource
,
String
table
,
Serializable
key
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
remove
(
link
,
getSchema
(
link
,
table
),
key
);
}
default
boolean
removeBatch
(
String
datasource
,
String
table
,
List
<
Serializable
>
idList
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
removeBatch
(
link
,
getSchema
(
link
,
table
),
idList
);
}
default
boolean
removeByMap
(
String
datasource
,
String
table
,
BaseData
et
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
removeByMap
(
link
,
getSchema
(
link
,
table
),
et
);
}
default
boolean
removeByMapBatch
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
removeByMapBatch
(
link
,
getSchema
(
link
,
table
),
list
);
}
default
BaseData
get
(
String
datasource
,
String
table
,
Serializable
key
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
get
(
link
,
getSchema
(
link
,
table
),
key
);
}
default
List
<
BaseData
>
getBatch
(
String
datasource
,
String
table
,
List
<
Serializable
>
idList
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
getBatch
(
link
,
getSchema
(
link
,
table
),
idList
);
}
default
BaseData
getByMap
(
String
datasource
,
String
table
,
BaseData
et
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
getByMap
(
link
,
getSchema
(
link
,
table
),
et
);
}
default
List
<
BaseData
>
getByMapBatch
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
getByMapBatch
(
link
,
getSchema
(
link
,
table
),
list
);
}
default
List
<
BaseData
>
getBatchKey
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
getBatchKey
(
link
,
getSchema
(
link
,
table
),
list
);
}
default
Long
count
(
String
datasource
,
String
table
,
BaseData
et
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
count
(
link
,
getSchema
(
link
,
table
),
et
);
}
default
boolean
checkKey
(
String
datasource
,
String
table
,
BaseData
et
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
checkKey
(
link
,
getSchema
(
link
,
table
),
et
);
}
default
BaseData
save
(
String
datasource
,
String
table
,
BaseData
et
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
save
(
link
,
getSchema
(
link
,
table
),
et
,
bGet
);
}
default
List
<
BaseData
>
saveBatch
(
String
datasource
,
String
table
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
DSLink
link
=
getDSLink
(
datasource
);
return
saveBatch
(
link
,
getSchema
(
link
,
table
),
list
,
bGet
);
}
default
List
<
BaseData
>
select
(
String
datasource
,
String
table
,
BaseData
et
){
DSLink
link
=
getDSLink
(
datasource
);
return
select
(
link
,
getSchema
(
link
,
table
),
et
);
}
default
Page
<
BaseData
>
select
(
String
datasource
,
String
table
,
BaseData
et
,
Pageable
pageable
){
DSLink
link
=
getDSLink
(
datasource
);
return
select
(
link
,
getSchema
(
link
,
table
),
et
,
pageable
);
}
default
List
<
BaseData
>
query
(
String
datasource
,
String
table
,
String
dataQuery
,
FilterData
context
){
DSLink
link
=
getDSLink
(
datasource
);
return
query
(
link
,
getSchema
(
link
,
table
),
dataQuery
,
context
);
}
default
Page
<
BaseData
>
query
(
String
datasource
,
String
table
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
){
DSLink
link
=
getDSLink
(
datasource
);
return
query
(
link
,
getSchema
(
link
,
table
),
dataQuery
,
context
,
pageable
);
}
default
List
<
BaseData
>
selectRaw
(
String
datasource
,
String
table
,
String
sql
,
FilterData
context
){
DSLink
link
=
getDSLink
(
datasource
);
return
selectRaw
(
link
,
getSchema
(
link
,
table
),
sql
,
context
);
}
default
boolean
execRaw
(
String
datasource
,
String
table
,
String
sql
,
BaseData
param
){
DSLink
link
=
getDSLink
(
datasource
);
return
execRaw
(
link
,
getSchema
(
link
,
table
),
sql
,
param
);
}
default
List
<
BaseData
>
fetch
(
String
datasource
,
String
table
,
String
dataSet
,
FilterData
context
){
DSLink
link
=
getDSLink
(
datasource
);
return
fetch
(
link
,
getSchema
(
link
,
table
),
dataSet
,
context
);
}
default
Page
<
BaseData
>
fetch
(
String
datasource
,
String
table
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
){
DSLink
link
=
getDSLink
(
datasource
);
return
fetch
(
link
,
getSchema
(
link
,
table
),
dataSet
,
context
,
pageable
);
}
DSLink
getDSLink
(
String
datasource
);
POSchema
getSchema
(
DSLink
link
,
String
table
);
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/BaseDataService.java
浏览文件 @
b0595b0b
...
@@ -3,11 +3,10 @@ package cn.ibizlab.core.data.service.impl;
...
@@ -3,11 +3,10 @@ package cn.ibizlab.core.data.service.impl;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.dto.*
;
import
cn.ibizlab.core.data.dto.*
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.service.IDOModelService
;
import
cn.ibizlab.core.data.service.*
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
cn.ibizlab.core.data.service.IDataService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.context.annotation.Lazy
;
...
@@ -19,6 +18,8 @@ import org.springframework.util.ObjectUtils;
...
@@ -19,6 +18,8 @@ import org.springframework.util.ObjectUtils;
import
org.springframework.util.StringUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
@@ -30,18 +31,14 @@ import java.util.Map;
...
@@ -30,18 +31,14 @@ import java.util.Map;
@Service
@Service
public
class
BaseDataService
implements
IDataService
{
public
class
BaseDataService
implements
IDataService
{
@Override
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
modelService
.
getDOModel
(
system
,
entity
);
}
@Autowired
@Autowired
private
Db
Data
ServiceImpl
dbProxyService
;
private
Db
Persistent
ServiceImpl
dbProxyService
;
@Autowired
@Autowired
@Lazy
@Lazy
private
Mongo
Data
ServiceImpl
mongoProxyService
;
private
Mongo
Persistent
ServiceImpl
mongoProxyService
;
@Autowired
@Autowired
private
ModelService
modelService
;
private
ModelService
modelService
;
...
@@ -50,40 +47,49 @@ public class BaseDataService implements IDataService {
...
@@ -50,40 +47,49 @@ public class BaseDataService implements IDataService {
private
IDSSettingService
dsSettingService
;
private
IDSSettingService
dsSettingService
;
public
I
DataService
getProxyService
(
String
datasource
)
public
I
PersistentService
getProxyService
(
DSLink
link
)
{
{
DSLink
dsLink
=
dsSettingService
.
getDataSource
(
datasource
);
if
(
link
.
isMongodb
())
if
(
dsLink
.
isMongodb
())
return
mongoProxyService
;
else
if
(
dsLink
.
isElasticSearch
())
return
mongoProxyService
;
else
if
(
dsLink
.
isCassandra
())
return
mongoProxyService
;
return
mongoProxyService
;
else
if
(
link
.
isElasticSearch
())
return
dbProxyService
;
else
if
(
link
.
isCassandra
())
return
dbProxyService
;
else
else
return
dbProxyService
;
return
dbProxyService
;
}
}
@Override
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
modelService
.
getDOModel
(
system
,
entity
);
}
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
}
@Override
@Override
public
ResponseData
call
(
DOModel
model
,
String
scope
,
String
method
,
String
datasource
,
RequestData
requestBody
)
public
ResponseData
call
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
method
,
RequestData
requestBody
)
{
{
if
(
"create"
.
equalsIgnoreCase
(
method
))
if
(
"create"
.
equalsIgnoreCase
(
method
))
{
{
if
(
create
(
model
,
scope
,
datasource
,
requestBody
.
getBaseData
())
)
if
(
create
(
model
,
scope
,
link
,
requestBody
.
getBaseData
())!=
null
)
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
else
else
return
ResponseData
.
error
(
1
,
""
);
return
ResponseData
.
error
(
1
,
""
);
}
}
else
if
(
"update"
.
equalsIgnoreCase
(
method
))
else
if
(
"update"
.
equalsIgnoreCase
(
method
))
{
{
if
(
update
(
model
,
scope
,
datasource
,
requestBody
.
getBaseData
())
)
if
(
update
(
model
,
scope
,
link
,
requestBody
.
getBaseData
())!=
null
)
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
else
else
return
ResponseData
.
error
(
1
,
""
);
return
ResponseData
.
error
(
1
,
""
);
}
}
else
if
(
"save"
.
equalsIgnoreCase
(
method
))
else
if
(
"save"
.
equalsIgnoreCase
(
method
))
{
{
if
(
save
(
model
,
scope
,
datasource
,
requestBody
.
getBaseData
())
)
if
(
save
(
model
,
scope
,
link
,
requestBody
.
getBaseData
())!=
null
)
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
else
else
return
ResponseData
.
error
(
1
,
""
);
return
ResponseData
.
error
(
1
,
""
);
...
@@ -95,7 +101,7 @@ public class BaseDataService implements IDataService {
...
@@ -95,7 +101,7 @@ public class BaseDataService implements IDataService {
key
=
model
.
getKeyValue
(
requestBody
.
getBaseData
(),
false
);
key
=
model
.
getKeyValue
(
requestBody
.
getBaseData
(),
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
if
(
ObjectUtils
.
isEmpty
(
key
))
return
ResponseData
.
error
(
400
,
"key 没有输入"
);
return
ResponseData
.
error
(
400
,
"key 没有输入"
);
if
(
remove
(
model
,
scope
,
datasource
,
key
))
if
(
remove
(
model
,
scope
,
link
,
key
))
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
else
else
return
ResponseData
.
error
(
1
,
""
);
return
ResponseData
.
error
(
1
,
""
);
...
@@ -107,7 +113,7 @@ public class BaseDataService implements IDataService {
...
@@ -107,7 +113,7 @@ public class BaseDataService implements IDataService {
key
=
model
.
getKeyValue
(
requestBody
.
getBaseData
(),
false
);
key
=
model
.
getKeyValue
(
requestBody
.
getBaseData
(),
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
if
(
ObjectUtils
.
isEmpty
(
key
))
return
ResponseData
.
error
(
400
,
"key 没有输入"
);
return
ResponseData
.
error
(
400
,
"key 没有输入"
);
BaseData
data
=
get
(
model
,
scope
,
datasource
,
key
);
BaseData
data
=
get
(
model
,
scope
,
link
,
key
);
if
(
data
!=
null
)
if
(
data
!=
null
)
return
ResponseData
.
ok
(
data
);
return
ResponseData
.
ok
(
data
);
else
else
...
@@ -115,110 +121,157 @@ public class BaseDataService implements IDataService {
...
@@ -115,110 +121,157 @@ public class BaseDataService implements IDataService {
}
}
else
if
(
"checkKey"
.
equalsIgnoreCase
(
method
))
else
if
(
"checkKey"
.
equalsIgnoreCase
(
method
))
{
{
if
(
checkKey
(
model
,
scope
,
datasource
,
requestBody
.
getBaseData
()))
if
(
checkKey
(
model
,
scope
,
link
,
requestBody
.
getBaseData
()))
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
return
ResponseData
.
ok
(
requestBody
.
getBaseData
());
else
else
return
ResponseData
.
error
(
1
,
""
);
return
ResponseData
.
error
(
1
,
""
);
}
}
else
if
(
"getDraft"
.
equalsIgnoreCase
(
method
))
else
if
(
"getDraft"
.
equalsIgnoreCase
(
method
))
{
{
return
ResponseData
.
ok
(
getDraft
(
model
,
scope
,
datasource
,
requestBody
.
getBaseData
()));
return
ResponseData
.
ok
(
getDraft
(
model
,
scope
,
link
,
requestBody
.
getBaseData
()));
}
}
else
if
(
"createBatch"
.
equalsIgnoreCase
(
method
))
else
if
(
"createBatch"
.
equalsIgnoreCase
(
method
))
{
{
createBatch
(
model
,
scope
,
datasource
,
requestBody
.
getListData
());
createBatch
(
model
,
scope
,
link
,
requestBody
.
getListData
());
return
ResponseData
.
ok
(
true
);
return
ResponseData
.
ok
(
true
);
}
}
else
if
(
"updateBatch"
.
equalsIgnoreCase
(
method
))
else
if
(
"updateBatch"
.
equalsIgnoreCase
(
method
))
{
{
updateBatch
(
model
,
scope
,
datasource
,
requestBody
.
getListData
());
updateBatch
(
model
,
scope
,
link
,
requestBody
.
getListData
());
return
ResponseData
.
ok
(
true
);
return
ResponseData
.
ok
(
true
);
}
}
else
if
(
"saveBatch"
.
equalsIgnoreCase
(
method
))
else
if
(
"saveBatch"
.
equalsIgnoreCase
(
method
))
{
{
saveBatch
(
model
,
scope
,
datasource
,
requestBody
.
getListData
());
saveBatch
(
model
,
scope
,
link
,
requestBody
.
getListData
());
return
ResponseData
.
ok
(
true
);
return
ResponseData
.
ok
(
true
);
}
}
return
null
;
return
null
;
}
}
@Override
@Override
public
boolean
create
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
BaseData
create
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
model
.
fillParentKey
(
et
).
fillDefaultValue
(
et
,
true
);
return
getProxyService
(
datasource
).
create
(
model
,
scope
,
datasource
,
et
);
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
getProxyService
(
link
).
create
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
),
true
));
}
}
@Override
@Override
public
void
createBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
public
List
<
BaseData
>
createBatch
(
DOModel
model
,
String
scope
,
DSLink
link
,
List
<
BaseData
>
list
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
getProxyService
(
datasource
).
createBatch
(
model
,
scope
,
datasource
,
list
);
list
.
forEach
(
et
->
{
model
.
fillParentKey
(
et
).
fillDefaultValue
(
et
,
true
);
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
});
return
getProxyService
(
link
).
createBatch
(
link
,
poSchema
,
poSchema
.
trans2PO
(
list
),
false
);
}
}
@Override
@Override
public
boolean
update
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
BaseData
update
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
model
.
fillParentKey
(
et
).
fillDefaultValue
(
et
,
false
);
return
getProxyService
(
datasource
).
update
(
model
,
scope
,
datasource
,
et
);
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
getProxyService
(
link
).
update
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
),
true
));
}
}
@Override
@Override
public
void
updateBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
public
List
<
BaseData
>
updateBatch
(
DOModel
model
,
String
scope
,
DSLink
link
,
List
<
BaseData
>
list
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
getProxyService
(
datasource
).
updateBatch
(
model
,
scope
,
datasource
,
list
);
list
.
forEach
(
et
->
{
model
.
fillParentKey
(
et
).
fillDefaultValue
(
et
,
false
);
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
});
return
getProxyService
(
link
).
updateBatch
(
link
,
poSchema
,
poSchema
.
trans2PO
(
list
),
false
);
}
}
@Override
@Override
public
boolean
remove
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
public
boolean
remove
(
DOModel
model
,
String
scope
,
DSLink
link
,
Serializable
key
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
if
(
ObjectUtils
.
isEmpty
(
key
))
return
getProxyService
(
datasource
).
remove
(
model
,
scope
,
datasource
,
key
);
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
link
).
removeByMap
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
));
}
}
@Override
@Override
public
void
removeBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
public
boolean
removeBatch
(
DOModel
model
,
String
scope
,
DSLink
link
,
List
<
Serializable
>
idList
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
getProxyService
(
datasource
).
removeBatch
(
model
,
scope
,
datasource
,
idList
);
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
});
return
getProxyService
(
link
).
removeByMapBatch
(
link
,
poSchema
,
poSchema
.
trans2PO
(
batch
));
}
}
@Override
@Override
public
boolean
removeByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
boolean
removeByMap
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
return
getProxyService
(
datasource
).
removeByMap
(
model
,
scope
,
datasource
,
et
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
link
).
removeByMap
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
));
}
}
@Override
@Override
public
BaseData
get
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
public
BaseData
get
(
DOModel
model
,
String
scope
,
DSLink
link
,
Serializable
key
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
if
(
ObjectUtils
.
isEmpty
(
key
))
return
getProxyService
(
datasource
).
get
(
model
,
scope
,
datasource
,
key
);
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
getProxyService
(
link
).
getByMap
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
)));
}
}
@Override
@Override
public
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
public
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
DSLink
link
,
List
<
Serializable
>
idList
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
datasource
).
getBatch
(
model
,
scope
,
datasource
,
idList
);
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
});
return
poSchema
.
trans
(
getProxyService
(
link
).
getByMapBatch
(
link
,
poSchema
,
poSchema
.
trans2PO
(
batch
)));
}
}
@Override
@Override
public
BaseData
getByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
BaseData
getByMap
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
return
getProxyService
(
datasource
).
getByMap
(
model
,
scope
,
datasource
,
et
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
getProxyService
(
link
).
getByMap
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
)));
}
}
@Override
@Override
public
BaseData
getDraft
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
BaseData
getDraft
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
model
.
fillParentKey
(
et
);
model
.
fillParentKey
(
et
);
if
(!
ObjectUtils
.
isEmpty
(
et
.
getParentDatas
()))
if
(!
ObjectUtils
.
isEmpty
(
et
.
getParentDatas
()))
{
{
et
.
getParentDatas
().
entrySet
().
forEach
(
entry
->{
et
.
getParentDatas
().
entrySet
().
forEach
(
entry
->{
...
@@ -258,80 +311,135 @@ public class BaseDataService implements IDataService {
...
@@ -258,80 +311,135 @@ public class BaseDataService implements IDataService {
}
}
@Override
@Override
public
boolean
checkKey
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
boolean
checkKey
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
return
getProxyService
(
datasource
).
checkKey
(
model
,
scope
,
datasource
,
et
);
if
(
ObjectUtils
.
isEmpty
(
key
))
return
false
;
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
link
).
checkKey
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
));
}
}
@Override
@Override
public
boolean
save
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
BaseData
save
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
if
(
checkKey
(
model
,
scope
,
link
,
et
))
return
getProxyService
(
datasource
).
save
(
model
,
scope
,
datasource
,
et
);
return
update
(
model
,
scope
,
link
,
et
);
else
return
create
(
model
,
scope
,
link
,
et
);
}
}
@Override
@Override
public
void
saveBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
public
List
<
BaseData
>
saveBatch
(
DOModel
model
,
String
scope
,
DSLink
link
,
List
<
BaseData
>
list
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
getProxyService
(
datasource
).
saveBatch
(
model
,
scope
,
datasource
,
list
);
List
<
BaseData
>
rt
=
poSchema
.
trans
(
getProxyService
(
link
).
getBatchKey
(
link
,
poSchema
,
poSchema
.
trans2PO
(
list
)));
Map
<
Serializable
,
Integer
>
keys
=
new
LinkedHashMap
<>();
rt
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(!
ObjectUtils
.
isEmpty
(
key
))
keys
.
put
(
key
,
1
);
});
List
<
BaseData
>
create
=
new
ArrayList
<>();
List
<
BaseData
>
update
=
new
ArrayList
<>();
list
.
forEach
(
et
->
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
keys
.
containsKey
(
key
))
update
.
add
(
et
);
else
create
.
add
(
et
);
});
List
rtList
=
new
ArrayList
<>();
if
(
update
.
size
()>
0
)
rtList
.
addAll
(
this
.
updateBatch
(
model
,
scope
,
link
,
update
));
if
(
create
.
size
()>
0
)
rtList
.
addAll
(
this
.
createBatch
(
model
,
scope
,
link
,
create
));
return
rtList
;
}
}
@Override
@Override
public
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
public
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
model
.
fillParentKey
(
et
);
return
getProxyService
(
datasource
).
select
(
model
,
scope
,
datasource
,
et
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
getProxyService
(
link
).
select
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
)));
}
}
@Override
@Override
public
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
,
Pageable
pageable
)
public
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
DSLink
link
,
BaseData
et
,
Pageable
pageable
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
model
.
fillParentKey
(
et
);
return
getProxyService
(
datasource
).
select
(
model
,
scope
,
datasource
,
et
,
pageable
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
Page
<
BaseData
>
pages
=
getProxyService
(
link
).
select
(
link
,
poSchema
,
poSchema
.
trans2PO
(
et
),
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
}
@Override
@Override
public
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
)
public
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
dataQuery
,
FilterData
context
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
datasource
).
query
(
model
,
scope
,
datasource
,
dataQuery
,
context
);
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
getProxyService
(
link
).
query
(
link
,
poSchema
,
dataQuery
,
context
));
}
}
@Override
@Override
public
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
public
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
datasource
).
query
(
model
,
scope
,
datasource
,
dataQuery
,
context
,
pageable
);
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
getProxyService
(
link
).
query
(
link
,
poSchema
,
dataQuery
,
context
,
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
}
@Override
@Override
public
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
FilterData
context
)
public
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
sql
,
FilterData
context
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
(
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
()
);
return
getProxyService
(
datasource
).
selectRaw
(
model
,
scope
,
datasource
,
sql
,
context
);
return
getProxyService
(
link
).
selectRaw
(
link
,
poSchema
,
sql
,
context
);
}
}
@Override
@Override
public
boolean
execRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
BaseData
param
)
public
boolean
execRaw
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
sql
,
BaseData
param
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
(
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
()
);
return
getProxyService
(
datasource
).
execRaw
(
model
,
scope
,
datasource
,
sql
,
param
);
return
getProxyService
(
link
).
execRaw
(
link
,
poSchema
,
sql
,
param
);
}
}
@Override
@Override
public
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
)
public
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
dataSet
,
FilterData
context
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
datasource
).
fetch
(
model
,
scope
,
datasource
,
dataSet
,
context
);
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
getProxyService
(
link
).
fetch
(
link
,
poSchema
,
dataSet
,
context
));
}
}
@Override
@Override
public
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
public
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
DSLink
link
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
getProxyService
(
datasource
).
fetch
(
model
,
scope
,
datasource
,
dataSet
,
context
,
pageable
);
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
getProxyService
(
link
).
fetch
(
link
,
poSchema
,
dataSet
,
context
,
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
}
...
...
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DbDataServiceImpl.java
已删除
100644 → 0
浏览文件 @
e8233e50
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.dto.*
;
import
cn.ibizlab.core.data.mapper.DbDataMapper
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.model.PojoSchema
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IDataService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.util.*
;
/**
* 实体[业务实体] 无存储服务对象接口实现
*/
@Slf4j
@Service
public
class
DbDataServiceImpl
implements
IDataService
{
@Value
(
"${ibiz.data.batchsize:500}"
)
private
int
BATCH_SIZE
;
@Autowired
private
DbDataMapper
dbDataMapper
;
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
ResponseData
call
(
DOModel
model
,
String
scope
,
String
datasource
,
String
method
,
RequestData
requestData
)
{
return
null
;
}
@Override
public
boolean
create
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
if
(
dbDataMapper
.
insertData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
))==
1
)
et
.
setAll
(
get
(
model
,
scope
,
datasource
,
key
));
return
true
;
}
@Override
public
void
createBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
insertBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
insertBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
update
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
dbDataMapper
.
updateData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
et
.
setAll
(
get
(
model
,
scope
,
datasource
,(
Serializable
)
key
));
return
true
;
}
@Override
public
void
updateBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
updateBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
updateBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
remove
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
{
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
dbDataMapper
.
removeData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
true
;
}
@Override
public
void
removeBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
idList
.
forEach
(
key
->{
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
dbDataMapper
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
removeByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
dbDataMapper
.
removeData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
true
;
}
@Override
public
BaseData
get
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
{
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
List
<
BaseData
>
list
=
dbDataMapper
.
getData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
model
.
getName
(),
key
.
toString
());
return
poSchema
.
trans
(
list
.
get
(
0
));
}
@Override
public
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
idList
.
forEach
(
key
->{
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
poSchema
.
trans2PO
(
batch
);
rt
.
addAll
(
dbDataMapper
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
rt
.
addAll
(
dbDataMapper
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
return
poSchema
.
trans
(
rt
);
}
@Override
public
BaseData
getByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
List
<
BaseData
>
list
=
dbDataMapper
.
getData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
model
.
getName
(),
key
.
toString
());
return
poSchema
.
trans
(
list
.
get
(
0
));
}
@Override
public
BaseData
getDraft
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
model
.
fillParentKey
(
et
);
if
(!
ObjectUtils
.
isEmpty
(
et
.
getParentDatas
()))
{
et
.
getParentDatas
().
entrySet
().
forEach
(
entry
->{
String
refSchemaKey
=
entry
.
getKey
();
BaseData
parent
=
entry
.
getValue
();
if
(
parent
.
keySet
().
size
()==
0
)
return
;
PojoSchema
refSchema
=
model
.
getSchema
().
getRefSchema
(
refSchemaKey
);
Map
<
String
,
PojoSchema
>
refProperties
=
refSchema
.
getRefProperties
();
if
(
refProperties
.
size
()<=
1
)
return
;
if
((!
StringUtils
.
isEmpty
(
refSchema
.
getName
()))&&(!
StringUtils
.
isEmpty
(
parent
.
getKey
())))
{
}
});
}
return
et
;
}
@Override
public
boolean
checkKey
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
return
false
;
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
int
cnt
=
dbDataMapper
.
countData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
cnt
==
1
;
}
@Override
public
boolean
save
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
if
(
checkKey
(
model
,
scope
,
datasource
,
et
))
return
update
(
model
,
scope
,
datasource
,
et
);
else
return
create
(
model
,
scope
,
datasource
,
et
);
}
@Override
public
void
saveBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
poSchema
.
trans2PO
(
batch
);
rt
.
addAll
(
dbDataMapper
.
getBatchKey
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
rt
.
addAll
(
dbDataMapper
.
getBatchKey
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
Map
<
Serializable
,
Integer
>
keys
=
new
LinkedHashMap
<>();
rt
.
forEach
(
et
->{
poSchema
.
trans
(
et
);
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(!
ObjectUtils
.
isEmpty
(
key
))
keys
.
put
(
key
,
1
);
});
List
<
BaseData
>
create
=
new
ArrayList
<>();
List
<
BaseData
>
update
=
new
ArrayList
<>();
list
.
forEach
(
et
->
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
keys
.
containsKey
(
key
))
update
.
add
(
et
);
else
create
.
add
(
et
);
});
if
(
update
.
size
()>
0
)
this
.
updateBatch
(
model
,
scope
,
datasource
,
update
);
if
(
create
.
size
()>
0
)
this
.
createBatch
(
model
,
scope
,
datasource
,
create
);
}
@Override
public
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
dbDataMapper
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
)));
}
@Override
public
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
dbDataMapper
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
),
FilterData
.
getPages
(
poSchema
,
pageable
));
return
new
PageImpl
<
BaseData
>(
poSchema
.
trans
(
pages
.
getRecords
()),
pageable
,
pages
.
getTotal
());
}
@Override
public
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
dbDataMapper
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-dq-"
+
dataQuery
+
"-"
),
context
,
context
.
getSearchCond
()));
}
@Override
public
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
dbDataMapper
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-dq-"
+
dataQuery
+
"-"
),
context
,
context
.
getSearchCond
(),
context
.
getPages
());
return
new
PageImpl
<
BaseData
>(
poSchema
.
trans
(
pages
.
getRecords
()),
pageable
,
pages
.
getTotal
());
}
@Override
public
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
dbDataMapper
.
queryData
(
link
.
getName
(),
poSchema
,
sql
,
context
,
context
.
getSearchCond
());
}
@Override
public
boolean
execRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
BaseData
param
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
dbDataMapper
.
executeRaw
(
link
.
getName
(),
poSchema
,
sql
,
param
);
}
@Override
public
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
dbDataMapper
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-ds-"
+
dataSet
+
"-"
),
context
,
context
.
getSearchCond
()));
}
@Override
public
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
dbDataMapper
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-ds-"
+
dataSet
+
"-"
),
context
,
context
.
getSearchCond
(),
context
.
getPages
());
return
new
PageImpl
<
BaseData
>(
poSchema
.
trans
(
pages
.
getRecords
()),
pageable
,
pages
.
getTotal
());
}
@Override
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
modelService
.
getDOModel
(
system
,
entity
);
}
@Autowired
private
ModelService
modelService
;
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/DbPersistentServiceImpl.java
0 → 100644
浏览文件 @
b0595b0b
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.mapper.DbDataMapper
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IPersistentService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.context.annotation.Primary
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageImpl
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@Primary
@Service
@Slf4j
public
class
DbPersistentServiceImpl
implements
IPersistentService
{
@Value
(
"${ibiz.data.batchsize:500}"
)
private
int
BATCH_SIZE
;
@Autowired
private
DbDataMapper
repository
;
@Override
public
BaseData
create
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
insertData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
createBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
list
.
forEach
(
et
->{
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
repository
.
insertBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
repository
.
insertBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
BaseData
update
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
updateData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
updateBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
list
.
forEach
(
et
->{
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
repository
.
updateBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
repository
.
updateBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
boolean
remove
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
return
true
;
}
@Override
public
boolean
removeByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
list
.
forEach
(
et
->{
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
return
true
;
}
@Override
public
BaseData
get
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
poSchema
.
getName
(),
key
.
toString
());
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
rt
.
addAll
(
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
rt
.
addAll
(
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
return
rt
;
}
@Override
public
BaseData
getByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
poSchema
.
getName
(),
""
);
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
list
.
forEach
(
et
->{
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
rt
.
addAll
(
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
rt
.
addAll
(
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
return
rt
;
}
@Override
public
List
<
BaseData
>
getBatchKey
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
list
.
forEach
(
et
->{
batch
.
add
(
et
);
if
(
batch
.
size
()>=
BATCH_SIZE
)
{
rt
.
addAll
(
repository
.
getBatchKey
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
});
if
(
batch
.
size
()>
0
)
{
rt
.
addAll
(
repository
.
getBatchKey
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
return
rt
;
}
@Override
public
Long
count
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
boolean
checkKey
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
Long
cnt
=
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
return
cnt
==
1
;
}
@Override
public
BaseData
save
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
if
(
checkKey
(
link
,
poSchema
,
et
))
return
update
(
link
,
poSchema
,
et
,
bGet
);
else
return
create
(
link
,
poSchema
,
et
,
bGet
);
}
@Override
public
List
<
BaseData
>
saveBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
List
<
BaseData
>
rt
=
this
.
getBatchKey
(
link
,
poSchema
,
list
);
Map
<
Serializable
,
Integer
>
keys
=
new
LinkedHashMap
<>();
rt
.
forEach
(
et
->{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(!
ObjectUtils
.
isEmpty
(
key
))
keys
.
put
(
key
,
1
);
});
List
<
BaseData
>
create
=
new
ArrayList
<>();
List
<
BaseData
>
update
=
new
ArrayList
<>();
list
.
forEach
(
et
->
{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(
keys
.
containsKey
(
key
))
update
.
add
(
et
);
else
create
.
add
(
et
);
});
List
rtList
=
new
ArrayList
<>();
if
(
update
.
size
()>
0
)
rtList
.
addAll
(
this
.
updateBatch
(
link
,
poSchema
,
update
,
bGet
));
if
(
create
.
size
()>
0
)
rtList
.
addAll
(
this
.
createBatch
(
link
,
poSchema
,
create
,
bGet
));
return
rtList
;
}
@Override
public
List
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
selectData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
Page
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
Pageable
pageable
)
{
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
repository
.
selectData
(
link
.
getName
(),
poSchema
,
et
,
FilterData
.
getPages
(
poSchema
,
pageable
));
return
new
PageImpl
<
BaseData
>(
pages
.
getRecords
(),
pageable
,
pages
.
getTotal
());
}
@Override
public
List
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-dq-"
+
dataQuery
+
"-"
),
context
,
context
.
getSearchCond
());
}
@Override
public
Page
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-dq-"
+
dataQuery
+
"-"
),
context
,
context
.
getSearchCond
(),
context
.
getPages
());
return
new
PageImpl
<
BaseData
>(
pages
.
getRecords
(),
pageable
,
pages
.
getTotal
());
}
@Override
public
List
<
BaseData
>
selectRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
FilterData
context
)
{
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
sql
,
context
,
context
.
getSearchCond
());
}
@Override
public
boolean
execRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
BaseData
param
)
{
repository
.
executeRaw
(
link
.
getName
(),
poSchema
,
sql
,
param
);
return
true
;
}
@Override
public
List
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-ds-"
+
dataSet
+
"-"
),
context
,
context
.
getSearchCond
());
}
@Override
public
Page
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
com
.
baomidou
.
mybatisplus
.
extension
.
plugins
.
pagination
.
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
context
.
getSql
(
"-ds-"
+
dataSet
+
"-"
),
context
,
context
.
getSearchCond
(),
context
.
getPages
());
return
new
PageImpl
<
BaseData
>(
pages
.
getRecords
(),
pageable
,
pages
.
getTotal
());
}
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
}
@Override
public
POSchema
getSchema
(
DSLink
link
,
String
table
)
{
return
null
;
}
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/MongoDataServiceImpl.java
已删除
100644 → 0
浏览文件 @
e8233e50
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
cn.ibizlab.core.data.domain.DOModel
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.dto.RequestData
;
import
cn.ibizlab.core.data.dto.ResponseData
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.repository.MongoDataRepository
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IDataService
;
import
cn.ibizlab.core.data.service.ModelService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
org.springframework.util.StringUtils
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* 实体[业务实体] 无存储服务对象接口实现
*/
@Slf4j
@Service
public
class
MongoDataServiceImpl
implements
IDataService
{
@Autowired
private
MongoDataRepository
mongoDataRepository
;
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
ResponseData
call
(
DOModel
model
,
String
scope
,
String
datasource
,
String
method
,
RequestData
requestData
)
{
return
null
;
}
@Override
public
boolean
create
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
if
(
mongoDataRepository
.
insertData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
))==
1
)
et
.
setAll
(
get
(
model
,
scope
,
datasource
,
key
));
return
true
;
}
@Override
public
void
createBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
mongoDataRepository
.
insertBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
update
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
mongoDataRepository
.
updateData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
et
.
setAll
(
get
(
model
,
scope
,
datasource
,(
Serializable
)
key
));
return
true
;
}
@Override
public
void
updateBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
mongoDataRepository
.
updateBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
remove
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
{
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
mongoDataRepository
.
removeData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
true
;
}
@Override
public
void
removeBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
idList
.
forEach
(
key
->{
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
mongoDataRepository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
boolean
removeByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
mongoDataRepository
.
removeData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
true
;
}
@Override
public
BaseData
get
(
DOModel
model
,
String
scope
,
String
datasource
,
Serializable
key
)
{
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
List
<
BaseData
>
list
=
mongoDataRepository
.
getData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
model
.
getName
(),
key
.
toString
());
return
poSchema
.
trans
(
list
.
get
(
0
));
}
@Override
public
List
<
BaseData
>
getBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
rt
=
new
ArrayList
<>();
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
idList
.
forEach
(
key
->{
BaseData
et
=
model
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
rt
.
addAll
(
mongoDataRepository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
));
batch
.
clear
();
}
return
poSchema
.
trans
(
rt
);
}
@Override
public
BaseData
getByMap
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
List
<
BaseData
>
list
=
mongoDataRepository
.
getData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
model
.
getName
(),
key
.
toString
());
return
poSchema
.
trans
(
list
.
get
(
0
));
}
@Override
public
BaseData
getDraft
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
return
et
;
}
@Override
public
boolean
checkKey
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
return
false
;
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
int
cnt
=
mongoDataRepository
.
countData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
return
cnt
==
1
;
}
@Override
public
boolean
save
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
Serializable
key
=
model
.
getKeyValue
(
et
,
true
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
mongoDataRepository
.
saveData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
));
et
.
setAll
(
get
(
model
,
scope
,
datasource
,(
Serializable
)
key
));
return
true
;
}
@Override
public
void
saveBatch
(
DOModel
model
,
String
scope
,
String
datasource
,
List
<
BaseData
>
list
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
list
.
forEach
(
et
->{
Serializable
key
=
model
.
getKeyValue
(
et
,
false
);
if
(
ObjectUtils
.
isEmpty
(
key
))
throw
new
BadRequestAlertException
(
"未找到主键"
,
model
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>=
0
)
{
poSchema
.
trans2PO
(
batch
);
mongoDataRepository
.
saveBatchData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
}
@Override
public
List
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
poSchema
.
trans
(
mongoDataRepository
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
)));
}
@Override
public
Page
<
BaseData
>
select
(
DOModel
model
,
String
scope
,
String
datasource
,
BaseData
et
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
Page
<
BaseData
>
pages
=
mongoDataRepository
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
),
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
@Override
public
List
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
mongoDataRepository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
));
}
@Override
public
Page
<
BaseData
>
query
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
mongoDataRepository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
@Override
public
List
<
BaseData
>
selectRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
return
mongoDataRepository
.
queryData
(
link
.
getName
(),
poSchema
,
sql
,
context
);
}
@Override
public
boolean
execRaw
(
DOModel
model
,
String
scope
,
String
datasource
,
String
sql
,
BaseData
param
)
{
throw
new
BadRequestAlertException
(
"没有实现方法execRaw"
,
model
.
getName
(),
sql
);
}
@Override
public
List
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
return
poSchema
.
trans
(
mongoDataRepository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
));
}
@Override
public
Page
<
BaseData
>
fetch
(
DOModel
model
,
String
scope
,
String
datasource
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
if
(
StringUtils
.
isEmpty
(
datasource
))
datasource
=
model
.
getDefaultDataSource
();
DSLink
link
=
dsSettingService
.
getDataSource
(
datasource
);
POSchema
poSchema
=
model
.
getPOSchema
(
link
.
getType
());
model
.
fillParentFilter
(
context
);
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
mongoDataRepository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
poSchema
.
trans
(
pages
.
getContent
());
return
pages
;
}
@Override
public
DOModel
getDOModel
(
String
system
,
String
entity
)
{
return
modelService
.
getDOModel
(
system
,
entity
);
}
@Autowired
private
ModelService
modelService
;
}
ibzdata-core/src/main/java/cn/ibizlab/core/data/service/impl/MongoPersistentServiceImpl.java
0 → 100644
浏览文件 @
b0595b0b
package
cn
.
ibizlab
.
core
.
data
.
service
.
impl
;
import
cn.ibizlab.core.data.dto.BaseData
;
import
cn.ibizlab.core.data.dto.FilterData
;
import
cn.ibizlab.core.data.model.DSLink
;
import
cn.ibizlab.core.data.model.POSchema
;
import
cn.ibizlab.core.data.repository.MongoDataRepository
;
import
cn.ibizlab.core.data.service.IDSSettingService
;
import
cn.ibizlab.core.data.service.IPersistentService
;
import
cn.ibizlab.util.errors.BadRequestAlertException
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.Pageable
;
import
org.springframework.stereotype.Service
;
import
org.springframework.util.ObjectUtils
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
java.util.List
;
import
java.util.Map
;
@Service
@Slf4j
public
class
MongoPersistentServiceImpl
implements
IPersistentService
{
@Autowired
private
MongoDataRepository
repository
;
@Override
public
BaseData
create
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
insertData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
createBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
repository
.
insertBathData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
BaseData
update
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
repository
.
updateData
(
link
.
getName
(),
poSchema
,
et
);
if
(
bGet
)
et
.
setAll
(
getByMap
(
link
,
poSchema
,
et
));
return
et
;
}
@Override
public
List
<
BaseData
>
updateBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
repository
.
updateBathData
(
link
.
getName
(),
poSchema
,
list
);
if
(
bGet
)
return
getByMapBatch
(
link
,
poSchema
,
list
);
return
list
;
}
@Override
public
boolean
remove
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
});
if
(
batch
.
size
()>
0
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
batch
);
batch
.
clear
();
}
return
true
;
}
@Override
public
boolean
removeByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
repository
.
removeData
(
link
.
getName
(),
poSchema
,
et
);
return
true
;
}
@Override
public
boolean
removeByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
repository
.
removeBathData
(
link
.
getName
(),
poSchema
,
list
);
return
true
;
}
@Override
public
BaseData
get
(
DSLink
link
,
POSchema
poSchema
,
Serializable
key
)
{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
poSchema
.
getName
(),
key
.
toString
());
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
Serializable
>
idList
)
{
List
<
BaseData
>
batch
=
new
ArrayList
<>();
idList
.
forEach
(
key
->{
BaseData
et
=
poSchema
.
newData
(
key
);
if
(
et
==
null
)
throw
new
BadRequestAlertException
(
"未找到主键"
,
poSchema
.
getName
(),
null
);
batch
.
add
(
et
);
});
return
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
batch
);
}
@Override
public
BaseData
getByMap
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
List
<
BaseData
>
list
=
repository
.
getData
(
link
.
getName
(),
poSchema
,
et
);
if
(
ObjectUtils
.
isEmpty
(
list
)||
list
.
size
()>
1
)
throw
new
BadRequestAlertException
(
"未找到数据"
,
poSchema
.
getName
(),
""
);
return
list
.
get
(
0
);
}
@Override
public
List
<
BaseData
>
getByMapBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
return
repository
.
getBatchData
(
link
.
getName
(),
poSchema
,
list
);
}
@Override
public
List
<
BaseData
>
getBatchKey
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
)
{
return
repository
.
getBatchKey
(
link
.
getName
(),
poSchema
,
list
);
}
@Override
public
Long
count
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
boolean
checkKey
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
Long
cnt
=
repository
.
countData
(
link
.
getName
(),
poSchema
,
et
);
return
cnt
==
1
;
}
@Override
public
BaseData
save
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
boolean
bGet
)
{
if
(
checkKey
(
link
,
poSchema
,
et
))
return
update
(
link
,
poSchema
,
et
,
bGet
);
else
return
create
(
link
,
poSchema
,
et
,
bGet
);
}
@Override
public
List
<
BaseData
>
saveBatch
(
DSLink
link
,
POSchema
poSchema
,
List
<
BaseData
>
list
,
boolean
bGet
)
{
List
<
BaseData
>
rt
=
this
.
getBatchKey
(
link
,
poSchema
,
list
);
Map
<
Serializable
,
Integer
>
keys
=
new
LinkedHashMap
<>();
rt
.
forEach
(
et
->{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(!
ObjectUtils
.
isEmpty
(
key
))
keys
.
put
(
key
,
1
);
});
List
<
BaseData
>
create
=
new
ArrayList
<>();
List
<
BaseData
>
update
=
new
ArrayList
<>();
list
.
forEach
(
et
->
{
Serializable
key
=
poSchema
.
getKeyValue
(
et
,
false
);
if
(
keys
.
containsKey
(
key
))
update
.
add
(
et
);
else
create
.
add
(
et
);
});
List
rtList
=
new
ArrayList
<>();
if
(
update
.
size
()>
0
)
rtList
.
addAll
(
this
.
updateBatch
(
link
,
poSchema
,
update
,
bGet
));
if
(
create
.
size
()>
0
)
rtList
.
addAll
(
this
.
createBatch
(
link
,
poSchema
,
create
,
bGet
));
return
rtList
;
}
@Override
public
List
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
)
{
return
repository
.
selectData
(
link
.
getName
(),
poSchema
,
et
);
}
@Override
public
Page
<
BaseData
>
select
(
DSLink
link
,
POSchema
poSchema
,
BaseData
et
,
Pageable
pageable
)
{
Page
<
BaseData
>
pages
=
repository
.
selectData
(
link
.
getName
(),
poSchema
,
poSchema
.
trans2PO
(
et
),
pageable
);
return
pages
;
}
@Override
public
List
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
);
}
@Override
public
Page
<
BaseData
>
query
(
DSLink
link
,
POSchema
poSchema
,
String
dataQuery
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
return
pages
;
}
@Override
public
List
<
BaseData
>
selectRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
FilterData
context
)
{
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
sql
,
context
);
}
@Override
public
boolean
execRaw
(
DSLink
link
,
POSchema
poSchema
,
String
sql
,
BaseData
param
)
{
throw
new
BadRequestAlertException
(
"没有实现方法execRaw"
,
poSchema
.
getName
(),
sql
);
}
@Override
public
List
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
)
{
context
.
setPOSchema
(
poSchema
);
return
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
);
}
@Override
public
Page
<
BaseData
>
fetch
(
DSLink
link
,
POSchema
poSchema
,
String
dataSet
,
FilterData
context
,
Pageable
pageable
)
{
context
.
setPOSchema
(
poSchema
);
if
(
pageable
!=
null
)
context
.
setPageable
(
pageable
);
else
pageable
=
context
.
getPageable
();
Page
<
BaseData
>
pages
=
repository
.
queryData
(
link
.
getName
(),
poSchema
,
""
,
context
,
pageable
);
return
pages
;
}
@Autowired
private
IDSSettingService
dsSettingService
;
@Override
public
DSLink
getDSLink
(
String
datasource
)
{
return
dsSettingService
.
getDataSource
(
datasource
);
}
@Override
public
POSchema
getSchema
(
DSLink
link
,
String
table
)
{
return
null
;
}
}
ibzdata-core/src/main/resources/mapper/data/DbData/DbDataMapper.xml
浏览文件 @
b0595b0b
...
@@ -88,7 +88,7 @@
...
@@ -88,7 +88,7 @@
</foreach>
</foreach>
</select>
</select>
<select
id=
"countData"
parameterType=
"cn.ibizlab.core.data.dto.BaseData"
resultType=
"java.lang.
Integer
"
>
<select
id=
"countData"
parameterType=
"cn.ibizlab.core.data.dto.BaseData"
resultType=
"java.lang.
Long
"
>
select count(1) as cnt from ${schema.name}
select count(1) as cnt from ${schema.name}
where
where
<if
test=
"schema.logicValidColumn!=null"
>
<if
test=
"schema.logicValidColumn!=null"
>
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录