From d3e304221464c5f66f3c24e3186baff0f313660e Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 03 二月 2026 11:36:36 +0800
Subject: [PATCH] feat(product-process): 生产核算字段重构

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |  111 +++++++++++++++++++++++--------------------------------
 1 files changed, 46 insertions(+), 65 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
index 7464933..3a42fc7 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -1,7 +1,6 @@
 package com.ruoyi.sales.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
@@ -9,14 +8,11 @@
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-import com.ruoyi.account.pojo.AccountIncome;
 import com.ruoyi.account.service.AccountIncomeService;
 import com.ruoyi.basic.mapper.CustomerMapper;
 import com.ruoyi.basic.mapper.ProductMapper;
 import com.ruoyi.basic.mapper.ProductModelMapper;
 import com.ruoyi.basic.pojo.Customer;
-import com.ruoyi.basic.pojo.Product;
-import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.common.enums.FileNameType;
 import com.ruoyi.common.exception.base.BaseException;
 import com.ruoyi.common.utils.DateUtils;
@@ -27,9 +23,10 @@
 import com.ruoyi.framework.web.domain.AjaxResult;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
-import com.ruoyi.production.dto.ProductStructureDto;
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.production.pojo.*;
+import com.ruoyi.production.service.ProductionProductMainService;
+import com.ruoyi.production.service.impl.ProductionProductMainServiceImpl;
 import com.ruoyi.project.system.domain.SysDept;
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
@@ -151,6 +148,9 @@
     private ProductMapper productMapper;
     @Autowired
     private ProductStructureMapper productStructureMapper;
+    @Autowired
+    private ProductionProductMainService productionProductMainService;
+    ;
 
     @Override
     public List<SalesLedger> selectSalesLedgerList(SalesLedgerDto salesLedgerDto) {
@@ -177,6 +177,14 @@
             product.setTempNoInvoiceNum(product.getNoInvoiceNum());
             product.setRegister(SecurityUtils.getLoginUser().getUser().getNickName());
             product.setRegisterDate(LocalDateTime.now());
+            // 鍙戣揣淇℃伅
+            ShippingInfo shippingInfo = shippingInfoMapper.selectOne(new LambdaQueryWrapper<ShippingInfo>()
+                    .eq(ShippingInfo::getSalesLedgerProductId, product.getId())
+                    .orderByDesc(ShippingInfo::getCreateTime)
+                    .last("limit 1"));
+            if (shippingInfo != null) {
+                product.setShippingStatus(shippingInfo.getStatus());
+            }
         }
 
         // 3.鏌ヨ涓婁紶鏂囦欢
@@ -267,75 +275,51 @@
 
     @Override
     public List<MonthlyAmountDto> getAmountHalfYear(Integer type) {
+
         LocalDate now = LocalDate.now();
-        LocalDateTime currentDateTime = LocalDateTime.now();
-
-        // 鏍规嵁 type 纭畾鏌ヨ鐨勬椂闂撮棿闅旓紙澶╂暟锛夊拰鎬绘煡璇㈠ぉ鏁�
-        int daysPerPeriod;
-        int totalDays;
-        switch (type) {
-            case 1:
-                daysPerPeriod = 5;   // 姣�5澶╂煡涓�娆�
-                totalDays = 30;       // 6娆� 脳 5澶� = 30澶�
-                break;
-            case 2:
-                daysPerPeriod = 15;    // 姣�15澶╂煡涓�娆�
-                totalDays = 90;       // 6娆� 脳 15澶� = 90澶�
-                break;
-            case 3:
-                daysPerPeriod = 30;   // 姣�30澶╂煡涓�娆�
-                totalDays = 180;      // 6娆� 脳 30澶� = 180澶�
-                break;
-            default:
-                throw new IllegalArgumentException("Invalid type value: " + type);
-        }
-
         List<MonthlyAmountDto> result = new ArrayList<>();
 
-        // 寰幆6娆★紝姣忔鏌ヨ涓�涓椂闂存鐨勬暟鎹�
-        for (int i = 0; i < 6; i++) {
-            // 璁$畻褰撳墠鏃堕棿娈电殑璧峰鍜岀粨鏉熸椂闂�
-            LocalDateTime endTime = currentDateTime.minusDays(i * daysPerPeriod);
-            LocalDateTime startTime = endTime.minusDays(daysPerPeriod);
+        for (int i = 5; i >= 0; i--) {
+            YearMonth yearMonth = YearMonth.from(now.minusMonths(i));
+            LocalDateTime startTime = yearMonth.atDay(1).atStartOfDay();
+            LocalDateTime endTime = yearMonth.atEndOfMonth().atTime(23, 59, 59);
 
-            // 鏌ヨ鍥炴閲戦
+            //  鍥炴閲戦
             LambdaQueryWrapper<ReceiptPayment> receiptPaymentQuery = new LambdaQueryWrapper<>();
             receiptPaymentQuery
                     .ge(ReceiptPayment::getCreateTime, startTime)
-                    .lt(ReceiptPayment::getCreateTime, endTime);
-            List<ReceiptPayment> receiptPayments = receiptPaymentMapper.selectList(receiptPaymentQuery);
+                    .le(ReceiptPayment::getCreateTime, endTime);
 
-            // 鏌ヨ寮�绁ㄩ噾棰�
-            LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>();
-            invoiceLedgerQuery
-                    .ge(InvoiceLedger::getCreateTime, startTime)
-                    .lt(InvoiceLedger::getCreateTime, endTime);
-            List<InvoiceLedger> invoiceLedgers = invoiceLedgerMapper.selectList(invoiceLedgerQuery);
+            List<ReceiptPayment> receiptPayments =
+                    receiptPaymentMapper.selectList(receiptPaymentQuery);
 
-            // 璁$畻鍥炴鎬婚
             BigDecimal receiptAmount = receiptPayments.stream()
                     .map(ReceiptPayment::getReceiptPaymentAmount)
                     .filter(Objects::nonNull)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
 
-            // 璁$畻寮�绁ㄦ�婚
+            //  寮�绁ㄩ噾棰�
+            LambdaQueryWrapper<InvoiceLedger> invoiceLedgerQuery = new LambdaQueryWrapper<>();
+            invoiceLedgerQuery
+                    .ge(InvoiceLedger::getCreateTime, startTime)
+                    .le(InvoiceLedger::getCreateTime, endTime);
+
+            List<InvoiceLedger> invoiceLedgers =
+                    invoiceLedgerMapper.selectList(invoiceLedgerQuery);
+
             BigDecimal invoiceAmount = invoiceLedgers.stream()
                     .map(InvoiceLedger::getInvoiceTotal)
                     .filter(Objects::nonNull)
                     .reduce(BigDecimal.ZERO, BigDecimal::add);
 
-            // 鏋勯�犺繑鍥炵殑 DTO
             MonthlyAmountDto dto = new MonthlyAmountDto();
-            dto.setMonth(startTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + " ~ " +
-                    endTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
+            dto.setMonth(yearMonth.format(DateTimeFormatter.ofPattern("yyyy-MM")));
             dto.setReceiptAmount(receiptAmount);
             dto.setInvoiceAmount(invoiceAmount);
 
             result.add(dto);
         }
 
-        // 鍙嶈浆鍒楄〃锛屼娇鏃堕棿椤哄簭浠庢棭鍒版櫄
-        Collections.reverse(result);
         return result;
     }
 
@@ -370,7 +354,7 @@
 //            // 浜у搧澶х被鏁版嵁
 //            List<Product> productList = productMapper.selectList(new LambdaQueryWrapper<Product>().in(Product::getProductName,
 //                    salesLedgerProductImportDtoList.stream().map(SalesLedgerImportDto::getProductCategory).collect(Collectors.toList())));
-            List<Map<String,Object>> list = productModelMapper.getProductAndModelList();
+            List<Map<String, Object>> list = productModelMapper.getProductAndModelList();
             // 褰曞叆浜烘暟鎹�
             List<SysUser> sysUsers = sysUserMapper.selectList(new LambdaQueryWrapper<SysUser>().in(SysUser::getNickName,
                     salesLedgerImportDtoList.stream().map(SalesLedgerImportDto::getEntryPerson).collect(Collectors.toList())));
@@ -378,7 +362,7 @@
                 SalesLedger salesLedger1 = salesLedgerMapper.selectOne(new LambdaQueryWrapper<SalesLedger>()
                         .eq(SalesLedger::getSalesContractNo, salesLedgerImportDto.getSalesContractNo())
                         .last("LIMIT 1"));
-                if(salesLedger1 != null){
+                if (salesLedger1 != null) {
                     continue;
                 }
                 SalesLedger salesLedger = new SalesLedger();
@@ -411,7 +395,7 @@
                     throw new RuntimeException("閿�鍞崟鍙�:" + salesLedgerImportDto.getSalesContractNo() + ",鏃犲搴斾骇鍝佹暟鎹紒");
                 salesLedger.setContractAmount(salesLedgerProductImportDtos.stream()
                         .map(SalesLedgerProductImportDto::getTaxInclusiveTotalPrice)
-                        .reduce(BigDecimal.ZERO,BigDecimal::add));
+                        .reduce(BigDecimal.ZERO, BigDecimal::add));
                 salesLedgerMapper.insert(salesLedger);
 
 
@@ -446,6 +430,8 @@
                     salesLedgerProduct.setApproveStatus(0);
                     salesLedgerProduct.setPendingInvoiceTotal(salesLedgerProductImportDto.getTaxInclusiveTotalPrice());
                     salesLedgerProductMapper.insert(salesLedgerProduct);
+                    // 娣诲姞鐢熶骇鏁版嵁
+                    salesLedgerProductServiceImpl.addProductionData(salesLedgerProduct);
                 }
             }
 
@@ -570,26 +556,21 @@
         }
         // 鍒犻櫎鍙戣揣鍙拌处璁板綍
         List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
-                .eq(ShippingInfo::getSalesLedgerId, idList));
-        if(CollectionUtils.isNotEmpty(shippingInfos)){
+                .in(ShippingInfo::getSalesLedgerId, idList));
+        if (CollectionUtils.isNotEmpty(shippingInfos)) {
             shippingInfoServiceImpl.delete(shippingInfos.stream().map(ShippingInfo::getId).collect(Collectors.toList()));
         }
         // 鍒犻櫎闄勪欢琛�
         commonFileService.deleteByBusinessIds(idList, FileNameType.SALE.getValue());
 
         // 鍒犻櫎鐢熶骇绠℃帶鏁版嵁
-        // 鍒犻櫎鐢熶骇璁㈠崟鏁版嵁
-        LambdaQueryWrapper<SalesLedgerScheduling> in = new LambdaQueryWrapper<SalesLedgerScheduling>()
-                .in(SalesLedgerScheduling::getSalesLedgerId, idList);
-        salesLedgerSchedulingMapper.delete(in);
-        // 鍒犻櫎鐢熶骇娲惧伐鏁版嵁
-        LambdaQueryWrapper<SalesLedgerWork> workOrderWrapper = new LambdaQueryWrapper<>();
-        workOrderWrapper.in(SalesLedgerWork::getSalesLedgerId, idList);
-        salesLedgerWorkMapper.delete(workOrderWrapper);
-        // 鍒犻櫎鐢熶骇鏍哥畻鏁版嵁
-        LambdaQueryWrapper<SalesLedgerProductionAccounting> reportWrapper = new LambdaQueryWrapper<>();
-        reportWrapper.in(SalesLedgerProductionAccounting::getSalesLedgerId, idList);
-        salesLedgerProductionAccountingMapper.delete(reportWrapper);
+        //鏌ヨ鐢熶骇鎶ュ伐id
+        ArrayList<Long> mainIdList = productionProductMainService.listMain(idList);
+        if (CollectionUtils.isNotEmpty(mainIdList)) {
+            mainIdList.stream().forEach(mainId -> {
+                productionProductMainService.removeProductMain(mainId);
+            });
+        }
         // 2. 鍐嶅垹闄や富琛ㄦ暟鎹�
         return salesLedgerMapper.deleteBatchIds(idList);
     }

--
Gitblit v1.9.3