From bb5bf872de5e67d7b406e3a305c9dfcbd0f218a6 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 26 六月 2025 18:03:55 +0800
Subject: [PATCH] 采购,正式库优化

---
 main-business/src/main/resources/db/migration/postgresql/V20250604104500__create_table_pending_inventory.sql     |    4 
 main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java                     |    4 
 main-business/src/main/java/com/ruoyi/business/entity/PurchaseRegistration.java                                  |    2 
 main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java                     |    5 +
 main-business/src/main/java/com/ruoyi/business/dto/ProductionMasterDto.java                                      |    2 
 main-business/src/main/java/com/ruoyi/business/controller/PurchaseRegistrationController.java                    |    8 
 main-business/src/main/resources/db/migration/postgresql/V20250604111200__create_table_official_inventory.sql    |    8 +
 main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java                    |   86 +++++++++++++++++
 main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java                                     |   11 +-
 main-business/src/main/java/com/ruoyi/business/service/PurchaseRegistrationService.java                          |    4 
 main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java                                     |   16 ++
 main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java                                      |   11 ++
 main-business/src/main/resources/db/migration/postgresql/V20250603160101__create_table_purchase_registration.sql |   38 +++---
 main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java                 |   51 +++++++---
 14 files changed, 194 insertions(+), 56 deletions(-)

diff --git a/main-business/src/main/java/com/ruoyi/business/controller/PurchaseRegistrationController.java b/main-business/src/main/java/com/ruoyi/business/controller/PurchaseRegistrationController.java
index d35457e..b749402 100644
--- a/main-business/src/main/java/com/ruoyi/business/controller/PurchaseRegistrationController.java
+++ b/main-business/src/main/java/com/ruoyi/business/controller/PurchaseRegistrationController.java
@@ -25,16 +25,16 @@
     private PurchaseRegistrationService purchaseRegistrationService;
 
     /**
-     * 鏌ヨ
+     * 閲囪喘鐧昏琛ㄦ煡璇�
      */
     @GetMapping("/list")
-    public R<IPage<PurchaseRegistration>> list(Page page, PurchaseRegistrationDto purchaseRegistrationDto) {
+    public R<IPage<PurchaseRegistration>> list(Page<PurchaseRegistration> page, PurchaseRegistrationDto purchaseRegistrationDto) {
         IPage<PurchaseRegistration> list = purchaseRegistrationService.selectPurchaseRegistrationList(page,purchaseRegistrationDto);
         return R.ok(list);
     }
 
     /**
-     * 鏂板淇敼
+     * 閲囪喘鐧昏琛ㄦ柊澧炰慨鏀�
      */
     @PostMapping("/addOrEditPR")
     public R addOrEditSupply(@RequestBody PurchaseRegistrationDto purchaseRegistrationDto) {
@@ -42,7 +42,7 @@
     }
 
     /**
-     * 鍒犻櫎
+     * 閲囪喘鐧昏琛ㄥ垹闄�
      */
     @DeleteMapping("/delPR")
     public R remove(@RequestBody Long[] ids) {
diff --git a/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java b/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java
index f21ce91..79b234f 100644
--- a/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java
+++ b/main-business/src/main/java/com/ruoyi/business/dto/OfficialInventoryDto.java
@@ -9,13 +9,12 @@
 @Data
 public class OfficialInventoryDto extends OfficialInventory {
 
-    private List<Map<String, String>> fields;
+    private List<Map<String, String>> fields;//鏌ヨ杩斿洖鐨勭叅绉嶄俊鎭敭鍊煎
 
-    private List<Long> ids;
+    private List<Long> ids;//瑕佸悎骞剁殑姝e紡搴撶殑id
 
-    /**
-     * 鐓ょ
-     */
-    private String coal;
+    private String coal; //鐓ょ
+
+    private String supplierName; //渚涘簲鍟�
 
 }
diff --git a/main-business/src/main/java/com/ruoyi/business/dto/ProductionMasterDto.java b/main-business/src/main/java/com/ruoyi/business/dto/ProductionMasterDto.java
index 7ac7670..4ef8db9 100644
--- a/main-business/src/main/java/com/ruoyi/business/dto/ProductionMasterDto.java
+++ b/main-business/src/main/java/com/ruoyi/business/dto/ProductionMasterDto.java
@@ -10,6 +10,8 @@
 @Data
 public class ProductionMasterDto extends ProductionMaster {
 
+    private String searchAll;
+
     private List<Production> productionList;  //鐢熶骇鏄庣粏
 
     private List<ProductionInventory>  productionInventoryList; //浣跨敤搴撳瓨鏄庣粏
diff --git a/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java b/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java
index 034e377..6dd6ed6 100644
--- a/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java
+++ b/main-business/src/main/java/com/ruoyi/business/entity/OfficialInventory.java
@@ -33,10 +33,11 @@
     @TableField(value = "pending_id")
     private Long pendingId;
     /**
-     * 渚涜揣鍟嗗悕绉�
+     * 渚涜揣鍟咺D
      */
-    @TableField(value = "supplier_name")
-    private String supplierName;
+    @TableField(value = "supplier_id")
+    private Long supplierId;
+
     /**
      * 鐓ょ
      */
@@ -81,7 +82,8 @@
      * 鐧昏浜篿d
      */
     @TableField(value = "registrant_id")
-    private String registrantId;
+    private Long registrantId;
+
     /**
      * 鐧昏鏃ユ湡
      */
@@ -89,6 +91,12 @@
     private LocalDate registrationDate;
 
     /**
+     * 鐓よ川鏂规id
+     */
+    @TableField(value = "coal_plan_id")
+    private Long coalPlanId;
+
+    /**
      * 鍚堝苟id
      */
     @TableField(value = "merge_id")
diff --git a/main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java b/main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java
index 1b4c928..e46fc5a 100644
--- a/main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java
+++ b/main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java
@@ -34,6 +34,12 @@
     @TableField(value = "master_id")
     private Long masterId;
     /**
+     *
+     * 閲囪喘id
+     */
+    @TableField(value = "purchase_id")
+    private Long purchaseId;
+    /**
      * 渚涜揣鍟嗗悕绉�
      */
     @TableField(value = "supplier_name")
@@ -84,6 +90,11 @@
     @TableField(value = "registrant_id")
     private Long registrantId;
     /**
+     * 鐓よ川鏂规id
+     */
+    @TableField(value = "coal_plan_id")
+    private Long coalPlanId;
+    /**
      * 鐧昏鏃ユ湡
      */
     @TableField(value = "registration_date")
diff --git a/main-business/src/main/java/com/ruoyi/business/entity/PurchaseRegistration.java b/main-business/src/main/java/com/ruoyi/business/entity/PurchaseRegistration.java
index 1cee4a2..482e72e 100644
--- a/main-business/src/main/java/com/ruoyi/business/entity/PurchaseRegistration.java
+++ b/main-business/src/main/java/com/ruoyi/business/entity/PurchaseRegistration.java
@@ -82,7 +82,7 @@
      * 鐧昏浜篿d
      */
     @TableField(value = "registrant_id")
-    private String registrantId;
+    private Long registrantId;
     /**
      * 鐧昏鏃ユ湡
      */
diff --git a/main-business/src/main/java/com/ruoyi/business/service/PurchaseRegistrationService.java b/main-business/src/main/java/com/ruoyi/business/service/PurchaseRegistrationService.java
index 910d656..3626551 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/PurchaseRegistrationService.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/PurchaseRegistrationService.java
@@ -2,9 +2,9 @@
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.baomidou.mybatisplus.extension.service.IService;
 import com.ruoyi.business.dto.PurchaseRegistrationDto;
 import com.ruoyi.business.entity.PurchaseRegistration;
-import com.baomidou.mybatisplus.extension.service.IService;
 
 /**
  * <p>
@@ -16,7 +16,7 @@
  */
 public interface PurchaseRegistrationService extends IService<PurchaseRegistration> {
 
-    IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto);
+    IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page<PurchaseRegistration> page, PurchaseRegistrationDto purchaseRegistrationDto);
 
     int addOrEditPR(PurchaseRegistrationDto purchaseRegistrationDto);
 
diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
index 6e1f4d6..ceafff7 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/OfficialInventoryServiceImpl.java
@@ -9,9 +9,11 @@
 import com.ruoyi.basic.entity.CoalField;
 import com.ruoyi.basic.entity.CoalInfo;
 import com.ruoyi.basic.entity.CoalValue;
+import com.ruoyi.basic.entity.Supply;
 import com.ruoyi.basic.mapper.CoalFieldMapper;
 import com.ruoyi.basic.mapper.CoalInfoMapper;
 import com.ruoyi.basic.mapper.CoalValueMapper;
+import com.ruoyi.basic.mapper.SupplyMapper;
 import com.ruoyi.business.dto.OfficialInventoryDto;
 import com.ruoyi.business.entity.OfficialInventory;
 import com.ruoyi.business.mapper.OfficialInventoryMapper;
@@ -48,12 +50,15 @@
 
     private final CoalInfoMapper coalInfoMapper;
 
+    private final SupplyMapper supplyMapper;
+
 
     @Override
     public IPage<OfficialInventoryDto> selectOfficialInventoryList(Page page, OfficialInventoryDto officialInventoryDto) {
 
         //  鍏堟煡鍑哄師濮嬫暟鎹紙OfficialInventory锛�
         LambdaQueryWrapper<OfficialInventory> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.orderByAsc(OfficialInventory::getCreateTime);
         IPage<OfficialInventory> entityPage = officialInventoryMapper.selectPage(page, queryWrapper);
 
         //  鍒涘缓涓�涓柊鐨� Dto 鍒嗛〉缁撴灉
@@ -61,6 +66,19 @@
         BeanUtils.copyProperties(entityPage, dtoPage);
 
         List<OfficialInventoryDto> dtoList = new ArrayList<>();
+
+        List<Long> supplierIds = entityPage.getRecords().stream()
+                .map(OfficialInventory::getSupplierId)
+                .toList();
+
+        Map<Long, Supply> supplyMap;
+        if (!supplierIds.isEmpty()) {
+            List<Supply> infos = supplyMapper.selectList(new LambdaQueryWrapper<Supply>().in(Supply::getId, supplierIds));
+            supplyMap = infos.stream().collect(Collectors.toMap(Supply::getId, Function.identity()));
+        } else {
+            supplyMap = new HashMap<>();
+        }
+
 
         //  鏌ヨ鎵�鏈夊彲鐢ㄥ瓧娈碉紙CoalField锛�
         List<CoalField> coalFields = coalFieldMapper.selectList(null);
@@ -88,6 +106,13 @@
         for (OfficialInventory entity : entityPage.getRecords()) {
             OfficialInventoryDto dto = new OfficialInventoryDto();
             BeanUtils.copyProperties(entity, dto);
+
+            // 渚涘簲鍟嗕俊鎭�
+            Supply supply = supplyMap.get(entity.getSupplierId());
+            if (supply != null) {
+                dto.setSupplierName(supply.getSupplierName());
+            }
+
             List<CoalValue> coalValues;
             if (entity.getMergeId() == null) {
                 coalValues = coalValueMapper.selectList(new LambdaQueryWrapper<CoalValue>()
@@ -136,6 +161,64 @@
     public int editOfficial(OfficialInventoryDto officialInventoryDto) {
         OfficialInventory officialInventory = new OfficialInventory();
         BeanUtils.copyProperties(officialInventoryDto, officialInventory);
+
+        if (officialInventoryDto.getMergeId() != null) {
+            // 1. 鏋勫缓鏌ヨ鏉′欢
+            LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getId())
+                    .eq(CoalValue::getType, "2");
+
+            // 2. 鏌ヨ澶氫釜绗﹀悎鏉′欢鐨凜oalValue璁板綍
+            List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper);
+
+            if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) {
+                // 3. 鍒涘缓瀛楁鏄犲皠鍏崇郴 (field key -> coal_value)
+                Map<String, String> fieldValueMap = new HashMap<>();
+                for (Map<String, String> fieldMap : officialInventoryDto.getFields()) {
+                    fieldValueMap.putAll(fieldMap);
+                }
+
+                // 4. 鏇存柊
+                for (CoalValue coalValue : coalValues) {
+                    String fieldKey = coalValue.getFields(); // 鏁版嵁搴撲腑鐨刦ield key
+                    if (fieldValueMap.containsKey(fieldKey)) {
+                        String newValue = fieldValueMap.get(fieldKey);
+                        if (!Objects.equals(coalValue.getCoalValue(), newValue)) {
+                            coalValue.setCoalValue(newValue);
+                            coalValueMapper.updateById(coalValue);
+                        }
+                    }
+                }
+            }
+        } else {
+            // 鏋勫缓鏌ヨ鏉′欢
+            LambdaQueryWrapper<CoalValue> queryWrapper = new LambdaQueryWrapper<>();
+            queryWrapper.eq(CoalValue::getPlanId, officialInventoryDto.getPendingId())
+                    .eq(CoalValue::getType, "1");
+
+            // 2. 鏌ヨ澶氫釜绗﹀悎鏉′欢鐨凜oalValue璁板綍
+            List<CoalValue> coalValues = coalValueMapper.selectList(queryWrapper);
+
+            if (!CollectionUtils.isEmpty(coalValues) && !CollectionUtils.isEmpty(officialInventoryDto.getFields())) {
+                // 3. 鍒涘缓瀛楁鏄犲皠鍏崇郴 (field key -> coal_value)
+                Map<String, String> fieldValueMap = new HashMap<>();
+                for (Map<String, String> fieldMap : officialInventoryDto.getFields()) {
+                    fieldValueMap.putAll(fieldMap);
+                }
+
+                // 4. 鏇存柊
+                for (CoalValue coalValue : coalValues) {
+                    String fieldKey = coalValue.getFields(); // 鏁版嵁搴撲腑鐨刦ield key
+                    if (fieldValueMap.containsKey(fieldKey)) {
+                        String newValue = fieldValueMap.get(fieldKey);
+                        if (!Objects.equals(coalValue.getCoalValue(), newValue)) {
+                            coalValue.setCoalValue(newValue);
+                            coalValueMapper.updateById(coalValue);
+                        }
+                    }
+                }
+            }
+        }
         return officialInventoryMapper.updateById(officialInventory);
     }
 
@@ -185,7 +268,8 @@
         BeanUtils.copyProperties(officialInventoryDto, officialInventory);
         officialInventory.setId(null);
         officialInventory.setMergeId(ids.toString());
-        officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserName());
+        officialInventory.setSupplierId(officialInventoryDto.getSupplierId());
+        officialInventory.setRegistrantId(SecurityUtils.getLoginUser().getUser().getUserId());
         if (officialInventoryMapper.insert(officialInventory) <= 0) {
             throw new BaseException("搴撳瓨璁板綍鍒涘缓澶辫触");
         }
diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
index 5e340eb..412e7bb 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PendingInventoryServiceImpl.java
@@ -233,6 +233,7 @@
             BigDecimal left = pendingInventory.getInventoryQuantity().subtract(quantity);
             if (left.compareTo(BigDecimal.ZERO) > 0) {
                 pendingInventory.setInventoryQuantity(left);
+                pendingInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 pendingInventoryMapper.updateById(pendingInventory);
             } else {
                 pendingInventoryMapper.deleteById(pendingInventoryDto.getPId());
@@ -242,8 +243,11 @@
                 OfficialInventory officialInventory = new OfficialInventory();
                 BeanUtils.copyProperties(pendingInventory, officialInventory);
                 officialInventory.setId(null);
+                officialInventory.setCoalPlanId(pendingInventoryDto.getCoalPlanId());
                 officialInventory.setPendingId(pendingInventoryDto.getPId());
                 officialInventory.setInventoryQuantity(quantity);
+                officialInventory.setRegistrantId(1L);
+                officialInventory.setSupplierId(pendingInventoryDto.getSupplierId());
                 officialInventoryMapper.insert(officialInventory);
             } else {
                 OfficialInventory officialInventory = officialInventoryMapper.selectById(pendingInventoryDto.getOfficialId());
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 3d006fd..c92da97 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
@@ -50,6 +50,11 @@
         // 1. 鏋勫缓涓昏〃鏌ヨ鏉′欢
         LambdaQueryWrapper<ProductionMaster> masterQueryWrapper = new LambdaQueryWrapper<>();
 
+
+
+
+
+
         // 2. 鎵ц涓昏〃鍒嗛〉鏌ヨ
         IPage<ProductionMaster> entityPage = productionMasterMapper.selectPage(page, masterQueryWrapper);
 
diff --git a/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java b/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java
index 51c2d14..ad63a6c 100644
--- a/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java
+++ b/main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java
@@ -1,7 +1,6 @@
 package com.ruoyi.business.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
@@ -24,7 +23,10 @@
 import org.springframework.util.Assert;
 
 import java.time.LocalDate;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Objects;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -48,16 +50,29 @@
     private final SupplyMapper supplyMapper;
 
     @Override
-    public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto) {
+    public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page<PurchaseRegistration> page, PurchaseRegistrationDto dto) {
         LambdaQueryWrapper<PurchaseRegistration> queryWrapper = new LambdaQueryWrapper<>();
-        if (StringUtils.isNotBlank(purchaseRegistrationDto.getSearchAll())){
-            queryWrapper.and(wrapper -> wrapper
-                    .like(PurchaseRegistration::getCoalId, purchaseRegistrationDto.getSearchAll())
-                    .or()
-                    .like(PurchaseRegistration::getSupplierName, purchaseRegistrationDto.getSearchAll())
-            );
+
+        String keyword = dto.getSearchAll();
+        if (StringUtils.isNotBlank(keyword)) {
+            // 鏌ヨ鐓ょ鍚嶇О涓ā绯婂尮閰嶇殑coalId鍒楄〃
+            List<Long> matchedCoalIds = coalInfoMapper.selectList(
+                            new LambdaQueryWrapper<CoalInfo>().like(CoalInfo::getCoal, keyword)
+                    ).stream()
+                    .map(CoalInfo::getId)
+                    .collect(Collectors.toList());
+
+            // 缁勮鏌ヨ鏉′欢锛氱叅绉岻D鍦ㄥ尮閰嶇殑鍒楄〃涓� 鎴� 渚涘簲鍟嗗悕绉板尮閰�
+            queryWrapper.and(w -> {
+                if (!matchedCoalIds.isEmpty()) {
+                    w.in(PurchaseRegistration::getCoalId, matchedCoalIds).or();
+                }
+                w.like(PurchaseRegistration::getSupplierName, keyword);
+            });
         }
+
         queryWrapper.orderByDesc(PurchaseRegistration::getCreateTime);
+
         return purchaseRegistrationMapper.selectPage(page, queryWrapper);
     }
 
@@ -74,7 +89,6 @@
         if (coalInfo == null) {
             throw new BaseException("鐓ょ淇℃伅涓嶅瓨鍦�");
         }
-//        purchaseRegistration.setCoal(coalInfo.getCoal());
         Supply supply = supplyMapper.selectById(purchaseRegistrationDto.getSupplierId());
         if (supply == null) {
             throw new BaseException("渚涘簲鍟嗕俊鎭笉瀛樺湪");
@@ -109,22 +123,27 @@
         BeanUtils.copyProperties(purchaseRegistration, pendingInventory);
 
         // 璁剧疆寰呭叆搴撹褰曠壒鏈夌殑灞炴�э紙濡傛灉鏈夛級
+        pendingInventory.setId(null);
+        pendingInventory.setPurchaseId(purchaseRegistration.getId());
         pendingInventory.setCoalId(purchaseRegistration.getCoalId());
         pendingInventory.setInventoryQuantity(purchaseRegistration.getPurchaseQuantity());
         return pendingInventory;
     }
 
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public int delByIds(Long[] ids) {
-        // 妫�鏌ュ弬鏁�
         if (ids == null || ids.length == 0) {
             return 0;
         }
-        // 鏋勯�犳洿鏂版潯浠�
-        UpdateWrapper<PurchaseRegistration> updateWrapper = new UpdateWrapper<>();
-        updateWrapper.in("id", ids)
-                .set("deleted", 1);  // 璁剧疆 deleted 涓� 1 琛ㄧず宸插垹闄�
-        // 鎵ц鎵归噺閫昏緫鍒犻櫎
-        return purchaseRegistrationMapper.update(null, updateWrapper);
+
+        // 1. 鍒犻櫎鍏宠仈鐨凱endingInventory璁板綍
+        LambdaQueryWrapper<PendingInventory> wrapper = new LambdaQueryWrapper<>();
+        wrapper.in(PendingInventory::getPurchaseId, Arrays.asList(ids));
+        pendingInventoryMapper.delete(wrapper);  // 鏀逛负delete鎿嶄綔
+
+        // 2. 鎵归噺鍒犻櫎閲囪喘娉ㄥ唽璁板綍
+        return purchaseRegistrationMapper.deleteByIds(Arrays.asList(ids));
     }
+
 }
diff --git a/main-business/src/main/resources/db/migration/postgresql/V20250603160101__create_table_purchase_registration.sql b/main-business/src/main/resources/db/migration/postgresql/V20250603160101__create_table_purchase_registration.sql
index 92dd4e6..d24a052 100644
--- a/main-business/src/main/resources/db/migration/postgresql/V20250603160101__create_table_purchase_registration.sql
+++ b/main-business/src/main/resources/db/migration/postgresql/V20250603160101__create_table_purchase_registration.sql
@@ -1,26 +1,26 @@
 -- 鍒涘缓 purchase_registration 琛�
 CREATE TABLE purchase_registration
 (
-    id                        BIGSERIAL PRIMARY KEY,                              -- 涓婚敭ID锛岃嚜鍔ㄩ�掑
-    supplier_id               BIGINT         NOT NULL,                            -- 渚涘簲鍟嗗悕绉癐D锛屼笉鍏佽涓虹┖
-    supplier_name             VARCHAR(255)   NOT NULL,                            -- 渚涘簲鍟嗗悕绉帮紝涓嶅厑璁镐负绌�
-    unit                      VARCHAR(50)    NOT NULL,                            -- 鍗曚綅锛屼笉鍏佽涓虹┖
-    coal_id                   BIGINT         NOT NULL,                            -- 鐓ょ绫诲瀷id
-    coal                      VARCHAR(255),                                       -- 鐓ょ绫诲瀷
-    purchase_quantity         DECIMAL(10, 2) NOT NULL,                            -- 閲囪喘鏁伴噺锛屼笉鍏佽涓虹┖
-    price_including_tax       DECIMAL(10, 2) NOT NULL,                            -- 鍗曚环锛堝惈绋庯級锛屼笉鍏佽涓虹┖
-    total_price_including_tax DECIMAL(10, 2) NOT NULL,                            -- 鎬讳环锛堝惈绋庯級锛屼笉鍏佽涓虹┖
-    tax_rate                  DECIMAL(5, 2)  NOT NULL,                            -- 绋庣巼锛屼笉鍏佽涓虹┖
-    price_excluding_tax       DECIMAL(10, 2) NOT NULL,                            -- 涓嶅惈绋庡崟浠凤紝涓嶅厑璁镐负绌�
-    total_price_excluding_tax DECIMAL(10, 2) NOT NULL,                            -- 涓嶅惈绋庢�讳环锛屼笉鍏佽涓虹┖
-    registrant_id             VARCHAR(255)   NOT NULL,                            -- 鐧昏浜篿d锛屼笉鍏佽涓虹┖
-    registration_date         DATE           NOT NULL,                            -- 鐧昏鏃ユ湡锛屼笉鍏佽涓虹┖
+    id                        BIGSERIAL PRIMARY KEY,             -- 涓婚敭ID锛岃嚜鍔ㄩ�掑
+    supplier_id               BIGINT         NOT NULL,           -- 渚涘簲鍟嗗悕绉癐D锛屼笉鍏佽涓虹┖
+    supplier_name             VARCHAR(255)   NOT NULL,           -- 渚涘簲鍟嗗悕绉帮紝涓嶅厑璁镐负绌�
+    unit                      VARCHAR(50)    NOT NULL,           -- 鍗曚綅锛屼笉鍏佽涓虹┖
+    coal_id                   BIGINT         NOT NULL,           -- 鐓ょ绫诲瀷id
+    coal                      VARCHAR(255),                      -- 鐓ょ绫诲瀷
+    purchase_quantity         DECIMAL(10, 2) NOT NULL,           -- 閲囪喘鏁伴噺锛屼笉鍏佽涓虹┖
+    price_including_tax       DECIMAL(10, 2) NOT NULL,           -- 鍗曚环锛堝惈绋庯級锛屼笉鍏佽涓虹┖
+    total_price_including_tax DECIMAL(10, 2) NOT NULL,           -- 鎬讳环锛堝惈绋庯級锛屼笉鍏佽涓虹┖
+    tax_rate                  DECIMAL(5, 2)  NOT NULL,           -- 绋庣巼锛屼笉鍏佽涓虹┖
+    price_excluding_tax       DECIMAL(10, 2) NOT NULL,           -- 涓嶅惈绋庡崟浠凤紝涓嶅厑璁镐负绌�
+    total_price_excluding_tax DECIMAL(10, 2) NOT NULL,           -- 涓嶅惈绋庢�讳环锛屼笉鍏佽涓虹┖
+    registrant_id             BIGINT         NOT NULL,           -- 鐧昏浜篿d锛屼笉鍏佽涓虹┖
+    registration_date         DATE           NOT NULL,           -- 鐧昏鏃ユ湡锛屼笉鍏佽涓虹┖
 
-    deleted                   INT            NOT NULL  DEFAULT 0,                 -- 杞垹闄ゆ爣蹇楋細0=鏈垹闄わ紝1=宸插垹闄�
-    create_by                 VARCHAR(255),                                       -- 鍒涘缓浜虹敤鎴峰悕
-    create_time               TIMESTAMP WITHOUT TIME ZONE, -- 鍒涘缓鏃堕棿锛岄粯璁ゅ綋鍓嶆椂闂�
-    update_by                 VARCHAR(255),                                       -- 鏈�鍚庢洿鏂颁汉鐢ㄦ埛鍚�
-    update_time               TIMESTAMP WITHOUT TIME ZONE  -- 鏈�鍚庢洿鏂版椂闂达紝榛樿褰撳墠鏃堕棿
+    deleted                   INT            NOT NULL DEFAULT 0, -- 杞垹闄ゆ爣蹇楋細0=鏈垹闄わ紝1=宸插垹闄�
+    create_by                 VARCHAR(255),                      -- 鍒涘缓浜虹敤鎴峰悕
+    create_time               TIMESTAMP WITHOUT TIME ZONE,       -- 鍒涘缓鏃堕棿锛岄粯璁ゅ綋鍓嶆椂闂�
+    update_by                 VARCHAR(255),                      -- 鏈�鍚庢洿鏂颁汉鐢ㄦ埛鍚�
+    update_time               TIMESTAMP WITHOUT TIME ZONE        -- 鏈�鍚庢洿鏂版椂闂达紝榛樿褰撳墠鏃堕棿
 );
 
 -- 涓鸿〃娣诲姞娉ㄩ噴
diff --git a/main-business/src/main/resources/db/migration/postgresql/V20250604104500__create_table_pending_inventory.sql b/main-business/src/main/resources/db/migration/postgresql/V20250604104500__create_table_pending_inventory.sql
index d51c775..83e436d 100644
--- a/main-business/src/main/resources/db/migration/postgresql/V20250604104500__create_table_pending_inventory.sql
+++ b/main-business/src/main/resources/db/migration/postgresql/V20250604104500__create_table_pending_inventory.sql
@@ -17,6 +17,8 @@
     supplier_id               BIGINT,                                 -- 渚涜揣鍟咺D
     coal_id                   BIGINT,                                 -- 鐓ょID
     master_id                 BIGINT,                                 -- 鐢熶骇鍔犲伐id
+    purchase_id               BIGINT,                                 -- 閲囪喘id
+    coal_plan_id               BIGINT,                                 -- 鐓よ川鏂规id
 
     deleted                   INTEGER      DEFAULT 0,                 -- 杞垹闄ゆ爣蹇楋紝0=鏈垹闄わ紝1=宸插垹闄�
     create_by                 VARCHAR(255),                           -- 鍒涘缓璇ヨ褰曠殑鐢ㄦ埛
@@ -45,6 +47,8 @@
 COMMENT ON COLUMN pending_inventory.supplier_id IS '渚涜揣鍟咺D';
 COMMENT ON COLUMN pending_inventory.coal_id IS '鐓ょID';
 COMMENT ON COLUMN pending_inventory.master_id IS '鐢熶骇鍔犲伐id';
+COMMENT ON COLUMN pending_inventory.purchase_id IS '閲囪喘id';
+COMMENT ON COLUMN pending_inventory.coal_plan_id IS '鐓よ川鏂规id';
 
 COMMENT ON COLUMN pending_inventory.deleted IS '杞垹闄ゆ爣蹇楋紝0=鏈垹闄わ紝1=宸插垹闄�';
 COMMENT ON COLUMN pending_inventory.create_by IS '鍒涘缓璇ヨ褰曠殑鐢ㄦ埛';
diff --git a/main-business/src/main/resources/db/migration/postgresql/V20250604111200__create_table_official_inventory.sql b/main-business/src/main/resources/db/migration/postgresql/V20250604111200__create_table_official_inventory.sql
index d9562f7..b40aa8e 100644
--- a/main-business/src/main/resources/db/migration/postgresql/V20250604111200__create_table_official_inventory.sql
+++ b/main-business/src/main/resources/db/migration/postgresql/V20250604111200__create_table_official_inventory.sql
@@ -2,7 +2,7 @@
 CREATE TABLE official_inventory
 (
     id                        BIGSERIAL PRIMARY KEY,             -- 涓婚敭ID
-    supplier_name             VARCHAR(255)   NOT NULL,           -- 渚涜揣鍟嗗悕绉�
+    supplier_id               BIGINT,                            -- 渚涜揣鍟唅d
     coal_id                   BIGINT         NOT NULL,           -- 鐓ょ
     unit                      VARCHAR(50)    NOT NULL,           -- 鍗曚綅
     inventory_quantity        DECIMAL(10, 0),                    -- 搴撳瓨鏁伴噺
@@ -11,9 +11,10 @@
     price_excluding_tax       DECIMAL(10, 2) NOT NULL,           -- 涓嶅惈绋庡崟浠�
     total_price_excluding_tax DECIMAL(10, 2) NOT NULL,           -- 涓嶅惈绋庢�讳环
     pending_replenishment     DECIMAL(10, 0),                    -- 寰呰ˉ搴�
-    registrant_id             VARCHAR(50)    NOT NULL,           -- 鐧昏浜篿d
+    registrant_id             BIGINT         NOT NULL,           -- 鐧昏浜篿d
     type                      VARCHAR(50),                       -- 绫诲瀷       1 閲囪喘/ 2 姝e紡   鍏ュ簱
     pending_id                BIGINT,                            -- 寰呭叆搴搃d
+    coal_plan_id               BIGINT,                                 -- 鐓よ川鏂规id
     merge_id                  VARCHAR(255),                      -- 鍚堝苟id
     registration_date         TIMESTAMP WITHOUT TIME ZONE,
 
@@ -29,7 +30,7 @@
 
 -- 娣诲姞瀛楁娉ㄩ噴
 COMMENT ON COLUMN official_inventory.id IS '涓婚敭ID';
-COMMENT ON COLUMN official_inventory.supplier_name IS '渚涜揣鍟嗗悕绉�';
+COMMENT ON COLUMN official_inventory.supplier_id IS '渚涜揣鍟唅d';
 COMMENT ON COLUMN official_inventory.coal_id IS '鐓ょid';
 COMMENT ON COLUMN official_inventory.unit IS '鍗曚綅';
 COMMENT ON COLUMN official_inventory.inventory_quantity IS '搴撳瓨鏁伴噺';
@@ -39,6 +40,7 @@
 COMMENT ON COLUMN official_inventory.registrant_id IS '鐧昏浜篿d';
 COMMENT ON COLUMN official_inventory.registration_date IS '鐧昏鏃ユ湡';
 COMMENT ON COLUMN official_inventory.merge_id IS '鍚堝苟id';
+COMMENT ON COLUMN official_inventory.coal_plan_id IS '鐓よ川鏂规id';
 
 COMMENT ON COLUMN official_inventory.deleted IS '杞垹闄ゆ爣蹇楋紝0=鏈垹闄わ紝1=宸插垹闄�';
 COMMENT ON COLUMN official_inventory.create_by IS '鍒涘缓璇ヨ褰曠殑鐢ㄦ埛';

--
Gitblit v1.9.3