From 24d8b0c95f0d38a76374d2e27a8e49c26cc84f98 Mon Sep 17 00:00:00 2001
From: yuan <123@>
Date: 星期日, 21 六月 2026 19:21:13 +0800
Subject: [PATCH] fix: 修改生产订单完成进度时间

---
 src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java |  165 +++++++++++++++++++++++++++++++++++++-----------------
 1 files changed, 113 insertions(+), 52 deletions(-)

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 e4e8888..46c6f58 100644
--- a/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
+++ b/src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -3,10 +3,18 @@
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.ruoyi.account.bean.dto.purchase.PurchaseInboundDto;
+import com.ruoyi.account.bean.dto.purchase.PurchaseReturnDto;
+import com.ruoyi.account.bean.dto.sales.SalesOutboundDto;
+import com.ruoyi.account.bean.dto.sales.SalesReturnDto;
+import com.ruoyi.account.bean.vo.purchase.PurchaseInboundVo;
+import com.ruoyi.account.bean.vo.purchase.PurchaseReturnVo;
+import com.ruoyi.account.bean.vo.sales.SalesOutboundVo;
+import com.ruoyi.account.bean.vo.sales.SalesReturnVo;
 import com.ruoyi.account.mapper.AccountStatementMapper;
 import com.ruoyi.account.mapper.purchase.AccountPurchasePaymentMapper;
 import com.ruoyi.account.mapper.sales.AccountSalesCollectionMapper;
-import com.ruoyi.account.pojo.AccountStatement;
 import com.ruoyi.account.pojo.purchase.AccountPurchasePayment;
 import com.ruoyi.account.pojo.sales.AccountSalesCollection;
 import com.ruoyi.approve.mapper.ApproveProcessMapper;
@@ -29,11 +37,13 @@
 import com.ruoyi.home.dto.*;
 import com.ruoyi.home.mapper.HomeMapper;
 import com.ruoyi.home.service.HomeService;
+import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper;
 import com.ruoyi.production.bean.dto.ProductionProductOutputDto;
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
+import com.ruoyi.purchase.mapper.PurchaseReturnOrdersMapper;
 import com.ruoyi.purchase.pojo.PurchaseLedger;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
 import com.ruoyi.quality.mapper.QualityUnqualifiedMapper;
@@ -45,10 +55,13 @@
 import com.ruoyi.sales.pojo.SalesLedgerProduct;
 import com.ruoyi.staff.mapper.StaffOnJobMapper;
 import com.ruoyi.staff.pojo.StaffOnJob;
+import com.ruoyi.stock.mapper.StockInRecordMapper;
 import com.ruoyi.stock.mapper.StockInventoryMapper;
+import com.ruoyi.stock.mapper.StockOutRecordMapper;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
 import org.springframework.util.CollectionUtils;
 
 import java.math.BigDecimal;
@@ -71,6 +84,10 @@
 public class HomeServiceImpl implements HomeService {
 
     private final SalesLedgerMapper salesLedgerMapper;
+    private final StockOutRecordMapper stockOutRecordMapper;
+    private final ReturnManagementMapper returnManagementMapper;
+    private final StockInRecordMapper stockInRecordMapper;
+    private final PurchaseReturnOrdersMapper purchaseReturnOrdersMapper;
 
     private final PurchaseLedgerMapper purchaseLedgerMapper;
 
@@ -417,14 +434,26 @@
         LocalDate startDate = range[0];
         LocalDate endDate = range[1];
 
+        //閿�鍞嚭搴�
         BigDecimal receivableBase = sumSalesContractAmount(startDate, endDate);
+        //閿�鍞��璐�
+        BigDecimal salesReturnAmount = sumSalesReturnAmount(startDate, endDate);
+        //閲囪喘鍏ュ簱
         BigDecimal payableBase = sumPurchaseContractAmount(startDate, endDate);
+        //閲囪喘閫�璐�
+        BigDecimal purchaseReturnAmount = sumPurchaseReturnAmount(startDate, endDate);
+        //鏀舵
         BigDecimal advanceMoney = sumCollectionAmount(startDate, endDate);
+        //浠樻
         BigDecimal prepayMoney = sumPaymentAmount(startDate, endDate);
 
-        dto.setReceivableMoney(scaleMoney(maxZero(receivableBase.subtract(advanceMoney))));
-        dto.setPayableMoney(scaleMoney(maxZero(payableBase.subtract(prepayMoney))));
+        //搴旀敹閲戦=閿�鍞嚭搴�-閿�鍞��璐�
+        dto.setReceivableMoney(scaleMoney(maxZero(receivableBase.subtract(salesReturnAmount))));
+        //搴斾粯閲戦=閲囪喘鍏ュ簱-閲囪喘閫�璐�
+        dto.setPayableMoney(scaleMoney(maxZero(payableBase.subtract(purchaseReturnAmount))));
+        //鏀舵閲戦=鏀舵鍗�
         dto.setAdvanceMoney(scaleMoney(advanceMoney));
+        //浠樻閲戦=浠樻鍗�
         dto.setPrepayMoney(scaleMoney(prepayMoney));
         return dto;
     }
@@ -469,9 +498,20 @@
 
     @Override
     public ProductionProgressDto productionProgress() {
+        LocalDateTime now = LocalDateTime.now();
+
+        LocalDateTime startOfMonth = now
+                .with(TemporalAdjusters.firstDayOfMonth())
+                .with(LocalTime.MIN);
+
+        LocalDateTime endOfMonth = now
+                .with(TemporalAdjusters.lastDayOfMonth())
+                .with(LocalTime.MAX);
+
+
         ProductionProgressDto productionProgressDto = new ProductionProgressDto();
-        List<ProductionProgressOrderDto> orderDetails = productionOrderMapper.selectProgressOrders(
-                LocalDateTime.now().minusMonths(1), LocalDateTime.now());
+        List<ProductionProgressOrderDto> orderDetails = productionOrderMapper
+                .selectProgressOrders(startOfMonth, endOfMonth);
         productionProgressDto.setCompletedOrderDetails(orderDetails);
         long totalCount = orderDetails.size();
         long count = orderDetails.stream().filter(
@@ -491,7 +531,7 @@
     public ProductionTurnoverDto workInProcessTurnover() {
         ProductionTurnoverDto productionTurnoverDto = new ProductionTurnoverDto();
         List<ProductionTaskStatisticsDto> taskList = productionOperationTaskMapper
-                .selectTaskStatisticsByDate(LocalDate.now().minusMonths(1), LocalDate.now());
+                .selectTaskStatisticsByDate(LocalDate.now().with(TemporalAdjusters.firstDayOfMonth()), LocalDate.now().with(TemporalAdjusters.lastDayOfMonth()));
         long sum = taskList.stream()
                 .filter(task -> defaultDecimal(task.getPlanQuantity()).compareTo(defaultDecimal(task.getCompleteQuantity())) > 0)
                 .map(ProductionTaskStatisticsDto::getPlanQuantity)
@@ -1239,33 +1279,21 @@
         YearMonth currentMonth = YearMonth.from(today);
         LocalDate startDate = currentMonth.atDay(1);
         LocalDate endDate = currentMonth.atEndOfMonth();
-
+        //鏀舵
         BigDecimal monthlyIncome = sumCollectionAmount(startDate, endDate);
+        //閿�鍞嚭搴�
         BigDecimal receivableBase = sumSalesContractAmount(startDate, endDate);
-        String collectionRate = toRateString(monthlyIncome, receivableBase);
-
-        String currentMonthText = currentMonth.toString();
-        List<AccountStatement> receivableStatements = defaultList(accountStatementMapper.selectList(
-                new LambdaQueryWrapper<AccountStatement>()
-                        .eq(AccountStatement::getAccountType, 1)
-                        .le(AccountStatement::getStatementMonth, currentMonthText)));
-
-        long overdueNum = receivableStatements.stream()
-                .filter(item -> item.getStatementMonth() != null && item.getStatementMonth().compareTo(currentMonthText) < 0)
-                .filter(item -> defaultDecimal(item.getClosingBalance()).compareTo(BigDecimal.ZERO) > 0)
-                .count();
-
-        long totalReceivableCount = receivableStatements.size();
-        String overdueRate = totalReceivableCount == 0
-                ? "0.00"
-                : BigDecimal.valueOf(overdueNum)
-                .multiply(BigDecimal.valueOf(100))
-                .divide(BigDecimal.valueOf(totalReceivableCount), 2, RoundingMode.HALF_UP)
-                .toString();
-
+        //閿�鍞��璐�
+        BigDecimal salesReturnAmount = sumSalesReturnAmount(startDate, endDate);
+        //鍥炴鐜�=鏀舵/(閿�鍞嚭搴�-閿�鍞��璐�)搴旀敹
+        String collectionRate = toRateString(monthlyIncome, receivableBase.subtract(salesReturnAmount));
+        //閫炬湡鏁�=(閿�鍞嚭搴撻噾棰�-閿�鍞��璐ч噾棰�)搴旀敹閲戦-鏀舵閲戦
+        BigDecimal overdueAmount = receivableBase.subtract(salesReturnAmount).subtract(monthlyIncome);
+        //閫炬湡鐜�=閫炬湡鏁�/搴旀敹閲戦
+        String overdueRate = toRateString(overdueAmount, receivableBase);
         dto.setMonthlyIncome(scaleMoney(monthlyIncome));
         dto.setCollectionRate(collectionRate);
-        dto.setOverdueNum(BigDecimal.valueOf(overdueNum));
+        dto.setOverdueNum(overdueAmount);
         dto.setOverdueRate(overdueRate);
         return dto;
     }
@@ -1277,16 +1305,25 @@
         YearMonth currentMonth = YearMonth.from(today);
         LocalDate startDate = currentMonth.atDay(1);
         LocalDate endDate = currentMonth.atEndOfMonth();
-
+        //鏀嚭
         BigDecimal monthlyExpenditure = sumPaymentAmount(startDate, endDate);
+        //閲囪喘鍏ュ簱
         BigDecimal payableBase = sumPurchaseContractAmount(startDate, endDate);
+        //閲囪喘閫�璐�
+        BigDecimal purchaseReturnAmount = sumPurchaseReturnAmount(startDate, endDate);
+        //浠樻鐜�=浠樻/(閲囪喘鍏ュ簱-閲囪喘閫�璐�)搴斾粯
+        String paymentRate = toRateString(monthlyExpenditure, payableBase.subtract(purchaseReturnAmount));
+        //鏀舵
         BigDecimal monthlyIncome = sumCollectionAmount(startDate, endDate);
+        //姣涘埄娑�= 鏀舵-鏀嚭
         BigDecimal grossProfit = monthlyIncome.subtract(monthlyExpenditure);
+        //鍒╂鼎鐜�=姣涘埄娑�/鏀舵
+        String profitMarginRate = toRateString(grossProfit, monthlyIncome);
 
         dto.setMonthlyExpenditure(scaleMoney(monthlyExpenditure));
-        dto.setPaymentRate(toRateString(monthlyExpenditure, payableBase));
+        dto.setPaymentRate(paymentRate);
         dto.setGrossProfit(scaleMoney(grossProfit));
-        dto.setProfitMarginRate(toRateString(grossProfit, monthlyIncome));
+        dto.setProfitMarginRate(profitMarginRate);
         return dto;
     }
 
@@ -1320,15 +1357,15 @@
         String endStr = endDate.atStartOfDay()
                 .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
 
-//        List<Map<String, Object>> inputList = productionProductInputMapper.selectInputStats(startStr, endStr);
-        List<Map<String, Object>> inputList = null;
+        List<Map<String, Object>> inputList = productionProductInputMapper.selectInputStats(startStr, endStr);
+        //List<Map<String, Object>> inputList = null;
         List<Map<String, Object>> outputList = productionProductOutputMapper.selectDailyOutputStats(startStr, endStr);
 
         Map<String, InputOutputAnalysisDto> dateMap = new HashMap<>();
 
         if (!CollectionUtils.isEmpty(inputList)) {
             for (Map<String, Object> map : inputList) {
-                String date = (String) map.get("date");
+                String date = (String) map.get("statDate");
                 if (date == null)
                     continue;
                 InputOutputAnalysisDto dto = dateMap.getOrDefault(date, new InputOutputAnalysisDto());
@@ -1341,7 +1378,7 @@
 
         if (!CollectionUtils.isEmpty(outputList)) {
             for (Map<String, Object> map : outputList) {
-                String date = (String) map.get("date");
+                String date = (String) map.get("statDate");
                 if (date == null)
                     continue;
                 InputOutputAnalysisDto dto = dateMap.getOrDefault(date, new InputOutputAnalysisDto());
@@ -1600,16 +1637,16 @@
     @Override
     public List<MapDto> orderCount() {
         LocalDate now = LocalDate.now();
+        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
 
-        String currentStart = now.withDayOfMonth(1).atStartOfDay()
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-        String currentEnd = now.atTime(LocalTime.MAX).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        LocalDateTime startDateTime = now.with(TemporalAdjusters.firstDayOfMonth()).atStartOfDay();
+        LocalDateTime endDateTime = now.with(TemporalAdjusters.lastDayOfMonth()).atTime(LocalTime.MAX);
 
-        LocalDate lastMonthDate = now.minusMonths(1);
-        String lastStart = lastMonthDate.withDayOfMonth(1).atStartOfDay()
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
-        String lastEnd = lastMonthDate.withDayOfMonth(lastMonthDate.lengthOfMonth()).atTime(LocalTime.MAX)
-                .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+        String currentStart = startDateTime.format(dateTimeFormatter);
+        String currentEnd = endDateTime.format(dateTimeFormatter);
+
+        String lastStart = startDateTime.minusMonths(1).format(dateTimeFormatter);
+        String lastEnd = endDateTime.format(dateTimeFormatter);
 
         int currentCreated = productionOrderMapper.countCreated(currentStart, currentEnd);
         int lastCreated = productionOrderMapper.countCreated(lastStart, lastEnd);
@@ -2317,20 +2354,43 @@
         return new LocalDate[]{startDate, endDate};
     }
 
+    //璁$畻鏃ユ湡鍐呯殑閿�鍞嚭搴撻噾棰�
     private BigDecimal sumSalesContractAmount(LocalDate startDate, LocalDate endDate) {
-        List<SalesLedger> salesLedgers = defaultList(salesLedgerMapper.selectList(new LambdaQueryWrapper<SalesLedger>()
-                .ge(SalesLedger::getEntryDate, toDate(startDate))
-                .lt(SalesLedger::getEntryDate, toExclusiveEndDate(endDate))));
-        return sumAmount(salesLedgers, SalesLedger::getContractAmount);
+        SalesOutboundDto salesOutboundDto = new SalesOutboundDto();
+        salesOutboundDto.setStartDate(startDate);
+        salesOutboundDto.setEndDate(endDate);
+        List<SalesOutboundVo> salesOutboundVos = stockOutRecordMapper.listPageAccountSales(new Page(1, -1), salesOutboundDto).getRecords();
+        return sumAmount(salesOutboundVos, SalesOutboundVo::getOutboundAmount);
     }
 
+    //璁$畻鏃ユ湡鍐呯殑閿�鍞��璐ч噾棰�
+    private BigDecimal sumSalesReturnAmount(LocalDate startDate, LocalDate endDate) {
+        SalesReturnDto salesReturnDto = new SalesReturnDto();
+        salesReturnDto.setStartDate(startDate);
+        salesReturnDto.setEndDate(endDate);
+        List<SalesReturnVo> salesReturnVos = returnManagementMapper.listPageAccountSalesReturn(new Page(1, -1), salesReturnDto).getRecords();
+        return sumAmount(salesReturnVos, SalesReturnVo::getRefundAmount);
+    }
+
+    //璁$畻鏃ユ湡鍐呯殑閲囪喘鍏ュ簱閲戦
     private BigDecimal sumPurchaseContractAmount(LocalDate startDate, LocalDate endDate) {
-        List<PurchaseLedger> purchaseLedgers = defaultList(purchaseLedgerMapper.selectList(new LambdaQueryWrapper<PurchaseLedger>()
-                .ge(PurchaseLedger::getEntryDate, toDate(startDate))
-                .lt(PurchaseLedger::getEntryDate, toExclusiveEndDate(endDate))));
-        return sumAmount(purchaseLedgers, PurchaseLedger::getContractAmount);
+        PurchaseInboundDto purchaseInboundDto = new PurchaseInboundDto();
+        purchaseInboundDto.setStartDate(startDate);
+        purchaseInboundDto.setEndDate(endDate);
+        List<PurchaseInboundVo> purchaseInboundVos = stockInRecordMapper.listPageAccountPurchase(new Page(1, -1), purchaseInboundDto).getRecords();
+        return sumAmount(purchaseInboundVos, PurchaseInboundVo::getInboundAmount);
     }
 
+    //璁$畻鏃ユ湡鍐呯殑閲囪喘閫�璐ч噾棰�
+    private BigDecimal sumPurchaseReturnAmount(LocalDate startDate, LocalDate endDate) {
+        PurchaseReturnDto purchaseReturnDto = new PurchaseReturnDto();
+        purchaseReturnDto.setStartDate(startDate);
+        purchaseReturnDto.setEndDate(endDate);
+        List<PurchaseReturnVo> purchaseReturnVos = purchaseReturnOrdersMapper.listPageAccountPurchaseReturn(new Page(1, -1), purchaseReturnDto).getRecords();
+        return sumAmount(purchaseReturnVos, PurchaseReturnVo::getTotalAmount);
+    }
+
+    //璁$畻鏃ユ湡鍐呯殑鎬绘敹娆鹃噾棰�
     private BigDecimal sumCollectionAmount(LocalDate startDate, LocalDate endDate) {
         List<AccountSalesCollection> collections = defaultList(accountSalesCollectionMapper.selectList(
                 new LambdaQueryWrapper<AccountSalesCollection>()
@@ -2339,6 +2399,7 @@
         return sumAmount(collections, AccountSalesCollection::getCollectionAmount);
     }
 
+    //璁$畻鏃ユ湡鍐呯殑鎬讳粯娆鹃噾棰�
     private BigDecimal sumPaymentAmount(LocalDate startDate, LocalDate endDate) {
         List<AccountPurchasePayment> payments = defaultList(accountPurchasePaymentMapper.selectList(
                 new LambdaQueryWrapper<AccountPurchasePayment>()

--
Gitblit v1.9.3