package com.product.data.entity;
|
|
import com.product.common.lang.StringUtils;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.data.config.CmnConst;
|
|
import java.util.Date;
|
|
/**
|
* @Author cheng
|
* @Date 2022/2/11 9:38
|
* @Desc 执行记录
|
*/
|
public class SyncExecuteRecordEntity {
|
/**
|
* 同步任务uuid
|
*/
|
private String syncTaskUuid;
|
/**
|
* 同步类型
|
*/
|
private int syncType;
|
/**
|
* 开始索引位置
|
*/
|
private int startPosition = -1;
|
/**
|
* 结束索引位置
|
*/
|
private int endPosition = -1;
|
/**
|
* 增量数量
|
*/
|
private int increaseNumber = 0;
|
/**
|
* 更新数量
|
*/
|
private int updateNumber = 0;
|
/**
|
* 错误数量
|
*/
|
private int errorNumber = 0;
|
/**
|
* 错误信息
|
*/
|
private StringBuilder errorInfo;
|
/**
|
* 执行完成时间 (来源数据库系统时间戳)
|
*/
|
private Object finishSourceTime;
|
|
|
private FieldSetEntity logRecord;
|
/**
|
* 插入查询条件(增量)
|
* 用于更新完成后使用
|
*/
|
private String insertQueryFilter;
|
/**
|
* 更新查询条件(增量)
|
* 用于更新完成后使用
|
*/
|
private String updateQueryFilter;
|
|
|
public SyncExecuteRecordEntity(String syncTaskUuid, int syncType) {
|
this.syncTaskUuid = syncTaskUuid;
|
this.syncType = syncType;
|
|
}
|
|
public String getRecordUuid() {
|
return this.logRecord != null ? this.logRecord.getUUID() : null;
|
}
|
|
public SyncExecuteRecordEntity(FieldSetEntity fse) {
|
this.logRecord = fse;
|
this.syncTaskUuid = fse.getString("sync_task_uuid");
|
this.syncType = fse.getInteger("sync_type");
|
this.startPosition = fse.getInteger("start_position");
|
this.endPosition = fse.getInteger("end_position");
|
this.increaseNumber = fse.getInteger("increase_number");
|
this.updateNumber = fse.getInteger("update_number");
|
this.errorNumber = fse.getInteger("error_number");
|
Date finish_source_time = fse.getDate("finish_source_time");
|
if (finish_source_time != null) {
|
this.finishSourceTime = fse.getObject("finish_source_time");
|
}
|
String error_info = fse.getString("error_info");
|
if (!StringUtils.isEmpty(error_info)) {
|
this.errorInfo = new StringBuilder(error_info);
|
}
|
|
}
|
|
public String getInsertQueryFilter() {
|
return insertQueryFilter;
|
}
|
|
public void setInsertQueryFilter(String insertQueryFilter) {
|
this.insertQueryFilter = insertQueryFilter;
|
}
|
|
public String getUpdateQueryFilter() {
|
return updateQueryFilter;
|
}
|
|
public void setUpdateQueryFilter(String updateQueryFilter) {
|
this.updateQueryFilter = updateQueryFilter;
|
}
|
|
public void setStartPosition(int startPosition) {
|
this.startPosition = startPosition;
|
if (startPosition >= endPosition && endPosition != -1) {
|
this.startPosition = endPosition;
|
}
|
if (logRecord != null) {
|
this.logRecord.setValue("start_position", this.startPosition);
|
}
|
}
|
|
public void setEndPosition(int endPosition) {
|
this.endPosition = endPosition;
|
if (startPosition >= endPosition) {
|
startPosition = endPosition;
|
}
|
if (logRecord != null) {
|
this.logRecord.setValue("end_position", this.endPosition);
|
}
|
}
|
|
public FieldSetEntity getRecord(int endPosition, Long finishSourceTime) {
|
this.endPosition = endPosition;
|
if (startPosition >= endPosition) {
|
startPosition = endPosition;
|
}
|
this.finishSourceTime = finishSourceTime;
|
if (this.logRecord == null) {
|
this.logRecord = new FieldSetEntity();
|
this.logRecord.setTableName(CmnConst.TABLE_SYNC_MANAGER_LOG);
|
this.logRecord.setValue(CmnConst.CREATED_BY, 1);
|
this.logRecord.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
|
this.logRecord.setValue(CmnConst.ORG_LEVEL_UUID, "/");
|
} else {
|
this.logRecord.setValue(CmnConst.UPDATED_BY, 1);
|
this.logRecord.setValue(CmnConst.UPDATED_UTC_DATETIME, new Date());
|
}
|
this.logRecord.setValue("sync_task_uuid", this.syncTaskUuid);
|
this.logRecord.setValue("sync_type", this.syncType);
|
this.logRecord.setValue("start_position", this.startPosition);
|
this.logRecord.setValue("end_position", this.endPosition);
|
this.logRecord.setValue("increase_number", this.increaseNumber);
|
this.logRecord.setValue("update_number", this.updateNumber);
|
this.logRecord.setValue("error_number", this.errorNumber);
|
this.logRecord.setValue("error_info", this.errorInfo != null ? this.errorInfo.toString() : null);
|
this.logRecord.setValue("finish_source_time", this.finishSourceTime);
|
return this.logRecord;
|
}
|
|
public void addIncreaseNumber(int number) {
|
this.increaseNumber += number;
|
if (logRecord != null) {
|
this.logRecord.setValue("increase_number", this.increaseNumber);
|
}
|
}
|
|
public void addErrorNumber(int number) {
|
this.errorNumber += number;
|
if (logRecord != null) {
|
this.logRecord.setValue("error_number", this.errorNumber);
|
}
|
}
|
|
public void addUpdateNumber(int number) {
|
this.updateNumber += number;
|
if (logRecord != null) {
|
this.logRecord.setValue("update_number", this.updateNumber);
|
}
|
}
|
|
public void addErrorInfo(String errorMsg) {
|
if (this.errorInfo == null) {
|
errorInfo = new StringBuilder();
|
}
|
if (errorMsg.length() > 0) {
|
errorInfo.append("\n");
|
}
|
errorInfo.append(errorMsg);
|
if (logRecord != null) {
|
this.logRecord.setValue("error_info", this.errorInfo != null ? this.errorInfo.toString() : null);
|
}
|
|
}
|
|
public String getSyncTaskUuid() {
|
return syncTaskUuid;
|
}
|
|
public int getSyncType() {
|
return syncType;
|
}
|
|
public int getStartPosition() {
|
return startPosition;
|
}
|
|
public int getEndPosition() {
|
return endPosition;
|
}
|
|
public int getIncreaseNumber() {
|
return increaseNumber;
|
}
|
|
public int getUpdateNumber() {
|
return updateNumber;
|
}
|
|
public int getErrorNumber() {
|
return errorNumber;
|
}
|
|
public StringBuilder getErrorInfo() {
|
return errorInfo;
|
}
|
|
public Object getFinishSourceTime() {
|
return finishSourceTime;
|
}
|
|
public FieldSetEntity getLogRecord() {
|
return logRecord;
|
}
|
}
|