1、时间范围修改
This commit is contained in:
parent
7ff2521610
commit
2e115a96c3
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -425,7 +425,11 @@ public class DataLinkUpController {
|
|||||||
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
||||||
// 全量分页迁移数据到汇总表
|
// 全量分页迁移数据到汇总表
|
||||||
long summarizeStartTime = System.currentTimeMillis();
|
long summarizeStartTime = System.currentTimeMillis();
|
||||||
dataSyncService.summarizeScopeData(targetTable, null, null, null, hzb);
|
if (tablename.equals("应收表")){
|
||||||
|
dataSyncService.summarizeScopeDataYs(targetTable, null, null, null, hzb);
|
||||||
|
}else {
|
||||||
|
dataSyncService.summarizeScopeData(targetTable, null, null, null, hzb);
|
||||||
|
}
|
||||||
LOGGER.info("全量数据汇总完成,耗时:{}ms", System.currentTimeMillis() - summarizeStartTime);
|
LOGGER.info("全量数据汇总完成,耗时:{}ms", System.currentTimeMillis() - summarizeStartTime);
|
||||||
} else {
|
} else {
|
||||||
// 获取目标表时间字段名
|
// 获取目标表时间字段名
|
||||||
@ -448,6 +452,13 @@ public class DataLinkUpController {
|
|||||||
dataSyncService.summarizeScopeDataYs(targetTable, startDate, endDate, targetTimeField, hzb);
|
dataSyncService.summarizeScopeDataYs(targetTable, startDate, endDate, targetTimeField, hzb);
|
||||||
}else {
|
}else {
|
||||||
dataSyncService.summarizeScopeData(targetTable, startDate, endDate, targetTimeField, hzb);
|
dataSyncService.summarizeScopeData(targetTable, startDate, endDate, targetTimeField, hzb);
|
||||||
|
if (hzb.equals("BO_EU_DWD_ORDER_RKD_HZ")){
|
||||||
|
int update = DBSql.update("UPDATE BO_EU_DWD_ORDER_RKD_HZ rkd " +
|
||||||
|
" JOIN BO_EU_ZZDYQY zzd ON rkd.BKGS = zzd.BKGS AND rkd.KCZZ = zzd.XSZZ " +
|
||||||
|
" SET rkd.QYGS = zzd.QYGS " +
|
||||||
|
" WHERE rkd.QYGS IS NULL");
|
||||||
|
LOGGER.info("更新入库单区域公司条数:{}",update);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
LOGGER.info("范围数据汇总完成,耗时:{}ms", System.currentTimeMillis() - summarizeStartTime);
|
LOGGER.info("范围数据汇总完成,耗时:{}ms", System.currentTimeMillis() - summarizeStartTime);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,11 @@ public class PurchaseDataLinkUpJob implements IJob {
|
|||||||
// 汇总各板块数据
|
// 汇总各板块数据
|
||||||
LOGGER.info("======== 开始执行销售汇总各板块数据 ========");
|
LOGGER.info("======== 开始执行销售汇总各板块数据 ========");
|
||||||
syncService.sumBkTable(mainConfigs);
|
syncService.sumBkTable(mainConfigs);
|
||||||
|
int update = DBSql.update("UPDATE BO_EU_DWD_ORDER_RKD_HZ rkd " +
|
||||||
|
" JOIN BO_EU_ZZDYQY zzd ON rkd.BKGS = zzd.BKGS AND rkd.KCZZ = zzd.XSZZ " +
|
||||||
|
" SET rkd.QYGS = zzd.QYGS " +
|
||||||
|
" WHERE rkd.QYGS IS NULL");
|
||||||
|
LOGGER.info("更新入库单区域公司条数:{}",update);
|
||||||
LOGGER.info("======== 销售汇总各板块数据执行完成 ========");
|
LOGGER.info("======== 销售汇总各板块数据执行完成 ========");
|
||||||
|
|
||||||
//计算汇总维度
|
//计算汇总维度
|
||||||
|
|||||||
@ -167,10 +167,13 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
|||||||
Date startDate, Date endDate) {
|
Date startDate, Date endDate) {
|
||||||
try {
|
try {
|
||||||
String deleteSql = "DELETE FROM " + targetTable +
|
String deleteSql = "DELETE FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
|
" WHERE " + targetTimeField + " >= ? ";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
targetTable, deletedCount, startDate, endDate);
|
String endDateStr = simpleDateFormat.format(endDate)+" 23:59:59";
|
||||||
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
|
||||||
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} )",
|
||||||
|
targetTable, deletedCount, startDateStr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
|
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@ -270,8 +273,8 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
|||||||
|
|
||||||
for (int i = 0; i < timeRanges.size(); i++) {
|
for (int i = 0; i < timeRanges.size(); i++) {
|
||||||
Date[] range = timeRanges.get(i);
|
Date[] range = timeRanges.get(i);
|
||||||
String startDate = simpleDateFormat2.format(range[0]);
|
String startDate = simpleDateFormat2.format(range[0])+" 00:00:00";
|
||||||
String endDate = simpleDateFormat2.format(range[1]);
|
String endDate = simpleDateFormat2.format(range[1])+" 23:59:59";
|
||||||
|
|
||||||
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
||||||
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
||||||
@ -590,11 +593,6 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
|||||||
String sourceField = mapping.getString("TBBZD");
|
String sourceField = mapping.getString("TBBZD");
|
||||||
String targetField = mapping.getString("LDBZD");
|
String targetField = mapping.getString("LDBZD");
|
||||||
|
|
||||||
// if (!source.containsKey(sourceField)) {
|
|
||||||
// LOGGER.debug("源字段[{}]不存在于查询结果中", sourceField);
|
|
||||||
// continue;
|
|
||||||
// }
|
|
||||||
|
|
||||||
String operationExpr = mapping.getString("TBBZDJSLJ");
|
String operationExpr = mapping.getString("TBBZDJSLJ");
|
||||||
if (StringUtils.isNotBlank(operationExpr)) {
|
if (StringUtils.isNotBlank(operationExpr)) {
|
||||||
// 解析运算表达式 (格式: [运算符][数字])
|
// 解析运算表达式 (格式: [运算符][数字])
|
||||||
@ -743,10 +741,12 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
|||||||
}
|
}
|
||||||
// 按时间范围删除
|
// 按时间范围删除
|
||||||
String deleteSql = "DELETE FROM " + hzb +
|
String deleteSql = "DELETE FROM " + hzb +
|
||||||
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
|
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
hzb,deletedCount, startDate, endDate);
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate});
|
||||||
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} )",
|
||||||
|
hzb,deletedCount, startDate);
|
||||||
|
|
||||||
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
||||||
// 按时间范围分页迁移数据到汇总表
|
// 按时间范围分页迁移数据到汇总表
|
||||||
@ -783,10 +783,10 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
|||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
} else {
|
} else {
|
||||||
startDate = simpleDateFormat.format(startDated);
|
startDate = simpleDateFormat.format(startDated)+" 00:00:00";
|
||||||
endDate = simpleDateFormat.format(endDated);
|
endDate = simpleDateFormat.format(endDated)+" 23:59:59";
|
||||||
pageSql = "SELECT * FROM " + targetTable +
|
pageSql = "SELECT * FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
|
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
|
||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
LOGGER.info("执行查询的sql:{}", pageSql);
|
LOGGER.info("执行查询的sql:{}", pageSql);
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
|
|||||||
@ -64,8 +64,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
|
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
|
||||||
|
|
||||||
// 处理当前板块的每条配置
|
// 处理当前板块的每条配置
|
||||||
boolean connectionFailed = false;
|
|
||||||
String errorMsg = "";
|
|
||||||
for (BO mainConfig : plateConfigs) {
|
for (BO mainConfig : plateConfigs) {
|
||||||
try {
|
try {
|
||||||
DateRange dateRange = processMainConfig(mainConfig);
|
DateRange dateRange = processMainConfig(mainConfig);
|
||||||
@ -197,8 +195,11 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
Date startDate, Date endDate) {
|
Date startDate, Date endDate) {
|
||||||
try {
|
try {
|
||||||
String deleteSql = "DELETE FROM " + targetTable +
|
String deleteSql = "DELETE FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
|
" WHERE " + targetTimeField + " >= ? ";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
|
String endDateStr = simpleDateFormat.format(endDate)+" 23:59:59";
|
||||||
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
||||||
targetTable, deletedCount, startDate, endDate);
|
targetTable, deletedCount, startDate, endDate);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -746,8 +747,9 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
.addQuery("BINDID =", bindId)
|
.addQuery("BINDID =", bindId)
|
||||||
.list();
|
.list();
|
||||||
//获取板块公司
|
//获取板块公司
|
||||||
String bkgs = DBSql.getString("SELECT BKGS FROM " + targetTable, "BKGS");
|
List<RowMap> maps = DBSql.getMaps("SELECT BKGS FROM " + targetTable + " GROUP BY BKGS");
|
||||||
|
String bkgss = maps.stream().map(o -> o.getString("BKGS")).collect(Collectors.joining(","));
|
||||||
|
String[] bkgsArr = bkgss.split(",");
|
||||||
// 根据时间字段是否为空设置日期范围
|
// 根据时间字段是否为空设置日期范围
|
||||||
Date startDate = null;
|
Date startDate = null;
|
||||||
Date endDate = null;
|
Date endDate = null;
|
||||||
@ -755,10 +757,12 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
// 删除目标表数据(根据时间字段是否为空决定删除范围)
|
// 删除目标表数据(根据时间字段是否为空决定删除范围)
|
||||||
if (timeField == null || timeField.isEmpty()) {
|
if (timeField == null || timeField.isEmpty()) {
|
||||||
// 全量删除
|
// 全量删除
|
||||||
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
|
for (String bkgs : bkgsArr) {
|
||||||
int deletedCount = DBSql.update(deleteSql);
|
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
|
||||||
LOGGER.info("已删除目标表[{}}]中{}条数据(时间范围: {} - {})",
|
int deletedCount = DBSql.update(deleteSql);
|
||||||
hzb,deletedCount, startDate, endDate);
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
||||||
|
hzb,deletedCount, startDate, endDate);
|
||||||
|
}
|
||||||
|
|
||||||
// 根据时间范围增加数据分页查询数据存储
|
// 根据时间范围增加数据分页查询数据存储
|
||||||
// 全量分页迁移数据到汇总表
|
// 全量分页迁移数据到汇总表
|
||||||
@ -777,14 +781,15 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
|
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
|
||||||
}
|
}
|
||||||
// 按时间范围删除
|
// 按时间范围删除
|
||||||
String deleteSql = "DELETE FROM " + hzb +
|
for (String bkgs : bkgsArr) {
|
||||||
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
|
String deleteSql = "DELETE FROM " + hzb +
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
|
||||||
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
String endDateStr = simpleDateFormat.format(endDate)+" 23:59:59";
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr, endDateStr});
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
LOGGER.info("已删除目标表["+hzb+"]中{}条数据(时间范围: {} )",
|
||||||
hzb,deletedCount, startDateStr, endDateStr);
|
deletedCount, startDate);
|
||||||
|
}
|
||||||
|
|
||||||
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
||||||
// 按时间范围分页迁移数据到汇总表
|
// 按时间范围分页迁移数据到汇总表
|
||||||
@ -837,10 +842,10 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
} else {
|
} else {
|
||||||
startDate = simpleDateFormat.format(startDated);
|
startDate = simpleDateFormat.format(startDated)+" 00:00:00";
|
||||||
endDate = simpleDateFormat.format(endDated);
|
endDate = simpleDateFormat.format(endDated)+" 23:59:59";
|
||||||
pageSql = "SELECT * FROM " + targetTable +
|
pageSql = "SELECT * FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
|
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
|
||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
LOGGER.info("执行查询的sql:{}", pageSql);
|
LOGGER.info("执行查询的sql:{}", pageSql);
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
@ -968,12 +973,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
|||||||
bos.add(bo);
|
bos.add(bo);
|
||||||
}
|
}
|
||||||
|
|
||||||
int update = DBSql.update("UPDATE BO_EU_DWD_ORDER_RKD_HZ rkd " +
|
|
||||||
" JOIN BO_EU_ZZDYQY zzd ON rkd.BKGS = zzd.BKGS AND rkd.KCZZ = zzd.XSZZ " +
|
|
||||||
" SET rkd.QYGS = zzd.QYGS " +
|
|
||||||
" WHERE rkd.QYGS IS NULL");
|
|
||||||
LOGGER.info("更新入库单区域公司条数:{}",update);
|
|
||||||
|
|
||||||
SDK.getBOAPI().createDataBO(hzb, bos, UserContext.fromUID("admin"));
|
SDK.getBOAPI().createDataBO(hzb, bos, UserContext.fromUID("admin"));
|
||||||
LOGGER.info("已迁移{}条数据到汇总表(页号: {},时间范围: {} - {})",
|
LOGGER.info("已迁移{}条数据到汇总表(页号: {},时间范围: {} - {})",
|
||||||
bos.size(), pageNo, startDate, endDate);
|
bos.size(), pageNo, startDate, endDate);
|
||||||
|
|||||||
@ -65,13 +65,8 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
|
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
|
||||||
|
|
||||||
// 处理当前板块的每条配置
|
// 处理当前板块的每条配置
|
||||||
boolean connectionFailed = false;
|
|
||||||
String errorMsg = "";
|
|
||||||
for (BO mainConfig : plateConfigs) {
|
for (BO mainConfig : plateConfigs) {
|
||||||
try {
|
try {
|
||||||
// RDSAPI ccId = SDK.getCCAPI().getRDSAPI(mainConfig.getString("CC_ID"));
|
|
||||||
// Connection open = ccId.open();
|
|
||||||
// open.close();
|
|
||||||
DateRange dateRange = processMainConfig(mainConfig);
|
DateRange dateRange = processMainConfig(mainConfig);
|
||||||
list.add(dateRange);
|
list.add(dateRange);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -103,6 +98,7 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
String partitionField = mainConfig.getString("FQBZD");
|
String partitionField = mainConfig.getString("FQBZD");
|
||||||
String bkgs = mainConfig.getString("BKGS");
|
String bkgs = mainConfig.getString("BKGS");
|
||||||
String jezd = mainConfig.getString("JEZD");
|
String jezd = mainConfig.getString("JEZD");
|
||||||
|
String tablename = mainConfig.getString("TABLENAME");
|
||||||
DateRange dateRange = new DateRange();
|
DateRange dateRange = new DateRange();
|
||||||
|
|
||||||
LOGGER.info("处理配置:BindID={}, 源表={}, 目标表={}, CC_ID={}, 时间字段={}, 分区字段配置={}",
|
LOGGER.info("处理配置:BindID={}, 源表={}, 目标表={}, CC_ID={}, 时间字段={}, 分区字段配置={}",
|
||||||
@ -147,6 +143,14 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
// 查询源表数据(跨库查询)
|
// 查询源表数据(跨库查询)
|
||||||
querySourceData(ccId, tableName, timeField, startDate, endDate, partitionField,
|
querySourceData(ccId, tableName, timeField, startDate, endDate, partitionField,
|
||||||
fieldMappings, targetTable,jezd);
|
fieldMappings, targetTable,jezd);
|
||||||
|
if (tablename.equals("应收表")){
|
||||||
|
LOGGER.info("开始执行应收的明细汇总");
|
||||||
|
querySourceDataYS(ccId, tableName, timeField, startDate, endDate, partitionField,
|
||||||
|
fieldMappings, targetTable, jezd);
|
||||||
|
}else {
|
||||||
|
querySourceData(ccId, tableName, timeField, startDate, endDate, partitionField,
|
||||||
|
fieldMappings, targetTable, jezd);
|
||||||
|
}
|
||||||
dateRange.setStartDate(startDate);
|
dateRange.setStartDate(startDate);
|
||||||
dateRange.setEndDate(endDate);
|
dateRange.setEndDate(endDate);
|
||||||
return dateRange;
|
return dateRange;
|
||||||
@ -235,8 +239,8 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
|
|
||||||
for (int i = 0; i < timeRanges.size(); i++) {
|
for (int i = 0; i < timeRanges.size(); i++) {
|
||||||
Date[] range = timeRanges.get(i);
|
Date[] range = timeRanges.get(i);
|
||||||
String startDate = simpleDateFormat2.format(range[0]);
|
String startDate = simpleDateFormat2.format(range[0])+" 00:00:00";
|
||||||
String endDate = simpleDateFormat2.format(range[1]);
|
String endDate = simpleDateFormat2.format(range[1])+" 23:59:59";
|
||||||
|
|
||||||
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
||||||
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
||||||
@ -362,7 +366,6 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
.append(" AND ")
|
.append(" AND ")
|
||||||
.append(timeField).append(" < ?")
|
.append(timeField).append(" < ?")
|
||||||
.append(" ORDER BY ").append(timeField);
|
.append(" ORDER BY ").append(timeField);
|
||||||
//.append(" BETWEEN ? AND ? ORDER BY " + timeField + "");
|
|
||||||
if (jezd != null && !jezd.isEmpty()) {
|
if (jezd != null && !jezd.isEmpty()) {
|
||||||
conditionBuilder.append(", " + jezd + " ");
|
conditionBuilder.append(", " + jezd + " ");
|
||||||
}
|
}
|
||||||
@ -370,8 +373,6 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
}
|
}
|
||||||
} else if (timeField != null && !timeField.isEmpty()) {
|
} else if (timeField != null && !timeField.isEmpty()) {
|
||||||
// 没有分区字段,但时间字段存在,使用时间范围条件
|
// 没有分区字段,但时间字段存在,使用时间范围条件
|
||||||
/*conditionBuilder.append(timeField)
|
|
||||||
.append(" BETWEEN ? AND ? ORDER BY " + timeField + "");*/
|
|
||||||
conditionBuilder.append(timeField).append(" >= ?")
|
conditionBuilder.append(timeField).append(" >= ?")
|
||||||
.append(" AND ")
|
.append(" AND ")
|
||||||
.append(timeField).append(" < ?")
|
.append(timeField).append(" < ?")
|
||||||
@ -457,10 +458,13 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
Date startDate, Date endDate) {
|
Date startDate, Date endDate) {
|
||||||
try {
|
try {
|
||||||
String deleteSql = "DELETE FROM " + targetTable +
|
String deleteSql = "DELETE FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
|
" WHERE " + targetTimeField + " >= ? ";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
targetTable, deletedCount, startDate, endDate);
|
String endDateStr = simpleDateFormat.format(endDate)+" 23:59:59";
|
||||||
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
|
||||||
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} )",
|
||||||
|
targetTable, deletedCount, startDateStr);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
|
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
|
||||||
}
|
}
|
||||||
@ -729,7 +733,9 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
.addQuery("BINDID =", bindId)
|
.addQuery("BINDID =", bindId)
|
||||||
.list();
|
.list();
|
||||||
//获取板块公司
|
//获取板块公司
|
||||||
String bkgs = DBSql.getString("SELECT BKGS FROM " + targetTable, "BKGS");
|
List<RowMap> maps = DBSql.getMaps("SELECT BKGS FROM " + targetTable + " GROUP BY BKGS");
|
||||||
|
String bkgss = maps.stream().map(o -> o.getString("BKGS")).collect(Collectors.joining(","));
|
||||||
|
String[] bkgsArr = bkgss.split(",");
|
||||||
|
|
||||||
// 根据时间字段是否为空设置日期范围
|
// 根据时间字段是否为空设置日期范围
|
||||||
Date startDate = null;
|
Date startDate = null;
|
||||||
@ -738,11 +744,12 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
// 删除目标表数据(根据时间字段是否为空决定删除范围)
|
// 删除目标表数据(根据时间字段是否为空决定删除范围)
|
||||||
if (timeField == null || timeField.isEmpty()) {
|
if (timeField == null || timeField.isEmpty()) {
|
||||||
// 全量删除
|
// 全量删除
|
||||||
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
|
for (String bkgs : bkgsArr) {
|
||||||
int deletedCount = DBSql.update(deleteSql);
|
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
int deletedCount = DBSql.update(deleteSql);
|
||||||
hzb,deletedCount, startDate, endDate);
|
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
||||||
|
hzb,deletedCount, startDate, endDate);
|
||||||
|
}
|
||||||
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
||||||
// 全量分页迁移数据到汇总表
|
// 全量分页迁移数据到汇总表
|
||||||
if (tablename.equals("应收表")){
|
if (tablename.equals("应收表")){
|
||||||
@ -757,22 +764,21 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
endDate = cal.getTime();
|
endDate = cal.getTime();
|
||||||
cal.add(Calendar.DATE, -DAYS_BACK + 1); // 30天前(含)
|
cal.add(Calendar.DATE, -DAYS_BACK + 1); // 30天前(含)
|
||||||
startDate = cal.getTime();
|
startDate = cal.getTime();
|
||||||
|
|
||||||
// 获取目标表时间字段名
|
// 获取目标表时间字段名
|
||||||
String targetTimeField = getTargetTimeField(fieldMappings, timeField);
|
String targetTimeField = getTargetTimeField(fieldMappings, timeField);
|
||||||
if (targetTimeField == null) {
|
if (targetTimeField == null) {
|
||||||
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
|
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
|
||||||
}
|
}
|
||||||
// 按时间范围删除
|
// 按时间范围删除
|
||||||
String deleteSql = "DELETE FROM " + hzb +
|
for (String bkgs : bkgsArr) {
|
||||||
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
|
String deleteSql = "DELETE FROM " + hzb +
|
||||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
|
||||||
String startDateStr = simpleDateFormat.format(startDate);
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
String endDateStr = simpleDateFormat.format(endDate);
|
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
|
||||||
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr+" 00:00:00", endDateStr+" 23:59:59"});
|
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
|
||||||
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
|
LOGGER.info("已删除目标表["+hzb+"]中{}条数据(时间范围: {} )",
|
||||||
hzb,deletedCount, startDateStr+" 00:00:00", endDateStr+" 23:59:59");
|
deletedCount, startDateStr);
|
||||||
|
}
|
||||||
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
|
||||||
// 按时间范围分页迁移数据到汇总表
|
// 按时间范围分页迁移数据到汇总表
|
||||||
if (tablename.equals("应收表")){
|
if (tablename.equals("应收表")){
|
||||||
@ -817,10 +823,10 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
|||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
} else {
|
} else {
|
||||||
startDate = simpleDateFormat.format(startDated);
|
startDate = simpleDateFormat.format(startDated) + " 00:00:00";
|
||||||
endDate = simpleDateFormat.format(endDated);
|
endDate = simpleDateFormat.format(endDated) + " 23:59:59";
|
||||||
pageSql = "SELECT * FROM " + targetTable +
|
pageSql = "SELECT * FROM " + targetTable +
|
||||||
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
|
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
|
||||||
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||||
LOGGER.info("执行查询的sql:{}", pageSql);
|
LOGGER.info("执行查询的sql:{}", pageSql);
|
||||||
pageData = DBSql.getMaps(pageSql);
|
pageData = DBSql.getMaps(pageSql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user