From 8c627df4abacbe7397d0c1831f1a71c62ebe15b2 Mon Sep 17 00:00:00 2001
From: maven <2163098428@qq.com>
Date: 星期三, 15 十月 2025 10:45:33 +0800
Subject: [PATCH] yys  1.随机排产

---
 main-business/src/main/java/com/ruoyi/business/service/impl/ProductionMasterServiceImpl.java |   44 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 44 insertions(+), 0 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 d4521c4..a77c7d4 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
@@ -11,6 +11,7 @@
 import com.ruoyi.business.entity.*;
 import com.ruoyi.business.mapper.*;
 import com.ruoyi.business.service.ProductionMasterService;
+import com.ruoyi.common.core.domain.model.LoginUser;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
@@ -458,4 +459,47 @@
 
         return productionIdsToDelete.size();
     }
+
+    @Override
+    public Object randomScheduling(LoginUser loginUser) {
+        List<OfficialInventory> officialInventories = officialInventoryMapper.selectList(null);
+        if(CollectionUtils.isEmpty(officialInventories)){
+            throw new BaseException("娌℃湁鍙皟搴︾殑搴撳瓨");
+        }
+        Random random = new Random();
+        // 鍦ㄥ畼鏂瑰簱瀛樹腑闅忔満閫夋嫨涓�涓�
+        OfficialInventory officialInventory = officialInventories.get(random.nextInt(officialInventories.size()));
+        List<ProductionInventory> productionInventories = new ArrayList<>();
+        ProductionInventory productionInventory = new ProductionInventory();
+        productionInventory.setOfficialId(officialInventory.getId());
+        productionInventory.setCoalId(officialInventory.getCoalId());
+        productionInventory.setInventoryQuantity(officialInventory.getInventoryQuantity().intValue());
+        productionInventory.setUsedQuantity(random.nextInt(officialInventory.getInventoryQuantity().intValue()) + 1);
+        productionInventories.add(productionInventory);
+        List<Production> productions = new ArrayList<>();
+        Production production = new Production();
+        production.setCoalId(officialInventory.getCoalId());
+        // 1-500闅忔満鐢熸垚
+        production.setEnergyConsumptionCost(BigDecimal.valueOf(random.nextInt(500) + 1));
+        production.setEquipmentDepreciation(BigDecimal.valueOf(random.nextInt(500) + 1));
+        production.setLaborCost(BigDecimal.valueOf(random.nextInt(500) + 1));
+        production.setProductionQuantity(BigDecimal.valueOf(random.nextInt(500) + 1));
+        production.setPurchasePrice(BigDecimal.valueOf(random.nextInt(500) + 1));
+
+        // 姹傚拰
+        BigDecimal add = production.getEquipmentDepreciation()
+                .add(production.getEnergyConsumptionCost())
+                .add(production.getLaborCost())
+                .add(production.getPurchasePrice())
+                .add(production.getProductionQuantity());
+        production.setTotalCost(add);
+        production.setType(2);
+        production.setProducerId(loginUser.getUserId());
+        production.setProducer(loginUser.getUsername());
+        productions.add(production);
+        ProductionMasterDto productionMasterDto = new ProductionMasterDto();
+        productionMasterDto.setProductionList(productions);
+        productionMasterDto.setProductionInventoryList(productionInventories);
+        return addOrEditPM(productionMasterDto);
+    }
 }

--
Gitblit v1.9.3