From ea50de60adc0a47496ca237dee5b91ecc7e09246 Mon Sep 17 00:00:00 2001 From: liyongde <1419499670@qq.com> Date: Thu, 17 Aug 2023 09:34:57 +0800 Subject: [PATCH] =?UTF-8?q?opt:=20=E9=94=99=E8=AF=AF=E4=BB=BB=E5=8A=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nl/wms/sch/task_manage/AbstractTask.java | 25 ++++++++----------- .../src/test/java/org/nl/point/test.java | 13 ++++++++++ 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java index 32dd6b7..941fce9 100644 --- a/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java +++ b/lms/nladmin-system/nlsso-server/src/main/java/org/nl/wms/sch/task_manage/AbstractTask.java @@ -116,26 +116,21 @@ public abstract class AbstractTask { resultForAcs.setCode(HttpStatus.HTTP_BAD_REQUEST); resultForAcs.setMessage(e.getMessage()); } - // todo: 可优化点:解除双层循环判断任务的完成性 // 如果下发完毕,就修改状态 if (resultForAcs.getCode() == 200) { // 解析 JSONArray errArr = resultForAcs.getErrArr(); for (SchBaseTask schBaseTask : taskList) { - if (errArr == null) { - schBaseTask.setTask_status(TaskStatus.ISSUED.getCode()); - } else { - schBaseTask.setTask_status(TaskStatus.ISSUED.getCode()); - // 判断是否是出错的任务 - for (int i = 0; i < errArr.size(); i++) { - JSONObject errObj = errArr.getJSONObject(i); - String taskCode = errObj.getString("task_code"); - if (taskCode.equals(schBaseTask.getTask_code())) { - // 出错的任务就设置出错信息为备注,不是出错就设置下发 - schBaseTask.setTask_status(TaskStatus.CREATED.getCode()); - schBaseTask.setRemark(errObj.getString("message")); - break; - } + schBaseTask.setTask_status(TaskStatus.ISSUED.getCode()); + // 判断是否是出错的任务 + for (int i = 0; ObjectUtil.isNotEmpty(errArr) && i < errArr.size(); i++) { + JSONObject errObj = errArr.getJSONObject(i); + String taskCode = errObj.getString("task_code"); + if (taskCode.equals(schBaseTask.getTask_code())) { + // 出错的任务就设置出错信息为备注,不是出错就设置下发 + schBaseTask.setTask_status(TaskStatus.CREATED.getCode()); + schBaseTask.setRemark(errObj.getString("message")); + break; } } } diff --git a/lms/nladmin-system/nlsso-server/src/test/java/org/nl/point/test.java b/lms/nladmin-system/nlsso-server/src/test/java/org/nl/point/test.java index 6eea692..1a6f940 100644 --- a/lms/nladmin-system/nlsso-server/src/test/java/org/nl/point/test.java +++ b/lms/nladmin-system/nlsso-server/src/test/java/org/nl/point/test.java @@ -1,7 +1,9 @@ package org.nl.point; import cn.hutool.core.date.DateUtil; +import cn.hutool.core.util.ObjectUtil; import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import org.checkerframework.checker.units.qual.A; @@ -11,6 +13,8 @@ import org.nl.wms.ext.acs.service.dto.to.wms.ApplyDeviceDto; import org.nl.wms.ext.acs.service.dto.to.wms.ApplyTaskRequest; import org.nl.wms.sch.region.service.ISchBaseRegionService; import org.nl.wms.sch.region.service.dao.SchBaseRegion; +import org.nl.wms.sch.task.service.dao.SchBaseTask; +import org.nl.wms.sch.task_manage.task.core.TaskStatus; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; @@ -98,5 +102,14 @@ public class test { JSONObject jsonObject = JSONObject.parseObject(s); System.out.println(jsonObject); } + @Test + public void test05() { + JSONArray errArr = null; + for (int i = 0; ObjectUtil.isNotEmpty(errArr) && i < errArr.size(); i++) { + JSONObject errObj = errArr.getJSONObject(i); + System.out.println("1"); + } + System.out.println("2"); + } }