1、时间范围修改

This commit is contained in:
llllon 2025-09-23 11:58:00 +08:00
parent 7ff2521610
commit 2e115a96c3
9 changed files with 100 additions and 79 deletions

View File

@ -425,7 +425,11 @@ public class DataLinkUpController {
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
// 全量分页迁移数据到汇总表
long summarizeStartTime = System.currentTimeMillis();
if (tablename.equals("应收表")){
dataSyncService.summarizeScopeDataYs(targetTable, null, null, null, hzb);
}else {
dataSyncService.summarizeScopeData(targetTable, null, null, null, hzb);
}
LOGGER.info("全量数据汇总完成,耗时:{}ms", System.currentTimeMillis() - summarizeStartTime);
} else {
// 获取目标表时间字段名
@ -448,6 +452,13 @@ public class DataLinkUpController {
dataSyncService.summarizeScopeDataYs(targetTable, startDate, endDate, targetTimeField, hzb);
}else {
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);
}

View File

@ -44,6 +44,11 @@ public class PurchaseDataLinkUpJob implements IJob {
// 汇总各板块数据
LOGGER.info("======== 开始执行销售汇总各板块数据 ========");
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("======== 销售汇总各板块数据执行完成 ========");
//计算汇总维度

View File

@ -167,10 +167,13 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
Date startDate, Date endDate) {
try {
String deleteSql = "DELETE FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
targetTable, deletedCount, startDate, endDate);
" WHERE " + targetTimeField + " >= ? ";
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("已删除目标表[{}]中{}条数据(时间范围: {} ",
targetTable, deletedCount, startDateStr);
} catch (Exception e) {
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
}
@ -270,8 +273,8 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
for (int i = 0; i < timeRanges.size(); i++) {
Date[] range = timeRanges.get(i);
String startDate = simpleDateFormat2.format(range[0]);
String endDate = simpleDateFormat2.format(range[1]);
String startDate = simpleDateFormat2.format(range[0])+" 00:00:00";
String endDate = simpleDateFormat2.format(range[1])+" 23:59:59";
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
if ("ORACLE".equalsIgnoreCase(DBname)) {
@ -590,11 +593,6 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
String sourceField = mapping.getString("TBBZD");
String targetField = mapping.getString("LDBZD");
// if (!source.containsKey(sourceField)) {
// LOGGER.debug("源字段[{}]不存在于查询结果中", sourceField);
// continue;
// }
String operationExpr = mapping.getString("TBBZDJSLJ");
if (StringUtils.isNotBlank(operationExpr)) {
// 解析运算表达式 (格式: [运算符][数字])
@ -743,10 +741,12 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
}
// 按时间范围删除
String deleteSql = "DELETE FROM " + hzb +
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
hzb,deletedCount, startDate, endDate);
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} ",
hzb,deletedCount, startDate);
// 根据时间范围增加数据分页查询数据存储到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;
pageData = DBSql.getMaps(pageSql);
} else {
startDate = simpleDateFormat.format(startDated);
endDate = simpleDateFormat.format(endDated);
startDate = simpleDateFormat.format(startDated)+" 00:00:00";
endDate = simpleDateFormat.format(endDated)+" 23:59:59";
pageSql = "SELECT * FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
LOGGER.info("执行查询的sql{}", pageSql);
pageData = DBSql.getMaps(pageSql);

View File

@ -64,8 +64,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
// 处理当前板块的每条配置
boolean connectionFailed = false;
String errorMsg = "";
for (BO mainConfig : plateConfigs) {
try {
DateRange dateRange = processMainConfig(mainConfig);
@ -197,8 +195,11 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
Date startDate, Date endDate) {
try {
String deleteSql = "DELETE FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
" WHERE " + targetTimeField + " >= ? ";
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("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
targetTable, deletedCount, startDate, endDate);
} catch (Exception e) {
@ -746,8 +747,9 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
.addQuery("BINDID =", bindId)
.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 endDate = null;
@ -755,10 +757,12 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
// 删除目标表数据根据时间字段是否为空决定删除范围
if (timeField == null || timeField.isEmpty()) {
// 全量删除
for (String bkgs : bkgsArr) {
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
int deletedCount = DBSql.update(deleteSql);
LOGGER.info("已删除目标表[{}}]中{}条数据(时间范围: {} - {})",
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
hzb,deletedCount, startDate, endDate);
}
// 根据时间范围增加数据分页查询数据存储
// 全量分页迁移数据到汇总表
@ -777,14 +781,15 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
}
// 按时间范围删除
for (String bkgs : bkgsArr) {
String deleteSql = "DELETE FROM " + hzb +
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
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, endDateStr});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {}",
hzb,deletedCount, startDateStr, endDateStr);
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
LOGGER.info("已删除目标表["+hzb+"]中{}条数据(时间范围: {} ",
deletedCount, startDate);
}
// 根据时间范围增加数据分页查询数据存储到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;
pageData = DBSql.getMaps(pageSql);
} else {
startDate = simpleDateFormat.format(startDated);
endDate = simpleDateFormat.format(endDated);
startDate = simpleDateFormat.format(startDated)+" 00:00:00";
endDate = simpleDateFormat.format(endDated)+" 23:59:59";
pageSql = "SELECT * FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
LOGGER.info("执行查询的sql{}", pageSql);
pageData = DBSql.getMaps(pageSql);
@ -968,12 +973,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
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"));
LOGGER.info("已迁移{}条数据到汇总表(页号: {},时间范围: {} - {}",
bos.size(), pageNo, startDate, endDate);

View File

@ -65,13 +65,8 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
LOGGER.info("处理板块【{}】的{}条配置", plate, plateConfigs.size());
// 处理当前板块的每条配置
boolean connectionFailed = false;
String errorMsg = "";
for (BO mainConfig : plateConfigs) {
try {
// RDSAPI ccId = SDK.getCCAPI().getRDSAPI(mainConfig.getString("CC_ID"));
// Connection open = ccId.open();
// open.close();
DateRange dateRange = processMainConfig(mainConfig);
list.add(dateRange);
} catch (Exception e) {
@ -103,6 +98,7 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
String partitionField = mainConfig.getString("FQBZD");
String bkgs = mainConfig.getString("BKGS");
String jezd = mainConfig.getString("JEZD");
String tablename = mainConfig.getString("TABLENAME");
DateRange dateRange = new DateRange();
LOGGER.info("处理配置BindID={}, 源表={}, 目标表={}, CC_ID={}, 时间字段={}, 分区字段配置={}",
@ -147,6 +143,14 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
// 查询源表数据跨库查询
querySourceData(ccId, tableName, timeField, startDate, endDate, partitionField,
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.setEndDate(endDate);
return dateRange;
@ -235,8 +239,8 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
for (int i = 0; i < timeRanges.size(); i++) {
Date[] range = timeRanges.get(i);
String startDate = simpleDateFormat2.format(range[0]);
String endDate = simpleDateFormat2.format(range[1]);
String startDate = simpleDateFormat2.format(range[0])+" 00:00:00";
String endDate = simpleDateFormat2.format(range[1])+" 23:59:59";
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
if ("ORACLE".equalsIgnoreCase(DBname)) {
@ -362,7 +366,6 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
.append(" AND ")
.append(timeField).append(" < ?")
.append(" ORDER BY ").append(timeField);
//.append(" BETWEEN ? AND ? ORDER BY " + timeField + "");
if (jezd != null && !jezd.isEmpty()) {
conditionBuilder.append(", " + jezd + " ");
}
@ -370,8 +373,6 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
}
} else if (timeField != null && !timeField.isEmpty()) {
// 没有分区字段但时间字段存在使用时间范围条件
/*conditionBuilder.append(timeField)
.append(" BETWEEN ? AND ? ORDER BY " + timeField + "");*/
conditionBuilder.append(timeField).append(" >= ?")
.append(" AND ")
.append(timeField).append(" < ?")
@ -457,10 +458,13 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
Date startDate, Date endDate) {
try {
String deleteSql = "DELETE FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN ? AND ?";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDate, endDate});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
targetTable, deletedCount, startDate, endDate);
" WHERE " + targetTimeField + " >= ? ";
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("已删除目标表[{}]中{}条数据(时间范围: {} ",
targetTable, deletedCount, startDateStr);
} catch (Exception e) {
throw new RuntimeException("删除目标表数据失败: " + e.getMessage(), e);
}
@ -729,7 +733,9 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
.addQuery("BINDID =", bindId)
.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;
@ -738,11 +744,12 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
// 删除目标表数据根据时间字段是否为空决定删除范围
if (timeField == null || timeField.isEmpty()) {
// 全量删除
for (String bkgs : bkgsArr) {
String deleteSql = "DELETE FROM "+hzb+" WHERE BKGS = '"+bkgs+"'";
int deletedCount = DBSql.update(deleteSql);
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
hzb,deletedCount, startDate, endDate);
}
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
// 全量分页迁移数据到汇总表
if (tablename.equals("应收表")){
@ -757,22 +764,21 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
endDate = cal.getTime();
cal.add(Calendar.DATE, -DAYS_BACK + 1); // 30天前
startDate = cal.getTime();
// 获取目标表时间字段名
String targetTimeField = getTargetTimeField(fieldMappings, timeField);
if (targetTimeField == null) {
LOGGER.error("无法找到源时间字段[{}]对应的目标表字段,跳过同步", timeField);
}
// 按时间范围删除
for (String bkgs : bkgsArr) {
String deleteSql = "DELETE FROM " + hzb +
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " BETWEEN ? AND ?";
" WHERE BKGS = '"+bkgs+"' AND " + targetTimeField + " >= ? ";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startDateStr = simpleDateFormat.format(startDate);
String endDateStr = simpleDateFormat.format(endDate);
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr+" 00:00:00", endDateStr+" 23:59:59"});
LOGGER.info("已删除目标表[{}]中{}条数据(时间范围: {} - {})",
hzb,deletedCount, startDateStr+" 00:00:00", endDateStr+" 23:59:59");
String startDateStr = simpleDateFormat.format(startDate)+" 00:00:00";
int deletedCount = DBSql.update(deleteSql, new Object[]{startDateStr});
LOGGER.info("已删除目标表["+hzb+"]中{}条数据(时间范围: {} ",
deletedCount, startDateStr);
}
// 根据时间范围增加数据分页查询数据存储到BO_EU_BNBM_DATALINKUP_XS_XSL_HZ
// 按时间范围分页迁移数据到汇总表
if (tablename.equals("应收表")){
@ -817,10 +823,10 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
pageData = DBSql.getMaps(pageSql);
} else {
startDate = simpleDateFormat.format(startDated);
endDate = simpleDateFormat.format(endDated);
startDate = simpleDateFormat.format(startDated) + " 00:00:00";
endDate = simpleDateFormat.format(endDated) + " 23:59:59";
pageSql = "SELECT * FROM " + targetTable +
" WHERE " + targetTimeField + " BETWEEN '" + startDate + "' AND '" + endDate + "' " +
" WHERE " + targetTimeField + " >= '" + startDate + "' " +
" ORDER BY ID LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
LOGGER.info("执行查询的sql{}", pageSql);
pageData = DBSql.getMaps(pageSql);