| | |
| | | if (logItems.isEmpty()) { |
| | | throw new CoolException("调整明细为空!!"); |
| | | } |
| | | Map<Long, List<ReviseLogItem>> listMap = logItems.stream().collect(Collectors.groupingBy(ReviseLogItem::getLocId)); |
| | | listMap.keySet().forEach(items -> { |
| | | Loc loc = locService.getById(items); |
| | | // 按库位ID分组,如果locId为null则按locCode分组 |
| | | Map<String, List<ReviseLogItem>> listMap = logItems.stream() |
| | | .filter(item -> item.getLocCode() != null && !item.getLocCode().isEmpty()) |
| | | .collect(Collectors.groupingBy(item -> { |
| | | // 优先使用locId,如果为null则使用locCode作为key |
| | | return item.getLocId() != null ? String.valueOf(item.getLocId()) : item.getLocCode(); |
| | | })); |
| | | |
| | | listMap.keySet().forEach(key -> { |
| | | List<ReviseLogItem> reviseItems = listMap.get(key); |
| | | if (Objects.isNull(reviseItems) || reviseItems.isEmpty()) { |
| | | throw new CoolException("调整明细为空!!"); |
| | | } |
| | | |
| | | // 获取第一个明细的库位信息 |
| | | ReviseLogItem firstItem = reviseItems.get(0); |
| | | String locCode = firstItem.getLocCode(); |
| | | Long locId = firstItem.getLocId(); |
| | | |
| | | // 查询库位:优先使用locId,如果为null则使用locCode |
| | | Loc loc = null; |
| | | if (locId != null) { |
| | | loc = locService.getById(locId); |
| | | } |
| | | if (loc == null && locCode != null && !locCode.isEmpty()) { |
| | | loc = locService.getOne(new LambdaQueryWrapper<Loc>().eq(Loc::getCode, locCode).eq(Loc::getDeleted, 0)); |
| | | } |
| | | |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | throw new CoolException("库位不存在!库位编码:" + locCode + ", 库位ID:" + locId); |
| | | } |
| | | List<LocItem> list = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); |
| | | if (!list.isEmpty()) { |
| | | throw new CoolException("库位:" + loc.getCode() + ", 调整信息为空!!"); |
| | | } |
| | | |
| | | // 删除原库位的库存明细(如果存在) |
| | | locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); |
| | | listMap.get(items).forEach(logItem -> { |
| | | |
| | | Loc finalLoc = loc; |
| | | reviseItems.forEach(logItem -> { |
| | | LocItem locDetl = new LocItem(); |
| | | BeanUtils.copyProperties(logItem, locDetl); |
| | | locDetl.setLocId(loc.getId()) |
| | | locDetl.setLocId(finalLoc.getId()) |
| | | .setType(OrderType.ORDER_REVISE.type) |
| | | .setWkType(Short.parseShort(OrderWorkType.ORDER_WORK_TYPE_STOCK_REVISE.type)) |
| | | .setLocCode(loc.getCode()) |
| | | .setLocCode(finalLoc.getCode()) |
| | | .setAnfme(logItem.getReviseQty()) |
| | | .setUpdateBy(loginUserId) |
| | | .setId(null) |