From b25258e282d5a53d851a7e19132ecbc842eee7b9 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期一, 02 二月 2026 09:10:38 +0800
Subject: [PATCH] fix: 生产核算分析缺少数量及合格率

---
 src/main/java/com/ruoyi/home/controller/HomeController.java                    |    2 
 src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml |   29 ++++++++------
 src/main/java/com/ruoyi/home/service/HomeService.java                          |    2 
 src/main/java/com/ruoyi/home/dto/ProductionAccountingDto.java                  |   30 +++++++++++++++
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java                 |   53 ++++++++++++--------------
 5 files changed, 74 insertions(+), 42 deletions(-)

diff --git a/src/main/java/com/ruoyi/home/controller/HomeController.java b/src/main/java/com/ruoyi/home/controller/HomeController.java
index e4d29f7..8d72113 100644
--- a/src/main/java/com/ruoyi/home/controller/HomeController.java
+++ b/src/main/java/com/ruoyi/home/controller/HomeController.java
@@ -192,7 +192,7 @@
     @GetMapping("/productionAccountingAnalysis")
     @ApiOperation("鐢熶骇鏍哥畻鍒嗘瀽")
     public AjaxResult productionAccountingAnalysis(@RequestParam(value = "type", defaultValue = "1") Integer type){
-        List<MapDto> list = homeService.productionAccountingAnalysis(type);
+        List<ProductionAccountingDto> list   = homeService.productionAccountingAnalysis(type);
         return AjaxResult.success(list);
     }
 
diff --git a/src/main/java/com/ruoyi/home/dto/ProductionAccountingDto.java b/src/main/java/com/ruoyi/home/dto/ProductionAccountingDto.java
new file mode 100644
index 0000000..6d461ef
--- /dev/null
+++ b/src/main/java/com/ruoyi/home/dto/ProductionAccountingDto.java
@@ -0,0 +1,30 @@
+package com.ruoyi.home.dto;
+
+import java.math.BigDecimal;
+
+import lombok.Data;
+
+@Data
+public class ProductionAccountingDto {
+
+    /**
+     * 鏃ユ湡
+     */
+    private String dateStr;
+
+    /**
+     * 瀹屾垚鏁伴噺
+     */
+    private Integer numberOfCompleted;
+
+    /**
+     * 閲戦
+     */
+    private BigDecimal amount;
+
+    /**
+     * 鍚堟牸鐜�
+     */
+    private BigDecimal passRate;
+
+}
diff --git a/src/main/java/com/ruoyi/home/service/HomeService.java b/src/main/java/com/ruoyi/home/service/HomeService.java
index 0a37187..77bbf6b 100644
--- a/src/main/java/com/ruoyi/home/service/HomeService.java
+++ b/src/main/java/com/ruoyi/home/service/HomeService.java
@@ -71,7 +71,7 @@
 
     List<WorkOrderEfficiencyDto> workOrderEfficiencyAnalysis(Integer type);
 
-    List<MapDto> productionAccountingAnalysis(Integer type);
+    List<ProductionAccountingDto> productionAccountingAnalysis(Integer type);
 
     List<MapDto> orderCount();
 }
diff --git a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
index 454c7a8..a377159 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -35,6 +35,7 @@
 import com.ruoyi.production.mapper.ProductWorkOrderMapper;
 import com.ruoyi.production.mapper.ProductionProductInputMapper;
 import com.ruoyi.production.mapper.ProductionProductOutputMapper;
+import com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper;
 import com.ruoyi.production.pojo.ProductWorkOrder;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysUser;
@@ -128,11 +129,6 @@
     private CustomerMapper customerMapper;
     @Autowired
     private SupplierManageMapper supplierManageMapper;
-    @Autowired
-    private SysUserMapper sysUserMapper;
-    @Autowired
-    private SysUserDeptMapper sysUserDeptMapper;
-
     @Autowired
     private HomeMapper homeMapper;
 
@@ -263,8 +259,8 @@
                 .filter(Objects::nonNull)
                 .reduce(BigDecimal.ZERO, BigDecimal::add);
         BigDecimal subtract1 = todayContractAmount.subtract(lastYearYesterdayContractAmount); // 淇敼锛氫娇鐢�
-                                                                                              // todayContractAmount 鑰屼笉鏄�
-                                                                                              // yesterdayContractAmount
+        // todayContractAmount 鑰屼笉鏄�
+        // yesterdayContractAmount
         // 鏃ョ幆姣�
         String chain = "";
         if (subtract1.compareTo(BigDecimal.ZERO) == 0
@@ -458,8 +454,8 @@
         }
         // 搴旀敹
         List<SalesLedger> salesLedgers = salesLedgerMapper.selectList(new LambdaQueryWrapper<SalesLedger>()
-        // .ge(SalesLedger::getEntryDate, startDate)
-        // .lt(SalesLedger::getEntryDate, endDate)
+                // .ge(SalesLedger::getEntryDate, startDate)
+                // .lt(SalesLedger::getEntryDate, endDate)
         );
         // BigDecimal receivableMoney =
         // salesLedgers.stream().map(SalesLedger::getContractAmount).reduce(BigDecimal.ZERO,
@@ -468,8 +464,8 @@
         // 搴斾粯
         List<PurchaseLedger> procurementRecords = purchaseLedgerMapper
                 .selectList(new LambdaQueryWrapper<PurchaseLedger>()
-                // .ge(PurchaseLedger::getEntryDate, startDate)
-                // .lt(PurchaseLedger::getEntryDate, endDate)
+                        // .ge(PurchaseLedger::getEntryDate, startDate)
+                        // .lt(PurchaseLedger::getEntryDate, endDate)
                 );
         // BigDecimal payableMoney =
         // procurementRecords.stream().map(PurchaseLedger::getContractAmount).reduce(BigDecimal.ZERO,
@@ -477,8 +473,8 @@
         BigDecimal payableMoney = sumAmount(procurementRecords, PurchaseLedger::getContractAmount);
         // 棰勬敹
         List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(new LambdaQueryWrapper<ReceiptPayment>()
-        // .ge(ReceiptPayment::getReceiptPaymentDate, startDate)
-        // .lt(ReceiptPayment::getReceiptPaymentDate, endDate)
+                // .ge(ReceiptPayment::getReceiptPaymentDate, startDate)
+                // .lt(ReceiptPayment::getReceiptPaymentDate, endDate)
         );
         // BigDecimal advanceMoney =
         // receiptPayments.stream().map(ReceiptPayment::getReceiptPaymentAmount).reduce(BigDecimal.ZERO,
@@ -487,8 +483,8 @@
         // 棰勪粯
         List<PaymentRegistration> paymentRegistrations = paymentRegistrationMapper
                 .selectList(new LambdaQueryWrapper<PaymentRegistration>()
-                // .ge(PaymentRegistration::getPaymentDate, startDate)
-                // .lt(PaymentRegistration::getPaymentDate, endDate)
+                        // .ge(PaymentRegistration::getPaymentDate, startDate)
+                        // .lt(PaymentRegistration::getPaymentDate, endDate)
                 );
         // BigDecimal prepayMoney =
         // paymentRegistrations.stream().map(PaymentRegistration::getCurrentPaymentAmount).reduce(BigDecimal.ZERO,
@@ -552,7 +548,7 @@
         productionProgressDto.setCompletedOrderDetails(productOrderDtos);
         long totalCount = productOrderDtos.size();
         long count = productOrderDtos.stream().filter(
-                productOrderDto -> productOrderDto.getCompleteQuantity().compareTo(productOrderDto.getQuantity()) >= 0)
+                        productOrderDto -> productOrderDto.getCompleteQuantity().compareTo(productOrderDto.getQuantity()) >= 0)
                 .count();
         long count2 = productOrderDtos.stream()
                 .filter(productOrderDto -> productOrderDto.getCompleteQuantity().compareTo(BigDecimal.ZERO) == 0)
@@ -1787,10 +1783,10 @@
     }
 
     @Autowired
-    private com.ruoyi.production.mapper.SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
+    private SalesLedgerProductionAccountingMapper salesLedgerProductionAccountingMapper;
 
     @Override
-    public List<MapDto> productionAccountingAnalysis(Integer type) {
+    public List<ProductionAccountingDto> productionAccountingAnalysis(Integer type) {
         LocalDate today = LocalDate.now();
         LocalDate startDate;
         LocalDate endDate = today;
@@ -1812,26 +1808,27 @@
                 break;
         }
 
-        String startStr = startDate.atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
-        String endStr = endDate.atTime(LocalTime.MAX).format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
+        String startStr = startDate.atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
 
-        List<Map<String, Object>> wagesList = salesLedgerProductionAccountingMapper.selectDailyWagesStats(startStr,
-                endStr);
+        String endStr = endDate.plusDays(1).atStartOfDay().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+
+        List<Map<String, Object>> wagesList = salesLedgerProductionAccountingMapper.selectDailyWagesStats(startStr, endStr);
 
         if (CollectionUtils.isEmpty(wagesList)) {
             return new ArrayList<>();
         }
 
-        List<MapDto> result = new ArrayList<>();
+        List<ProductionAccountingDto> result = new ArrayList<>();
         for (Map<String, Object> map : wagesList) {
-            MapDto dto = new MapDto();
-            dto.setName((String) map.get("date"));
-            BigDecimal wages = (BigDecimal) map.get("wages");
-            dto.setValue(wages != null ? wages.toString() : "0");
+            ProductionAccountingDto dto = new ProductionAccountingDto();
+            dto.setDateStr(map.get("dateStr").toString());
+            dto.setNumberOfCompleted(((BigDecimal) map.get("numberOfCompleted")).intValue());
+            dto.setAmount(map.get("amount") != null ? (BigDecimal) map.get("amount") : BigDecimal.ZERO);
+            dto.setPassRate(map.get("passRate") != null ? (BigDecimal) map.get("passRate") : BigDecimal.ZERO);
             result.add(dto);
         }
 
-        result.sort(Comparator.comparing(MapDto::getName));
+        result.sort(Comparator.comparing(ProductionAccountingDto::getDateStr));
 
         return result;
     }
diff --git a/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml b/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
index 31e95de..3535b77 100644
--- a/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
+++ b/src/main/resources/mapper/production/SalesLedgerProductionAccountingMapper.xml
@@ -88,18 +88,23 @@
 
     </select>
 
-
-
     <select id="selectDailyWagesStats" resultType="java.util.Map">
-        SELECT
-            DATE_FORMAT(scheduling_date, '%Y-%m-%d') as date,
-            SUM(finished_num * work_hours) as wages
-        FROM
-            sales_ledger_production_accounting
-        WHERE
-            scheduling_date &gt;= #{startDate}
-            AND scheduling_date &lt;= #{endDate}
-        GROUP BY
-            scheduling_date
+        SELECT DATE(ppout.create_time)                                                         AS dateStr,
+               SUM(ppout.quantity - IFNULL(ppout.scrap_qty, 0))                                AS numberOfCompleted,
+               SUM((ppout.quantity - IFNULL(ppout.scrap_qty, 0)) * IFNULL(pp.salary_quota, 0)) AS amount,
+               ROUND(
+                       SUM(ppout.quantity - IFNULL(ppout.scrap_qty, 0)) * 100 / NULLIF(SUM(ppout.quantity), 0),
+                       2
+               )                                                                               AS passRate
+        FROM production_product_output ppout
+                 LEFT JOIN production_product_main ppm ON ppm.id = ppout.product_main_id
+                 LEFT JOIN product_process_route_item ppri ON ppri.id = ppm.product_process_route_item_id
+                 LEFT JOIN product_process pp ON pp.id = ppri.process_id
+        WHERE ppout.create_time &gt;= #{startDate}
+          AND ppout.create_time &lt; #{endDate}
+        GROUP BY DATE(ppout.create_time)
+        ORDER BY DATE(ppout.create_time);
     </select>
+
+
 </mapper>

--
Gitblit v1.9.3