lqh 1 жил өмнө
parent
commit
f0d6ada5b1

+ 2 - 2
hx-customer/src/main/java/com/fjhx/customer/handle/HandleXiaomanData.java

@@ -70,13 +70,13 @@ public class HandleXiaomanData {
      * @param allCustomer
      * @return
      */
-    public static CustomerListApiVo handleAllCustomer(String res,Set<Long> allCustomer){
+    public static CustomerListApiVo handleAllCustomer(String res,Set<Long> allCustomer,boolean flag){
         //反序列化对象
         CustomerListApiVo customerListApiVo = handleDate(res, new TypeReference<R<CustomerListApiVo>>() { });
         //判断列表是否为空
         if (!customerListApiVo.getList().isEmpty()){
             //保存或修改
-            xiaomanCustomerService.handleSaveOrUpdate(customerListApiVo.getList(),allCustomer);
+            xiaomanCustomerService.handleSaveOrUpdate(customerListApiVo.getList(),allCustomer,flag);
         }
         return customerListApiVo;
     }

+ 1 - 1
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/XiaomanCustomerService.java

@@ -51,7 +51,7 @@ public interface XiaomanCustomerService  {
      */
     void delete(Long id);
 
-    void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer);
+    void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer,boolean flag);
 
     void initAllList();
     void updateList();

+ 4 - 3
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanApiServiceImpl.java

@@ -71,7 +71,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
             int totalPage;
             do {
                 String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));
-                CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect);
+                CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect,true);
                 int totalItem = customerListApiVo.getTotalItem();
                 totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
                 pageIndex++;
@@ -148,7 +148,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
                 params.put("start_time", DateUtil.parse(nowStr).offset(DateField.HOUR, -hours).toString("yyyy-MM-dd HH:00:00"));
                 params.put("end_time", nowStr);
                 String str = getData(XiaomanContant.GET_UPDATE_CUSTOMER_API_URL, token, params);
-                CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect);
+                CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect,false);
                 int totalItem = customerListApiVo.getTotalItem();
                 totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
                 pageIndex++;
@@ -324,7 +324,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
 
     @Override
     public void dealCustomerTagDict(String label,String key) {
-
+        DynamicDataSourceContextHolder.push(SourceConstant.BASE);
         DictTenantData dictTenantData = new DictTenantData();
         dictTenantData.setDictCode("customer_tag");
         dictTenantData.setDictValue(label);
@@ -332,6 +332,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
         dictTenantData.setTenantId(XiaomanContant.TENANT_ID);
         dictTenantData.setSort(100);
         dictTenantDataService.save(dictTenantData);
+        DynamicDataSourceContextHolder.poll();
 
     }
 }

+ 146 - 86
hx-customer/src/main/java/com/fjhx/customer/service/xiaoman/impl/XiaomanCustomerServiceImpl.java

@@ -122,7 +122,7 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
     }
 
     @Override
-    public void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer) {
+    public void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer,boolean flag) {
         List<XiaomanCustomer> xiaomanCustomerList = new ArrayList<>(customerApiVoList);
         for (XiaomanCustomer customer : xiaomanCustomerList){
             try {
@@ -135,7 +135,8 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                     xiaomanCustomerInfoJsonService.updateById(xiaomanCustomerInfoJson);
                     CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
                     });
-                    Long s = customerConversion(infoVo);
+                    //true 全量更新
+                    Long s = flag ? customerConversionAll(infoVo): customerConversionUpdate(infoVo);
                     customer.setCustomerId(s);
                     updateById(customer);
                 }else {
@@ -149,7 +150,8 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                     CustomerInfoVo infoVo = HandleXiaomanData.handleDate(customerDetailJson, new TypeReference<R<CustomerInfoVo>>() {
                     });
                     //小满客户 =》 客户
-                    Long s = customerConversion(infoVo);
+                    //true 全量更新
+                    Long s = flag ? customerConversionAll(infoVo): customerConversionUpdate(infoVo);
                     customer.setCustomerId(s);
                     save(customer);
                     System.out.println("2");
@@ -158,15 +160,67 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                e.printStackTrace();
             }
         }
+    }
+
+    /**
+     * 小满客户 =》 客户
+     * @param vo
+     */
+    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()){
+            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", 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);
+                }
+
+            }
 
 
+        }
+        customer.setCountryName(vo.getCountryName());
+        customerService.save(customer);
+
+
+        return customer.getId();
     }
 
+
+
     /**
      * 小满客户 =》 客户
      * @param vo
      */
-    public Long customerConversion(CustomerInfoVo vo) {
+    public Long customerConversionUpdate(CustomerInfoVo vo) {
         SecurityUtils.setTenantId(XiaomanContant.TENANT_ID);
         List<Customer> list = customerService.lambdaQuery()
                 .eq(StringUtils.isNotEmpty(vo.getName()), Customer::getName, vo.getName())
@@ -182,84 +236,8 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                 customer.setCompanyId(vo.getCompanyId());
                 //公司编号
                 customer.setCustomerCode(vo.getSerialId());
-                //业务员ID
-                if (!vo.getOwner().isEmpty()){
-                    DynamicDataSourceContextHolder.push(SourceConstant.BASE);
-                    SysUser sysUser = sysUserService.lambdaQuery().eq(SysUser::getNickNameEn, vo.getOwner().get(0).getName()).one();
-                    if (Objects.nonNull(sysUser)){
-                        customer.setUserId(sysUser.getUserId());
-                    }
-                    DynamicDataSourceContextHolder.poll();
-                }
-                //TODO 标签tag  customer_tag
-                if (!vo.getTag().isEmpty()){
-                    Set<String> tags = new HashSet<>();
-                    vo.getTag().forEach(x->{
-                        List<DictTenantDataVo> customerTag = DictUtils.getDictList("customer_tag");
-                        AtomicReference<String> key  = new AtomicReference<>("");
-                        customerTag.forEach(tag ->{
-                            if (tag.getDictValue().equals(x.getTagName())){
-                                key.set(tag.getDictKey());
-                            }
-                        });
-                        if (StringUtils.isNull(key)){
-                            xiaomanApiService.dealCustomerTagDict(x.getTagName(),x.getTagId());
-                            tags.add(x.getTagId());
-                        }else {
-                            tags.add(String.valueOf(key));
-                        }
-
-                    });
-                    customer.setTag(String.join(",",tags));
-                }
-
-                //客户名称
-                customer.setName(vo.getName());
-                //客户简称
-                customer.setShortName(vo.getShortName());
-
-                if (!vo.getOriginList().isEmpty()){
-                    List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_source");
-                    Set<String> sources = new HashSet<>();
-                    vo.getOriginList().forEach(x->{
-                        customerSource.forEach(tag ->{
-                            if (tag.getDictValue().equals(x)){
-                                sources.add(tag.getDictKey());
-                            }
-                        });
-                    });
-                    customer.setSource(String.join(",",sources));
-                }
-
-
-                //客户规模
-                customer.setScaleId(vo.getScaleId());
-
-                if (StringUtils.isNotEmpty(vo.getTrailStatus())){
-                    AtomicReference<String> status = new AtomicReference<>("");
-                    List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_status");
-                        customerSource.forEach(tag ->{
-                            if (tag.getDictValue().equals(vo.getTrailStatus())){
-                                status.set(tag.getDictKey());
-                            }
-                        });
-                    customer.setStatus(String.valueOf(status));
-                }
-
-
-
-                //公司网址
-                customer.setHomepage(vo.getHomepage());
-                //小满传真
-                customer.setFax(vo.getFax());
-                //小满电话区号
-                customer.setTelAreaCode(vo.getTelAreaCode());
-                //小满电话
-                customer.setTel(vo.getTel());
-                //小满备注
-                customer.setRemark(vo.getRemark());
-
 
+                extracted(vo, customer);
                 //联系人
                 if (!vo.getCustomers().isEmpty()){
                     Map<String, CustomerUser> collect = customerUserService.lambdaQuery()
@@ -319,17 +297,12 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
                                 collect.put(customerUser.getEmail(),customerUser);
                             }
                         }
-
                     }
-
-
                 }
                 customer.setCountryName(vo.getCountryName());
                 customerService.updateById(customer);
             }
-
         }
-
         SecurityUtils.clearTenantId();
         if (!list.isEmpty()) {
             Long collect = list.stream().map(Customer::getId).collect(Collectors.toList()).get(0);
@@ -340,6 +313,93 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
 
     }
 
+    /**
+     * 公用方法
+     * @param vo
+     * @param customer
+     */
+    private void extracted(CustomerInfoVo vo, Customer customer) {
+        customer.setAddress(vo.getAddress());
+        //小满公司ID
+        customer.setCompanyId(vo.getCompanyId());
+        //公司编号
+        customer.setCustomerCode(vo.getSerialId());
+        //业务员ID
+        if (!vo.getOwner().isEmpty()){
+            DynamicDataSourceContextHolder.push(SourceConstant.BASE);
+            SysUser sysUser = sysUserService.lambdaQuery().eq(SysUser::getNickNameEn, vo.getOwner().get(0).getName()).one();
+            if (Objects.nonNull(sysUser)){
+                customer.setUserId(sysUser.getUserId());
+            }
+            DynamicDataSourceContextHolder.poll();
+        }
+        //标签tag  customer_tag
+        if (!vo.getTag().isEmpty()){
+            Set<String> tags = new HashSet<>();
+            vo.getTag().forEach(x->{
+                List<DictTenantDataVo> customerTag = DictUtils.getDictList("customer_tag");
+                AtomicReference<String> key  = new AtomicReference<>("");
+                customerTag.forEach(tag ->{
+                    if (tag.getDictValue().equals(x.getTagName())){
+                        key.set(tag.getDictKey());
+                    }
+                });
+                if (StringUtils.isEmpty(key.toString())){
+                    xiaomanApiService.dealCustomerTagDict(x.getTagName(),x.getTagId());
+                    tags.add(x.getTagId());
+                }else {
+                    tags.add(String.valueOf(key));
+                }
+
+            });
+            customer.setTag(String.join(",",tags));
+        }
+
+        //客户名称
+        customer.setName(vo.getName());
+        //客户简称
+        customer.setShortName(vo.getShortName());
+        //客户来源
+        if (!vo.getOriginList().isEmpty()){
+            List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_source");
+            Set<String> sources = new HashSet<>();
+            vo.getOriginList().forEach(x->{
+                customerSource.forEach(tag ->{
+                    if (tag.getDictValue().equals(x)){
+                        sources.add(tag.getDictKey());
+                    }
+                });
+            });
+            customer.setSource(String.join(",",sources));
+        }
+
+
+        //客户规模
+        customer.setScaleId(vo.getScaleId());
+        //客户状态
+        if (StringUtils.isNotEmpty(vo.getTrailStatus())){
+            AtomicReference<String> status = new AtomicReference<>("");
+            List<DictTenantDataVo> customerSource = DictUtils.getDictList("customer_status");
+            customerSource.forEach(tag ->{
+                if (tag.getDictValue().equals(vo.getTrailStatus())){
+                    status.set(tag.getDictKey());
+                }
+            });
+            customer.setStatus(String.valueOf(status));
+        }
+
+        //公司网址
+        customer.setHomepage(vo.getHomepage());
+        //小满传真
+        customer.setFax(vo.getFax());
+        //小满电话区号
+        customer.setTelAreaCode(vo.getTelAreaCode());
+        //小满电话
+        customer.setTel(vo.getTel());
+        //小满备注
+        customer.setRemark(vo.getRemark());
+    }
+
     @Override
     public void initAllList() {
         xiaomanApiService.initAllList();