提交 1f98e9dd 编写于 作者: jianxueyun's avatar jianxueyun

同步表数据记录日志

上级 f87ca35e
......@@ -9,8 +9,11 @@ import cn.ibizlab.core.lite.extensions.service.LiteDataService;
import cn.ibizlab.core.lite.extensions.service.LiteModelService;
import cn.ibizlab.core.lite.mapper.TableSyncMapper;
import cn.ibizlab.core.lite.service.impl.TableSyncServiceImpl;
import cn.ibizlab.core.rule.domain.ExecLog;
import cn.ibizlab.core.rule.service.IExecLogService;
import cn.ibizlab.util.filter.QueryFilter;
import cn.ibizlab.util.helper.DataObject;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
......@@ -25,6 +28,7 @@ import org.springframework.util.StringUtils;
import java.sql.Timestamp;
import java.sql.Wrapper;
import java.text.SimpleDateFormat;
import java.util.*;
/**
......@@ -67,6 +71,9 @@ public class TableSyncExService extends TableSyncServiceImpl {
@Autowired
private LiteDataService liteDataService;
@Autowired
private IExecLogService execLogService;
public void sync(List<TableSync> list)
{
for(TableSync sync:list)
......@@ -115,8 +122,15 @@ public class TableSyncExService extends TableSyncServiceImpl {
filter.ge(sourceModel.getLastModifyField().getColumnName(),lastTimestamp);
Timestamp runTimestamp=new Timestamp(System.currentTimeMillis());
final String dsName=dsId;
ExecLog execlog = new ExecLog();
execlog.setName("[SYNC]" + new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + "[" + entityName + "]");
execlog.setKeyValueField(entityName);
execlog.setRetCode(0);
execlog.setSucc(0);
execlog.setSystemId(systemId);
execlog.setRunResult("Service成功,process successfully");
liteDataService.searchCursor(sourceModel,sync.getSourceExpression(),sourceDsId,filter, new LiteDataCallback<List<EntityObj>>() {
@Override
public void total(Integer total) {
......@@ -131,6 +145,9 @@ public class TableSyncExService extends TableSyncServiceImpl {
param.put("lastruntime", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
execlog.setCnt(total);
execLogService.create(execlog);
}
else {
String updateSql = "UPDATE ibztablesync SET lastread=0,lastwrite=0," +
......@@ -144,7 +161,6 @@ public class TableSyncExService extends TableSyncServiceImpl {
param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
}
}
......@@ -169,6 +185,16 @@ public class TableSyncExService extends TableSyncServiceImpl {
param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
try {
DynamicDataSourceContextHolder.push("master");
execlog.setSucc(execlog.getSucc() + datas.size());
execLogService.update(execlog);
} catch (Exception ex) {
log.error("详细错误信息:" + ex.getMessage());
} finally {
DynamicDataSourceContextHolder.poll();
}
}
else
{
......@@ -183,8 +209,20 @@ public class TableSyncExService extends TableSyncServiceImpl {
//param.put("etltimestamp", runTimestamp);
param.put("syncid", sync.getId());
updateBySQL(updateSql,param);
}
try {
DynamicDataSourceContextHolder.push("master");
String runBody = JSONObject.toJSONString(datas);
execlog.setRunBody(runBody);
execlog.setRetCode(1);
execlog.setRunResult("sync同步失败:" + sync.getEntityName());
execLogService.update(execlog);
} catch (Exception ex) {
log.error("详细错误信息:" + ex.getMessage());
} finally {
DynamicDataSourceContextHolder.poll();
}
}
return rt;
}
......@@ -194,10 +232,8 @@ public class TableSyncExService extends TableSyncServiceImpl {
{
log.error("sync同步失败:"+sync.getEntityName()+":"+ex.getMessage());
ex.printStackTrace();
}
}
}
private void updateBySQL(String updateSql , Map param)
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册