提交 f7d1a3da 编写于 作者: zhouweidong's avatar zhouweidong

优化saveBatch,解决save时et存在id无法填充createdate的问题。

上级 4282ef05
...@@ -181,6 +181,8 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa ...@@ -181,6 +181,8 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
</#if> </#if>
</#list> </#list>
</#if> </#if>
<#comment>引入proxyservice</#comment>
<@autowiredProxyService/>
protected int batchSize = 500; protected int batchSize = 500;
...@@ -451,7 +453,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa ...@@ -451,7 +453,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
if (null == et) { if (null == et) {
return false; return false;
} else { } else {
return checkKey(et) ? this.update(et) : this.create(et); return checkKey(et) ? proxyService.update(et) : proxyService.create(et);
} }
} }
...@@ -463,7 +465,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa ...@@ -463,7 +465,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
<#if hasMinorPSDERs gt 0> <#if hasMinorPSDERs gt 0>
list.forEach(item->fillParentData(item)); list.forEach(item->fillParentData(item));
</#if> </#if>
saveOrUpdateBatch(list,batchSize); <@saveBatch/>
return true; return true;
} }
...@@ -475,7 +477,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa ...@@ -475,7 +477,7 @@ public class ${item.getCodeName()}ServiceImpl extends ServiceImpl<${de.getCodeNa
<#if hasMinorPSDERs gt 0> <#if hasMinorPSDERs gt 0>
list.forEach(item->fillParentData(item)); list.forEach(item->fillParentData(item));
</#if> </#if>
saveOrUpdateBatch(list,batchSize); <@saveBatch/>
} }
<#elseif deaction.getCodeName()?lower_case == "remove"> <#elseif deaction.getCodeName()?lower_case == "remove">
...@@ -3070,4 +3072,23 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser ...@@ -3070,4 +3072,23 @@ public class ${item.getCodeName()}ServiceImpl implements I${de.getCodeName()}Ser
} }
</#macro> </#macro>
<#comment>批量保存</#comment>
<#macro saveBatch>
List<${item.getCodeName()}> create = new ArrayList<>();
List<${item.getCodeName()}> update = new ArrayList<>();
for (${item.getCodeName()} et : list) {
if (ObjectUtils.isEmpty(et.getId()) || ObjectUtils.isEmpty(getById(et.getId()))) {
create.add(et);
} else {
update.add(et);
}
}
if (create.size() > 0) {
proxyService.createBatch(create);
}
if (update.size() > 0) {
proxyService.updateBatch(update);
}
</#macro>
</#if> </#if>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册