From 8f1d8c7b0f63862baf0bd76ded25abd183b80881 Mon Sep 17 00:00:00 2001 From: shahaibo <1023316923@qq.com> Date: Mon, 12 Aug 2024 12:47:39 +0800 Subject: [PATCH] TASK:mixi; --- .../common/tasks/MiTuExportScheduledTask.java | 53 ++++++++++--------- .../com/mixi/service/TAppProductService.java | 4 +- 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/java/com/mixi/common/tasks/MiTuExportScheduledTask.java b/src/main/java/com/mixi/common/tasks/MiTuExportScheduledTask.java index b0d096a..6390838 100644 --- a/src/main/java/com/mixi/common/tasks/MiTuExportScheduledTask.java +++ b/src/main/java/com/mixi/common/tasks/MiTuExportScheduledTask.java @@ -73,7 +73,7 @@ public class MiTuExportScheduledTask { // customerTypeAnalysis(); // getBestSell(); // getData(); -// dailySalesIncentiveStatistics(); +// runDailySalesIncentiveStatisticsForPast30Days(); // updateProductStock(); } @@ -101,7 +101,7 @@ public class MiTuExportScheduledTask { // bestSellIsNotNull.lambda().isNotNull(TProduct::getBestSell); List productListAll = productMapper.selectList(bestSellIsNotNull); LocalDate today = LocalDate.now(); - for (int i = 0; i < 1; i++) { + for (int i = 0; i < 30; i++) { // 将这一天的商品销售数量入库 miTuProductSellNumEntry(today, productListAll); today = today.minusDays(1); @@ -2391,11 +2391,18 @@ public class MiTuExportScheduledTask { @Resource private SalesRecordMapper salesRecordMapper; - public void dailySalesIncentiveStatistics() { + private void runDailySalesIncentiveStatisticsForPast30Days() { + LocalDate today = LocalDate.now(); + for (int i = 0; i < 30; i++) { + dailySalesIncentiveStatistics(today); + today = today.minusDays(1); // 日期向前移动一天 + } + } + public void dailySalesIncentiveStatistics(LocalDate localDate) { // 获取前一日所有商品销售记录 // 全日最高個人生意額 (每日計) - List saleRecordList = getSales(); + List saleRecordList = getSales(localDate); if (!CollectionUtils.isEmpty(saleRecordList)) { Transaction transaction = saleRecordList.get(0); SalesRecord salesRecord = new SalesRecord(); @@ -2406,7 +2413,7 @@ public class MiTuExportScheduledTask { } // 全日最高個人銷售件數 (每日計) - List saleRecordList1 = getSalesNumTop(); + List saleRecordList1 = getSalesNumTop(localDate); if (!CollectionUtils.isEmpty(saleRecordList1)) { int i = 0; Transaction transaction = saleRecordList1.get(0); @@ -2429,7 +2436,7 @@ public class MiTuExportScheduledTask { } } - List saleRecordList2 = getSalesByCategory(); + List saleRecordList2 = getSalesByCategory(localDate); if (!CollectionUtils.isEmpty(saleRecordList2)) { for (Transaction transaction : saleRecordList2) { SalesRecord salesRecord = new SalesRecord(); @@ -2440,7 +2447,7 @@ public class MiTuExportScheduledTask { } } - List saleRecordList3 = getSalesByMultiSelling(); + List saleRecordList3 = getSalesByMultiSelling(localDate); if (!CollectionUtils.isEmpty(saleRecordList3)) { for (Transaction transaction : saleRecordList3) { SalesRecord salesRecord = new SalesRecord(); @@ -2451,7 +2458,7 @@ public class MiTuExportScheduledTask { } } - List saleRecordList4 = getSalesByPluCode(); + List saleRecordList4 = getSalesByPluCode(localDate); if (!CollectionUtils.isEmpty(saleRecordList4)) { for (Transaction transaction : saleRecordList4) { SalesRecord salesRecord = new SalesRecord(); @@ -2468,9 +2475,9 @@ public class MiTuExportScheduledTask { } - private List getSalesByPluCode() { + private List getSalesByPluCode(LocalDate localDate) { // 获取今日日期 - LocalDate today = LocalDate.now(); + LocalDate today = localDate; // 获取昨日日期 LocalDate yesterday = today.minusDays(1); @@ -2525,9 +2532,9 @@ public class MiTuExportScheduledTask { return result; } - private List getSalesByMultiSelling() { + private List getSalesByMultiSelling(LocalDate localDate) { // 获取今日日期 - LocalDate today = LocalDate.now(); + LocalDate today = localDate; // 获取昨日日期 LocalDate yesterday = today.minusDays(1); @@ -2589,16 +2596,13 @@ public class MiTuExportScheduledTask { return result; } - private List getSales() { - // 获取今日日期 - LocalDate today = LocalDate.now(); - + private List getSales(LocalDate date) { // 获取昨日日期 - LocalDate yesterday = today.minusDays(1); + LocalDate yesterday = date.minusDays(1); // 格式化日期 DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); - String todayStr = today.format(formatter); + String todayStr = date.format(formatter); String yesterdayStr = yesterday.format(formatter); List result = new ArrayList<>(); Connection conn = null; @@ -2614,8 +2618,7 @@ public class MiTuExportScheduledTask { // 执行查询 System.out.println("创建声明..."); stmt = conn.createStatement(); - String sql; - sql = "SELECT\n" + + String sql = "SELECT\n" + "saleman_name,\n" + "SUM(net_amt) AS total_net_amt\n" + "FROM v_MZG016A\n" + @@ -2646,12 +2649,12 @@ public class MiTuExportScheduledTask { } System.out.println("查询执行完成!"); return result; - } - private List getSalesNumTop() { + + private List getSalesNumTop(LocalDate localDate) { // 获取今日日期 - LocalDate today = LocalDate.now(); + LocalDate today = localDate; // 获取昨日日期 LocalDate yesterday = today.minusDays(1); @@ -2708,9 +2711,9 @@ public class MiTuExportScheduledTask { } - private List getSalesByCategory() { + private List getSalesByCategory(LocalDate localDate) { // 获取今日日期 - LocalDate today = LocalDate.now(); + LocalDate today = localDate; // 获取昨日日期 LocalDate yesterday = today.minusDays(1); diff --git a/src/main/java/com/mixi/service/TAppProductService.java b/src/main/java/com/mixi/service/TAppProductService.java index f29f280..fb8646c 100644 --- a/src/main/java/com/mixi/service/TAppProductService.java +++ b/src/main/java/com/mixi/service/TAppProductService.java @@ -383,8 +383,8 @@ public class TAppProductService extends ServiceImpl { .ge("sell_date", LocalDate.parse(startDate)) .lt("sell_date", LocalDate.parse(endDate)) .groupBy("product_id") - .orderByDesc("sell_num") - .last("LIMIT 10"); + .orderByDesc("sell_num"); +// .last("LIMIT 10"); if (byId != null) { qw.eq("sh_code", byId.getName());