Преглед изворни кода

1、更改country_name 为 xm_country_name
2、更新接口,全量同步

liqihao пре 1 година
родитељ
комит
2369f0d3fa

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/entity/customer/po/Customer.java

@@ -184,6 +184,6 @@ public class Customer extends BasePo {
     /**
      * 小满国家
      */
-    private String countryName;
+    private String xmCountryName;
 
 }

+ 101 - 55
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

@@ -125,11 +125,14 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
     public void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer,boolean flag) {
         List<XiaomanCustomer> xiaomanCustomerList = new ArrayList<>(customerApiVoList);
         for (XiaomanCustomer customer : xiaomanCustomerList) {
+            if (customer.getCompanyId() == 18906983782932L){
                 if (allCustomer.contains(customer.getCompanyId())) {
                     processCustomer(customer, true,flag);
                 } else {
                     processCustomer(customer, false,flag);
                 }
+            }
+
         }
     }
 
@@ -182,7 +185,7 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
 
         //联系人
         if (!vo.getCustomers().isEmpty()){
-           List<CustomerInfoVo.Customer> newCistomer  = new ArrayList<>();
+            List<CustomerInfoVo.Customer> newCistomer  = new ArrayList<>();
              vo.getCustomers().stream().collect(Collectors.groupingBy(CustomerInfoVo.Customer::getEmail)).forEach((k,v)->{
                 CustomerInfoVo.Customer customer1 = v.get(v.size() - 1);
                  newCistomer.add(customer1);
@@ -218,7 +221,7 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
 
 
         }
-        customer.setCountryName(vo.getCountryName());
+        customer.setXmCountryName(vo.getCountryName());
         customerService.save(customer);
 
 
@@ -251,66 +254,109 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                 extracted(vo, customer);
                 //联系人
                 if (!vo.getCustomers().isEmpty()){
-                    Map<String, CustomerUser> collect = customerUserService.lambdaQuery()
-                            .eq(CustomerUser::getCustomerId, customer.getId())
-                            .list().stream().collect(Collectors.toMap(CustomerUser::getEmail, Function.identity()));
-                    //1、小满客户的联系人email为空,不做同步
-                    //2、小满客户的联系人email与客户表联系人相匹配,以小满为主修改联系人信息
-                    //3、小满客户的联系人email与客户表联系人不匹配,以小满为主新增联系人信息
-                    for (CustomerInfoVo.Customer cus  :vo.getCustomers()){
-                        if (StringUtils.isNotEmpty(cus.getEmail())){
-                            //如果email匹配成功新增 ,以小满为主修改客户信息
-                            if (collect.containsKey(cus.getEmail()) ){
-                                CustomerUser customerUser = collect.get(cus.getEmail());
-                                customerUser.setName(cus.getName());
-                                customerUser.setEmail(cus.getEmail());
-                                List<Map> maps = new ArrayList<>();
-                                if (! cus.getContact().isEmpty()) {
-                                    for (CustomerInfoVo.Contact contact : cus.getContact()) {
-                                        Map map1 = new HashMap();
-                                        map1.put("type", contact.getType());
-                                        map1.put("contactNo", contact.getValue());
-                                        maps.add(map1);
-                                    }
-                                }else {
-                                    Map map1 = new HashMap();
-                                    map1.put("type", "");
-                                    map1.put("contactNo", "");
-                                    maps.add(map1);
-                                }
-                                customerUser.setPhone(cus.getTel());
-                                customerUser.setContactJson(JSON.toJSONString(maps));
-                                customerUserService.updateById(customerUser);
-                            }else {
-                                CustomerUser customerUser = new CustomerUser();
-                                customerUser.setCustomerId(customer.getId());
-                                customerUser.setName(cus.getName());
-                                customerUser.setEmail(cus.getEmail());
-                                List<Map> maps = new ArrayList<>();
-                                if (! cus.getContact().isEmpty()){
-                                    for (CustomerInfoVo.Contact contact : cus.getContact()) {
-                                        Map map1 = new HashMap();
-                                        map1.put("type", contact.getType());
-                                        map1.put("contactNo", contact.getValue());
-                                        maps.add(map1);
-                                    }
-                                }else{
+
+                    //删除原有邮箱
+                    customerUserService.lambdaUpdate()
+                            .eq(CustomerUser::getCustomerId,customer.getId()).remove();
+
+                    for (CustomerInfoVo.Customer cus  :vo.getCustomers()) {
+                        if (StringUtils.isNotEmpty(cus.getEmail())) {
+                            CustomerUser customerUser = new CustomerUser();
+                            customerUser.setCustomerId(customer.getId());
+                            customerUser.setName(cus.getName());
+                            customerUser.setEmail(cus.getEmail());
+                            List<Map> maps = new ArrayList<>();
+                            if (!cus.getContact().isEmpty()) {
+                                for (CustomerInfoVo.Contact contact : cus.getContact()) {
                                     Map map1 = new HashMap();
-                                    map1.put("type", "");
-                                    map1.put("contactNo", "");
+                                    map1.put("type", contact.getType());
+                                    map1.put("contactNo", contact.getValue());
                                     maps.add(map1);
                                 }
-                                customerUser.setPhone(cus.getTel());
-                                customerUser.setContactJson(JSON.toJSONString(maps));
-                                customerUserService.save(customerUser);
-
-                                //新增后添加至map中
-                                collect.put(customerUser.getEmail(),customerUser);
+                            } else {
+                                Map map1 = new HashMap();
+                                map1.put("type", "");
+                                map1.put("contactNo", "");
+                                maps.add(map1);
                             }
+                            customerUser.setPhone(cus.getTel());
+                            customerUser.setContactJson(JSON.toJSONString(maps));
+                            customerUserService.save(customerUser);
                         }
                     }
+
+//                    Map<String, CustomerUser> collect = customerUserService.lambdaQuery()
+//                            .eq(CustomerUser::getCustomerId, customer.getId())
+//                            .list().stream().collect(Collectors.toMap(CustomerUser::getEmail, Function.identity()));
+//                    //用于匹配原有联系人是否存在
+//                    Set<String> stringSet =  customerUserService.lambdaQuery()
+//                            .eq(CustomerUser::getCustomerId, customer.getId())
+//                            .list().stream().map(CustomerUser::getEmail).collect(Collectors.toSet());
+                    //1、小满客户的联系人email为空,不做同步
+                    //2、小满客户的联系人email与客户表联系人相匹配,以小满为主修改联系人信息
+                    //3、小满客户的联系人email与客户表联系人不匹配,以小满为主新增联系人信息
+
+//                    for (CustomerInfoVo.Customer cus  :vo.getCustomers()){
+//                        if (StringUtils.isNotEmpty(cus.getEmail())){
+//                            //如果email匹配成功新增 ,以小满为主修改客户信息
+//                            if (collect.containsKey(cus.getEmail()) ){
+//                                CustomerUser customerUser = collect.get(cus.getEmail());
+//                                customerUser.setName(cus.getName());
+//                                customerUser.setEmail(cus.getEmail());
+//                                List<Map> maps = new ArrayList<>();
+//                                if (! cus.getContact().isEmpty()) {
+//                                    for (CustomerInfoVo.Contact contact : cus.getContact()) {
+//                                        Map map1 = new HashMap();
+//                                        map1.put("type", contact.getType());
+//                                        map1.put("contactNo", contact.getValue());
+//                                        maps.add(map1);
+//                                    }
+//                                }else {
+//                                    Map map1 = new HashMap();
+//                                    map1.put("type", "");
+//                                    map1.put("contactNo", "");
+//                                    maps.add(map1);
+//                                }
+//                                customerUser.setPhone(cus.getTel());
+//                                customerUser.setContactJson(JSON.toJSONString(maps));
+//                                customerUserService.updateById(customerUser);
+//
+//                                stringSet.remove(cus.getEmail());
+//                            }else {
+//                                CustomerUser customerUser = new CustomerUser();
+//                                customerUser.setCustomerId(customer.getId());
+//                                customerUser.setName(cus.getName());
+//                                customerUser.setEmail(cus.getEmail());
+//                                List<Map> maps = new ArrayList<>();
+//                                if (! cus.getContact().isEmpty()){
+//                                    for (CustomerInfoVo.Contact contact : cus.getContact()) {
+//                                        Map map1 = new HashMap();
+//                                        map1.put("type", contact.getType());
+//                                        map1.put("contactNo", contact.getValue());
+//                                        maps.add(map1);
+//                                    }
+//                                }else{
+//                                    Map map1 = new HashMap();
+//                                    map1.put("type", "");
+//                                    map1.put("contactNo", "");
+//                                    maps.add(map1);
+//                                }
+//                                customerUser.setPhone(cus.getTel());
+//                                customerUser.setContactJson(JSON.toJSONString(maps));
+//                                customerUserService.save(customerUser);
+//
+//                                //新增后添加至map中
+//                                collect.put(customerUser.getEmail(),customerUser);
+//                            }
+//                        }
+//                    }
+//                    //如果原有数据未匹配删除数据
+//                    if (!stringSet.isEmpty()){
+//                        customerUserService.lambdaUpdate().in(CustomerUser::getEmail,stringSet)
+//                                .eq(CustomerUser::getCustomerId,customer.getId()).remove();
+//                    }
                 }
-                customer.setCountryName(vo.getCountryName());
+                customer.setXmCountryName(vo.getCountryName());
                 customerService.updateById(customer);
             }
         }

+ 2 - 2
hx-customer/src/main/resources/mapper/customer/CustomerMapper.xml

@@ -31,7 +31,7 @@
             c.tel_area_code,
             c.tel,
             c.remark,
-            c.country_name
+            c.xm_country_name
         from customer c
             ${ew.customSqlSegment}
     </select>
@@ -62,7 +62,7 @@
             c.fax,
             c.tel_area_code,
             c.tel,
-            c.country_name
+            c.xm_country_name
         from customer c
             ${ew.customSqlSegment}
     </select>