提交 d880dd45 编写于 作者: sq3536's avatar sq3536

同步表数据代码优化

上级 59ad8c9e
......@@ -138,20 +138,38 @@ public class TableSyncExService extends TableSyncServiceImpl {
@Override
public boolean processData(List<EntityObj> datas) {
liteDataService.saveBatch(entityModel,dsName,datas);
String updateSql = "UPDATE ibztablesync SET lastwrite=(CASE WHEN lastwrite is null then 0 else lastwrite end+#{et.count})," +
"lastendtime=CASE WHEN lastread <= lastwrite THEN #{et.lastendtime} ELSE lastendtime END," +
"etltimestamp=CASE WHEN lastread <= lastwrite THEN #{et.etltimestamp} ELSE etltimestamp END," +
"lastrunresult=CASE WHEN lastread <= lastwrite THEN 'FINISH' ELSE lastrunresult END WHERE syncid = #{et.syncid}";
HashMap<String, Object> param = new HashMap<>();
param.put("count", datas.size());
param.put("lastendtime", new Timestamp(System.currentTimeMillis()));
param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
return true;
boolean rt=liteDataService.saveBatch(entityModel,dsName,datas);
if(rt)
{
String updateSql = "UPDATE ibztablesync SET lastwrite=(CASE WHEN lastwrite is null then 0 else lastwrite end+#{et.count})," +
"lastendtime=CASE WHEN lastread <= lastwrite THEN #{et.lastendtime} ELSE lastendtime END," +
"etltimestamp=CASE WHEN lastread <= lastwrite THEN #{et.etltimestamp} ELSE etltimestamp END," +
"lastrunresult=CASE WHEN lastread <= lastwrite THEN 'FINISH' ELSE lastrunresult END WHERE syncid = #{et.syncid}";
HashMap<String, Object> param = new HashMap<>();
param.put("count", datas.size());
param.put("lastendtime", new Timestamp(System.currentTimeMillis()));
param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
}
else
{
String updateSql = "UPDATE ibztablesync SET lastwrite=CASE WHEN lastwrite is null then 0 else lastwrite end," +
"lastruntime=#{et.lastruntime}," +
"lastendtime=#{et.lastendtime}," +
//"etltimestamp=#{et.etltimestamp}," +
"lastrunresult='ERROR' WHERE syncid = #{et.syncid}";
HashMap<String, Object> param = new HashMap<>();
param.put("lastendtime", new Timestamp(System.currentTimeMillis()));
param.put("lastruntime", runTimestamp);
//param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
}
return rt;
}
});
}
......
......@@ -187,7 +187,7 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
EntityObj rowdata;
while ((rowdata = (EntityObj) myMyBatisCursorItemReader.read()) != null) {
datas.add(rowdata);
if(datas.size() >= 5){
if(datas.size() >= processSize){
boolean rt=callback.processData(datas);
datas.clear();
if(!rt)
......@@ -226,7 +226,8 @@ public class DbEntityService extends ServiceImpl<DbEntityMapper, EntityObj> impl
});
});
return baseMapper.saveBatch(entityModel, list);
baseMapper.saveBatch(entityModel, list);
return true;
} catch (Exception ex) {
log.error("详细错误信息:" + ex.getMessage() + ", 执行sql:" + entityModel.getTableName());
......
......@@ -58,18 +58,22 @@ public class LiteDataService {
public boolean saveBatch(EntityModel entityModel, String dsName, List<EntityObj> list) {
List<List<EntityObj>> splist=splitList(list, 500);
splist.forEach(objs->{
getEntityService(StringUtils.isEmpty(dsName)?entityModel.getDsName():dsName).saveBatch(dsName,entityModel,objs);
});
for(List<EntityObj> objs:splist)
{
if(!getEntityService(StringUtils.isEmpty(dsName)?entityModel.getDsName():dsName).saveBatch(dsName,entityModel,objs))
return false;
}
return true;
}
public boolean saveBatch(String systemId, String entityName, String dsName, List<EntityObj> list) {
EntityModel entityModel = liteModelService.getEntityModel(systemId,entityName);
List<List<EntityObj>> splist=splitList(list, 500);
splist.forEach(objs->{
getEntityService(StringUtils.isEmpty(dsName)?entityModel.getDsName():dsName).saveBatch(dsName,entityModel,objs);
});
for(List<EntityObj> objs:splist)
{
if(!getEntityService(StringUtils.isEmpty(dsName)?entityModel.getDsName():dsName).saveBatch(dsName,entityModel,objs))
return false;
}
return true;
}
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册