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/ShippingInfoServiceImpl.java | 129 +++++++++++++++++++++++++++++++++---------
1 files changed, 101 insertions(+), 28 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
index 3d105fd..69a0820 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/ShippingInfoServiceImpl.java
@@ -11,21 +11,24 @@
import com.ruoyi.basic.utils.FileUtil;
import com.ruoyi.common.enums.FileNameType;
import com.ruoyi.common.enums.StockOutQualifiedRecordTypeEnum;
-import com.ruoyi.other.service.impl.TempFileServiceImpl;
+import com.ruoyi.procurementrecord.bean.vo.ShippingProductVo;
import com.ruoyi.procurementrecord.utils.StockUtils;
-import com.ruoyi.sales.dto.SalesLedgerProductDto;
+import com.ruoyi.sales.dto.ShippingApproveDto;
import com.ruoyi.sales.dto.ShippingInfoDto;
+import com.ruoyi.sales.dto.ShippingProductDetailDto;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.mapper.ShippingInfoMapper;
+import com.ruoyi.sales.mapper.ShippingProductDetailMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.pojo.ShippingInfo;
+import com.ruoyi.sales.pojo.ShippingProductDetail;
import com.ruoyi.sales.service.ShippingInfoService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
-import java.util.Collections;
+import java.math.BigDecimal;
import java.util.List;
/**
@@ -37,19 +40,25 @@
@RequiredArgsConstructor
public class ShippingInfoServiceImpl extends ServiceImpl<ShippingInfoMapper, ShippingInfo> implements ShippingInfoService {
+
private final ShippingInfoMapper shippingInfoMapper;
- private final TempFileServiceImpl tempFileService;
+
+
private final SalesLedgerProductMapper salesLedgerProductMapper;
+
private final StockUtils stockUtils;
+
private final CommonFileServiceImpl commonFileService;
+
private final ApproveProcessServiceImpl approveProcessService;
private final FileUtil fileUtil;
+ private final ShippingProductDetailMapper shippingProductDetailMapper;
@Override
public IPage<ShippingInfoDto> listPage(Page page, ShippingInfo req) {
IPage<ShippingInfoDto> listPage = shippingInfoMapper.listPage(page, req);
- listPage.getRecords().forEach(item ->{
- item.setCommonFileList(commonFileService.getFileListByBusinessId(item.getId(), FileNameType.SHIP.getValue()));
+ listPage.getRecords().forEach(item -> {
+ item.setStorageBlobVOs(fileUtil.getStorageBlobVOsByApplicationAndRecordTypeAndRecordId(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, item.getId()));
});
return listPage;
}
@@ -61,9 +70,14 @@
throw new RuntimeException("鍙戣揣淇℃伅涓嶅瓨鍦�");
}
//鎵e噺搴撳瓨
- if(!"宸插彂璐�".equals(byId.getStatus())){
- SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(byId.getSalesLedgerProductId());
- stockUtils.substractStock(salesLedgerProduct.getProductModelId(), salesLedgerProduct.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId());
+ if (!"宸插彂璐�".equals(byId.getStatus())) {
+ List<ShippingProductDetail> shippingProductDetails = shippingProductDetailMapper.selectList(new LambdaQueryWrapper<ShippingProductDetail>().eq(ShippingProductDetail::getShippingInfoId, req.getId()));
+ if (CollectionUtils.isEmpty(shippingProductDetails)) {
+ throw new RuntimeException("鍙戣揣淇℃伅涓嶅瓨鍦�");
+ }
+ for (ShippingProductDetail shippingProductDetail : shippingProductDetails) {
+ stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo());
+ }
}
byId.setExpressNumber(req.getExpressNumber());
byId.setExpressCompany(req.getExpressCompany());
@@ -72,40 +86,39 @@
byId.setShippingDate(req.getShippingDate());
boolean update = this.updateById(byId);
// 淇濆瓨鏂囦欢
- fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.ShippingInfo, req.getId(), req.getStorageBlobDTOs());
- return update ;
+ fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs());
+ return update;
}
@Override
public boolean delete(List<Long> ids) {
List<ShippingInfo> shippingInfos = shippingInfoMapper.selectList(new LambdaQueryWrapper<ShippingInfo>()
.in(ShippingInfo::getId, ids));
- if(CollectionUtils.isEmpty(shippingInfos)) return false;
+ if (CollectionUtils.isEmpty(shippingInfos)) return false;
// 鍒犻櫎闄勪欢
commonFileService.deleteByBusinessIds(ids, FileNameType.SHIP.getValue());
- // 鎵e凡鍙戣揣搴撳瓨
- for (ShippingInfo shippingInfo : shippingInfos) {
- if("宸插彂璐�".equals(shippingInfo.getStatus())) {
+ // 鍒犻櫎鍙戣揣瀹℃壒
+ if (CollectionUtils.isNotEmpty(shippingInfos)) {
+ for (ShippingInfo shippingInfo : shippingInfos) {
+ List<ApproveProcess> one = approveProcessService.list(new LambdaQueryWrapper<ApproveProcess>()
+ .like(ApproveProcess::getApproveReason, shippingInfo.getShippingNo()));
+ if (one != null) {
+ List<Long> list = one.stream().map(ApproveProcess::getId).toList();
+ approveProcessService.delByIds(list);
+ }
+ // 鎵e凡鍙戣揣搴撳瓨
stockUtils.deleteStockOutRecord(shippingInfo.getId(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode());
}
}
- // 鍒犻櫎鍙戣揣瀹℃壒
- if(CollectionUtils.isNotEmpty(shippingInfos)){
- for (ShippingInfo shippingInfo : shippingInfos){
- ApproveProcess one = approveProcessService.getOne(new LambdaQueryWrapper<ApproveProcess>()
- .like(ApproveProcess::getApproveReason, shippingInfo.getShippingNo()));
- if(one != null){
- approveProcessService.delByIds(Collections.singletonList(one.getId()));
- }
- }
- }
+ //鍒犻櫎鍙戣揣鏄庣粏
+ shippingProductDetailMapper.delete(new LambdaQueryWrapper<ShippingProductDetail>().in(ShippingProductDetail::getShippingInfoId, ids));
- return this.removeBatchByIds(ids);
+ return this.removeByIds(ids);
}
@Override
- public List<SalesLedgerProductDto> getReturnManagementDtoById(Long shippingId) {
- return shippingInfoMapper.getReturnManagementDtoById(shippingId );
+ public List<ShippingProductVo> getReturnManagementDtoById(Long shippingId) {
+ return shippingInfoMapper.getReturnManagementDtoById(shippingId);
}
@@ -113,4 +126,64 @@
public List<ShippingInfo> getShippingInfoByCustomerName(String customerName) {
return shippingInfoMapper.getShippingInfoByCustomerName(customerName);
}
+
+ @Override
+ public boolean add(ShippingInfoDto req) {
+ if (CollectionUtils.isEmpty(req.getBatchNoDetailList())) {
+ throw new RuntimeException("鍙戣揣鏄庣粏涓嶈兘涓虹┖");
+ }
+// normalizeShippingQuantity(req.getBatchNoDetailList(), req.getSalesLedgerProductId());
+ this.save(req);
+ req.getBatchNoDetailList().forEach(item -> item.setShippingInfoId(req.getId()));
+ shippingProductDetailMapper.insert(req.getBatchNoDetailList());
+ for (ShippingProductDetail shippingProductDetail : req.getBatchNoDetailList()) {
+ stockUtils.substractStock(shippingProductDetail.getProductModelId(), shippingProductDetail.getQuantity(), StockOutQualifiedRecordTypeEnum.SALE_SHIP_STOCK_OUT.getCode(), req.getId(), shippingProductDetail.getBatchNo());
+ }
+ // 淇濆瓨鏂囦欢
+ fileUtil.saveStorageAttachment(ApplicationTypeEnum.IMAGE, RecordTypeEnum.SHIPPING_INFO, req.getId(), req.getStorageBlobDTOs());
+ return true;
+ }
+
+ @Override
+ public List<ShippingProductDetailDto> getDetail(Long id) {
+ return shippingProductDetailMapper.getDetail(id);
+ }
+
+ @Override
+ public ShippingApproveDto getDateilByShippingNo(String shippingNo) {
+ ShippingApproveDto shippingApproveDto = new ShippingApproveDto();
+ ShippingInfo shippingInfo = new ShippingInfo();
+ shippingInfo.setShippingNo(shippingNo);
+ shippingApproveDto.setShippingInfo(shippingInfoMapper.listPage(new Page(1, -1), shippingInfo).getRecords().get(0));
+ List<ShippingProductDetailDto> dateilByShippingNo = shippingProductDetailMapper.getDateilByShippingNo(shippingNo);
+ shippingApproveDto.setShippingProductDetailDtoList(dateilByShippingNo);
+ return shippingApproveDto;
+ }
+
+ /**
+ * 姝e父鍖栧彂璐ф暟閲�
+ * @param shippingProductDetails
+ * @param salesLedgerProductId
+ */
+ private void normalizeShippingQuantity(List<ShippingProductDetail> shippingProductDetails, Long salesLedgerProductId) {
+ if (CollectionUtils.isEmpty(shippingProductDetails)) {
+ return;
+ }
+ BigDecimal singleQuantity = BigDecimal.ONE;
+ if (salesLedgerProductId != null) {
+ SalesLedgerProduct salesLedgerProduct = salesLedgerProductMapper.selectById(salesLedgerProductId);
+ if (salesLedgerProduct != null && salesLedgerProduct.getSingleQuantity() != null
+ && salesLedgerProduct.getSingleQuantity().compareTo(BigDecimal.ZERO) > 0) {
+ singleQuantity = salesLedgerProduct.getSingleQuantity();
+ }
+ }
+ if (singleQuantity.compareTo(BigDecimal.ONE) == 0) {
+ return;
+ }
+ for (ShippingProductDetail shippingProductDetail : shippingProductDetails) {
+ if (shippingProductDetail.getQuantity() != null) {
+ shippingProductDetail.setQuantity(shippingProductDetail.getQuantity().multiply(singleQuantity));
+ }
+ }
+ }
}
--
Gitblit v1.9.3