From 7b6741f6ccf11d0043ad94914d41a9bd23452d00 Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期五, 29 五月 2026 15:13:24 +0800
Subject: [PATCH] feat(sales): 添加销售台账审核反审功能 1.在销售台账下新增子级菜单:未审批订单和反审核数据。分别进行订单审 核和查看反审核的历史数据。 2.在销售台账页面,新增一个编辑按钮,可以对已审核的订单进行单价修 改。 3.新增反审核按钮,对已审核的订单进行反审核,反审核之后会保存当前订 单的数据快照,便于在反审核菜单进行查看。反审核的订单重新生成一条销 售订单数据进行编辑。

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |  181 ++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 161 insertions(+), 20 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 faceef0..ac676ab 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -5,18 +5,16 @@
 import com.baomidou.mybatisplus.core.mapper.BaseMapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
-
 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.service.AccountIncomeService;
-import com.ruoyi.approve.service.IApproveProcessService;
-import com.ruoyi.approve.vo.ApproveProcessVO;
 import com.fasterxml.jackson.databind.JsonNode;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.ruoyi.account.service.AccountIncomeService;
 import com.ruoyi.approve.pojo.ApproveProcess;
-import com.ruoyi.common.enums.ApproveTypeEnum;
+import com.ruoyi.approve.service.IApproveProcessService;
+import com.ruoyi.approve.vo.ApproveProcessVO;
 import com.ruoyi.basic.mapper.CustomerMapper;
 import com.ruoyi.basic.mapper.ProductMapper;
 import com.ruoyi.basic.mapper.ProductModelMapper;
@@ -25,32 +23,22 @@
 import com.ruoyi.basic.pojo.Product;
 import com.ruoyi.basic.pojo.ProductModel;
 import com.ruoyi.basic.service.ICustomerRegionsService;
-import com.ruoyi.common.enums.FileNameType;
-import com.ruoyi.common.enums.SaleEnum;
-import com.ruoyi.common.enums.StockInQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockInUnQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
-import com.ruoyi.common.enums.StockOutUnQualifiedRecordTypeEnum;
+import com.ruoyi.common.enums.*;
 import com.ruoyi.common.exception.ServiceException;
 import com.ruoyi.common.exception.base.BaseException;
-import com.ruoyi.common.utils.DateUtils;
-import com.ruoyi.common.utils.EnumUtil;
-import com.ruoyi.common.utils.OrderUtils;
-import com.ruoyi.common.utils.SecurityUtils;
-import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.common.utils.*;
 import com.ruoyi.common.utils.poi.ExcelUtil;
 import com.ruoyi.framework.security.LoginUser;
 import com.ruoyi.other.mapper.TempFileMapper;
 import com.ruoyi.other.pojo.TempFile;
+import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.production.mapper.*;
 import com.ruoyi.production.pojo.ProcessRoute;
 import com.ruoyi.production.pojo.ProcessRouteItem;
 import com.ruoyi.production.service.ProductionProductMainService;
-
 import com.ruoyi.project.system.domain.SysUser;
 import com.ruoyi.project.system.mapper.SysDeptMapper;
 import com.ruoyi.project.system.mapper.SysUserMapper;
-import com.ruoyi.procurementrecord.utils.StockUtils;
 import com.ruoyi.purchase.dto.SimpleReturnOrderGroupDto;
 import com.ruoyi.purchase.mapper.PurchaseReturnOrderProductsMapper;
 import com.ruoyi.quality.mapper.QualityInspectMapper;
@@ -70,6 +58,7 @@
 import com.ruoyi.sales.service.ISalesLedgerService;
 import com.ruoyi.stock.dto.StockInventoryDto;
 import com.ruoyi.stock.mapper.StockInRecordMapper;
+import com.ruoyi.stock.mapper.StockInventoryMapper;
 import com.ruoyi.stock.mapper.StockOutRecordMapper;
 import com.ruoyi.stock.pojo.StockInRecord;
 import com.ruoyi.stock.pojo.StockOutRecord;
@@ -100,8 +89,8 @@
 import java.nio.file.StandardCopyOption;
 import java.time.LocalDate;
 import java.time.LocalDateTime;
-import java.time.ZoneId;
 import java.time.YearMonth;
+import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
@@ -165,6 +154,7 @@
     private final StockInventoryService stockInventoryService;
     private final StockInRecordMapper stockInRecordMapper;
     private final StockOutRecordMapper stockOutRecordMapper;
+    private final StockInventoryMapper stockInventoryMapper;
     private final StockInRecordService stockInRecordService;
     private final StockOutRecordService stockOutRecordService;
     private final StockUtils stockUtils;
@@ -400,6 +390,7 @@
 
     @Override
     public IPage<SalesLedger> selectSalesLedgerListPage(Page page, SalesLedgerDto salesLedgerDto) {
+        // 娣诲姞 reviewStatus 鐨勭瓫閫夋潯浠�
         IPage<SalesLedger> iPage = salesLedgerMapper.selectSalesLedgerListPage(page, salesLedgerDto);
 
         if (CollectionUtils.isEmpty(iPage.getRecords())) {
@@ -484,6 +475,14 @@
             salesLedger.setIsFh(isFh);
 
             salesLedger.setIsEdit(!isFh);
+            
+            // 鏍规嵁 reviewStatus 鎺у埗鍙嶅鐩稿叧瀛楁鐨勬樉绀�
+            if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() != 2) {
+                // 褰� reviewStatus 涓嶄负 2 鏃讹紝闅愯棌鍙嶅鏃堕棿銆佸弽瀹′汉鍜屽弽瀹′汉ID
+                salesLedger.setCounterReviewTime(null);
+                salesLedger.setCounterReviewPerson(null);
+                salesLedger.setCounterReviewPersonId(null);
+            }
         }
 
         if (salesLedgerDto.getStatus() != null && salesLedgerDto.getStatus()) {
@@ -902,6 +901,13 @@
             } else {
                 if (salesLedger.getDeliveryStatus() == 5) {
                     throw new ServiceException("璁㈠崟宸插彂璐�,绂佹缂栬緫");
+                }
+                if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() == 1) {
+                    salesLedger.setReviewStatus(salesLedgerDto.getReviewStatus());
+                } else if (salesLedger.getReviewStatus() != null && salesLedger.getReviewStatus() == 2) {
+                    handleCounterReview(salesLedger);
+                } else {
+                    salesLedger.setReviewStatus(0);
                 }
                 salesLedgerMapper.updateById(salesLedger);
             }
@@ -3318,4 +3324,139 @@
         }
         baseMapper.updateById(salesLedger);
     }
-}
+
+    
+    /**
+     * 澶勭悊閿�鍞彴璐﹀弽瀹¢�昏緫
+     * 1. 璁剧疆鍙嶅鐩稿叧淇℃伅锛堟椂闂淬�佷汉鍛橈級
+     * 2. 澶嶅埗鍘熼攢鍞彴璐﹀強浜у搧鏁版嵁锛岀敓鎴愭柊鐨勫彴璐�
+     * 3. 瀵瑰師鍙拌处鐨勫簱瀛樻暟鎹繘琛屽弽鍚戞搷浣�
+     */
+    private void handleCounterReview(SalesLedger salesLedger) {
+        // 1. 璁剧疆鍙嶅鐩稿叧淇℃伅
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        salesLedger.setCounterReviewTime(LocalDateTime.now());
+        salesLedger.setCounterReviewPerson(loginUser.getUser().getNickName());
+        salesLedger.setCounterReviewPersonId(loginUser.getUserId());
+        salesLedger.setReviewStatus(2);
+        
+        Long originalSalesLedgerId = salesLedger.getId();
+        
+        // 2. 鏌ヨ鍘熼攢鍞彴璐︽暟鎹�
+        SalesLedger originalLedger = salesLedgerMapper.selectById(originalSalesLedgerId);
+        if (originalLedger == null) {
+            throw new ServiceException("鍘熻鍗曚笉瀛樺湪锛屾棤娉曞弽瀹�");
+        }
+        
+        // 3. 鍒涘缓鏂扮殑閿�鍞彴璐︼紝澶嶅埗鍘熷彴璐︽暟鎹�
+        SalesLedger newLedger = new SalesLedger();
+        BeanUtils.copyProperties(originalLedger, newLedger);
+        newLedger.setId(null); // 娓呯┖ID锛屽噯澶囨彃鍏ユ柊璁板綍
+        newLedger.setSalesContractNo(generateSalesContractNo()); // 鐢熸垚鏂板悎鍚屽彿
+        newLedger.setDeliveryStatus(1); // 璁剧疆涓烘湭鍙戣揣鐘舵��
+        newLedger.setStockStatus(0); // 璁剧疆涓烘湭鍏ュ簱鐘舵��
+        newLedger.setReviewStatus(0); // 璁剧疆涓烘湭瀹℃牳鐘舵��
+        newLedger.setCounterReviewTime(null); // 娓呯┖鍙嶅鏃堕棿
+        newLedger.setCounterReviewPerson(null); // 娓呯┖鍙嶅浜�
+        newLedger.setCounterReviewPersonId(null); // 娓呯┖鍙嶅浜篒D
+        
+        // 4. 鎻掑叆鏂扮殑閿�鍞彴璐�
+        salesLedgerMapper.insert(newLedger);
+        
+        // 5. 鏌ヨ骞跺鍒跺師鍙拌处鐨勬墍鏈変骇鍝佹暟鎹�
+        List<SalesLedgerProduct> originalProducts = salesLedgerProductMapper.selectList(
+            Wrappers.<SalesLedgerProduct>lambdaQuery()
+                .eq(SalesLedgerProduct::getSalesLedgerId, originalSalesLedgerId)
+        );
+        
+        for (SalesLedgerProduct originalProduct : originalProducts) {
+            // 5.1 鍒涘缓鏂颁骇鍝佽褰曪紝澶嶅埗鍘熶骇鍝佹暟鎹�
+            SalesLedgerProduct newProduct = new SalesLedgerProduct();
+            BeanUtils.copyProperties(originalProduct, newProduct);
+            newProduct.setId(null); // 娓呯┖ID锛屽噯澶囨彃鍏ユ柊璁板綍
+            newProduct.setSalesLedgerId(newLedger.getId()); // 鍏宠仈鍒版柊鐨勫彴璐D
+            newProduct.setStockedQuantity(BigDecimal.ZERO); // 宸插叆搴撴暟閲忛噸缃负0
+            newProduct.setShippedQuantity(BigDecimal.ZERO); // 宸插嚭搴撴暟閲忛噸缃负0
+            newProduct.setUnqualifiedStockedQuantity(BigDecimal.ZERO); // 涓嶅悎鏍煎叆搴撴暟閲忛噸缃负0
+            newProduct.setUnqualifiedShippedQuantity(BigDecimal.ZERO); // 涓嶅悎鏍煎嚭搴撴暟閲忛噸缃负0
+            newProduct.setReturnQuality(BigDecimal.ZERO); // 閫�璐ф暟閲忛噸缃负0
+            newProduct.setAvailableQuality(newProduct.getQuantity().subtract(newProduct.getReturnQuality())); // 閲嶆柊璁$畻鍙敤鏁伴噺
+            newProduct.setProductStockStatus(0); // 浜у搧搴撳瓨鐘舵�侀噸缃负0
+            newProduct.fillRemainingQuantity(); // 閲嶆柊璁$畻鍓╀綑鏁伴噺
+            
+            // 5.2 鎻掑叆鏂颁骇鍝佽褰�
+            salesLedgerProductMapper.insert(newProduct);
+        }
+        
+        // 6. 澶勭悊鍘熻鍗曠殑搴撳瓨鏁版嵁锛堢敓鎴愬弽瀹″嚭鍏ュ簱璁板綍锛�
+        processOriginalOrderStock(originalSalesLedgerId);
+    }
+
+    /**
+     * 澶勭悊鍘熻鍗曠殑搴撳瓨鏁版嵁
+     * 1. 瀵瑰師璁㈠崟鐨勫叆搴撴暟鎹敓鎴愬弽瀹″嚭搴撹褰曪紙閿�鍞�-鍙嶅鍑哄簱锛�
+     * 2. 瀵瑰師璁㈠崟鐨勫嚭搴撴暟鎹敓鎴愬弽瀹″叆搴撹褰曪紙閿�鍞�-鍙嶅鍏ュ簱锛�
+     * 3. 鏇存柊搴撳瓨琛ㄦ暟鎹�
+     */
+    private void processOriginalOrderStock(Long originalSalesLedgerId) {
+        // 1. 鏌ヨ鍘熻鍗曠殑鎵�鏈夊叆搴撹褰�
+        List<StockInRecord> stockInRecords = stockInRecordMapper.selectList(
+            Wrappers.<StockInRecord>lambdaQuery()
+                .eq(StockInRecord::getSalesLedgerId, originalSalesLedgerId)
+        );
+        
+        // 2. 瀵规瘡鏉″叆搴撹褰曠敓鎴愬搴旂殑鍙嶅鍑哄簱璁板綍
+        for (StockInRecord stockInRecord : stockInRecords) {
+            // 2.1 鍒涘缓鍙嶅鍑哄簱璁板綍
+            StockOutRecord stockOutRecord = new StockOutRecord();
+            stockOutRecord.setOutboundBatches(OrderUtils.countTodayByCreateTime(stockOutRecordMapper, "CK")); // 鐢熸垚鍑哄簱鎵规鍙�
+            stockOutRecord.setStockOutNum(stockInRecord.getStockInNum()); // 鍑哄簱鏁伴噺绛変簬鍘熷叆搴撴暟閲�
+            stockOutRecord.setRecordId(stockInRecord.getId()); // 璁板綍鍘熷叆搴撹褰旾D
+            stockOutRecord.setRecordType(StockOutQualifiedRecordTypeEnum.SALE_COUNTER_REVIEW_STOCK_OUT.getCode()); // 璁剧疆涓洪攢鍞弽瀹″嚭搴撶被鍨�
+            stockOutRecord.setProductModelId(stockInRecord.getProductModelId()); // 浜у搧瑙勬牸ID
+            stockOutRecord.setRemark("閿�鍞�-鍙嶅鍑哄簱"); // 澶囨敞
+            stockOutRecord.setType(stockInRecord.getType()); // 绫诲瀷锛堝悎鏍�/涓嶅悎鏍硷級
+            stockOutRecord.setSalesLedgerId(stockInRecord.getSalesLedgerId()); // 閿�鍞鍗旾D
+            stockOutRecord.setSalesLedgerProductId(stockInRecord.getSalesLedgerProductId()); // 閿�鍞鍗曚骇鍝両D
+            
+            // 2.2 鎻掑叆鍙嶅鍑哄簱璁板綍
+            stockOutRecordMapper.insert(stockOutRecord);
+            
+            // 2.3 浠庡簱瀛樿〃涓墸鍑忕浉搴旀暟閲�
+            StockInventoryDto stockInventoryDto = new StockInventoryDto();
+            stockInventoryDto.setProductModelId(stockOutRecord.getProductModelId());
+            stockInventoryDto.setQualitity(stockOutRecord.getStockOutNum());
+            stockInventoryMapper.updateSubtractStockInventory(stockInventoryDto);
+        }
+        
+        // 3. 鏌ヨ鍘熻鍗曠殑鎵�鏈夊嚭搴撹褰�
+        List<StockOutRecord> stockOutRecords = stockOutRecordMapper.selectList(
+            Wrappers.<StockOutRecord>lambdaQuery()
+                .eq(StockOutRecord::getSalesLedgerId, originalSalesLedgerId)
+        );
+        
+        // 4. 瀵规瘡鏉″嚭搴撹褰曠敓鎴愬搴旂殑鍙嶅鍏ュ簱璁板綍
+        for (StockOutRecord stockOutRecord : stockOutRecords) {
+            // 4.1 鍒涘缓鍙嶅鍏ュ簱璁板綍
+            StockInRecord stockInRecord = new StockInRecord();
+            stockInRecord.setInboundBatches(OrderUtils.countTodayByCreateTime(stockInRecordMapper, "RK")); // 鐢熸垚鍏ュ簱鎵规鍙�
+            stockInRecord.setStockInNum(stockOutRecord.getStockOutNum()); // 鍏ュ簱鏁伴噺绛変簬鍘熷嚭搴撴暟閲�
+            stockInRecord.setRecordId(stockOutRecord.getId()); // 璁板綍鍘熷嚭搴撹褰旾D
+            stockInRecord.setRecordType(StockInQualifiedRecordTypeEnum.SALE_COUNTER_REVIEW_STOCK_IN.getCode()); // 璁剧疆涓洪攢鍞弽瀹″叆搴撶被鍨�
+            stockInRecord.setProductModelId(stockOutRecord.getProductModelId()); // 浜у搧瑙勬牸ID
+            stockInRecord.setRemark("閿�鍞�-鍙嶅鍏ュ簱"); // 澶囨敞
+            stockInRecord.setType(stockOutRecord.getType()); // 绫诲瀷锛堝悎鏍�/涓嶅悎鏍硷級
+            stockInRecord.setSalesLedgerId(stockOutRecord.getSalesLedgerId()); // 閿�鍞鍗旾D
+            stockInRecord.setSalesLedgerProductId(stockOutRecord.getSalesLedgerProductId()); // 閿�鍞鍗曚骇鍝両D
+            
+            // 4.2 鎻掑叆鍙嶅鍏ュ簱璁板綍
+            stockInRecordMapper.insert(stockInRecord);
+            
+            // 4.3 鍚戝簱瀛樿〃涓鍔犵浉搴旀暟閲�
+            StockInventoryDto stockInventoryDto = new StockInventoryDto();
+            stockInventoryDto.setProductModelId(stockInRecord.getProductModelId());
+            stockInventoryDto.setQualitity(stockInRecord.getStockInNum());
+            stockInventoryMapper.updateAddStockInventory(stockInventoryDto);
+        }
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3