src/main/java/com/ruoyi/sales/controller/SalesLedgerProductController.java
@@ -86,14 +86,16 @@ // procurementDto.setSalesLedgerProductId(item.getId()); // procurementDto.setProductCategory(item.getProductCategory()); // IPage<ProcurementPageDtoCopy> result = procurementRecordService.listPageCopyByProduction(new Page<>(1,-1), procurementDto); BigDecimal stockQuantity = stockUtils.getStockQuantity(item.getProductModelId()).get("stockQuantity"); if(stockQuantity != null) { // BigDecimal stockQuantity = stockUtils.getStockQuantity(item.getProductModelId()).get("stockQuantity"); // ProcurementPageDtoCopy procurementDtoCopy = result.getRecords().get(0); if (item.getQuantity().compareTo(stockQuantity) <= 0 && item.getApproveStatus() == 0) { item.setApproveStatus(1); salesLedgerProductService.addOrUpdateSalesLedgerProduct(item); if (item.getApproveStatus() != 2) { if (item.getHasSufficientStock() == 0) { item.setApproveStatus(0); }else { item.setApproveStatus(1); } } } }); return AjaxResult.success(list); } src/main/java/com/ruoyi/sales/mapper/SalesLedgerProductMapper.java
@@ -20,6 +20,8 @@ * @date 2025-05-08 */ public interface SalesLedgerProductMapper extends MyBaseMapper<SalesLedgerProduct> { List<SalesLedgerProduct> selectProduct() ; List<SalesLedgerProduct> selectSalesLedgerProductList(@Param("salesLedgerProduct") SalesLedgerProduct salesLedgerProduct); SalesLedgerProduct selectSalesLedgerProductByMainId(@Param("productMainId") Long productMainId); src/main/java/com/ruoyi/sales/pojo/SalesLedgerProduct.java
@@ -224,4 +224,7 @@ @ApiModelProperty(value = "是否质检") private Boolean isChecked; @TableField(exist = false) private Integer hasSufficientStock; } src/main/java/com/ruoyi/stock/controller/StockInventoryController.java
@@ -3,14 +3,23 @@ import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.compensationperformance.pojo.CompensationPerformance; import com.ruoyi.framework.aspectj.lang.annotation.Log; import com.ruoyi.framework.aspectj.lang.enums.BusinessType; import com.ruoyi.framework.web.domain.R; import com.ruoyi.stock.dto.StockInventoryDto; import com.ruoyi.stock.execl.StockInventoryExportData; import com.ruoyi.stock.service.StockInventoryService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletResponse; import java.util.ArrayList; import java.util.List; /** * <p> @@ -56,7 +65,14 @@ @GetMapping("importStockInventory") @ApiOperation("导入库存") public R importStockInventory(MultipartFile file) { return R.ok(stockInventoryService.importStockInventory(file)); return stockInventoryService.importStockInventory(file); } @Log(title = "下载库存导入模板", businessType = BusinessType.EXPORT) @PostMapping("/exportStockInventory") public void exportStockInventory(HttpServletResponse response) { List<StockInventoryExportData> list = new ArrayList<>(); ExcelUtil<StockInventoryExportData> util = new ExcelUtil<>(StockInventoryExportData.class); util.exportExcel(response, list, "下载薪资管理列表模板"); } } src/main/java/com/ruoyi/stock/execl/StockInventoryExportData.java
@@ -1,5 +1,24 @@ package com.ruoyi.stock.execl; import com.alibaba.excel.annotation.ExcelProperty; import com.ruoyi.framework.aspectj.lang.annotation.Excel; import lombok.Data; import java.math.BigDecimal; @Data public class StockInventoryExportData { @Excel(name = "产品名称") private String model; @Excel(name = "规格") private String productName; @Excel(name = "库存数量") private BigDecimal qualitity; @Excel(name = "备注") private String remark; } src/main/java/com/ruoyi/stock/service/StockInventoryService.java
@@ -24,5 +24,5 @@ Boolean subtractStockInventory(StockInventoryDto stockInventoryDto); Boolean importStockInventory(MultipartFile file); R importStockInventory(MultipartFile file); } src/main/java/com/ruoyi/stock/service/impl/StockInventoryServiceImpl.java
@@ -6,9 +6,13 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page; import com.ruoyi.basic.excel.SupplierManageExcelDto; import com.ruoyi.basic.pojo.SupplierManage; import com.ruoyi.common.enums.StockQualifiedRecordTypeEnum; import com.ruoyi.common.utils.SecurityUtils; import com.ruoyi.common.utils.poi.ExcelUtil; import com.ruoyi.framework.web.domain.R; import com.ruoyi.procurementrecord.utils.StockUtils; import com.ruoyi.sales.mapper.SalesLedgerProductMapper; import com.ruoyi.sales.pojo.SalesLedgerProduct; import com.ruoyi.stock.dto.StockInRecordDto; import com.ruoyi.stock.dto.StockInventoryDto; import com.ruoyi.stock.dto.StockOutRecordDto; @@ -30,6 +34,8 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; /** * <p> @@ -46,7 +52,8 @@ private StockInventoryMapper stockInventoryMapper; private StockInRecordService stockInRecordService; private StockOutRecordService stockOutRecordService; private SalesLedgerProductMapper salesLedgerProductMapper; private StockUtils stockUtils; @Override public IPage<StockInventoryDto> pagestockInventory(Page page, StockInventoryDto stockInventoryDto) { return stockInventoryMapper.pagestockInventory(page, stockInventoryDto); @@ -102,20 +109,28 @@ } @Override public Boolean importStockInventory(MultipartFile file) { public R importStockInventory(MultipartFile file) { try { final StringBuffer[] errorMsg = {new StringBuffer()}; //查询所有的产品 List<SalesLedgerProduct> salesLedgerProducts =salesLedgerProductMapper.selectProduct(); ExcelUtil<StockInventoryExportData> util = new ExcelUtil<StockInventoryExportData>(StockInventoryExportData.class); List<StockInventoryExportData> list = util.importExcel(file.getInputStream()); ArrayList<StockInventory> stockInventories = new ArrayList<>(); list.stream().forEach(dto -> { // TODO: 2026/1/21 添加入库记录 salesLedgerProducts.stream().forEach(item->{ if (item.getProductCategory().equals(dto.getProductName())&&item.getSpecificationModel().equals(dto.getModel())) { //更新库存 stockUtils.addStock(item.getId(),dto.getQualitity(), StockQualifiedRecordTypeEnum.CUSTOMIZATION_STOCK_IN.getCode(),0L); }else { errorMsg[0] = errorMsg[0].append("产品名称:"+dto.getProductName()+"规格:"+dto.getModel()+"不存在").append("\n"); } }); }); this.saveOrUpdateBatch(stockInventories); return true; return R.ok(errorMsg[0]); }catch (Exception e){ e.printStackTrace(); } return false; return R.fail(); } } src/main/resources/mapper/sales/SalesLedgerProductMapper.xml
@@ -8,10 +8,15 @@ SELECT T1.*, t3.shipping_car_number, t3.shipping_date t3.shipping_date, CASE WHEN t2.qualitity > T1.quantity THEN 1 ELSE 0 END as has_sufficient_stock FROM sales_ledger_product T1 left join shipping_info t3 on T1.id = t3.sales_ledger_product_id LEFT JOIN stock_inventory t2 ON T1.product_model_id = t2.product_model_id LEFT JOIN shipping_info t3 ON T1.id = t3.sales_ledger_product_id <where> 1=1 <if test="salesLedgerProduct.salesLedgerId != null and salesLedgerProduct.salesLedgerId != '' "> @@ -147,4 +152,12 @@ WHERE sl.id = #{salesLedegerId}) A group by a.model, a.product_name, a.unit </select> <select id="selectProduct" resultType="com.ruoyi.sales.pojo.SalesLedgerProduct"> select p.product_name as product_category, pm.model as specification_model, pm.id from product_model pm left join product p on pm.product_id = p.id </select> </mapper>