From 5eec9b5a9d8bf9e49663d5a51cab7490fef5b204 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期二, 26 八月 2025 15:22:03 +0800
Subject: [PATCH] yys  生产管控(完成基本功能)

---
 main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java |   69 +++++++++++++++++++++++++---------
 1 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java
index 4157611..25dae27 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java
@@ -19,7 +19,9 @@
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.time.LocalDate;
+import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.stream.Collectors;
 
@@ -171,7 +173,7 @@
         batchInsertInventories(masterId, dto.getProductionInventoryList());
 
         // 鎻掑叆寰呭叆搴撴暟鎹�
-        insertPendingInventory(dto.getProductionList());
+//        insertPendingInventory(dto.getProductionList());
 
         return 1;
     }
@@ -261,6 +263,7 @@
             BeanUtils.copyProperties(p, copy);
             copy.setId(null);
             copy.setProductionMasterId(masterId);
+            copy.setStatus(1);
             productionMapper.insert(copy);
         }
     }
@@ -281,14 +284,42 @@
     /**
      * 灏嗗姞宸ヤ骇鐢熺殑浜у搧璁板綍鍒板緟鍏ュ簱琛�
      */
-    private void insertPendingInventory(List<Production> list) {
+    public void insertPendingInventory(List<Production> list) {
+        LocalDate currentDate = LocalDate.now();
+        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
+        String formattedDate = currentDate.format(formatter);
+        final int SCALE = 2;
+        final RoundingMode ROUNDING_MODE = RoundingMode.HALF_UP;
+        final BigDecimal TAX_RATE = new BigDecimal("1.13");
+
         for (Production p : list) {
             PendingInventory pending = new PendingInventory();
             pending.setCoalId(p.getCoalId());
             pending.setInventoryQuantity(p.getProductionQuantity());
-            pending.setSupplierName("鐢熶骇鍔犲伐鍏ュ簱");
-            pending.setTotalPriceIncludingTax(p.getTotalCost());
-            pending.setPriceIncludingTax(p.getPurchasePrice());
+            pending.setUnit("鍚�");
+            pending.setSupplierName(formattedDate + " - " + "鐢熶骇鍔犲伐鍏ュ簱");
+
+            // 闈炵┖澶勭悊
+            BigDecimal totalCost = p.getTotalCost() == null ? BigDecimal.ZERO : p.getTotalCost();
+            BigDecimal productionQuantity = p.getProductionQuantity() == null ? BigDecimal.ZERO : p.getProductionQuantity();
+
+            // 鍚◣鎬讳环
+            BigDecimal totalPriceIncludingTax = totalCost.multiply(productionQuantity)
+                    .setScale(SCALE, ROUNDING_MODE);
+            pending.setTotalPriceIncludingTax(totalPriceIncludingTax);
+
+            // 鍚◣鍗曚环
+            pending.setPriceIncludingTax(totalCost.setScale(SCALE, ROUNDING_MODE));
+
+            // 涓嶅惈绋庡崟浠凤紙鐩存帴淇濈暀2浣嶅皬鏁帮級
+            BigDecimal priceExcludingTax = totalCost.divide(TAX_RATE, SCALE, ROUNDING_MODE);
+            pending.setPriceExcludingTax(priceExcludingTax);
+
+            // 涓嶅惈绋庢�讳环
+            BigDecimal totalPriceExcludingTax = priceExcludingTax.multiply(productionQuantity)
+                    .setScale(SCALE, ROUNDING_MODE);
+            pending.setTotalPriceExcludingTax(totalPriceExcludingTax);
+
             pending.setRegistrantId(p.getProducerId());
             pending.setRegistrationDate(LocalDate.now());
             pendingInventoryMapper.insert(pending);
@@ -372,20 +403,20 @@
         }
 
         // 鎵归噺鏇存柊瀹樻柟搴撳瓨
-        for (Map.Entry<Long, BigDecimal> entry : inventoryAdjustMap.entrySet()) {
-            OfficialInventory official = officialInventoryMapper.selectById(entry.getKey());
-            if (official == null) {
-                throw new BaseException("瀹樻柟搴撳瓨涓嶅瓨鍦紝ID: " + entry.getKey());
-            }
-
-            // 浣跨敤绾跨▼瀹夊叏鐨凚igDecimal鎿嶄綔
-            official.setInventoryQuantity(
-                    Optional.ofNullable(official.getInventoryQuantity())
-                            .orElse(BigDecimal.ZERO)
-                            .add(entry.getValue())
-            );
-            officialInventoryMapper.updateById(official);
-        }
+//        for (Map.Entry<Long, BigDecimal> entry : inventoryAdjustMap.entrySet()) {
+//            OfficialInventory official = officialInventoryMapper.selectById(entry.getKey());
+//            if (official == null) {
+//                throw new BaseException("瀹樻柟搴撳瓨涓嶅瓨鍦紝ID: " + entry.getKey());
+//            }
+//
+//            // 浣跨敤绾跨▼瀹夊叏鐨凚igDecimal鎿嶄綔
+//            official.setInventoryQuantity(
+//                    Optional.ofNullable(official.getInventoryQuantity())
+//                            .orElse(BigDecimal.ZERO)
+//                            .add(entry.getValue())
+//            );
+//            officialInventoryMapper.updateById(official);
+//        }
 
         // 鎵归噺鍒犻櫎鐢熶骇搴撳瓨
         if (!productionIdsToDelete.isEmpty()) {

--
Gitblit v1.9.3