package com.product.data.sync.util;
|
|
import com.product.common.lang.StringUtils;
|
import com.product.core.dao.BaseDao;
|
import com.product.core.entity.FieldSetEntity;
|
import com.product.core.service.support.AbstractBaseService;
|
import com.product.data.sync.config.CmnConst;
|
import com.product.util.BaseUtil;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import java.sql.Connection;
|
import java.sql.SQLException;
|
import java.util.Date;
|
import java.util.List;
|
|
@Service
|
public class ExceptionLog extends AbstractBaseService {
|
@Autowired
|
public BaseDao baseDao;
|
|
@Override
|
public BaseDao getBaseDao() {
|
return baseDao;
|
}
|
|
@Override
|
public void setBaseDao(BaseDao baseDao) {
|
this.baseDao = baseDao;
|
}
|
|
/**
|
* 新增修改失败修改日志,添加错误详情子表
|
* @param sync_config_log_uuid 日志主表uuid
|
* @param list 错误数据唯一标识集合
|
* @param e 异常
|
*/
|
public void addSubExceptionLog(String sync_config_log_uuid, List<String> list, Exception e) {
|
FieldSetEntity subException = new FieldSetEntity();
|
subException.setTableName(CmnConst.PRODUCT_SYS_DATABASE_SYNC_CONFIG_LOG_SUB);
|
subException.setValue(CmnConst.SYNC_CONFIG_LOG_UUID, sync_config_log_uuid);
|
subException.setValue(CmnConst.ERROR_INFO, e.getMessage());
|
//直接开集合并去掉括号
|
subException.setValue(CmnConst.WRONG_DATA_KEY, StringUtils.strip(list.toString(), "[]"));
|
baseDao.add(subException);
|
}
|
|
/**
|
* 新增修改失败修改日志,添加错误详情子表
|
* @param sync_config_log_uuid 日志主表uuid
|
* @param e 异常
|
* @param currentPage 含错误数据的页数
|
*/
|
public void addSubExceptionLog(String sync_config_log_uuid, Exception e, Integer currentPage) {
|
FieldSetEntity subException = new FieldSetEntity();
|
subException.setTableName(CmnConst.PRODUCT_SYS_DATABASE_SYNC_CONFIG_LOG_SUB);
|
subException.setValue(CmnConst.SYNC_CONFIG_LOG_UUID, sync_config_log_uuid);
|
subException.setValue(CmnConst.ERROR_INFO, e.getMessage());
|
Integer startIndex = (currentPage - 1) * 1000;
|
Integer endIndex = currentPage * 1000;
|
//直接开集合并去掉括号
|
subException.setValue(CmnConst.WRONG_DATA_KEY, "[" + startIndex + "-" + endIndex + "]");
|
//添加时间
|
subException.setValue(CmnConst.CREATED_UTC_DATETIME, new Date());
|
baseDao.add(subException);
|
}
|
|
/**
|
* 启动数据同步默认创建日志
|
* @param configUuid 同步配置uuid
|
* @param data_origin_name 数据源表名
|
* @param system_table_name 系统表名
|
* @return 日志uuid
|
*/
|
public String addExceptionLog(String configUuid, String data_origin_name, String system_table_name) {
|
FieldSetEntity exceptionLog = new FieldSetEntity();
|
exceptionLog.setTableName(CmnConst.PRODUCT_SYS_DATABASE_SYNC_CONFIG_LOG);
|
exceptionLog.setValue(CmnConst.SYNC_CONFIG_UUID, configUuid);
|
exceptionLog.setValue(CmnConst.DATA_ORIGIN_NAME, data_origin_name);
|
exceptionLog.setValue(CmnConst.SYNC_TIME, new Date());
|
exceptionLog.setValue(CmnConst.SYSTEM_TABLE_NAME, system_table_name);
|
return baseDao.add(exceptionLog);
|
}
|
|
/**
|
* 查询成功或中途失败修改同步日志
|
* @param conn 数据源连接
|
* @param uuid 日志uuid
|
* @param e 查询时异常
|
* @param addNum 新增条数
|
* @param upNum 修改条数
|
* @param errorNum 错误条数
|
* @param totalNumber 总条数
|
*/
|
public void upExceptionLog(Connection conn, String uuid, Exception e, Integer addNum, Integer upNum, Integer deleteNumber, Integer errorNum, Integer totalNumber) {
|
StringBuffer exception = new StringBuffer();
|
if (e != null) {
|
exception.append(e.getMessage());
|
}
|
if (conn != null) {
|
try {
|
conn.close();
|
} catch (SQLException ex) {
|
ex.printStackTrace();
|
exception.append("\n");
|
exception.append(ex.getMessage());
|
}
|
}
|
FieldSetEntity exceptionLog = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DATABASE_SYNC_CONFIG_LOG, uuid, false);
|
String errInfo = exceptionLog.getString(CmnConst.ERR_INFO);
|
if(!BaseUtil.strIsNull(errInfo)){
|
exception.append("\n").append(errInfo);
|
}
|
exceptionLog.setValue(CmnConst.ERR_INFO, exception.toString());
|
exceptionLog.setValue(CmnConst.SYNC_TIME, new Date());
|
exceptionLog.setValue(CmnConst.ADD_NUM, addNum);
|
exceptionLog.setValue(CmnConst.UPDATE_NUM, upNum);
|
exceptionLog.setValue(CmnConst.DELETE_NUM, deleteNumber);
|
exceptionLog.setValue(CmnConst.FAIL_NUM, errorNum);
|
exceptionLog.setValue(CmnConst.TOTAL_NUMBER, totalNumber);
|
baseDao.update(exceptionLog);
|
}
|
|
/**
|
* 修改日志
|
* @param uuid 日志uuid
|
* @param e 查询时异常
|
*/
|
public void upExceptionLog(String uuid, Exception e) {
|
StringBuffer exception = new StringBuffer();
|
if (e != null) {
|
exception.append(e.getMessage());
|
}
|
FieldSetEntity exceptionLog = baseDao.getFieldSetEntity(CmnConst.PRODUCT_SYS_DATABASE_SYNC_CONFIG_LOG, uuid, false);
|
String errInfo = exceptionLog.getString(CmnConst.ERR_INFO);
|
if(!BaseUtil.strIsNull(errInfo)){
|
exception.append("\n").append(errInfo);
|
}
|
exceptionLog.setValue(CmnConst.ERR_INFO, exception.toString());
|
baseDao.update(exceptionLog);
|
}
|
}
|