chen.lin
昨天 7e5973a3061989a976e2c19ef588bb2f34f29cf4
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
@@ -699,37 +699,43 @@
            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.compareTo(ISSUED_TOLERANCE) > 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);
                if (issued.compareTo(ISSUED_TOLERANCE) <= 0) {
                    break;
                }
                // 该库位可分配数量:取本行待分配与库位库存的较小值
                double allocatable = Math.min(issued.doubleValue(), locItem.getAnfme() != null ? locItem.getAnfme() : 0);
                ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
                if (existDtos.add(existDto)) {
                    // 首次使用该库位:加入列表并扣减 issued
                    locItem.setOutQty(allocatable);
                    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)
                        );
                    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());
                    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);
                        }
                        list.add(orderOutItemDto);
                        issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
                        orderOutItemDto.setStaNos(maps);
                        //默认获取第一站点
                        DeviceSite deviceSite = deviceSites.stream().findFirst().get();
                        orderOutItemDto.setSiteNo(deviceSite.getSite());
                    }
                    list.add(orderOutItemDto);
                    issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
                } else {
                    // 该库位已被前序订单行占用:只扣减 issued,不重复加入列表,避免产生“库存不足”脏数据
                    issued = issued.subtract(new BigDecimal(String.valueOf(allocatable)));
                }
            }
            if (issued.compareTo(ISSUED_TOLERANCE) > 0) {