1、修改应收账款

This commit is contained in:
llllon 2025-09-09 15:03:56 +08:00
parent f59dcdc0e4
commit 028bd539b2
2 changed files with 160 additions and 56 deletions

View File

@ -234,7 +234,7 @@ public class DataLinkUpController {
Date startDate = Date.from(startDateTime.atZone(ZoneId.systemDefault()).toInstant());
DataSummaryService summaryService = null;
SaleCountDimensionImpl saleCountDimension = null;
ExecutorService executorService = null; // 线程池用于并行处理销售业务
// ExecutorService executorService = null; // 线程池用于并行处理销售业务
try {
LOGGER.info("开始执行销售数据多维度汇总计算");
@ -258,8 +258,8 @@ public class DataLinkUpController {
if ("销售".equals(ssyw)) {
summaryService = new SaleDataSummaryServiceImpl();
saleCountDimension = new SaleCountDimensionImpl();
executorService = Executors.newFixedThreadPool(2); // 创建固定大小为2的线程池
LOGGER.info("销售业务检测到创建summaryService和saleCountDimension实例初始化线程池");
// executorService = Executors.newFixedThreadPool(2); // 创建固定大小为2的线程池
// LOGGER.info("销售业务检测到创建summaryService和saleCountDimension实例初始化线程池");
}else {
summaryService = new PurchaseDataSummaryServiceImpl();
LOGGER.info("采购业务检测到创建summaryService实例");
@ -274,40 +274,48 @@ public class DataLinkUpController {
if ("销售".equals(ssyw)) {
LOGGER.info("======== 开始并行执行销售数据汇总计算BKGS: {} ========", bo.get("BKGS"));
LOGGER.info("开始执行一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
summaryService.calculateSummary(dateRange, bo);
LOGGER.info("完成一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
// 创建并提交两个并行任务
DataSummaryService finalSummaryService = summaryService;
Future<?> summaryFuture = executorService.submit(() -> {
try {
LOGGER.info("开始执行一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
finalSummaryService.calculateSummary(dateRange, bo);
LOGGER.info("完成一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
} catch (Exception e) {
LOGGER.error("一体化-销售数据汇总计算异常BKGS: {}", bo.get("BKGS"), e);
throw new RuntimeException("一体化-销售数据汇总计算失败: " + e.getMessage(), e);
}
});
// DataSummaryService finalSummaryService = summaryService;
// Future<?> summaryFuture = executorService.submit(() -> {
// try {
// LOGGER.info("开始执行一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
// finalSummaryService.calculateSummary(dateRange, bo);
// LOGGER.info("完成一体化-销售数据汇总计算BKGS: {}", bo.get("BKGS"));
// } catch (Exception e) {
// LOGGER.error("一体化-销售数据汇总计算异常BKGS: {}", bo.get("BKGS"), e);
// throw new RuntimeException("一体化-销售数据汇总计算失败: " + e.getMessage(), e);
// }
// });
SaleCountDimensionImpl finalSaleCountDimension = saleCountDimension;
Future<?> countFuture = executorService.submit(() -> {
try {
LOGGER.info("开始执行销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
finalSaleCountDimension.calculateSummary(dateRange, bo);
LOGGER.info("完成销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
} catch (Exception e) {
LOGGER.error("销售数据多维度汇总计算异常BKGS: {}", bo.get("BKGS"), e);
throw new RuntimeException("销售数据多维度汇总计算失败: " + e.getMessage(), e);
}
});
LOGGER.info("开始执行销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
finalSaleCountDimension.calculateSummary(dateRange, bo);
LOGGER.info("完成销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
// Future<?> countFuture = executorService.submit(() -> {
// try {
// LOGGER.info("开始执行销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
// finalSaleCountDimension.calculateSummary(dateRange, bo);
// LOGGER.info("完成销售数据多维度汇总计算BKGS: {}", bo.get("BKGS"));
// } catch (Exception e) {
// LOGGER.error("销售数据多维度汇总计算异常BKGS: {}", bo.get("BKGS"), e);
// throw new RuntimeException("销售数据多维度汇总计算失败: " + e.getMessage(), e);
// }
// });
// 等待两个任务完成
try {
summaryFuture.get();
countFuture.get();
LOGGER.info("销售数据并行计算完成BKGS: {}", bo.get("BKGS"));
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("销售数据并行计算执行异常BKGS: {}", bo.get("BKGS"), e);
throw new RuntimeException("销售数据并行计算失败: " + e.getMessage(), e);
}
// try {
// summaryFuture.get();
// countFuture.get();
// LOGGER.info("销售数据并行计算完成BKGS: {}", bo.get("BKGS"));
// } catch (InterruptedException | ExecutionException e) {
// LOGGER.error("销售数据并行计算执行异常BKGS: {}", bo.get("BKGS"), e);
// throw new RuntimeException("销售数据并行计算失败: " + e.getMessage(), e);
// }
} else {
// 非销售业务单线程执行
LOGGER.info("======== 开始执行采购数据汇总计算BKGS: {} ========", bo.get("BKGS"));
@ -322,18 +330,18 @@ public class DataLinkUpController {
}
}
// 如果是销售业务关闭线程池
if ("销售".equals(ssyw) && executorService != null) {
executorService.shutdown();
try {
if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
executorService.shutdownNow();
}
} catch (InterruptedException e) {
executorService.shutdownNow();
Thread.currentThread().interrupt();
}
LOGGER.info("销售业务线程池已关闭");
}
// if ("销售".equals(ssyw) && executorService != null) {
// executorService.shutdown();
// try {
// if (!executorService.awaitTermination(60, TimeUnit.SECONDS)) {
// executorService.shutdownNow();
// }
// } catch (InterruptedException e) {
// executorService.shutdownNow();
// Thread.currentThread().interrupt();
// }
// LOGGER.info("销售业务线程池已关闭");
// }
}
ro.put("success", true);
@ -346,15 +354,16 @@ public class DataLinkUpController {
ro.put("message", errorMsg);
// 确保异常时关闭线程池
if (executorService != null) {
executorService.shutdownNow();
}
}finally {
// 最终确保线程池关闭
if (executorService != null) {
executorService.shutdown();
}
// if (executorService != null) {
// executorService.shutdownNow();
// }
}
// finally {
// // 最终确保线程池关闭
// if (executorService != null) {
// executorService.shutdown();
// }
// }
long methodEndTime = System.currentTimeMillis();
LOGGER.info("【完成】数据计算汇总操作,总耗时:{}ms", methodEndTime - methodStartTime);
return ro;

View File

@ -86,28 +86,29 @@ public class SaleCountDimensionImpl implements DataSummaryService {
// 设置为当前月的最后一天
cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
dateRange.setEndDate(cal.getTime());
// calculateForCurrentDate(bkgs);
// calculateMonthlyData(dateRange, bkgs);
// 处理营业收入数据
newProcessRevenueData(dateRange,bkgs);
// 处理销量销额数据分页查询
newProcessSalesVolumeData(dateRange,bkgs);
// 区域两金占比
newProcessRegionTwoFundsRatio(dateRange,bkgs);
// 处理应收账款数据分页查询
newprocessReceivableData(dateRange, bkgs);
LOGGER.info("{}销售数据多维度汇总计算完成",bkgs);
} else {
LOGGER.info("开始执行销售数据多维度汇总计算(时间范围: {} 至 {})",
dateRange.getStartDate(), dateRange.getEndDate());
// 计算月度维度数据按月遍历
calculateMonthlyData(dateRange, bkgs);
// 处理营业收入数据
newProcessRevenueData(dateRange,bkgs);
// 处理销量销额数据分页查询
newProcessSalesVolumeData(dateRange,bkgs);
// 区域两金占比
newProcessRegionTwoFundsRatio(dateRange,bkgs);
// 处理应收账款数据分页查询
newprocessReceivableData(dateRange, bkgs);
LOGGER.info("{}销售数据多维度汇总计算完成",bkgs);
}
@ -118,6 +119,100 @@ public class SaleCountDimensionImpl implements DataSummaryService {
}
}
private void newprocessReceivableData(DateRange dateRange, String bkgs) {
LOGGER.info("开始处理应收账款数据,开始时间: {}, 板块公司: {}", dateRange.getStartDate(), bkgs);
int totalCount = 0;
// 删除已存在的记录
String deleteSql = "DELETE FROM " + BO_EU_XS_YSZK + " WHERE YEARMONTH >= ? AND BKGS = ?";
try {
int deleted = DBSql.update(deleteSql, new Object[]{DATE_FORMAT.format(dateRange.getStartDate()), bkgs});
LOGGER.info("应收账款-已删除{}条记录", deleted);
} catch (Exception e) {
LOGGER.error("应收账款-删除{}数据错误删除sql为{},请检查数据库链接:{}", bkgs, deleteSql, e.getMessage());
throw e;
}
String sql = "SELECT t.RQ,t.QYGS,t.XSZZ,t.SHENGQU,t.SHIQU,t.QX,t.QCYE,t.LJXS,t.LJHK,t.YSYE," +
" t.ZLFX0_60,t.ZLFX60_1,t.ZLFX1_2,t.ZLFX2_3,t.ZLFX3_4,t.ZLFX4_5,t.ZLFX5" +
" FROM BO_EU_BNBM_DATALINKUP_XS_YSL t" +
" INNER JOIN (" +
" SELECT QYGS,SHIQU,MAX(RQ) AS MaxRQ,YEAR(RQ) AS Year,MONTH(RQ) AS Month" +
" FROM BO_EU_BNBM_DATALINKUP_XS_YSL" +
" WHERE DATE(RQ) >= ? AND BKGS = ?" +
" GROUP BY QYGS, SHIQU, YEAR(RQ), MONTH(RQ)" +
" ) AS grouped ON t.QYGS = grouped.QYGS AND t.SHIQU = grouped.SHIQU AND t.RQ = grouped.MaxRQ" +
" WHERE t.BKGS = ?" +
" ORDER BY t.QYGS, t.SHIQU, t.RQ";
List<RowMap> maps = DBSql.getMaps(sql, DATE_FORMAT.format(dateRange.getStartDate()), bkgs);
// 获取公司位置信息
List<RowMap> companyList = DBSql.getMaps("SELECT GSMC,JD,WD FROM BO_EU_BNBM_DATALINKUP_GSJWD");
Map<String, Location> resultMap = companyList.stream()
.filter(row -> row.get("GSMC") != null)
.collect(Collectors.toMap(
row -> row.get("GSMC").toString(),
row -> new Location(
row.get("JD") != null ? row.get("JD").toString() : null,
row.get("WD") != null ? row.get("WD").toString() : null
),
(existing, replacement) -> existing
));
if (maps==null){
LOGGER.info("应收账款数据第无数据");
return;
}
// 分页查询应收账款数据
int page = 0;
boolean hasMore = true;
ArrayList<BO> bos = new ArrayList<>();
for (RowMap map : maps) {
String xszz = map.getString("XSZZ");
String rq = map.getString("RQ");
BO bo = new BO();
bo.set("YEARMONTH", YEAR_MONTH_FORMAT.format(rq));
bo.set("BKGS", bkgs);
bo.set("QYGS", map.getString("QYGS"));
bo.set("GC", xszz);
bo.set("SQ", map.getString("SHENGQU"));
bo.set("CITY", map.getString("SHIQU"));
bo.set("QX", map.getString("QX"));
if (resultMap.containsKey(xszz)) {
Location location = resultMap.get(xszz);
bo.set("JD", location.getLongitude());
bo.set("WD", location.getLatitude());
}
bo.set("QCYE", map.getDouble("QCYE"));
bo.set("NFH", map.getDouble("LJXS"));
bo.set("NHK", map.getDouble("LJHK"));
bo.set("YSZE", map.getDouble("YSYE"));
bo.set("ZL60", map.getDouble("ZLFX0_60"));
bo.set("ZL60_1", map.getDouble("ZLFX60_1"));
bo.set("ZL1_2", map.getDouble("ZLFX1_2"));
bo.set("ZL2_3", map.getDouble("ZLFX2_3"));
bo.set("ZL3_4", map.getDouble("ZLFX3_4"));
bo.set("ZL4_5", map.getDouble("ZLFX4_5"));
bo.set("ZL5", map.getDouble("ZLFX5"));
bos.add(bo);
}
// 批量新增BO
if (!bos.isEmpty()) {
for (int i = 0; i < bos.size(); i += BATCH_SIZE) {
int end = Math.min(bos.size(), i + BATCH_SIZE);
List<BO> batchList = bos.subList(i, end);
SDK.getBOAPI().createDataBO(BO_EU_XS_YSZK, batchList, UserContext.fromUID("admin"));
}
totalCount += bos.size();
LOGGER.info("应收账款数据第{}页处理完成,本页{}条记录,累计{}条", page + 1, bos.size(), totalCount);
page++;
}
LOGGER.info("应收账款数据处理完成,共处理{}条记录", totalCount);
}
/**
* 区域两金占比
* @param dateRange 时间范围