增加定时任务提醒单元测试
continuous-integration/drone/push Build is passing Details

畅捷通报表
YXY 1 year ago
parent d03f990461
commit bf17724cb5

@ -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);
}
}
}
}

@ -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<LarkCompanyTableInfo> larkList = this.getLarkList();
if (CollectionUtils.isEmpty(larkList)) {
return;
}
List<EventLog> logList = new ArrayList<>();
// LocalDateTime now = LocalDateTime.of(2023, 5, 7, 15, 10);
for (LarkCompanyTableInfo larkCompanyTableInfo : larkList) {
try {
List<LarkTableConfiguration> 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)) {

Loading…
Cancel
Save