|
|
@@ -31,6 +31,7 @@ public class KdzlServiceImpl implements KdzlService {
|
|
|
private static final int TOKEN_EXPIRE_SECONDS = 7200;
|
|
|
private static final int CACHE_ADVANCE_EXPIRE_SECONDS = 600;
|
|
|
private static final String CUSTOMER_NEXT_CACHE_KEY = "kdzl:customer_next";
|
|
|
+ private static final int MAX_COUNT = 2000;
|
|
|
|
|
|
@Autowired
|
|
|
private RedisCache redisCache;
|
|
|
@@ -89,8 +90,8 @@ public class KdzlServiceImpl implements KdzlService {
|
|
|
}
|
|
|
|
|
|
Integer cachedNext = redisCache.getCacheObject(CUSTOMER_NEXT_CACHE_KEY);
|
|
|
- Integer start = (cachedNext != null) ? cachedNext : 0;
|
|
|
- int count = 1000;
|
|
|
+ int start = (cachedNext != null) ? cachedNext : 0;
|
|
|
+ int count = MAX_COUNT;
|
|
|
|
|
|
String params = "access_token=" + accessToken + "&start=" + start + "&count=" + count;
|
|
|
String response = HttpUtils.sendGet(URL + "/customer/export", params);
|
|
|
@@ -111,16 +112,17 @@ public class KdzlServiceImpl implements KdzlService {
|
|
|
customerList = customerResponse.getCustms();
|
|
|
log.info("成功导出客户数量: {}, 当前start: {}", customerList.size(), start);
|
|
|
|
|
|
- Integer next = customerResponse.getNext();
|
|
|
- if (next != null) {
|
|
|
+ if (customerList.size() == MAX_COUNT) {
|
|
|
+ Integer next = start + count;
|
|
|
redisCache.setCacheObject(CUSTOMER_NEXT_CACHE_KEY, next, 7, TimeUnit.DAYS);
|
|
|
- log.info("next值已存入/更新缓存: {}", next);
|
|
|
+ log.info("数据量达到{},更新next缓存为: {}", MAX_COUNT, next);
|
|
|
} else {
|
|
|
redisCache.deleteObject(CUSTOMER_NEXT_CACHE_KEY);
|
|
|
- log.info("next为null,已清除缓存,所有客户数据已获取完毕");
|
|
|
+ log.info("数据量不足{},清除缓存,所有客户数据已获取完毕", MAX_COUNT);
|
|
|
}
|
|
|
} else {
|
|
|
log.info("未查询到客户数据");
|
|
|
+ redisCache.deleteObject(CUSTOMER_NEXT_CACHE_KEY);
|
|
|
}
|
|
|
} else {
|
|
|
String errMsg = jsonObject.getString("errmsg");
|
|
|
@@ -129,7 +131,73 @@ public class KdzlServiceImpl implements KdzlService {
|
|
|
} catch (Exception e) {
|
|
|
log.error("导出客户异常", e);
|
|
|
}
|
|
|
- log.info("导出客户完成,共导出客户数量,数据: {},{}", customerList.size(), customerList);
|
|
|
+ log.info("导出客户完成,共导出客户数量: {}, 数据: {}", customerList.size(), customerList);
|
|
|
+ return customerList;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<Custm> exportCustomersByPost(Integer start, Long psid) {
|
|
|
+ List<Custm> customerList = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ String accessToken = getAccessToken();
|
|
|
+ if (accessToken.isEmpty()) {
|
|
|
+ log.error("获取access_token失败,无法导出会员");
|
|
|
+ return customerList;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (start == null) {
|
|
|
+ start = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ String url = URL + "/open/api/customer/exportCustomer?access_token=" + accessToken;
|
|
|
+
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ requestBody.put("start", start);
|
|
|
+ if (psid != null) {
|
|
|
+ requestBody.put("psid", psid);
|
|
|
+ }
|
|
|
+
|
|
|
+ log.info("导出会员请求URL: {}, 请求体: {}", url, requestBody.toJSONString());
|
|
|
+
|
|
|
+ String response = HttpUtils.sendPost(url, requestBody.toJSONString());
|
|
|
+
|
|
|
+ log.info("导出会员响应: {}", response);
|
|
|
+
|
|
|
+ if (response.isEmpty()) {
|
|
|
+ log.error("导出会员失败,响应为空");
|
|
|
+ return customerList;
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(response);
|
|
|
+ CustomerResponse customerResponse = jsonObject.toJavaObject(CustomerResponse.class);
|
|
|
+ Integer result = customerResponse.getResult();
|
|
|
+
|
|
|
+ if (result != null && result == 0) {
|
|
|
+ if (!CollectionUtils.isEmpty(customerResponse.getCustms())) {
|
|
|
+ customerList = customerResponse.getCustms();
|
|
|
+ log.info("成功导出会员数量: {}, 当前start: {}", customerList.size(), start);
|
|
|
+
|
|
|
+ if (!customerList.isEmpty()) {
|
|
|
+ Custm lastCustomer = customerList.get(customerList.size() - 1);
|
|
|
+ if (lastCustomer.getCustmid() != null) {
|
|
|
+ redisCache.setCacheObject(CUSTOMER_NEXT_CACHE_KEY, lastCustomer.getCustmid().intValue(), 7, TimeUnit.DAYS);
|
|
|
+ log.info("下次start值已存入/更新缓存: {}", lastCustomer.getCustmid());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.info("未查询到会员数据");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ String errMsg = jsonObject.getString("errmsg");
|
|
|
+ log.error("导出会员失败,错误码: {}, 错误信息: {}", result, errMsg);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("导出会员异常", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ //log.info("导出会员完成,共导出会员数量: {}, 数据: {}", customerList.size(), customerList);
|
|
|
+ log.info("导出会员完成,共导出会员数量: {}", customerList.size());
|
|
|
return customerList;
|
|
|
}
|
|
|
}
|