feat(mat): 添加物料库存信息查询功能
- 新增 MatMaterialWithInventoryVo 视图对象用于封装物料及库存信息 - 在 IMatMaterialService 中添加 queryListWithInventory 和 queryPageListWithInventory 方法 - 实现物料列表接口返回包含库存信息的数据结构 - 更新导出功能以支持带库存信息的物料数据导出 - 优化 MatPurchaseServiceImpl 中的 Bean 属性复制逻辑 - 重构采购分页查询结果处理方式
This commit is contained in:
@@ -21,6 +21,7 @@ import com.gear.common.core.validate.QueryGroup;
|
||||
import com.gear.common.enums.BusinessType;
|
||||
import com.gear.common.utils.poi.ExcelUtil;
|
||||
import com.gear.mat.domain.vo.MatMaterialVo;
|
||||
import com.gear.mat.domain.vo.MatMaterialWithInventoryVo;
|
||||
import com.gear.mat.domain.bo.MatMaterialBo;
|
||||
import com.gear.mat.service.IMatMaterialService;
|
||||
import com.gear.common.core.page.TableDataInfo;
|
||||
@@ -43,8 +44,8 @@ public class MatMaterialController extends BaseController {
|
||||
* 查询配料配件基础信息列表
|
||||
*/
|
||||
@GetMapping("/list")
|
||||
public TableDataInfo<MatMaterialVo> list(MatMaterialBo bo, PageQuery pageQuery) {
|
||||
return iMatMaterialService.queryPageList(bo, pageQuery);
|
||||
public TableDataInfo<MatMaterialWithInventoryVo> list(MatMaterialBo bo, PageQuery pageQuery) {
|
||||
return iMatMaterialService.queryPageListWithInventory(bo, pageQuery);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,8 +54,9 @@ public class MatMaterialController extends BaseController {
|
||||
@Log(title = "配料配件基础信息", businessType = BusinessType.EXPORT)
|
||||
@PostMapping("/export")
|
||||
public void export(MatMaterialBo bo, HttpServletResponse response) {
|
||||
List<MatMaterialVo> list = iMatMaterialService.queryList(bo);
|
||||
ExcelUtil.exportExcel(list, "配料配件基础信息", MatMaterialVo.class, response);
|
||||
// 使用增强的服务方法获取带库存信息的物料列表
|
||||
List<MatMaterialWithInventoryVo> list = iMatMaterialService.queryListWithInventory(bo);
|
||||
ExcelUtil.exportExcel(list, "配料配件基础信息", MatMaterialWithInventoryVo.class, response);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
package com.gear.mat.domain.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 物料信息与库存信息视图对象
|
||||
*
|
||||
* @author ruoyi
|
||||
* @date 2026-01-31
|
||||
*/
|
||||
@Data
|
||||
public class MatMaterialWithInventoryVo {
|
||||
|
||||
/**
|
||||
* 物料ID
|
||||
*/
|
||||
private Long materialId;
|
||||
|
||||
/**
|
||||
* 物料名称
|
||||
*/
|
||||
private String materialName;
|
||||
|
||||
/**
|
||||
* 规格
|
||||
*/
|
||||
private String spec;
|
||||
|
||||
/**
|
||||
* 型号
|
||||
*/
|
||||
private String model;
|
||||
|
||||
/**
|
||||
* 生产厂家
|
||||
*/
|
||||
private String factory;
|
||||
|
||||
/**
|
||||
* 单位
|
||||
*/
|
||||
private String unit;
|
||||
|
||||
/**
|
||||
* 当前库存数量
|
||||
*/
|
||||
private BigDecimal currentStock;
|
||||
|
||||
/**
|
||||
* 在途数量(未完成入库的采购数量)
|
||||
*/
|
||||
private BigDecimal inTransitNum;
|
||||
|
||||
/**
|
||||
* 计划采购总数量
|
||||
*/
|
||||
private BigDecimal planNum;
|
||||
|
||||
/**
|
||||
* 已入库数量
|
||||
*/
|
||||
private BigDecimal receivedNum;
|
||||
|
||||
public MatMaterialWithInventoryVo() {
|
||||
this.currentStock = BigDecimal.ZERO;
|
||||
this.inTransitNum = BigDecimal.ZERO;
|
||||
this.planNum = BigDecimal.ZERO;
|
||||
this.receivedNum = BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
// Copy constructor from MatMaterialVo
|
||||
public MatMaterialWithInventoryVo(MatMaterialVo material) {
|
||||
this.materialId = material.getMaterialId();
|
||||
this.materialName = material.getMaterialName();
|
||||
this.spec = material.getSpec();
|
||||
this.model = material.getModel();
|
||||
this.factory = material.getFactory();
|
||||
this.unit = material.getUnit();
|
||||
this.currentStock = material.getCurrentStock() != null ? material.getCurrentStock() : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package com.gear.mat.service;
|
||||
|
||||
import com.gear.mat.domain.MatMaterial;
|
||||
import com.gear.mat.domain.vo.MatMaterialVo;
|
||||
import com.gear.mat.domain.vo.MatMaterialWithInventoryVo;
|
||||
import com.gear.mat.domain.bo.MatMaterialBo;
|
||||
import com.gear.common.core.page.TableDataInfo;
|
||||
import com.gear.common.core.domain.PageQuery;
|
||||
@@ -32,6 +33,11 @@ public interface IMatMaterialService {
|
||||
*/
|
||||
List<MatMaterialVo> queryList(MatMaterialBo bo);
|
||||
|
||||
/**
|
||||
* 查询配料配件基础信息列表(包含库存信息)
|
||||
*/
|
||||
List<MatMaterialWithInventoryVo> queryListWithInventory(MatMaterialBo bo);
|
||||
|
||||
/**
|
||||
* 新增配料配件基础信息
|
||||
*/
|
||||
@@ -46,4 +52,9 @@ public interface IMatMaterialService {
|
||||
* 校验并批量删除配料配件基础信息信息
|
||||
*/
|
||||
Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid);
|
||||
|
||||
/**
|
||||
* 查询配料配件基础信息列表(包含库存信息)
|
||||
*/
|
||||
TableDataInfo<MatMaterialWithInventoryVo> queryPageListWithInventory(MatMaterialBo bo, PageQuery pageQuery);
|
||||
}
|
||||
|
||||
@@ -7,17 +7,21 @@ import com.gear.common.core.domain.PageQuery;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.gear.mat.domain.vo.MaterialInventoryVo;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.gear.mat.domain.bo.MatMaterialBo;
|
||||
import com.gear.mat.domain.vo.MatMaterialVo;
|
||||
import com.gear.mat.domain.vo.MatMaterialWithInventoryVo;
|
||||
import com.gear.mat.domain.MatMaterial;
|
||||
import com.gear.mat.mapper.MatMaterialMapper;
|
||||
import com.gear.mat.service.IMatMaterialService;
|
||||
import com.gear.mat.service.IMatPurchaseService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 配料配件基础信息Service业务层处理
|
||||
@@ -30,6 +34,7 @@ import java.util.Collection;
|
||||
public class MatMaterialServiceImpl implements IMatMaterialService {
|
||||
|
||||
private final MatMaterialMapper baseMapper;
|
||||
private final IMatPurchaseService matPurchaseService;
|
||||
|
||||
/**
|
||||
* 查询配料配件基础信息
|
||||
@@ -111,4 +116,60 @@ public class MatMaterialServiceImpl implements IMatMaterialService {
|
||||
}
|
||||
return baseMapper.deleteBatchIds(ids) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TableDataInfo<MatMaterialWithInventoryVo> queryPageListWithInventory(MatMaterialBo bo, PageQuery pageQuery) {
|
||||
// 先查询物料基本信息
|
||||
TableDataInfo<MatMaterialVo> materialTable = queryPageList(bo, pageQuery);
|
||||
|
||||
// 将MatMaterialVo转换为MatMaterialWithInventoryVo
|
||||
List<MatMaterialWithInventoryVo> inventoryList = materialTable.getRows().stream()
|
||||
.map(material -> {
|
||||
MatMaterialWithInventoryVo inventoryVo = new MatMaterialWithInventoryVo(material);
|
||||
|
||||
// 查询该物料的库存信息
|
||||
List<MaterialInventoryVo> materialInventoryList = matPurchaseService.queryMaterialInventory(material.getMaterialId());
|
||||
|
||||
if (!materialInventoryList.isEmpty()) {
|
||||
MaterialInventoryVo inventoryInfo = materialInventoryList.get(0);
|
||||
inventoryVo.setInTransitNum(inventoryInfo.getInTransitNum());
|
||||
inventoryVo.setPlanNum(inventoryInfo.getPlanNum());
|
||||
inventoryVo.setReceivedNum(inventoryInfo.getReceivedNum());
|
||||
}
|
||||
|
||||
return inventoryVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建返回结果
|
||||
Page<MatMaterialWithInventoryVo> resultPage = new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize(), materialTable.getTotal());
|
||||
resultPage.setRecords(inventoryList);
|
||||
|
||||
return TableDataInfo.build(resultPage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<MatMaterialWithInventoryVo> queryListWithInventory(MatMaterialBo bo) {
|
||||
// 先查询物料基本信息
|
||||
List<MatMaterialVo> materialList = queryList(bo);
|
||||
|
||||
// 将MatMaterialVo转换为MatMaterialWithInventoryVo
|
||||
return materialList.stream()
|
||||
.map(material -> {
|
||||
MatMaterialWithInventoryVo inventoryVo = new MatMaterialWithInventoryVo(material);
|
||||
|
||||
// 查询该物料的库存信息
|
||||
List<MaterialInventoryVo> materialInventoryList = matPurchaseService.queryMaterialInventory(material.getMaterialId());
|
||||
|
||||
if (!materialInventoryList.isEmpty()) {
|
||||
MaterialInventoryVo inventoryInfo = materialInventoryList.get(0);
|
||||
inventoryVo.setInTransitNum(inventoryInfo.getInTransitNum());
|
||||
inventoryVo.setPlanNum(inventoryInfo.getPlanNum());
|
||||
inventoryVo.setReceivedNum(inventoryInfo.getReceivedNum());
|
||||
}
|
||||
|
||||
return inventoryVo;
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.gear.mat.domain.vo.*;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.gear.mat.domain.bo.MatPurchaseBo;
|
||||
import com.gear.mat.domain.MatPurchase;
|
||||
@@ -55,11 +56,8 @@ public class MatPurchaseServiceImpl implements IMatPurchaseService {
|
||||
Page<MatPurchaseVo> result = baseMapper.selectVoPagePlus(pageQuery.build(), qw);
|
||||
// 添加库存信息
|
||||
List<MatPurchaseVo> inventoryList = convertToPurchaseWithInventoryVo(result.getRecords());
|
||||
|
||||
Page<MatPurchaseVo> inventoryResult = new Page<>(result.getCurrent(), result.getSize(), result.getTotal());
|
||||
inventoryResult.setRecords(inventoryList);
|
||||
|
||||
return TableDataInfo.build(inventoryResult);
|
||||
result.setRecords(inventoryList);
|
||||
return TableDataInfo.build(result);
|
||||
}
|
||||
|
||||
private QueryWrapper<MatPurchase> buildQueryWrapperPlus(MatPurchaseBo bo) {
|
||||
@@ -236,15 +234,7 @@ public class MatPurchaseServiceImpl implements IMatPurchaseService {
|
||||
MatPurchaseVo vo = new MatPurchaseVo();
|
||||
|
||||
// 复制基本采购信息
|
||||
vo.setPurchaseId(purchase.getPurchaseId());
|
||||
vo.setPurchaseNo(purchase.getPurchaseNo());
|
||||
vo.setFactory(purchase.getFactory());
|
||||
vo.setMaterialId(purchase.getMaterialId());
|
||||
vo.setPlanNum(purchase.getPlanNum());
|
||||
vo.setPurchasePrice(purchase.getPurchasePrice());
|
||||
vo.setStatus(purchase.getStatus());
|
||||
vo.setRemark(purchase.getRemark());
|
||||
|
||||
BeanUtils.copyProperties(purchase, vo);
|
||||
// 获取物料信息
|
||||
MatMaterialVo material = matMaterialService.queryById(purchase.getMaterialId());
|
||||
if (material != null) {
|
||||
|
||||
Reference in New Issue
Block a user