提交 e23da381 作者: 洪东保

定时器里面都要异步执行

父级 99424384
package com.cmeeting.job; package com.cmeeting.job;
import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.thread.ThreadUtil;
import com.azure.core.credential.AccessToken; import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenRequestContext; import com.azure.core.credential.TokenRequestContext;
import com.azure.identity.ClientSecretCredential; import com.azure.identity.ClientSecretCredential;
...@@ -83,21 +84,23 @@ public class CmeetingJob { ...@@ -83,21 +84,23 @@ public class CmeetingJob {
*/ */
@Scheduled(cron = "0 30 6 * * ?") @Scheduled(cron = "0 30 6 * * ?")
public void weComUserSync() { public void weComUserSync() {
if (!redisUtils.setnx("weComUserSync", "weComUserSync", 20 * 60 * 60)) { ThreadUtil.execute(()-> {
return; if (!redisUtils.setnx("weComUserSync", "weComUserSync", 20 * 60 * 60)) {
} return;
try { }
log.info("-------企微人员定时同步任务开始-------"); try {
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)); log.info("-------企微人员定时同步任务开始-------");
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
weComService.doUsers();
log.info("-------企微人员定时同步任务结束--------"); weComService.doUsers();
} catch (Exception e) { log.info("-------企微人员定时同步任务结束--------");
e.printStackTrace(); } catch (Exception e) {
log.error("企微人员定时同步失败"); e.printStackTrace();
} finally { log.error("企微人员定时同步失败");
redisUtils.del("weComUserSync"); } finally {
} redisUtils.del("weComUserSync");
}
});
} }
/** /**
...@@ -106,20 +109,22 @@ public class CmeetingJob { ...@@ -106,20 +109,22 @@ public class CmeetingJob {
@Scheduled(cron = "0 0 7 * * ?") @Scheduled(cron = "0 0 7 * * ?")
// @Scheduled(fixedRate = 5 * 60 * 1000) // @Scheduled(fixedRate = 5 * 60 * 1000)
public void TencentUserSync() { public void TencentUserSync() {
if (!redisUtils.setnx("TencentUserSync", "TencentUserSync", 20 * 60 * 60)) { ThreadUtil.execute(()-> {
return; if (!redisUtils.setnx("TencentUserSync", "TencentUserSync", 20 * 60 * 60)) {
} return;
try { }
log.info("-------腾讯会议人员定时同步任务开始-------"); try {
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)); log.info("-------腾讯会议人员定时同步任务开始-------");
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
tencentMeetingService.doUsers();
log.info("-------腾讯会议人员定时同步任务结束--------"); tencentMeetingService.doUsers();
} catch (Exception e) { log.info("-------腾讯会议人员定时同步任务结束--------");
e.printStackTrace(); } catch (Exception e) {
} finally { e.printStackTrace();
redisUtils.del("TencentUserSync"); } finally {
} redisUtils.del("TencentUserSync");
}
});
} }
/** /**
...@@ -127,61 +132,65 @@ public class CmeetingJob { ...@@ -127,61 +132,65 @@ public class CmeetingJob {
*/ */
@Scheduled(cron = "0 20 7 * * ?") @Scheduled(cron = "0 20 7 * * ?")
public void userBind() { public void userBind() {
if (!redisUtils.setnx("userBind", "userBind", 20 * 60 * 60)) { ThreadUtil.execute(()-> {
return; if (!redisUtils.setnx("userBind", "userBind", 20 * 60 * 60)) {
} return;
try { }
log.info("-------关联企微腾会人员定时任务开始-------"); try {
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE)); log.info("-------关联企微腾会人员定时任务开始-------");
weComService.userBind(); log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
log.info("-------关联企微腾会人员定时任务结束--------"); weComService.userBind();
} catch (Exception e) { log.info("-------关联企微腾会人员定时任务结束--------");
e.printStackTrace(); } catch (Exception e) {
} finally { e.printStackTrace();
redisUtils.del("userBind"); } finally {
} redisUtils.del("userBind");
}
});
} }
@Scheduled(fixedRate = 20 * 60 * 1000, initialDelay = 1 * 60 * 1000) @Scheduled(fixedRate = 20 * 60 * 1000, initialDelay = 1 * 60 * 1000)
public void execute() { public void execute() {
if (isDev) { ThreadUtil.execute(()-> {
return; if (isDev) {
}
if (!redisUtils.setnx("Scheduled-All", "Scheduled-All", 18 * 60)) {
return;
}
try {
//查出企微id和腾会id的关联关系
List<UserId> userIdRelations = userIdMapper.selectList(null);
Map<String, String> widTidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getWid, UserId::getTid));
Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid));
//查出企微的人员信息
List<WeComUser> weComUserList = weComService.list();
Map<String, WeComUser> weComUserMap = weComUserList.stream().collect(Collectors.toMap(WeComUser::getUserId, Function.identity()));
//智能体授权人员
List<UserDTO> accessUserIds = tencentMeetingService.getAccessUserIds(widTidRelations);
if (CollectionUtils.isEmpty(accessUserIds)) {
log.info("无生成纪要权限的人员");
return; return;
} }
List<TencentMeetingVO.RecordFile> meetingFiles = tencentMeetingService.getMeetingFiles(accessUserIds, weComUserMap); if (!redisUtils.setnx("Scheduled-All", "Scheduled-All", 18 * 60)) {
if (meetingFiles == null || meetingFiles.isEmpty()) {
log.info("没有录制文件需要处理");
return; return;
} }
try {
//查出企微id和腾会id的关联关系
List<UserId> userIdRelations = userIdMapper.selectList(null);
Map<String, String> widTidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getWid, UserId::getTid));
Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid));
//查出企微的人员信息
List<WeComUser> weComUserList = weComService.list();
Map<String, WeComUser> weComUserMap = weComUserList.stream().collect(Collectors.toMap(WeComUser::getUserId, Function.identity()));
//智能体授权人员
List<UserDTO> accessUserIds = tencentMeetingService.getAccessUserIds(widTidRelations);
if (CollectionUtils.isEmpty(accessUserIds)) {
log.info("无生成纪要权限的人员");
return;
}
List<TencentMeetingVO.RecordFile> meetingFiles = tencentMeetingService.getMeetingFiles(accessUserIds, weComUserMap);
//获取模板授权的人员 if (meetingFiles == null || meetingFiles.isEmpty()) {
List<UserDTO.TemplateAuthorizedUserDTO> authorizedUsers = meetingRecordTemplateService.selectAuthorizedUsers(); log.info("没有录制文件需要处理");
return;
}
// 提交处理任务 //获取模板授权的人员
producer.submitBatchTasks(meetingFiles, authorizedUsers, tidWidRelations, Boolean.FALSE); List<UserDTO.TemplateAuthorizedUserDTO> authorizedUsers = meetingRecordTemplateService.selectAuthorizedUsers();
} catch (Exception e) {
e.printStackTrace(); // 提交处理任务
} finally { producer.submitBatchTasks(meetingFiles, authorizedUsers, tidWidRelations, Boolean.FALSE);
redisUtils.del("Scheduled-All"); } catch (Exception e) {
} e.printStackTrace();
} finally {
redisUtils.del("Scheduled-All");
}
});
} }
...@@ -190,110 +199,114 @@ public class CmeetingJob { ...@@ -190,110 +199,114 @@ public class CmeetingJob {
*/ */
@Scheduled(fixedRate = 30 * 60 * 1000, initialDelay = 3 * 60 * 1000) @Scheduled(fixedRate = 30 * 60 * 1000, initialDelay = 3 * 60 * 1000)
public void meetingMinutesRetry() { public void meetingMinutesRetry() {
if (isDev) { ThreadUtil.execute(()-> {
return; if (isDev) {
}
if (!redisUtils.setnx("Scheduled-retry", "Scheduled-retry", 28 * 60)) {
return;
}
try {
log.info("-------生成纪要重试定时任务开始-------");
log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
//查出所有早于一小时前的,生成失败且未重试过的会议
// 不能用status筛选,因为可能线程执行一般服务终止,status状态没变
List<MeetingInfo> meetingInfoList =
meetingInfoService.list(new LambdaQueryWrapper<MeetingInfo>()
.isNotNull(MeetingInfo::getMeetingRecordId)
.eq(MeetingInfo::getEmailPushAccess, Boolean.TRUE)
.eq(MeetingInfo::getIsGenerated, Boolean.FALSE)
.eq(MeetingInfo::getGenerateRetry, Boolean.FALSE)
.ne(MeetingInfo::getStatus, MeetingState.EMPTY.getCode())
.le(MeetingInfo::getSyncTime, LocalDateTime.now().minusHours(1))
);
if (meetingInfoList == null || meetingInfoList.isEmpty()) {
log.info("没有生成失败的会议需要重试");
return; return;
} }
List<TencentMeetingVO.RecordFile> meetingFiles = new ArrayList<>(); if (!redisUtils.setnx("Scheduled-retry", "Scheduled-retry", 28 * 60)) {
for (MeetingInfo meetingInfo : meetingInfoList) { return;
TencentMeetingVO.RecordFile recordFile = TencentMeetingVO.RecordFile.builder()
.meetingId(meetingInfo.getMeetingId())
.meetingRecordId(meetingInfo.getMeetingRecordId())
.subMeetingId(meetingInfo.getSubMeetingId())
.recordFileIdList(Arrays.asList(meetingInfo.getRecordFileId().split(","))).build();
meetingFiles.add(recordFile);
} }
try {
//查出企微id和腾会id的关联关系 log.info("-------生成纪要重试定时任务开始-------");
List<UserId> userIdRelations = userIdMapper.selectList(null); log.info("当前时间: " + LocalDate.now().format(DateTimeFormatter.ISO_LOCAL_DATE));
Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid));
//查出所有早于一小时前的,生成失败且未重试过的会议
//获取模板授权的人员 // 不能用status筛选,因为可能线程执行一般服务终止,status状态没变
List<UserDTO.TemplateAuthorizedUserDTO> authorizedUsers = meetingRecordTemplateService.selectAuthorizedUsers(); List<MeetingInfo> meetingInfoList =
meetingInfoService.list(new LambdaQueryWrapper<MeetingInfo>()
// 提交处理任务 .isNotNull(MeetingInfo::getMeetingRecordId)
producer.submitBatchTasks(meetingFiles, authorizedUsers, tidWidRelations, Boolean.TRUE); .eq(MeetingInfo::getEmailPushAccess, Boolean.TRUE)
log.info("-------生成纪要重试定时任务结束--------"); .eq(MeetingInfo::getIsGenerated, Boolean.FALSE)
} catch (Exception e) { .eq(MeetingInfo::getGenerateRetry, Boolean.FALSE)
e.printStackTrace(); .ne(MeetingInfo::getStatus, MeetingState.EMPTY.getCode())
} finally { .le(MeetingInfo::getSyncTime, LocalDateTime.now().minusHours(1))
redisUtils.del("Scheduled-retry"); );
}
} if (meetingInfoList == null || meetingInfoList.isEmpty()) {
log.info("没有生成失败的会议需要重试");
/** return;
* 定时扫描早于一小时之前的,所有邮件推送未重试过的会议,重新推送邮件 }
*/
@Scheduled(fixedRate = 10 * 60 * 1000, initialDelay = 1 * 60 * 1000)
public void emailPushRetry() {
if (isDev) {
return;
}
if (!redisUtils.setnx("Scheduled-email-retry", "Scheduled-email-retry", 28 * 60)) {
return;
}
try {
log.info("-------邮件推送重试定时任务开始-------");
//查出所有早于一小时前的,邮件推送失败且未重试过的会议
List<MeetingInfo> meetingInfoList =
meetingInfoService.list(new LambdaQueryWrapper<MeetingInfo>()
.isNotNull(MeetingInfo::getMeetingRecordId)
.eq(MeetingInfo::getEmailPushAccess, Boolean.TRUE)
.eq(MeetingInfo::getIsGenerated, Boolean.TRUE)
.eq(MeetingInfo::getIsPushed, Boolean.FALSE)
.eq(MeetingInfo::getPushRetry, Boolean.FALSE)
.le(MeetingInfo::getSyncTime, LocalDateTime.now().minusHours(1))
);
if (meetingInfoList == null || meetingInfoList.isEmpty()) {
log.info("没有推送失败的邮件需要重试");
} else {
List<TencentMeetingVO.RecordFile> meetingFiles = new ArrayList<>(); List<TencentMeetingVO.RecordFile> meetingFiles = new ArrayList<>();
for (MeetingInfo meetingInfo : meetingInfoList) { for (MeetingInfo meetingInfo : meetingInfoList) {
TencentMeetingVO.RecordFile recordFile = TencentMeetingVO.RecordFile.builder() TencentMeetingVO.RecordFile recordFile = TencentMeetingVO.RecordFile.builder()
.meetingId(meetingInfo.getMeetingId()) .meetingId(meetingInfo.getMeetingId())
.subMeetingId(meetingInfo.getSubMeetingId())
.meetingRecordId(meetingInfo.getMeetingRecordId()) .meetingRecordId(meetingInfo.getMeetingRecordId())
.recordFileIdList(Arrays.asList(meetingInfo.getRecordFileId().split(","))) .subMeetingId(meetingInfo.getSubMeetingId())
.build(); .recordFileIdList(Arrays.asList(meetingInfo.getRecordFileId().split(","))).build();
meetingFiles.add(recordFile); meetingFiles.add(recordFile);
} }
//查出企微id和腾会id的关联关系 //查出企微id和腾会id的关联关系
List<UserId> userIdRelations = userIdMapper.selectList(null); List<UserId> userIdRelations = userIdMapper.selectList(null);
Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid)); Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid));
//获取模板授权的人员
List<UserDTO.TemplateAuthorizedUserDTO> authorizedUsers = meetingRecordTemplateService.selectAuthorizedUsers();
// 提交处理任务 // 提交处理任务
producer.submitEmailPushTasks(meetingFiles, tidWidRelations); producer.submitBatchTasks(meetingFiles, authorizedUsers, tidWidRelations, Boolean.TRUE);
log.info("-------生成纪要重试定时任务结束--------");
} catch (Exception e) {
e.printStackTrace();
} finally {
redisUtils.del("Scheduled-retry");
} }
log.info("-------邮件推送重试定时任务结束--------"); });
} catch (Exception e) { }
e.printStackTrace();
} finally { /**
redisUtils.del("Scheduled-email-retry"); * 定时扫描早于一小时之前的,所有邮件推送未重试过的会议,重新推送邮件
} */
@Scheduled(fixedRate = 10 * 60 * 1000, initialDelay = 1 * 60 * 1000)
public void emailPushRetry() {
ThreadUtil.execute(()-> {
if (isDev) {
return;
}
if (!redisUtils.setnx("Scheduled-email-retry", "Scheduled-email-retry", 28 * 60)) {
return;
}
try {
log.info("-------邮件推送重试定时任务开始-------");
//查出所有早于一小时前的,邮件推送失败且未重试过的会议
List<MeetingInfo> meetingInfoList =
meetingInfoService.list(new LambdaQueryWrapper<MeetingInfo>()
.isNotNull(MeetingInfo::getMeetingRecordId)
.eq(MeetingInfo::getEmailPushAccess, Boolean.TRUE)
.eq(MeetingInfo::getIsGenerated, Boolean.TRUE)
.eq(MeetingInfo::getIsPushed, Boolean.FALSE)
.eq(MeetingInfo::getPushRetry, Boolean.FALSE)
.le(MeetingInfo::getSyncTime, LocalDateTime.now().minusHours(1))
);
if (meetingInfoList == null || meetingInfoList.isEmpty()) {
log.info("没有推送失败的邮件需要重试");
} else {
List<TencentMeetingVO.RecordFile> meetingFiles = new ArrayList<>();
for (MeetingInfo meetingInfo : meetingInfoList) {
TencentMeetingVO.RecordFile recordFile = TencentMeetingVO.RecordFile.builder()
.meetingId(meetingInfo.getMeetingId())
.subMeetingId(meetingInfo.getSubMeetingId())
.meetingRecordId(meetingInfo.getMeetingRecordId())
.recordFileIdList(Arrays.asList(meetingInfo.getRecordFileId().split(",")))
.build();
meetingFiles.add(recordFile);
}
//查出企微id和腾会id的关联关系
List<UserId> userIdRelations = userIdMapper.selectList(null);
Map<String, String> tidWidRelations = userIdRelations.stream().collect(Collectors.toMap(UserId::getTid, UserId::getWid));
// 提交处理任务
producer.submitEmailPushTasks(meetingFiles, tidWidRelations);
}
log.info("-------邮件推送重试定时任务结束--------");
} catch (Exception e) {
e.printStackTrace();
} finally {
redisUtils.del("Scheduled-email-retry");
}
});
} }
@Resource @Resource
...@@ -308,58 +321,60 @@ public class CmeetingJob { ...@@ -308,58 +321,60 @@ public class CmeetingJob {
@Scheduled(cron = "50 59 7,9,11,13,15,17,19,21,23 * * ?") @Scheduled(cron = "50 59 7,9,11,13,15,17,19,21,23 * * ?")
public void emailStatisticsPush() { public void emailStatisticsPush() {
if (isDev) { ThreadUtil.execute(()->{
return; if (isDev) {
} return;
log.info("推送统计邮件!");
if (!redisUtils.setnx("emailStatisticsPush", "emailStatisticsPush", 4000)) {
return;
}
log.info("推送统计邮件开始!");
List<StatisticsEmailPush.Attachment> attachments = new ArrayList<>();
Date date = new Date();
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.add(Calendar.HOUR_OF_DAY, 1); // 增加 1 小时
Date newDate = calendar.getTime(); // 返回增加后的 Date 对象
String subject = "会议纪要推送记录-" + new SimpleDateFormat("yyyyMMdd HH").format(newDate) + ":00";
String content;
if (CollUtil.isEmpty(statisticsEmailPushProperties.getToEmails())) {
log.error("收件人为空!");
return;
}
File file = new File(savePath + subject + ".xlsx");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
boolean b = meetingInfoService.statisticsEmail(subject, simpleDateFormat1.parse(simpleDateFormat.format(date) + " 00:00:00"),
simpleDateFormat1.parse(simpleDateFormat.format(date) + " 23:59:59"), new FileOutputStream(file));
if (b) {
content = "<p data-olk-copy-source=\\\"MessageBody\\\">Dear all:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;附件为今天Cmeeting会议纪要生成和发送情况,烦请查收。</p>";
StatisticsEmailPush.Attachment attachment = new StatisticsEmailPush.Attachment();
attachment.setName(subject);
attachment.setBytes(IOUtils.toByteArray(Files.newInputStream(file.toPath())));
attachments.add(attachment);
} else {
content = "<p data-olk-copy-source=\\\"MessageBody\\\">Dear all:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;今天到目前为止没有会议。</p>";
} }
StatisticsEmailPush emailPushBuilder = StatisticsEmailPush.builder() log.info("推送统计邮件!");
.toEmails(statisticsEmailPushProperties.getToEmails()) if (!redisUtils.setnx("emailStatisticsPush", "emailStatisticsPush", 4000)) {
.attachments(attachments) return;
.subject(subject) }
.content(content) log.info("推送统计邮件开始!");
.build(); List<StatisticsEmailPush.Attachment> attachments = new ArrayList<>();
emailSender.emailStatisticsPush(emailPushBuilder);
} catch (IOException | ParseException e) { Date date = new Date();
throw new RuntimeException(e);
} finally { Calendar calendar = Calendar.getInstance();
file.delete(); calendar.setTime(date);
// redisUtils.del("emailStatisticsPush"); calendar.add(Calendar.HOUR_OF_DAY, 1); // 增加 1 小时
} Date newDate = calendar.getTime(); // 返回增加后的 Date 对象
log.info("推送统计邮件完成!"); String subject = "会议纪要推送记录-" + new SimpleDateFormat("yyyyMMdd HH").format(newDate) + ":00";
String content;
if (CollUtil.isEmpty(statisticsEmailPushProperties.getToEmails())) {
log.error("收件人为空!");
return;
}
File file = new File(savePath + subject + ".xlsx");
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
boolean b = meetingInfoService.statisticsEmail(subject, simpleDateFormat1.parse(simpleDateFormat.format(date) + " 00:00:00"),
simpleDateFormat1.parse(simpleDateFormat.format(date) + " 23:59:59"), new FileOutputStream(file));
if (b) {
content = "<p data-olk-copy-source=\\\"MessageBody\\\">Dear all:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;附件为今天Cmeeting会议纪要生成和发送情况,烦请查收。</p>";
StatisticsEmailPush.Attachment attachment = new StatisticsEmailPush.Attachment();
attachment.setName(subject);
attachment.setBytes(IOUtils.toByteArray(Files.newInputStream(file.toPath())));
attachments.add(attachment);
} else {
content = "<p data-olk-copy-source=\\\"MessageBody\\\">Dear all:<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;今天到目前为止没有会议。</p>";
}
StatisticsEmailPush emailPushBuilder = StatisticsEmailPush.builder()
.toEmails(statisticsEmailPushProperties.getToEmails())
.attachments(attachments)
.subject(subject)
.content(content)
.build();
emailSender.emailStatisticsPush(emailPushBuilder);
} catch (IOException | ParseException e) {
throw new RuntimeException(e);
} finally {
file.delete();
redisUtils.del("emailStatisticsPush");
}
log.info("推送统计邮件完成!");
});
} }
// @Scheduled(cron = "0 0 * * * ?") // @Scheduled(cron = "0 0 * * * ?")
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论