From 61a7d9eb8c0bb672fdd3a0da2b7f48dc8cfef389 Mon Sep 17 00:00:00 2001
From: wanshenmean <cathay_xy@163.com>
Date: 星期二, 31 三月 2026 10:48:39 +0800
Subject: [PATCH] Merge branch 'zheng'
---
Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs | 77 +++++++++++++++++++++++++++-----------
1 files changed, 55 insertions(+), 22 deletions(-)
diff --git a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
index 71f1e9b..81f3390 100644
--- a/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
+++ b/Code/WMS/WIDESEA_WMSServer/WIDESEA_StockService/StockInfoService.cs
@@ -2,6 +2,7 @@
using WIDESEA_Core.BaseRepository;
using WIDESEA_Core.BaseServices;
using WIDESEA_DTO.Stock;
+using WIDESEA_IBasicService;
using WIDESEA_IStockService;
using WIDESEA_Model.Models;
@@ -18,11 +19,23 @@
public IRepository<Dt_StockInfo> Repository => BaseDal;
/// <summary>
+ /// 璐т綅淇℃伅鏈嶅姟鎺ュ彛锛堢敤浜庤幏鍙栦粨搴撹揣浣嶄俊鎭級
+ /// </summary>
+ private readonly ILocationInfoService _locationInfoService;
+
+ /// <summary>
+ /// 浠撳簱淇℃伅鏈嶅姟鎺ュ彛锛堢敤浜庤幏鍙栦粨搴撳熀鏈俊鎭級
+ /// </summary>
+ private readonly IWarehouseService _warehouseService;
+
+ /// <summary>
/// 鏋勯�犲嚱鏁�
/// </summary>
/// <param name="baseDal">鍩虹鏁版嵁璁块棶瀵硅薄</param>
- public StockInfoService(IRepository<Dt_StockInfo> baseDal) : base(baseDal)
+ public StockInfoService(IRepository<Dt_StockInfo> baseDal, ILocationInfoService locationInfoService, IWarehouseService warehouseService) : base(baseDal)
{
+ _locationInfoService = locationInfoService;
+ _warehouseService = warehouseService;
}
/// <summary>
@@ -88,16 +101,17 @@
public async Task<Stock3DLayoutDTO> Get3DLayoutAsync(int warehouseId)
{
// 1. 鏌ヨ浠撳簱淇℃伅
- var warehouse = await Repository.Change<Dt_Warehouse>().GetFirstAsync(x => x.Id == warehouseId);
+ var warehouse = await _warehouseService.Repository.QueryFirstAsync(x => x.WarehouseId == warehouseId);
// 2. 鏌ヨ璇ヤ粨搴撴墍鏈夎揣浣�
- var locations = await Repository.Change<Dt_LocationInfo>().GetListAsync(x => x.WarehouseId == warehouseId);
+ var locations = await _locationInfoService.Repository.QueryDataAsync(x => x.WarehouseId == warehouseId);
// 3. 鏌ヨ璇ヤ粨搴撴墍鏈夊簱瀛樹俊鎭紙鍖呭惈Details瀵艰埅灞炴�э級
- var stockInfos = await Repository.Change<Dt_StockInfo>().Includes(x => x.Details).GetListAsync(x => x.WarehouseId == warehouseId);
+ var stockInfos = await Repository.QueryDataNavAsync(x => x.WarehouseId == warehouseId && x.LocationId != 0);
// 4. 鎻愬彇鐗╂枡缂栧彿鍜屾壒娆″彿鍒楄〃锛堝幓閲嶏級
var materielCodeList = stockInfos
+ .Where(s => s.Details != null)
.SelectMany(s => s.Details)
.Select(d => d.MaterielCode)
.Where(c => !string.IsNullOrEmpty(c))
@@ -105,6 +119,7 @@
.ToList();
var batchNoList = stockInfos
+ .Where(s => s.Details != null)
.SelectMany(s => s.Details)
.Select(d => d.BatchNo)
.Where(b => !string.IsNullOrEmpty(b))
@@ -132,32 +147,50 @@
// 灏濊瘯浠庡簱瀛樺瓧鍏镐腑鑾峰彇搴撳瓨淇℃伅
if (stockDict.TryGetValue(loc.Id, out var stockInfo))
{
+ // 绌烘墭鐩樹篃鏈夊簱瀛樿褰曪紝鍙槸涓嶅寘鍚槑缁�
item.PalletCode = stockInfo.PalletCode;
- item.StockQuantity = stockInfo.Details.Sum(d => d.StockQuantity);
+ item.StockStatus = stockInfo.StockStatus; // 鐩存帴浣跨敤鍚庣搴撳瓨鐘舵��
- // 鑾峰彇绗竴涓槑缁嗙殑鐗╂枡淇℃伅锛堝鏋滃瓨鍦級
- var firstDetail = stockInfo.Details.FirstOrDefault();
- if (firstDetail != null)
+ // 鍙湁褰揇etails涓嶄负null涓旀湁鏁版嵁鏃舵墠澶勭悊搴撳瓨鏄庣粏
+ if (stockInfo.Details != null && stockInfo.Details.Any())
{
- item.MaterielCode = firstDetail.MaterielCode;
- item.MaterielName = firstDetail.MaterielName;
- item.BatchNo = firstDetail.BatchNo;
- }
+ item.StockQuantity = stockInfo.Details.Sum(d => d.StockQuantity);
- // 璁$畻搴撳瓨鐘舵��
- var ratio = item.MaxCapacity > 0 ? item.StockQuantity / item.MaxCapacity : 0;
- if (ratio >= 0.9f)
- item.StockStatus = 3; // 宸叉弧 (FULL)
- else if (ratio >= 0.1f)
- item.StockStatus = 1; // 鏈夎揣 (HAS_STOCK)
- else if (ratio > 0)
- item.StockStatus = 2; // 搴撳瓨绱у紶 (LOW_STOCK)
+ // 鑾峰彇绗竴涓槑缁嗙殑鐗╂枡淇℃伅锛堝鏋滃瓨鍦級
+ var firstDetail = stockInfo.Details.FirstOrDefault();
+ if (firstDetail != null)
+ {
+ item.MaterielCode = firstDetail.MaterielCode;
+ item.MaterielName = firstDetail.MaterielName;
+ item.BatchNo = firstDetail.BatchNo;
+ }
+
+ // 濉厖搴撳瓨鏄庣粏鍒楄〃
+ item.Details = stockInfo.Details.Select(d => new StockDetailItemDTO
+ {
+ Id = d.Id,
+ MaterielCode = d.MaterielCode,
+ MaterielName = d.MaterielName,
+ BatchNo = d.BatchNo,
+ StockQuantity = d.StockQuantity,
+ Unit = d.Unit,
+ ProductionDate = d.ProductionDate,
+ EffectiveDate = d.EffectiveDate,
+ OrderNo = d.OrderNo,
+ Status = d.Status
+ }).ToList();
+ }
else
- item.StockStatus = 0; // 鏃犺揣 (EMPTY)
+ {
+ // 绌烘墭鐩橈紙鏃犳槑缁嗭級
+ item.StockQuantity = 0;
+ item.Details = new List<StockDetailItemDTO>(); // 纭繚鏄┖鍒楄〃鑰岄潪null
+ }
}
else
{
- item.StockStatus = 0; // 鏃犺揣 (EMPTY)
+ // 鏃犲簱瀛樿褰曪紝璐т綅涓虹┖
+ item.StockStatus = 0; // 绌洪棽
item.StockQuantity = 0;
}
--
Gitblit v1.9.3