|
@@ -1532,38 +1532,62 @@ public class SalesForecastSummaryController {
|
|
|
BladeUser bladeUser) {
|
|
BladeUser bladeUser) {
|
|
|
|
|
|
|
|
QueryWrapper<ViewWhqohSel> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<ViewWhqohSel> queryWrapper = new QueryWrapper<>();
|
|
|
- Page<ViewWhqohSel> page = new Page<>();
|
|
|
|
|
|
|
+ // 补充:设置分页参数(原代码未设置page的current和size,会导致分页失效)
|
|
|
|
|
+ Page<ViewWhqohSel> page = new Page<>(query.getCurrent(), query.getSize());
|
|
|
|
|
|
|
|
- // 3. 查询库存视图数据
|
|
|
|
|
|
|
+ // 1. 查询库存视图数据
|
|
|
IPage<ViewWhqohSel> whqohPage = whqohSelService.page(page, queryWrapper);
|
|
IPage<ViewWhqohSel> whqohPage = whqohSelService.page(page, queryWrapper);
|
|
|
|
|
|
|
|
- // 4. 手动映射为PjpfStockDesc分页数据
|
|
|
|
|
|
|
+ // 2. 手动映射并去重:以goodsId + storageId为维度去重,重复则合并库存数量
|
|
|
|
|
+ Map<String, PjpfStockDesc> stockMap = whqohPage.getRecords().stream()
|
|
|
|
|
+ .map(whqoh -> {
|
|
|
|
|
+ PjpfStockDesc stock = new PjpfStockDesc();
|
|
|
|
|
+ // 字段映射(根据业务逻辑调整)
|
|
|
|
|
+ stock.setId(whqoh.getItemId()); // 商品ID作为主键
|
|
|
|
|
+ stock.setTenantId(whqoh.getOrgId().toString()); // 组织ID作为租户ID
|
|
|
|
|
+ stock.setStorageId(whqoh.getWarehouseId()); // 仓库ID
|
|
|
|
|
+ stock.setStorageName(whqoh.getWarehouseName()); // 仓库名称
|
|
|
|
|
+ stock.setGoodsId(whqoh.getItemId()); // 商品ID
|
|
|
|
|
+ stock.setCode(whqoh.getItemCode()); // 物料编号(商品编码)
|
|
|
|
|
+ stock.setCname(whqoh.getItemName()); // 商品名称
|
|
|
|
|
+ stock.setTypeNo(whqoh.getItemPecs()); // 规格型号(映射自Item_PECS)
|
|
|
|
|
+ stock.setProductDescription(whqoh.getItemDescription()); // 商品描述
|
|
|
|
|
+ stock.setSalesCompanyId(whqoh.getOrgId()); // 所属公司ID(组织ID)
|
|
|
|
|
+ stock.setSalesCompanyName(whqoh.getOrgName()); // 所属公司名称(组织名称)
|
|
|
|
|
+ stock.setBalanceQuantity(whqoh.getStoreQty()); // 结余数量(总)
|
|
|
|
|
+ stock.setStoreInventory(whqoh.getStoreQty()); // 商城库存(假设与总库存一致)
|
|
|
|
|
+ // 其他需要的字段继续映射...
|
|
|
|
|
+ return stock;
|
|
|
|
|
+ })
|
|
|
|
|
+ // 核心去重逻辑:key为goodsId+storageId,重复时合并库存数量
|
|
|
|
|
+ .collect(Collectors.toMap(
|
|
|
|
|
+ // 构建去重key:商品ID + 仓库ID(确保唯一)
|
|
|
|
|
+ stock -> stock.getGoodsId() + "_" + stock.getStorageId(),
|
|
|
|
|
+ // value为当前库存对象
|
|
|
|
|
+ stock -> stock,
|
|
|
|
|
+ // 重复时的合并规则:将重复记录的库存数量累加
|
|
|
|
|
+ (existingStock, newStock) -> {
|
|
|
|
|
+ // 合并结余数量
|
|
|
|
|
+ existingStock.setBalanceQuantity(
|
|
|
|
|
+ existingStock.getBalanceQuantity().add(newStock.getBalanceQuantity())
|
|
|
|
|
+ );
|
|
|
|
|
+ // 合并商城库存
|
|
|
|
|
+ existingStock.setStoreInventory(
|
|
|
|
|
+ existingStock.getStoreInventory().add(newStock.getStoreInventory())
|
|
|
|
|
+ );
|
|
|
|
|
+ // 其他需要合并的字段可在此补充(比如库存金额等)
|
|
|
|
|
+ return existingStock;
|
|
|
|
|
+ }
|
|
|
|
|
+ ));
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 转换为列表并构建分页对象
|
|
|
|
|
+ List<PjpfStockDesc> stockList = new ArrayList<>(stockMap.values());
|
|
|
IPage<PjpfStockDesc> stockPage = new Page<>(
|
|
IPage<PjpfStockDesc> stockPage = new Page<>(
|
|
|
whqohPage.getCurrent(),
|
|
whqohPage.getCurrent(),
|
|
|
whqohPage.getSize(),
|
|
whqohPage.getSize(),
|
|
|
- whqohPage.getTotal()
|
|
|
|
|
|
|
+ // 注意:如果需要分页总数为去重后的数量,可改为stockList.size();如果保留原总数,用whqohPage.getTotal()
|
|
|
|
|
+ stockList.size()
|
|
|
);
|
|
);
|
|
|
-
|
|
|
|
|
- List<PjpfStockDesc> stockList = whqohPage.getRecords().stream().map(whqoh -> {
|
|
|
|
|
- PjpfStockDesc stock = new PjpfStockDesc();
|
|
|
|
|
- // 字段映射(根据业务逻辑调整)
|
|
|
|
|
- stock.setId(whqoh.getItemId()); // 商品ID作为主键
|
|
|
|
|
- stock.setTenantId(whqoh.getOrgId().toString()); // 组织ID作为租户ID
|
|
|
|
|
- stock.setStorageId(whqoh.getWarehouseId()); // 仓库ID
|
|
|
|
|
- stock.setStorageName(whqoh.getWarehouseName()); // 仓库名称
|
|
|
|
|
- stock.setGoodsId(whqoh.getItemId()); // 商品ID
|
|
|
|
|
- stock.setCode(whqoh.getItemCode()); // 物料编号(商品编码)
|
|
|
|
|
- stock.setCname(whqoh.getItemName()); // 商品名称
|
|
|
|
|
- stock.setTypeNo(whqoh.getItemPecs()); // 规格型号(映射自Item_PECS)
|
|
|
|
|
- stock.setProductDescription(whqoh.getItemDescription()); // 商品描述
|
|
|
|
|
- stock.setSalesCompanyId(whqoh.getOrgId()); // 所属公司ID(组织ID)
|
|
|
|
|
- stock.setSalesCompanyName(whqoh.getOrgName()); // 所属公司名称(组织名称)
|
|
|
|
|
- stock.setBalanceQuantity(whqoh.getStoreQty()); // 结余数量(总)
|
|
|
|
|
- stock.setStoreInventory(whqoh.getStoreQty()); // 商城库存(假设与总库存一致)
|
|
|
|
|
- // 其他需要的字段继续映射...
|
|
|
|
|
- return stock;
|
|
|
|
|
- }).collect(Collectors.toList());
|
|
|
|
|
-
|
|
|
|
|
stockPage.setRecords(stockList);
|
|
stockPage.setRecords(stockList);
|
|
|
|
|
|
|
|
// 转换VO并返回
|
|
// 转换VO并返回
|