|
@@ -3,12 +3,22 @@ package org.springblade.dingding.service.impl;
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.nacos.shaded.com.google.gson.JsonElement;
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.JsonObject;
|
|
|
import com.alibaba.nacos.shaded.com.google.gson.JsonParser;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpGet;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
import org.springblade.core.log.exception.ServiceException;
|
|
|
import org.springblade.dingding.service.MeetingService;
|
|
|
+import org.springblade.dingding.vo.MeetingSchedule;
|
|
|
import org.springblade.dingding.vo.MeetingVo;
|
|
|
+import org.springblade.dingding.vo.ScheduleItem;
|
|
|
import org.springframework.http.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.HttpClientErrorException;
|
|
@@ -16,15 +26,17 @@ import org.springframework.web.client.HttpServerErrorException;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
import org.springframework.web.util.UriComponentsBuilder;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URI;
|
|
|
+import java.net.URISyntaxException;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.LocalTime;
|
|
|
import java.time.ZoneId;
|
|
|
import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.time.format.TextStyle;
|
|
|
+import java.util.*;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class MeetingServiceImpl implements MeetingService {
|
|
@@ -32,13 +44,15 @@ public class MeetingServiceImpl implements MeetingService {
|
|
|
private static final String DINGTALK_API_BASE = "https://api.dingtalk.com/v1.0/";
|
|
|
private static final String APP_KEY = "ding6mvrzcxcbdggel0h";
|
|
|
private static final String APP_SECRET = "TctTp-Qmyh9r20bdeHcLWZ8qfxSEP8R29qo53GZH2elWV-yDZMqgqFKEjp5PtlXZ";
|
|
|
+ private static final String USER_ID = "01141506681633389467";
|
|
|
+
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public MeetingVo getMeetingInfo() {
|
|
|
+ public List<MeetingVo> getMeetingInfo() {
|
|
|
List<MeetingVo> vos=new ArrayList<>();
|
|
|
String accessToken = getAccessToken();
|
|
|
- String unionId = getUnionId(accessToken);
|
|
|
+ String unionId = (String) getUserInfo(accessToken,"unionid",USER_ID);
|
|
|
String meetingsJson = getMeetings(accessToken, unionId);
|
|
|
try {
|
|
|
// 解析JSON字符串
|
|
@@ -66,22 +80,341 @@ public class MeetingServiceImpl implements MeetingService {
|
|
|
for (MeetingVo vo : vos) {
|
|
|
String[] roomIds = new String[]{vo.getRoomId()};
|
|
|
String meetingHistory = getMeetingHistory(accessToken, unionId,roomIds,startTime,endTime);
|
|
|
-
|
|
|
+ List<ScheduleItem> scheduleItems = parseScheduleItemsWithStream(meetingHistory);
|
|
|
+ List<MeetingSchedule>list=new ArrayList<>();
|
|
|
+ if(!scheduleItems.isEmpty()){
|
|
|
+ //循环查出预定的会议是否正在进行
|
|
|
+ for (ScheduleItem item : scheduleItems) {
|
|
|
+ String stringStartDateTime = extractTimeFromDateTime(item.getStartDateTime());
|
|
|
+ String stringEndDateTime = extractTimeFromDateTime(item.getEndDateTime());
|
|
|
+ //正在进行的会议
|
|
|
+ if(isCurrentTimeInRange(item.getStartDateTime(),item.getEndDateTime())){
|
|
|
+ String meetingList = getMeetingList(item.getOrganizerId(), accessToken);
|
|
|
+ JSONObject meetingListjsonObject = JSON.parseObject(meetingList);
|
|
|
+ JSONArray onGoingConfIdList = meetingListjsonObject.getJSONArray("onGoingConfIdList");
|
|
|
+ String tatil = getMeetingDetail(accessToken, onGoingConfIdList.getString(0));
|
|
|
+ String userID = getUserID(accessToken, item.getOrganizerId());
|
|
|
+ Object o = getUserInfo(accessToken, "dept_id_list", userID);
|
|
|
+ List<String> deptIdList = JSON.parseArray(o.toString(), String.class);
|
|
|
+ String departmentInfo = getDepartmentInfo(accessToken, deptIdList.get(0));
|
|
|
+ vo.setStatus(2);
|
|
|
+ vo.setMeetingTheme(tatil);
|
|
|
+ vo.setMeetingDept(departmentInfo);
|
|
|
+ String name = (String)getUserInfo(accessToken, "name", userID);
|
|
|
+ vo.setMeetingBooker(name);
|
|
|
+ vo.setMeetingTime(formatDateTimeRangeWithFormatter(item.getStartDateTime(),item.getEndDateTime()));
|
|
|
+ String allUser = getAllUser(onGoingConfIdList.getString(0), accessToken);
|
|
|
+ vo.setParticipants(allUser);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //今日预约的会议
|
|
|
+ MeetingSchedule schedule = new MeetingSchedule();
|
|
|
+ String userID = getUserID(accessToken, item.getOrganizerId());
|
|
|
+ Object o = getUserInfo(accessToken, "dept_id_list", userID);
|
|
|
+ List<String> deptIdList = JSON.parseArray(o.toString(), String.class);
|
|
|
+ String departmentInfo = getDepartmentInfo(accessToken, deptIdList.get(0));
|
|
|
+ schedule.setReservationTime(stringStartDateTime+"~"+stringEndDateTime);
|
|
|
+ schedule.setReservationDept(departmentInfo);
|
|
|
+ vo.setStatus(1);
|
|
|
+ list.add(schedule);
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ vo.setStatus(1);
|
|
|
+ }
|
|
|
+ vo.setMeetingSession(list.size());
|
|
|
+ vo.setMeetings(list);
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return vos;
|
|
|
+ }
|
|
|
|
|
|
+ public String getAllUser(String CONFERENCE_ID,String ACCESS_TOKEN){
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ try {
|
|
|
+ // 构建请求 URL
|
|
|
+ StringBuilder urlBuilder = new StringBuilder("https://api.dingtalk.com/v1.0/conference/videoConferences/")
|
|
|
+ .append(CONFERENCE_ID)
|
|
|
+ .append("/members");
|
|
|
+ HttpGet httpGet = new HttpGet(new URI(urlBuilder.toString()));
|
|
|
+ // 设置 Header 参数
|
|
|
+ httpGet.setHeader("x-acs-dingtalk-access-token", ACCESS_TOKEN);
|
|
|
+ httpGet.setHeader("Content-Type", "application/json");
|
|
|
+ // 发送请求并获取响应
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
+ try {
|
|
|
+ // 解析响应实体为字符串
|
|
|
+ String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(responseString);
|
|
|
+ // 获取memberModelMap
|
|
|
+ JSONArray memberModels = jsonObject.getJSONArray("memberModels");
|
|
|
+ Set<String> set=new HashSet<>();
|
|
|
+ for (int i = 0; i < memberModels.size(); i++) {
|
|
|
+ JSONObject memberModel = memberModels.getJSONObject(i);
|
|
|
+ String userNick = memberModel.getString("userNick");
|
|
|
+ set.add(userNick);
|
|
|
+ }
|
|
|
+ return String.join(",",set);
|
|
|
+ } finally {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ } catch (IOException | URISyntaxException e) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String formatDateTimeRangeWithFormatter(String startDateTime, String endDateTime) {
|
|
|
+ try {
|
|
|
+ ZonedDateTime startTime = ZonedDateTime.parse(startDateTime);
|
|
|
+ ZonedDateTime endTime = ZonedDateTime.parse(endDateTime);
|
|
|
+
|
|
|
+ // 手动构建格式
|
|
|
+ String startFormatted = String.format("%d年%d月%d日 %s %02d:%02d",
|
|
|
+ startTime.getYear(),
|
|
|
+ startTime.getMonthValue(),
|
|
|
+ startTime.getDayOfMonth(),
|
|
|
+ startTime.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE),
|
|
|
+ startTime.getHour(),
|
|
|
+ startTime.getMinute());
|
|
|
+
|
|
|
+ String endFormatted = String.format("%d年%d月%d日 %s %02d:%02d",
|
|
|
+ endTime.getYear(),
|
|
|
+ endTime.getMonthValue(),
|
|
|
+ endTime.getDayOfMonth(),
|
|
|
+ endTime.getDayOfWeek().getDisplayName(TextStyle.FULL, Locale.CHINESE),
|
|
|
+ endTime.getHour(),
|
|
|
+ endTime.getMinute());
|
|
|
+
|
|
|
+ return startFormatted + " ~ " + endFormatted;
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ return "时间格式错误";
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ public boolean isCurrentTimeInRange(String startDateTime, String endDateTime) {
|
|
|
+ try {
|
|
|
+ // 解析开始时间和结束时间
|
|
|
+ ZonedDateTime startTime = ZonedDateTime.parse(startDateTime);
|
|
|
+ ZonedDateTime endTime = ZonedDateTime.parse(endDateTime);
|
|
|
|
|
|
+ // 获取当前时间(使用相同时区)
|
|
|
+ ZonedDateTime now = ZonedDateTime.now(startTime.getZone());
|
|
|
|
|
|
+ // 检查当前时间是否在范围内(包含边界)
|
|
|
+ return !now.isBefore(startTime) && !now.isAfter(endTime);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getMeetingList(String UNION_ID, String ACCESS_TOKEN){
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ try {
|
|
|
+ // 构建请求 URL
|
|
|
+ String url = "https://api.dingtalk.com/v1.0/conference/users/lists?unionId=" + UNION_ID;
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
+ // 设置请求头中的 access token
|
|
|
+ httpGet.setHeader("x-acs-dingtalk-access-token", ACCESS_TOKEN);
|
|
|
+ httpGet.setHeader("Content-Type", "application/json");
|
|
|
+
|
|
|
+ // 发送请求并获取响应
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
+ try {
|
|
|
+ org.apache.http.HttpEntity entity = response.getEntity();
|
|
|
+ if (entity != null) {
|
|
|
+ // 将响应实体转换为字符串
|
|
|
+ return EntityUtils.toString(entity, "UTF-8");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
+ public String getMeetingDetail(String ACCESS_TOKEN,String CONFERENCE_ID){
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ try {
|
|
|
+ // 构建请求 URL,包含会议 ID
|
|
|
+ String url = "https://api.dingtalk.com/v1.0/conference/videoConferences/" + CONFERENCE_ID;
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
+
|
|
|
+ // 设置 Header 参数
|
|
|
+ httpGet.setHeader("x-acs-dingtalk-access-token", ACCESS_TOKEN);
|
|
|
+ httpGet.setHeader("Content-Type", "application/json");
|
|
|
+
|
|
|
+ // 发送请求并获取响应
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
+ try {
|
|
|
+ // 解析响应实体为字符串
|
|
|
+ String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(responseString);
|
|
|
+ JSONObject confInfo = jsonObject.getJSONObject("confInfo");
|
|
|
+ if (confInfo != null) {
|
|
|
+ return confInfo.getString("title");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ } catch (IOException e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ public String getUserID(String ACCESS_TOKEN,String UNION_ID) throws Exception {
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ try {
|
|
|
+ // 构建请求 URL,包含 access_token 和 unionid 参数
|
|
|
+ String url = "https://oapi.dingtalk.com/user/getUseridByUnionid?access_token=" + ACCESS_TOKEN + "&unionid=" + UNION_ID;
|
|
|
+ HttpGet httpGet = new HttpGet(url);
|
|
|
+
|
|
|
+ // 发送请求并获取响应
|
|
|
+ CloseableHttpResponse response = httpClient.execute(httpGet);
|
|
|
+ try {
|
|
|
+ // 解析响应实体为字符串
|
|
|
+ String responseString = EntityUtils.toString(response.getEntity(), "UTF-8");
|
|
|
+ // 解析 JSON 响应
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(responseString);
|
|
|
+
|
|
|
+ // 检查是否调用成功(errcode 为 0 表示成功)
|
|
|
+ if (jsonObject.getInteger("errcode") == 0) {
|
|
|
+ // 获取 userId
|
|
|
+ String userId = jsonObject.getString("userid");
|
|
|
+ return userId;
|
|
|
+ } else {
|
|
|
+ throw new Exception("获取userId失败");
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ response.close();
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new Exception("获取userId失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public int compareDateTimeWithNow(String stringStartDateTime) {
|
|
|
+ try {
|
|
|
+ // 解析输入的时间字符串
|
|
|
+ ZonedDateTime inputTime = ZonedDateTime.parse(stringStartDateTime);
|
|
|
+
|
|
|
+ // 获取当前时间(使用相同时区)
|
|
|
+ ZonedDateTime now = ZonedDateTime.now(inputTime.getZone());
|
|
|
+
|
|
|
+ // 比较时间
|
|
|
+ if (inputTime.isAfter(now)) {
|
|
|
+ return 1; // 输入时间大于当前时间
|
|
|
+ } else {
|
|
|
+ return 2; // 输入时间小于或等于当前时间
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return 2; // 默认返回2(过去时间)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查询部门信息
|
|
|
+ */
|
|
|
+ public String getDepartmentInfo(String accessToken, String deptId) throws Exception {
|
|
|
+ CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+ String url = "https://oapi.dingtalk.com/topapi/v2/department/get?access_token=" + accessToken;
|
|
|
+
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.setHeader("Content-Type", "application/json;charset=UTF-8");
|
|
|
+
|
|
|
+ // 构建请求体
|
|
|
+ JSONObject requestBody = new JSONObject();
|
|
|
+ requestBody.put("dept_id", deptId);
|
|
|
+ httpPost.setEntity(new StringEntity(requestBody.toString(), "UTF-8"));
|
|
|
+
|
|
|
+ // 发送请求并获取响应
|
|
|
+ try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
|
|
|
+ // 使用Apache HttpClient的HttpEntity
|
|
|
+ org.apache.http.HttpEntity entity = response.getEntity(); // 不要强制转换
|
|
|
+ if (entity != null) {
|
|
|
+ String string = EntityUtils.toString(entity, "UTF-8");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(string);
|
|
|
+ JSONObject resultObj = jsonObject.getJSONObject("result");
|
|
|
+ return resultObj.getString("name"); // 使用getString更安全
|
|
|
+ }
|
|
|
+ } finally {
|
|
|
+ httpClient.close();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ public String extractTimeFromDateTime(String dateTimeString) {
|
|
|
+ try {
|
|
|
+ // 解析带时区的时间字符串
|
|
|
+ ZonedDateTime zonedDateTime = ZonedDateTime.parse(dateTimeString);
|
|
|
+
|
|
|
+ // 只提取小时和分钟
|
|
|
+ DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm");
|
|
|
+ return zonedDateTime.format(timeFormatter);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return "00:00"; // 返回默认值如果解析失败
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<ScheduleItem> parseScheduleItemsWithStream(String meetingHistoryJson) {
|
|
|
+ try {
|
|
|
+ JSONObject jsonObject = JSON.parseObject(meetingHistoryJson);
|
|
|
+ JSONArray scheduleInfoArray = jsonObject.getJSONArray("scheduleInformation");
|
|
|
+
|
|
|
+ if (scheduleInfoArray != null) {
|
|
|
+ return scheduleInfoArray.stream()
|
|
|
+ .map(obj -> (JSONObject) obj)
|
|
|
+ .flatMap(scheduleInfo -> {
|
|
|
+ JSONArray items = scheduleInfo.getJSONArray("scheduleItems");
|
|
|
+ return items != null ? items.stream().map(item -> (JSONObject) item) : java.util.stream.Stream.empty();
|
|
|
+ })
|
|
|
+ .map(this::convertToScheduleItem)
|
|
|
+ .collect(java.util.stream.Collectors.toList());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+
|
|
|
+ private ScheduleItem convertToScheduleItem(JSONObject scheduleItemObj) {
|
|
|
+ ScheduleItem item = new ScheduleItem();
|
|
|
+
|
|
|
+ item.setEventId(scheduleItemObj.getString("eventId"));
|
|
|
+ item.setStatus(scheduleItemObj.getString("status"));
|
|
|
+
|
|
|
+ JSONObject organizerObj = scheduleItemObj.getJSONObject("organizer");
|
|
|
+ if (organizerObj != null) {
|
|
|
+ item.setOrganizerId(organizerObj.getString("id"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject startObj = scheduleItemObj.getJSONObject("start");
|
|
|
+ if (startObj != null) {
|
|
|
+ item.setStartDateTime(startObj.getString("dateTime"));
|
|
|
+ item.setStartTimeZone(startObj.getString("timeZone"));
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject endObj = scheduleItemObj.getJSONObject("end");
|
|
|
+ if (endObj != null) {
|
|
|
+ item.setEndDateTime(endObj.getString("dateTime"));
|
|
|
+ item.setEndTimeZone(endObj.getString("timeZone"));
|
|
|
+ }
|
|
|
+
|
|
|
+ return item;
|
|
|
+ }
|
|
|
+
|
|
|
//解析json字符串
|
|
|
- private String parseFromJson(String json,String key) {
|
|
|
+ private String parseFromJson(String json,String key) {
|
|
|
try {
|
|
|
JsonObject jsonObject = JsonParser.parseString(json).getAsJsonObject();
|
|
|
- return jsonObject.get(key).getAsString();
|
|
|
+ JsonElement result = jsonObject.get("result");
|
|
|
+ return result.getAsJsonObject().get(key).getAsString();
|
|
|
} catch (Exception e) {
|
|
|
return null;
|
|
|
}
|
|
@@ -102,7 +435,8 @@ public class MeetingServiceImpl implements MeetingService {
|
|
|
HttpEntity<String> entity = new HttpEntity<>(requestBody, headers);
|
|
|
try {
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
- return parseFromJson(response.getBody(), "accessToken");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(response.getBody());
|
|
|
+ return jsonObject.getString("accessToken");
|
|
|
} catch (Exception e) {
|
|
|
throw new ServiceException("获取AccessToken失败");
|
|
|
}
|
|
@@ -112,27 +446,29 @@ public class MeetingServiceImpl implements MeetingService {
|
|
|
* 获取unionId 操作人id
|
|
|
* @return
|
|
|
*/
|
|
|
- public String getUnionId(String accessToken){
|
|
|
+ public Object getUserInfo(String accessToken,String key,String userid){
|
|
|
String url = "https://oapi.dingtalk.com/topapi/v2/user/get?access_token="+accessToken;
|
|
|
RestTemplate restTemplate = new RestTemplate();
|
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
Map<String, String> requestBody = new HashMap<>();
|
|
|
requestBody.put("language", "zh_CN");
|
|
|
- requestBody.put("userid", "01141506681633389467");
|
|
|
+ requestBody.put("userid", userid);
|
|
|
ObjectMapper objectMapper = new ObjectMapper();
|
|
|
try {
|
|
|
String jsonString = objectMapper.writeValueAsString(requestBody);
|
|
|
HttpEntity<String> entity = new HttpEntity<>(jsonString, headers);
|
|
|
ResponseEntity<String> response = restTemplate.postForEntity(url, entity, String.class);
|
|
|
- return parseFromJson(response.getBody(), "unionId");
|
|
|
+ JSONObject jsonObject = JSON.parseObject(response.getBody());
|
|
|
+ JSONObject result = jsonObject.getJSONObject("result");
|
|
|
+ return result.get(key);
|
|
|
} catch (Exception e) {
|
|
|
- throw new ServiceException("获取unionId失败");
|
|
|
+ throw new ServiceException("获取用户信息失败");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取会议室列表
|
|
|
- public String getMeetings(String accessToken,String unionId) {
|
|
|
+ public String getMeetings(String accessToken,String unionId) {
|
|
|
if (accessToken == null || accessToken.isEmpty()) {
|
|
|
System.out.println("获取accessToken失败");
|
|
|
return null;
|
|
@@ -165,42 +501,42 @@ public class MeetingServiceImpl implements MeetingService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //获取会议室详情
|
|
|
- public String getMeetingDetail(String accessToken,String roomId,String unionId) {
|
|
|
- // 构建请求URL(注意是meetingRooms单个资源路径,不是列表接口)
|
|
|
- String baseUrl = DINGTALK_API_BASE + "rooms/meetingRooms/" + roomId;
|
|
|
- UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(baseUrl)
|
|
|
- .queryParam("unionId", unionId);
|
|
|
-
|
|
|
- // 创建REST模板并设置请求头
|
|
|
- RestTemplate restTemplate = new RestTemplate();
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
- headers.set("x-acs-dingtalk-access-token", accessToken);
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
- // 添加User-Agent头,模拟浏览器请求
|
|
|
- headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
|
|
|
- HttpEntity<?> entity = new HttpEntity<>(headers);
|
|
|
- try {
|
|
|
- // 发送GET请求
|
|
|
- ResponseEntity<String> response = restTemplate.exchange(
|
|
|
- uriBuilder.toUriString(),
|
|
|
- HttpMethod.GET,
|
|
|
- entity,
|
|
|
- String.class
|
|
|
- );
|
|
|
- // 处理响应
|
|
|
- if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
- return response.getBody();
|
|
|
- } else {
|
|
|
- throw new ServiceException("获取会议室详情异常");
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new ServiceException("获取会议室详情失败");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public String getMeetingHistory(String accessToken, String unionId,String[] roomIds, String startTime, String endTime) {
|
|
|
+// //获取会议室详情
|
|
|
+// public String getMeetingDetail(String accessToken,String roomId,String unionId) {
|
|
|
+// // 构建请求URL(注意是meetingRooms单个资源路径,不是列表接口)
|
|
|
+// String baseUrl = DINGTALK_API_BASE + "rooms/meetingRooms/" + roomId;
|
|
|
+// UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromHttpUrl(baseUrl)
|
|
|
+// .queryParam("unionId", unionId);
|
|
|
+//
|
|
|
+// // 创建REST模板并设置请求头
|
|
|
+// RestTemplate restTemplate = new RestTemplate();
|
|
|
+// HttpHeaders headers = new HttpHeaders();
|
|
|
+// headers.set("x-acs-dingtalk-access-token", accessToken);
|
|
|
+// headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
+// // 添加User-Agent头,模拟浏览器请求
|
|
|
+// headers.set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36");
|
|
|
+// HttpEntity<?> entity = new HttpEntity<>(headers);
|
|
|
+// try {
|
|
|
+// // 发送GET请求
|
|
|
+// ResponseEntity<String> response = restTemplate.exchange(
|
|
|
+// uriBuilder.toUriString(),
|
|
|
+// HttpMethod.GET,
|
|
|
+// entity,
|
|
|
+// String.class
|
|
|
+// );
|
|
|
+// // 处理响应
|
|
|
+// if (response.getStatusCode().is2xxSuccessful()) {
|
|
|
+// return response.getBody();
|
|
|
+// } else {
|
|
|
+// throw new ServiceException("获取会议室详情异常");
|
|
|
+// }
|
|
|
+// } catch (Exception e) {
|
|
|
+// throw new ServiceException("获取会议室详情失败");
|
|
|
+// }
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ public String getMeetingHistory(String accessToken, String unionId,String[] roomIds, String startTime, String endTime) {
|
|
|
// 构建请求 URL,包含 Path 参数 userId
|
|
|
String baseUrl = DINGTALK_API_BASE + "calendar/users/{userId}/meetingRooms/schedules/query";
|
|
|
Map<String, Object> paramMap = new HashMap<>();
|