Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
提交反馈
为 GitLab 提交贡献
登录
切换导航
iBiz4j Spring R7
项目
项目
详情
动态
版本
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
iBiz-R7后台标准模板
iBiz4j Spring R7
提交
fdd3455d
提交
fdd3455d
编写于
7月 21, 2020
作者:
zhouweidong
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
实体数据导入
上级
ea5cc5e9
变更
5
隐藏空白字符变更
内嵌
并排
正在显示
5 个修改的文件
包含
287 行增加
和
15 行删除
+287
-15
%DE%%ITEM%.java.ftl
...S_PKGPATH%/core/%MOD_PKGPATH%/mapping/%DE%%ITEM%.java.ftl
+31
-0
I%DE%Service.java.ftl
...PKGPATH%/core/%MOD_PKGPATH%/service/I%DE%Service.java.ftl
+12
-0
%DE%ServiceImpl.java.ftl
.../core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
+203
-12
%ITEM%Resource.java.ftl
...YS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
+39
-1
DEFieldDefaultValueAspect.java.ftl
...S_PKGPATH%/util/aspect/DEFieldDefaultValueAspect.java.ftl
+2
-2
未找到文件。
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/mapping/%DE%%ITEM%.java.ftl
0 → 100644
浏览文件 @
fdd3455d
<#
ibiztemplate
>
TARGET
=
PSDEDATAIMP
</#
ibiztemplate
>
package
${
pub
.
getPKGCodeName
()}.
core
.${
de
.
getPSSystemModule
().
codeName
?
lower_case
}.
mapping
;
import
${
pub
.
getPKGCodeName
()}.
core
.${
de
.
getPSSystemModule
().
codeName
?
lower_case
}.
domain
.${
de
.
codeName
};
import
org
.
mapstruct
.*;
import
java
.
util
.
List
;
@
Mapper
(
componentModel
=
"spring"
,
uses
=
{})
public
interface
${
de
.
codeName
}${
item
.
codeName
}
{
<#
if
item
.
getPSDEDataImportItems
??
&&
item
.
getPSDEDataImportItems
()??>
@
Mappings
({
<#
list
de
.
getPSDEDataImportItems
as
importItem
>
<#
if
importItem
.
getPSDEField
()??>
<#
assign
deFieldName
=
srfcaseformat
(
importItem
.
getPSDEField
().
getCodeName
(),
'l_u2lC'
)
>
@
Mapping
(
target
=
"${deFieldName}"
,
source
=
"${deFieldName}"
),
</#
if
>
</#
list
>
})
@
BeanMapping
(
ignoreByDefault
=
true
)
</#
if
>
${
de
.
codeName
}
toDomain
(${
de
.
codeName
}
entity
);
List
<${
de
.
codeName
}>
toDomain
(
List
<${
de
.
codeName
}>
entities
);
}
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/service/I%DE%Service.java.ftl
浏览文件 @
fdd3455d
...
...
@@ -7,6 +7,14 @@ TARGET=PSDATAENTITY
<#
if
de
.
getPSDEFieldByPDT
(
'ORGID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'ORGSECTORID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'CREATEMAN'
,
true
)??
>
<#
assign
hasDEPrefield
=
true
>
</#
if
>
<#
assign
hasDEImport
=
false
>
<#
comment
>
实体数据导入
</#
comment
>
<#
if
de
.
getAllPSDEDataImports
??
&&
de
.
getAllPSDEDataImports
()??>
<#
list
de
.
getAllPSDEDataImports
()
as
deImport
>
<#
assign
hasDEImport
=
true
>
<#
break
>
</#
list
>
</#
if
>
<#
if
de
.
getStorageMode
()==
1
||
de
.
getStorageMode
()==
2
||
de
.
getStorageMode
()==
4
||
de
.
getStorageMode
()==
0
>
package
${
pub
.
getPKGCodeName
()}.
core
.${
item
.
getPSSystemModule
().
getCodeName
()?
lower_case
}.
service
;
...
...
@@ -194,6 +202,10 @@ public interface I${item.codeName}Service{
</#
if
>
</#
list
>
</#
if
>
<#
comment
>
实体数据导入
</#
comment
>
<#
if
hasDEImport
>
JSONObject
importData
(
List
<${
de
.
codeName
}>
entities
,
int
batchSize
,
boolean
isIgnoreError
);
</#
if
>
</#
macro
>
<#
comment
>
输出测试行为
</#
comment
>
...
...
SLN/%PUBPRJ%-core/src/main/java/%SYS_PKGPATH%/core/%MOD_PKGPATH%/service/impl/%DE%ServiceImpl.java.ftl
浏览文件 @
fdd3455d
...
...
@@ -58,6 +58,14 @@ TARGET=PSDATAENTITY
</#
if
>
</#
list
>
</#
if
>
<#
assign
hasDEImport
=
false
>
<#
comment
>
实体数据导入
</#
comment
>
<#
if
de
.
getAllPSDEDataImports
??
&&
de
.
getAllPSDEDataImports
()??>
<#
list
de
.
getAllPSDEDataImports
()
as
deImport
>
<#
assign
hasDEImport
=
true
>
<#
break
>
</#
list
>
</#
if
>
package
${
pub
.
getPKGCodeName
()}.
core
.${
item
.
getPSSystemModule
().
getCodeName
()?
lower_case
}.
service
.
impl
;
import
java
.
io
.
Serializable
;
...
...
@@ -580,6 +588,7 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
if
nested
>
<@
autowiredProxyService
/>
@
Override
public
void
saveBy
${
srfcaseformat
(
MajorField
.
codeName
,
'l_u2lC'
)?
cap_first
}(${
srfjavatype
(
MajorField
.
stdDataType
)}
${
MajorkeyField
.
codeName
?
lower_case
},
List
<${
item
.
getCodeName
()}>
list
)
{
if
(
list
==
null
)
...
...
@@ -602,11 +611,11 @@ ${deaction.getRender().code}
_create
.
add
(
sub
);
}
if
(
_update
.
size
()>
0
)
this
.
updateBatch
(
_update
);
proxyService
.
updateBatch
(
_update
);
if
(
_create
.
size
()>
0
)
this
.
createBatch
(
_create
);
proxyService
.
createBatch
(
_create
);
if
(
delIds
.
size
()>
0
)
this
.
removeBatch
(
delIds
);
proxyService
.
removeBatch
(
delIds
);
}
</#
if
>
...
...
@@ -865,6 +874,8 @@ ${deaction.getRender().code}
}
</#
if
>
<#
comment
>
实体数据导入
</#
comment
>
<@
deImportData
/>
}
<#
comment
>
NOSQL
存储
</#
comment
>
...
...
@@ -1258,6 +1269,7 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
if
nested
>
<@
autowiredProxyService
/>
@
Override
public
void
saveBy
${
srfcaseformat
(
MajorField
.
codeName
,
'l_u2lC'
)?
cap_first
}(${
srfjavatype
(
MajorField
.
stdDataType
)}
${
MajorkeyField
.
codeName
?
lower_case
},
List
<${
item
.
getCodeName
()}>
list
)
{
if
(
list
==
null
)
...
...
@@ -1280,11 +1292,11 @@ ${deaction.getRender().code}
_create
.
add
(
sub
);
}
if
(
_update
.
size
()>
0
)
this
.
updateBatch
(
_update
);
proxyService
.
updateBatch
(
_update
);
if
(
_create
.
size
()>
0
)
this
.
createBatch
(
_create
);
proxyService
.
createBatch
(
_create
);
if
(
delIds
.
size
()>
0
)
this
.
removeBatch
(
delIds
);
proxyService
.
removeBatch
(
delIds
);
}
</#
if
>
...
...
@@ -1348,6 +1360,8 @@ ${deaction.getRender().code}
}
</#
if
>
<#
comment
>
实体数据导入
</#
comment
>
<@
deImportData
/>
}
...
...
@@ -1783,6 +1797,7 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
if
nested
>
<@
autowiredProxyService
/>
@
Override
public
void
saveBy
${
srfcaseformat
(
MajorField
.
codeName
,
'l_u2lC'
)?
cap_first
}(${
srfjavatype
(
MajorField
.
stdDataType
)}
${
MajorkeyField
.
codeName
?
lower_case
},
List
<${
item
.
getCodeName
()}>
list
)
{
if
(
list
==
null
)
...
...
@@ -1805,11 +1820,11 @@ ${deaction.getRender().code}
_create
.
add
(
sub
);
}
if
(
_update
.
size
()>
0
)
this
.
updateBatch
(
_update
);
proxyService
.
updateBatch
(
_update
);
if
(
_create
.
size
()>
0
)
this
.
createBatch
(
_create
);
proxyService
.
createBatch
(
_create
);
if
(
delIds
.
size
()>
0
)
this
.
removeBatch
(
delIds
);
proxyService
.
removeBatch
(
delIds
);
}
</#
if
>
...
...
@@ -1849,6 +1864,9 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
comment
>
实体数据导入
</#
comment
>
<@
deImportData
/>
}
<#
comment
>
无存储
</#
comment
>
...
...
@@ -2089,6 +2107,7 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
if
nested
>
<@
autowiredProxyService
/>
@
Override
public
void
saveBy
${
srfcaseformat
(
MajorField
.
codeName
,
'l_u2lC'
)?
cap_first
}(${
srfjavatype
(
MajorField
.
stdDataType
)}
${
MajorkeyField
.
codeName
?
lower_case
},
List
<${
item
.
getCodeName
()}>
list
)
{
if
(
list
==
null
)
...
...
@@ -2111,11 +2130,11 @@ ${deaction.getRender().code}
_create
.
add
(
sub
);
}
if
(
_update
.
size
()>
0
)
this
.
updateBatch
(
_update
);
proxyService
.
updateBatch
(
_update
);
if
(
_create
.
size
()>
0
)
this
.
createBatch
(
_create
);
proxyService
.
createBatch
(
_create
);
if
(
delIds
.
size
()>
0
)
this
.
removeBatch
(
delIds
);
proxyService
.
removeBatch
(
delIds
);
}
</#
if
>
...
...
@@ -2149,6 +2168,8 @@ ${deaction.getRender().code}
</#
list
>
</#
if
>
<#
comment
>
实体数据导入
</#
comment
>
<@
deImportData
/>
}
</#
if
>
...
...
@@ -2405,4 +2426,174 @@ ${deaction.getRender().code}
</#
if
>
</#
if
>
</#
macro
>
<#
comment
>
注入代理行为
</#
comment
>
<#
macro
autowiredProxyService
>
<#
if
!P.exists(de.codeName,'proxyService')>
@
Autowired
@
Lazy
I
${
de
.
codeName
}
Service
proxyService
;
</#
if
>
</#
macro
>
<#
comment
>
实体数据导入
</#
comment
>
<#
macro
deImportData
>
<#
if
hasDEImport
>
<@
autowiredProxyService
/>
/**
*
上传数据检查
*
@
param
entities
*
@
param
mode
*
@
return
*/
private
JSONObject
testImportData
(
List
<${
de
.
codeName
}>
entities
,
boolean
isIgnoreError
)
{
JSONObject
rs
=
new
JSONObject
();
Set
ids
=
new
HashSet
<>();//
主键
List
<
String
>
errorMsgs
=
new
ArrayList
<>();
List
<
Integer
>
errorLines
=
new
ArrayList
<>();
List
<${
de
.
codeName
}>
duplicateKeys
=
new
ArrayList
<>();
String
keyField
=
DEFieldCacheMap
.
getDEKeyField
(${
de
.
codeName
}.
class
);
if
(
ObjectUtils
.
isEmpty
(
keyField
)){
errorLines
.
add
(
1
);
rs
.
put
(
"rst"
,
1
);
rs
.
put
(
"msg"
,
"数据导入失败,未能获取到实体[${de.codeName}]的主键属性"
);
rs
.
put
(
"errorLines"
,
errorLines
);
return
rs
;
}
//
主键重复性判断
.
外键约束判断(上传数据自身的检查
/
数据库的检查)
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
${
de
.
codeName
}
entity
=
entities
.
get
(
i
);
Object
id
=
entity
.
get
(
keyField
);
if
(
ObjectUtils
.
isEmpty
(
id
))
{
id
=
entity
.
getDefaultKey
(
true
);
entity
.
set
(
keyField
,
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
de
.
getMajorPSDER1Ns
??
&&
de
.
getMajorPSDER1Ns
()??>
//
外键约束检查
<#
list
de
.
getMinorPSDERs
()
as
MinorPSDER
>
<#
if
MinorPSDER
??
&&
MinorPSDER
.
getDERType
()==
'DER1N'
&&
(
MinorPSDER
.
getMajorPSDataEntity
().
getStorageMode
()==
1
||
MinorPSDER
.
getMajorPSDataEntity
().
getStorageMode
()==
2
||
MinorPSDER
.
getMajorPSDataEntity
().
getStorageMode
()==
4
)>
<#
if
MinorPSDER
.
getMajorPSDataEntity
??
&&
MinorPSDER
.
getMajorPSDataEntity
()??
&&
MinorPSDER
.
getCodeName
??
&&
MinorPSDER
.
getCodeName
()??>
<#
assign
MajorKeyFieldCodeName
=
srfcaseformat
(
MinorPSDER
.
getPSPickupDEField
().
codeName
,
'l_u2lC'
)?
cap_first
>
<#
assign
MajorEntityCodeName
=
MinorPSDER
.
getMajorPSDataEntity
().
codeName
>
<#
assign
MajorEntityService
=
srfcaseformat
(
MinorPSDER
.
getMajorPSDataEntity
().
getCodeName
(),
'l_u2lC'
)+
"Service"
>
//
实体关系
[${
MinorPSDER
.
name
}]
if
(
!ObjectUtils.isEmpty(et.get${MajorKeyFieldCodeName}())){
${
MajorEntityCodeName
}
fkEntity
=${
MajorEntityService
}.
getById
(
et
.
get
${
MajorKeyFieldCodeName
}());
if
(
ObjectUtils
.
isEmpty
(
fkEntity
)){
Integer
lineNum
=
i
+
1
;
errorLines
.
add
(
lineNum
);
errorMsgs
.
add
(
String
.
format
(
"第"
+
lineNum
+
"行:[%s]父数据有误。"
,
et
.
get
${
MajorKeyFieldCodeName
}()));
if
(
isIgnoreError
){
et
.
set
${
MajorKeyFieldCodeName
}(
null
);
continue
;
}
else
{
break
;
}
}
}
</#
if
>
</#
if
>
</#
list
>
</#
if
>
}
if
(
duplicateKeys
.
size
()>
0
){
for
(${
de
.
codeName
}
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
mode
*
@
return
*/
@
Override
@
Transactional
public
JSONObject
importData
(
List
<${
de
.
codeName
}>
entities
,
int
batchSize
,
boolean
isIgnoreError
)
{
JSONObject
rs
=
testImportData
(
entities
,
isIgnoreError
);
if
(
rs
.
getInteger
(
"rst"
)==
1
&&
!isIgnoreError)
return
rs
;
String
keyField
=
DEFieldCacheMap
.
getDEKeyField
(${
de
.
codeName
}.
class
);
List
<${
de
.
codeName
}>
tempDEList
=
new
ArrayList
<>();
Set
tempIds
=
new
HashSet
<>();//
主键
for
(
int
i
=
0
;
i
<
entities
.
size
();
i
++)
{
${
de
.
codeName
}
entity
=
entities
.
get
(
i
);
tempDEList
.
add
(
entity
);
tempIds
.
add
(
entity
.
get
(
keyField
));
//
分批次提交
if
(
tempDEList
.
size
()>=
batchSize
||
(
tempDEList
.
size
()<
batchSize
&&
i
==
entities
.
size
()-
1
)){
commit
(
tempDEList
,
tempIds
);
tempDEList
.
clear
();
tempIds
.
clear
();
}
}
rs
.
put
(
"rst"
,
0
);
return
rs
;
}
/**
*
批量提交
*
@
param
entities
数据
*
@
param
ids
要提交数据的
id
*/
@
Transactional
public
void
commit
(
List
<${
de
.
codeName
}>
entities
,
Set
ids
){
String
keyField
=
DEFieldCacheMap
.
getDEKeyField
(${
de
.
codeName
}.
class
);
List
<${
de
.
codeName
}>
_create
=
new
ArrayList
<>();
List
<${
de
.
codeName
}>
_update
=
new
ArrayList
<>();
Set
oldIds
=
new
HashSet
<>();
if
(
ids
.
size
()>
0
){
List
<${
de
.
codeName
}>
oldEntities
=
this
.
listByIds
(
ids
);
for
(${
de
.
codeName
}
entity
:
oldEntities
){
oldIds
.
add
(
entity
.
get
(
keyField
));
}
}
for
(${
de
.
codeName
}
entity
:
entities
){
Object
id
=
entity
.
get
(
keyField
);
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
);
}
</#
if
>
</#
macro
>
</#
if
>
SLN/%PUBPRJ%-provider/%PUBPRJ%-provider-%SYSAPI_PKGPATH%/src/main/java/%SYS_PKGPATH%/%SYSAPI_PKGPATH%/rest/%ITEM%Resource.java.ftl
浏览文件 @
fdd3455d
...
...
@@ -22,6 +22,14 @@ TARGET=PSDESERVICEAPI
<#
if
de
.
getPSDEFieldByPDT
(
'ORGID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'ORGSECTORID'
,
true
)??
||
de
.
getPSDEFieldByPDT
(
'CREATEMAN'
,
true
)??
>
<#
assign
hasDEPrefield
=
true
>
</#
if
>
<#
assign
hasDEImport
=
false
>
<#
comment
>
实体数据导入
</#
comment
>
<#
if
de
.
getAllPSDEDataImports
??
&&
de
.
getAllPSDEDataImports
()??>
<#
list
de
.
getAllPSDEDataImports
()
as
deImport
>
<#
assign
hasDEImport
=
true
>
<#
break
>
</#
list
>
</#
if
>
package
${
pubPkgCodeName
}.${
itemSysApiCodeNameLC
}.
rest
;
import
java
.
sql
.
Timestamp
;
...
...
@@ -614,7 +622,37 @@ public class ${itemCodeName}Resource {
</#
if
>
</#
list
>
</#
if
>
<#--
关系接口
end
-->
<#
comment
>
实体数据导入
</#
comment
>
<#
if
hasDEImport
>
<#
list
de
.
getAllPSDEDataImports
()
as
deImport
>
@
Autowired
${
pub
.
getPKGCodeName
()}.
core
.${
de
.
getPSSystemModule
().
codeName
?
lower_case
}.
mapping
.${
deCodeName
}${
deImport
.
codeName
}
${
deImport
.
codeName
?
lower_case
}
ImpMapping
;
</#
list
>
@
RequestMapping
(
method
=
RequestMethod
.
POST
,
value
=
"/${srfpluralize(itemCodeNameLC)}/import"
)
public
ResponseEntity
<
JSONObject
>
importData
(@
RequestParam
(
value
=
"name"
)
String
config
,
@
RequestBody
List
<${
deCodeName
}>
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
{
<#
list
de
.
getAllPSDEDataImports
()
as
deImport
>
<#
if
deImport_index
==
0
>
if
(
config
.
equals
(
"${deImport.codeName}"
)){
rs
=${
deCodeNameLC
}
Service
.
importData
(${
deImport
.
codeName
?
lower_case
}
ImpMapping
.
toDomain
(
dtos
),${
deImport
.
getBatchSize
()},${
deImport
.
isIgnoreError
()?
c
});
}
<#
else
>
else
if
(
config
.
equals
(
"${deImport.codeName}"
)){
rs
=${
deCodeNameLC
}
Service
.
importData
(${
deImport
.
codeName
?
lower_case
}
ImpMapping
.
toDomain
(
dtos
),${
deImport
.
getBatchSize
()},${
deImport
.
isIgnoreError
()?
c
});
}
</#
if
>
</#
list
>
return
ResponseEntity
.
status
(
HttpStatus
.
OK
).
body
(
rs
);
}
}
</#
if
>
}
</#
if
>
</#
if
>
...
...
SLN/%PUBPRJ%-util/src/main/java/%SYS_PKGPATH%/util/aspect/DEFieldDefaultValueAspect.java.ftl
浏览文件 @
fdd3455d
...
...
@@ -98,9 +98,9 @@ public class DEFieldDefaultValueAspect
for
(
Object
item
:(
List
)
obj
)
{
if
(
item
instanceof
EntityBase
)
{
if
(
deFields
==
null
)
{
deFields
=
DEFieldCacheMap
.
getDEFields
(
obj
.
getClass
());
deFields
=
DEFieldCacheMap
.
getDEFields
(
item
.
getClass
());
curUser
=
AuthenticationUser
.
getAuthenticationUser
();
keyField
=
DEFieldCacheMap
.
getDEKeyField
(
obj
.
getClass
());
keyField
=
DEFieldCacheMap
.
getDEKeyField
(
item
.
getClass
());
if
(
StringUtils
.
isEmpty
(
keyField
))
return
true
;
}
...
...
编辑
预览
Markdown
格式
0%
请重试
or
添加新附件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
先完成此消息的编辑!
取消
想要评论请
注册
或
登录