Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
功
功能演示系统
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
示例
功能演示系统
提交
9ce3c14b
提交
9ce3c14b
编写于
4年前
作者:
ibizdev
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Mosher 发布系统代码 [后台服务,演示应用]
上级
cf35628b
变更
6
隐藏空白字符变更
内嵌
并排
正在显示
6 个修改的文件
包含
218 行增加
和
3 行删除
+218
-3
IBIZBOOKDataImport.java
...va/cn/ibizlab/core/sample/mapping/IBIZBOOKDataImport.java
+25
-0
IBIZOrderImport.java
.../java/cn/ibizlab/core/sample/mapping/IBIZOrderImport.java
+2
-2
IIBIZBOOKService.java
...java/cn/ibizlab/core/sample/service/IIBIZBOOKService.java
+4
-0
IBIZBOOKServiceImpl.java
...ibizlab/core/sample/service/impl/IBIZBOOKServiceImpl.java
+168
-0
h2_table.xml
demo-core/src/main/resources/liquibase/h2_table.xml
+1
-1
IBIZBOOKResource.java
...c/main/java/cn/ibizlab/demoapi/rest/IBIZBOOKResource.java
+18
-0
未找到文件。
demo-core/src/main/java/cn/ibizlab/core/sample/mapping/IBIZBOOKDataImport.java
0 → 100644
浏览文件 @
9ce3c14b
package
cn
.
ibizlab
.
core
.
sample
.
mapping
;
import
cn.ibizlab.core.sample.domain.IBIZBOOK
;
import
org.mapstruct.*
;
import
java.util.List
;
@Mapper
(
componentModel
=
"spring"
,
uses
=
{})
public
interface
IBIZBOOKDataImport
{
@Mappings
({
@Mapping
(
target
=
"ibizbookid"
,
source
=
"ibizbookid"
),
@Mapping
(
target
=
"type"
,
source
=
"type"
),
@Mapping
(
target
=
"press"
,
source
=
"press"
),
@Mapping
(
target
=
"author"
,
source
=
"author"
),
@Mapping
(
target
=
"price"
,
source
=
"price"
),
@Mapping
(
target
=
"ibizbookname"
,
source
=
"ibizbookname"
),
})
@BeanMapping
(
ignoreByDefault
=
true
)
IBIZBOOK
toDomain
(
IBIZBOOK
entity
);
List
<
IBIZBOOK
>
toDomain
(
List
<
IBIZBOOK
>
entities
);
}
This diff is collapsed.
Click to expand it.
demo-core/src/main/java/cn/ibizlab/core/sample/mapping/IBIZOrderImport.java
浏览文件 @
9ce3c14b
...
...
@@ -8,10 +8,10 @@ import java.util.List;
public
interface
IBIZOrderImport
{
@Mappings
({
@Mapping
(
target
=
"ibizorderid"
,
source
=
"ibizorderid"
),
@Mapping
(
target
=
"ibizordername"
,
source
=
"ibizordername"
),
@Mapping
(
target
=
"ordertype"
,
source
=
"ordertype"
),
@Mapping
(
target
=
"ordertime"
,
source
=
"ordertime"
),
@Mapping
(
target
=
"orderuid"
,
source
=
"orderuid"
),
@Mapping
(
target
=
"ibizordername"
,
source
=
"ibizordername"
),
@Mapping
(
target
=
"ordertype"
,
source
=
"ordertype"
),
})
@BeanMapping
(
ignoreByDefault
=
true
)
IBIZOrder
toDomain
(
IBIZOrder
entity
);
...
...
This diff is collapsed.
Click to expand it.
demo-core/src/main/java/cn/ibizlab/core/sample/service/IIBIZBOOKService.java
浏览文件 @
9ce3c14b
...
...
@@ -37,6 +37,10 @@ public interface IIBIZBOOKService extends IService<IBIZBOOK> {
boolean
save
(
IBIZBOOK
et
);
void
saveBatch
(
List
<
IBIZBOOK
>
list
);
Page
<
IBIZBOOK
>
searchDefault
(
IBIZBOOKSearchContext
context
);
JSONObject
importData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
);
@Async
(
"asyncExecutor"
)
void
asyncImportData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
);
/**
*自定义查询SQL
* @param sql select * from table where id =#{et.param}
...
...
This diff is collapsed.
Click to expand it.
demo-core/src/main/java/cn/ibizlab/core/sample/service/impl/IBIZBOOKServiceImpl.java
浏览文件 @
9ce3c14b
...
...
@@ -213,6 +213,174 @@ public class IBIZBOOKServiceImpl extends ServiceImpl<IBIZBOOKMapper, IBIZBOOK> i
}
}
@Autowired
@Lazy
IIBIZBOOKService
proxyService
;
@Value
(
"${ibiz.syncImportLimit:1000}"
)
private
int
syncImportLimit
;
/**
* 上传数据检查
* @param entities
* @param isIgnoreError
* @return
*/
private
JSONObject
testImportData
(
List
<
IBIZBOOK
>
entities
,
boolean
isIgnoreError
)
{
JSONObject
rs
=
new
JSONObject
();
Set
ids
=
new
HashSet
<>();
List
<
String
>
errorMsgs
=
new
ArrayList
<>();
List
<
Integer
>
errorLines
=
new
ArrayList
<>();
List
<
IBIZBOOK
>
duplicateKeys
=
new
ArrayList
<>();
String
keyField
=
DEFieldCacheMap
.
getDEKeyField
(
IBIZBOOK
.
class
);
if
(
ObjectUtils
.
isEmpty
(
keyField
)){
errorLines
.
add
(
1
);
rs
.
put
(
"rst"
,
1
);
rs
.
put
(
"msg"
,
"数据导入失败,未能获取到实体[IBIZBOOK]的主键属性"
);
rs
.
put
(
"errorLines"
,
errorLines
);
return
rs
;
}
//主键重复性判断.外键约束判断(上传数据自身的检查/数据库的检查)
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
IBIZBOOK
entity
=
entities
.
get
(
i
);
Object
id
=
entity
.
getIbizbookid
();
if
(
ObjectUtils
.
isEmpty
(
id
))
{
id
=
entity
.
getDefaultKey
(
true
);
if
(
ObjectUtils
.
isEmpty
(
id
)){
Integer
lineNum
=
i
+
1
;
errorLines
.
add
(
lineNum
);
errorMsgs
.
add
(
"第"
+
lineNum
+
"行:无法获取当前数据主键。"
);
continue
;
}
else
{
entity
.
setIbizbookid
((
String
)
id
);
}
}
if
(!
ids
.
contains
(
id
)){
ids
.
add
(
id
);
}
else
{
Integer
lineNum
=
i
+
1
;
errorLines
.
add
(
lineNum
);
errorMsgs
.
add
(
"第"
+
lineNum
+
"行:导入数据之间存在重复数据。"
);
if
(
isIgnoreError
){
duplicateKeys
.
add
(
entity
);
continue
;
}
else
{
break
;
}
}
}
if
(
duplicateKeys
.
size
()>
0
){
for
(
IBIZBOOK
duplicateKey:
duplicateKeys
){
entities
.
remove
(
duplicateKey
);
}
}
if
(
errorMsgs
.
size
()
>
0
)
{
rs
.
put
(
"rst"
,
1
);
rs
.
put
(
"msg"
,
String
.
join
(
"<br>"
,
errorMsgs
));
rs
.
put
(
"errorLines"
,
errorLines
);
return
rs
;
}
rs
.
put
(
"rst"
,
0
);
return
rs
;
}
/**
* 实体数据导入
* @param entities
* @param batchSize
* @param isIgnoreError
* @return
*/
@Override
@Transactional
public
JSONObject
importData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
)
{
if
(
entities
.
size
()>
syncImportLimit
){
proxyService
.
asyncImportData
(
entities
,
batchSize
,
isIgnoreError
);
JSONObject
rs
=
new
JSONObject
();
rs
.
put
(
"rst"
,
0
);
rs
.
put
(
"msg"
,
String
.
format
(
"当前导入数据已超过同步导入数量上限[%s],系统正在进行异步导入,请稍后!"
,
syncImportLimit
));
rs
.
put
(
"data"
,
entities
);
return
rs
;
}
else
{
return
syncImportData
(
entities
,
batchSize
,
isIgnoreError
);
}
}
@Override
@Transactional
public
void
asyncImportData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
){
executeImportData
(
entities
,
batchSize
,
isIgnoreError
);
}
@Transactional
public
JSONObject
syncImportData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
){
return
executeImportData
(
entities
,
batchSize
,
isIgnoreError
);
}
@Transactional
public
JSONObject
executeImportData
(
List
<
IBIZBOOK
>
entities
,
int
batchSize
,
boolean
isIgnoreError
)
{
JSONObject
rs
=
testImportData
(
entities
,
isIgnoreError
);
if
(
rs
.
getInteger
(
"rst"
)==
1
&&
!
isIgnoreError
)
{
return
rs
;
}
List
<
IBIZBOOK
>
tempDEList
=
new
ArrayList
<>();
Set
tempIds
=
new
HashSet
<>();
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
IBIZBOOK
entity
=
entities
.
get
(
i
);
tempDEList
.
add
(
entity
);
Object
id
=
entity
.
getIbizbookid
();
if
(!
ObjectUtils
.
isEmpty
(
id
))
{
tempIds
.
add
(
id
);
}
if
(
tempDEList
.
size
()>=
batchSize
||
(
tempDEList
.
size
()<
batchSize
&&
i
==
entities
.
size
()-
1
)){
commit
(
tempDEList
,
tempIds
);
tempDEList
.
clear
();
tempIds
.
clear
();
}
}
rs
.
put
(
"rst"
,
0
);
rs
.
put
(
"data"
,
entities
);
return
rs
;
}
/**
* 批量提交
* @param entities 数据
* @param ids 要提交数据的id
*/
@Transactional
public
void
commit
(
List
<
IBIZBOOK
>
entities
,
Set
ids
){
List
<
IBIZBOOK
>
_create
=
new
ArrayList
<>();
List
<
IBIZBOOK
>
_update
=
new
ArrayList
<>();
Set
oldIds
=
new
HashSet
<>();
if
(
ids
.
size
()>
0
){
List
<
IBIZBOOK
>
oldEntities
=
this
.
listByIds
(
ids
);
for
(
IBIZBOOK
entity:
oldEntities
){
oldIds
.
add
(
entity
.
getIbizbookid
());
}
}
for
(
IBIZBOOK
entity:
entities
){
Object
id
=
entity
.
getIbizbookid
();
if
(
oldIds
.
contains
(
id
))
{
_update
.
add
(
entity
);
}
else
{
_create
.
add
(
entity
);
}
}
if
(
_update
.
size
()>
0
)
{
proxyService
.
updateBatch
(
_update
);
}
if
(
_create
.
size
()>
0
)
{
proxyService
.
createBatch
(
_create
);
}
}
...
...
This diff is collapsed.
Click to expand it.
demo-core/src/main/resources/liquibase/h2_table.xml
浏览文件 @
9ce3c14b
...
...
@@ -28,7 +28,7 @@
<!--输出实体[IBIZBOOK]数据结构 -->
<changeSet
author=
"a_LAB01_df847bdfd"
id=
"tab-ibizbook-8
2
-2"
>
<changeSet
author=
"a_LAB01_df847bdfd"
id=
"tab-ibizbook-8
6
-2"
>
<createTable
tableName=
"T_IBIZBOOK"
>
<column
name=
"CREATEMAN"
remarks=
""
type=
"VARCHAR(60)"
>
</column>
...
...
This diff is collapsed.
Click to expand it.
demo-provider/demo-provider-demoapi/src/main/java/cn/ibizlab/demoapi/rest/IBIZBOOKResource.java
浏览文件 @
9ce3c14b
...
...
@@ -159,5 +159,23 @@ public class IBIZBOOKResource {
}
@Autowired
cn
.
ibizlab
.
core
.
sample
.
mapping
.
IBIZBOOKDataImport
dataimportImpMapping
;
@RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/ibizbooks/import"
)
public
ResponseEntity
<
JSONObject
>
importData
(
@RequestParam
(
value
=
"config"
)
String
config
,
@RequestBody
List
<
IBIZBOOK
>
dtos
){
JSONObject
rs
=
new
JSONObject
();
if
(
dtos
.
size
()==
0
){
rs
.
put
(
"rst"
,
1
);
rs
.
put
(
"msg"
,
"未传入内容"
);
return
ResponseEntity
.
status
(
HttpStatus
.
NO_CONTENT
).
body
(
rs
);
}
else
{
if
(
"DataImport"
.
equals
(
config
)){
rs
=
ibizbookService
.
importData
(
dataimportImpMapping
.
toDomain
(
dtos
),
1000
,
false
);
}
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
rs
);
}
}
}
This diff is collapsed.
Click to expand it.
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录