Răsfoiți Sursa

获取全量列表,获取数据详情

openHj 1 an în urmă
părinte
comite
a769a63df6

+ 3 - 0
hx-customer/src/main/java/com/fjhx/customer/contants/XiaomanContant.java

@@ -3,6 +3,8 @@ package com.fjhx.customer.contants;
 public class XiaomanContant {
 
     public static final String ALL_CUSTOMER_API_URL = "https://api-sandbox.xiaoman.cn/v1/company/list";
+    /**客户数据查询**/
+    public static final String CUSTOMER_DETAIL_API_URL = "https://api-sandbox.xiaoman.cn/v1/company/info";
     /**任务状态redis key**/
     public static final String TASK_STATUS_KEY = "all_customer:task_status_key";
     public static final String TASK_STATUS_VALUE = "start_task";
@@ -13,4 +15,5 @@ public class XiaomanContant {
 //    public static final int DELAY_DELETE_KEY_TIME = 18000;
     public static final int DELAY_DELETE_KEY_TIME = 300;
 
+
 }

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

@@ -4,6 +4,7 @@ package com.fjhx.customer.handle;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.StrUtil;
 import cn.hutool.http.HttpUtil;
+import com.alibaba.fastjson2.JSONObject;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
 import com.fjhx.customer.entity.xiaoman.po.XiaomanConfig;
@@ -99,7 +100,7 @@ public class HandleXiaomanData {
             int pageIndex = 1;
             int totalPage;
             do {
-                String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, pageIndex);
+                String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));
                 CustomerListApiVo customerListApiVo = handleAllCustomer(str, collect);
                 int totalItem = customerListApiVo.getTotalItem();
                 totalPage = (totalItem / PAGE_SIZE) + (totalItem % PAGE_SIZE > 0 ? 1 : 0);
@@ -115,11 +116,37 @@ public class HandleXiaomanData {
         redisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新完成,完成时间:" + DateUtil.now());
     }
 
-    public static String getData(String url, String token, int page) {
+
+    /**
+     * 获取客户详情
+     * @author hj
+     * @date 2024/4/6 21:38
+     * @param companyId 
+     */
+    public static String getCustomerDetail(Long companyId){
+        XiaomanConfig config = xiaomanConfigService.getConfig();
+        String token = config.getAccessToken();
         Map<String, Object> params = new HashMap<>();
-        params.put("start_index", page);
-        params.put("count", PAGE_SIZE);
+        params.put("companyId", companyId);
+        params.put("format", "1");
+        return getData(XiaomanContant.CUSTOMER_DETAIL_API_URL, token, params);
+    }
+
+
+    private static Map<String, Object> initPageParams(int page) {
+        Map<String, Object> params = new HashMap<>();
+        params.put("page", page);
+        params.put("pageSize", PAGE_SIZE);
+        return params;
+    }
+
+    public static String getData(String url, String token, Map<String, Object> params) {
         String res = HttpUtil.createGet(url).header("Authorization", "Bearer " + token).form(params).execute().body();
+        JSONObject jsonObject = JSONObject.parseObject(res);
+        String error = jsonObject.getString("error");
+        if (StrUtil.isNotBlank(error)) {
+            throw new RuntimeException("获取小满数据异常:" + error);
+        }
         return res;
     }
 

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

@@ -5,7 +5,7 @@ import com.fjhx.customer.entity.xiaoman.po.XiaomanCustomerInfoJson;
 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.XiaomanCustomerInfoJsonService;
 import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.stereotype.Service;
@@ -34,8 +34,8 @@ import static com.ruoyi.common.utils.wrapper.IWrapper.getWrapper;
 @Service
 public class XiaomanCustomerServiceImpl extends ServiceImpl<XiaomanCustomerMapper, XiaomanCustomer> implements XiaomanCustomerService {
 
-//    @Resource
-//    private XiaomanCustomerInfoJsonService xiaomanCustomerInfoJsonService;
+    @Resource
+    private XiaomanCustomerInfoJsonService xiaomanCustomerInfoJsonService;
 
     @Override
     public List<XiaomanCustomerVo> getList(XiaomanCustomerSelectDto dto) {