提交 0db0455d 作者: duanxincheng

企微腾会绑定关系定时任务

父级 b450608b
package com.cmeeting.controller; package com.cmeeting.controller;
import com.cmeeting.service.TecentMeetingService; import com.cmeeting.service.TencentMeetingService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
...@@ -9,10 +9,10 @@ import org.springframework.web.bind.annotation.*; ...@@ -9,10 +9,10 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/tencentMeeting") @RequestMapping("/tencentMeeting")
public class TencentMeetingController { public class TencentMeetingController {
@Autowired @Autowired
private TecentMeetingService tecentMeetingService; private TencentMeetingService tencentMeetingService;
@GetMapping("/add") @GetMapping("/add")
public void addUsers() { public void addUsers() {
tecentMeetingService.doUsers(); tencentMeetingService.doUsers();
} }
} }
...@@ -4,11 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; ...@@ -4,11 +4,9 @@ import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cmeeting.dto.UserDTO; import com.cmeeting.dto.UserDTO;
import com.cmeeting.mapper.primary.UserIdMapper; import com.cmeeting.mapper.primary.UserIdMapper;
import com.cmeeting.pojo.MeetingInfo; import com.cmeeting.pojo.MeetingInfo;
import com.cmeeting.pojo.UserId;
import com.cmeeting.pojo.WeComUser;
import com.cmeeting.service.FileProcessProducer; import com.cmeeting.service.FileProcessProducer;
import com.cmeeting.service.MeetingInfoService; import com.cmeeting.service.MeetingInfoService;
import com.cmeeting.service.TecentMeetingService; import com.cmeeting.service.TencentMeetingService;
import com.cmeeting.service.WeComService; import com.cmeeting.service.WeComService;
import com.cmeeting.vo.TencentMeetingVO; import com.cmeeting.vo.TencentMeetingVO;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -30,12 +28,10 @@ public class CmeetingJob { ...@@ -30,12 +28,10 @@ public class CmeetingJob {
@Autowired @Autowired
private WeComService weComService; private WeComService weComService;
@Autowired @Autowired
private TecentMeetingService tecentMeetingService; private TencentMeetingService tencentMeetingService;
@Autowired @Autowired
private MeetingInfoService meetingInfoService; private MeetingInfoService meetingInfoService;
@Autowired @Autowired
private UserIdMapper userIdMapper;
@Autowired
private FileProcessProducer producer; private FileProcessProducer producer;
// @PostConstruct // @PostConstruct
...@@ -47,6 +43,10 @@ public class CmeetingJob { ...@@ -47,6 +43,10 @@ public class CmeetingJob {
// public void tencentUserInit(){ // public void tencentUserInit(){
// TencentUserSync(); // TencentUserSync();
// } // }
// @PostConstruct
// public void userBindInit(){
// userBind();
// }
/** /**
* 企微人员定时同步 * 企微人员定时同步
...@@ -74,7 +74,7 @@ public class CmeetingJob { ...@@ -74,7 +74,7 @@ public class CmeetingJob {
log.info("-------腾讯会议人员定时同步任务开始-------"); log.info("-------腾讯会议人员定时同步任务开始-------");
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)); log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
tecentMeetingService.doUsers(); tencentMeetingService.doUsers();
log.info("-------腾讯会议人员定时同步任务结束--------"); log.info("-------腾讯会议人员定时同步任务结束--------");
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -84,56 +84,15 @@ public class CmeetingJob { ...@@ -84,56 +84,15 @@ public class CmeetingJob {
/** /**
* 绑定企微和腾会人员关系 * 绑定企微和腾会人员关系
*/ */
// @Scheduled(fixedRate = 5 * 60 * 1000) @Scheduled(cron = "0 20 7 * * ?")
public void userBind() { public void userBind() {
String weComToken = weComService.getToken(); log.info("-------关联企微腾会人员定时任务开始-------");
//查出没有建立关联的企微人员 log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
List<WeComUser> noBindUsers = weComService.noBindUsers(); weComService.userBind();
List<UserId> userIds = new ArrayList<>(); log.info("-------关联企微腾会人员定时任务结束--------");
// List<WeComUser> sameNameUsers = noBindUsers.stream().filter(item -> "1".equals(item.getIsRepeatName())).collect(Collectors.toList());
// for (WeComUser user : sameNameUsers) {
// Map<String, String> meetingCodeAndMeetingid = weComService.createTempMeeting(user.getUserId(), weComToken);
// String meetingId = meetingCodeAndMeetingid.get("meetingid");
// String meetingCode = meetingCodeAndMeetingid.get("meeting_code");
// if (meetingCode == null || meetingCode.isEmpty()) {
// System.err.println("会议创建失败,跳过用户: " + user.getUserId());
// continue;
// }
// // 3.2 查询会议详情,获取主持人腾讯会议 userid(假设是 host_userid)
// String hostUserId = tecentMeetingService.getMeetingHost(meetingCode);
// if (hostUserId == null || hostUserId.isEmpty()) {
// System.err.println("获取主持人失败,跳过会议: " + meetingCode);
// weComService.cancelMeeting(meetingId, weComToken); // 尝试取消无效会议
// continue;
// }
// UserId userId = new UserId(user.getUserName(), user.getUserId(), hostUserId);
// userIds.add(userId);
// }
// List<WeComUser> normalUsers = noBindUsers.stream().filter(item -> "0".equals(item.getIsRepeatName())).collect(Collectors.toList());
for (WeComUser user : noBindUsers) {
Map<String, String> meetingCodeAndMeetingid = weComService.createTempMeeting(user.getUserId(), weComToken);
String meetingId = meetingCodeAndMeetingid.get("meetingid");
String meetingCode = meetingCodeAndMeetingid.get("meeting_code");
if (meetingCode == null || meetingCode.isEmpty()) {
System.err.println("会议创建失败,跳过用户: " + user.getUserId());
continue;
}
// 3.2 查询会议详情,获取主持人腾讯会议 userid(假设是 host_userid)
String hostUserId = tecentMeetingService.getMeetingHost(meetingCode);
if (hostUserId == null || hostUserId.isEmpty()) {
System.err.println("获取主持人失败,跳过会议: " + meetingCode);
weComService.cancelMeeting(meetingId, weComToken); // 尝试取消无效会议
continue;
}
UserId userId = UserId.builder().userName(user.getUserName()).wid(user.getUserId()).tid(hostUserId).build();
userIds.add(userId);
}
userIdMapper.insertUsers(userIds);
} }
// @Scheduled(fixedRate = 5 * 60 * 1000,initialDelay = 2 * 60 * 1000) // @Scheduled(fixedRate = 10 * 60 * 1000,initialDelay = 2 * 60 * 1000)
@Scheduled(fixedRate = 10 * 60 * 1000) @Scheduled(fixedRate = 10 * 60 * 1000)
public void execute() { public void execute() {
// 定义时间格式化器 // 定义时间格式化器
...@@ -152,12 +111,12 @@ public class CmeetingJob { ...@@ -152,12 +111,12 @@ public class CmeetingJob {
log.info("结束时间: " + now.format(formatter) + " | Unix 时间戳: " + nowTimestamp); log.info("结束时间: " + now.format(formatter) + " | Unix 时间戳: " + nowTimestamp);
log.info("----------------------------------"); log.info("----------------------------------");
List<UserDTO> accessUserIds = tecentMeetingService.getAccessUserIds(); List<UserDTO> accessUserIds = tencentMeetingService.getAccessUserIds();
if (CollectionUtils.isEmpty(accessUserIds)) { if (CollectionUtils.isEmpty(accessUserIds)) {
log.info("无生成纪要权限的人员"); log.info("无生成纪要权限的人员");
return; return;
} }
List<TencentMeetingVO.RecordFile> meetingFiles = tecentMeetingService.getMeetingFiles(accessUserIds); List<TencentMeetingVO.RecordFile> meetingFiles = tencentMeetingService.getMeetingFiles(accessUserIds);
if (meetingFiles == null || meetingFiles.isEmpty()) { if (meetingFiles == null || meetingFiles.isEmpty()) {
log.info("没有录制文件需要处理"); log.info("没有录制文件需要处理");
......
...@@ -8,7 +8,7 @@ import com.cmeeting.vo.TencentMeetingVO; ...@@ -8,7 +8,7 @@ import com.cmeeting.vo.TencentMeetingVO;
import java.util.List; import java.util.List;
public interface TecentMeetingService extends IService<TencentMeetingUser> { public interface TencentMeetingService extends IService<TencentMeetingUser> {
void batchInsert(List<TencentMeetingUser> users); void batchInsert(List<TencentMeetingUser> users);
void doUsers(); void doUsers();
......
package com.cmeeting.service; package com.cmeeting.service;
import com.baomidou.mybatisplus.extension.service.IService; import com.baomidou.mybatisplus.extension.service.IService;
import com.cmeeting.pojo.MeetingInfo;
import com.cmeeting.pojo.WeComUser; import com.cmeeting.pojo.WeComUser;
import java.util.List; import java.util.List;
...@@ -16,7 +17,12 @@ public interface WeComService extends IService<WeComUser> { ...@@ -16,7 +17,12 @@ public interface WeComService extends IService<WeComUser> {
List<WeComUser> noBindUsers(); List<WeComUser> noBindUsers();
Map<String, String> createTempMeeting(String wid, String token); MeetingInfo createTempMeeting(String wid, String token);
void cancelMeeting(String meetingId, String weComToken); void cancelMeeting(String meetingId, String weComToken);
/**
* 绑定企微和腾会的人员关系
*/
void userBind();
} }
...@@ -12,7 +12,7 @@ import com.cmeeting.pojo.CoreModulePermissions; ...@@ -12,7 +12,7 @@ import com.cmeeting.pojo.CoreModulePermissions;
import com.cmeeting.pojo.MeetingInfo; import com.cmeeting.pojo.MeetingInfo;
import com.cmeeting.pojo.TencentMeetingUser; import com.cmeeting.pojo.TencentMeetingUser;
import com.cmeeting.pojo.UserId; import com.cmeeting.pojo.UserId;
import com.cmeeting.service.TecentMeetingService; import com.cmeeting.service.TencentMeetingService;
import com.cmeeting.util.RedisUtils; import com.cmeeting.util.RedisUtils;
import com.cmeeting.util.SignatureUtil; import com.cmeeting.util.SignatureUtil;
import com.cmeeting.vo.CorpRecordsVO; import com.cmeeting.vo.CorpRecordsVO;
...@@ -25,45 +25,32 @@ import com.tencentcloudapi.wemeet.core.exception.ClientException; ...@@ -25,45 +25,32 @@ import com.tencentcloudapi.wemeet.core.exception.ClientException;
import com.tencentcloudapi.wemeet.core.exception.ServiceException; import com.tencentcloudapi.wemeet.core.exception.ServiceException;
import com.tencentcloudapi.wemeet.service.meetings.api.MeetingsApi; import com.tencentcloudapi.wemeet.service.meetings.api.MeetingsApi;
import com.tencentcloudapi.wemeet.service.meetings.model.*; import com.tencentcloudapi.wemeet.service.meetings.model.*;
import com.tencentcloudapi.wemeet.service.records.api.RecordsApi;
import com.tencentcloudapi.wemeet.service.records.model.*;
import com.tencentcloudapi.wemeet.service.user_manager.api.UserManagerApi; import com.tencentcloudapi.wemeet.service.user_manager.api.UserManagerApi;
import com.tencentcloudapi.wemeet.service.user_manager.model.V1UsersListGet200Response; import com.tencentcloudapi.wemeet.service.user_manager.model.V1UsersListGet200Response;
import com.tencentcloudapi.wemeet.service.user_manager.model.V1UsersListGet200ResponseUsersInner; import com.tencentcloudapi.wemeet.service.user_manager.model.V1UsersListGet200ResponseUsersInner;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import okhttp3.Headers;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom; import java.security.SecureRandom;
import java.time.*; import java.time.*;
import java.util.*; import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j @Slf4j
public class TecentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,TencentMeetingUser> implements TecentMeetingService { public class TencentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,TencentMeetingUser> implements TencentMeetingService {
@Resource @Resource
private TecentMeetingMapper tecentMeetingMapper; private TecentMeetingMapper tecentMeetingMapper;
@Resource @Resource
...@@ -773,7 +760,7 @@ public class TecentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,Te ...@@ -773,7 +760,7 @@ public class TecentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,Te
} }
/** /**
* 通过meetingId获取到会议主持人对应的腾讯会议userid * 通过meetingCode获取到会议主持人对应的腾讯会议userid
* *
* @param meetingCode * @param meetingCode
* @return * @return
...@@ -787,48 +774,36 @@ public class TecentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,Te ...@@ -787,48 +774,36 @@ public class TecentMeetingServiceImpl extends ServiceImpl<TecentMeetingMapper,Te
.withAppId(tencentAppId).withSdkId(tencentSdkId) .withAppId(tencentAppId).withSdkId(tencentSdkId)
.withSecret(tencentSecretId, tencentSecretKey) .withSecret(tencentSecretId, tencentSecretKey)
.build(); .build();
MeetingsApi.ApiV1MeetingsGetRequest request = MeetingsApi.ApiV1MeetingsGetRequest request =
new MeetingsApi.ApiV1MeetingsGetRequest.Builder() new MeetingsApi.ApiV1MeetingsGetRequest.Builder()
.userid(tencentAdminUserId) .userid(tencentAdminUserId)
.instanceid("1") .instanceid("1")
.meetingCode(meetingCode) .meetingCode(meetingCode)
.build(); .build();
AuthenticatorBuilder<JWTAuthenticator> authenticatorBuilder =
new JWTAuthenticator.Builder().nonce(BigInteger.valueOf(Math.abs((new SecureRandom()).nextInt()))).timestamp(String.valueOf(System.currentTimeMillis() / 1000L));
try { try {
MeetingsApi.ApiV1MeetingsGetResponse response = MeetingsApi.ApiV1MeetingsGetResponse response =
client.meetings().v1MeetingsGet(request, authenticatorBuilder); client.meetings().v1MeetingsGet(request,
// response from `v1MeetingsGet`: V1MeetingsGet200Response new JWTAuthenticator.Builder()
System.out.printf("Response from `MeetingsApi.v1MeetingsGet`: \nheader: %s\n%s\n", .nonce(BigInteger.valueOf(Math.abs((new SecureRandom()).nextInt())))
response.getHeader(), response.getData()); .timestamp(String.valueOf(System.currentTimeMillis() / 1000L)));
// 提取主持人 userid // 提取主持人 userid
// 5. 处理响应数据
if (response == null || response.getData() == null) { if (response == null || response.getData() == null) {
throw new RuntimeException("API响应数据为空"); return null;
} }
// 6. 使用更安全的方式解析响应
V1MeetingsGet200Response responseData = response.getData(); V1MeetingsGet200Response responseData = response.getData();
if (responseData.getMeetingInfoList() == null || responseData.getMeetingInfoList().isEmpty()) { if (responseData.getMeetingInfoList() == null || responseData.getMeetingInfoList().isEmpty()) {
throw new RuntimeException("未找到会议信息"); return null;
} }
V1MeetingsGet200ResponseMeetingInfoListInner meetingInfo = responseData.getMeetingInfoList().get(0); V1MeetingsGet200ResponseMeetingInfoListInner meetingInfo = responseData.getMeetingInfoList().get(0);
if (meetingInfo.getCurrentHosts() == null || meetingInfo.getCurrentHosts().isEmpty()) { if (meetingInfo.getCurrentHosts() == null || meetingInfo.getCurrentHosts().isEmpty()) {
throw new RuntimeException("会议没有主持人"); return null;
} }
String hostUserId = meetingInfo.getCurrentHosts().get(0).getUserid(); String hostUserId = meetingInfo.getCurrentHosts().get(0).getUserid();
if (hostUserId == null || hostUserId.isEmpty()) {
throw new RuntimeException("主持人userid为空");
}
System.out.println("成功获取主持人userid: {}" + hostUserId); System.out.println("成功获取主持人userid: {}" + hostUserId);
return hostUserId; return hostUserId;
} catch (ClientException e) { } catch (Exception e) {
System.out.printf("Error when calling `MeetingsApi.v1MeetingsGet`: %s\n", e); return null;
throw new RuntimeException(e);
} catch (ServiceException e) {
System.out.printf("Error when calling `MeetingsApi.v1MeetingsGet`: %s\n", e);
System.out.printf("Full HTTP response: %s\n", new String(e.getApiResp().getRawBody()));
throw new RuntimeException(e);
} }
} }
} }
...@@ -3,33 +3,31 @@ package com.cmeeting.service.impl; ...@@ -3,33 +3,31 @@ package com.cmeeting.service.impl;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cmeeting.mapper.primary.UserIdMapper;
import com.cmeeting.mapper.primary.WeComUserMapper; import com.cmeeting.mapper.primary.WeComUserMapper;
import com.cmeeting.pojo.MeetingInfo;
import com.cmeeting.pojo.UserId;
import com.cmeeting.pojo.WeComUser; import com.cmeeting.pojo.WeComUser;
import com.cmeeting.service.TencentMeetingService;
import com.cmeeting.service.WeComService; import com.cmeeting.service.WeComService;
import com.cmeeting.util.RedisUtils; import com.cmeeting.util.RedisUtils;
import com.tencentcloudapi.wemeet.Client; import lombok.extern.slf4j.Slf4j;
import com.tencentcloudapi.wemeet.core.authenticator.AuthenticatorBuilder;
import com.tencentcloudapi.wemeet.core.authenticator.JWTAuthenticator;
import com.tencentcloudapi.wemeet.core.exception.ClientException;
import com.tencentcloudapi.wemeet.core.exception.ServiceException;
import com.tencentcloudapi.wemeet.service.meetings.api.MeetingsApi;
import com.tencentcloudapi.wemeet.service.meetings.model.V1MeetingsGet200Response;
import com.tencentcloudapi.wemeet.service.meetings.model.V1MeetingsGet200ResponseMeetingInfoListInner;
import okhttp3.*; import okhttp3.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.math.BigInteger;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.security.SecureRandom;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Service @Service
@Slf4j
public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> implements WeComService { public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> implements WeComService {
private static final String CORP_ID = "wx34544d057db97ffd"; private static final String CORP_ID = "wx34544d057db97ffd";
...@@ -40,6 +38,10 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i ...@@ -40,6 +38,10 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i
private WeComUserMapper weComUserMapper; private WeComUserMapper weComUserMapper;
@Resource @Resource
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Resource
private TencentMeetingService tencentMeetingService;
@Autowired
private UserIdMapper userIdMapper;
@Override @Override
public void batchInsert(List<WeComUser> users) { public void batchInsert(List<WeComUser> users) {
...@@ -115,17 +117,15 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i ...@@ -115,17 +117,15 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i
* 创建预约会议(传入 wid 作为主持人) * 创建预约会议(传入 wid 作为主持人)
*/ */
@Override @Override
public Map<String, String> createTempMeeting(String wid, String token) { public MeetingInfo createTempMeeting(String wid, String token) {
String url = "https://qyapi.weixin.qq.com/cgi-bin/meeting/create?access_token=" + token; String url = "https://qyapi.weixin.qq.com/cgi-bin/meeting/create?access_token=" + token;
org.json.JSONObject body = new org.json.JSONObject() org.json.JSONObject body = new org.json.JSONObject()
.put("admin_userid", wid) // 主持人 userid .put("admin_userid", wid) // 主持人 userid
.put("title", "自动创建会议") .put("title", "Cmeeting会议助手创建会议")
.put("meeting_start", System.currentTimeMillis() / 1000 + 3600) // 1小时后开始 .put("meeting_start", System.currentTimeMillis() / 1000 + 3600) // 1小时后开始
.put("meeting_duration", 3600) .put("meeting_duration", 3600)
.put("invitees", new org.json.JSONObject() // 添加 invitees 字段 .put("invitees", new org.json.JSONObject() // 添加 invitees 字段
.put("userid", new String[]{wid}) // 将 wid 作为参会人 .put("userid", new String[]{wid})); // 将 wid 作为参会人
);
Request request = new Request.Builder() Request request = new Request.Builder()
.url(url) .url(url)
...@@ -134,13 +134,13 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i ...@@ -134,13 +134,13 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i
try (Response response = new OkHttpClient().newCall(request).execute()) { try (Response response = new OkHttpClient().newCall(request).execute()) {
org.json.JSONObject json = new org.json.JSONObject(response.body().string()); org.json.JSONObject json = new org.json.JSONObject(response.body().string());
MeetingInfo meetingInfo = new MeetingInfo();
if (json.getInt("errcode") != 0) { if (json.getInt("errcode") != 0) {
return null; // 或者抛出异常 return meetingInfo; // 或者抛出异常
} }
Map<String, String> result = new HashMap<>(); meetingInfo.setMeetingId(json.getString("meetingid"));
result.put("meetingid", json.getString("meetingid")); meetingInfo.setMeetingCode(json.getString("meeting_code"));
result.put("meeting_code", json.getString("meeting_code")); return meetingInfo;
return result;
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
...@@ -187,6 +187,41 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i ...@@ -187,6 +187,41 @@ public class WeComServiceImpl extends ServiceImpl<WeComUserMapper, WeComUser> i
} }
@Override
public void userBind() {
String weComToken = getToken();
//查出没有建立关联的企微人员
List<WeComUser> noBindUsers = noBindUsers();
List<UserId> userIds = new ArrayList<>();
try{
for (WeComUser user : noBindUsers) {
MeetingInfo meetingInfo = createTempMeeting(user.getUserId(), weComToken);
String meetingId = meetingInfo.getMeetingId();
String meetingCode = meetingInfo.getMeetingCode();
if (meetingCode == null || meetingCode.isEmpty()) {
log.error("会议创建失败,跳过用户: " + user.getUserId());
continue;
}
// 查询会议详情,获取主持人腾讯会议userid
String hostUserId = tencentMeetingService.getMeetingHost(meetingCode);
if (hostUserId == null || hostUserId.isEmpty()) {
log.error("获取主持人失败,跳过会议: " + meetingCode);
cancelMeeting(meetingId, weComToken); // 尝试取消无效会议
continue;
}
UserId userId = UserId.builder().userName(user.getUserName()).wid(user.getUserId()).tid(hostUserId).build();
userIds.add(userId);
}
}catch (Exception e){
throw new RuntimeException(e);
}finally {
if(!CollectionUtils.isEmpty(userIds)){
userIdMapper.insertUsers(userIds);
}
}
}
/** /**
* 获取企微部门列表 * 获取企微部门列表
* *
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<mapper namespace="com.cmeeting.mapper.primary.UserIdMapper"> <mapper namespace="com.cmeeting.mapper.primary.UserIdMapper">
<!-- 批量插入用户ID信息 --> <!-- 批量插入用户ID信息 -->
<insert id="insertUsers" parameterType="List"> <insert id="insertUsers" parameterType="List">
INSERT INTO userid ( INSERT IGNORE INTO userid (
user_name, user_name,
wid, wid,
tid tid
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论