fix: 任务定位

This commit is contained in:
2026-07-16 15:44:58 +08:00
parent be46cf49c5
commit 1d12732646
65 changed files with 11693 additions and 18 deletions

View File

@@ -20,6 +20,11 @@
<groupId>cn.nl.cloud</groupId>
<artifactId>nl-spring-boot-starter-env</artifactId>
</dependency>
<!-- DB 相关 -->
<dependency>
<groupId>cn.nl.cloud</groupId>
<artifactId>nl-spring-boot-starter-redis</artifactId>
</dependency>
<!-- 依赖服务 -->
<dependency>

View File

@@ -1,5 +1,6 @@
package cn.code.nl.module.task.service.transporttask;
import cn.code.nl.framework.common.exception.ServiceException;
import cn.code.nl.framework.common.pojo.PageResult;
import cn.code.nl.framework.common.util.object.BeanUtils;
import cn.code.nl.framework.execute.biz.api.TaskCommonApi;
@@ -21,6 +22,8 @@ import cn.hutool.core.util.StrUtil;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
@@ -55,6 +58,9 @@ public class TransportTaskServiceImpl implements TransportTaskService {
@Resource
private TaskCommonApiFactory taskCommonApiFactory;
@Resource
private RedissonClient redissonClient;
/**
* 操作类型 -> 处理方法 路由表ACS 反馈与 PC 端操作共用)
*/
@@ -183,12 +189,25 @@ public class TransportTaskServiceImpl implements TransportTaskService {
*/
@Override
public void dispatchOperation(TransportTaskDO task, TaskOperationTypeEnum type, AcsFeedbackReqDTO reqDTO) {
BiConsumer<TransportTaskDO, AcsFeedbackReqDTO> handler = operationHandlers.get(type);
if (handler == null) {
log.warn("操作类型未注册处理器, taskId={}, type={}", task.getTaskId(), type.getCode());
return;
RLock lock = redissonClient.getLock(String.valueOf(task.getTaskId()));
if (lock.tryLock()) {
try {
BiConsumer<TransportTaskDO, AcsFeedbackReqDTO> handler = operationHandlers.get(type);
if (handler == null) {
log.warn("操作类型未注册处理器, taskId={}, type={}", task.getTaskId(), type.getCode());
return;
}
handler.accept(task, reqDTO);
} catch (Exception ex) {
log.error("[messageResend][执行异常][lockKey={}]", task.getTaskId(), ex);
} finally {
if (lock.isHeldByCurrentThread()) {
lock.unlock();
}
}
} else {
throw new ServiceException(5007, "任务标识为:" + task.getTaskId() + "的任务正在操作中!");
}
handler.accept(task, reqDTO);
}
/**