From bf17724cb5843ba95ef233f14579ade002fc4bb7 Mon Sep 17 00:00:00 2001 From: YXY <932687738@qq.com> Date: Wed, 6 Sep 2023 22:48:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=8F=90=E9=86=92=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../system/ScheduledRemindersTaskJobTest.java | 33 ++++++++++++++++ .../quartz/task/ScheduledRemindersTask.java | 38 +++++++++++++++++-- 2 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/ScheduledRemindersTaskJobTest.java diff --git a/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/ScheduledRemindersTaskJobTest.java b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/ScheduledRemindersTaskJobTest.java new file mode 100644 index 0000000..a680d96 --- /dev/null +++ b/ruoyi-admin/src/test/java/com/ruoyi/web/controller/system/ScheduledRemindersTaskJobTest.java @@ -0,0 +1,33 @@ +package java.com.ruoyi.web.controller.system; + +import com.ruoyi.common.utils.DateUtils; +import com.ruoyi.quartz.task.ScheduledRemindersTask; +import lombok.extern.slf4j.Slf4j; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; + +import java.time.LocalDateTime; + +@Slf4j +@SpringBootTest +class ScheduledRemindersTaskJobTest { + @Autowired + private ScheduledRemindersTask scheduledRemindersTask; + + @Test + void execute() { + LocalDateTime startDate = LocalDateTime.of(2023, 9, 6, 0, 0); + LocalDateTime endDate = LocalDateTime.of(2023, 9, 6, 22, 30); + while (startDate.isBefore(endDate) || startDate.isBefore(endDate)){ + try { + System.out.println( DateUtils.ldt2str(startDate, DateUtils.YYYY_MM_DD_HH_MM_SS)); + scheduledRemindersTask.scheduledRemindersTemporarily(startDate); + }catch (Exception e) { + log.error("ScheduledRemindersTaskJobTest execute time:{}", DateUtils.ldt2str(startDate, DateUtils.YYYY_MM_DD_HH_MM_SS), e); + }finally { + startDate = startDate.plusMinutes(15L); + } + } + } +} diff --git a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java index e3b1e6f..3a9ee2a 100644 --- a/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java +++ b/ruoyi-quartz/src/main/java/com/ruoyi/quartz/task/ScheduledRemindersTask.java @@ -29,10 +29,7 @@ import java.math.BigDecimal; import java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; +import java.util.*; import java.util.stream.Collectors; /** @@ -72,6 +69,39 @@ public class ScheduledRemindersTask { */ private static final String RANGE_KEY = "提醒时间"; + public void scheduledRemindersTemporarily(LocalDateTime now) { + if (Boolean.FALSE.equals(syncFlag)) { + return; + } + log.info("scheduledRemindersTask start"); + List larkList = this.getLarkList(); + if (CollectionUtils.isEmpty(larkList)) { + return; + } + List logList = new ArrayList<>(); +// LocalDateTime now = LocalDateTime.of(2023, 5, 7, 15, 10); + for (LarkCompanyTableInfo larkCompanyTableInfo : larkList) { + try { + List larkConfiguration = this.getLarkConfiguration(larkCompanyTableInfo); + for (LarkTableConfiguration larkTableConfiguration : larkConfiguration) { + ConfigurationSubTypeEnum subType = ConfigurationSubTypeEnum.getByCode(larkTableConfiguration.getSubConfigType()); + if (subType == null) { + throw new RuntimeException(String.format("tableId:%s 配置子类:%s 无对应策略处理逻辑", larkTableConfiguration.getLarkTableId(), larkTableConfiguration.getSubConfigType())); + } + //按类型执行消息分配动作 + this.allocateSendMessage(subType,now,larkTableConfiguration,logList,larkCompanyTableInfo); + } + } catch (Exception e) { + log.error("ScheduledRemindersTask#scheduledReminders error request:{}", JSONObject.toJSONString(larkCompanyTableInfo), e); + logList.add(new EventLog(larkCompanyTableInfo.getId(), EventOperateType.SCHEDULE_REMINDER.getCode(), JSONObject.toJSONString(larkCompanyTableInfo), null, e.getMessage())); + } + } + if (CollectionUtils.isNotEmpty(logList)) { + eventLogMapper.insertBatchEventLog(logList); + } + log.info("scheduledRemindersTask end"); + } + public void scheduledReminders() { if (Boolean.FALSE.equals(syncFlag)) {