|
@@ -4,10 +4,17 @@ package com.fjhx.customer.handle;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
+import cn.hutool.core.lang.generator.UUIDGenerator;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.http.HttpUtil;
|
|
|
+import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
+import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
+import com.fjhx.common.aspect.DataSourceAspect;
|
|
|
+import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
|
|
|
import com.fjhx.customer.entity.xiaoman.po.XiaomanConfig;
|
|
|
import com.fasterxml.jackson.core.type.TypeReference;
|
|
@@ -17,8 +24,15 @@ import com.fjhx.customer.entity.xiaoman.vo.CustomerInfoVo;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.XiaomanCustomerVo;
|
|
|
import com.fjhx.customer.service.xiaoman.XiaomanCustomerService;
|
|
|
+import com.fjhx.tenant.entity.dict.dto.DictTenantDataSelectDto;
|
|
|
+import com.fjhx.tenant.entity.dict.po.DictTenantData;
|
|
|
+import com.fjhx.tenant.entity.dict.vo.DictTenantDataVo;
|
|
|
+import com.fjhx.tenant.service.dict.DictTenantDataService;
|
|
|
+import com.ruoyi.common.core.domain.entity.SysDictData;
|
|
|
+import com.ruoyi.common.utils.SecurityUtils;
|
|
|
import com.ruoyi.common.utils.spring.SpringUtils;
|
|
|
import com.fjhx.customer.service.xiaoman.XiaomanConfigService;
|
|
|
+import com.ruoyi.system.service.ISysDictDataService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
@@ -37,9 +51,9 @@ public class HandleXiaomanData {
|
|
|
private static XiaomanConfigService xiaomanConfigService = SpringUtils.getBean(XiaomanConfigService.class);
|
|
|
private static XiaomanCustomerService xiaomanCustomerService = SpringUtils.getBean(XiaomanCustomerService.class);
|
|
|
private static StringRedisTemplate redisTemplate = SpringUtils.getBean(StringRedisTemplate.class);
|
|
|
-
|
|
|
- private static final int PAGE_SIZE = 1000;
|
|
|
-
|
|
|
+ private static DictTenantDataService dictTenantDataService = SpringUtils.getBean(DictTenantDataService.class);
|
|
|
+ private static final int PAGE_SIZE = 20;
|
|
|
+ private static final String TENANT_ID = "ehsd";
|
|
|
public static void main(String[] args) {
|
|
|
String filePath = "D:\\java_conding\\erhong\\hx-customer\\src\\main\\java\\com\\fjhx\\customer\\handle\\bbb.json";
|
|
|
String jsonData = "";
|
|
@@ -116,7 +130,7 @@ public class HandleXiaomanData {
|
|
|
String token = config.getAccessToken();
|
|
|
List<XiaomanCustomerVo> list = xiaomanCustomerService.getList(new XiaomanCustomerSelectDto());
|
|
|
Set<Long> collect = list.stream().map(XiaomanCustomerVo::getCompanyId).collect(Collectors.toSet());
|
|
|
- int pageIndex = 1;
|
|
|
+ int pageIndex = 4326;
|
|
|
int totalPage;
|
|
|
do {
|
|
|
String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));
|
|
@@ -124,7 +138,7 @@ public class HandleXiaomanData {
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / PAGE_SIZE) + (totalItem % PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
|
- } while (pageIndex < totalPage);
|
|
|
+ } while (pageIndex <= totalPage);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
redisTemplate.delete(XiaomanContant.TASK_STATUS_KEY);
|
|
@@ -175,13 +189,16 @@ public class HandleXiaomanData {
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / PAGE_SIZE) + (totalItem % PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
|
- } while (pageIndex < totalPage);
|
|
|
+ } while (pageIndex <= totalPage);
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private static final List<String> SELECTOR_KEY = Arrays.asList("trail_status", "group_id", "pool_id", "origin");
|
|
|
+ private static final Map<String, String> SELECTOR_KEY = new HashMap(){{
|
|
|
+ put("trail_status", "customer_status");
|
|
|
+ put("origin", "customer_source");
|
|
|
+ }};
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -189,18 +206,78 @@ public class HandleXiaomanData {
|
|
|
* @author hj
|
|
|
* @date 2024/4/7 10:51
|
|
|
*/
|
|
|
+ @DSTransactional
|
|
|
public static void getSelectorData() {
|
|
|
XiaomanConfig config = xiaomanConfigService.getConfig();
|
|
|
+ SecurityUtils.setTenantId(TENANT_ID);
|
|
|
String token = config.getAccessToken();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
|
- SELECTOR_KEY.forEach(key -> {
|
|
|
- params.put("field", key);
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
+ SELECTOR_KEY.forEach((k, v) -> {
|
|
|
+ params.put("field", k);
|
|
|
String str = getData(XiaomanContant.SELECTOR_API_URL, token, params);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(str);
|
|
|
+ DictTenantDataSelectDto dictTenantDataSelectDto = new DictTenantDataSelectDto();
|
|
|
+ dictTenantDataSelectDto.setDictCode(v);
|
|
|
+ List<DictTenantDataVo> dictTenantDataServiceList = dictTenantDataService.getList(dictTenantDataSelectDto);
|
|
|
+ Map<String, String> collect = dictTenantDataServiceList.stream().collect(Collectors.toMap(DictTenantDataVo::getDictValue, DictTenantDataVo::getDictKey));
|
|
|
+ JSONArray data = jsonObject.getJSONArray("data");
|
|
|
+ if("trail_status".equals(k)){
|
|
|
+ dealCustomerStatusDict(data, collect);
|
|
|
+ } else if("origin".equals(k)){
|
|
|
+ dealCustomerSourceDict(data, collect);
|
|
|
+ }
|
|
|
log.info("获取小满下拉框字典数据:{}", jsonObject);
|
|
|
});
|
|
|
+ SecurityUtils.clearTenantId();
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
+ private static void dealCustomerSourceDict(JSONArray data, Map<String, String> collect) {
|
|
|
+ List<DictTenantData> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject jsonObject = data.getJSONObject(i);
|
|
|
+ String label = jsonObject.getString("origin_name");
|
|
|
+ boolean result = collect.containsKey(label);
|
|
|
+ if(!result){
|
|
|
+ DictTenantData dictTenantData = new DictTenantData();
|
|
|
+ dictTenantData.setDictCode("customer_source");
|
|
|
+ dictTenantData.setDictValue(label);
|
|
|
+ dictTenantData.setDictKey(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ dictTenantData.setTenantId(TENANT_ID);
|
|
|
+ dictTenantData.setSort(100);
|
|
|
+ list.add(dictTenantData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ dictTenantDataService.saveBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static void dealCustomerStatusDict(JSONArray data, Map<String, String> collect) {
|
|
|
+ List<DictTenantData> list = new ArrayList<>();
|
|
|
+ for (int i = 0; i < data.size(); i++) {
|
|
|
+ JSONObject jsonObject = data.getJSONObject(i);
|
|
|
+ String label = jsonObject.getString("status_name");
|
|
|
+ boolean result = collect.containsKey(label);
|
|
|
+ if(!result){
|
|
|
+ DictTenantData dictTenantData = new DictTenantData();
|
|
|
+ dictTenantData.setDictCode("customer_status");
|
|
|
+ dictTenantData.setDictValue(label);
|
|
|
+ dictTenantData.setDictKey(IdUtil.getSnowflakeNextIdStr());
|
|
|
+ dictTenantData.setTenantId(TENANT_ID);
|
|
|
+ dictTenantData.setSort(100);
|
|
|
+ list.add(dictTenantData);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()){
|
|
|
+ dictTenantDataService.saveBatch(list);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
private static Map<String, Object> initPageParams(int page) {
|
|
|
Map<String, Object> params = new HashMap<>();
|