From e0529614c187a5457ca3f587a16edeec51d69d15 Mon Sep 17 00:00:00 2001 From: cuijian <cuijian@xalxzn.com> Date: 星期一, 16 六月 2025 10:41:16 +0800 Subject: [PATCH] 刀具寿命 --- lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 51 insertions(+), 0 deletions(-) diff --git a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java index cc05fae..1a8fef7 100644 --- a/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java +++ b/lxzn-module-tms/src/main/java/org/jeecg/modules/tms/service/impl/OutboundOrderServiceImpl.java @@ -8,6 +8,7 @@ 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; @@ -42,6 +43,7 @@ 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; @@ -383,6 +385,10 @@ 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)); @@ -418,6 +424,14 @@ //鏇存柊搴撳瓨鍙拌处 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: @@ -438,20 +452,33 @@ 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("鏈煡鐨勫嚭搴撶被鍨嬶紒"); @@ -476,6 +503,9 @@ .setGoodsShelvesCode(detail.getOutboundLocation()) .setOutNumber(outboundQuantity) .setOutStorehouseId(outboundOrder.getId()) + .setRatedLife(ratedLife) + .setUseLife(useLife) + .setRemainingPercentage(remandLife) .setOperateType("1");//1锛氭寜鐢宠鍗� outStoreAddList.add(outStoreDetail); @@ -562,6 +592,8 @@ 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()); @@ -573,20 +605,34 @@ 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 -> { @@ -607,12 +653,17 @@ //璁板綍鍑哄簱娴佹按 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); } -- Gitblit v1.9.3