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