diff --git a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java index 14e3d20..11a43e1 100644 --- a/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java +++ b/huaheng-wms-core/src/main/java/org/jeecg/modules/wms/config/locationMonitor/controller/LocationMonitorController.java @@ -1,9 +1,11 @@ package org.jeecg.modules.wms.config.locationMonitor.controller; + import java.math.BigDecimal; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.stream.Collectors; +import java.util.stream.Stream; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; @@ -26,169 +28,147 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import io.swagger.annotations.Api; - /** +/** * @Description: 库存监控 * @Author: lty - * @Date: 2023/1/29 + * @Date: 2023/1/29 */ -@Api(tags="库存监控") +@Api(tags = "库存监控") @RestController @RequestMapping("/location/locationMonitor") @Slf4j -public class LocationMonitorController{ - @Autowired - private IContainerService containerService; - @Resource - private ILocationService locationService; - @Resource - private IInventoryDetailService inventoryDetailService; +public class LocationMonitorController { + @Autowired + private IContainerService containerService; + @Resource + private ILocationService locationService; + @Resource + private IInventoryDetailService inventoryDetailService; - /** - * 库存概括 - */ - @GetMapping("/getStatus") - @ResponseBody - public Result getStatus(String zoneCode) { - HashMap<String, Integer> map = new HashMap<>(); - LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery(); - queryWrapper.eq(Location::getZoneCode,zoneCode); - List<Location> locationList = locationService.list(queryWrapper); - map.put("location", locationList.size()); - queryWrapper = Wrappers.lambdaQuery(); - queryWrapper.and(wrapper->wrapper.isNull(Location::getContainerCode).or().eq(Location::getContainerCode,"")) - .eq(Location::getZoneCode,zoneCode); - List<Location> emptyLocationList = locationService.list(queryWrapper); - map.put("emptyLocation", emptyLocationList.size()); - LambdaQueryWrapper<Container> containerLambdaQueryWrapper2 = Wrappers.lambdaQuery(); - containerLambdaQueryWrapper2.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_EMPTY); - List<Container> containerList2 = containerService.list(containerLambdaQueryWrapper2); - List<String> containerCodeList2 = containerList2.stream().map(Container::getCode).collect(Collectors.toList()); - LambdaQueryWrapper<Location> locationLambdaQueryWrapper2 = Wrappers.lambdaQuery(); - locationLambdaQueryWrapper2.in(Location::getContainerCode, containerCodeList2); - locationLambdaQueryWrapper2.eq(Location::getZoneCode, zoneCode); - List<Location> haveEmptyContainLocation = locationService.list(locationLambdaQueryWrapper2); - map.put("haveContainLocation", haveEmptyContainLocation.size()); - LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); - containerLambdaQueryWrapper.eq(Container::getStatus, QuantityConstant.STATUS_CONTAINER_SOME); - List<Container> containerList = containerService.list(containerLambdaQueryWrapper); - int containerListSize = containerList.size(); - List<String> containerCodeList = containerList.stream().map(Container::getCode).collect(Collectors.toList()); - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); - locationLambdaQueryWrapper.in(containerListSize !=0, Location::getContainerCode, containerCodeList); - locationLambdaQueryWrapper.eq(Location::getZoneCode, zoneCode); - List<Location> haveInventoryLocation = locationService.list(locationLambdaQueryWrapper); - map.put("haveInventoryLocation", haveInventoryLocation.size()); - return Result.ok(map); - } + /** + * 库存概括 + */ + @GetMapping("/getStatus") + @ResponseBody + public Result getStatus(String zoneCode) { + HashMap<String, Integer> map = new HashMap<>(); + LambdaQueryWrapper<Location> queryWrapper = Wrappers.lambdaQuery(); + queryWrapper.select(Location::getStatus,Location::getContainerCode).eq(Location::getZoneCode, zoneCode); + List<Location> locationList = locationService.list(queryWrapper); + map.put("location", locationList.size()); + //换stream进行数据拣选速度更快 + List<Location> emptyLocationList = locationList.stream().filter( + t -> StringUtils.isEmpty(t.getContainerCode())).collect(Collectors.toList()); + map.put("emptyLocation", emptyLocationList.size()); + LambdaQueryWrapper<Container> containerLambdaQueryWrapper = Wrappers.lambdaQuery(); + containerLambdaQueryWrapper.select(Container::getCode, Container::getStatus); + List<Container> containerList = containerService.list(); + List<String> containerCodeList = containerList.stream().filter(t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY)).map(Container::getCode).collect(Collectors.toList()); + List<Location> haveEmptyContainLocation = locationList.stream().filter( + t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY) && StringUtils.isNotEmpty(t.getContainerCode()) + && containerCodeList.contains(t.getContainerCode())).collect(Collectors.toList()); + map.put("haveContainLocation", haveEmptyContainLocation.size()); + List<String> containerCodeList1 = containerList.stream().filter(t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_SOME)).map(Container::getCode).collect(Collectors.toList()); + List<Location> haveInventoryLocationList = locationList.stream().filter( + t -> t.getStatus().equals(QuantityConstant.STATUS_CONTAINER_EMPTY) && StringUtils.isNotEmpty(t.getContainerCode()) + && containerCodeList1.contains(t.getContainerCode())).collect(Collectors.toList()); + map.put("haveInventoryLocation", haveInventoryLocationList.size()); + return Result.ok(map); + } - /** - * 查询库位列表 - */ - @PostMapping("/getLocationInfo") - @ResponseBody - public Result getLocationInfo (String type, String row, String line, String layer, String grid, HttpServletRequest req) { - if(StringUtils.isEmpty(type)) { - return Result.error("type不能为空"); - } - String warehouseCode = HuahengJwtUtil.getWarehouseCodeByToken(req); - /* 查询库位信息*/ - LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); - locationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(row), Location::getRow, row) - .eq(StringUtils.isNotEmpty(line), Location::getIcolumn, line) - .eq(StringUtils.isNotEmpty(layer), Location::getLayer, layer) - .eq(StringUtils.isNotEmpty(grid),Location::getGrid, grid) - .eq(Location::getWarehouseCode, warehouseCode) - .eq(StringUtils.isNotEmpty(type), Location::getZoneCode, type); - List<Location> locations = locationService.list(locationLambdaQueryWrapper); - List<Location> locationList = new ArrayList<>(); + /** + * 查询库位列表 + */ + @PostMapping("/getLocationInfo") + @ResponseBody + public Result getLocationInfo(String type, String row, String line, String layer, String grid, HttpServletRequest req) { + if (StringUtils.isEmpty(type)) { + return Result.error("type不能为空"); + } + String warehouseCode = HuahengJwtUtil.getWarehouseCodeByToken(req); + /* 查询库位信息*/ + LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); + locationLambdaQueryWrapper.eq(StringUtils.isNotEmpty(row), Location::getRow, row) + .eq(StringUtils.isNotEmpty(line), Location::getIcolumn, line) + .eq(StringUtils.isNotEmpty(layer), Location::getLayer, layer) + .eq(StringUtils.isNotEmpty(grid), Location::getGrid, grid) + .eq(Location::getWarehouseCode, warehouseCode) + .eq(StringUtils.isNotEmpty(type), Location::getZoneCode, type); + List<Location> locations = locationService.list(locationLambdaQueryWrapper); + List<Location> locationList = new ArrayList<>(); - /* 查询库存明细*/ - LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery(); - inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode); - List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda); + /* 查询库存明细*/ + LambdaQueryWrapper<InventoryDetail> inventoryDetailLambda = Wrappers.lambdaQuery(); + inventoryDetailLambda.eq(InventoryDetail::getWarehouseCode, warehouseCode); + List<InventoryDetail> inventoryDetailList = inventoryDetailService.list(inventoryDetailLambda); - for (Location location1 : locations) { - InventoryDetail inventoryDetail = null; - String materialName = null; - for (InventoryDetail inventoryDetail2 : inventoryDetailList) { - if(location1.getCode().equals(inventoryDetail2.getLocationCode())) { - inventoryDetail = inventoryDetail2; - } - } - List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 -> - inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList()); + for (Location location1 : locations) { + InventoryDetail inventoryDetail = null; + String materialName = null; + for (InventoryDetail inventoryDetail2 : inventoryDetailList) { + if (location1.getCode().equals(inventoryDetail2.getLocationCode())) { + inventoryDetail = inventoryDetail2; + } + } + List<InventoryDetail> inventoryDetails = inventoryDetailList.stream().filter(inventoryDetail1 -> + inventoryDetail1.getLocationCode().equals(location1.getCode())).collect(Collectors.toList()); - int locationAttribute = 0; - String status = location1.getStatus(); - String containerCode = location1.getContainerCode(); - List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList()); - List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList()); - List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList()); - List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList()); - if(QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) { - if(StringUtils.isEmpty(containerCode)) { - locationAttribute = LocationStatus.IDLE_EMPTY_LOCATION; - } else { - if(inventoryDetail == null) { - locationAttribute = LocationStatus.IDLE_EMPTY_CONTAINER; - } else { - location1.setMaterialName(materialNameList); - location1.setMaterialCode(materialCodeList); - location1.setBatch(batchList); - location1.setQty(qtyList); - locationAttribute = LocationStatus.IDLE_FULL_CONTAINER; - } - } - } else if(QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) { - if(StringUtils.isEmpty(containerCode)) { - locationAttribute = LocationStatus.LOCK_EMPTY_LOCATION; - } else { - if(inventoryDetail == null) { - locationAttribute = LocationStatus.LOCK_EMPTY_CONTAINER; - } else { - location1.setMaterialName(materialNameList); - location1.setMaterialCode(materialCodeList); - location1.setBatch(batchList); - location1.setQty(qtyList); - locationAttribute = LocationStatus.LOCK_FULL_CONTAINER; - } - } - } + int locationAttribute = 0; + String status = location1.getStatus(); + String containerCode = location1.getContainerCode(); + List<String> materialNameList = inventoryDetails.stream().map(InventoryDetail::getMaterialName).collect(Collectors.toList()); + List<String> batchList = inventoryDetails.stream().map(InventoryDetail::getBatch).collect(Collectors.toList()); + List<String> materialCodeList = inventoryDetails.stream().map(InventoryDetail::getMaterialCode).collect(Collectors.toList()); + List<BigDecimal> qtyList = inventoryDetails.stream().map(InventoryDetail::getQty).collect(Collectors.toList()); + if (QuantityConstant.STATUS_LOCATION_EMPTY.equals(status)) { + if (StringUtils.isEmpty(containerCode)) { + locationAttribute = LocationStatus.IDLE_EMPTY_LOCATION; + } else { + if (inventoryDetail == null) { + locationAttribute = LocationStatus.IDLE_EMPTY_CONTAINER; + } else { + location1.setMaterialName(materialNameList); + location1.setMaterialCode(materialCodeList); + location1.setBatch(batchList); + location1.setQty(qtyList); + locationAttribute = LocationStatus.IDLE_FULL_CONTAINER; + } + } + } else if (QuantityConstant.STATUS_LOCATION_LOCK.equals(status)) { + if (StringUtils.isEmpty(containerCode)) { + locationAttribute = LocationStatus.LOCK_EMPTY_LOCATION; + } else { + if (inventoryDetail == null) { + locationAttribute = LocationStatus.LOCK_EMPTY_CONTAINER; + } else { + location1.setMaterialName(materialNameList); + location1.setMaterialCode(materialCodeList); + location1.setBatch(batchList); + location1.setQty(qtyList); + locationAttribute = LocationStatus.LOCK_FULL_CONTAINER; + } + } + } -// if(location1.getDeleted()) { -// if(StringUtils.isEmpty(containerCode)) { -// locationAttribute = LocationStatus.DISABLE_EMPTY_LOCATION; -// } else { -// if(inventoryDetail == null) { -// locationAttribute = LocationStatus.DISABLE_EMPTY_CONTAINER; -// } else { -// location1.setMaterialName(materialNameList); -// location1.setMaterialCode(materialCodeList); -// location1.setBatch(batchList); -// location1.setQty(qtyList); -// locationAttribute = LocationStatus.DISABLE_FULL_CONTAINER; -// } -// } -// } - location1.setLocationAttribute(String.valueOf(locationAttribute)); - locationList.add(location1); - } - return Result.ok(locations); - } + location1.setLocationAttribute(String.valueOf(locationAttribute)); + locationList.add(location1); + } + return Result.ok(locations); + } - /** - * 查询库位列表 - */ - @PostMapping("/getAllLocation") - @ResponseBody - public Result getAllLocation (@RequestParam(name = "type")String type) { - if(StringUtils.isEmpty(type)) { - return Result.error("type不能为空"); - } - return Result.ok(locationService.getAllLocation(type)); - } + /** + * 查询库位列表 + */ + @PostMapping("/getAllLocation") + @ResponseBody + public Result getAllLocation(@RequestParam(name = "type") String type) { + if (StringUtils.isEmpty(type)) { + return Result.error("type不能为空"); + } + return Result.ok(locationService.getAllLocation(type)); + } - } +}