diff --git a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java index 8882bf2..dc811a8 100644 --- a/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java +++ b/src/main/java/com/huaheng/api/wcs/service/warecellAllocation/WarecellAllocationServiceImpl.java @@ -115,6 +115,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService taskDetailLambda.eq(TaskDetail::getTaskId, wcsTask.getTaskNo()); List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambda); + /* 循环查询入库组盘明细*/ List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>(); for (TaskDetail taskDetail : taskDetailList) { receiptContainerDetailList.add(receiptContainerDetailService.getById(taskDetail.getAllocationId())); @@ -122,6 +123,7 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService //去重 receiptContainerDetailList = receiptContainerDetailList.stream().distinct().collect(Collectors.toList()); + /* 循环入库组盘明细,重新分配库位*/ for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetailList) { ReceiptContainerHeader receiptContainerHeader = receiptContainerHeaderService.getById(receiptContainerDetail.getReceiptContainerId()); @@ -164,7 +166,6 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService receiptContainerDetail2.setLocationCode(locationCode); if (!receiptContainerDetailService.updateById(receiptContainerDetail2)){throw new ServiceException("更新库位编码到入库组盘明细");} } - } if (StringUtils.isNotEmpty(locationCode)){ @@ -251,10 +252,88 @@ public class WarecellAllocationServiceImpl implements WarecellAllocationService } - ////去向分配 + /** + * 去向分配 + */ @Override public AjaxResult destinationAllocation(WcsTask wcsTask) { - return null; + //1、判断非空字段 + if(StringUtils.isEmpty(wcsTask.getTaskNo())){ + return AjaxResult.error("任务号为空"); + } + if(StringUtils.isNull(wcsTask.getLength())){ + return AjaxResult.error("长为空"); + } + if(StringUtils.isNull(wcsTask.getWidth())){ + return AjaxResult.error("宽为空"); + } + if(StringUtils.isNull(wcsTask.getHeight())){ + return AjaxResult.error("高为空"); + } + if(StringUtils.isNull(wcsTask.getWeight())){ + return AjaxResult.error("重为空"); + } + + //查询满足条件的库位类型 + LambdaQueryWrapper<LocationType> lambdaQueryWrapper = Wrappers.lambdaQuery(); + lambdaQueryWrapper.gt(LocationType::getLength,wcsTask.getLength()) + .gt(LocationType::getWidth, wcsTask.getWidth()) + .gt(LocationType::getHeight, wcsTask.getHeight()) + .gt(LocationType::getMaxWeight, wcsTask.getWidth()); + List<LocationType> locationTypeList = locationTypeService.list(lambdaQueryWrapper); + + if (locationTypeList.isEmpty()){ + return AjaxResult.error("没有区域可分配"); + } + List<String> codeList = new ArrayList<>(); + for (LocationType locationType: locationTypeList) { + codeList.add(locationType.getCode()); + } + + //定位库位List + List<String> positioningLocationCodeList = null; + //查询任务明细 + LambdaQueryWrapper<TaskDetail> taskDetailLambda = Wrappers.lambdaQuery(); + taskDetailLambda.eq(TaskDetail::getTaskId, wcsTask.getTaskNo()); + List<TaskDetail> taskDetailList = taskDetailService.list(taskDetailLambda); + + /* 循环查询入库组盘明细*/ + List<ReceiptContainerDetail> receiptContainerDetailList = new ArrayList<>(); + for (TaskDetail taskDetail : taskDetailList) { + receiptContainerDetailList.add(receiptContainerDetailService.getById(taskDetail.getAllocationId())); + } + //去重 + receiptContainerDetailList = receiptContainerDetailList.stream().distinct().collect(Collectors.toList()); + + for (ReceiptContainerDetail receiptContainerDetail : receiptContainerDetailList) { + String locatingRule = this.taskPositioning(receiptContainerDetail); + + LambdaQueryWrapper<FilterConfigDetail> filterConfigDetailLambda = Wrappers.lambdaQuery(); + filterConfigDetailLambda.eq(FilterConfigDetail::getCode, locatingRule) + .eq(FilterConfigDetail::getWarehouseCode, ShiroUtils.getWarehouseCode()); + FilterConfigDetail filterConfigDetail = filterConfigDetailService.getOne(filterConfigDetailLambda); + String[] locatingRules = filterConfigDetail.getStatement().split("limit"); + + //根据定位规则查询库位编码 + LambdaQueryWrapper<Location> locationLambda = Wrappers.lambdaQuery(); + locationLambda.last(locatingRules[0]); + List<Location> locationList = locationService.list(locationLambda); + List<String> locationCodeList = locationTypeList.stream().map(t-> t.getCode()).collect(Collectors.toList()); + List<Location> newLocation = locationList.stream().filter(t-> locationCodeList.contains(t.getLocationType())).collect(Collectors.toList()); + if (!newLocation.isEmpty()){ + positioningLocationCodeList.add(newLocation.get(0).getCode()); + } + + if (StringUtils.isEmpty(positioningLocationCodeList)){ + throw new ServiceException("没有区域可分配"); + } + } + + LambdaQueryWrapper<Location> locationLambdaQueryWrapper = Wrappers.lambdaQuery(); + locationLambdaQueryWrapper.eq(Location::getCode, positioningLocationCodeList.get(0)); + Location location = locationService.getOne(locationLambdaQueryWrapper); + String destinationArea = location.getRoadway(); + return AjaxResult.success(destinationArea); } } \ No newline at end of file