| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.core.toolkit.StringUtils; |
| | | import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import lombok.extern.slf4j.Slf4j; |
| | |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | |
| | | |
| | | Map<String, BigDecimal> outBoundRequestMap = outBoundRequestList.stream() |
| | | .collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, OutBoundRequestDto::getOutboundQuantity)); |
| | | Map<String, BigDecimal> ratedLifeMap = outBoundRequestList.stream() |
| | | .collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getRatedLife() != null ? dto.getRatedLife() : null)); |
| | | Map<String, BigDecimal> useLifeMap = outBoundRequestList.stream() |
| | | .collect(Collectors.toMap(OutBoundRequestDto::getOutboundDetailId, dto->dto.getUseLife() != null ? dto.getUseLife() : null)); |
| | | //处理库存台账及台账明细 |
| | | Map<String, ToolLedger> toolLedgerMap = toolLedgerService.list(new LambdaQueryWrapper<ToolLedger>().in(ToolLedger::getToolId, toolIdList)).stream() |
| | | .collect(Collectors.toMap(ToolLedger::getToolId, item -> item, (k1, k2) -> k1)); |
| | |
| | | //更新库存台账 |
| | | ToolLedger toolLedger = toolLedgerMap.get(detail.getToolCode()); |
| | | BigDecimal outboundQuantity = outBoundRequestMap.get(detail.getId()); |
| | | BigDecimal ratedLife = ratedLifeMap.get(detail.getId()); |
| | | BigDecimal useLife = useLifeMap.get(detail.getId()); |
| | | //唯一编码不为空时(管到把),计算剩余寿命 |
| | | BigDecimal remandLife = null; |
| | | if(StringUtils.isNotBlank(detail.getToolId())){ |
| | | ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.lambdaQuery().eq(ToolLedgerDetail::getToolId,detail.getToolId()).one(); |
| | | remandLife = (ratedLife.multiply(toolLedgerDetail.getRemainingPercentage()).subtract(useLife).max(BigDecimal.ZERO)).divide(ratedLife, 4, RoundingMode.HALF_UP); |
| | | } |
| | | OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(outboundOrder.getOutStorehouseType()); |
| | | switch (outStorehouseType) { |
| | | case TOOL_BORROW: |
| | |
| | | toolLedgerUpdateList.add(toolLedger); |
| | | |
| | | //更新台账明细 |
| | | BigDecimal finalRemandLife = remandLife; |
| | | toolLedgerDetailList.stream().filter(item -> item.getToolCode().equals(detail.getToolCode()) && item.getToolId().equals(detail.getToolId())) |
| | | .findFirst().ifPresent(item -> { |
| | | switch (outStorehouseType) { |
| | | case TOOL_BORROW: |
| | | item.setStatus(ToolCirculationStatus.BORROWED.getValue()); |
| | | item.setRatedLife(ratedLife); |
| | | item.setUseLife(useLife); |
| | | item.setRemainingPercentage(finalRemandLife); |
| | | break; |
| | | case MAINTENANCE_OUTBOUND: |
| | | item.setStatus(ToolCirculationStatus.REPAIRING.getValue()); |
| | | item.setRatedLife(ratedLife); |
| | | item.setUseLife(useLife); |
| | | item.setRemainingPercentage(finalRemandLife); |
| | | break; |
| | | case CALIBRATION_OUTBOUND: |
| | | item.setStatus(ToolCirculationStatus.INSPECTING.getValue()); |
| | | item.setRatedLife(ratedLife); |
| | | item.setUseLife(useLife); |
| | | item.setRemainingPercentage(finalRemandLife); |
| | | break; |
| | | case GRINDING_OUTBOUND: |
| | | item.setStatus(ToolCirculationStatus.GRINDING.getValue()); |
| | | item.setRatedLife(ratedLife); |
| | | item.setUseLife(useLife); |
| | | item.setRemainingPercentage(finalRemandLife); |
| | | break; |
| | | default: |
| | | throw new JeecgBootException("未知的出库类型!"); |
| | |
| | | .setGoodsShelvesCode(detail.getOutboundLocation()) |
| | | .setOutNumber(outboundQuantity) |
| | | .setOutStorehouseId(outboundOrder.getId()) |
| | | .setRatedLife(ratedLife) |
| | | .setUseLife(useLife) |
| | | .setRemainingPercentage(remandLife) |
| | | .setOperateType("1");//1:按申请单 |
| | | outStoreAddList.add(outStoreDetail); |
| | | |
| | |
| | | for (String toolLedgerDetailId : boundAddDtoMap.keySet()) { |
| | | OutBoundAddDto outBoundAddDto = boundAddDtoMap.get(toolLedgerDetailId); |
| | | BigDecimal outboundQuantity = outBoundAddDto.getOutboundQuantity(); |
| | | BigDecimal ratedLife = outBoundAddDto.getRatedLife(); |
| | | BigDecimal useLife = outBoundAddDto.getUseLife(); |
| | | ToolLedgerDetail toolLedgerDetail = toolLedgerDetailMap.get(toolLedgerDetailId); |
| | | if (Objects.isNull(toolLedgerDetail) || toolLedgerDetail.getQuantity().compareTo(outboundQuantity) < 0) { |
| | | BaseTools tools = baseToolsService.getById(outBoundAddDto.getToolCode()); |
| | |
| | | toolLedgerDetail.setQuantity(toolLedgerDetail.getQuantity().subtract(outboundQuantity)); |
| | | } else { |
| | | //有唯一编码,管道把的 |
| | | //计算剩余寿命 |
| | | BigDecimal remandLife = (ratedLife.multiply(toolLedgerDetail.getRemainingPercentage()).subtract(useLife).max(BigDecimal.ZERO)).divide(ratedLife, 4, RoundingMode.HALF_UP); |
| | | toolLedgerDetail.setQuantity(BigDecimal.ZERO);//数量只会是0和1 |
| | | OutStorehouseType outStorehouseType = OutStorehouseType.getByValue(boundAddList.get(0).getOutStorehouseType()); |
| | | switch (outStorehouseType) { |
| | | case TOOL_BORROW: |
| | | toolLedgerDetail.setStatus(ToolCirculationStatus.BORROWED.getValue()); |
| | | toolLedgerDetail.setRatedLife(ratedLife); |
| | | toolLedgerDetail.setUseLife(useLife); |
| | | toolLedgerDetail.setRemainingPercentage(remandLife); |
| | | break; |
| | | case MAINTENANCE_OUTBOUND: |
| | | toolLedgerDetail.setStatus(ToolCirculationStatus.REPAIRING.getValue()); |
| | | toolLedgerDetail.setRatedLife(ratedLife); |
| | | toolLedgerDetail.setUseLife(useLife); |
| | | toolLedgerDetail.setRemainingPercentage(remandLife); |
| | | break; |
| | | case CALIBRATION_OUTBOUND: |
| | | toolLedgerDetail.setStatus(ToolCirculationStatus.INSPECTING.getValue()); |
| | | toolLedgerDetail.setRatedLife(ratedLife); |
| | | toolLedgerDetail.setUseLife(useLife); |
| | | toolLedgerDetail.setRemainingPercentage(remandLife); |
| | | break; |
| | | case GRINDING_OUTBOUND: |
| | | toolLedgerDetail.setStatus(ToolCirculationStatus.GRINDING.getValue()); |
| | | toolLedgerDetail.setRatedLife(ratedLife); |
| | | toolLedgerDetail.setUseLife(useLife); |
| | | toolLedgerDetail.setRemainingPercentage(remandLife); |
| | | //同时更新刃磨单状态 |
| | | toolSharpeningList.stream().filter(item -> item.getToolCode().equals(outBoundAddDto.getToolCode()) |
| | | && item.getToolId().equals(outBoundAddDto.getToolId())).findFirst().ifPresent(item -> { |
| | |
| | | //记录出库流水 |
| | | List<OutStoreDetail> outStoreAddList = CollectionUtil.newArrayList(); |
| | | for (OutBoundAddDto outBoundAddDto : boundAddList) { |
| | | //获取剩余寿命 |
| | | ToolLedgerDetail toolLedgerDetail = toolLedgerDetailService.getById(outBoundAddDto.getToolLedgerDetailId()); |
| | | OutStoreDetail outStoreDetail = new OutStoreDetail() |
| | | .setToolCode(outBoundAddDto.getToolCode()) |
| | | .setToolId(outBoundAddDto.getToolId()) |
| | | .setOutStorehouseType(outBoundAddDto.getOutStorehouseType()) |
| | | .setGoodsShelvesCode(outBoundAddDto.getOutboundLocation()) |
| | | .setOutNumber(outBoundAddDto.getOutboundQuantity()) |
| | | .setRatedLife(outBoundAddDto.getRatedLife()) |
| | | .setUseLife(outBoundAddDto.getUseLife()) |
| | | .setRemainingPercentage(toolLedgerDetail.getRemainingPercentage()) |
| | | .setOperateType("2");//2:手工操作 |
| | | outStoreAddList.add(outStoreDetail); |
| | | } |