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 |   66 +++++++++++++++++++++++++++++++++
 1 files changed, 66 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 af6ca44..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;
@@ -324,8 +325,30 @@
 
             pending.setRegistrantId(p.getProducerId());
             pending.setRegistrationDate(LocalDate.now());
+
+            pending.setCode(generateCode(p.getType()));
+            pending.setType(p.getType());
             pendingInventoryMapper.insert(pending);
         }
+    }
+
+    private String generateCode(Integer type) {
+        LocalDate now = LocalDate.now();
+        String year = now.format(DateTimeFormatter.ofPattern("yyyyMMdd"));
+        String s = "";
+        //鐢熸垚缂栫爜
+        switch (type){
+            case 1:
+                s = "CP";
+                break;
+            case 2:
+                s = "YL";
+                break;
+        }
+        // 鏌ヨ褰撳ぉ寰呭叆搴撴柊澧炴潯鏁�
+        Long count = pendingInventoryMapper.selectCount(new LambdaQueryWrapper<PendingInventory>()
+                .apply("date_trunc('day', create_time) = date_trunc('day', now())"));
+        return s + year + String.format("%03d", count + 1);
     }
 
     @Override
@@ -436,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