From 768b011a17b9e63e4b6570989824152145952eda Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期三, 08 四月 2026 17:30:06 +0800
Subject: [PATCH] feat: 排产指派工人进行报工

---
 src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java |   35 +++++++++++++++++++++++++++++------
 1 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
index 13d7ccb..d3712b1 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -92,6 +92,25 @@
 
     @Override
     public Boolean addProductMain(ProductionProductMainDto dto) {
+        ProductWorkOrder workOrder = productWorkOrderMapper.selectById(dto.getWorkOrderId());
+        if (workOrder == null) {
+            throw new ServiceException("鎶ュ伐澶辫触,宸ュ崟涓嶅瓨鍦�");
+        }
+        Long currentUserId = dto.getUserId();
+        Long workerId = workOrder.getWorkerId();
+        Long handoverUserId = workOrder.getHandoverUserId();
+        boolean isWorker = workerId != null && workerId.equals(currentUserId);
+        boolean isHandover = handoverUserId != null && handoverUserId.equals(currentUserId);
+
+        if (!isWorker) {
+            // 涓嶆槸鎸囨淳宸ヤ汉
+            if (handoverUserId == null) {
+                throw new ServiceException("鎶ュ伐澶辫触,褰撳墠宸ュ崟鏈氦鎺�,鍙湁鎸囨淳宸ヤ汉鍙互鎶ュ伐");
+            }
+            if (!isHandover) {
+                throw new ServiceException("鎶ュ伐澶辫触,浣犱笉鏄宸ュ崟鐨勪氦鎺ヤ汉鍛�");
+            }
+        }
         SysUser user = userMapper.selectUserById(dto.getUserId());
         ProductionProductMain productionProductMain = new ProductionProductMain();
         //褰撳墠宸ヨ壓璺嚎瀵瑰簲鐨勫伐搴忚鎯�
@@ -207,7 +226,7 @@
                                 qualityInspectParamMapper.insert(param);
                             });
                 }
-            }else {
+            } else {
                 //鐩存帴鍏ュ簱
                 stockUtils.addStock(productProcessRouteItem.getProductModelId(), productQty, StockInQualifiedRecordTypeEnum.PRODUCTION_REPORT_STOCK_IN.getCode(), productionProductMain.getId());
             }
@@ -234,13 +253,17 @@
                 }
             }
             productOrderMapper.updateById(productOrder);
-            /*娣诲姞鐢熶骇鏍哥畻*/
+            /*娣诲姞鐢熶骇鏍哥畻        鍖哄垎宸ュ簭鏄浠惰繕鏄鏃�*/
+            BigDecimal workHours = (productProcess.getType() == 1)
+                    ? productProcess.getSalaryQuota().multiply(productQty)
+                    : productProcess.getSalaryQuota();
+
             SalesLedgerProductionAccounting salesLedgerProductionAccounting = SalesLedgerProductionAccounting.builder()
                     .productMainId(productionProductMain.getId())
                     .schedulingUserId(user.getUserId())
                     .schedulingUserName(user.getNickName())
                     .finishedNum(productQty)
-                    .workHours(productProcess.getSalaryQuota())
+                    .workHours(workHours)
                     .process(productProcess.getName())
                     .schedulingDate(LocalDate.now())
                     .tenantId(dto.getTenantId())
@@ -260,10 +283,10 @@
     public Boolean removeProductMain(Long id) {
         //鍒ゆ柇璇ユ潯鎶ュ伐鏄惁涓嶅悎鏍煎鐞�,濡傛灉涓嶅悎鏍煎鐞嗕簡锛屽垯涓嶅厑璁稿垹闄�
         List<QualityInspect> qualityInspects = qualityInspectMapper.selectList(Wrappers.<QualityInspect>lambdaQuery().eq(QualityInspect::getProductMainId, id));
-        if (qualityInspects.size() > 0){
+        if (qualityInspects.size() > 0) {
             List<QualityUnqualified> qualityUnqualifieds = qualityUnqualifiedMapper.selectList(Wrappers.<QualityUnqualified>lambdaQuery()
                     .in(QualityUnqualified::getInspectId, qualityInspects.stream().map(QualityInspect::getId).collect(Collectors.toList())));
-            if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState()==1) {
+            if (qualityUnqualifieds.size() > 0 && qualityUnqualifieds.get(0).getInspectState() == 1) {
                 throw new ServiceException("璇ユ潯鎶ュ伐宸茬粡涓嶅悎鏍煎鐞嗕簡锛屼笉鍏佽鍒犻櫎");
             }
         }
@@ -317,7 +340,7 @@
                     new LambdaQueryWrapper<QualityInspectParam>()
                             .eq(QualityInspectParam::getInspectId, q.getId()));
             qualityInspectMapper.deleteById(q.getId());
-                stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode());
+            stockUtils.deleteStockInRecord(q.getId(), StockInQualifiedRecordTypeEnum.QUALITYINSPECT_STOCK_IN.getCode());
         });
 
         // 鍒犻櫎浜у嚭璁板綍

--
Gitblit v1.9.3