|
@@ -5,14 +5,16 @@ 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.controller.admin.auth.vo.AuthOaLoginReqVO;
|
|
|
import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
import cn.iocoder.yudao.module.system.oa.SslSkippingRestTemplate;
|
|
|
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
|
|
import cn.iocoder.yudao.module.system.service.auth.AdminAuthService;
|
|
|
|
|
+import cn.iocoder.yudao.server.dal.dataobject.SrmNoticeDO;
|
|
|
|
|
+import cn.iocoder.yudao.server.dal.mysql.SrmNoticeMapper;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.google.common.collect.ImmutableMap;
|
|
import com.google.common.collect.ImmutableMap;
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
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.http.*;
|
|
|
import org.springframework.stereotype.Component;
|
|
import org.springframework.stereotype.Component;
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
import org.springframework.util.MultiValueMap;
|
|
import org.springframework.util.MultiValueMap;
|
|
@@ -20,10 +22,9 @@ import org.springframework.web.client.RestClientException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
-import java.util.LinkedHashMap;
|
|
|
|
|
-import java.util.Map;
|
|
|
|
|
-import java.util.Objects;
|
|
|
|
|
|
|
+import java.time.Instant;
|
|
|
|
|
+import java.util.*;
|
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@Component
|
|
@Component
|
|
|
public class SrmRest {
|
|
public class SrmRest {
|
|
@@ -31,8 +32,12 @@ public class SrmRest {
|
|
|
private String srmTodoUrl;
|
|
private String srmTodoUrl;
|
|
|
@Value("${srm.done}")
|
|
@Value("${srm.done}")
|
|
|
private String srmDoneUrl;
|
|
private String srmDoneUrl;
|
|
|
|
|
+ @Value("${srm.notice}")
|
|
|
|
|
+ private String srmNoticeUrl;
|
|
|
@Resource
|
|
@Resource
|
|
|
private AdminAuthService authService;
|
|
private AdminAuthService authService;
|
|
|
|
|
+ @Autowired
|
|
|
|
|
+ private SrmNoticeMapper srmNoticeMapper;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取SRM的待办及已办的数量
|
|
* 获取SRM的待办及已办的数量
|
|
@@ -75,6 +80,7 @@ public class SrmRest {
|
|
|
}
|
|
}
|
|
|
System.out.println("result srm todo:" + todoStr);
|
|
System.out.println("result srm todo:" + todoStr);
|
|
|
JSONArray todoList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(todoStr).get("content")));
|
|
JSONArray todoList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(todoStr).get("content")));
|
|
|
|
|
+ Integer todoTotalElements = Integer.valueOf(JSON.toJSONString(JSON.parseObject(todoStr).get("totalElements")));
|
|
|
|
|
|
|
|
//待办消息处理
|
|
//待办消息处理
|
|
|
Map<String, Object> doneRequestBody = new LinkedHashMap<>();
|
|
Map<String, Object> doneRequestBody = new LinkedHashMap<>();
|
|
@@ -89,10 +95,88 @@ public class SrmRest {
|
|
|
String doneStr = restTemplate.postForObject(srmDoneUrl, requestEntitydone, String.class);
|
|
String doneStr = restTemplate.postForObject(srmDoneUrl, requestEntitydone, String.class);
|
|
|
System.out.println("result srm done:" + doneStr);
|
|
System.out.println("result srm done:" + doneStr);
|
|
|
JSONArray doneList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(doneStr).get("content")));
|
|
JSONArray doneList = JSON.parseArray(JSON.toJSONString(JSON.parseObject(doneStr).get("content")));
|
|
|
|
|
+ Integer doneTotalElements = Integer.valueOf(JSON.toJSONString(JSON.parseObject(doneStr).get("totalElements")));
|
|
|
//已办消息处理
|
|
//已办消息处理
|
|
|
- return ImmutableMap.of("todoList", todoList, "doneList", doneList,"todoCount", doneList.size(),"doneCount", doneList.size());
|
|
|
|
|
|
|
+ return ImmutableMap.of("todoList", todoList, "doneList", doneList,"todoCount", todoTotalElements,"doneCount", doneTotalElements);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
|
+ String date1 = "2026-04-30T20:00:00.209Z";
|
|
|
|
|
+ String date2 = "2025-12-25T12:00:00.000Z";
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 转成时间戳
|
|
|
|
|
+ Instant instant1 = Instant.parse(date1);
|
|
|
|
|
+ Instant instant2 = Instant.parse(date2);
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 比较大小
|
|
|
|
|
+ if (instant1.isAfter(instant2)) {
|
|
|
|
|
+ System.out.println("date1 比 date2 晚");
|
|
|
|
|
+ } else if (instant1.isBefore(instant2)) {
|
|
|
|
|
+ System.out.println("date1 比 date2 早");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ System.out.println("两个时间一样");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ public List getSrmNotice(String workcode, SrmNoticeDO srmNoticeDO) {
|
|
|
|
|
+ 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", 1000);
|
|
|
|
|
+ requestBody.put("page", 0);
|
|
|
|
|
+ requestBody.put("sort", "createdDate,DESC");
|
|
|
|
|
+ requestBody.put("propertyNames", "readStatus");
|
|
|
|
|
+ requestBody.put("propertyValues", 0);
|
|
|
|
|
+ System.out.println("==============================" + JSON.toJSONString(requestBody));
|
|
|
|
|
+ HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers);
|
|
|
|
|
+ RestTemplate restTemplate = SslSkippingRestTemplate.createRestTemplate();
|
|
|
|
|
+ String todoStr = null;
|
|
|
|
|
+ try {
|
|
|
|
|
+ ResponseEntity<String> exchange = restTemplate.exchange(srmNoticeUrl, HttpMethod.GET, requestEntity, String.class);
|
|
|
|
|
+ todoStr = exchange.getBody();
|
|
|
|
|
+ List<JSONObject> jsonObjects = JSON.parseArray(todoStr, JSONObject.class);
|
|
|
|
|
+ if (Objects.isNull(jsonObjects)){
|
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
|
+ }
|
|
|
|
|
+ List<JSONObject> needInsert = jsonObjects.stream().filter(e -> {
|
|
|
|
|
+ String createdDate = JSON.toJSONString(e.get("createdDate"));
|
|
|
|
|
+ if (StringUtils.isBlank(createdDate)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+ Instant instant1 = Instant.parse(createdDate);
|
|
|
|
|
+ Instant instant2 = Instant.parse(srmNoticeDO.getSrmCreateTime());
|
|
|
|
|
+ return instant1.isAfter(instant2);
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ List<SrmNoticeDO> collect = needInsert.stream().map(f -> {
|
|
|
|
|
+ SrmNoticeDO srmNoticeDO1 = new SrmNoticeDO();
|
|
|
|
|
+ srmNoticeDO1.setDeleted(false);
|
|
|
|
|
+ srmNoticeDO1.setSrmCreateTime(String.valueOf(f.get("createdDate")));
|
|
|
|
|
+ srmNoticeDO1.setSrmCreator(String.valueOf(f.get("userId")));
|
|
|
|
|
+ JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(f.get("information")));
|
|
|
|
|
+ srmNoticeDO1.setTitle(jsonObject.getString("title"));
|
|
|
|
|
+ srmNoticeDO1.setContent(jsonObject.getString("content"));
|
|
|
|
|
+ srmNoticeDO1.setReadStatus("0");
|
|
|
|
|
+ srmNoticeDO1.setImgUrl(jsonObject.getString("imgUrl"));
|
|
|
|
|
+ srmNoticeDO1.setReqUrl(jsonObject.getString("reqUrl"));
|
|
|
|
|
+ return srmNoticeDO1;
|
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
|
+ srmNoticeMapper.insertBatch(collect);
|
|
|
|
|
+ return collect;
|
|
|
|
|
+ } catch (RestClientException e) {
|
|
|
|
|
+ throw new RuntimeException(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
}
|
|
}
|