|
@@ -0,0 +1,103 @@
|
|
|
+package com.management.platform.util;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.fasterxml.jackson.databind.DeserializationFeature;
|
|
|
+import com.fasterxml.jackson.databind.MapperFeature;
|
|
|
+import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
|
|
+import com.management.platform.entity.FeishuInfo;
|
|
|
+import org.apache.http.client.entity.UrlEncodedFormEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.message.BasicNameValuePair;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.http.*;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.math.BigInteger;
|
|
|
+import java.security.MessageDigest;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.sql.Timestamp;
|
|
|
+import java.time.LocalDateTime;
|
|
|
+import java.time.format.DateTimeFormatter;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+public class BeiSenUtils {
|
|
|
+ static String port="10.1.10.41:20170";
|
|
|
+
|
|
|
+ public static void main(String[] args) {
|
|
|
+ BeiSenUtils dockWithMLD=new BeiSenUtils();
|
|
|
+ JSONObject jsonObject=new JSONObject();
|
|
|
+ LocalDateTime startDate=LocalDateTime.parse("2022-08-01 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ LocalDateTime endDate=LocalDateTime.parse("2022-08-31 00:00:00",DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
|
|
+ jsonObject.put("startDate",startDate);
|
|
|
+ jsonObject.put("endDate",endDate);
|
|
|
+ String jsonString = jsonObject.toJSONString();
|
|
|
+// dockWithMLD.getResult("http://"+port+"/api/cube/restful/interface/getModeDataPageList/getTravelRecord",jsonString);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static String getToken(){
|
|
|
+ String result="";
|
|
|
+ String url = "https://openapi.italent.cn/token";
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ JSONObject requestMap = new JSONObject();
|
|
|
+ requestMap.put("grant_type","client_credentials");
|
|
|
+ requestMap.put("app_key","94DC8A7C7D3146FD9ECA8641208D7A2D");
|
|
|
+ requestMap.put("app_secret","FAC17C75768B4160A3D0C5250629AD92B5AF0AF70B824809BFBD20F1A6C9CF88");
|
|
|
+ HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
+ ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+ if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp = ResponseEntity.getBody();
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
+ result=respJson.getString("access_token");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static List<JSONArray> getByTimeWindow(String scrollId,String startTime,String stopTime){
|
|
|
+ List<JSONArray> resultList=new ArrayList<>();
|
|
|
+ String url = "https://openapi.italent.cn/TenantBaseExternal/api/v5/Employee/GetByTimeWindow";
|
|
|
+ HttpHeaders headers = new HttpHeaders();
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
|
|
|
+ headers.setContentType(type);
|
|
|
+ String accessToken = getToken();
|
|
|
+ System.out.println("--------Bearer TOKEN--------"+accessToken);
|
|
|
+ headers.add("Authorization","Bearer "+accessToken);
|
|
|
+ JSONObject requestMap = new JSONObject();
|
|
|
+ requestMap.put("timeWindowQueryType",1);
|
|
|
+ requestMap.put("startTime",startTime+"T00:00:00");
|
|
|
+ requestMap.put("stopTime",stopTime+"T23:59:59");
|
|
|
+ System.out.println("--------headers请求头数据-------"+headers);
|
|
|
+ System.out.println("--------requestMap请求参数-------"+requestMap);
|
|
|
+ if(!StringUtils.isEmpty(scrollId)){
|
|
|
+ requestMap.put("scrollId",scrollId);
|
|
|
+ }
|
|
|
+ HttpEntity<JSONObject> entity = new HttpEntity<>(requestMap, headers);
|
|
|
+ ResponseEntity<String> ResponseEntity = restTemplate.postForEntity(url, entity, String.class);
|
|
|
+ if (ResponseEntity.getStatusCode() == HttpStatus.OK) {
|
|
|
+ String resp= ResponseEntity.getBody();
|
|
|
+ JSONObject respJson = JSONObject.parseObject(resp);
|
|
|
+ if(respJson.getIntValue("code")==200){
|
|
|
+ resultList.add(respJson.getJSONArray("data"));
|
|
|
+ String nextScrollId = respJson.getString("scrollId");
|
|
|
+ if(!StringUtils.isEmpty(nextScrollId)&&respJson.getJSONArray("data").size()>0){
|
|
|
+ List<JSONArray> byTimeWindow = getByTimeWindow(nextScrollId,startTime,stopTime);
|
|
|
+ resultList.addAll(byTimeWindow);
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return resultList;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|