feat(inventory): 添加库存数量查询接口
- 新增 MaterialInventoryVO 视图对象用于返回库存数量信息 - 实现按工厂分组汇总库存数量的功能 - 添加 getTotalNum 和 getItems 方法返回总计和明细数据 - 在 InventoryController 中新增 getCount 接口提供库存查询服务 - 使用 Stream API 进行数据分组和数量累加计算 - 集成 BigDecimal 类型确保数值计算精度
This commit is contained in:
parent
be458e2ac7
commit
92c85d9481
|
|
@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollectionUtil;
|
||||||
import cn.hutool.core.util.IdUtil;
|
import cn.hutool.core.util.IdUtil;
|
||||||
import cn.hutool.core.util.NumberUtil;
|
import cn.hutool.core.util.NumberUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
import com.nflg.wms.admin.pojo.vo.MaterialInventoryVO;
|
||||||
import com.nflg.wms.admin.repository.InventoryCheckTaskScanRecordResitory;
|
import com.nflg.wms.admin.repository.InventoryCheckTaskScanRecordResitory;
|
||||||
import com.nflg.wms.admin.service.QmsService;
|
import com.nflg.wms.admin.service.QmsService;
|
||||||
import com.nflg.wms.common.constant.STATE;
|
import com.nflg.wms.common.constant.STATE;
|
||||||
|
|
@ -344,4 +345,39 @@ public class InventoryController extends BaseController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取库存数量
|
||||||
|
* @param materialNo 物料编号
|
||||||
|
*/
|
||||||
|
@GetMapping("getCount")
|
||||||
|
public ApiResult<MaterialInventoryVO> getCount(@RequestParam String materialNo) {
|
||||||
|
List<WmsInventory> inventories = inventoryService.lambdaQuery()
|
||||||
|
.eq(WmsInventory::getMaterialNo, materialNo)
|
||||||
|
.list();
|
||||||
|
|
||||||
|
// 按工厂分组汇总数量
|
||||||
|
List<MaterialInventoryVO.Item> items = inventories.stream()
|
||||||
|
.collect(Collectors.groupingBy(
|
||||||
|
WmsInventory::getFactoryNo,
|
||||||
|
Collectors.reducing(BigDecimal.ZERO, WmsInventory::getNum, BigDecimal::add))
|
||||||
|
)
|
||||||
|
.entrySet()
|
||||||
|
.stream()
|
||||||
|
.map(entry -> new MaterialInventoryVO.Item()
|
||||||
|
.setFactoryNo(entry.getKey())
|
||||||
|
.setNum(entry.getValue())
|
||||||
|
)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
BigDecimal totalNum = inventories.stream()
|
||||||
|
.map(WmsInventory::getNum)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
|
|
||||||
|
MaterialInventoryVO vo = new MaterialInventoryVO()
|
||||||
|
.setTotalNum(totalNum)
|
||||||
|
.setItems(items);
|
||||||
|
return ApiResult.success(vo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
package com.nflg.wms.admin.pojo.vo;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import lombok.experimental.Accessors;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 物料库存数量视图对象
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public class MaterialInventoryVO {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 库存总数量(所有库存地点合计)
|
||||||
|
*/
|
||||||
|
private BigDecimal totalNum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 各库存地点的数量明细
|
||||||
|
*/
|
||||||
|
private List<Item> items;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Accessors(chain = true)
|
||||||
|
public static class Item {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 工厂编号
|
||||||
|
*/
|
||||||
|
private String factoryNo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 数量
|
||||||
|
*/
|
||||||
|
private BigDecimal num;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue