YPZ 3 週間 前
親
コミット
6a02986889

+ 16 - 9
java/storlead-sasa/storlead-trade/src/main/java/com/storlead/trade/task/CustomerSyncTask.java

@@ -70,25 +70,32 @@ public class CustomerSyncTask {
 
     private void doSync() {
         // 1. 查 customer_analysis_result 中已有的最大 customer_id(无记录则从 0 开始全量同步)
-        CustomerAnalysisResultEntity maxEntity = customerAnalysisResultService.lambdaQuery()
+//        CustomerAnalysisResultEntity maxEntity = customerAnalysisResultService.lambdaQuery()
+//                .select(CustomerAnalysisResultEntity::getCustomerId)
+//                .orderByDesc(CustomerAnalysisResultEntity::getCustomerId)
+//                .last("LIMIT 1")
+//                .one();
+//        long maxCustomerId = maxEntity == null || maxEntity.getCustomerId() == null
+//                ? 0L : maxEntity.getCustomerId();
+        List<Long> customerIdList = customerAnalysisResultService.list(new LambdaQueryWrapper<CustomerAnalysisResultEntity>()
                 .select(CustomerAnalysisResultEntity::getCustomerId)
-                .orderByDesc(CustomerAnalysisResultEntity::getCustomerId)
-                .last("LIMIT 1")
-                .one();
-        long maxCustomerId = maxEntity == null || maxEntity.getCustomerId() == null
-                ? 0L : maxEntity.getCustomerId();
+                .eq(CustomerAnalysisResultEntity::getIsDelete, CommonConstant.DEL_FLAG_0))
+                .stream()
+                .map(CustomerAnalysisResultEntity::getCustomerId)
+                .collect(Collectors.toList());
+
 
         // 2. 查客户表中 id 大于 maxCustomerId 的未删除客户(只取 id)
         List<Long> newCustomerIdList = customerTradeService.list(new LambdaQueryWrapper<CustomerEntity>()
                 .select(CustomerEntity::getId)
                 .eq(CustomerEntity::getIsDelete, CommonConstant.DEL_FLAG_0)
-                .gt(CustomerEntity::getId, maxCustomerId))
+                .ne(CustomerEntity::getId, customerIdList))
                 .stream()
                 .map(CustomerEntity::getId)
                 .collect(Collectors.toList());
 
         if (newCustomerIdList.isEmpty()) {
-            log.info("[CustomerSyncTask] 无新增客户,maxCustomerId={},本次同步 0 条", maxCustomerId);
+            log.info("[CustomerSyncTask] 无新增客户");
             return;
         }
 
@@ -104,6 +111,6 @@ public class CustomerSyncTask {
             }).collect(Collectors.toList());
             customerAnalysisResultService.saveBatch(entityList);
         }
-        log.info("[CustomerSyncTask] 同步完成,maxCustomerId={},新增 {} 条客户待分析记录", maxCustomerId, total);
+        log.info("[CustomerSyncTask] 同步完成,新增 {} 条客户待分析记录",  total);
     }
 }