From 587b9c633f7a47975ec88814e81b492c7861ec79 Mon Sep 17 00:00:00 2001 From: Donghuang Date: Sat, 26 Nov 2022 21:33:57 +0800 Subject: [PATCH] chore: opt duplicate customer import --- .../support/CustomerYearToDateSaleServiceSupport.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server/crm/src/main/java/com/pudonghot/ambition/crm/service/support/CustomerYearToDateSaleServiceSupport.java b/server/crm/src/main/java/com/pudonghot/ambition/crm/service/support/CustomerYearToDateSaleServiceSupport.java index 92c5245..94ee811 100644 --- a/server/crm/src/main/java/com/pudonghot/ambition/crm/service/support/CustomerYearToDateSaleServiceSupport.java +++ b/server/crm/src/main/java/com/pudonghot/ambition/crm/service/support/CustomerYearToDateSaleServiceSupport.java @@ -105,15 +105,22 @@ public class CustomerYearToDateSaleServiceSupport return; } - val customer = customerMapper.find( + val customers = customerMapper.list( new Search(Customer.ID2, customerId2) .eq(Customer.NAME, customerName)); - if (customer == null) { + if (customers.isEmpty()) { log.warn("No customer [{}] found, ignore.", customerName); return; } + if (customers.size() > 1) { + log.warn("Duplicate customers [{}] found, error.", customers); + throw new IllegalStateException( + "Duplicate customer found, id [" + customerId2 + "] name [" + customerName + "]"); + } + + val customer = customers.iterator().next(); val customerId = customer.getId(); customerYtdSale.setCustomerId(customerId); customerYtdSale.setYear(StringUtils.trim(record.get(3)));