|
@@ -52,28 +52,14 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
@Resource
|
|
|
DictTenantDataService dictTenantDataService;
|
|
|
|
|
|
- private static final Map<String, String> SELECTOR_KEY = new HashMap() {{
|
|
|
- put("trail_status", "customer_status");
|
|
|
- put("origin", "customer_source");
|
|
|
- }};
|
|
|
-
|
|
|
- public static void updateInfoData(String token, String body) {
|
|
|
- String res = HttpUtil.createPost(XiaomanContant.UPDATE_INFO_API_URL).header("Authorization", "Bearer " + token).body(body).execute().body();
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
- String error = jsonObject.getString("error");
|
|
|
- if (StrUtil.isNotBlank(error)) {
|
|
|
- throw new RuntimeException("获取小满数据异常:" + error);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // @DSTransactional
|
|
|
+// @DSTransactional
|
|
|
@Override
|
|
|
@Async
|
|
|
public void initAllList() {
|
|
|
boolean result = setNxWithExpiration(XiaomanContant.TASK_STATUS_KEY, XiaomanContant.TASK_STATUS_VALUE, XiaomanContant.DELAY_DELETE_KEY_TIME);
|
|
|
if (!result) {
|
|
|
String mes = stringRedisTemplate.opsForValue().get(XiaomanContant.TASK_STATUS_DESC_KEY);
|
|
|
- throw new RuntimeException(StrUtil.isBlank(mes) ? "全量更新正在进行中" : mes);
|
|
|
+ throw new RuntimeException(StrUtil.isBlank(mes)? "全量更新正在进行中" : mes);
|
|
|
}
|
|
|
stringRedisTemplate.opsForValue().set(XiaomanContant.TASK_STATUS_DESC_KEY, "全量更新正在进行中");
|
|
|
try {
|
|
@@ -87,7 +73,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
int totalPage;
|
|
|
do {
|
|
|
String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));
|
|
|
- CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect);
|
|
|
+ CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect,true);
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
@@ -104,13 +90,12 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
|
|
|
/**
|
|
|
* 设置key-value并设置过期时间
|
|
|
- *
|
|
|
+ * @author hj
|
|
|
+ * @date 2024/4/6 21:14
|
|
|
* @param key
|
|
|
* @param value
|
|
|
* @param seconds
|
|
|
* @return boolean
|
|
|
- * @author hj
|
|
|
- * @date 2024/4/6 21:14
|
|
|
*/
|
|
|
@Override
|
|
|
public boolean setNxWithExpiration(String key, String value, long seconds) {
|
|
@@ -123,15 +108,15 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 获取客户详情
|
|
|
- *
|
|
|
- * @param companyId
|
|
|
* @author hj
|
|
|
* @date 2024/4/6 21:38
|
|
|
+ * @param companyId
|
|
|
*/
|
|
|
@Override
|
|
|
- public String getCustomerDetail(Long companyId) {
|
|
|
+ public String getCustomerDetail(Long companyId){
|
|
|
XiaomanConfig config = xiaomanConfigService.getConfig();
|
|
|
String token = config.getAccessToken();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
@@ -140,15 +125,15 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
return getData(XiaomanContant.CUSTOMER_DETAIL_API_URL, token, params);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 客户更新列表
|
|
|
- *
|
|
|
* @author hj
|
|
|
* @date 2024/4/6 21:54
|
|
|
*/
|
|
|
@Override
|
|
|
@Async
|
|
|
- public void updateList() {
|
|
|
+ public void updateList(){
|
|
|
try {
|
|
|
//先更新一下数据字典
|
|
|
getSelectorData();
|
|
@@ -162,10 +147,10 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
do {
|
|
|
Map<String, Object> params = initPageParams(pageIndex);
|
|
|
String nowStr = DateUtil.offsetHour(DateUtil.date(), 1).toString("yyyy-MM-dd HH:00:00");
|
|
|
- params.put("start_time", DateUtil.parse(nowStr).offset(DateField.HOUR, -8).toString("yyyy-MM-dd HH:00:00"));
|
|
|
+ params.put("start_time", DateUtil.parse(nowStr).offset(DateField.HOUR, -hours).toString("yyyy-MM-dd HH:00:00"));
|
|
|
params.put("end_time", nowStr);
|
|
|
String str = getData(XiaomanContant.GET_UPDATE_CUSTOMER_API_URL, token, params);
|
|
|
- CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect);
|
|
|
+ CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect,false);
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
@@ -176,27 +161,14 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static Map<String, Object> initPageParams(int page) {
|
|
|
- Map<String, Object> params = new HashMap<>();
|
|
|
- params.put("start_index", page);
|
|
|
- params.put("count", XiaomanContant.PAGE_SIZE);
|
|
|
- return params;
|
|
|
- }
|
|
|
-
|
|
|
+ private static final Map<String, String> SELECTOR_KEY = new HashMap(){{
|
|
|
+ put("trail_status", "customer_status");
|
|
|
+ put("origin", "customer_source");
|
|
|
+ }};
|
|
|
|
|
|
- private 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;
|
|
|
- }
|
|
|
|
|
|
/**
|
|
|
* 获取下拉框字典数据
|
|
|
- *
|
|
|
* @author hj
|
|
|
* @date 2024/4/7 10:51
|
|
|
*/
|
|
@@ -215,11 +187,11 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
DictTenantDataSelectDto dictTenantDataSelectDto = new DictTenantDataSelectDto();
|
|
|
dictTenantDataSelectDto.setDictCode(v);
|
|
|
List<DictTenantDataVo> dictTenantDataServiceList = dictTenantDataService.getList(dictTenantDataSelectDto);
|
|
|
- Map<String, DictTenantData> collect = dictTenantDataServiceList.stream().collect(Collectors.toMap(DictTenantDataVo::getDictValue, o -> BeanUtil.copyProperties(o, DictTenantData.class)));
|
|
|
+ Map<String, DictTenantData> collect = dictTenantDataServiceList.stream().collect(Collectors.toMap(DictTenantDataVo::getDictValue, o-> BeanUtil.copyProperties(o, DictTenantData.class)));
|
|
|
JSONArray data = jsonObject.getJSONArray("data");
|
|
|
- if ("trail_status".equals(k)) {
|
|
|
+ if("trail_status".equals(k)){
|
|
|
dealCustomerStatusDict(data, collect);
|
|
|
- } else if ("origin".equals(k)) {
|
|
|
+ } else if("origin".equals(k)){
|
|
|
dealCustomerSourceDict(data, collect);
|
|
|
}
|
|
|
log.info("获取小满下拉框字典数据:{}", jsonObject);
|
|
@@ -228,24 +200,49 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
DynamicDataSourceContextHolder.poll();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ private static Map<String, Object> initPageParams(int page) {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("start_index", page);
|
|
|
+ params.put("count", XiaomanContant.PAGE_SIZE);
|
|
|
+ return params;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@Override
|
|
|
- public void updateXiaomanData(XiaomanUpdateInfoVO xiaomanUpdateInfoVO) {
|
|
|
- if (ObjectUtil.isNull(xiaomanUpdateInfoVO)) {
|
|
|
+ public void updateXiaomanData(XiaomanUpdateInfoVO xiaomanUpdateInfoVO){
|
|
|
+ if (ObjectUtil.isNull(xiaomanUpdateInfoVO)){
|
|
|
throw new RuntimeException("数据为空");
|
|
|
}
|
|
|
- if (StrUtil.isBlank(xiaomanUpdateInfoVO.getName())) {
|
|
|
+ if (StrUtil.isBlank(xiaomanUpdateInfoVO.getName())){
|
|
|
throw new RuntimeException("客户名称为空");
|
|
|
}
|
|
|
xiaomanUpdateInfoVO.setPoolId(0);
|
|
|
List<XiaomanUpdateInfoVO.Customer> customers = xiaomanUpdateInfoVO.getCustomers();
|
|
|
- if (CollectionUtil.isEmpty(customers)) {
|
|
|
+ if (CollectionUtil.isEmpty(customers)){
|
|
|
throw new RuntimeException("客户联系人为空");
|
|
|
}
|
|
|
for (XiaomanUpdateInfoVO.Customer customer : customers) {
|
|
|
- if (StrUtil.isBlank(customer.getName())) {
|
|
|
+ if (StrUtil.isBlank(customer.getName())){
|
|
|
throw new RuntimeException("客户联系人名称存在为空");
|
|
|
}
|
|
|
- if (StrUtil.isBlank(customer.getEmail())) {
|
|
|
+ if (StrUtil.isBlank(customer.getEmail())){
|
|
|
throw new RuntimeException("客户联系人email存在为空");
|
|
|
}
|
|
|
customer.setMainCustomerFlag("0");
|
|
@@ -259,6 +256,22 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
updateInfoData(token, body);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void updateInfoData(String token, String body){
|
|
|
+ String res = HttpUtil.createPost(XiaomanContant.UPDATE_INFO_API_URL).header("Authorization", "Bearer " + token).body(body).execute().body();
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ String error = jsonObject.getString("error");
|
|
|
+ if (StrUtil.isNotBlank(error)) {
|
|
|
+ throw new RuntimeException("获取小满数据异常:" + error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
private void dealCustomerSourceDict(JSONArray data, Map<String, DictTenantData> collect) {
|
|
|
List<DictTenantData> list = new ArrayList<>();
|
|
|
for (int i = 0; i < data.size(); i++) {
|
|
@@ -266,7 +279,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
String label = jsonObject.getString("origin_name");
|
|
|
String key = jsonObject.getString("origin_id");
|
|
|
boolean result = collect.containsKey(label);
|
|
|
- if (!result) {
|
|
|
+ if(!result){
|
|
|
DictTenantData dictTenantData = new DictTenantData();
|
|
|
dictTenantData.setDictCode("customer_source");
|
|
|
dictTenantData.setDictValue(label);
|
|
@@ -274,13 +287,13 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
dictTenantData.setTenantId(XiaomanContant.TENANT_ID);
|
|
|
dictTenantData.setSort(100);
|
|
|
list.add(dictTenantData);
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
DictTenantData dictTenantData = collect.get(label);
|
|
|
dictTenantData.setDictKey(key);
|
|
|
dictTenantDataService.updateById(dictTenantData);
|
|
|
}
|
|
|
}
|
|
|
- if (!list.isEmpty()) {
|
|
|
+ if (!list.isEmpty()){
|
|
|
dictTenantDataService.saveBatch(list);
|
|
|
}
|
|
|
}
|
|
@@ -292,7 +305,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
String label = jsonObject.getString("status_name");
|
|
|
String key = jsonObject.getString("status_id");
|
|
|
boolean result = collect.containsKey(label);
|
|
|
- if (!result) {
|
|
|
+ if(!result){
|
|
|
DictTenantData dictTenantData = new DictTenantData();
|
|
|
dictTenantData.setDictCode("customer_status");
|
|
|
dictTenantData.setDictValue(label);
|
|
@@ -300,20 +313,20 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
dictTenantData.setTenantId(XiaomanContant.TENANT_ID);
|
|
|
dictTenantData.setSort(100);
|
|
|
list.add(dictTenantData);
|
|
|
- } else {
|
|
|
+ }else {
|
|
|
DictTenantData dictTenantData = collect.get(label);
|
|
|
dictTenantData.setDictKey(key);
|
|
|
dictTenantDataService.updateById(dictTenantData);
|
|
|
}
|
|
|
}
|
|
|
- if (!list.isEmpty()) {
|
|
|
+ if (!list.isEmpty()){
|
|
|
dictTenantDataService.saveBatch(list);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void dealCustomerTagDict(String label, String key) {
|
|
|
-
|
|
|
+ public void dealCustomerTagDict(String label,String key) {
|
|
|
+ DynamicDataSourceContextHolder.push(SourceConstant.BASE);
|
|
|
DictTenantData dictTenantData = new DictTenantData();
|
|
|
dictTenantData.setDictCode("customer_tag");
|
|
|
dictTenantData.setDictValue(label);
|
|
@@ -321,6 +334,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
dictTenantData.setTenantId(XiaomanContant.TENANT_ID);
|
|
|
dictTenantData.setSort(100);
|
|
|
dictTenantDataService.save(dictTenantData);
|
|
|
+ DynamicDataSourceContextHolder.poll();
|
|
|
|
|
|
}
|
|
|
|