浏览代码

1、入库

lqh 1 年之前
父节点
当前提交
5467e0df14

+ 51 - 47
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

@@ -210,65 +210,69 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                             .eq(CustomerUser::getCustomerId, customer.getId())
                             .list().stream().collect(Collectors.toMap(CustomerUser::getEmail, Function.identity()));
 
-
+                    Set<String > str = new HashSet<>();
                     for (CustomerInfoVo.Customer cus  :vo.getCustomers()){
-                        //如果email匹配成功新增 ,否则修改
-                        if (collect.containsKey(cus.getEmail())){
-                            List<Map> maps = new ArrayList<>();
-                            CustomerUser customerUser = collect.get(cus.getEmail());
-                            for (CustomerInfoVo.Contact contact: cus.getContact()){
-                                if (StringUtils.isNotEmpty(customerUser.getContactJson())){
+                        if ( !str.contains(customer.getId()+"_"+ cus.getEmail())){
+                            //如果email匹配成功新增 ,否则修改
+                            if (collect.containsKey(cus.getEmail()) ){
+                                List<Map> maps = new ArrayList<>();
+                                CustomerUser customerUser = collect.get(cus.getEmail());
+                                if (StringUtils.isNotEmpty(customerUser.getContactJson())) {
                                     maps = JSON.parseArray(customerUser.getContactJson(), Map.class);
-                                    for (Map map:maps){
-                                        if (!contact.getValue().equals(map.get("contactNo")) && !contact.getType().equals(map.get("type"))){
-                                            Map map1 = new HashMap();
-                                            map1.put("type",contact.getType());
-                                            map1.put("contactNo",contact.getValue());
-                                            maps.add(map1);
-                                        }else {
-                                            System.out.println();
+                                }
+                                for (CustomerInfoVo.Contact contact: cus.getContact()){
+                                    if (StringUtils.isNotEmpty(customerUser.getContactJson())){
+                                        for (Map map:maps){
+                                            if (!contact.getValue().equals(map.get("contactNo")) && !contact.getType().equals(map.get("type"))){
+                                                Map map1 = new HashMap();
+                                                map1.put("type",contact.getType());
+                                                map1.put("contactNo",contact.getValue());
+                                                maps.add(map1);
+                                            }else {
+                                                System.out.println();
+                                            }
                                         }
+
+                                    }else {
+                                        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",contact.getType());
-                                    map1.put("contactNo",contact.getValue());
-                                    maps.add(map1);
                                 }
-
-                            }
-                            customerUser.setEmail(cus.getEmail());
-                            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()) {
+                                customerUser.setEmail(cus.getEmail());
+                                customerUser.setContactJson(JSON.toJSONString(maps));
+                                str.add(customer.getId()+"_"+ cus.getEmail());
+                                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{
                                     Map map1 = new HashMap();
-                                    map1.put("type", contact.getType());
-                                    map1.put("contactNo", contact.getValue());
+                                    map1.put("type", "");
+                                    map1.put("contactNo", "");
                                     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);
-
-                        }
-
+                                customerUser.setContactJson(JSON.toJSONString(maps));
 
+                                str.add(customer.getId()+"_"+ cus.getEmail());
+                                customerUserService.save(customerUser);
 
+                            }
+                        }
                     }
 
                 }