Ver código fonte

1、数据处理

lqh 1 ano atrás
pai
commit
a6fe5dbd6b

+ 243 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/xiaoman/vo/CustomerInfoVo.java

@@ -0,0 +1,243 @@
+package com.fjhx.customer.entity.xiaoman.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.util.Date;
+import java.util.List;
+
+@Data
+public class CustomerInfoVo {
+
+    @JsonProperty("company_id")
+    private long companyId;
+
+    @JsonProperty("serial_id")
+    private String serialId;
+
+    @JsonProperty("user_id")
+    private List<String> userId;
+
+    @Data
+    public static class Owner {
+        @JsonProperty("user_id")
+        private String userId;
+
+        @JsonProperty("avatar")
+        private String avatar;
+
+        @JsonProperty("name")
+        private String name;
+
+        @JsonProperty("nickname")
+        private String nickname;
+    }
+
+    @JsonProperty("owner")
+    private List<Owner> owner;
+
+    @JsonProperty("create_user")
+    private long createUser;
+
+    @Data
+    public static class LastOwnerInfo {
+        @JsonProperty("nickname")
+        private String nickname;
+
+        @JsonProperty("user_id")
+        private long userId;
+
+        @JsonProperty("avatar")
+        private String avatar;
+    }
+
+    @JsonProperty("last_owner_info")
+    private LastOwnerInfo lastOwnerInfo;
+
+    @JsonProperty("pool_id")
+    private int poolId;
+
+    @JsonProperty("pool_name")
+    private String poolName;
+
+    @JsonProperty("private_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date privateTime;
+
+    @JsonProperty("public_time")
+    private String publicTime;
+
+    @JsonProperty("release_count")
+    private int releaseCount;
+
+    @JsonProperty("edit_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date editTime;
+
+    @JsonProperty("main_lead_id")
+    private int mainLeadId;
+
+    @JsonProperty("lead_name")
+    private String leadName;
+
+    @JsonProperty("origin")
+    private String origin;
+
+    @JsonProperty("origin_name")
+    private String originName;
+
+    @JsonProperty("tag")
+    private List<String> tag;
+
+    @JsonProperty("client_tag_list")
+    private List<String> clientTagList;
+
+    public static class SourceDetail {
+        @JsonProperty("alibaba_store_info")
+        private List<AlibabaStoreInfo> alibabaStoreInfo;
+
+        @JsonProperty("site_info")
+        private List<String> siteInfo;
+
+    }
+
+    @JsonProperty("source_detail")
+    private SourceDetail sourceDetail;
+
+    @JsonProperty("name")
+    private String name;
+
+    @JsonProperty("short_name")
+    private String shortName;
+
+    @JsonProperty("origin_list")
+    private List<String> originList;
+
+    @JsonProperty("biz_type")
+    private String bizType;
+
+    // 嵌套的内部类
+    @Data
+    public static class AlibabaStoreInfo {
+        @JsonProperty("store_id")
+        private String storeId;
+
+        @JsonProperty("store_name")
+        private String storeName;
+
+        @JsonProperty("enable_flag")
+        private String enableFlag;
+
+        @JsonProperty("oauth_flag")
+        private String oauthFlag;
+
+        @JsonProperty("sync_customer_flag")
+        private String syncCustomerFlag;
+
+    }
+
+
+    @JsonProperty("annual_procurement")
+    private int annualProcurement;
+
+    @JsonProperty("country")
+    private String country;
+
+    @JsonProperty("intention_level")
+    private int intentionLevel;
+
+    @JsonProperty("province")
+    private String province;
+
+    @JsonProperty("timezone")
+    private String timezone;
+
+    @JsonProperty("city")
+    private String city;
+
+    @JsonProperty("scale_id")
+    private int scaleId;
+
+    @JsonProperty("trail_status")
+    private String trailStatus;
+
+    @JsonProperty("homepage")
+    private String homepage;
+
+    @JsonProperty("fax")
+    private String fax;
+
+    @JsonProperty("tel_area_code")
+    private String telAreaCode;
+
+    @JsonProperty("tel")
+    private String tel;
+
+    @JsonProperty("address")
+    private String address;
+
+    @JsonProperty("remark")
+    private String remark;
+
+    @JsonProperty("category_ids")
+    private List<Integer> categoryIds;
+
+    @JsonProperty("create_time")
+    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    private Date createTime;
+
+    @JsonProperty("customers")
+    private List<Customer> customers;
+
+    @JsonProperty("country_name")
+    private String countryName;
+
+    @Data
+    public static class Customer {
+        @JsonProperty("customer_id")
+        private long customerId;
+
+        @JsonProperty("company_id")
+        private long companyId;
+
+        @JsonProperty("name")
+        private String name;
+
+        @JsonProperty("email")
+        private String email;
+
+        @JsonProperty("gender")
+        private int gender;
+
+        @JsonProperty("remark")
+        private String remark;
+
+        @JsonProperty("birth")
+        private String birth;
+
+        @JsonProperty("post_grade")
+        private int postGrade;
+
+        @JsonProperty("post")
+        private String post;
+
+        @JsonProperty("image_list")
+        private List<String> imageList;
+
+        @JsonProperty("contact")
+        private List<String> contact;
+
+        @JsonProperty("main_customer_flag")
+        private int mainCustomerFlag;
+
+        @JsonProperty("tel_area_code")
+        private String telAreaCode;
+
+        @JsonProperty("tel")
+        private String tel;
+
+    }
+
+
+}

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

@@ -2,31 +2,24 @@ package com.fjhx.customer.handle;
 
 
 import cn.hutool.http.HttpUtil;
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
 import com.fjhx.customer.entity.xiaoman.po.XiaomanConfig;
 import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
 import com.fasterxml.jackson.core.type.TypeReference;
 import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
+import com.fjhx.customer.entity.xiaoman.vo.CustomerInfoVo;
 import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
 import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
-import com.fjhx.customer.service.xiaoman.impl.XiaomanCustomerServiceImpl;
 import com.ruoyi.common.utils.spring.SpringUtils;
-import org.springframework.beans.BeanUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Component;
 import com.fjhx.customer.service.xiaoman.XiaomanConfigService;
-import com.ruoyi.common.utils.spring.SpringUtils;
-import okhttp3.HttpUrl;
 
 
-import javax.swing.*;
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 public class HandleXiaomanData {
     private static final String ALL_CUSTOMER_API_URL = "https://api-sandbox.xiaoman.cn/v1/company/list";
@@ -36,7 +29,7 @@ public class HandleXiaomanData {
     private static final int PAGE_SIZE = 20;
 
     public static void main(String[] args) {
-        String filePath = "D:\\java_conding\\erhong\\hx-customer\\src\\main\\java\\com\\fjhx\\customer\\handle\\aaa.json";
+        String filePath = "D:\\java_conding\\erhong\\hx-customer\\src\\main\\java\\com\\fjhx\\customer\\handle\\bbb.json";
         String jsonData = "";
 
         try (BufferedReader br = new BufferedReader(new FileReader(filePath))) {
@@ -44,21 +37,20 @@ public class HandleXiaomanData {
             while ((line = br.readLine()) != null) {
                 jsonData += line;
             }
-
-            handleAllCustomer(jsonData);
+            handleList(jsonData, new TypeReference<R<CustomerInfoVo>>() { });
+//            handleAllCustomer(jsonData);
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
 
-    public static CustomerListApiVo handleAllCustomer(String res){
+    public static CustomerListApiVo handleAllCustomer(String res,Set<Long> allCustomer){
+        //反序列化对象
         CustomerListApiVo customerListApiVo = handleList(res, new TypeReference<R<CustomerListApiVo>>() { });
-
+        //判断列表是否为空
         if (!customerListApiVo.getList().isEmpty()){
-
-            xiaomanCustomerService.handleSaveOrUpdate(customerListApiVo.getList());
+            xiaomanCustomerService.handleSaveOrUpdate(customerListApiVo.getList(),allCustomer);
         }
-
         return customerListApiVo;
     }
 
@@ -67,6 +59,7 @@ public class HandleXiaomanData {
     public static <T> T handleList(String res, TypeReference<R<T>> typeReference) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {
+            objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
             R<T> result = objectMapper.readValue(res, typeReference);
             if (result.isOk()) {
                 return result.getData();
@@ -87,11 +80,12 @@ public class HandleXiaomanData {
     public static void initAllList(){
         XiaomanConfig config = xiaomanConfigService.getConfig();
         String token = config.getAccessToken();
+        Set<Long> set = xiaomanCustomerService.getList(new XiaomanCustomerSelectDto()).stream().map(XiaomanCustomer::getCompanyId).collect(Collectors.toSet());
         int pageIndex = 1;
         int totalPage = 1;
         do {
             String str = getData(ALL_CUSTOMER_API_URL, token, pageIndex);
-            CustomerListApiVo customerListApiVo = handleAllCustomer(str);
+            CustomerListApiVo customerListApiVo = handleAllCustomer(str,set);
             int totalItem = customerListApiVo.getTotalItem();
             totalPage = (totalItem / PAGE_SIZE) + (totalItem % PAGE_SIZE > 0 ? 1 : 0);
             pageIndex++;

+ 56 - 283
hx-customer/src/main/java/com/fjhx/customer/handle/bbb.json

@@ -1,319 +1,92 @@
 {
   "code": 200,
   "message": "success",
-  "now": "2024-04-06 11:23:22",
+  "now": "2024-04-06 20:17:16",
   "data": {
-    "company_id": 18669166854018,
-    "short_name": "",
-    "name": "Thu Pham",
-    "category_ids": [],
-    "serial_id": "86776",
-    "archive_time": "2024-04-01 15:55:43",
+    "company_id": 18846628768390,
+    "serial_id": "86795",
+    "user_id": [
+      "56322068"
+    ],
     "owner": [
       {
-        "user_id": "56322072",
-        "avatar": "https://v4client.oss-cn-hangzhou.aliyuncs.com/other/img/56322072/600d4e6ddf7d5b6ee403f5c6f522e79ea773f6ccf548e9d03ccc9a96988987d1.png",
-        "name": "Jimmy",
-        "nickname": "Jimmy"
+        "user_id": "56322068",
+        "avatar": "https://v4client.oss-cn-hangzhou.aliyuncs.com/other/img/56322068/1a2df65fa32a4ee0a6b637c0ca6b3f4b29582e092cbd79b9a49536ccb82fa3fe.png",
+        "name": "Cici",
+        "nickname": "Cici"
       }
     ],
-    "archive_type": 4,
-    "country": "VN",
-    "biz_type": "",
+    "create_user": 56322068,
     "last_owner_info": {
       "nickname": "无",
       "user_id": 0,
       "avatar": ""
     },
-    "private_time": "2024-04-01 15:55:47",
+    "pool_id": 0,
+    "pool_name": "",
+    "private_time": "2024-04-05 17:39:57",
     "public_time": "",
-    "intention_level": 0,
+    "release_count": 0,
+    "edit_time": "2024-04-06 18:23:46",
+    "main_lead_id": 0,
+    "lead_name": "",
+    "origin": "TM咨询",
+    "origin_name": "TM咨询",
+    "tag": [],
+    "client_tag_list": [],
+    "source_detail": {
+      "alibaba_store_info": [
+        {
+          "store_id": "215261497",
+          "store_name": "福州尔泓商贸有限公司",
+          "enable_flag": "1",
+          "oauth_flag": "1",
+          "sync_customer_flag": "1"
+        }
+      ],
+      "site_info": []
+    },
+    "name": "CLP Trading GmbH",
+    "short_name": "",
+    "origin_list": [
+      "TM咨询"
+    ],
+    "biz_type": "",
     "annual_procurement": 0,
+    "country": "DE",
+    "intention_level": 0,
     "province": "",
+    "timezone": "1",
     "city": "",
-    "timezone": "7",
     "scale_id": 0,
-    "star": 0,
-    "group_id": 0,
-    "trail_status": {
-      "status_id": "0",
-      "status_name": "无",
-      "status_color": "#cccccc"
-    },
-    "origin": 4,
-    "origin_list": [
-      4
-    ],
-    "origin_name": "阿里巴巴(B2B平台)",
+    "trail_status": "无",
     "homepage": "",
     "fax": "",
-    "tel": [
-      "",
-      ""
-    ],
     "tel_area_code": "",
+    "tel": "",
     "address": "",
     "remark": "",
-    "image_list": [],
-    "next_follow_up_time": "",
-    "create_user": 56322072,
-    "create_time": "2024-04-01 15:55:47",
-    "last_edit_user": "56322072",
-    "update_time": "2024-04-06 11:12:47",
-    "tag": [],
-    "product_group_ids": [],
-    "release_count": 0,
-    "public_type": 0,
-    "edit_time": "2024-04-06 11:12:46",
-    "main_lead_id": 0,
-    "order_time": "2024-04-06 11:12:47",
-    "recent_follow_up_time": "2024-04-01 15:55:48",
-    "client_tag_list": [],
-    "pool_user_map": [],
-    "company": [
-      {
-        "group_id": 1,
-        "name": "基本信息",
-        "fields": [
-          {
-            "id": "name",
-            "name": "公司名称",
-            "field_type": "1",
-            "value": "Thu Pham"
-          },
-          {
-            "id": "short_name",
-            "name": "简称",
-            "field_type": "1",
-            "value": ""
-          },
-          {
-            "id": "origin_list",
-            "name": "客户来源",
-            "field_type": "7",
-            "value": [
-              "阿里巴巴(B2B平台)"
-            ]
-          },
-          {
-            "id": "origin",
-            "name": "客户来源",
-            "field_type": 3,
-            "value": "阿里巴巴(B2B平台)"
-          }
-        ]
-      },
-      {
-        "group_id": 2,
-        "name": "特征信息",
-        "fields": [
-          {
-            "id": "biz_type",
-            "name": "客户类型",
-            "field_type": "3",
-            "value": ""
-          },
-          {
-            "id": "annual_procurement",
-            "name": "年采购额",
-            "field_type": "3",
-            "value": 0
-          },
-          {
-            "id": "country",
-            "name": "国家地区",
-            "field_type": "3",
-            "value": "VN"
-          },
-          {
-            "id": "intention_level",
-            "name": "采购意向",
-            "field_type": "3",
-            "value": 0
-          },
-          {
-            "id": "province",
-            "name": "省份",
-            "field_type": "3",
-            "value": ""
-          },
-          {
-            "id": "timezone",
-            "name": "时区",
-            "field_type": "3",
-            "value": "7"
-          },
-          {
-            "id": "city",
-            "name": "城市",
-            "field_type": "3",
-            "value": ""
-          },
-          {
-            "id": "scale_id",
-            "name": "规模",
-            "field_type": "3",
-            "value": 0
-          }
-        ]
-      },
-      {
-        "group_id": 3,
-        "name": "管理信息",
-        "fields": [
-          {
-            "id": "trail_status",
-            "name": "客户阶段",
-            "field_type": "3",
-            "value": "无"
-          }
-        ]
-      },
-      {
-        "group_id": 4,
-        "name": "联系信息",
-        "fields": [
-          {
-            "id": "homepage",
-            "name": "公司网址",
-            "field_type": "1",
-            "value": ""
-          },
-          {
-            "id": "fax",
-            "name": "传真",
-            "field_type": "1",
-            "value": ""
-          },
-          {
-            "id": "tel",
-            "name": "座机",
-            "field_type": "1",
-            "value": {
-              "tel_area_code": "",
-              "tel": ""
-            }
-          },
-          {
-            "id": "address",
-            "name": "详细地址",
-            "field_type": "2",
-            "value": ""
-          }
-        ]
-      },
-      {
-        "group_id": 5,
-        "name": "其他信息",
-        "fields": [
-          {
-            "id": "remark",
-            "name": "公司备注",
-            "field_type": "2",
-            "value": ""
-          },
-          {
-            "id": "14200691088213",
-            "name": "餐厨用品",
-            "field_type": "3",
-            "value": ""
-          }
-        ]
-      }
-    ],
-    "lead": {
-      "main_lead_id": 0,
-      "lead_name": null
-    },
+    "category_ids": [],
+    "create_time": "2024-04-05 17:39:57",
     "customers": [
       {
-        "customer_id": 18669166853969,
-        "company_id": 18669166854018,
-        "name": "Thu Pham",
-        "email": "thupham99vn@gmail.com",
+        "customer_id": 18846628830511,
+        "company_id": 18846628768390,
+        "name": "Camon Ye",
+        "email": "",
         "gender": 0,
         "remark": "",
         "birth": "",
-        "tel_list": [],
         "post_grade": 1,
         "post": "",
-        "image_list": "",
+        "image_list": [],
         "contact": [],
         "main_customer_flag": 1,
-        "external_field_data": []
-      }
-    ],
-    "alibaba_store_info": [
-      {
-        "store_id": "239374100",
-        "store_name": "福建尔泓时代家居用品有限公司",
-        "enable_flag": "1",
-        "oauth_flag": "1",
-        "sync_customer_flag": "1"
-      }
-    ],
-    "source_detail": {
-      "alibaba_store_info": [
-        {
-          "store_id": "239374100",
-          "store_name": "福建尔泓时代家居用品有限公司",
-          "enable_flag": "1",
-          "oauth_flag": "1",
-          "sync_customer_flag": "1"
-        }
-      ],
-      "site_info": []
-    },
-    "alibaba_relation_list": [
-      {
-        "store_id": 239374100,
-        "alibaba_company_name": "Thu Pham",
-        "owner_account_id": 251531563,
-        "detail_url": "https://alicrm.alibaba.com/#customerId=ba19b4a20a40ca9779ac57de5ab31a34",
-        "company_id": 18669166854018,
-        "owner_info": {
-          "seller_account_id": "251531563",
-          "seller_email": "sale5@bridge-style.cc",
-          "enable_flag": "1",
-          "login_id": "cn1541243301embs",
-          "first_name": "Jimmy",
-          "last_name": "Wang"
-        },
-        "last_owner_info": {
-          "seller_account_id": 0,
-          "seller_email": "",
-          "enable_flag": 0,
-          "first_name": "",
-          "last_name": "",
-          "login_id": ""
-        },
-        "company_info": {
-          "company_id": 18669166854018,
-          "name": "Thu Pham",
-          "serial_id": "86776",
-          "pool_id": 0,
-          "is_archive": 1,
-          "create_time": "2024-04-01 15:55:47",
-          "trail_status": 0,
-          "user_id": [
-            56322072
-          ],
-          "user_info": [
-            {
-              "user_id": "56322072",
-              "nickname": "Jimmy"
-            }
-          ]
-        },
-        "store_info": {
-          "store_id": "239374100",
-          "store_name": "福建尔泓时代家居用品有限公司",
-          "delete_flag": false,
-          "exception": 0
-        }
+        "tel_area_code": "",
+        "tel": ""
       }
     ],
-    "deal_time": "",
-    "country_name": "越南"
+    "14200691088213": "",
+    "country_name": "德国"
   }
 }

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

@@ -9,6 +9,7 @@ import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
 import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerDto;
 
 import java.util.List;
+import java.util.Set;
 
 /**
  * <p>
@@ -50,5 +51,5 @@ public interface XiaomanCustomerService  {
      */
     void delete(Long id);
 
-    void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList);
+    void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer);
 }

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

@@ -4,6 +4,7 @@ import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
 import com.fjhx.customer.entity.xiaoman.vo.CustomerApiVo;
 import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
 import com.fjhx.customer.mapper.xiaoman.XiaomanCustomerMapper;
+import com.fjhx.customer.service.xiaoman.XiaomanCustomerInfoJsonService;
 import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
@@ -14,8 +15,10 @@ import com.ruoyi.common.utils.wrapper.IWrapper;
 import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerDto;
 import cn.hutool.core.bean.BeanUtil;
 
+import javax.annotation.Resource;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Set;
 
 import static com.ruoyi.common.utils.wrapper.IWrapper.getWrapper;
 
@@ -30,6 +33,9 @@ import static com.ruoyi.common.utils.wrapper.IWrapper.getWrapper;
 @Service
 public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMapper, XiaomanCustomer> implements XiaomanCustomerService {
 
+    @Resource
+    private XiaomanCustomerInfoJsonService xiaomanCustomerInfoJsonService;
+
     @Override
     public List<XiaomanCustomerVo> getList(XiaomanCustomerSelectDto dto) {
         IWrapper<XiaomanCustomer> wrapper = getWrapper();
@@ -69,9 +75,29 @@ public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMappe
     }
 
     @Override
-    public void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList) {
+    public void handleSaveOrUpdate(List<CustomerApiVo> customerApiVoList, Set<Long> allCustomer) {
         List<XiaomanCustomer> xiaomanCustomerList = new ArrayList<>(customerApiVoList);
-        saveOrUpdateBatch(xiaomanCustomerList);
+
+        for (XiaomanCustomer customer : xiaomanCustomerList){
+            if (allCustomer.contains(customer.getCompanyId())){
+                updateById(customer);
+                //TODO 获取详情
+
+                //TODO 更新数据
+
+            }else {
+                save(customer);
+                //TODO 获取详情
+
+
+                //TODO 更新数据
+
+
+            }
+
+
+        }
+
 
     }
 }