|
@@ -1,7 +1,13 @@
|
|
|
package cn.iocoder.yudao.server.rest;
|
|
package cn.iocoder.yudao.server.rest;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
+import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
|
|
|
+import cn.iocoder.yudao.server.controller.admin.vo.crm.CrmTodoVo;
|
|
|
|
|
+import cn.iocoder.yudao.server.dal.dataobject.CrmNoticeDO;
|
|
|
|
|
+import cn.iocoder.yudao.server.dal.mysql.CrmNoticeMapper;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
+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;
|
|
@@ -13,9 +19,9 @@ 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 javax.annotation.Resource;
|
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.util.concurrent.CompletableFuture;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
@@ -23,6 +29,11 @@ public class CrmRest {
|
|
|
private static final String CLIENT_ID = "baca57533e1909447a6f1918cad00bc2";
|
|
private static final String CLIENT_ID = "baca57533e1909447a6f1918cad00bc2";
|
|
|
private static final String CLIENT_SECRET = "d38fcf6dcb0f754cece55862b1ae77b3";
|
|
private static final String CLIENT_SECRET = "d38fcf6dcb0f754cece55862b1ae77b3";
|
|
|
private static final String REDIRECT_URI = "https://api-tencent.xiaoshouyi.com/";
|
|
private static final String REDIRECT_URI = "https://api-tencent.xiaoshouyi.com/";
|
|
|
|
|
+ private final CrmNoticeMapper crmNoticeMapper;
|
|
|
|
|
+
|
|
|
|
|
+ public CrmRest(CrmNoticeMapper crmNoticeMapper) {
|
|
|
|
|
+ this.crmNoticeMapper = crmNoticeMapper;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 刷新token
|
|
* 刷新token
|
|
@@ -48,26 +59,77 @@ public class CrmRest {
|
|
|
* @param token
|
|
* @param token
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public String querySqlUser(String token, String workcode) {
|
|
|
|
|
|
|
+ public String querySqlUser(String token, String dingUserId) {
|
|
|
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/query?q=select id,name,unionId,phone,personalEmail from userselect id,name,unionId,phone,personalEmail from user",
|
|
|
|
|
|
|
+ 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",
|
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
HttpMethod.GET, requestEntity, String.class);
|
|
|
String body = exchange.getBody();
|
|
String body = exchange.getBody();
|
|
|
- List<CrmUser> crmUsers = JSON.parseArray(body, CrmUser.class);
|
|
|
|
|
|
|
+ String result = JSON.parseObject(body).getString("result");
|
|
|
|
|
+ String records = JSON.parseObject(result).getJSONArray("records").toJSONString();
|
|
|
|
|
+
|
|
|
|
|
+ List<CrmUser> crmUsers = JSON.parseArray(records, CrmUser.class);
|
|
|
AtomicReference<String> userId = new AtomicReference<>("");
|
|
AtomicReference<String> userId = new AtomicReference<>("");
|
|
|
if (crmUsers != null) {
|
|
if (crmUsers != null) {
|
|
|
- crmUsers.stream().filter(e -> e.getUnionId().equals(workcode)).findAny().ifPresent(f ->{
|
|
|
|
|
|
|
+ crmUsers.stream().filter(e -> e.getUnionId().equals(dingUserId)).findAny().ifPresent(f ->{
|
|
|
userId.set(f.getId());
|
|
userId.set(f.getId());
|
|
|
});
|
|
});
|
|
|
}
|
|
}
|
|
|
return userId.get();
|
|
return userId.get();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public ImmutableMap<String, Object> getCrmTodoList(String token, String crmUserId) {
|
|
|
|
|
+ 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.0/creekflow/task/filter?assigneeIds="+crmUserId+"&status=pending&pageNo=1&pageSize=1000",
|
|
|
|
|
+ HttpMethod.GET, requestEntity, String.class);
|
|
|
|
|
+ String body = exchange.getBody();
|
|
|
|
|
+ String data = JSON.parseObject(body).getString("data");
|
|
|
|
|
+ String records = JSON.parseObject(data).getJSONArray("records").toJSONString();
|
|
|
|
|
+ List<CrmTodoVo> crmTodoVos = JSON.parseArray(records, CrmTodoVo.class);
|
|
|
|
|
+ Integer dataCount = JSON.parseObject(data).getInteger("dataCount");
|
|
|
|
|
+
|
|
|
|
|
+ return ImmutableMap.of("todoCount", dataCount,"todoList", crmTodoVos);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ public List getCrmNotice(String token, String crmUserId, String workcode) {
|
|
|
|
|
+ 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/notice/v2.0/notice/actions/list?userId="+crmUserId+"&pageNo=1&pageSize=1000",
|
|
|
|
|
+ HttpMethod.GET, requestEntity, String.class);
|
|
|
|
|
+ String body = exchange.getBody();
|
|
|
|
|
+ String data = JSON.parseObject(body).getString("result");
|
|
|
|
|
+ JSONArray objects = JSON.parseArray(data);
|
|
|
|
|
+ if (CollUtil.isEmpty(objects)) {return new ArrayList<>();}
|
|
|
|
|
+ String data1 = JSON.parseObject(objects.get(0).toString()).getString("data");
|
|
|
|
|
+ String records = JSON.parseObject(data1).getJSONArray("records").toJSONString();
|
|
|
|
|
+ List<CrmNotice> crmNotices = JSON.parseArray(records, CrmNotice.class);
|
|
|
|
|
|
|
|
|
|
+ //todo 异步逻辑处理
|
|
|
|
|
+// CompletableFuture.runAsync(()->{
|
|
|
|
|
+ //先删除
|
|
|
|
|
+ crmNoticeMapper.deleteByMap(ImmutableMap.of("work_code",workcode));
|
|
|
|
|
+ //再添加到消息表里面
|
|
|
|
|
+ crmNotices.forEach(e ->{
|
|
|
|
|
+ CrmNoticeDO crmNoticeDO = new CrmNoticeDO();
|
|
|
|
|
+ CrmNoticeDetail notice = e.getNotice();
|
|
|
|
|
+ BeanUtils.copyProperties(notice,crmNoticeDO);
|
|
|
|
|
+ crmNoticeDO.setContentMajor(e.getContent());
|
|
|
|
|
+ crmNoticeDO.setDeleted(false);
|
|
|
|
|
+ crmNoticeDO.setWorkCode(workcode);
|
|
|
|
|
+ crmNoticeMapper.insert(crmNoticeDO);
|
|
|
|
|
+ });
|
|
|
|
|
+// });
|
|
|
|
|
|
|
|
|
|
+ return crmNotices;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
@Data
|
|
@Data
|
|
|
static class CrmUser{
|
|
static class CrmUser{
|
|
@@ -77,4 +139,26 @@ public class CrmRest {
|
|
|
private String phone;
|
|
private String phone;
|
|
|
private String personalEmail;
|
|
private String personalEmail;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Data
|
|
|
|
|
+ static class CrmNotice{
|
|
|
|
|
+ private String content;
|
|
|
|
|
+ private CrmNoticeDetail notice;
|
|
|
|
|
+ }
|
|
|
|
|
+ @Data
|
|
|
|
|
+ static class CrmNoticeDetail {
|
|
|
|
|
+ private Long sourceId;
|
|
|
|
|
+ private int typeFlg;
|
|
|
|
|
+ private String systemId;
|
|
|
|
|
+ private Long targetId;
|
|
|
|
|
+ private Long operateId;
|
|
|
|
|
+ private int noticeType;
|
|
|
|
|
+ private String content;
|
|
|
|
|
+ private Long createdAt;
|
|
|
|
|
+ private int appType;
|
|
|
|
|
+ private Long tenantId;
|
|
|
|
|
+ private Long beLongId;
|
|
|
|
|
+ private Long id;
|
|
|
|
|
+ private int status;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|