diff --git a/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java b/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java index 94828e57..7b7079e6 100644 --- a/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java +++ b/src/main/java/com/dispose/dispose/impl/HaoHanImpl.java @@ -112,11 +112,6 @@ public class HaoHanImpl implements DisposeEntryManager { return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); } - if (rsp.getState() != ErrorCode.ERR_OK.getCode()) { - log.error("----Error Haohan stop task {} return error: {}, {}", devTaskId, rsp.getState(), rsp.getMsg()); - return new MulReturnType<>(ErrorCode.ERR_HAOHAN_ERROR, null); - } - log.info("----Finish Haohan Stop Cleanup Task: {}", devTaskId); return new MulReturnType<>(ErrorCode.ERR_OK, null); }catch (JsonProcessingException e) { diff --git a/src/main/java/com/dispose/mapper/TaskInfoMapper.java b/src/main/java/com/dispose/mapper/TaskInfoMapper.java index 4c63663b..34559854 100644 --- a/src/main/java/com/dispose/mapper/TaskInfoMapper.java +++ b/src/main/java/com/dispose/mapper/TaskInfoMapper.java @@ -34,7 +34,7 @@ public interface TaskInfoMapper extends Mapper, MySqlMapper * @param deviceId the device id * @return the task info */ - List getTaskInfo(@Param("taskId") Long taskId, + TaskInfo getTaskInfo(@Param("taskId") Long taskId, @Param("deviceId") Long deviceId); /** diff --git a/src/main/java/com/dispose/service/impl/TaskServiceImpl.java b/src/main/java/com/dispose/service/impl/TaskServiceImpl.java index 7b507705..d3b4f4de 100644 --- a/src/main/java/com/dispose/service/impl/TaskServiceImpl.java +++ b/src/main/java/com/dispose/service/impl/TaskServiceImpl.java @@ -254,34 +254,28 @@ public class TaskServiceImpl implements TaskService { dev.forEach(k -> { DisposeEntryManager dp = DeviceRouter.getDeviceRouterFactory(k.getType(), k.getIpAddr()); - List taskInfoList = taskInfoMapper.getTaskInfo(taskId, k.getId()); + TaskInfo taskInfo = taskInfoMapper.getTaskInfo(taskId, k.getId()); - taskInfoList.forEach(t -> { - if (t.getExternId() == null) { - t.setExternId(-1L); - } - - // 异步启动处置任务 - CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()], t.getExternId())) - .whenComplete((v, ex) -> { - if (ex != null) { + // 异步启动处置任务 + CompletableFuture.supplyAsync(() -> dp.stopDispose(task.getDisposeIp(), DeviceCapacity.values()[task.getType()], taskInfo.getExternId())) + .whenComplete((v, ex) -> { + if (ex != null) { + // 恢复缓存中任务状态到先前状态 + taskCacheManager.upgradeTaskStatus(taskId, prdStatus); + log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage()); + } else { + if (v.getFirstParam() != ErrorCode.ERR_OK) { // 恢复缓存中任务状态到先前状态 taskCacheManager.upgradeTaskStatus(taskId, prdStatus); - log.error("Stop task: taskId:{}, error:{}", taskId, ex.getMessage()); + log.error("Stop task: taskId:{}, error:{}", taskId, v.getFirstParam().getMsg()); } else { - if (v.getFirstParam() != ErrorCode.ERR_OK) { - // 恢复缓存中任务状态到先前状态 - taskCacheManager.upgradeTaskStatus(taskId, prdStatus); - log.error("Stop task: taskId:{}, error:{}", taskId, v.getFirstParam().getMsg()); - } else { - // 任务执行完成后更新数据库处置任务状态 - finishTask(taskId); - log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}", - taskId, task.getDisposeIp(), task.getType()); - } + // 任务执行完成后更新数据库处置任务状态 + finishTask(taskId); + log.info("Stop task finished: taskId:{}, disposeId:{}, type:{}", + taskId, task.getDisposeIp(), task.getType()); } - }); - }); + } + }); }); } else { log.error("No such task: taskId:{}", taskId); diff --git a/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java b/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java index a13e6f0c..43a43d35 100644 --- a/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java +++ b/src/test/java/com/dispose/test/mapper/TaskInfoMapperTest.java @@ -133,10 +133,10 @@ public class TaskInfoMapperTest extends InitTestEnvironment { for (TaskInfoDetail task : taskInfoDetailList ) { log.info("taskId-->{}, deviceId-->{}", task.getId(), task.getDeviceId()); - List taskInfoList = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId()); - if (taskInfoList.size() > 0) { - Assert.assertNotEquals(taskInfoList.size(), 0); - log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfoList)); + TaskInfo taskInfo = taskInfoMapper.getTaskInfo(task.getId(), task.getDeviceId()); + if (taskInfo != null) { + Assert.assertNotNull(taskInfo); + log.info(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(taskInfo)); } } }