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 |   68 ++++++++++++++++++++++++++++++----
 1 files changed, 60 insertions(+), 8 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 936e09c..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;
 
@@ -155,7 +157,7 @@
 		//鍒犻櫎鎵�鏈夋槑缁�
 		outboundDetailService.remove(new LambdaQueryWrapper<OutboundDetail>()
 				.eq(OutboundDetail::getOutStorehouseId, outboundOrder.getId()));
-		OutboundOrder outboundOrderUpdate = BeanUtil.copyProperties(outboundOrder, OutboundOrder.class);
+		OutboundOrder outboundOrderUpdate = OutboundOrderConvert.INSTANCE.convert(outboundOrder);
 		outboundOrderMapper.updateById(outboundOrderUpdate);
 		List<OutboundDetail> detailList = CollectionUtil.newArrayList();
 		outboundOrder.getOutboundDetailList().forEach(item->{
@@ -175,13 +177,14 @@
 		if (!Objects.equals(outboundOrder.getOrderStatus(), OutBillStatus.DRAFT.getValue())) {
 			throw new JeecgBootException("鏃犳硶鎻愪氦闈炶崏绋跨姸鎬佺殑鍑哄簱鐢宠鍗曪紒");
 		}
-		//閿佸畾鐢宠鍗曟槑缁嗕腑宸ュ叿搴撳瓨
-		if (lockOutboundStock(id)) {
-			//鍚姩娴佺▼
-			if (triggerProcess(outboundOrder)) {
-				outboundOrder.setOrderStatus(OutBillStatus.SUBMITTED.getValue());
-				updateById(outboundOrder);
-			}
+		if (!OutStorehouseType.PREPARATION_OUTBOUND.getValue().equals(outboundOrder.getOutStorehouseType())) {
+			//涓嶆槸浠庡噯澶囧崟杞叆鐨勫嚭搴撶敵璇凤紝鎵ц閿佸簱
+			lockOutboundStock(id);
+		}
+		//鍚姩娴佺▼
+		if (triggerProcess(outboundOrder)) {
+			outboundOrder.setOrderStatus(OutBillStatus.SUBMITTED.getValue());
+			updateById(outboundOrder);
 		}
     }
 
@@ -382,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));
@@ -417,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:
@@ -437,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("鏈煡鐨勫嚭搴撶被鍨嬶紒");
@@ -475,6 +503,9 @@
 					.setGoodsShelvesCode(detail.getOutboundLocation())
 					.setOutNumber(outboundQuantity)
 					.setOutStorehouseId(outboundOrder.getId())
+					.setRatedLife(ratedLife)
+					.setUseLife(useLife)
+					.setRemainingPercentage(remandLife)
 					.setOperateType("1");//1锛氭寜鐢宠鍗�
 			outStoreAddList.add(outStoreDetail);
 
@@ -561,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());
@@ -572,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 -> {
@@ -606,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