浏览代码

1、数据处理

lqh 1 年之前
父节点
当前提交
34b434e9b6

+ 7 - 0
hx-customer/src/main/java/com/fjhx/customer/entity/xiaoman/vo/CustomerListApiVo.java

@@ -18,7 +18,14 @@ import java.util.List;
 public class CustomerListApiVo {
     List<CustomerApiVo> list = new ArrayList<>();
 
+
+    /**
+     * 总条数
+     */
     public int totalItem;
 
+    /**
+     * 条数
+     */
     public int count;
 }

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

@@ -1,16 +1,24 @@
 package com.fjhx.customer.handle;
 
 
-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.vo.CustomerApiVo;
+import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomer;
 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 javax.swing.*;
 import java.io.BufferedReader;
 import java.io.FileReader;
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
 
 public class HandleXiaomanData {
 
@@ -26,12 +34,26 @@ public class HandleXiaomanData {
                 jsonData += line;
             }
 
-            handleList(jsonData, new TypeReference<R<CustomerListApiVo>>() {});
+            handleAllCustomer(jsonData);
         } catch (IOException e) {
             e.printStackTrace();
         }
     }
 
+    public static CustomerListApiVo handleAllCustomer(String res){
+        CustomerListApiVo customerListApiVo = handleList(res, new TypeReference<R<CustomerListApiVo>>() { });
+
+        XiaomanCustomerServiceImpl xiaomanCustomerService = SpringUtils.getBean(XiaomanCustomerServiceImpl.class);
+        if (!customerListApiVo.getList().isEmpty()){
+            List<XiaomanCustomer> xiaomanCustomerList = new ArrayList<>(customerListApiVo.getList());
+            xiaomanCustomerService.saveOrUpdateBatch(xiaomanCustomerList);
+        }
+
+        return customerListApiVo;
+    }
+
+
+
     public static <T> T handleList(String res, TypeReference<R<T>> typeReference) {
         ObjectMapper objectMapper = new ObjectMapper();
         try {