|
@@ -1,7 +1,6 @@
|
|
|
package com.fjhx.customer.service.xiaoman.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
-import cn.hutool.core.collection.CollectionUtil;
|
|
|
import cn.hutool.core.date.DateField;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.NumberUtil;
|
|
@@ -56,7 +55,21 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
@Resource
|
|
|
RedisCache redisCache;
|
|
|
|
|
|
-// @DSTransactional
|
|
|
+ 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
|
|
|
@Override
|
|
|
@Async
|
|
|
public void initAllList() {
|
|
@@ -82,7 +95,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
String token = config.getAccessToken();
|
|
|
|
|
|
String str = getData(XiaomanContant.ALL_CUSTOMER_API_URL, token, initPageParams(pageIndex));
|
|
|
- CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect,true);
|
|
|
+ CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect, true);
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
@@ -100,12 +113,13 @@ 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) {
|
|
@@ -118,15 +132,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.getCache();
|
|
|
String token = config.getAccessToken();
|
|
|
Map<String, Object> params = new HashMap<>();
|
|
@@ -135,7 +149,6 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
return getData(XiaomanContant.CUSTOMER_DETAIL_API_URL, token, params);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/**
|
|
|
* 客户更新列表
|
|
|
*
|
|
@@ -162,7 +175,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
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,false);
|
|
|
+ CustomerListApiVo customerListApiVo = HandleXiaomanData.handleAllCustomer(str, collect, false);
|
|
|
int totalItem = customerListApiVo.getTotalItem();
|
|
|
totalPage = (totalItem / XiaomanContant.PAGE_SIZE) + (totalItem % XiaomanContant.PAGE_SIZE > 0 ? 1 : 0);
|
|
|
pageIndex++;
|
|
@@ -173,14 +186,27 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private static final Map<String, String> SELECTOR_KEY = new HashMap(){{
|
|
|
- put("trail_status", "customer_status");
|
|
|
- put("origin", "customer_source");
|
|
|
- }};
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 获取下拉框字典数据
|
|
|
+ *
|
|
|
* @author hj
|
|
|
* @date 2024/4/7 10:51
|
|
|
*/
|
|
@@ -199,11 +225,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);
|
|
@@ -212,37 +238,12 @@ 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);
|
|
@@ -267,22 +268,6 @@ 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++) {
|
|
@@ -290,7 +275,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);
|
|
@@ -298,13 +283,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);
|
|
|
}
|
|
|
}
|
|
@@ -316,7 +301,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);
|
|
@@ -324,19 +309,19 @@ 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");
|
|
@@ -359,7 +344,7 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
return;
|
|
|
}
|
|
|
XiaomanUpdateInfoVO xVo = new XiaomanUpdateInfoVO();
|
|
|
- List<XiaomanUpdateInfoVO.Customer> xiaomanCustomerUserList = new ArrayList<>();
|
|
|
+ List<JSONObject> xiaomanCustomerUserList = new ArrayList<>();
|
|
|
|
|
|
//=========================
|
|
|
List<CustomerUser> customerUserList = dto.getCustomerUserList();
|
|
@@ -368,45 +353,57 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
log.info("->" + contactJsonStr + "<-");
|
|
|
JSONArray contactJsonArr = ObjectUtil.isEmpty(contactJsonStr) ? new JSONArray() : JSONArray.parseArray(contactJsonStr);
|
|
|
|
|
|
- XiaomanUpdateInfoVO.Customer xCU = new XiaomanUpdateInfoVO.Customer();
|
|
|
- xCU.setName(cu.getName());//联系人名称
|
|
|
- xCU.setEmail(cu.getEmail());//客户简称
|
|
|
- xCU.setRemark(dto.getRemark());//客户联系人备注
|
|
|
- xCU.setTelAreaCode(Long.parseLong(dto.getTelAreaCode())); //客户联系人电话区号
|
|
|
-
|
|
|
+ JSONObject xCU = new JSONObject();
|
|
|
+ xCU.put("mainCustomerFlag", 0);//主要联系人设置标志
|
|
|
+ xCU.put("name", cu.getName());//客户联系人名称
|
|
|
+ xCU.put("email", cu.getEmail());//客户联系人邮箱
|
|
|
+ xCU.put("remark", dto.getRemark());//客户联系人备注
|
|
|
+ xCU.put("telAreaCode", dto.getTelAreaCode());//客户联系人电话区号
|
|
|
//更多联系方式
|
|
|
for (int i = 0; i < contactJsonArr.size(); i++) {
|
|
|
JSONObject contactJson = contactJsonArr.getJSONObject(i);
|
|
|
- String contactNo = contactJson.getString("contactNo");
|
|
|
- switch (contactJson.getString("type")) {
|
|
|
- case "mobile":
|
|
|
- xCU.setTel(contactJson.getLong("contactNo"));//客户联系人电话
|
|
|
- break;
|
|
|
- case "qq":
|
|
|
- xCU.setQq(contactNo);//客户联系人QQ
|
|
|
- break;
|
|
|
- case "LinkedIn":
|
|
|
- xCU.setLinkedin(contactNo);//客户联系人LinkedIn
|
|
|
- break;
|
|
|
- case "Skype":
|
|
|
- xCU.setSkype(contactNo);//客户联系人Skype
|
|
|
- break;
|
|
|
- case "wa":
|
|
|
- xCU.setWhatsapp(contactNo);//客户联系人Whatsapp
|
|
|
- break;
|
|
|
- case "Facebook":
|
|
|
- xCU.setFacebook(contactNo);//客户联系人Facebook
|
|
|
- break;
|
|
|
- case "wechat":
|
|
|
- xCU.setWechat(contactNo);//客户联系人Wechat
|
|
|
- break;
|
|
|
- case "twitter":
|
|
|
- xCU.setTwitter(contactNo);//客户联系人Twitter
|
|
|
- break;
|
|
|
- }
|
|
|
+ xCU.put(contactJson.getString("type"), contactJson.getString("contactNo"));
|
|
|
}
|
|
|
-
|
|
|
xiaomanCustomerUserList.add(xCU);
|
|
|
+
|
|
|
+// XiaomanUpdateInfoVO.Customer xCU = new XiaomanUpdateInfoVO.Customer();
|
|
|
+// xCU.setName(cu.getName());//联系人名称
|
|
|
+// xCU.setEmail(cu.getEmail());//客户简称
|
|
|
+// xCU.setRemark(dto.getRemark());//客户联系人备注
|
|
|
+// xCU.setTelAreaCode(Long.parseLong(dto.getTelAreaCode())); //客户联系人电话区号
|
|
|
+//
|
|
|
+// //更多联系方式
|
|
|
+// for (int i = 0; i < contactJsonArr.size(); i++) {
|
|
|
+// JSONObject contactJson = contactJsonArr.getJSONObject(i);
|
|
|
+// String contactNo = contactJson.getString("contactNo");
|
|
|
+// switch (contactJson.getString("type")) {
|
|
|
+// case "mobile":
|
|
|
+// xCU.setTel(contactJson.getLong("contactNo"));//客户联系人电话
|
|
|
+// break;
|
|
|
+// case "qq":
|
|
|
+// xCU.setQq(contactNo);//客户联系人QQ
|
|
|
+// break;
|
|
|
+// case "LinkedIn":
|
|
|
+// xCU.setLinkedin(contactNo);//客户联系人LinkedIn
|
|
|
+// break;
|
|
|
+// case "Skype":
|
|
|
+// xCU.setSkype(contactNo);//客户联系人Skype
|
|
|
+// break;
|
|
|
+// case "wa":
|
|
|
+// xCU.setWhatsapp(contactNo);//客户联系人Whatsapp
|
|
|
+// break;
|
|
|
+// case "Facebook":
|
|
|
+// xCU.setFacebook(contactNo);//客户联系人Facebook
|
|
|
+// break;
|
|
|
+// case "wechat":
|
|
|
+// xCU.setWechat(contactNo);//客户联系人Wechat
|
|
|
+// break;
|
|
|
+// case "twitter":
|
|
|
+// xCU.setTwitter(contactNo);//客户联系人Twitter
|
|
|
+// break;
|
|
|
+// }
|
|
|
+// }
|
|
|
+// xiaomanCustomerUserList.add(xCU);
|
|
|
}
|
|
|
//=========================
|
|
|
xVo.setCompanyId(dto.getCompanyId());//公司客户ID (创建时无需设置,更新时需要设置)
|
|
@@ -414,16 +411,16 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
xVo.setName(dto.getName());//客户名称
|
|
|
xVo.setShortName(dto.getShortName());//客户简称
|
|
|
xVo.setHomepage(dto.getHomepage());//网站主页
|
|
|
- xVo.setFax(Long.parseLong(dto.getFax()));//传真
|
|
|
- xVo.setTelAreaCode(Long.parseLong(dto.getTelAreaCode()));//客户电话区号
|
|
|
- xVo.setTel(Long.parseLong(dto.getTel()));//客户电话
|
|
|
+ xVo.setFax(ObjectUtil.isEmpty(dto.getFax()) ? null : Long.parseLong(dto.getFax()));//传真
|
|
|
+ xVo.setTelAreaCode(ObjectUtil.isEmpty(dto.getTelAreaCode()) ? null : Long.parseLong(dto.getTelAreaCode()));//客户电话区号
|
|
|
+ xVo.setTel(ObjectUtil.isEmpty(dto.getTel()) ? null : Long.parseLong(dto.getTel()));//客户电话
|
|
|
xVo.setAddress(dto.getAddress());//地址
|
|
|
xVo.setRemark(dto.getRemark());//备注
|
|
|
xVo.setCustomers(xiaomanCustomerUserList);//客户联系人
|
|
|
//客户来源ID
|
|
|
List<Long> originList = Arrays.stream(dto.getSource().split(",")).map(Long::valueOf).collect(Collectors.toList());
|
|
|
xVo.setOriginList(originList);
|
|
|
- xVo.setTrailStatus(Long.parseLong(dto.getStatus()));//客户状态ID
|
|
|
+ xVo.setTrailStatus(ObjectUtil.isEmpty(dto.getStatus()) ? null : Long.parseLong(dto.getStatus()));//客户状态ID
|
|
|
//=========================
|
|
|
|
|
|
updateXiaomanData(xVo);
|