|
|
|
@ -1,12 +1,18 @@
|
|
|
|
|
package com.docus.server.archivefile.service.impl;
|
|
|
|
|
|
|
|
|
|
import com.docus.core.util.Func;
|
|
|
|
|
import com.docus.core.util.ListUtils;
|
|
|
|
|
import com.docus.core.util.property.Setters;
|
|
|
|
|
import com.docus.infrastructure.redis.service.IdService;
|
|
|
|
|
import com.docus.infrastructure.web.exception.ApiException;
|
|
|
|
|
import com.docus.infrastructure.web.exception.ExceptionCode;
|
|
|
|
|
import com.docus.infrastructure.web.request.SearchRequest;
|
|
|
|
|
import com.docus.infrastructure.web.response.PageResult;
|
|
|
|
|
import com.docus.server.archivefile.infrastructure.dao.ITaskConfigDao;
|
|
|
|
|
import com.docus.server.archivefile.infrastructure.dao.ITaskConfigRetryLogDao;
|
|
|
|
|
import com.docus.server.archivefile.service.ITaskConfigService;
|
|
|
|
|
import com.docus.server.entity.TaskConfig;
|
|
|
|
|
import com.docus.server.entity.TaskConfigRetryLog;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
@ -14,12 +20,15 @@ import org.springframework.util.CollectionUtils;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
public class TaskConfigServiceImpl implements ITaskConfigService {
|
|
|
|
|
@Resource
|
|
|
|
|
private ITaskConfigDao taskConfigDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private ITaskConfigRetryLogDao taskConfigRetryLogDao;
|
|
|
|
|
@Resource
|
|
|
|
|
private IdService idService;
|
|
|
|
|
@Resource
|
|
|
|
|
private TrackRetryService trackRetryService;
|
|
|
|
@ -42,21 +51,50 @@ public class TaskConfigServiceImpl implements ITaskConfigService {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public TaskConfig getTaskConfigById(String taskConfigId) {
|
|
|
|
|
return taskConfigDao.findById(taskConfigId);
|
|
|
|
|
TaskConfig config = taskConfigDao.findById(taskConfigId);
|
|
|
|
|
List<TaskConfigRetryLog> taskConfigRetryLogs = taskConfigRetryLogDao.findBy("messageId", config.getId());
|
|
|
|
|
if (!CollectionUtils.isEmpty(taskConfigRetryLogs)) {
|
|
|
|
|
config.setHaveRetryLog(true);
|
|
|
|
|
}
|
|
|
|
|
return config;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Override
|
|
|
|
|
public boolean updateTaskConfig(TaskConfig taskConfig) {
|
|
|
|
|
if (Func.isNull(taskConfig.getId())) {
|
|
|
|
|
|
|
|
|
|
validSave(taskConfig.getRetryKey(), taskConfig.getName());
|
|
|
|
|
|
|
|
|
|
taskConfig.setId(idService.getDateSeq());
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
validUpdate(taskConfig.getId(), taskConfig.getName(), taskConfig.getRetryKey());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return taskConfigDao.saveOrUpdate(taskConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<TaskConfig> search(SearchRequest searchRequest) {
|
|
|
|
|
return taskConfigDao.searchTaskConfig(searchRequest);
|
|
|
|
|
PageResult<TaskConfig> result = searchTaskMessage(searchRequest);
|
|
|
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(result.getList())) {
|
|
|
|
|
return new PageResult<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<TaskConfigRetryLog> retryLogs = taskConfigRetryLogDao.findBy("messageId", ListUtils.distinctSelect(result.getList(), TaskConfig::getId));
|
|
|
|
|
Map<Long, TaskConfigRetryLog> taskConfigRetryLogMap = ListUtils.toMap(retryLogs, TaskConfigRetryLog::getMessageId);
|
|
|
|
|
|
|
|
|
|
Setters.<TaskConfig>instance().list(result.getList()).cycleSetProperties(taskConfig -> {
|
|
|
|
|
if (taskConfigRetryLogMap.containsKey(taskConfig.getId())) {
|
|
|
|
|
taskConfig.setHaveRetryLog(true);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
@ -91,4 +129,32 @@ public class TaskConfigServiceImpl implements ITaskConfigService {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validUpdate(Long id, String name, String retryKey) {
|
|
|
|
|
int count = taskConfigDao.findByNameAndIdAndKey(id, name, null);
|
|
|
|
|
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "任务名称不能重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int keyCount = taskConfigDao.findByNameAndIdAndKey(id, null, retryKey);
|
|
|
|
|
|
|
|
|
|
if (keyCount > 0) {
|
|
|
|
|
throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "任务重试键不能重复");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void validSave(String retryKey, String name) {
|
|
|
|
|
TaskConfig keyConfig = taskConfigDao.findOneBy("retryKey", retryKey);
|
|
|
|
|
|
|
|
|
|
if (Func.notNull(keyConfig)) {
|
|
|
|
|
throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "任务重试键不能重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TaskConfig nameConfig = taskConfigDao.findOneBy("name", name);
|
|
|
|
|
|
|
|
|
|
if (Func.notNull(nameConfig)) {
|
|
|
|
|
throw new ApiException(ExceptionCode.ParamIllegal.getCode(), "任务名称不能重复");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|