| | |
| | | return R.ok(locItems); |
| | | } |
| | | |
| | | @Override |
| | | public R getOrderOutTaskItem(OrderOutTaskParam param,Long orderItemId) { |
| | | |
| | | OrderOutTaskParam orderOutTaskParam = new OrderOutTaskParam(); |
| | | orderOutTaskParam.setWaveId(param.getWaveId()); |
| | | |
| | | if (Cools.isEmpty(param.getWaveId())) { |
| | | throw new CoolException("策略参数为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderId())) { |
| | | throw new CoolException("单据ID为空"); |
| | | } |
| | | WkOrderItem byId = asnOrderItemService.getById(orderItemId); |
| | | param.setOrderId(byId.getOrderId()); |
| | | |
| | | WaveRule waveRule = waveRuleService.getOne(new LambdaQueryWrapper<WaveRule>() |
| | | .eq(WaveRule::getId, param.getWaveId())); |
| | | if (Cools.isEmpty(waveRule)) { |
| | | throw new CoolException("未找到当前策略"); |
| | | } |
| | | List<OrderOutItemDto> locItems = null; |
| | | List<Long> itemIds = new ArrayList<>(); |
| | | itemIds.add(orderItemId); |
| | | locItems = getOutOrderList(param.getOrderId(), waveRule,itemIds); |
| | | return R.ok(locItems); |
| | | } |
| | | |
| | | @Override |
| | | public List<OrderOutItemDto> getOrderOutTaskItemAuto(OrderOutTaskParam param) { |
| | | if (Cools.isEmpty(param.getWaveId())) { |
| | | throw new CoolException("策略参数为空"); |
| | | } |
| | | if (Cools.isEmpty(param.getOrderId())) { |
| | | throw new CoolException("单据ID为空"); |
| | | } |
| | | WaveRule waveRule = waveRuleService.getOne(new LambdaQueryWrapper<WaveRule>() |
| | | .eq(WaveRule::getId, param.getWaveId())); |
| | | if (Cools.isEmpty(waveRule)) { |
| | | throw new CoolException("未找到当前策略"); |
| | | } |
| | | List<OrderOutItemDto> locItems = null; |
| | | locItems = getOutOrderList(param.getOrderId(), waveRule); |
| | | return locItems; |
| | | } |
| | | |
| | | /** |
| | | * 生成出库任务 |
| | | * |
| | |
| | | throw new CoolException("参数不能为空!!"); |
| | | } |
| | | //优先生成浅库位任务 |
| | | List<OutStockToTaskParams> Items = params.stream() |
| | | List<OutStockToTaskParams> itemList = params.stream() |
| | | .sorted(Comparator.comparing(OutStockToTaskParams::getLocCode) |
| | | .thenComparing(item -> { |
| | | return LocUtils.isShallowLoc(item.getLocCode()) ? 1 : 0; |
| | | }).reversed()).collect(Collectors.toList()); |
| | | |
| | | for (OutStockToTaskParams param : Items) { |
| | | WkOrder wkOrder = outStockService.getById(outId); |
| | | if (Cools.isEmpty(wkOrder)) { |
| | | throw new CoolException("单据不存在!!"); |
| | | } |
| | | List<List<OutStockToTaskParams>> itemLists = new ArrayList<>(); |
| | | List<String> locList = new ArrayList<>(); |
| | | for (OutStockToTaskParams item : itemList) { |
| | | if (!locList.contains(item.getLocCode())) { |
| | | List<OutStockToTaskParams> items = new ArrayList<>(); |
| | | locList.add(item.getLocCode()); |
| | | items.add(item); |
| | | itemLists.add(items); |
| | | } else { |
| | | for (List<OutStockToTaskParams> items : itemLists){ |
| | | boolean sign = false; |
| | | for (OutStockToTaskParams itemOld : items) { |
| | | if (itemOld.getLocCode().equals(item.getLocCode())) { |
| | | sign = true; |
| | | items.add(item); |
| | | } |
| | | break; |
| | | } |
| | | if (sign) { |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | for (List<OutStockToTaskParams> items : itemLists){ |
| | | OutStockToTaskParams param = items.get(0); |
| | | if (Objects.isNull(param) || StringUtils.isBlank(param.getLocCode())) { |
| | | continue; |
| | | } |
| | | Loc loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, param.getLocCode()).eq(Loc::getBarcode, param.getBarcode())); |
| | | if (!Objects.isNull(loc)) { |
| | | List<LocItem> locItems = new ArrayList<>(); |
| | | LocItem locItem = locItemService.getById(param.getId()); |
| | | for (OutStockToTaskParams itemOld : items) { |
| | | LocItem locItem = locItemService.getById(itemOld.getId()); |
| | | |
| | | WkOrderItem orderItem = outStockItemService.getOne(new LambdaQueryWrapper<WkOrderItem>() |
| | | .eq(WkOrderItem::getOrderId, outId) |
| | | .eq(StringUtils.isNotBlank(locItem.getBatch()), WkOrderItem::getSplrBatch, locItem.getBatch()) |
| | | .eq(StringUtils.isNotBlank(locItem.getFieldsIndex()), WkOrderItem::getFieldsIndex, locItem.getFieldsIndex()) |
| | | .eq(WkOrderItem::getMatnrId, locItem.getMatnrId())); |
| | | WkOrderItem orderItem = outStockItemService.getOne(new LambdaQueryWrapper<WkOrderItem>() |
| | | .eq(WkOrderItem::getOrderId, outId) |
| | | // .eq(StringUtils.isNotBlank(locItem.getBatch()), WkOrderItem::getSplrBatch, locItem.getBatch()) |
| | | .eq(WkOrderItem::getMatnrId, locItem.getMatnrId())); |
| | | // .eq(StringUtils.isNotBlank(locItem.getFieldsIndex()), WkOrderItem::getFieldsIndex, locItem.getFieldsIndex()) |
| | | |
| | | if (Objects.isNull(orderItem)) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | if (Objects.isNull(orderItem)) { |
| | | throw new CoolException("单据明细不存在!!"); |
| | | } |
| | | |
| | | locItem.setOutQty(itemOld.getOutQty()) |
| | | .setBatch(itemOld.getBatch()) |
| | | .setSourceId(outId) |
| | | .setSourceCode(orderItem.getOrderCode()) |
| | | .setSource(orderItem.getId()); |
| | | locItems.add(locItem); |
| | | |
| | | |
| | | Double workQty = Math.round((orderItem.getWorkQty() + locItem.getOutQty()) * 10000) / 10000.0; |
| | | |
| | | orderItem.setUpdateBy(loginUserId).setUpdateTime(new Date()).setWorkQty(workQty); |
| | | |
| | | if (!outStockItemService.updateById(orderItem)) { |
| | | throw new CoolException("单据明细修改失败!!"); |
| | | } |
| | | } |
| | | |
| | | locItem.setOutQty(param.getOutQty()) |
| | | .setBatch(param.getBatch()) |
| | | .setSourceId(outId) |
| | | .setSourceCode(orderItem.getOrderCode()) |
| | | .setSource(orderItem.getId()); |
| | | locItems.add(locItem); |
| | | |
| | | LocToTaskParams taskParams = new LocToTaskParams(); |
| | | taskParams.setType(Constants.TASK_TYPE_ORDER_OUT_STOCK) |
| | |
| | | .setItems(locItems) |
| | | .setSourceId(outId) |
| | | .setSiteNo(param.getSiteNo()); |
| | | //增加备货出库类型判断 |
| | | Short type = wkOrder.getWkType().equals(OrderWorkType.ORDER_WORK_TYPE_STOCK_UP.type) |
| | | ?TaskResouceType.TASK_RESOUCE_STOCK_UP.val |
| | | :TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val; |
| | | try { |
| | | //生成出库任务 |
| | | locItemService.generateTask(TaskResouceType.TASK_RESOUCE_ORDER_TYPE.val, taskParams, loginUserId); |
| | | locItemService.generateTask(type, taskParams, loginUserId); |
| | | } catch (Exception e) { |
| | | logger.error("UNK", e); |
| | | throw new CoolException(e.getMessage()); |
| | | } |
| | | |
| | | |
| | | Double workQty = Math.round((orderItem.getWorkQty() + locItem.getOutQty()) * 10000) / 10000.0; |
| | | |
| | | orderItem.setUpdateBy(loginUserId).setUpdateTime(new Date()).setWorkQty(workQty); |
| | | |
| | | if (!outStockItemService.updateById(orderItem)) { |
| | | throw new CoolException("单据明细修改失败!!"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | Double sum = Items.stream().mapToDouble(OutStockToTaskParams::getOutQty).sum(); |
| | | Double sum = itemList.stream().mapToDouble(OutStockToTaskParams::getOutQty).sum(); |
| | | //更新出库单明细及主单 |
| | | WkOrder outOrder = outStockService.getById(outId); |
| | | if (Objects.isNull(outOrder)) { |
| | |
| | | |
| | | } |
| | | |
| | | private List<OrderOutItemDto> getOutOrderList(Long orderId, WaveRule waveRule,List<Long> orderItemIdList) { |
| | | List<WkOrderItem> wkOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<WkOrderItem>() |
| | | .in(WkOrderItem::getId, orderItemIdList).eq(WkOrderItem::getOrderId, orderId)); |
| | | List<OrderOutItemDto> list = new ArrayList<>(); |
| | | Set<ExistDto> existDtos = new HashSet<>(); |
| | | for (WkOrderItem wkOrderItem : wkOrderItems) { |
| | | BigDecimal issued = new BigDecimal(wkOrderItem.getAnfme().toString()) |
| | | .subtract(new BigDecimal(wkOrderItem.getWorkQty().toString()) |
| | | ); |
| | | if (issued.doubleValue() <= 0) { |
| | | continue; |
| | | } |
| | | List<LocItem> locItems = new ArrayList<>(); |
| | | if (WaveRuleType.Efficiency_First.type.equals(waveRule.getType())) { |
| | | locItems = LocManageUtil.getEfficiencyFirstItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); |
| | | } else if (WaveRuleType.First_In_First_Out.type.equals(waveRule.getType())) { |
| | | locItems = LocManageUtil.getFirstInFirstOutItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); |
| | | } else { |
| | | locItems = LocManageUtil.getFirstInFirstOutItemList(wkOrderItem.getMatnrCode(), wkOrderItem.getSplrBatch(), wkOrderItem.getAnfme()); |
| | | } |
| | | for (LocItem locItem : locItems) { |
| | | Loc loc = locService.getById(locItem.getLocId()); |
| | | List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, locItem.getLocCode())); |
| | | if (issued.doubleValue() > 0) { |
| | | ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode()); |
| | | if (existDtos.add(existDto)) { |
| | | locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue()); |
| | | locItem.setBarcode(loc.getBarcode()); |
| | | OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); |
| | | orderOutItemDto.setLocItem(locItem); |
| | | |
| | | List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>() |
| | | .eq(DeviceSite::getChannel, loc.getChannel()) |
| | | .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type) |
| | | ); |
| | | |
| | | if (!deviceSites.isEmpty()) { |
| | | List<OrderOutItemDto.staListDto> maps = new ArrayList<>(); |
| | | for (DeviceSite sta : deviceSites) { |
| | | OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto(); |
| | | staListDto.setStaNo(sta.getSite()); |
| | | staListDto.setStaName(sta.getSite()); |
| | | maps.add(staListDto); |
| | | } |
| | | orderOutItemDto.setStaNos(maps); |
| | | //默认获取第一站点 |
| | | DeviceSite deviceSite = deviceSites.stream().findFirst().get(); |
| | | orderOutItemDto.setSiteNo(deviceSite.getSite()); |
| | | } |
| | | |
| | | list.add(orderOutItemDto); |
| | | |
| | | issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString())); |
| | | } |
| | | } |
| | | } |
| | | if (issued.doubleValue() > 0) { |
| | | LocItem locItem = new LocItem() |
| | | .setId(new Random().nextLong()) |
| | | .setMatnrCode(wkOrderItem.getMatnrCode()) |
| | | .setMaktx(wkOrderItem.getMaktx()) |
| | | .setAnfme(0.00) |
| | | .setWorkQty(issued.doubleValue()) |
| | | .setOutQty(issued.doubleValue()) |
| | | .setUnit(wkOrderItem.getStockUnit()) |
| | | .setBatch(wkOrderItem.getSplrBatch()); |
| | | OrderOutItemDto orderOutItemDto = new OrderOutItemDto(); |
| | | orderOutItemDto.setLocItem(locItem); |
| | | list.add(orderOutItemDto); |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | |
| | | } |
| | | |
| | | /** |
| | | * @param |
| | | * @param wave |