From 69e0f44e279f7763fa9c9a4d105f154db39ee1d8 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期六, 23 五月 2026 11:38:02 +0800
Subject: [PATCH] feat(sales): 添加每件数量字段支持及多业务流程优化
---
src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java | 62 +++++++++++++++++++++---------
1 files changed, 43 insertions(+), 19 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 f181ea0..32359ec 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesQuotationServiceImpl.java
@@ -4,17 +4,19 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
+import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
-
import com.ruoyi.approve.pojo.ApproveProcess;
-import com.ruoyi.approve.service.IApproveProcessService;
import com.ruoyi.approve.service.impl.ApproveProcessServiceImpl;
-import com.ruoyi.approve.vo.ApproveGetAndUpdateVo;
-import com.ruoyi.approve.vo.ApproveProcessVO;
+import com.ruoyi.approve.bean.vo.ApproveGetAndUpdateVo;
+import com.ruoyi.approve.bean.vo.ApproveProcessVO;
+import com.ruoyi.basic.mapper.CustomerMapper;
+import com.ruoyi.basic.pojo.Customer;
+import com.ruoyi.common.enums.IsDeleteEnum;
import com.ruoyi.common.utils.OrderUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
-import com.ruoyi.common.utils.uuid.UUID;
import com.ruoyi.framework.security.LoginUser;
import com.ruoyi.sales.dto.SalesQuotationDto;
import com.ruoyi.sales.mapper.SalesQuotationMapper;
@@ -23,27 +25,27 @@
import com.ruoyi.sales.pojo.SalesQuotationProduct;
import com.ruoyi.sales.service.SalesQuotationProductService;
import com.ruoyi.sales.service.SalesQuotationService;
-import org.springframework.beans.factory.annotation.Autowired;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import lombok.RequiredArgsConstructor;
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;
@Service
@Transactional(rollbackFor = Exception.class)
+@RequiredArgsConstructor
public class SalesQuotationServiceImpl extends ServiceImpl<SalesQuotationMapper, SalesQuotation> implements SalesQuotationService {
- @Autowired
- private SalesQuotationMapper salesQuotationMapper;
- @Autowired
- private SalesQuotationProductMapper salesQuotationProductMapper;
- @Autowired
- private SalesQuotationProductService salesQuotationProductService;
+ private final SalesQuotationProductMapper salesQuotationProductMapper;
+ private final SalesQuotationMapper salesQuotationMapper;
+ private final SalesQuotationProductService salesQuotationProductService;
- @Autowired
- private ApproveProcessServiceImpl approveProcessService;
+ private final ApproveProcessServiceImpl approveProcessService;
+ private final CustomerMapper customerMapper;
+
@Override
public IPage<SalesQuotationDto> listPage(Page page, SalesQuotationDto salesQuotationDto) {
IPage<SalesQuotationDto> salesQuotationDtoIPage = salesQuotationMapper.listPage(page, salesQuotationDto);
@@ -62,7 +64,12 @@
LoginUser loginUser = SecurityUtils.getLoginUser();
SalesQuotation salesQuotation = new SalesQuotation();
BeanUtils.copyProperties(salesQuotationDto, salesQuotation);
- String quotationNo = OrderUtils.countTodayByCreateTime(salesQuotationMapper, "QT");
+ salesQuotation.setId(null);
+ Customer customer = customerMapper.selectById(Long.valueOf(salesQuotationDto.getCustomerId()));
+ if (ObjectUtils.isNotEmpty(customer)) {
+ salesQuotation.setCustomer(customer.getCustomerName());
+ }
+ String quotationNo = OrderUtils.countTodayByCreateTime(salesQuotationMapper, "QT","quotation_no");
salesQuotation.setQuotationNo(quotationNo);
salesQuotation.setStatus("寰呭鎵�");
salesQuotationMapper.insert(salesQuotation);
@@ -72,6 +79,7 @@
List<SalesQuotationProduct> products = salesQuotationDto.getProducts().stream().map(product -> {
SalesQuotationProduct salesQuotationProduct = new SalesQuotationProduct();
BeanUtils.copyProperties(product, salesQuotationProduct);
+ salesQuotationProduct.setSingleQuantity(normalizeSingleQuantity(salesQuotationProduct.getSingleQuantity()));
salesQuotationProduct.setSalesQuotationId(salesQuotation.getId());
return salesQuotationProduct;
}).collect(Collectors.toList());
@@ -81,7 +89,6 @@
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());
@@ -89,7 +96,7 @@
approveProcessService.addApprove(approveProcessVO);
}catch (Exception e){
log.error("SalesQuotationServiceImpl error:{}", e);
- throw new RuntimeException("瀹℃壒澶辫触");
+ throw new RuntimeException("瀹℃壒澶辫触");
}
return true;
}
@@ -112,13 +119,13 @@
List<SalesQuotationProduct> products = salesQuotationDto.getProducts().stream().map(product -> {
SalesQuotationProduct salesQuotationProduct = new SalesQuotationProduct();
BeanUtils.copyProperties(product, salesQuotationProduct);
+ salesQuotationProduct.setSingleQuantity(normalizeSingleQuantity(salesQuotationProduct.getSingleQuantity()));
salesQuotationProduct.setSalesQuotationId(salesQuotation.getId());
return salesQuotationProduct;
}).collect(Collectors.toList());
salesQuotationProductService.saveBatch(products);
// 淇敼鎶ヤ环瀹℃壒
- vo.setApproveUserIds(salesQuotationDto.getApproveUserIds());
vo.setApproveType(6);
vo.setApproveReason(salesQuotationDto.getQuotationNo());
approveProcessService.updateApproveUser(vo);
@@ -126,10 +133,27 @@
}
@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::getApproveDelete, IsDeleteEnum.NOT_DELETED)
+ .eq(ApproveProcess::getApproveReason, salesQuotation.getQuotationNo()));
+ if(one != null){
+ approveProcessService.delByIds(Collections.singletonList(one.getId()));
+ }
return true;
}
+ private BigDecimal normalizeSingleQuantity(BigDecimal singleQuantity) {
+ if (singleQuantity == null || singleQuantity.compareTo(BigDecimal.ZERO) <= 0) {
+ return BigDecimal.ONE;
+ }
+ return singleQuantity;
+ }
+
}
--
Gitblit v1.9.3