2021-03-04 15:38:37 +08:00
|
|
|
package io.dataease.service.dataset;
|
|
|
|
|
|
|
|
import io.dataease.base.domain.DatasetTableTask;
|
|
|
|
import io.dataease.base.domain.DatasetTableTaskExample;
|
|
|
|
import io.dataease.base.mapper.DatasetTableTaskMapper;
|
2021-03-05 14:53:36 +08:00
|
|
|
import io.dataease.service.ScheduleService;
|
2021-03-04 15:38:37 +08:00
|
|
|
import org.apache.commons.lang3.StringUtils;
|
2021-03-08 11:35:28 +08:00
|
|
|
import org.quartz.CronExpression;
|
2021-03-04 15:38:37 +08:00
|
|
|
import org.springframework.stereotype.Service;
|
2021-03-11 10:37:58 +08:00
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
2021-03-04 15:38:37 +08:00
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Author gin
|
|
|
|
* @Date 2021/3/4 1:26 下午
|
|
|
|
*/
|
|
|
|
@Service
|
2021-03-11 10:37:58 +08:00
|
|
|
@Transactional
|
2021-03-04 15:38:37 +08:00
|
|
|
public class DataSetTableTaskService {
|
|
|
|
@Resource
|
|
|
|
private DatasetTableTaskMapper datasetTableTaskMapper;
|
2021-03-10 18:13:27 +08:00
|
|
|
@Resource
|
|
|
|
private DataSetTableTaskLogService dataSetTableTaskLogService;
|
2021-03-05 14:19:23 +08:00
|
|
|
@Resource
|
2021-03-05 14:53:36 +08:00
|
|
|
private ScheduleService scheduleService;
|
2021-03-05 14:19:23 +08:00
|
|
|
|
|
|
|
public DatasetTableTask save(DatasetTableTask datasetTableTask) throws Exception {
|
2021-03-08 11:35:28 +08:00
|
|
|
// check
|
|
|
|
if (StringUtils.isNotEmpty(datasetTableTask.getCron())) {
|
|
|
|
if (!CronExpression.isValidExpression(datasetTableTask.getCron())) {
|
|
|
|
throw new RuntimeException("cron expression error.");
|
|
|
|
}
|
|
|
|
}
|
2021-03-04 15:38:37 +08:00
|
|
|
if (StringUtils.isEmpty(datasetTableTask.getId())) {
|
|
|
|
datasetTableTask.setId(UUID.randomUUID().toString());
|
|
|
|
datasetTableTask.setCreateTime(System.currentTimeMillis());
|
|
|
|
datasetTableTaskMapper.insert(datasetTableTask);
|
|
|
|
} else {
|
2021-03-25 18:18:44 +08:00
|
|
|
datasetTableTaskMapper.updateByPrimaryKeySelective(datasetTableTask);
|
2021-03-04 15:38:37 +08:00
|
|
|
}
|
2021-03-05 14:53:36 +08:00
|
|
|
scheduleService.addSchedule(datasetTableTask);
|
2021-03-04 15:38:37 +08:00
|
|
|
return datasetTableTask;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void delete(String id) {
|
2021-03-05 14:19:23 +08:00
|
|
|
DatasetTableTask datasetTableTask = datasetTableTaskMapper.selectByPrimaryKey(id);
|
2021-03-04 15:38:37 +08:00
|
|
|
datasetTableTaskMapper.deleteByPrimaryKey(id);
|
2021-03-05 14:53:36 +08:00
|
|
|
scheduleService.deleteSchedule(datasetTableTask);
|
2021-03-10 18:13:27 +08:00
|
|
|
dataSetTableTaskLogService.deleteByTaskId(id);
|
|
|
|
}
|
|
|
|
|
2021-03-11 10:37:58 +08:00
|
|
|
public void delete(DatasetTableTask task) {
|
|
|
|
datasetTableTaskMapper.deleteByPrimaryKey(task.getId());
|
|
|
|
scheduleService.deleteSchedule(task);
|
|
|
|
dataSetTableTaskLogService.deleteByTaskId(task.getId());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void deleteByTableId(String id) {
|
|
|
|
DatasetTableTaskExample datasetTableTaskExample = new DatasetTableTaskExample();
|
|
|
|
DatasetTableTaskExample.Criteria criteria = datasetTableTaskExample.createCriteria();
|
|
|
|
criteria.andTableIdEqualTo(id);
|
|
|
|
List<DatasetTableTask> datasetTableTasks = datasetTableTaskMapper.selectByExample(datasetTableTaskExample);
|
|
|
|
datasetTableTasks.forEach(this::delete);
|
|
|
|
}
|
|
|
|
|
2021-03-10 18:13:27 +08:00
|
|
|
public DatasetTableTask get(String id) {
|
|
|
|
return datasetTableTaskMapper.selectByPrimaryKey(id);
|
2021-03-04 15:38:37 +08:00
|
|
|
}
|
|
|
|
|
2021-03-18 17:59:52 +08:00
|
|
|
public void update(DatasetTableTask datasetTableTask) {
|
|
|
|
datasetTableTaskMapper.updateByPrimaryKey(datasetTableTask);
|
|
|
|
}
|
|
|
|
|
2021-03-04 15:38:37 +08:00
|
|
|
public List<DatasetTableTask> list(DatasetTableTask datasetTableTask) {
|
|
|
|
DatasetTableTaskExample datasetTableTaskExample = new DatasetTableTaskExample();
|
|
|
|
DatasetTableTaskExample.Criteria criteria = datasetTableTaskExample.createCriteria();
|
|
|
|
if (StringUtils.isNotEmpty(datasetTableTask.getTableId())) {
|
|
|
|
criteria.andTableIdEqualTo(datasetTableTask.getTableId());
|
|
|
|
}
|
|
|
|
datasetTableTaskExample.setOrderByClause("create_time desc,name asc");
|
|
|
|
return datasetTableTaskMapper.selectByExample(datasetTableTaskExample);
|
|
|
|
}
|
|
|
|
}
|