1、同步明细修改为根据时间范围进行同步
This commit is contained in:
parent
2fdde8355b
commit
f8d2b24a0a
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -201,13 +201,23 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
||||
boolean hasMore;
|
||||
RDSAPI rdsapi = null;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startDate = simpleDateFormat.format(startDated);
|
||||
String endDate = simpleDateFormat.format(endDated);
|
||||
|
||||
try {
|
||||
rdsapi = SDK.getCCAPI().getRDSAPI(ccId);
|
||||
DBUtils.SUPPLY supply = rdsapi.getSupply();
|
||||
String DBname = supply.getName();
|
||||
LOGGER.info("数据库为:{}",DBname);
|
||||
|
||||
// 计算时间范围并拆分为30天一组
|
||||
List<Date[]> timeRanges = splitTimeRange(startDated, endDated, 30);
|
||||
LOGGER.info("时间范围拆分为 {} 个查询区间", timeRanges.size());
|
||||
|
||||
for (int i = 0; i < timeRanges.size(); i++) {
|
||||
Date[] range = timeRanges.get(i);
|
||||
String startDate = simpleDateFormat.format(range[0]);
|
||||
String endDate = simpleDateFormat.format(range[1]);
|
||||
|
||||
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
||||
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
||||
// 构建查询条件
|
||||
StringBuilder conditionBuilder = new StringBuilder();
|
||||
@ -284,13 +294,9 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
||||
// 分页查询数据
|
||||
do {
|
||||
// 使用Oracle分页语法 (12c+)
|
||||
String querySql = "SELECT * FROM ( " +
|
||||
"SELECT t.*, ROWNUM rn FROM (" +
|
||||
"SELECT * FROM " + tableName +
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +
|
||||
orderByBuilder.toString() + // 添加排序子句
|
||||
") t WHERE ROWNUM <= " + (pageNo * PAGE_SIZE) +
|
||||
") WHERE rn > " + ((pageNo - 1) * PAGE_SIZE);
|
||||
orderByBuilder.toString(); // 添加排序子句
|
||||
|
||||
LOGGER.debug("执行Oracle查询: {}", querySql);
|
||||
|
||||
@ -367,11 +373,8 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
// 分页查询数据
|
||||
do {
|
||||
String querySqls = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +" ";
|
||||
// " LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||
LOGGER.debug("执行查询querySqls: {}", querySqls);
|
||||
String querySql = SQLPagination.getPaginitionSQL(querySqls, (pageNo - 1) * PAGE_SIZE, PAGE_SIZE,DBname);
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString();
|
||||
|
||||
LOGGER.debug("执行查询querySql: {}", querySql);
|
||||
|
||||
@ -401,7 +404,7 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
} while (hasMore);
|
||||
}
|
||||
|
||||
}
|
||||
LOGGER.info("从表[{}]共查询到{}条数据,成功同步{}条数据",
|
||||
tableName, totalRows, totalSuccess);
|
||||
} catch (Exception e) {
|
||||
@ -457,6 +460,56 @@ public class ProductionDataSyncServiceImpl implements DataSyncService {
|
||||
return successCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间范围拆分为多个区间,并确保结束时间包含时间部分以覆盖完整日期
|
||||
* @param startDate 开始时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param endDate 结束时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param daysInterval 间隔天数
|
||||
* @return 时间区间列表,每个区间的结束时间调整为23:59:59以确保覆盖完整日期
|
||||
*/
|
||||
private static List<Date[]> splitTimeRange(Date startDate, Date endDate, int daysInterval) {
|
||||
List<Date[]> ranges = new ArrayList<>();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(startDate);
|
||||
|
||||
// 调整结束时间以包含完整日期
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
endCal.setTime(endDate);
|
||||
endCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
endCal.set(Calendar.MINUTE, 59);
|
||||
endCal.set(Calendar.SECOND, 59);
|
||||
endCal.set(Calendar.MILLISECOND, 999);
|
||||
Date adjustedEndDate = endCal.getTime();
|
||||
|
||||
while (calendar.getTime().before(adjustedEndDate)) {
|
||||
Date rangeStart = calendar.getTime();
|
||||
|
||||
// 增加间隔天数
|
||||
calendar.add(Calendar.DAY_OF_MONTH, daysInterval);
|
||||
Date potentialRangeEnd = calendar.getTime();
|
||||
|
||||
// 调整区间结束时间为当前日期的23:59:59
|
||||
Calendar rangeEndCal = Calendar.getInstance();
|
||||
rangeEndCal.setTime(potentialRangeEnd);
|
||||
rangeEndCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
rangeEndCal.set(Calendar.MINUTE, 59);
|
||||
rangeEndCal.set(Calendar.SECOND, 59);
|
||||
rangeEndCal.set(Calendar.MILLISECOND, 999);
|
||||
Date rangeEnd = rangeEndCal.getTime();
|
||||
|
||||
// 如果调整后的区间结束时间超过最终结束时间,使用调整后的结束时间
|
||||
if (rangeEnd.after(adjustedEndDate)) {
|
||||
rangeEnd = adjustedEndDate;
|
||||
}
|
||||
|
||||
ranges.add(new Date[]{rangeStart, rangeEnd});
|
||||
|
||||
// 准备下一个区间的开始时间:当前区间结束时间的下一天00:00:00
|
||||
calendar.add(Calendar.MILLISECOND, 1);
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字段映射转换
|
||||
* @param source 源数据记录
|
||||
|
||||
@ -233,13 +233,22 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
boolean hasMore;
|
||||
RDSAPI rdsapi = null;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startDate = simpleDateFormat.format(startDated);
|
||||
String endDate = simpleDateFormat.format(endDated);
|
||||
try {
|
||||
rdsapi = SDK.getCCAPI().getRDSAPI(ccId);
|
||||
DBUtils.SUPPLY supply = rdsapi.getSupply();
|
||||
String DBname = supply.getName();
|
||||
LOGGER.info("数据库为:{}",DBname);
|
||||
|
||||
// 计算时间范围并拆分为30天一组
|
||||
List<Date[]> timeRanges = splitTimeRange(startDated, endDated, 30);
|
||||
LOGGER.info("时间范围拆分为 {} 个查询区间", timeRanges.size());
|
||||
|
||||
for (int i = 0; i < timeRanges.size(); i++) {
|
||||
Date[] range = timeRanges.get(i);
|
||||
String startDate = simpleDateFormat.format(range[0]);
|
||||
String endDate = simpleDateFormat.format(range[1]);
|
||||
|
||||
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
||||
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
||||
// 构建查询条件
|
||||
StringBuilder conditionBuilder = new StringBuilder();
|
||||
@ -315,14 +324,9 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
|
||||
// 分页查询数据
|
||||
do {
|
||||
// 使用Oracle分页语法 (12c+)
|
||||
String querySql = "SELECT * FROM ( " +
|
||||
"SELECT t.*, ROWNUM rn FROM (" +
|
||||
"SELECT * FROM " + tableName +
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +
|
||||
orderByBuilder.toString() + // 添加排序子句
|
||||
") t WHERE ROWNUM <= " + (pageNo * PAGE_SIZE) +
|
||||
") WHERE rn > " + ((pageNo - 1) * PAGE_SIZE);
|
||||
orderByBuilder.toString(); // 添加排序子句
|
||||
|
||||
LOGGER.debug("执行Oracle查询: {}", querySql);
|
||||
|
||||
@ -399,11 +403,8 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
// 分页查询数据
|
||||
do {
|
||||
String querySqls = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +" ";
|
||||
// " LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||
LOGGER.debug("执行查询querySqls: {}", querySqls);
|
||||
String querySql = SQLPagination.getPaginitionSQL(querySqls, (pageNo - 1) * PAGE_SIZE, PAGE_SIZE,DBname);
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString();
|
||||
|
||||
LOGGER.debug("执行查询querySql: {}", querySql);
|
||||
|
||||
@ -433,16 +434,65 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
} while (hasMore);
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("从表[{}]共查询到{}条数据,成功同步{}条数据",
|
||||
tableName, totalRows, totalSuccess);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("查询源表[" + tableName + "]数据失败: " + e.getMessage(), e);
|
||||
}finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间范围拆分为多个区间,并确保结束时间包含时间部分以覆盖完整日期
|
||||
* @param startDate 开始时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param endDate 结束时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param daysInterval 间隔天数
|
||||
* @return 时间区间列表,每个区间的结束时间调整为23:59:59以确保覆盖完整日期
|
||||
*/
|
||||
private static List<Date[]> splitTimeRange(Date startDate, Date endDate, int daysInterval) {
|
||||
List<Date[]> ranges = new ArrayList<>();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(startDate);
|
||||
|
||||
// 调整结束时间以包含完整日期
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
endCal.setTime(endDate);
|
||||
endCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
endCal.set(Calendar.MINUTE, 59);
|
||||
endCal.set(Calendar.SECOND, 59);
|
||||
endCal.set(Calendar.MILLISECOND, 999);
|
||||
Date adjustedEndDate = endCal.getTime();
|
||||
|
||||
while (calendar.getTime().before(adjustedEndDate)) {
|
||||
Date rangeStart = calendar.getTime();
|
||||
|
||||
// 增加间隔天数
|
||||
calendar.add(Calendar.DAY_OF_MONTH, daysInterval);
|
||||
Date potentialRangeEnd = calendar.getTime();
|
||||
|
||||
// 调整区间结束时间为当前日期的23:59:59
|
||||
Calendar rangeEndCal = Calendar.getInstance();
|
||||
rangeEndCal.setTime(potentialRangeEnd);
|
||||
rangeEndCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
rangeEndCal.set(Calendar.MINUTE, 59);
|
||||
rangeEndCal.set(Calendar.SECOND, 59);
|
||||
rangeEndCal.set(Calendar.MILLISECOND, 999);
|
||||
Date rangeEnd = rangeEndCal.getTime();
|
||||
|
||||
// 如果调整后的区间结束时间超过最终结束时间,使用调整后的结束时间
|
||||
if (rangeEnd.after(adjustedEndDate)) {
|
||||
rangeEnd = adjustedEndDate;
|
||||
}
|
||||
|
||||
ranges.add(new Date[]{rangeStart, rangeEnd});
|
||||
|
||||
// 准备下一个区间的开始时间:当前区间结束时间的下一天00:00:00
|
||||
calendar.add(Calendar.MILLISECOND, 1);
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理并插入数据到目标表
|
||||
* @param sourceData 源数据列表
|
||||
@ -755,8 +805,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
bo.set(key, map.get(key));
|
||||
}
|
||||
}
|
||||
// LOGGER.info("明细汇总:字段值set完毕-01");
|
||||
if (bo!=null) {
|
||||
// 如果是采购_入库单汇总 刷新物料名称
|
||||
if (hzb.equals("BO_EU_DWD_ORDER_RKD_HZ")) {
|
||||
String bkgs = bo.getString("BKGS");
|
||||
@ -766,7 +814,6 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
String wlfl = bo.getString("WLFL");
|
||||
Double djhyfs = bo.get("DJHYF",Double.class);
|
||||
double djhyf = djhyfs != null ? djhyfs : 0.0;
|
||||
// LOGGER.info("采购_入库单汇总,刷新物料名称------物料名称:{},板块公司:{},物料编码:{},入库单位:{},单价:{},物料分类:{}", wlmc, bkgs, wlbm, jldw, djhyf, wlfl);
|
||||
|
||||
String newWlmc = "";
|
||||
if (StringUtils.isNotBlank(wlmc) || StringUtils.isNotBlank(wlbm)
|
||||
@ -788,12 +835,8 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
bo.set("WLMC", newWlmc);
|
||||
bo.set("OLDWLMC", wlmc);
|
||||
// LOGGER.info("明细汇总:物料分类更新完毕-02");
|
||||
} else {
|
||||
// LOGGER.info("明细汇总:物料名称为空不进行汇总-03");
|
||||
}
|
||||
// LOGGER.info("采购_入库单汇总,刷新物料名称------物料名称:{},板块公司:{},物料编码:{},入库单位:{},单价:{},物料分类:{}", wlmc, bkgs, wlbm, jldw, djhyf, wlfl);
|
||||
|
||||
if ("泰山石膏".equals(bkgs)) {
|
||||
// 泰山石膏处理入库单金额 入库数量*含税单价
|
||||
Double rksl = bo.get("RKSL", Double.class);// 入库数量
|
||||
@ -806,10 +849,7 @@ public class PurchaseDataSyncServiceImpl implements DataSyncService {
|
||||
bo.set("DHJE", multiply.doubleValue());
|
||||
}
|
||||
}
|
||||
|
||||
bos.add(bo);
|
||||
// LOGGER.info("明细汇总:bo add完毕-04");
|
||||
}
|
||||
}
|
||||
|
||||
SDK.getBOAPI().createDataBO(hzb, bos, UserContext.fromUID("admin"));
|
||||
|
||||
@ -178,13 +178,22 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
boolean hasMore;
|
||||
RDSAPI rdsapi = null;
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
String startDate = simpleDateFormat.format(startDated);
|
||||
String endDate = simpleDateFormat.format(endDated);
|
||||
try {
|
||||
rdsapi = SDK.getCCAPI().getRDSAPI(ccId);
|
||||
DBUtils.SUPPLY supply = rdsapi.getSupply();
|
||||
String DBname = supply.getName();
|
||||
LOGGER.info("数据库为:{}",DBname);
|
||||
|
||||
// 计算时间范围并拆分为30天一组
|
||||
List<Date[]> timeRanges = splitTimeRange(startDated, endDated, 30);
|
||||
LOGGER.info("时间范围拆分为 {} 个查询区间", timeRanges.size());
|
||||
|
||||
for (int i = 0; i < timeRanges.size(); i++) {
|
||||
Date[] range = timeRanges.get(i);
|
||||
String startDate = simpleDateFormat.format(range[0]);
|
||||
String endDate = simpleDateFormat.format(range[1]);
|
||||
|
||||
LOGGER.info("正在处理第 {} 个时间区间: {} 至 {}", i + 1, startDate, endDate);
|
||||
if ("ORACLE".equalsIgnoreCase(DBname)) {
|
||||
// 构建查询条件
|
||||
StringBuilder conditionBuilder = new StringBuilder();
|
||||
@ -261,13 +270,9 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
// 分页查询数据
|
||||
do {
|
||||
// 使用Oracle分页语法 (12c+)
|
||||
String querySql = "SELECT * FROM ( " +
|
||||
"SELECT t.*, ROWNUM rn FROM (" +
|
||||
"SELECT * FROM " + tableName +
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +
|
||||
orderByBuilder.toString() + // 添加排序子句
|
||||
") t WHERE ROWNUM <= " + (pageNo * PAGE_SIZE) +
|
||||
") WHERE rn > " + ((pageNo - 1) * PAGE_SIZE);
|
||||
orderByBuilder.toString(); // 添加排序子句
|
||||
|
||||
LOGGER.debug("执行Oracle查询: {}", querySql);
|
||||
|
||||
@ -344,11 +349,8 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
// 分页查询数据
|
||||
do {
|
||||
String querySqls = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString() +" ";
|
||||
// " LIMIT " + PAGE_SIZE + " OFFSET " + (pageNo - 1) * PAGE_SIZE;
|
||||
LOGGER.info("执行查询querySqls: {}", querySqls);
|
||||
String querySql = SQLPagination.getPaginitionSQL(querySqls, (pageNo - 1) * PAGE_SIZE, PAGE_SIZE,DBname);
|
||||
String querySql = "SELECT * FROM " + tableName +
|
||||
" WHERE " + conditionBuilder.toString();
|
||||
|
||||
LOGGER.info("执行查询querySql: {}", querySql);
|
||||
|
||||
@ -378,13 +380,12 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
} while (hasMore);
|
||||
}
|
||||
}
|
||||
|
||||
LOGGER.info("从表[{}]共查询到{}条数据,成功同步{}条数据",
|
||||
tableName, totalRows, totalSuccess);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("查询源表[" + tableName + "]数据失败: " + e.getMessage(), e);
|
||||
}finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -441,6 +442,56 @@ public class SaleDataSyncServiceImpl implements DataSyncService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间范围拆分为多个区间,并确保结束时间包含时间部分以覆盖完整日期
|
||||
* @param startDate 开始时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param endDate 结束时间(yyyy-MM-dd格式,时间部分为00:00:00)
|
||||
* @param daysInterval 间隔天数
|
||||
* @return 时间区间列表,每个区间的结束时间调整为23:59:59以确保覆盖完整日期
|
||||
*/
|
||||
private static List<Date[]> splitTimeRange(Date startDate, Date endDate, int daysInterval) {
|
||||
List<Date[]> ranges = new ArrayList<>();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(startDate);
|
||||
|
||||
// 调整结束时间以包含完整日期
|
||||
Calendar endCal = Calendar.getInstance();
|
||||
endCal.setTime(endDate);
|
||||
endCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
endCal.set(Calendar.MINUTE, 59);
|
||||
endCal.set(Calendar.SECOND, 59);
|
||||
endCal.set(Calendar.MILLISECOND, 999);
|
||||
Date adjustedEndDate = endCal.getTime();
|
||||
|
||||
while (calendar.getTime().before(adjustedEndDate)) {
|
||||
Date rangeStart = calendar.getTime();
|
||||
|
||||
// 增加间隔天数
|
||||
calendar.add(Calendar.DAY_OF_MONTH, daysInterval);
|
||||
Date potentialRangeEnd = calendar.getTime();
|
||||
|
||||
// 调整区间结束时间为当前日期的23:59:59
|
||||
Calendar rangeEndCal = Calendar.getInstance();
|
||||
rangeEndCal.setTime(potentialRangeEnd);
|
||||
rangeEndCal.set(Calendar.HOUR_OF_DAY, 23);
|
||||
rangeEndCal.set(Calendar.MINUTE, 59);
|
||||
rangeEndCal.set(Calendar.SECOND, 59);
|
||||
rangeEndCal.set(Calendar.MILLISECOND, 999);
|
||||
Date rangeEnd = rangeEndCal.getTime();
|
||||
|
||||
// 如果调整后的区间结束时间超过最终结束时间,使用调整后的结束时间
|
||||
if (rangeEnd.after(adjustedEndDate)) {
|
||||
rangeEnd = adjustedEndDate;
|
||||
}
|
||||
|
||||
ranges.add(new Date[]{rangeStart, rangeEnd});
|
||||
|
||||
// 准备下一个区间的开始时间:当前区间结束时间的下一天00:00:00
|
||||
calendar.add(Calendar.MILLISECOND, 1);
|
||||
}
|
||||
return ranges;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理并插入数据到目标表
|
||||
* @param sourceData 源数据列表
|
||||
|
||||
Loading…
Reference in New Issue
Block a user