From 57ab5d0df1c3015e96b675f526cc78e0604f7e4d Mon Sep 17 00:00:00 2001 From: Huluwa22 <2667400744@qq.com> Date: Sun, 23 Feb 2025 15:55:24 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E5=BA=93=E4=BD=8D=E4=BF=A1=E6=81=AF):=20?= =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E5=B1=82=E6=95=B0=E8=8E=B7=E5=8F=96=E5=BA=93?= =?UTF-8?q?=E4=BD=8D=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../wms/controller/LocationController.java | 113 ++++++++++++++---- 1 file changed, 92 insertions(+), 21 deletions(-) diff --git a/src/main/java/com/wms/controller/LocationController.java b/src/main/java/com/wms/controller/LocationController.java index 967b60c..a520ec1 100644 --- a/src/main/java/com/wms/controller/LocationController.java +++ b/src/main/java/com/wms/controller/LocationController.java @@ -30,6 +30,7 @@ import org.springframework.transaction.interceptor.TransactionAspectSupport; import org.springframework.web.bind.annotation.*; import java.util.*; +import java.util.stream.Collectors; /** * WMS库位控制类 @@ -56,6 +57,7 @@ public class LocationController extends BaseController { private final HttpServletRequest servletRequest; + /** * 查询库位 * @@ -70,8 +72,7 @@ public class LocationController extends BaseController { try { // 查询出所有符合条件的库位 Location location1 = new Location(); - //location1.setLocationId("A11-15-2"); - //location1.setWareArea("A"); + location1.setLayer(location.getLayer()); location1.setAreaId(2); List locations = locationService.selLocations(location1); if (locations.isEmpty()) { @@ -81,37 +82,35 @@ public class LocationController extends BaseController { rsp.setMessage("查询库位发生错误:库位不存在"); return JSON.toJSONString(rsp); } - List rowLocations = new LinkedList<>(); - // 查找到最大的排 - locations.sort(Comparator.comparing(Location::getQueue).reversed()); - int maxRow = locations.get(0).getQueue(); - // 按排查找库位 - for (int i = 0; i < maxRow; i++) { - int finalI = i; + List rowLocations = new ArrayList<>(); + // 查找所有排 + List queueList = locations.stream().map(l -> l.getQueue()).distinct().sorted().toList(); + + + for (Integer queue : queueList) { + // 当前排信息 List currentRowLocations = new ArrayList<>(locations.stream() - .filter(l -> l.getQueue().equals(finalI + 1)) + .filter(l -> l.getQueue().equals(queue)) .toList()); - // 先查找每一层的库位 + // 当前排的层数 + List lineList = currentRowLocations.stream().map(l -> l.getLine()).distinct().sorted().toList(); + // 先查找每一列的库位 List layerLocations = new LinkedList<>(); - // 找到这一排最大的层 - currentRowLocations.sort(Comparator.comparing(Location::getLayer).reversed()); - int maxLayer = currentRowLocations.get(0).getLayer(); - // 按照每一列查找库位 - for (int j = 0; j < maxLayer; j++) { - int finalJ = j; + for (Integer line : lineList ) { List currentLayerLocations = currentRowLocations.stream() - .filter(l -> l.getLayer().equals(finalJ + 1)) + .filter(l -> l.getLine().equals(line)) .toList(); LayerLocation tempLayerLocation = new LayerLocation(); - tempLayerLocation.setLayer(finalJ + 1); + tempLayerLocation.setLayer(line); tempLayerLocation.setCurrentColLocations(currentLayerLocations); layerLocations.add(tempLayerLocation); } RowLocation tempRowLocation = new RowLocation(); - tempRowLocation.setRow(finalI + 1); + tempRowLocation.setRow(queue); tempRowLocation.setCurrentLayerLocations(layerLocations); rowLocations.add(tempRowLocation); } + logger.info("查询库位数据成功,库区:{}", location.getAreaId()); // 设置最终数据 rsp.setReturnData(rowLocations); @@ -128,6 +127,78 @@ public class LocationController extends BaseController { } } +// /** +// * 查询库位 +// * +// * @param location 查询参数 +// * @return 结果 +// */ +// @PostMapping("/getLocations") +// @ResponseBody +// public String getLocations(@RequestBody Location location) { +// // 创建响应信息 +// ResponseEntity rsp = new ResponseEntity(); +// try { +// // 查询出所有符合条件的库位 +// Location location1 = new Location(); +// //location1.setLocationId("A11-15-2"); +// //location1.setWareArea("A"); +// location1.setAreaId(2); +// List locations = locationService.selLocations(location1); +// if (locations.isEmpty()) { +// logger.error("查询库位发生错误:库位不存在"); +// // 返回错误 +// rsp.setCode(ResponseCode.ERROR.getCode()); +// rsp.setMessage("查询库位发生错误:库位不存在"); +// return JSON.toJSONString(rsp); +// } +// List rowLocations = new LinkedList<>(); +// // 查找到最大的排 +// locations.sort(Comparator.comparing(Location::getQueue).reversed()); +// int maxRow = locations.get(0).getQueue(); +// // 按排查找库位 +// for (int i = 0; i < maxRow; i++) { +// int finalI = i; +// List currentRowLocations = new ArrayList<>(locations.stream() +// .filter(l -> l.getQueue().equals(finalI + 1)) +// .toList()); +// // 先查找每一层的库位 +// List layerLocations = new LinkedList<>(); +// // 找到这一排最大的层 +// currentRowLocations.sort(Comparator.comparing(Location::getLayer).reversed()); +// int maxLayer = currentRowLocations.get(0).getLayer(); +// // 按照每一列查找库位 +// for (int j = 0; j < maxLayer; j++) { +// int finalJ = j; +// List currentLayerLocations = currentRowLocations.stream() +// .filter(l -> l.getLayer().equals(finalJ + 1)) +// .toList(); +// LayerLocation tempLayerLocation = new LayerLocation(); +// tempLayerLocation.setLayer(finalJ + 1); +// tempLayerLocation.setCurrentColLocations(currentLayerLocations); +// layerLocations.add(tempLayerLocation); +// } +// RowLocation tempRowLocation = new RowLocation(); +// tempRowLocation.setRow(finalI + 1); +// tempRowLocation.setCurrentLayerLocations(layerLocations); +// rowLocations.add(tempRowLocation); +// } +// logger.info("查询库位数据成功,库区:{}", location.getAreaId()); +// // 设置最终数据 +// rsp.setReturnData(rowLocations); +// // 返回成功 +// rsp.setCode(ResponseCode.OK.getCode()); +// rsp.setMessage("查询库位成功"); +// return JSON.toJSONString(rsp); +// } catch (Exception e) { +// logger.info("查询库位发生错误:{}", e.getMessage()); +// // 返回其他异常 +// rsp.setCode(ResponseCode.ERROR.getCode()); +// rsp.setMessage(e.getMessage()); +// return JSON.toJSONString(rsp); +// } +// } + /** * 更新库位状态 * @@ -171,7 +242,7 @@ public class LocationController extends BaseController { } /** - * 更新库位状态 + * 查询空闲可用库位 * * @param location 库位 * @return 结果