src/main/java/com/ruoyi/home/service/impl/HomeServiceImpl.java
@@ -51,6 +51,7 @@ import com.ruoyi.sales.pojo.SalesLedgerProduct; import com.ruoyi.staff.mapper.StaffOnJobMapper; import com.ruoyi.staff.pojo.StaffOnJob; import com.ruoyi.stock.mapper.StockInventoryMapper; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -123,6 +124,7 @@ private SysUserMapper sysUserMapper; @Autowired private SysUserDeptMapper sysUserDeptMapper; private StockInventoryMapper stockInventoryMapper; @Override public HomeBusinessDto business() { @@ -193,17 +195,9 @@ // .filter(Objects::nonNull) // .reduce(BigDecimal.ZERO, BigDecimal::add); // BigDecimal stock = stockAmount.add(customStockAmount).subtract(outboundAmount); IPage<ProductModel> productModelIPage = productModelMapper.listPageProductModel(new Page<>(1, -1), new ProductModel()); if(!CollectionUtils.isEmpty(productModelIPage.getRecords())){ //获取规格id List<Long> modelIds = productModelIPage.getRecords().stream().map(ProductModel::getId).collect(Collectors.toList()); BigDecimal stockQuantityTotal = modelIds.stream() .map(stockUtils::getStockQuantity) .map(map -> map.get("stockQuantity")) .filter(Objects::nonNull) .reduce(BigDecimal.ZERO, BigDecimal::add); BigDecimal stockQuantityTotal = stockInventoryMapper.selectTotal(); homeBusinessDto.setInventoryNum(stockQuantityTotal.setScale(2, RoundingMode.HALF_UP).toString()); } // 获取当天入库数量 LambdaQueryWrapper<ProcurementRecordStorage> procurementRecordStorageLambdaQueryWrapper = new LambdaQueryWrapper<>(); @@ -426,7 +420,6 @@ } /** * * @param type 1-周 2-月 3-季度 * @return */ @@ -493,6 +486,7 @@ return statisticsReceivablePayableDto; } public static <T> BigDecimal sumAmount(List<T> list, java.util.function.Function<T, BigDecimal> amountExtractor) { return list.stream() // 提取金额时,将null替换为BigDecimal.ZERO @@ -500,6 +494,7 @@ // 累加,初始值为0,避免空流问题 .reduce(BigDecimal.ZERO, BigDecimal::add); } @Autowired private DeviceRepairMapper deviceRepairMapper; @@ -545,6 +540,7 @@ productionProgressDto.setPartialCompletedOrderCount(totalCount-count-count2); return productionProgressDto; } @Override public ProductionTurnoverDto workInProcessTurnover() { ProductionTurnoverDto productionTurnoverDto = new ProductionTurnoverDto(); src/main/java/com/ruoyi/procurementrecord/utils/StockUtils.java
@@ -29,19 +29,19 @@ private final StockInRecordService stockInRecordService; // 获取商品入库数量,出库数量,剩余库存 public Map<String, BigDecimal> getStockQuantity(Long productModelId) { // 入库数量 BigDecimal sumQuantity = procurementRecordMapper.getSumQuantity(productModelId); // 出库数量 BigDecimal outQuantity = procurementRecordOutMapper.getSumQuantity(productModelId); // 剩余库存 BigDecimal stockQuantity = outQuantity.compareTo(sumQuantity) > 0 ? BigDecimal.ZERO : sumQuantity.subtract(outQuantity); Map<String, BigDecimal> stockMap = new HashMap<>(); stockMap.put("inboundNum", sumQuantity); stockMap.put("outboundNum", outQuantity); stockMap.put("stockQuantity", stockQuantity); return stockMap; } // public Map<String, BigDecimal> getStockQuantity(Long productModelId) { // // 入库数量 // BigDecimal sumQuantity = procurementRecordMapper.getSumQuantity(productModelId); // // 出库数量 // BigDecimal outQuantity = procurementRecordOutMapper.getSumQuantity(productModelId); // // 剩余库存 // BigDecimal stockQuantity = outQuantity.compareTo(sumQuantity) > 0 ? BigDecimal.ZERO : sumQuantity.subtract(outQuantity); // Map<String, BigDecimal> stockMap = new HashMap<>(); // stockMap.put("inboundNum", sumQuantity); // stockMap.put("outboundNum", outQuantity); // stockMap.put("stockQuantity", stockQuantity); // return stockMap; // } /** * 不合格入库 src/main/java/com/ruoyi/production/service/impl/ProductionProductMainServiceImpl.java
@@ -142,15 +142,7 @@ productStructureDtos.add(productStructureDto); } for (ProductStructureDto productStructureDto : productStructureDtos) { ProductModel productModel1 = productModelMapper.selectById(productStructureDto.getProductModelId()); Product product = productMapper.selectById(productModel1.getProductId()); BigDecimal stockQuantity = stockUtils.getStockQuantity(productModel1.getId()).get("stockQuantity"); if (!(stockQuantity.compareTo(BigDecimal.ZERO) > 0)) { throw new RuntimeException(product.getProductName()+"产品的"+productModel1.getModel() + "的规格库存为0"); } if (stockQuantity.compareTo(productStructureDto.getUnitQuantity().multiply(dto.getQuantity())) < 0) { throw new RuntimeException(product.getProductName()+"产品的"+productModel1.getModel() + "的规格库存不足"); } ProductionProductInput productionProductInput = new ProductionProductInput(); productionProductInput.setProductModelId(productStructureDto.getProductModelId()); productionProductInput.setQuantity(productStructureDto.getUnitQuantity().multiply(dto.getQuantity())); src/main/java/com/ruoyi/sales/service/impl/SalesLedgerProductServiceImpl.java
@@ -28,6 +28,8 @@ import com.ruoyi.sales.pojo.SalesLedgerProduct; import com.ruoyi.sales.pojo.ShippingInfo; import com.ruoyi.sales.service.ISalesLedgerProductService; import com.ruoyi.stock.mapper.StockInventoryMapper; import com.ruoyi.stock.pojo.StockInventory; import lombok.AllArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -85,6 +87,8 @@ @Autowired private ProductStructureMapper productStructureMapper; @Autowired private StockInventoryMapper stockInventoryMapper; @Override public SalesLedgerProduct selectSalesLedgerProductById(Long id) { @@ -491,10 +495,11 @@ int count = 0; StringBuilder stringBuffer = new StringBuilder(); for (ProductStructureDto productStructureDto : productStructureDtos) { BigDecimal stockQuantity = stockUtils.getStockQuantity(productStructureDto.getProductModelId()).get("stockQuantity"); StockInventory stockInventory = stockInventoryMapper.selectOne(new QueryWrapper<StockInventory>().lambda().eq(StockInventory::getProductModelId, productStructureDto.getProductModelId())); //所需数量 BigDecimal multiply = salesLedgerProduct.getQuantity().multiply(productStructureDto.getUnitQuantity()); BigDecimal subtract =stockQuantity.subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING); BigDecimal subtract =stockInventory.getQualitity().subtract(stockInventory.getLockedQuantity()).subtract(multiply).divide(BigDecimal.ONE, 2, RoundingMode.CEILING); if (subtract.compareTo(BigDecimal.ZERO) <= 0) { count++; stringBuffer.append(productStructureDto.getProductName()) src/main/java/com/ruoyi/stock/mapper/StockInventoryMapper.java
@@ -10,6 +10,7 @@ import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; import java.math.BigDecimal; import java.util.List; /** @@ -35,4 +36,7 @@ IPage<StockInRecordDto> stockInventoryPage(@Param("ew") StockInventoryDto stockInventoryDto, Page page); IPage<StockInventoryDto> stockInAndOutRecord(@Param("ew") StockInventoryDto stockInventoryDto, Page page); BigDecimal selectTotal(); } src/main/resources/mapper/stock/StockInventoryMapper.xml
@@ -62,6 +62,7 @@ si.version, (si.qualitity - COALESCE(si.locked_quantity, 0)) as un_locked_quantity, pm.model, si.remark, pm.unit, p.product_name from stock_inventory si @@ -183,5 +184,9 @@ pm.unit, p.product_name </select> <select id="selectTotal" resultType="java.math.BigDecimal"> select sum(qualitity) from stock_inventory </select> </mapper>