Commit 03b421a8621d92ed4bf603181b34abbc0411c0d5
1 parent
a693d31e
✨ feat(stock): 添加虚拟仓过滤功能
新增虚拟仓过滤模式,支持排除虚拟仓和仅查看虚拟仓的选项。更新相关请求对象和数据查询逻辑,以便后端处理虚拟仓的过滤需求。
Showing
4 changed files
with
137 additions
and
0 deletions
yudao-module-mes/src/main/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImpl.java
| ... | ... | @@ -92,6 +92,7 @@ public class MesWmMaterialStockServiceImpl implements MesWmMaterialStockService |
| 92 | 92 | MesWmWarehouseDO virtualWarehouse = warehouseService.getWarehouseByCode( |
| 93 | 93 | MesWmWarehouseDO.WIP_VIRTUAL_WAREHOUSE); |
| 94 | 94 | Assert.notNull(virtualWarehouse, "虚拟仓库(WIP_VIRTUAL_WAREHOUSE)不存在"); |
| 95 | + virtualWarehouseId = virtualWarehouse.getId(); | |
| 95 | 96 | } |
| 96 | 97 | |
| 97 | 98 | // 2. 分页查询 | ... | ... |
yudao-module-mes/src/test/java/cn/iocoder/yudao/module/mes/service/wm/materialstock/MesWmMaterialStockServiceImplTest.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.mes.service.wm.materialstock; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; | |
| 5 | +import cn.iocoder.yudao.module.mes.controller.admin.wm.materialstock.vo.MesWmMaterialStockPageReqVO; | |
| 6 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.materialstock.MesWmMaterialStockDO; | |
| 7 | +import cn.iocoder.yudao.module.mes.dal.dataobject.wm.warehouse.MesWmWarehouseDO; | |
| 8 | +import cn.iocoder.yudao.module.mes.dal.mysql.wm.materialstock.MesWmMaterialStockMapper; | |
| 9 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemService; | |
| 10 | +import cn.iocoder.yudao.module.mes.service.md.item.MesMdItemTypeService; | |
| 11 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseAreaService; | |
| 12 | +import cn.iocoder.yudao.module.mes.service.wm.warehouse.MesWmWarehouseService; | |
| 13 | +import jakarta.annotation.Resource; | |
| 14 | +import org.junit.jupiter.api.Test; | |
| 15 | +import org.springframework.context.annotation.Import; | |
| 16 | +import org.springframework.test.context.bean.override.mockito.MockitoBean; | |
| 17 | + | |
| 18 | +import java.math.BigDecimal; | |
| 19 | +import java.time.LocalDateTime; | |
| 20 | +import java.util.function.Consumer; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; | |
| 23 | +import static org.junit.jupiter.api.Assertions.assertEquals; | |
| 24 | +import static org.mockito.Mockito.when; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * {@link MesWmMaterialStockServiceImpl} 的单元测试 | |
| 28 | + * | |
| 29 | + * @author 芋道源码 | |
| 30 | + */ | |
| 31 | +@Import(MesWmMaterialStockServiceImpl.class) | |
| 32 | +public class MesWmMaterialStockServiceImplTest extends BaseDbUnitTest { | |
| 33 | + | |
| 34 | + @Resource | |
| 35 | + private MesWmMaterialStockServiceImpl materialStockService; | |
| 36 | + | |
| 37 | + @Resource | |
| 38 | + private MesWmMaterialStockMapper materialStockMapper; | |
| 39 | + | |
| 40 | + @MockitoBean | |
| 41 | + private MesMdItemService itemService; | |
| 42 | + @MockitoBean | |
| 43 | + private MesMdItemTypeService itemTypeService; | |
| 44 | + @MockitoBean | |
| 45 | + private MesWmWarehouseAreaService areaService; | |
| 46 | + @MockitoBean | |
| 47 | + private MesWmWarehouseService warehouseService; | |
| 48 | + | |
| 49 | + @Test | |
| 50 | + public void testGetMaterialStockPage_virtualFilterOnly() { | |
| 51 | + // 准备数据:虚拟仓库存 + 普通仓库存 | |
| 52 | + Long virtualWarehouseId = 100L; | |
| 53 | + Long normalWarehouseId = 200L; | |
| 54 | + MesWmMaterialStockDO virtualStock = createMaterialStockPojo(o -> o.setWarehouseId(virtualWarehouseId)); | |
| 55 | + MesWmMaterialStockDO normalStock = createMaterialStockPojo(o -> o.setWarehouseId(normalWarehouseId)); | |
| 56 | + materialStockMapper.insert(virtualStock); | |
| 57 | + materialStockMapper.insert(normalStock); | |
| 58 | + mockVirtualWarehouse(virtualWarehouseId); | |
| 59 | + | |
| 60 | + // 调用:只看虚拟仓 | |
| 61 | + MesWmMaterialStockPageReqVO reqVO = new MesWmMaterialStockPageReqVO(); | |
| 62 | + reqVO.setVirtualFilter(MesWmMaterialStockPageReqVO.VIRTUAL_FILTER_ONLY); | |
| 63 | + PageResult<MesWmMaterialStockDO> result = materialStockService.getMaterialStockPage(reqVO); | |
| 64 | + | |
| 65 | + // 断言:只返回虚拟仓库存,且 total 与列表一致 | |
| 66 | + assertEquals(1, result.getTotal()); | |
| 67 | + assertEquals(1, result.getList().size()); | |
| 68 | + assertEquals(virtualStock.getId(), result.getList().get(0).getId()); | |
| 69 | + } | |
| 70 | + | |
| 71 | + @Test | |
| 72 | + public void testGetMaterialStockPage_virtualFilterExclude() { | |
| 73 | + // 准备数据:虚拟仓库存 + 普通仓库存 | |
| 74 | + Long virtualWarehouseId = 100L; | |
| 75 | + Long normalWarehouseId = 200L; | |
| 76 | + MesWmMaterialStockDO virtualStock = createMaterialStockPojo(o -> o.setWarehouseId(virtualWarehouseId)); | |
| 77 | + MesWmMaterialStockDO normalStock = createMaterialStockPojo(o -> o.setWarehouseId(normalWarehouseId)); | |
| 78 | + materialStockMapper.insert(virtualStock); | |
| 79 | + materialStockMapper.insert(normalStock); | |
| 80 | + mockVirtualWarehouse(virtualWarehouseId); | |
| 81 | + | |
| 82 | + // 调用:排除虚拟仓 | |
| 83 | + MesWmMaterialStockPageReqVO reqVO = new MesWmMaterialStockPageReqVO(); | |
| 84 | + reqVO.setVirtualFilter(MesWmMaterialStockPageReqVO.VIRTUAL_FILTER_EXCLUDE); | |
| 85 | + PageResult<MesWmMaterialStockDO> result = materialStockService.getMaterialStockPage(reqVO); | |
| 86 | + | |
| 87 | + // 断言:只返回普通仓库存,且 total 与列表一致 | |
| 88 | + assertEquals(1, result.getTotal()); | |
| 89 | + assertEquals(1, result.getList().size()); | |
| 90 | + assertEquals(normalStock.getId(), result.getList().get(0).getId()); | |
| 91 | + } | |
| 92 | + | |
| 93 | + private MesWmMaterialStockDO createMaterialStockPojo(Consumer<MesWmMaterialStockDO> consumer) { | |
| 94 | + return randomPojo(MesWmMaterialStockDO.class, o -> { | |
| 95 | + o.setQuantity(new BigDecimal("10.00")); | |
| 96 | + o.setReceiptTime(LocalDateTime.of(2026, 1, 1, 0, 0)); | |
| 97 | + o.setFrozen(false); | |
| 98 | + o.setDeleted(false); | |
| 99 | + consumer.accept(o); | |
| 100 | + }); | |
| 101 | + } | |
| 102 | + | |
| 103 | + private void mockVirtualWarehouse(Long virtualWarehouseId) { | |
| 104 | + MesWmWarehouseDO virtualWarehouse = new MesWmWarehouseDO(); | |
| 105 | + virtualWarehouse.setId(virtualWarehouseId); | |
| 106 | + when(warehouseService.getWarehouseByCode(MesWmWarehouseDO.WIP_VIRTUAL_WAREHOUSE)) | |
| 107 | + .thenReturn(virtualWarehouse); | |
| 108 | + } | |
| 109 | + | |
| 110 | +} | ... | ... |
yudao-module-mes/src/test/resources/sql/clean.sql
| ... | ... | @@ -13,5 +13,6 @@ DELETE FROM "mes_wm_item_receipt"; |
| 13 | 13 | DELETE FROM "mes_wm_item_receipt_line"; |
| 14 | 14 | DELETE FROM "mes_wm_item_receipt_detail"; |
| 15 | 15 | DELETE FROM "mes_wm_batch"; |
| 16 | +DELETE FROM "mes_wm_material_stock"; | |
| 16 | 17 | DELETE FROM "mes_pro_task"; |
| 17 | 18 | DELETE FROM "mes_pro_route_process"; | ... | ... |
yudao-module-mes/src/test/resources/sql/create_tables.sql
| ... | ... | @@ -620,6 +620,31 @@ CREATE TABLE IF NOT EXISTS "mes_wm_batch" ( |
| 620 | 620 | ); |
| 621 | 621 | |
| 622 | 622 | -- ---------------------------- |
| 623 | +-- MES 库存台账 | |
| 624 | +-- ---------------------------- | |
| 625 | +CREATE TABLE IF NOT EXISTS "mes_wm_material_stock" ( | |
| 626 | + "id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY, | |
| 627 | + "quantity" decimal(14,2) DEFAULT NULL, | |
| 628 | + "receipt_time" timestamp DEFAULT NULL, | |
| 629 | + "vendor_id" bigint DEFAULT NULL, | |
| 630 | + "item_type_id" bigint DEFAULT NULL, | |
| 631 | + "item_id" bigint DEFAULT NULL, | |
| 632 | + "batch_id" bigint DEFAULT NULL, | |
| 633 | + "batch_code" varchar(255) DEFAULT NULL, | |
| 634 | + "warehouse_id" bigint DEFAULT NULL, | |
| 635 | + "location_id" bigint DEFAULT NULL, | |
| 636 | + "area_id" bigint DEFAULT NULL, | |
| 637 | + "frozen" bit DEFAULT FALSE, | |
| 638 | + "creator" varchar(64) DEFAULT '', | |
| 639 | + "create_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 640 | + "updater" varchar(64) DEFAULT '', | |
| 641 | + "update_time" timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, | |
| 642 | + "deleted" bit NOT NULL DEFAULT FALSE, | |
| 643 | + "tenant_id" bigint NOT NULL DEFAULT 0, | |
| 644 | + PRIMARY KEY ("id") | |
| 645 | +); | |
| 646 | + | |
| 647 | +-- ---------------------------- | |
| 623 | 648 | -- MES 生产任务 |
| 624 | 649 | -- ---------------------------- |
| 625 | 650 | CREATE TABLE IF NOT EXISTS "mes_pro_task" ( | ... | ... |