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

同步表数据代码优化

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