|
@@ -14,6 +14,8 @@ import com.baomidou.dynamic.datasource.annotation.DSTransactional;
|
|
|
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
|
|
import com.fjhx.common.constant.SourceConstant;
|
|
|
import com.fjhx.customer.contants.XiaomanContant;
|
|
|
+import com.fjhx.customer.entity.customer.dto.CustomerDto;
|
|
|
+import com.fjhx.customer.entity.customer.po.CustomerUser;
|
|
|
import com.fjhx.customer.entity.xiaoman.dto.XiaomanCustomerSelectDto;
|
|
|
import com.fjhx.customer.entity.xiaoman.po.XiaomanConfig;
|
|
|
import com.fjhx.customer.entity.xiaoman.vo.CustomerListApiVo;
|
|
@@ -50,14 +52,28 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
@Resource
|
|
|
DictTenantDataService dictTenantDataService;
|
|
|
|
|
|
-// @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() {
|
|
|
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 {
|
|
@@ -88,12 +104,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) {
|
|
@@ -106,15 +123,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<>();
|
|
@@ -123,15 +140,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();
|
|
@@ -159,14 +176,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
|
|
|
*/
|
|
@@ -185,11 +215,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);
|
|
@@ -198,49 +228,24 @@ 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");
|
|
@@ -254,22 +259,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++) {
|
|
@@ -277,7 +266,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);
|
|
@@ -285,13 +274,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);
|
|
|
}
|
|
|
}
|
|
@@ -303,7 +292,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);
|
|
@@ -311,19 +300,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) {
|
|
|
|
|
|
DictTenantData dictTenantData = new DictTenantData();
|
|
|
dictTenantData.setDictCode("customer_tag");
|
|
@@ -334,4 +323,84 @@ public class XiaomanApiServiceImpl implements XiaomanApiService {
|
|
|
dictTenantDataService.save(dictTenantData);
|
|
|
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 推送客户数据到小满
|
|
|
+ */
|
|
|
+ @DSTransactional
|
|
|
+ @Override
|
|
|
+ public void updateXiaomanData(CustomerDto dto) {
|
|
|
+ if (ObjectUtil.isEmpty(dto.getCompanyId())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ XiaomanUpdateInfoVO xVo = new XiaomanUpdateInfoVO();
|
|
|
+ List<XiaomanUpdateInfoVO.Customer> xiaomanCustomerUserList = new ArrayList<>();
|
|
|
+
|
|
|
+ //=========================
|
|
|
+ List<CustomerUser> customerUserList = dto.getCustomerUserList();
|
|
|
+ for (CustomerUser cu : customerUserList) {
|
|
|
+ String contactJsonStr = cu.getContactJson();
|
|
|
+ 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())); //客户联系人电话区号
|
|
|
+
|
|
|
+ //更多联系方式
|
|
|
+ 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 (创建时无需设置,更新时需要设置)
|
|
|
+ xVo.setSerialId(dto.getCustomerCode());//客户编号id->客户表customer_code
|
|
|
+ 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.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
|
|
|
+ //=========================
|
|
|
+
|
|
|
+ updateXiaomanData(xVo);
|
|
|
+ }
|
|
|
}
|