| | |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Objects; |
| | | import java.util.Set; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Service("reviseLogService") |
| | |
| | | |
| | | @Autowired |
| | | private LocService locService; |
| | | |
| | | @Autowired |
| | | private ReviseLogItemService reviseLogItemService; |
| | | |
| | | /** |
| | | * 库存调整单明细添加 |
| | | * |
| | | * @param revise |
| | | * @param loginUserId |
| | | * @return |
| | |
| | | if (!reviseLogService.save(reviseLog)) { |
| | | throw new CoolException("调整单明细保存失败!!"); |
| | | } |
| | | |
| | | List<LocItem> locItems = locItemService.list(new LambdaQueryWrapper<LocItem>() |
| | | .eq(LocItem::getLocCode, item.getLocCode())); |
| | | if (!locItems.isEmpty()) { |
| | | locItems.forEach(ote -> { |
| | | ReviseLogItem logItem = new ReviseLogItem(); |
| | | BeanUtils.copyProperties(ote, logItem); |
| | | logItem.setReviseLogId(reviseLog.getId()); |
| | | if (!reviseLogItemService.save(logItem)) { |
| | | throw new CoolException("明细保存失败!!"); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | Double sum = locItems.stream().mapToDouble(LocItem::getAnfme).sum(); |
| | | |
| | | locRevise.setAnfme(Math.round((sum + locRevise.getAnfme()) * 10000) / 10000.0); |
| | | }); |
| | | |
| | | locRevise.setExceStatus(CommonExceStatus.COMMON_EXCE_STATUS_UN_EXCE.val); |
| | | |
| | | if (!locReviseService.updateById(locRevise)) { |
| | |
| | | if (!revise.getExceStatus().equals(CommonExceStatus.COMMON_EXCE_STATUS_EXCE_ING.val)) { |
| | | throw new CoolException("单据状态未执行或已完成,无法执行完成操作!!"); |
| | | } |
| | | ReviseLog logs = reviseLogService.getOne(new LambdaQueryWrapper<ReviseLog>().eq(ReviseLog::getReviseId, revise.getId())); |
| | | if (Objects.isNull(logs)) { |
| | | List<ReviseLog> logs = reviseLogService.list(new LambdaQueryWrapper<ReviseLog>().eq(ReviseLog::getReviseId, revise.getId())); |
| | | if (logs.isEmpty()) { |
| | | throw new CoolException("库存日志不存在!!"); |
| | | } |
| | | List<ReviseLogItem> logItems = reviseLogItemService.list(new LambdaQueryWrapper<ReviseLogItem>().eq(ReviseLogItem::getReviseLogId, logs.getId())); |
| | | Set<Long> longs = logs.stream().map(ReviseLog::getId).collect(Collectors.toSet()); |
| | | List<ReviseLogItem> logItems = reviseLogItemService.list(new LambdaQueryWrapper<ReviseLogItem>().in(ReviseLogItem::getReviseLogId, longs)); |
| | | 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); |
| | | if (Objects.isNull(loc)) { |
| | | throw new CoolException("库位不存在!!"); |
| | | } |
| | | locItemService.remove(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocId, loc.getId())); |
| | | listMap.get(items).forEach(logItem -> { |
| | | LocItem one = locItemService.getOne(new LambdaQueryWrapper<LocItem>() |
| | | .eq(LocItem::getMatnrId, logItem.getMatnrId()) |
| | | .eq(StringUtils.isNotBlank(logItem.getBatch()), LocItem::getBatch, logItem.getBatch()) |
| | | .eq(StringUtils.isNotBlank(logItem.getFieldsIndex()), LocItem::getFieldsIndex, logItem.getFieldsIndex()) |
| | | .eq(LocItem::getLocCode, logItem.getLocCode())); |
| | | if (Objects.isNull(one)) { |
| | | LocItem locDetl = new LocItem(); |
| | | BeanUtils.copyProperties(logItem, locDetl); |
| | | locDetl.setLocId(loc.getId()) |
| | |
| | | .setCreateBy(loginUserId); |
| | | if (!locItemService.save(locDetl)) { |
| | | throw new CoolException("库存明细保存失败!!"); |
| | | } |
| | | } else { |
| | | one.setAnfme(logItem.getReviseQty()); |
| | | if (!locItemService.updateById(one)) { |
| | | throw new CoolException("库存明细修改失败!!"); |
| | | } |
| | | } |
| | | }); |
| | | }); |