From 733b9e6837365d2817d7e8a0005b2c167c18f77e Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期四, 19 六月 2025 17:58:48 +0800
Subject: [PATCH] 1.生产加工  2.煤种id优化

---
 main-business/src/main/java/com/ruoyi/business/dto/PurchaseRegistrationDto.java                  |    2 
 basic-server/src/main/java/com/ruoyi/basic/controller/CoalInfoController.java                    |   14 ++++
 basic-server/src/main/java/com/ruoyi/basic/service/CoalInfoService.java                          |    4 +
 basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalInfoServiceImpl.java                 |    8 ++
 main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java     |   92 +++++++++++++++++++-----------
 main-business/src/main/java/com/ruoyi/business/entity/PendingInventory.java                      |    5 +
 main-business/src/main/java/com/ruoyi/business/entity/Production.java                            |    7 --
 main-business/src/main/java/com/ruoyi/business/entity/ProductionMaster.java                      |    7 ++
 main-business/src/main/java/com/ruoyi/business/service/impl/PurchaseRegistrationServiceImpl.java |    8 ++
 9 files changed, 103 insertions(+), 44 deletions(-)

diff --git a/basic-server/src/main/java/com/ruoyi/basic/controller/CoalInfoController.java b/basic-server/src/main/java/com/ruoyi/basic/controller/CoalInfoController.java
index 18937a0..b97c3d1 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/controller/CoalInfoController.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/controller/CoalInfoController.java
@@ -9,6 +9,8 @@
 import lombok.AllArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
+import java.util.List;
+
 /**
  * <p>
  * 鐓ょ淇℃伅琛� 鍓嶇鎺у埗鍣�
@@ -26,14 +28,22 @@
     private CoalInfoService coalInfoService;
 
     /**
-     * 鏌ヨ
+     * 鐓ょ鏌ヨ
      */
     @GetMapping("/list")
     public R<IPage<CoalInfo>> list(Page page, CoalInfoDto coalInfoDto) {
-        IPage<CoalInfo> list = coalInfoService.selectCoalInfoList(page,coalInfoDto);
+        IPage<CoalInfo> list = coalInfoService.selectCoalInfoList(page, coalInfoDto);
         return R.ok(list);
     }
 
+    /**
+     * 鐓ょ淇℃伅 list
+     */
+    @GetMapping("/coalInfoList")
+    public R<List<CoalInfo>> coalInfoList() {
+        return R.ok(coalInfoService.coalInfoList());
+    }
+
 
     /**
      * 鏂板淇敼
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/CoalInfoService.java b/basic-server/src/main/java/com/ruoyi/basic/service/CoalInfoService.java
index a1a1439..7824e81 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/CoalInfoService.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/CoalInfoService.java
@@ -6,6 +6,8 @@
 import com.ruoyi.basic.dto.CoalInfoDto;
 import com.ruoyi.basic.entity.CoalInfo;
 
+import java.util.List;
+
 /**
  * <p>
  * 鐓ょ淇℃伅琛� 鏈嶅姟绫�
@@ -21,4 +23,6 @@
     int addOrEditCoalInfo(CoalInfoDto coalInfoDto);
 
     int delCoalInfoByIds(Long[] ids);
+
+    List<CoalInfo> coalInfoList();
 }
diff --git a/basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalInfoServiceImpl.java b/basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalInfoServiceImpl.java
index fb2b5d0..0c81d6a 100644
--- a/basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalInfoServiceImpl.java
+++ b/basic-server/src/main/java/com/ruoyi/basic/service/impl/CoalInfoServiceImpl.java
@@ -16,6 +16,7 @@
 import org.springframework.util.StringUtils;
 
 import java.time.LocalDate;
+import java.util.List;
 import java.util.Objects;
 
 /**
@@ -36,7 +37,7 @@
     public IPage<CoalInfo> selectCoalInfoList(Page page, CoalInfoDto coalInfoDto) {
         LambdaQueryWrapper<CoalInfo> queryWrapper = new LambdaQueryWrapper<>();
         if (StringUtils.hasText(coalInfoDto.getSearchAll())) {
-            queryWrapper.like(CoalInfo::getCoal,coalInfoDto.getSearchAll());
+            queryWrapper.like(CoalInfo::getCoal, coalInfoDto.getSearchAll());
         }
         queryWrapper.orderByDesc(CoalInfo::getCreateTime);
         return coalInfoMapper.selectPage(page, queryWrapper);
@@ -70,4 +71,9 @@
         // 鎵ц鎵归噺閫昏緫鍒犻櫎
         return coalInfoMapper.update(null, updateWrapper);
     }
+
+    @Override
+    public List<CoalInfo> coalInfoList() {
+        return coalInfoMapper.selectList(null);
+    }
 }
diff --git a/main-business/src/main/java/com/ruoyi/business/dto/PurchaseRegistrationDto.java b/main-business/src/main/java/com/ruoyi/business/dto/PurchaseRegistrationDto.java
index 7fb13dc..10221b4 100644
--- a/main-business/src/main/java/com/ruoyi/business/dto/PurchaseRegistrationDto.java
+++ b/main-business/src/main/java/com/ruoyi/business/dto/PurchaseRegistrationDto.java
@@ -5,4 +5,6 @@
 
 @Data
 public class PurchaseRegistrationDto extends PurchaseRegistration {
+
+    private String searchAll;
 }
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 df8b306..07cea32 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
@@ -33,6 +33,11 @@
     /**
      * 鐓ょ
      */
+    @TableField(value = "coal_id")
+    private Long coalId;
+    /**
+     * 鐓ょ
+     */
     @TableField(value = "coal")
     private String coal;
     /**
diff --git a/main-business/src/main/java/com/ruoyi/business/entity/Production.java b/main-business/src/main/java/com/ruoyi/business/entity/Production.java
index 231294a..d760a80 100644
--- a/main-business/src/main/java/com/ruoyi/business/entity/Production.java
+++ b/main-business/src/main/java/com/ruoyi/business/entity/Production.java
@@ -38,15 +38,10 @@
     @TableField(value = "coal_id")
     private Long coalId;
     /**
-     * 鐓ょ
-     */
-    @TableField(value = "coal")
-    private String coal;
-    /**
      * 鐢熶骇鏁伴噺
      */
     @TableField(value = "production_quantity")
-    private Integer productionQuantity;
+    private BigDecimal productionQuantity;
     /**
      * 浜哄伐鎴愭湰
      */
diff --git a/main-business/src/main/java/com/ruoyi/business/entity/ProductionMaster.java b/main-business/src/main/java/com/ruoyi/business/entity/ProductionMaster.java
index aadb2ed..d35f0f6 100644
--- a/main-business/src/main/java/com/ruoyi/business/entity/ProductionMaster.java
+++ b/main-business/src/main/java/com/ruoyi/business/entity/ProductionMaster.java
@@ -33,10 +33,15 @@
     @TableField(value = "coal")
     private String coal;
     /**
+     * 鐓ょid
+     */
+    @TableField(value = "coal_id")
+    private String coalId;
+    /**
      * 鐢熶骇鏁伴噺
      */
     @TableField(value = "production_quantity")
-    private Integer productionQuantity;
+    private BigDecimal productionQuantity;
     /**
      * 浜哄伐鎴愭湰
      */
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 0a9dcc1..ff10b10 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
@@ -5,26 +5,21 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.basic.entity.CoalInfo;
+import com.ruoyi.basic.mapper.CoalInfoMapper;
 import com.ruoyi.business.dto.ProductionMasterDto;
-import com.ruoyi.business.entity.OfficialInventory;
-import com.ruoyi.business.entity.Production;
-import com.ruoyi.business.entity.ProductionInventory;
-import com.ruoyi.business.entity.ProductionMaster;
-import com.ruoyi.business.mapper.OfficialInventoryMapper;
-import com.ruoyi.business.mapper.ProductionInventoryMapper;
-import com.ruoyi.business.mapper.ProductionMapper;
-import com.ruoyi.business.mapper.ProductionMasterMapper;
+import com.ruoyi.business.entity.*;
+import com.ruoyi.business.mapper.*;
 import com.ruoyi.business.service.ProductionMasterService;
-import com.ruoyi.common.core.domain.entity.SysUser;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.bean.BeanUtils;
-import com.ruoyi.system.mapper.SysUserMapper;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.function.Function;
 import java.util.stream.Collectors;
 
 /**
@@ -47,7 +42,9 @@
 
     private final OfficialInventoryMapper officialInventoryMapper;
 
-    private final SysUserMapper sysUserMapper;
+    private final CoalInfoMapper coalInfoMapper;
+
+    private final PendingInventoryMapper pendingInventoryMapper;
 
     @Override
     public IPage<ProductionMasterDto> selectPMList(Page page, ProductionMasterDto productionMasterDto) {
@@ -126,8 +123,7 @@
         BigDecimal totalEnergyConsumptionCost = BigDecimal.ZERO;
         BigDecimal totalTotalCost = BigDecimal.ZERO;
         BigDecimal totalEquipmentDepreciation = BigDecimal.ZERO;
-        int totalProductionQuantity = 0;
-        StringBuilder coalBuilder = new StringBuilder();
+        BigDecimal totalProductionQuantity = BigDecimal.ZERO;
 
         for (Production production : productionMasterDto.getProductionList()) {
             totalPurchasePrice = totalPurchasePrice.add(production.getPurchasePrice());
@@ -135,13 +131,14 @@
             totalEnergyConsumptionCost = totalEnergyConsumptionCost.add(production.getEnergyConsumptionCost());
             totalTotalCost = totalTotalCost.add(production.getTotalCost());
             totalEquipmentDepreciation = totalEquipmentDepreciation.add(production.getEquipmentDepreciation());
-            totalProductionQuantity += production.getProductionQuantity();
-            if (coalBuilder.length() > 0) {
-                coalBuilder.append(","); // 鍦ㄥ厓绱犱箣闂存坊鍔犻�楀彿
-            }
-            coalBuilder.append(production.getCoal());
+            totalProductionQuantity = production.getProductionQuantity().add(totalProductionQuantity);
         }
-        String coalStr = coalBuilder.toString(); // 鐩存帴鑾峰彇鎷兼帴缁撴灉
+        //鐓ょ瀛楁
+        List<Long> coalIds = productionMasterDto.getProductionList().stream()
+                .map(Production::getCoalId)
+                .collect(Collectors.toList());
+
+        List<CoalInfo> coalInfos = coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds));
 
         // 2. 鍒涘缓涓昏〃瀵硅薄
         ProductionMaster productionMaster = new ProductionMaster();
@@ -150,18 +147,13 @@
         productionMaster.setEquipmentDepreciation(totalEquipmentDepreciation);
         productionMaster.setEnergyConsumptionCost(totalEnergyConsumptionCost);
         productionMaster.setLaborCost(totalLaborCost);
-        productionMaster.setCoal(coalStr);
+        productionMaster.setCoal(coalInfos.stream().map(CoalInfo::getCoal).collect(Collectors.joining(",")));
+        productionMaster.setCoalId(coalIds.stream().map(String::valueOf).collect(Collectors.joining(",")));
 
         Long masterId = productionMasterDto.getId();
         productionMaster.setId(masterId);
 
         // 3. 缁熶竴瀛愯〃澶勭悊閫昏緫
-        Long producerId = productionMasterDto.getProducerId();
-        if (producerId == null) {
-            throw new BaseException("璇烽�夋嫨鐢熶骇鑰�");
-        }
-        SysUser sysUser = sysUserMapper.selectUserById(producerId);
-        productionMaster.setProducer(sysUser.getUserName());
         if (masterId == null) {
             productionMasterMapper.insert(productionMaster);
             masterId = productionMaster.getId(); // 鑾峰彇鏂扮敓鎴愮殑ID
@@ -190,22 +182,54 @@
         batchInsertProductions(masterId, productionMasterDto.getProductionList());
         batchInsertInventories(masterId, productionMasterDto.getProductionInventoryList());
 
+        //5. 鎻掑叆鍒板緟鍏ュ簱
+        for (Production production : productionMasterDto.getProductionList()) {
+            PendingInventory pendingInventory = new PendingInventory();
+            pendingInventory.setCoalId(production.getCoalId());
+            pendingInventory.setInventoryQuantity(production.getProductionQuantity());
+            pendingInventory.setSupplierName("鐢熶骇鍔犲伐鍏ュ簱");
+            pendingInventory.setTotalPriceIncludingTax(production.getTotalCost());
+            pendingInventory.setPriceIncludingTax(production.getPurchasePrice());
+        }
         return 1;
     }
 
     // 鎵归噺鎻掑叆鐢熶骇鏁版嵁
     private void batchInsertProductions(Long masterId, List<Production> productions) {
-        List<Production> insertList = productions.stream()
-                .peek(p -> {
-                    p.setId(null);
-                    p.setProductionMasterId(masterId);
-                })
+        if (productions.isEmpty()) {
+            return;
+        }
+        // 1. 鏀堕泦鎵�鏈夐渶瑕佹煡璇㈢殑coalId
+        List<Long> coalIds = productions.stream()
+                .map(Production::getCoalId)
+                .filter(Objects::nonNull)
+                .distinct()
                 .collect(Collectors.toList());
 
-        if (!insertList.isEmpty()) {
-            for (Production production : productions) {
+        // 2. 鎵归噺鏌ヨcoalInfo鏁版嵁
+        Map<Long, CoalInfo> coalInfoMap = coalIds.isEmpty() ?
+                Collections.emptyMap() :
+                coalInfoMapper.selectList(new LambdaQueryWrapper<CoalInfo>().in(CoalInfo::getId, coalIds))
+                        .stream()
+                        .collect(Collectors.toMap(CoalInfo::getId, Function.identity()));
+        if (coalInfoMap.isEmpty()){
+            throw new BaseException("鐓ょ淇℃伅涓嶅瓨鍦�");
+        }
+
+        // 3. 鍑嗗鎵归噺鎻掑叆鏁版嵁
+        List<Production> batchInsertList = productions.stream()
+                .map(production -> {
+                    Production p = new Production(); // 鍒涘缓鏂板璞¢伩鍏嶅壇浣滅敤
+                    BeanUtils.copyProperties(production, p);
+                    // 澶嶅埗蹇呰瀛楁
+                    p.setProductionMasterId(masterId);
+                    p.setCoalId(production.getCoalId());
+                    return p;
+                })
+                .collect(Collectors.toList());
+        if (!batchInsertList.isEmpty()) {
+            for (Production production : batchInsertList) {
                 production.setId(null);
-                production.setProductionMasterId(masterId);
                 productionMapper.insert(production);
             }
         }
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 ff4252d..da11924 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
@@ -16,6 +16,7 @@
 import com.ruoyi.business.mapper.PurchaseRegistrationMapper;
 import com.ruoyi.business.service.PurchaseRegistrationService;
 import com.ruoyi.common.exception.base.BaseException;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import lombok.RequiredArgsConstructor;
 import org.springframework.stereotype.Service;
@@ -49,6 +50,13 @@
     @Override
     public IPage<PurchaseRegistration> selectPurchaseRegistrationList(Page page, PurchaseRegistrationDto purchaseRegistrationDto) {
         LambdaQueryWrapper<PurchaseRegistration> queryWrapper = new LambdaQueryWrapper<>();
+        if (StringUtils.isNotBlank(purchaseRegistrationDto.getSearchAll())){
+            queryWrapper.and(wrapper -> wrapper
+                    .like(PurchaseRegistration::getCoal, purchaseRegistrationDto.getSearchAll())
+                    .or()
+                    .like(PurchaseRegistration::getSupplierName, purchaseRegistrationDto.getSearchAll())
+            );
+        }
         queryWrapper.orderByDesc(PurchaseRegistration::getCreateTime);
         return purchaseRegistrationMapper.selectPage(page, queryWrapper);
     }

--
Gitblit v1.9.3