|
|
@@ -0,0 +1,91 @@
|
|
|
+package cn.iocoder.yudao.server.rest;
|
|
|
+
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
|
|
|
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
|
|
|
+import cn.iocoder.yudao.module.system.controller.admin.auth.vo.AuthOaLoginReqVO;
|
|
|
+import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
|
+import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.google.common.collect.ImmutableMap;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.util.LinkedMultiValueMap;
|
|
|
+import org.springframework.util.MultiValueMap;
|
|
|
+import org.springframework.web.client.RestClientException;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import javax.annotation.Resource;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+
|
|
|
+@Component
|
|
|
+public class SrmRest {
|
|
|
+ @Value("${srm.todo}")
|
|
|
+ private String srmTodoUrl;
|
|
|
+ @Value("${srm.done}")
|
|
|
+ private String srmDoneUrl;
|
|
|
+ @Resource
|
|
|
+ private AdminAuthService authService;
|
|
|
+
|
|
|
+ public ImmutableMap<String, Object> getSrmToDoList(String workcode, Integer pageNo, Integer pageSize) {
|
|
|
+ AuthOaLoginReqVO reqVO = new AuthOaLoginReqVO();
|
|
|
+ reqVO.setUsername(workcode);
|
|
|
+ String tokenStr = authService.srmSsoToken(reqVO);
|
|
|
+ String token = String.valueOf(JSON.parseObject(tokenStr).get("msg"));
|
|
|
+ if (Objects.isNull(token)||"null".equals(token)){
|
|
|
+ throw new ServiceException(new ErrorCode(3,"srm获取token异常"));
|
|
|
+ }
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ headers.set("Authorization", "Bearer "+token);
|
|
|
+ headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+
|
|
|
+
|
|
|
+ // 2. 创建请求体参数
|
|
|
+ Map<String, Object> requestBody = new LinkedHashMap<>();
|
|
|
+
|
|
|
+ requestBody.put("size", pageSize);
|
|
|
+ requestBody.put("number", pageNo-1);
|
|
|
+ requestBody.put("debugFlag", true);
|
|
|
+ requestBody.put("direction", "DESC");
|
|
|
+ requestBody.put("fromClientType", "PC");
|
|
|
+ requestBody.put("ignoreField", true);
|
|
|
+ requestBody.put("property", "lastModifiedDate");
|
|
|
+ System.out.println("==============================" + JSON.toJSONString(requestBody));
|
|
|
+ HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
+ String todoStr = null;
|
|
|
+ try {
|
|
|
+ todoStr = restTemplate.postForObject(srmTodoUrl, requestEntity, String.class);
|
|
|
+ } catch (RestClientException e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ System.out.println("result srm todo:" + todoStr);
|
|
|
+ JSONArray todoList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(todoStr).get("content")));
|
|
|
+
|
|
|
+ //待办消息处理
|
|
|
+ Map<String, Object> doneRequestBody = new LinkedHashMap<>();
|
|
|
+ doneRequestBody.put("size", pageSize);
|
|
|
+ doneRequestBody.put("number", pageNo-1);
|
|
|
+ doneRequestBody.put("debugFlag", true);
|
|
|
+ doneRequestBody.put("direction", "DESC");
|
|
|
+ doneRequestBody.put("fromClientType", "PC");
|
|
|
+ doneRequestBody.put("ignoreField", true);
|
|
|
+ doneRequestBody.put("property", "lastModifiedDate");
|
|
|
+ HttpEntity<Map<String, Object>> requestEntitydone = new HttpEntity<>(doneRequestBody, headers);
|
|
|
+ String doneStr = restTemplate.postForObject(srmDoneUrl, requestEntitydone, String.class);
|
|
|
+ System.out.println("result srm done:" + doneStr);
|
|
|
+ JSONArray doneList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(doneStr).get("content")));
|
|
|
+ //已办消息处理
|
|
|
+ return ImmutableMap.of("todoList", todoList, "doneList", doneList,"todoCount", doneList.size(),"doneCount", doneList.size());
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|