From f67161d150eb5720b28fd3f9fbb40c4145d1146c Mon Sep 17 00:00:00 2001
From: liding <756868258@qq.com>
Date: 星期三, 10 六月 2026 11:42:37 +0800
Subject: [PATCH] feat:1.已审核只能编辑单价 2.添加完成按钮 3.添加标签打印和单据打印次数展示

---
 src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java |  145 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 145 insertions(+), 0 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 0854853..527268f 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerServiceImpl.java
@@ -3357,6 +3357,97 @@
      * 2. 澶嶅埗鍘熼攢鍞彴璐﹀強浜у搧鏁版嵁锛岀敓鎴愭柊鐨勫彴璐�
      * 3. 瀵瑰師鍙拌处鐨勫簱瀛樻暟鎹繘琛屽弽鍚戞搷浣�
      */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public List<Long> counterReview(CounterReviewDto dto) {
+        if (dto == null || CollectionUtils.isEmpty(dto.getIds())) {
+            throw new ServiceException("璇烽�夋嫨瑕佸弽瀹℃牳鐨勮鍗�");
+        }
+        if (dto.getCounterReviewType() == null || (dto.getCounterReviewType() != 1 && dto.getCounterReviewType() != 2)) {
+            throw new ServiceException("璇烽�夋嫨鍙嶅鏍哥被鍨嬶細浣滃簾鎴栭噸鏂扮敓鎴�");
+        }
+        if (dto.getCounterReviewDesc() == null || dto.getCounterReviewDesc().trim().isEmpty()) {
+            throw new ServiceException("璇疯緭鍏ュ弽瀹℃牳鎻忚堪");
+        }
+
+        LoginUser loginUser = SecurityUtils.getLoginUser();
+        List<Long> newLedgerIds = new ArrayList<>();
+
+        for (Long id : dto.getIds()) {
+            SalesLedger originalLedger = salesLedgerMapper.selectById(id);
+            if (originalLedger == null) {
+                throw new ServiceException("璁㈠崟涓嶅瓨鍦紝鏃犳硶鍙嶅鏍�");
+            }
+            if (originalLedger.getReviewStatus() == null || originalLedger.getReviewStatus() != 1) {
+                throw new ServiceException("璁㈠崟" + originalLedger.getSalesContractNo() + "涓嶆槸宸插鏍哥姸鎬侊紝鏃犳硶鍙嶅鏍�");
+            }
+
+            // 1. 鏍囪鍘熻鍗曚负宸插弽瀹�
+            originalLedger.setReviewStatus(2);
+            originalLedger.setCounterReviewTime(LocalDateTime.now());
+            originalLedger.setCounterReviewPerson(loginUser.getUser().getNickName());
+            originalLedger.setCounterReviewPersonId(loginUser.getUserId());
+            originalLedger.setCounterReviewType(dto.getCounterReviewType());
+            originalLedger.setCounterReviewDesc(dto.getCounterReviewDesc());
+            salesLedgerMapper.updateById(originalLedger);
+
+            // 2. 浣滃簾搴撳瓨锛氬叆搴撴墸鍑忋�佸嚭搴撳鍔犮�佸垹闄よ褰�
+            processOriginalOrderStock(id);
+
+            // 3. 娓呴櫎璐ㄦ璁板綍
+            clearQualityInspectRecords(id);
+
+            // 4. 娓呴櫎鍙戣揣淇℃伅鍜屽彂璐у鎵硅褰�
+            clearShippingAndApprovalRecords(id);
+
+            // 5. 鍙栨秷瀹℃壒娴佺▼
+            cancelApproveProcesses(id, originalLedger.getSalesContractNo());
+
+            // 6. 閲嶆柊鐢熸垚锛氬垱寤烘柊鍙拌处鍓湰
+            if (dto.getCounterReviewType() == 2) {
+                SalesLedger newLedger = new SalesLedger();
+                BeanUtils.copyProperties(originalLedger, newLedger);
+                newLedger.setId(null);
+                newLedger.setSalesContractNo(generateSalesContractNo());
+                newLedger.setDeliveryStatus(1);
+                newLedger.setStockStatus(0);
+                newLedger.setReviewStatus(0);
+                newLedger.setCounterReviewTime(null);
+                newLedger.setCounterReviewPerson(null);
+                newLedger.setCounterReviewPersonId(null);
+                newLedger.setCounterReviewType(null);
+                newLedger.setCounterReviewDesc(null);
+                salesLedgerMapper.insert(newLedger);
+
+                // 澶嶅埗浜у搧鍒版柊鍙拌处
+                List<SalesLedgerProduct> originalProducts = salesLedgerProductMapper.selectList(
+                    Wrappers.<SalesLedgerProduct>lambdaQuery()
+                        .eq(SalesLedgerProduct::getSalesLedgerId, id)
+                );
+                for (SalesLedgerProduct originalProduct : originalProducts) {
+                    SalesLedgerProduct newProduct = new SalesLedgerProduct();
+                    BeanUtils.copyProperties(originalProduct, newProduct);
+                    newProduct.setId(null);
+                    newProduct.setSalesLedgerId(newLedger.getId());
+                    newProduct.setStockedQuantity(BigDecimal.ZERO);
+                    newProduct.setShippedQuantity(BigDecimal.ZERO);
+                    newProduct.setUnqualifiedStockedQuantity(BigDecimal.ZERO);
+                    newProduct.setUnqualifiedShippedQuantity(BigDecimal.ZERO);
+                    newProduct.setReturnQuality(BigDecimal.ZERO);
+                    newProduct.setAvailableQuality(newProduct.getQuantity().subtract(newProduct.getReturnQuality()));
+                    newProduct.setProductStockStatus(0);
+                    newProduct.fillRemainingQuantity();
+                    salesLedgerProductMapper.insert(newProduct);
+                }
+                newLedgerIds.add(newLedger.getId());
+            }
+        }
+        return newLedgerIds;
+    }
+
+    /**
+     * 鏃х増鍙嶅澶勭悊锛堝吋瀹� addOrUpdateSalesLedger 涓� reviewStatus=2 鐨勮皟鐢級
+     */
     private void handleCounterReview(SalesLedger salesLedger) {
         // 1. 璁剧疆鍙嶅鐩稿叧淇℃伅
         LoginUser loginUser = SecurityUtils.getLoginUser();
@@ -3549,4 +3640,58 @@
                 .eq(StockOutRecord::getSalesLedgerId, originalSalesLedgerId)
         );
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public void markOrderCompleted(List<Long> ids) {
+        if (CollectionUtils.isEmpty(ids)) {
+            throw new ServiceException("璇烽�夋嫨瑕佹爣璁板畬鎴愮殑璁㈠崟");
+        }
+        for (Long id : ids) {
+            SalesLedger ledger = salesLedgerMapper.selectById(id);
+            if (ledger == null) {
+                throw new ServiceException("璁㈠崟涓嶅瓨鍦紝鏃犳硶鏍囪瀹屾垚");
+            }
+            if (ledger.getReviewStatus() == null || ledger.getReviewStatus() != 1) {
+                throw new ServiceException("璁㈠崟" + ledger.getSalesContractNo() + "涓嶆槸宸插鏍哥姸鎬侊紝鏃犳硶鏍囪瀹屾垚");
+            }
+            if (ledger.getOrderStatus() != null && ledger.getOrderStatus() == 1) {
+                throw new ServiceException("璁㈠崟" + ledger.getSalesContractNo() + "宸插畬鎴愶紝鏃犻渶閲嶅鏍囪");
+            }
+        }
+        salesLedgerMapper.update(null,
+            Wrappers.<SalesLedger>lambdaUpdate()
+                .in(SalesLedger::getId, ids)
+                .set(SalesLedger::getOrderStatus, 1)
+        );
+    }
+
+    @Override
+    public void incrementPrintCount(Long id, String printType) {
+        if (id == null) {
+            throw new ServiceException("閿�鍞彴璐D涓嶈兘涓虹┖");
+        }
+        if (printType == null || (!"label".equals(printType) && !"document".equals(printType))) {
+            throw new ServiceException("鎵撳嵃绫诲瀷蹇呴』涓� label 鎴� document");
+        }
+        SalesLedger ledger = salesLedgerMapper.selectById(id);
+        if (ledger == null) {
+            throw new ServiceException("閿�鍞彴璐︿笉瀛樺湪");
+        }
+        if ("label".equals(printType)) {
+            int currentCount = ledger.getLabelPrintCount() == null ? 0 : ledger.getLabelPrintCount();
+            salesLedgerMapper.update(null,
+                Wrappers.<SalesLedger>lambdaUpdate()
+                    .eq(SalesLedger::getId, id)
+                    .set(SalesLedger::getLabelPrintCount, currentCount + 1)
+            );
+        } else {
+            int currentCount = ledger.getDocumentPrintCount() == null ? 0 : ledger.getDocumentPrintCount();
+            salesLedgerMapper.update(null,
+                Wrappers.<SalesLedger>lambdaUpdate()
+                    .eq(SalesLedger::getId, id)
+                    .set(SalesLedger::getDocumentPrintCount, currentCount + 1)
+            );
+        }
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3