|
@@ -13,6 +13,7 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
import lombok.Data;
|
|
import lombok.Data;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.http.HttpEntity;
|
|
import org.springframework.http.HttpEntity;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpMethod;
|
|
import org.springframework.http.HttpMethod;
|
|
@@ -21,10 +22,7 @@ import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.Comparator;
|
|
|
|
|
-import java.util.List;
|
|
|
|
|
-import java.util.Set;
|
|
|
|
|
|
|
+import java.util.*;
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -72,7 +70,7 @@ public class CrmRest {
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/data/v2/query?" +
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/data/v2/query?" +
|
|
|
- "q=select id,name,unionId,phone,personalEmail from user where unionId is not null",
|
|
|
|
|
|
|
+ "q=select id,name,unionId,phone,personalEmail from user where unionId is not null limit 0,300",
|
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
|
String body = exchange.getBody();
|
|
String body = exchange.getBody();
|
|
|
String result = JSON.parseObject(body).getString("result");
|
|
String result = JSON.parseObject(body).getString("result");
|
|
@@ -110,15 +108,58 @@ public class CrmRest {
|
|
|
return userId.get();
|
|
return userId.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ public void querySqlUserJob(String token) {
|
|
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
+ headers.add("Authorization", token);
|
|
|
|
|
+ HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
|
|
+ ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/data/v2/query?" +
|
|
|
|
|
+ "q=select id,name,unionId,phone,personalEmail from user where unionId is not null limit 0,300",
|
|
|
|
|
+ HttpMethod.GET, requestEntity, String.class);
|
|
|
|
|
+ String body = exchange.getBody();
|
|
|
|
|
+ String result = JSON.parseObject(body).getString("result");
|
|
|
|
|
+ String records = JSON.parseObject(result).getJSONArray("records").toJSONString();
|
|
|
|
|
+
|
|
|
|
|
+ List<CrmUser> crmUsers = JSON.parseArray(records, CrmUser.class);
|
|
|
|
|
+ List<CrmPersonDO> crmPersonDOS = crmPersonMapper.selectList();
|
|
|
|
|
+ Set<String> existIds = crmPersonDOS.stream()
|
|
|
|
|
+ .map(CrmPersonDO::getCrmUserId)
|
|
|
|
|
+ .collect(Collectors.toSet());
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //插入自己的数据库,保存crm人员信息
|
|
|
|
|
+ List<CrmUser> needInsertUsers = crmUsers.stream()
|
|
|
|
|
+ .filter(user -> !existIds.contains(user.getId()))
|
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
|
+ List<CrmPersonDO> collect = needInsertUsers.stream().map(e -> {
|
|
|
|
|
+ CrmPersonDO crmPersonDO = new CrmPersonDO();
|
|
|
|
|
+ crmPersonDO.setCrmUserId(e.getId());
|
|
|
|
|
+ crmPersonDO.setCrmUserName(e.getName());
|
|
|
|
|
+ crmPersonDO.setCrmUserPhone(e.getPhone());
|
|
|
|
|
+ crmPersonDO.setCrmUserMail(e.getPersonalEmail());
|
|
|
|
|
+ crmPersonDO.setCrmUserUnionid(e.getUnionId());
|
|
|
|
|
+ crmPersonDO.setDeleted(false);
|
|
|
|
|
+ return crmPersonDO;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ crmPersonMapper.insertBatch(collect);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public ImmutableMap<String, Object> getCrmTodoList(String token, String crmUserId, String type, Integer pageSize, Integer pageNo) {
|
|
public ImmutableMap<String, Object> getCrmTodoList(String token, String crmUserId, String type, Integer pageSize, Integer pageNo) {
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.add("Authorization", token);
|
|
headers.add("Authorization", token);
|
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(headers);
|
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/data/v2.0/creekflow/task/filter?assigneeIds="+crmUserId+"&status="+type+"&pageNum="+pageNo+"&pageSize="+pageSize, HttpMethod.GET, requestEntity, String.class);
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/data/v2.0/creekflow/task/filter?assigneeIds="+crmUserId+"&status="+type+"&pageNum="+pageNo+"&pageSize="+pageSize, HttpMethod.GET, requestEntity, String.class);
|
|
|
- String body = exchange.getBody();
|
|
|
|
|
- String data = JSON.parseObject(body).getString("data");
|
|
|
|
|
- String records = JSON.parseObject(data).getJSONArray("records").toJSONString();
|
|
|
|
|
|
|
+ String data = null;
|
|
|
|
|
+ String records = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ String body = exchange.getBody();
|
|
|
|
|
+ data = JSON.parseObject(body).getString("data");
|
|
|
|
|
+ records = JSON.parseObject(data).getJSONArray("records").toJSONString();
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return ImmutableMap.of("todoCount", 0,"todoList", new ArrayList<>());
|
|
|
|
|
+ }
|
|
|
List<CrmTodoVo> crmTodoVos = JSON.parseArray(records, CrmTodoVo.class);
|
|
List<CrmTodoVo> crmTodoVos = JSON.parseArray(records, CrmTodoVo.class);
|
|
|
Integer dataCount = JSON.parseObject(data).getInteger("dataCount");
|
|
Integer dataCount = JSON.parseObject(data).getInteger("dataCount");
|
|
|
List<CrmPersonDO> crmPersonDOS = crmPersonMapper.selectList();
|
|
List<CrmPersonDO> crmPersonDOS = crmPersonMapper.selectList();
|
|
@@ -137,9 +178,14 @@ public class CrmRest {
|
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/notice/v2.0/notice/actions/list?userId="+crmUserId+"&pageNo=1&pageSize=1000",
|
|
ResponseEntity<String> exchange = restTemplate.exchange("https://api-tencent.xiaoshouyi.com/rest/notice/v2.0/notice/actions/list?userId="+crmUserId+"&pageNo=1&pageSize=1000",
|
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
|
- String body = exchange.getBody();
|
|
|
|
|
- String data = JSON.parseObject(body).getString("result");
|
|
|
|
|
- JSONArray objects = JSON.parseArray(data);
|
|
|
|
|
|
|
+ JSONArray objects = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ String body = exchange.getBody();
|
|
|
|
|
+ String data = JSON.parseObject(body).getString("result");
|
|
|
|
|
+ objects = JSON.parseArray(data);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ return new ArrayList();
|
|
|
|
|
+ }
|
|
|
if (CollUtil.isEmpty(objects)) {return new ArrayList<>();}
|
|
if (CollUtil.isEmpty(objects)) {return new ArrayList<>();}
|
|
|
String data1 = JSON.parseObject(objects.get(0).toString()).getString("data");
|
|
String data1 = JSON.parseObject(objects.get(0).toString()).getString("data");
|
|
|
String records = JSON.parseObject(data1).getJSONArray("records").toJSONString();
|
|
String records = JSON.parseObject(data1).getJSONArray("records").toJSONString();
|