From 0e71c0b9912a1e5c600d48ae6a3a1f52cec9cbe1 Mon Sep 17 00:00:00 2001 From: TanYibin <5491541@qq.com> Date: Wed, 21 Jun 2023 12:33:32 +0800 Subject: [PATCH] 接口异常错误返回信息优化 --- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java | 5 +++-- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java | 10 +--------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java | 5 ++++- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java | 56 ++++++++++++++++++++++++++++++++++++++++---------------- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java | 3 ++- huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java | 25 +++++++++++-------------- 6 files changed, 61 insertions(+), 43 deletions(-) diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java index 096921c..c13f8d9 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/controller/WcsController.java @@ -1,5 +1,7 @@ package org.jeecg.modules.wms.api.wcs.controller; +import java.net.SocketException; + import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -59,8 +61,7 @@ public class WcsController extends HuahengBaseController { Result result = handleMultiProcess("warecellAllocation", lockKey, new MultiProcessListener() { @Override public Result<?> doProcess() { - Result result = wcsService.warecellAllocation(warecellDomain); - return result; + return wcsService.warecellAllocation(warecellDomain); } }); return result; diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java index fca4232..2338143 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/LocationAllocationServiceImpl.java @@ -107,8 +107,6 @@ public class LocationAllocationServiceImpl implements LocationAllocationService searchNumber = Integer.parseInt(value); } String lastString = "ORDER BY layer asc, id asc limit " + searchNumber; - StopWatch stopWatch = new StopWatch(); - stopWatch.start("aaa"); List<Integer> removeRoadWays = new ArrayList<>(); // 寻找可用巷道,空闲的空库位低于设定值,那么这个巷道就不能用来分配库位 for (Integer roadWay : roadWays) { @@ -122,9 +120,6 @@ public class LocationAllocationServiceImpl implements LocationAllocationService removeRoadWays.add(roadWay); } } - stopWatch.stop(); - System.out.println("waste aa:" + stopWatch.getLastTaskTimeMillis()); - stopWatch.start("bbb"); roadWays.removeAll(removeRoadWays); if (roadWays == null || roadWays.size() == 0) { throw new JeecgBootException("分配库位时, 巷道为空"); @@ -147,8 +142,6 @@ public class LocationAllocationServiceImpl implements LocationAllocationService } } locationList.removeAll(removeLocaationList); - stopWatch.stop(); - System.out.println("waste bb:" + stopWatch.getLastTaskTimeMillis()); if (locationList.size() == 0) { locationLambda = Wrappers.lambdaQuery(); locationLambda.eq(Location::getZoneCode, zoneCode).eq(Location::getWarehouseCode, warehouseCode).eq(Location::getRoadWay, roadWay) @@ -170,8 +163,7 @@ public class LocationAllocationServiceImpl implements LocationAllocationService return null; } Location location = locationList.stream().findFirst().orElse(null); - String locationCode = location.getCode(); - return locationCode; + return location.getCode(); } /** diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java index e5a244a..6639820 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsService.java @@ -1,5 +1,7 @@ package org.jeecg.modules.wms.api.wcs.service; +import java.net.SocketException; + import org.jeecg.common.api.vo.Result; import org.jeecg.modules.wms.api.wcs.entity.MaterialInfoEntity; import org.jeecg.modules.wms.api.wcs.entity.WarecellDomain; @@ -11,7 +13,8 @@ import org.jeecg.modules.wms.task.taskHeader.entity.TaskHeader; */ public interface WcsService { - /** 仓位分配 */ + /** 仓位分配 + * @throws SocketException */ Result warecellAllocation(WarecellDomain warecellDomain); /** diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java index 78bd0d7..91f73fe 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/api/wcs/service/WcsServiceImpl.java @@ -1,5 +1,6 @@ package org.jeecg.modules.wms.api.wcs.service; +import java.net.SocketException; import java.util.ArrayList; import java.util.List; import java.util.stream.Collectors; @@ -59,43 +60,57 @@ public class WcsServiceImpl implements WcsService { @Resource private IZoneService zoneService; + @Resource private ITaskHeaderService taskHeaderService; + @Resource private ITaskDetailService taskDetailService; + @Resource private IContainerService containerService; + @Resource private ILocationTypeService locationTypeService; + @Resource private ILocationHighService locationHighService; + @Resource private IParameterConfigurationService parameterConfigurationService; + @Resource private IReceiptContainerDetailService receiptContainerDetailService; + @Resource private IMaterialService materialService; + @Resource private IReceiptContainerHeaderService receiptContainerHeaderService; + @Resource private LocationAllocationService locationAllocationService; + @Resource private ILocationService locationService; + @Resource private IAddressService addressService; + @Resource private IContainerTypeService containerTypeService; /** * 库位分配 + * @throws SocketException */ @Override @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "''", bizType = "'入库单追踪'", tag = "'详情分配库位'", extra = "#extraJsonString", - msg = "'任务ID:' + #warecellDomain.getTaskNo() + ',库位编码:' + #locationCode", condition = "#receiptContainerDetailList.size() > 0", recordReturnValue = true) - @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'分配库位'", extra = "''", + msg = "'任务ID:' + #warecellDomain.getTaskNo() + ',库位编码:' + #locationCode", condition = "null != #success && #success", recordReturnValue = true) + @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'分配库位'", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result warecellAllocation(WarecellDomain warecellDomain) { log.info("开始分配库位"); String warehouseCode = warecellDomain.getWarehouseCode(); @@ -247,14 +262,15 @@ public class WcsServiceImpl implements WcsService { if (!taskHeaderService.updateById(taskHeader)) { throw new JeecgBootException("更新任务头表目标库位失败"); } - + WcsTask wcsTask = new WcsTask(); wcsTask.setToLocationCode(locationCode); wcsTask.setPreTaskNo(String.valueOf(preTaskNo)); - LogRecordContext.putVariable("locationCode", locationCode);// 操作日志收集 - LogRecordContext.putVariable("receiptContainerDetailList", receiptContainerDetailList);// 操作日志收集 - LogRecordContext.putVariable("extraJsonString", JSON.toJSONString(receiptContainerDetailList));// 操作日志收集 - LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + // 操作日志收集 + LogRecordContext.putVariable("locationCode", locationCode); + LogRecordContext.putVariable("extraJsonString", JSON.toJSONString(receiptContainerDetailList)); + LogRecordContext.putVariable("taskHeader", taskHeader); + LogRecordContext.putVariable("success", true); log.info("完成分配库位,任务号:" + taskNo + ", 库位号:" + locationCode); return Result.OK(wcsTask); } @@ -263,7 +279,7 @@ public class WcsServiceImpl implements WcsService { @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'任务下发'", extra = "''", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result wcsTaskAssign(TaskHeader taskHeader) { if (taskHeader == null) { return Result.error("wms任务为空"); @@ -415,6 +431,7 @@ public class WcsServiceImpl implements WcsService { } } LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + LogRecordContext.putVariable("success", true); return Result.ok("下发任务成功"); } @@ -500,7 +517,7 @@ public class WcsServiceImpl implements WcsService { @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'空出处理'", extra = "''", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode() + ',目标出入口:' + #taskHeader.getToPortCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result emptyOutHandle(String taskNo) { if (StringUtils.isEmpty(taskNo)) { return Result.error("任务号为空"); @@ -525,7 +542,9 @@ public class WcsServiceImpl implements WcsService { if (!success) { return Result.error("修改任务失败,空出处理失败"); } - LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + // 操作日志收集 + LogRecordContext.putVariable("taskHeader", taskHeader); + LogRecordContext.putVariable("success", true); return Result.ok("空出处理成功"); } @@ -533,7 +552,7 @@ public class WcsServiceImpl implements WcsService { @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'重入处理'", extra = "''", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode() + ',目标出入口:' + #taskHeader.getToPortCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result reentryHandle(String taskNo) { // 1、判断非空字段 if (StringUtils.isEmpty(taskNo)) { @@ -630,7 +649,9 @@ public class WcsServiceImpl implements WcsService { TaskReentryEntity taskReentryEntity = new TaskReentryEntity(); taskReentryEntity.setTaskNo(Integer.parseInt(taskNo)); taskReentryEntity.setRedirectionLocationCode(locationCode); - LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + // 操作日志收集 + LogRecordContext.putVariable("taskHeader", taskHeader); + LogRecordContext.putVariable("success", true); return Result.ok(taskReentryEntity); } @@ -638,7 +659,7 @@ public class WcsServiceImpl implements WcsService { @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'取货错处理'", extra = "''", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode() + ',目标出入口:' + #taskHeader.getToPortCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result pickupErrorHandle(String taskNo) { // 1、判断非空字段 if (StringUtils.isEmpty(taskNo)) { @@ -662,6 +683,7 @@ public class WcsServiceImpl implements WcsService { return Result.error("取货错处理失败,更新任务失败"); } LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + LogRecordContext.putVariable("success", true); return Result.ok("取货错处理成功"); } @@ -669,7 +691,7 @@ public class WcsServiceImpl implements WcsService { @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "#taskHeader.getId()", bizType = "'任务追踪'", tag = "'到达站台'", extra = "''", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode() + ',目标出入口:' + #taskHeader.getToPortCode()", - recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) public Result arrivedNotice(String taskNo, String port) { TaskHeader taskHeader = taskHeaderService.getById(taskNo); if (taskHeader == null) { @@ -685,7 +707,9 @@ public class WcsServiceImpl implements WcsService { if (!result) { return Result.error("更新到达站台失败"); } - LogRecordContext.putVariable("taskHeader", taskHeader);// 操作日志收集 + // 操作日志收集 + LogRecordContext.putVariable("taskHeader", taskHeader); + LogRecordContext.putVariable("success", true); return Result.ok("更新到达站台成功"); } diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java index c4198a1..6279bfe 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/framework/controller/HuahengBaseController.java @@ -5,6 +5,7 @@ import java.util.concurrent.TimeUnit; import javax.annotation.Nonnull; import org.jeecg.common.api.vo.Result; +import org.jeecg.common.exception.JeecgBootException; import org.jeecg.utils.support.RedissonDistributedLocker; import org.springframework.beans.factory.annotation.Autowired; @@ -73,7 +74,7 @@ public class HuahengBaseController { result = multiProcessListener.doProcess(); } catch (Exception e) { log.error("[{}] 执行分布式事务失败 lockKey = {},errorMessage = {}", taskName, fullLockKey, ExceptionUtil.getMessage(e), e); - throw ExceptionUtil.convertFromOrSuppressedThrowable(e, RuntimeException.class); + return Result.error(ExceptionUtil.getMessage(e)); } finally { redissonDistributedLocker.unlock(fullLockKey); final long finishTime = SystemClock.now(); diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java index 5aa5ae7..febd237 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/task/taskHeader/service/impl/TaskHeaderServiceImpl.java @@ -196,8 +196,8 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea return Result.error("创建移库任务时,起始库位:" + fromLocationCode + "未找到"); } Location toLocation = locationService.getLocationByCode(toLocationCode, warehouseCode); - if (fromLocation == null) { - return Result.error("创建移库任务时,起始库位:" + fromLocationCode + "未找到"); + if (toLocation == null) { + return Result.error("创建移库任务时,目标库位:" + toLocation + "未找到"); } String containerCode = fromLocation.getContainerCode(); // 这里增加组盘校验,如果此托盘存在未完成的组盘数据,则不能移库 @@ -979,11 +979,11 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "''", bizType = "'任务追踪'", tag = "'入库任务完成'", extra = "#extraJsonString1", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode()", - condition = "#taskDetailList.size() > 0", recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) @OperationLog(bizId = "''", bizType = "'入库单追踪'", tag = "'入库任务完成'", extra = "#extraJsonString1", msg = "'任务ID:' + #taskHeader.getId() + ',库位编码:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode()", - condition = "#taskDetailList.size() > 0", recordReturnValue = true) - @OperationLog(bizId = "''", bizType = "'入库单追踪'", tag = "'详情入库完成'", extra = "#extraJsonString2", msg = "''", condition = "#receiptDetaiList.size() > 0", + condition = "null != #success && #success", recordReturnValue = true) + @OperationLog(bizId = "''", bizType = "'入库单追踪'", tag = "'详情入库完成'", extra = "#extraJsonString2", msg = "''", condition = "null != #success && #success", recordReturnValue = true) public Result completeReceiptTask(TaskHeader taskHeader) { if (taskHeader == null) { @@ -1161,11 +1161,10 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea } receiptDetaiList = receiptDetaiList.stream().filter(t -> t.getStatus().equals(QuantityConstant.RECEIPT_HEADER_COMPLETED)).collect(Collectors.toList()); LogRecordContext.putVariable("taskHeader", taskHeader); - LogRecordContext.putVariable("taskDetailList", taskDetailList); LogRecordContext.putVariable("extraJsonString1", JSON.toJSONString(taskDetailList)); - LogRecordContext.putVariable("receiptDetaiList", receiptDetaiList); LogRecordContext.putVariable("extraJsonString2", JSON.toJSONString(receiptDetaiList)); - log.info("完成入库任务, 任务号" + taskHeader.getId()); + LogRecordContext.putVariable("success", true);// 操作日志收集 + log.info("完成入库任务, 任务号:" + taskHeader.getId()); return Result.ok("完成入库任务"); } @@ -1178,11 +1177,11 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea @Transactional(rollbackFor = Exception.class) @OperationLog(bizId = "''", bizType = "'任务追踪'", tag = "'出库任务完成'", extra = "#extraJsonString1", msg = "'任务类型:' + #taskHeader.getTaskType() + ',起始库位:' + #taskHeader.getFromLocationCode() + ',目标库位:' + #taskHeader.getToLocationCode() + ',容器编码:' + #taskHeader.getContainerCode()", - condition = "#taskDetailList.size() > 0", recordReturnValue = true) + condition = "null != #success && #success", recordReturnValue = true) @OperationLog(bizId = "''", bizType = "'出库单追踪'", tag = "'出库任务完成'", extra = "#extraJsonString1", msg = "'任务ID:' + #taskHeader.getId() + ',库位编码:' + #taskHeader.getFromLocationCode() + ',容器编码:' + #taskHeader.getContainerCode() + ',目标出入口:' + #taskHeader.getToPortCode()", - recordReturnValue = true) - @OperationLog(bizId = "''", bizType = "'出库单追踪'", tag = "'详情出库完成'", extra = "#extraJsonString2", msg = "''", condition = "#shipmentDetailList.size() > 0", + condition = "null != #success && #success", recordReturnValue = true) + @OperationLog(bizId = "''", bizType = "'出库单追踪'", tag = "'详情出库完成'", extra = "#extraJsonString2", msg = "''", condition = "null != #success && #success", recordReturnValue = true) public Result completeShipmentTask(TaskHeader taskHeader) { if (taskHeader == null) { @@ -1193,7 +1192,6 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea String fromLocationCode = taskHeader.getFromLocationCode(); String toLocationCode = taskHeader.getToLocationCode(); String containerCode = taskHeader.getContainerCode(); - String zoneCode = taskHeader.getZoneCode(); int taskType = taskHeader.getTaskType(); List<TaskDetail> taskDetailList = taskDetailService.getTaskDetailListByTaskId(taskHeader.getId()); boolean success = false; @@ -1383,10 +1381,9 @@ public class TaskHeaderServiceImpl extends ServiceImpl<TaskHeaderMapper, TaskHea // 操作记录添加 shipmentDetailList = shipmentDetailList.stream().filter(t -> t.getStatus().equals(QuantityConstant.SHIPMENT_HEADER_COMPLETED)).collect(Collectors.toList()); LogRecordContext.putVariable("taskHeader", taskHeader); - LogRecordContext.putVariable("taskDetailList", taskDetailList); // 操作记录添加 LogRecordContext.putVariable("extraJsonString1", JSON.toJSONString(taskDetailList)); - LogRecordContext.putVariable("shipmentDetailList", shipmentDetailList); LogRecordContext.putVariable("extraJsonString2", JSON.toJSONString(shipmentDetailList)); + LogRecordContext.putVariable("success", true); log.info("完成出库任务,任务号:" + taskHeader.getId()); return Result.ok("完成出库任务"); } -- libgit2 0.22.2