From c51ff05bf690c64dd0cd40c63afe41e12657b941 Mon Sep 17 00:00:00 2001
From: liyong <18434998025@163.com>
Date: 星期二, 20 一月 2026 16:21:08 +0800
Subject: [PATCH] feat(production): 数量保留两位小数
---
src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java | 98 +++++++++++++++++++++++++++++++++++++++++++++----
1 files changed, 90 insertions(+), 8 deletions(-)
diff --git a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
index b34d193..cf58848 100644
--- a/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
+++ b/src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -1,25 +1,35 @@
package com.ruoyi.sales.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.ruoyi.framework.web.domain.R;
+import com.ruoyi.procurementrecord.utils.StockUtils;
+import com.ruoyi.production.dto.ProductStructureDto;
+import com.ruoyi.production.mapper.ProcessRouteMapper;
+import com.ruoyi.production.mapper.ProductBomMapper;
+import com.ruoyi.production.mapper.ProductStructureMapper;
+import com.ruoyi.production.pojo.ProcessRoute;
import com.ruoyi.purchase.mapper.PurchaseLedgerMapper;
import com.ruoyi.purchase.pojo.PurchaseLedger;
+import com.ruoyi.sales.dto.InvoiceRegistrationProductDto;
+import com.ruoyi.sales.mapper.InvoiceRegistrationProductMapper;
import com.ruoyi.sales.mapper.SalesLedgerMapper;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedger;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
import com.ruoyi.sales.service.ISalesLedgerProductService;
import lombok.AllArgsConstructor;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
import java.lang.reflect.Field;
import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Objects;
-import java.util.Set;
+import java.math.RoundingMode;
+import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
@@ -38,6 +48,17 @@
private SalesLedgerMapper salesLedgerMapper;
private PurchaseLedgerMapper purchaseLedgerMapper;
+ private StockUtils stockUtils;
+
+ @Autowired
+ private InvoiceRegistrationProductMapper invoiceRegistrationProductMapper;
+
+ @Autowired
+ private ProcessRouteMapper processRouteMapper;
+ @Autowired
+ private ProductBomMapper productBomMapper;
+ @Autowired
+ private ProductStructureMapper productStructureMapper;
@Override
public SalesLedgerProduct selectSalesLedgerProductById(Long id) {
@@ -46,10 +67,32 @@
@Override
public List<SalesLedgerProduct> selectSalesLedgerProductList(SalesLedgerProduct salesLedgerProduct) {
- LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerProduct.getSalesLedgerId())
- .eq(SalesLedgerProduct::getType, salesLedgerProduct.getType());
- return salesLedgerProductMapper.selectList(queryWrapper);
+// LambdaQueryWrapper<SalesLedgerProduct> queryWrapper = new LambdaQueryWrapper<>();
+// queryWrapper.eq(SalesLedgerProduct::getSalesLedgerId, salesLedgerProduct.getSalesLedgerId())
+// .eq(SalesLedgerProduct::getType, salesLedgerProduct.getType());
+ List<SalesLedgerProduct> salesLedgerProducts = salesLedgerProductMapper.selectSalesLedgerProductList(salesLedgerProduct);
+ if (!CollectionUtils.isEmpty(salesLedgerProducts)) {
+ InvoiceRegistrationProductDto invoiceRegistrationProductDto = new InvoiceRegistrationProductDto();
+ invoiceRegistrationProductDto.setSalesLedgerId(salesLedgerProduct.getSalesLedgerId().intValue());
+ List<InvoiceRegistrationProductDto> invoiceRegistrationProductDtoList = invoiceRegistrationProductMapper.invoiceRegistrationProductList(invoiceRegistrationProductDto);
+ // 缁熻寮�绁ㄧ櫥璁颁骇鍝佺殑宸插紑绁ㄦ暟/宸插紑绁ㄩ噾棰�
+ if (!CollectionUtils.isEmpty(invoiceRegistrationProductDtoList)) {
+ for (SalesLedgerProduct ledgerProduct : salesLedgerProducts) {
+ BigDecimal invoiceNum = BigDecimal.ZERO;
+ BigDecimal invoiceAmount = BigDecimal.ZERO;
+ for (InvoiceRegistrationProductDto registrationProductDto : invoiceRegistrationProductDtoList) {
+ if (ledgerProduct.getId().intValue() == registrationProductDto.getSalesLedgerProductId()) {
+ invoiceNum = invoiceNum.add(registrationProductDto.getInvoiceNum());
+ invoiceAmount = invoiceAmount.add(registrationProductDto.getInvoiceAmount());
+ }
+ }
+ ledgerProduct.setInvoiceNum(invoiceNum);
+ ledgerProduct.setInvoiceAmount(invoiceAmount);
+ }
+ }
+
+ }
+ return salesLedgerProducts;
}
@Override
@@ -95,11 +138,15 @@
@Override
@Transactional(rollbackFor = Exception.class)
public int addOrUpdateSalesLedgerProduct(SalesLedgerProduct salesLedgerProduct) {
+ //鏈紑绁ㄦ暟閲�+閲戦
+ salesLedgerProduct.setNoInvoiceNum(salesLedgerProduct.getQuantity());
+ salesLedgerProduct.setNoInvoiceAmount(salesLedgerProduct.getTaxInclusiveTotalPrice());
int result;
Long salesLedgerId = salesLedgerProduct.getSalesLedgerId();
if (salesLedgerProduct.getId() == null) {
result = salesLedgerProductMapper.insert(salesLedgerProduct);
} else {
+ salesLedgerProduct.setFutureTickets(salesLedgerProduct.getQuantity());
result = salesLedgerProductMapper.updateById(salesLedgerProduct);
}
@@ -133,6 +180,41 @@
return result;
}
+ @Override
+ public R judgmentInventory(SalesLedgerProduct salesLedgerProduct) {
+ //鑾峰彇浜у搧鏈�鏂扮殑宸ヨ壓璺嚎
+ ProcessRoute processRoute = processRouteMapper.selectOne(new QueryWrapper<ProcessRoute>().lambda().eq(ProcessRoute::getProductModelId, salesLedgerProduct.getProductModelId()).orderByDesc(ProcessRoute::getCreateTime).last("LIMIT 1"));
+ if (processRoute == null) {
+ return R.fail("璇峰厛璁剧疆宸ヨ壓璺嚎");
+ }
+ List<ProductStructureDto> productStructureDtos = productStructureMapper.listBybomId(processRoute.getBomId());
+ if (productStructureDtos.isEmpty()) {
+ return R.fail("璇峰厛璁剧疆浜у搧缁撴瀯");
+ }
+ int count = 0;
+ StringBuilder stringBuffer = new StringBuilder();
+ for (ProductStructureDto productStructureDto : productStructureDtos) {
+ BigDecimal stockQuantity = stockUtils.getStockQuantity(productStructureDto.getProductModelId()).get("stockQuantity");
+ //鎵�闇�鏁伴噺
+ BigDecimal multiply = salesLedgerProduct.getQuantity().multiply(productStructureDto.getUnitQuantity());
+ BigDecimal subtract =stockQuantity.subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING);
+ if (subtract.compareTo(BigDecimal.ZERO) <= 0) {
+ count++;
+ stringBuffer.append(productStructureDto.getProductName())
+ .append("-")
+ .append(productStructureDto.getModel())
+ .append("搴撳瓨涓嶈冻锛屽皯")
+ .append(subtract)
+ .append(System.lineSeparator());
+ }
+ }
+ if (count>0) {
+ return R.fail(stringBuffer.toString());
+ }else {
+ return R.ok();
+ }
+ }
+
/**
* 閫氱敤鏂规硶锛氭牴鎹富琛↖D鍜屽瓙琛ㄥ垪琛紝鏇存柊涓昏〃鐨勫悎鍚岄噾棰�
*/
--
Gitblit v1.9.3