diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/JobScheduleService.java b/datavines-server/src/main/java/io/datavines/server/repository/service/JobScheduleService.java index 172d6ec0c..e8b91e67b 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/JobScheduleService.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/JobScheduleService.java @@ -31,6 +31,8 @@ public interface JobScheduleService extends IService { int deleteById(long id); + int deleteBySchedule(JobSchedule jobSchedule); + JobSchedule getById(long id); JobSchedule getByJobId(Long jobId); diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/SlaJobService.java b/datavines-server/src/main/java/io/datavines/server/repository/service/SlaJobService.java index b3e3a269b..245d4f8d8 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/SlaJobService.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/SlaJobService.java @@ -31,4 +31,6 @@ public interface SlaJobService extends IService { IPage pageSlaJob(Long slaId, String searchVal, Integer pageNumber, Integer pageSize); boolean createOrUpdateSlaJob(SlaJobCreateOrUpdate createOrUpdate); + + int deleteByJobId(Long id); } diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobScheduleServiceImpl.java b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobScheduleServiceImpl.java index 52695c04f..27a1c74f3 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobScheduleServiceImpl.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/JobScheduleServiceImpl.java @@ -28,6 +28,7 @@ import io.datavines.server.enums.ScheduleJobType; import io.datavines.server.repository.entity.Job; import io.datavines.server.repository.entity.JobSchedule; +import io.datavines.server.repository.mapper.JobMapper; import io.datavines.server.repository.mapper.JobScheduleMapper; import io.datavines.server.repository.service.JobScheduleService; import io.datavines.server.dqc.coordinator.quartz.QuartzExecutors; @@ -36,7 +37,6 @@ import io.datavines.server.dqc.coordinator.quartz.cron.FunCron; import io.datavines.server.enums.JobScheduleType; -import io.datavines.server.repository.service.JobService; import io.datavines.server.utils.ContextHolder; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; @@ -58,7 +58,7 @@ public class JobScheduleServiceImpl extends ServiceImpl implements JobSe @Autowired private SlaService slaService; + @Autowired + private SlaJobService slaJobService; + @Autowired private CatalogEntityMetricJobRelService catalogEntityMetricJobRelService; @@ -110,6 +113,9 @@ public class JobServiceImpl extends ServiceImpl implements JobSe @Autowired private CatalogEntityInstanceService catalogEntityInstanceService; + @Autowired + private JobScheduleService jobScheduleService; + @Override @Transactional(rollbackFor = Exception.class) public long create(JobCreate jobCreate) throws DataVinesServerException { @@ -413,10 +419,18 @@ public List listByDataSourceId(Long dataSourceId) { @Override @Transactional(rollbackFor = Exception.class) public int deleteById(long id) { + + catalogEntityMetricJobRelService.deleteByJobId(id); + jobExecutionService.deleteByJobId(id); + issueService.deleteByJobId(id); + + JobSchedule jobSchedule = jobScheduleService.getByJobId(id); + if (jobSchedule != null) { + jobScheduleService.deleteBySchedule(jobSchedule); + } + slaJobService.deleteByJobId(id); + if (baseMapper.deleteById(id) > 0) { - catalogEntityMetricJobRelService.deleteByJobId(id); - jobExecutionService.deleteByJobId(id); - issueService.deleteByJobId(id); return 1; } else { return 0; diff --git a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/SlaJobServiceImpl.java b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/SlaJobServiceImpl.java index 30b0e2fbd..422c75566 100644 --- a/datavines-server/src/main/java/io/datavines/server/repository/service/impl/SlaJobServiceImpl.java +++ b/datavines-server/src/main/java/io/datavines/server/repository/service/impl/SlaJobServiceImpl.java @@ -17,6 +17,7 @@ package io.datavines.server.repository.service.impl; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; @@ -38,6 +39,7 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; @Service @Slf4j @@ -98,4 +100,18 @@ public boolean createOrUpdateSlaJob(SlaJobCreateOrUpdate createOrUpdate) { return save(slaJob); } } + + @Override + public int deleteByJobId(Long id) { + List slaJobs = baseMapper.selectList(new QueryWrapper().eq("job_id", id)); + if (CollectionUtils.isNotEmpty(slaJobs)) { + List ids = slaJobs.stream() + .map(SlaJob::getId) + .collect(Collectors.toList()); + if (baseMapper.deleteBatchIds(ids) > 0) { + return 1; + } + } + return 0; + } }