fix(接口测试): 修复场景创建定时任务不发通知的缺陷

--bug=1039697 --user=王孝刚 【项目管理】消息管理-设置开启和关闭定时任务,收不到通知
https://www.tapd.cn/55049933/s/1500618
This commit is contained in:
wxg0103 2024-04-18 12:24:12 +08:00 committed by wxg0103
parent c287f5d607
commit ceaca62faf
2 changed files with 12 additions and 5 deletions

View File

@ -62,11 +62,12 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static io.metersphere.project.utils.NodeSortUtils.DEFAULT_NODE_INTERVAL_POS;
@Service @Service
public class ApiDefinitionImportUtilService { public class ApiDefinitionImportUtilService {
private static final String UNPLANNED_API = "api_unplanned_request"; private static final String UNPLANNED_API = "api_unplanned_request";
public static final Long ORDER_STEP = 5000L;
private final ThreadLocal<Long> currentApiOrder = new ThreadLocal<>(); private final ThreadLocal<Long> currentApiOrder = new ThreadLocal<>();
private final ThreadLocal<Long> currentApiCaseOrder = new ThreadLocal<>(); private final ThreadLocal<Long> currentApiCaseOrder = new ThreadLocal<>();
private final ThreadLocal<Long> currentModuleOrder = new ThreadLocal<>(); private final ThreadLocal<Long> currentModuleOrder = new ThreadLocal<>();
@ -191,7 +192,7 @@ public class ApiDefinitionImportUtilService {
public Long getNextOrder(String projectId) { public Long getNextOrder(String projectId) {
Long pos = extApiDefinitionMapper.getPos(projectId); Long pos = extApiDefinitionMapper.getPos(projectId);
return (pos == null ? 0 : pos) + ORDER_STEP; return (pos == null ? 0 : pos) + DEFAULT_NODE_INTERVAL_POS;
} }
public Long getImportNextOrder(String projectId) { public Long getImportNextOrder(String projectId) {
@ -199,7 +200,7 @@ public class ApiDefinitionImportUtilService {
if (order == null) { if (order == null) {
order = getNextOrder(projectId); order = getNextOrder(projectId);
} }
order = order + ORDER_STEP; order = order + DEFAULT_NODE_INTERVAL_POS;
currentApiOrder.set(order); currentApiOrder.set(order);
return order; return order;
} }
@ -219,7 +220,7 @@ public class ApiDefinitionImportUtilService {
if (order == null) { if (order == null) {
order = apiDefinitionModuleService.getNextOrder(projectId); order = apiDefinitionModuleService.getNextOrder(projectId);
} }
order = order + ORDER_STEP; order = order + DEFAULT_NODE_INTERVAL_POS;
currentModuleOrder.set(order); currentModuleOrder.set(order);
return order; return order;
} }

View File

@ -16,6 +16,7 @@ import org.quartz.SchedulerException;
import org.quartz.TriggerKey; import org.quartz.TriggerKey;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.List; import java.util.List;
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -123,7 +124,6 @@ public class ScheduleService {
schedule.setUpdateTime(System.currentTimeMillis()); schedule.setUpdateTime(System.currentTimeMillis());
schedule.setJob(clazz.getName()); schedule.setJob(clazz.getName());
scheduleMapper.updateByExampleSelective(schedule, example); scheduleMapper.updateByExampleSelective(schedule, example);
apiScheduleNoticeService.sendScheduleNotice(schedule, operator);
} else { } else {
schedule = scheduleConfig.genCronSchedule(null); schedule = scheduleConfig.genCronSchedule(null);
schedule.setJob(clazz.getName()); schedule.setJob(clazz.getName());
@ -133,6 +133,12 @@ public class ScheduleService {
schedule.setUpdateTime(System.currentTimeMillis()); schedule.setUpdateTime(System.currentTimeMillis());
scheduleMapper.insert(schedule); scheduleMapper.insert(schedule);
} }
//通知
if ((CollectionUtils.isEmpty(scheduleList) && BooleanUtils.isTrue(scheduleConfig.getEnable()))
|| (CollectionUtils.isNotEmpty(scheduleList) && !scheduleList.getFirst().getEnable().equals(scheduleConfig.getEnable()))) {
apiScheduleNoticeService.sendScheduleNotice(schedule, operator);
}
JobDataMap jobDataMap = scheduleManager.getDefaultJobDataMap(schedule, scheduleConfig.getCron(), operator); JobDataMap jobDataMap = scheduleManager.getDefaultJobDataMap(schedule, scheduleConfig.getCron(), operator);