Ver Fonte

1、更新接口,全量同步

liqihao há 1 ano atrás
pai
commit
c8c9bd5fd0

+ 2 - 91
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

@@ -175,22 +175,11 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
      */
     public Long customerConversionAll(CustomerInfoVo vo) {
         SecurityUtils.setTenantId(XiaomanContant.TENANT_ID);
-
         Customer customer = new Customer();
-
         customer.setId(vo.getCompanyId());
-
         extracted(vo, customer);
-
-
         //联系人
         if (!vo.getCustomers().isEmpty()){
-//            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);
-//            });
-
             for (CustomerInfoVo.Customer cus  : vo.getCustomers()){
                 if (StringUtils.isNotEmpty(cus.getEmail())){
                     CustomerUser customerUser = new CustomerUser();
@@ -214,12 +203,8 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                     customerUser.setPhone(cus.getTel());
                     customerUser.setContactJson(JSON.toJSONString(maps));
                     customerUserService.save(customerUser);
-
                 }
-
             }
-
-
         }
         customer.setXmCountryName(vo.getCountryName());
         customerService.save(customer);
@@ -243,7 +228,6 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                 .or()
                 .eq(Objects.nonNull(vo.getCompanyId()), Customer::getCompanyId, vo.getCompanyId())
                 .list();
-
         if (!list.isEmpty()){
             for (Customer customer :list){
                 //小满公司ID
@@ -254,13 +238,10 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                 extracted(vo, customer);
                 //联系人
                 if (!vo.getCustomers().isEmpty()){
-
                     //删除原有邮箱
                     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());
@@ -282,83 +263,13 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                             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.setXmCountryName(vo.getCountryName());
                 customerService.updateById(customer);
             }
+        }else {
+            customerConversionAll(vo);
         }
         SecurityUtils.clearTenantId();
         if (!list.isEmpty()) {