feat(sj_1.0.0): 添加重试日志删除接口

This commit is contained in:
opensnail 2024-04-25 18:37:41 +08:00
parent b2808a9544
commit 469e8061d2
4 changed files with 85 additions and 13 deletions

View File

@ -182,14 +182,14 @@
<licenses> <licenses>
<license> <license>
<name>GNU General Public License v3.0</name> <name>Apache License 2.0</name>
<url>https://www.gnu.org/licenses/gpl-3.0.txt</url> <url>https://www.apache.org/licenses/LICENSE-2.0</url>
</license> </license>
</licenses> </licenses>
<scm> <scm>
<url>https://github.com/byteblogs168/snail-job</url> <url>https://gitee.com/aizuda/snail-job</url>
<connection>https://gitee.com.aizuda.snailjob.git</connection> <connection>https://gitee.com/aizuda/snail-job</connection>
<developerConnection>https://gitee.com/aizuda/</developerConnection> <developerConnection>https://gitee.com/aizuda/</developerConnection>
</scm> </scm>

View File

@ -8,12 +8,15 @@ import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponse
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO; import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO;
import com.aizuda.snailjob.server.web.service.RetryTaskLogService; import com.aizuda.snailjob.server.web.service.RetryTaskLogService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* 重试日志接口 * 重试日志接口
@ -45,4 +48,16 @@ public class RetryTaskLogController {
public RetryTaskLogResponseVO getRetryTaskLogById(@PathVariable("id") Long id) { public RetryTaskLogResponseVO getRetryTaskLogById(@PathVariable("id") Long id) {
return retryTaskLogService.getRetryTaskLogById(id); return retryTaskLogService.getRetryTaskLogById(id);
} }
@LoginRequired
@DeleteMapping("{id}")
public Boolean deleteById(@PathVariable("id") Long id) {
return retryTaskLogService.deleteById(id);
}
@LoginRequired
@DeleteMapping("ids")
public Boolean batchDelete(@RequestBody Set<Long> ids) {
return retryTaskLogService.batchDelete(ids);
}
} }

View File

@ -12,6 +12,7 @@ import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponse
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO; import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO;
import java.util.List; import java.util.List;
import java.util.Set;
/** /**
* @author opensnail * @author opensnail
@ -26,4 +27,7 @@ public interface RetryTaskLogService {
RetryTaskLogResponseVO getRetryTaskLogById(Long id); RetryTaskLogResponseVO getRetryTaskLogById(Long id);
boolean deleteById(Long id);
boolean batchDelete(Set<Long> ids);
} }

View File

@ -1,8 +1,11 @@
package com.aizuda.snailjob.server.web.service.impl; package com.aizuda.snailjob.server.web.service.impl;
import cn.hutool.core.lang.Assert;
import cn.hutool.core.util.StrUtil; import cn.hutool.core.util.StrUtil;
import com.aizuda.snailjob.common.core.enums.RetryStatusEnum;
import com.aizuda.snailjob.common.core.util.JsonUtil; import com.aizuda.snailjob.common.core.util.JsonUtil;
import com.aizuda.snailjob.common.log.constant.LogFieldConstants; import com.aizuda.snailjob.common.log.constant.LogFieldConstants;
import com.aizuda.snailjob.server.common.exception.SnailJobServerException;
import com.aizuda.snailjob.server.web.model.request.UserSessionVO; import com.aizuda.snailjob.server.web.model.request.UserSessionVO;
import com.aizuda.snailjob.server.web.util.UserSessionUtils; import com.aizuda.snailjob.server.web.util.UserSessionUtils;
import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponseVO; import com.aizuda.snailjob.server.web.model.response.RetryTaskLogMessageResponseVO;
@ -22,11 +25,14 @@ import com.aizuda.snailjob.server.web.model.response.RetryTaskLogResponseVO;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@ -69,19 +75,21 @@ public class RetryTaskLogServiceImpl implements RetryTaskLogService {
retryTaskLogLambdaQueryWrapper.eq(RetryTaskLog::getIdempotentId, queryVO.getIdempotentId()); retryTaskLogLambdaQueryWrapper.eq(RetryTaskLog::getIdempotentId, queryVO.getIdempotentId());
} }
retryTaskLogLambdaQueryWrapper.select(RetryTaskLog::getGroupName, RetryTaskLog::getId, RetryTaskLog::getSceneName, retryTaskLogLambdaQueryWrapper.select(RetryTaskLog::getGroupName, RetryTaskLog::getId,
RetryTaskLog::getIdempotentId, RetryTaskLog::getBizNo, RetryTaskLog::getRetryStatus, RetryTaskLog::getSceneName,
RetryTaskLog::getCreateDt, RetryTaskLog::getUniqueId, RetryTaskLog::getTaskType); RetryTaskLog::getIdempotentId, RetryTaskLog::getBizNo, RetryTaskLog::getRetryStatus,
PageDTO<RetryTaskLog> retryTaskLogPageDTO = retryTaskLogMapper.selectPage(pageDTO, retryTaskLogLambdaQueryWrapper.orderByDesc(RetryTaskLog::getCreateDt)); RetryTaskLog::getCreateDt, RetryTaskLog::getUniqueId, RetryTaskLog::getTaskType);
PageDTO<RetryTaskLog> retryTaskLogPageDTO = retryTaskLogMapper.selectPage(pageDTO,
retryTaskLogLambdaQueryWrapper.orderByDesc(RetryTaskLog::getCreateDt));
return new PageResult<>( return new PageResult<>(
retryTaskLogPageDTO, retryTaskLogPageDTO,
RetryTaskLogResponseVOConverter.INSTANCE.batchConvert(retryTaskLogPageDTO.getRecords())); RetryTaskLogResponseVOConverter.INSTANCE.batchConvert(retryTaskLogPageDTO.getRecords()));
} }
@Override @Override
public RetryTaskLogMessageResponseVO getRetryTaskLogMessagePage( public RetryTaskLogMessageResponseVO getRetryTaskLogMessagePage(
RetryTaskLogMessageQueryVO queryVO) { RetryTaskLogMessageQueryVO queryVO) {
if (StrUtil.isBlank(queryVO.getUniqueId()) || StrUtil.isBlank(queryVO.getGroupName())) { if (StrUtil.isBlank(queryVO.getUniqueId()) || StrUtil.isBlank(queryVO.getGroupName())) {
RetryTaskLogMessageResponseVO jobLogResponseVO = new RetryTaskLogMessageResponseVO(); RetryTaskLogMessageResponseVO jobLogResponseVO = new RetryTaskLogMessageResponseVO();
jobLogResponseVO.setNextStartId(0L); jobLogResponseVO.setNextStartId(0L);
@ -100,7 +108,8 @@ public class RetryTaskLogServiceImpl implements RetryTaskLogService {
wrapper.eq(RetryTaskLogMessage::getGroupName, queryVO.getGroupName()); wrapper.eq(RetryTaskLogMessage::getGroupName, queryVO.getGroupName());
wrapper.orderByAsc(RetryTaskLogMessage::getId).orderByAsc(RetryTaskLogMessage::getRealTime); wrapper.orderByAsc(RetryTaskLogMessage::getId).orderByAsc(RetryTaskLogMessage::getRealTime);
PageDTO<RetryTaskLogMessage> selectPage = retryTaskLogMessageMapper.selectPage(pageDTO, wrapper.orderByDesc(RetryTaskLogMessage::getCreateDt)); PageDTO<RetryTaskLogMessage> selectPage = retryTaskLogMessageMapper.selectPage(pageDTO,
wrapper.orderByDesc(RetryTaskLogMessage::getCreateDt));
List<RetryTaskLogMessage> records = selectPage.getRecords(); List<RetryTaskLogMessage> records = selectPage.getRecords();
@ -156,7 +165,8 @@ public class RetryTaskLogServiceImpl implements RetryTaskLogService {
} }
messages = messages.stream().sorted((o1, o2) -> { messages = messages.stream().sorted((o1, o2) -> {
long value = Long.parseLong(o1.get(LogFieldConstants.TIME_STAMP)) - Long.parseLong(o2.get(LogFieldConstants.TIME_STAMP)); long value = Long.parseLong(o1.get(LogFieldConstants.TIME_STAMP)) - Long.parseLong(
o2.get(LogFieldConstants.TIME_STAMP));
if (value > 0) { if (value > 0) {
return 1; return 1;
@ -180,4 +190,47 @@ public class RetryTaskLogServiceImpl implements RetryTaskLogService {
RetryTaskLog retryTaskLog = retryTaskLogMapper.selectById(id); RetryTaskLog retryTaskLog = retryTaskLogMapper.selectById(id);
return RetryTaskLogResponseVOConverter.INSTANCE.convert(retryTaskLog); return RetryTaskLogResponseVOConverter.INSTANCE.convert(retryTaskLog);
} }
@Override
@Transactional
public boolean deleteById(final Long id) {
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
RetryTaskLog retryTaskLog = retryTaskLogMapper.selectOne(
new LambdaQueryWrapper<RetryTaskLog>().eq(RetryTaskLog::getRetryStatus, RetryStatusEnum.FINISH.getStatus())
.eq(RetryTaskLog::getNamespaceId, namespaceId)
.eq(RetryTaskLog::getId, id));
Assert.notNull(retryTaskLog, () -> new SnailJobServerException("数据删除失败"));
retryTaskLogMessageMapper.delete(new LambdaQueryWrapper<RetryTaskLogMessage>()
.eq(RetryTaskLogMessage::getNamespaceId, namespaceId)
.eq(RetryTaskLogMessage::getGroupName, retryTaskLog.getGroupName())
.eq(RetryTaskLogMessage::getUniqueId, retryTaskLog.getUniqueId())
);
return 1 == retryTaskLogMapper.deleteById(id);
}
@Override
@Transactional
public boolean batchDelete(final Set<Long> ids) {
String namespaceId = UserSessionUtils.currentUserSession().getNamespaceId();
List<RetryTaskLog> retryTaskLogs = retryTaskLogMapper.selectList(new LambdaQueryWrapper<RetryTaskLog>()
.eq(RetryTaskLog::getRetryStatus, RetryStatusEnum.FINISH.getStatus())
.eq(RetryTaskLog::getNamespaceId, namespaceId)
.in(RetryTaskLog::getId, ids)
);
Assert.notEmpty(retryTaskLogs, () -> new SnailJobServerException("数据不存在"));
Assert.isTrue(retryTaskLogs.size() == ids.size(), () -> new SnailJobServerException("数据不存在"));
for (final RetryTaskLog retryTaskLog : retryTaskLogs) {
retryTaskLogMessageMapper.delete(new LambdaQueryWrapper<RetryTaskLogMessage>()
.eq(RetryTaskLogMessage::getNamespaceId, namespaceId)
.eq(RetryTaskLogMessage::getGroupName, retryTaskLog.getGroupName())
.eq(RetryTaskLogMessage::getUniqueId, retryTaskLog.getUniqueId())
);
}
return 1 == retryTaskLogMapper.deleteBatchIds(ids);
}
} }