From 03ffc2598a261d1dc19e77b559268bb84032a389 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 21 四月 2026 08:51:45 +0800
Subject: [PATCH] feat(approve): 新增销售审批功能并优化审批流程

---
 src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java |   90 +++++++++++++++++++++++++-------------------
 1 files changed, 51 insertions(+), 39 deletions(-)

diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
index 8872e88..b27719c 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
@@ -13,6 +13,7 @@
 import com.ruoyi.approve.vo.ApproveProcessVO;
 import com.ruoyi.common.utils.OrderUtils;
 import com.ruoyi.common.utils.SecurityUtils;
+import com.ruoyi.common.utils.StringUtils;
 import com.ruoyi.common.utils.bean.BeanUtils;
 import com.ruoyi.common.utils.uuid.UUID;
 import com.ruoyi.framework.security.LoginUser;
@@ -28,8 +29,8 @@
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.time.LocalDate;
-import java.util.Collections;
 import java.util.List;
 import java.util.stream.Collectors;
 
@@ -43,12 +44,11 @@
     @Autowired
     private SalesQuotationProductService salesQuotationProductService;
 
-    @Autowired
-    private ApproveProcessServiceImpl approveProcessService;
+
     @Override
     public IPage<SalesQuotationDto> listPage(Page page, SalesQuotationDto salesQuotationDto) {
         IPage<SalesQuotationDto> salesQuotationDtoIPage = salesQuotationMapper.listPage(page, salesQuotationDto);
-        if(CollectionUtils.isEmpty(salesQuotationDtoIPage.getRecords())){
+        if (CollectionUtils.isEmpty(salesQuotationDtoIPage.getRecords())) {
             return salesQuotationDtoIPage;
         }
         salesQuotationDtoIPage.getRecords().forEach(record -> {
@@ -60,14 +60,14 @@
 
     @Override
     public boolean add(SalesQuotationDto salesQuotationDto) {
-        LoginUser loginUser = SecurityUtils.getLoginUser();
+//        LoginUser loginUser = SecurityUtils.getLoginUser();
         SalesQuotation salesQuotation = new SalesQuotation();
         BeanUtils.copyProperties(salesQuotationDto, salesQuotation);
-        String quotationNo = OrderUtils.countTodayByCreateTime(salesQuotationMapper, "QT","quotation_no");
+        String quotationNo = OrderUtils.countTodayByCreateTime(salesQuotationMapper, "QT", "quotation_no");
         salesQuotation.setQuotationNo(quotationNo);
         salesQuotation.setStatus("寰呭鎵�");
         salesQuotationMapper.insert(salesQuotation);
-        if(CollectionUtils.isEmpty(salesQuotationDto.getProducts())){
+        if (CollectionUtils.isEmpty(salesQuotationDto.getProducts())) {
             return true;
         }
         List<SalesQuotationProduct> products = salesQuotationDto.getProducts().stream().map(product -> {
@@ -76,38 +76,39 @@
             salesQuotationProduct.setSalesQuotationId(salesQuotation.getId());
             return salesQuotationProduct;
         }).collect(Collectors.toList());
-        salesQuotationProductService.saveBatch(products);
+        salesQuotationProductService.saveOrUpdateBatch(products);
         // 鎶ヤ环瀹℃壒
-        ApproveProcessVO approveProcessVO = new ApproveProcessVO();
-        approveProcessVO.setApproveType(6);
-        approveProcessVO.setApproveDeptId(loginUser.getCurrentDeptId());
-        approveProcessVO.setApproveReason(quotationNo);
-        approveProcessVO.setApproveUserIds(salesQuotationDto.getApproveUserIds());
-        approveProcessVO.setApproveUser(loginUser.getUserId());
-        approveProcessVO.setApproveTime(LocalDate.now().toString());
-        approveProcessVO.setPrice(salesQuotationDto.getTotalAmount());
-        try {
-            approveProcessService.addApprove(approveProcessVO);
-        }catch (Exception e){
-            log.error("SalesQuotationServiceImpl error:{}", e);
-            throw new RuntimeException("瀹℃壒澶辫触");
-        }
+//        ApproveProcessVO approveProcessVO = new ApproveProcessVO();
+//        approveProcessVO.setApproveType(6);
+//        approveProcessVO.setApproveDeptId(loginUser.getTenantId());
+//        approveProcessVO.setApproveReason(quotationNo);
+//        approveProcessVO.setApproveUserIds(salesQuotationDto.getApproveUserIds());
+//        approveProcessVO.setApproveUser(loginUser.getUserId());
+//        approveProcessVO.setApproveTime(LocalDate.now().toString());
+//        approveProcessVO.setPrice(salesQuotationDto.getTotalAmount());
+//        try {
+//            approveProcessService.addApprove(approveProcessVO);
+//        }catch (Exception e){
+//            log.error("SalesQuotationServiceImpl error:{}", e);
+//            throw new RuntimeException("瀹℃壒澶辫触");
+//        }
         return true;
     }
+
     @Override
     public boolean edit(SalesQuotationDto salesQuotationDto) {
         SalesQuotation salesQuotation = new SalesQuotation();
         BeanUtils.copyProperties(salesQuotationDto, salesQuotation);
         ApproveGetAndUpdateVo vo = new ApproveGetAndUpdateVo();
-        if("鎷掔粷".equals(salesQuotationDto.getStatus())){
+        if ("鎷掔粷".equals(salesQuotationDto.getStatus())) {
             vo.setApproveStatus(0);
             salesQuotation.setStatus("寰呭鎵�");
         }
-        if(salesQuotationMapper.updateById(salesQuotation)!=1){
+        if (salesQuotationMapper.updateById(salesQuotation) != 1) {
             return false;
         }
         salesQuotationProductMapper.delete(new LambdaQueryWrapper<SalesQuotationProduct>().eq(SalesQuotationProduct::getSalesQuotationId, salesQuotationDto.getId()));
-        if(CollectionUtils.isEmpty(salesQuotationDto.getProducts())){
+        if (CollectionUtils.isEmpty(salesQuotationDto.getProducts())) {
             return true;
         }
         List<SalesQuotationProduct> products = salesQuotationDto.getProducts().stream().map(product -> {
@@ -118,26 +119,37 @@
         }).collect(Collectors.toList());
 
         salesQuotationProductService.saveBatch(products);
-        // 淇敼鎶ヤ环瀹℃壒
-        vo.setApproveUserIds(salesQuotationDto.getApproveUserIds());
-        vo.setApproveType(6);
-        vo.setApproveReason(salesQuotationDto.getQuotationNo());
-        approveProcessService.updateApproveUser(vo);
+//        // 淇敼鎶ヤ环瀹℃壒
+//        vo.setApproveUserIds(salesQuotationDto.getApproveUserIds());
+//        vo.setApproveType(6);
+//        vo.setApproveReason(salesQuotationDto.getQuotationNo());
+//        approveProcessService.updateApproveUser(vo);
         return true;
     }
+
+    @Override
+    public BigDecimal detail(String type, String productName, String specification) {
+        if (StringUtils.isEmpty(type)) return null;
+        SalesQuotationProduct salesQuotationProduct = salesQuotationProductMapper.selectOne(new LambdaQueryWrapper<SalesQuotationProduct>()
+                .eq(SalesQuotationProduct::getProduct, productName)
+                .eq(SalesQuotationProduct::getSpecification, specification)
+                .orderByDesc(SalesQuotationProduct::getCreateTime)
+                .last("limit 1"));
+        if (salesQuotationProduct == null) return null;
+        switch (type) {
+            case "涓�鎵瑰晢":
+                return salesQuotationProduct.getUnitPrice();
+            case "缁堢鍟�":
+                return salesQuotationProduct.getUnitPriceTwo();
+            default:
+                return salesQuotationProduct.getUnitPriceThree();
+        }
+    }
+
     @Override
     public boolean delete(Long id) {
-        SalesQuotation salesQuotation = salesQuotationMapper.selectById(id);
-        if(salesQuotation==null) return false;
         salesQuotationMapper.deleteById(id);
         salesQuotationProductMapper.delete(new LambdaQueryWrapper<SalesQuotationProduct>().eq(SalesQuotationProduct::getSalesQuotationId, id));
-        // 鍒犻櫎鎶ヤ环瀹℃壒
-        ApproveProcess one = approveProcessService.getOne(new LambdaQueryWrapper<ApproveProcess>()
-                .eq(ApproveProcess::getApproveType, 6)
-                .eq(ApproveProcess::getApproveReason, salesQuotation.getQuotationNo()));
-        if(one != null){
-            approveProcessService.delByIds(Collections.singletonList(one.getId()));
-        }
         return true;
     }
 

--
Gitblit v1.9.3