From a6bc86e9bb73b0b6631a2e912904690d833d31a5 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期二, 25 十一月 2025 10:59:17 +0800
Subject: [PATCH] 11
---
StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs | 153 +++++++++++++++++++++++++++++++++++----------------
1 files changed, 105 insertions(+), 48 deletions(-)
diff --git a/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs b/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
index d49616c..7926c7b 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
@@ -27,14 +27,13 @@
throw new Exception("姣忛〉鏉℃暟蹇呴』涓�10銆�20鎴�50");
}
- // 1. 鏌ヨXB_RACKING_TASK_SYXT_LOG涓墍鏈夌殑鏉$爜骞跺幓閲�
- var distinctBarcodes = Db.Queryable<XbRackingTaskSyxtLog>()
+ // 1. 鏌ヨXB_RACKING_TASK_SYXT_LOG涓璉temBarcode鍜孭alletCode鐨勬槧灏勫叧绯�
+ var rackingTaskData = Db.Queryable<XbRackingTaskSyxtLog>()
.Where(x => !string.IsNullOrEmpty(x.ItemBarcode))
- .Select(x => x.ItemBarcode)
- .Distinct()
+ .Select(x => new { x.ItemBarcode, x.PalletCode })
.ToList();
- if (distinctBarcodes == null || !distinctBarcodes.Any())
+ if (rackingTaskData == null || !rackingTaskData.Any())
{
return new PagedResult<ReturnableStockDto>
{
@@ -49,6 +48,9 @@
};
}
+ // 1.1 鎻愬彇鍘婚噸鍚庣殑鏉$爜鍒楄〃鐢ㄤ簬鏌ヨ
+ var distinctBarcodes = rackingTaskData.Select(x => x.ItemBarcode).Distinct().ToList();
+
// 2. 鏋勫缓鏌ヨ鏉′欢
var query = Db.Queryable<MesInvItemStocks>()
.LeftJoin<MesItems>((stock, item) => stock.ItemId == item.Id)
@@ -56,7 +58,7 @@
.LeftJoin<Organize>((stock, item, depot, org) => item.UseOrg == org.Id.ToString())
.LeftJoin<MesUnit>((stock, item, depot, org, unit) => item.ItemUnit == unit.Id.ToString())
.Where((stock, item, depot, org, unit) =>
- distinctBarcodes.Contains(stock.ItemBarcode) &&
+ (distinctBarcodes.Contains(stock.ItemBarcode) || distinctBarcodes.Contains(stock.StackCode) ) &&
stock.Quantity > 0);
// 3. 搴旂敤鎼滅储鏉′欢
@@ -75,11 +77,6 @@
}
// 妯$硦鍖归厤鏉′欢
- if (!string.IsNullOrEmpty(conditions.StackCode))
- {
- query = query.Where((stock, item, depot, org, unit) =>
- stock.StackCode != null && stock.StackCode.Contains(conditions.StackCode));
- }
if (!string.IsNullOrEmpty(conditions.DepotName))
{
@@ -153,20 +150,12 @@
}
}
- // 4. 鏌ヨ鎬昏褰曟暟
- var totalRecords = query.Count();
-
- // 5. 璁$畻鍒嗛〉鍙傛暟
- var totalPages = (int)Math.Ceiling((double)totalRecords / searchDto.PageSize);
- var skip = (searchDto.PageIndex - 1) * searchDto.PageSize;
-
- // 6. 鏌ヨ褰撳墠椤垫暟鎹�(鍏堟煡鍑轰腑闂存暟鎹�)
+ // 4. 鏌ヨ鎵�鏈夌鍚堟潯浠剁殑鏁版嵁锛堜笉鍒嗛〉锛�
var queryResult = query
.OrderByDescending((stock, item, depot, org, unit) => stock.IndepDate)
.Select((stock, item, depot, org, unit) => new
{
stock.IqcStatus,
- stock.StackCode,
DepotCode = stock.DepotsCode,
depot.DepotName,
stock.DepotSectionsCode,
@@ -179,47 +168,115 @@
stock.IndepDate,
OrgCode = org.Fnumber,
OrgName = org.Fname,
- stock.ItemBarcode
+ stock.ItemBarcode,
+ StockStackCode = stock.StackCode
})
- .Skip(skip)
- .Take(searchDto.PageSize)
.ToList();
- // 7. 鍦ㄥ唴瀛樹腑杞崲涓篋TO
- var dataList = queryResult.Select(x => new ReturnableStockDto
+ // 5. 鍦ㄥ唴瀛樹腑杞崲涓篋TO锛屽叧鑱擯alletCode骞惰祴鍊糏temBarcode锛堜紭鍏堜娇鐢ㄧ鏉$爜StockStackCode锛�
+ var tempDataList = queryResult.Select(x =>
{
- IqcStatus = x.IqcStatus == "宸叉" ? "1" : "0",
- ItemType = x.DepotName == "鍘熸潗鏂欎粨" ? "0" : "1",
- StackCode = x.StackCode,
- DepotCode = x.DepotCode,
- DepotName = x.DepotName,
- DepotSectionsCode = x.DepotSectionsCode,
- ItemNo = x.ItemNo,
- ItemName = x.ItemName,
- ItemModel = x.ItemModel,
- Quantity = x.Quantity,
- ItemUnit = x.ItemUnit,
- ItemUnitName = x.ItemUnitName,
- IndepDate = x.IndepDate,
- OrgCode = x.OrgCode,
- OrgName = x.OrgName,
- ItemBarcode = x.ItemBarcode
+ // 浼樺厛浣跨敤StockStackCode锛屽惁鍒欎娇鐢↖temBarcode鍘绘煡鎵綪alletCode
+ var barcodeToMatch = !string.IsNullOrEmpty(x.StockStackCode) ? x.StockStackCode : x.ItemBarcode;
+ var palletCode = rackingTaskData
+ .Where(r => r.ItemBarcode == barcodeToMatch)
+ .Select(r => r.PalletCode)
+ .FirstOrDefault();
+
+ return new
+ {
+ IqcStatus = x.IqcStatus == "宸叉" ? "1" : "0",
+ ItemType = x.DepotName == "鍘熸潗鏂欎粨" ? "0" : "1",
+ StackCode = palletCode, // 浣跨敤PalletCode浣滀负姣嶆墭鐩樼紪鍙�
+ x.DepotCode,
+ x.DepotName,
+ x.DepotSectionsCode,
+ x.ItemNo,
+ x.ItemName,
+ x.ItemModel,
+ x.Quantity,
+ x.ItemUnit,
+ x.ItemUnitName,
+ x.IndepDate,
+ x.OrgCode,
+ x.OrgName,
+ ItemBarcode = barcodeToMatch
+ };
}).ToList();
- // 8. 搴旂敤ItemType绛涢��(鍦ㄥ唴瀛樹腑杩囨护)
+ // 5.1 搴旂敤IqcStatus鎼滅储鏉′欢锛堝湪鍐呭瓨涓繃婊わ級
+ if (conditions != null && !string.IsNullOrEmpty(conditions.IqcStatus))
+ {
+ tempDataList = tempDataList
+ .Where(x => x.IqcStatus == conditions.IqcStatus)
+ .ToList();
+ }
+
+ // 5.2 搴旂敤StackCode鎼滅储鏉′欢锛堝湪鍐呭瓨涓繃婊alletCode锛�
+ if (conditions != null && !string.IsNullOrEmpty(conditions.StackCode))
+ {
+ tempDataList = tempDataList
+ .Where(x => x.StackCode != null && x.StackCode.Contains(conditions.StackCode))
+ .ToList();
+ }
+
+ // 5.3 鍒嗙粍骞跺悎璁uantity
+ var dataList = tempDataList
+ .GroupBy(x => new
+ {
+ x.IqcStatus,
+ x.ItemType,
+ x.StackCode,
+ x.DepotCode,
+ x.DepotName,
+ x.DepotSectionsCode,
+ x.ItemNo,
+ x.ItemName,
+ x.ItemModel,
+ x.ItemUnit,
+ x.ItemUnitName,
+ x.OrgCode,
+ x.OrgName,
+ x.ItemBarcode
+ })
+ .Select(g => new ReturnableStockDto
+ {
+ IqcStatus = g.Key.IqcStatus,
+ ItemType = g.Key.ItemType,
+ StackCode = g.Key.StackCode,
+ DepotCode = g.Key.DepotCode,
+ DepotName = g.Key.DepotName,
+ DepotSectionsCode = g.Key.DepotSectionsCode,
+ ItemNo = g.Key.ItemNo,
+ ItemName = g.Key.ItemName,
+ ItemModel = g.Key.ItemModel,
+ Quantity = g.Sum(x => x.Quantity),
+ ItemUnit = g.Key.ItemUnit,
+ ItemUnitName = g.Key.ItemUnitName,
+ IndepDate = g.Max(x => x.IndepDate),
+ OrgCode = g.Key.OrgCode,
+ OrgName = g.Key.OrgName,
+ ItemBarcode = g.Key.ItemBarcode
+ }).ToList();
+
+ // 6. 搴旂敤ItemType绛涢��(鍦ㄥ唴瀛樹腑杩囨护)
if (conditions?.ItemType != null)
{
dataList = dataList.Where(x => x.ItemType == conditions.ItemType).ToList();
- // 閲嶆柊璁$畻鍒嗛〉淇℃伅
- totalRecords = dataList.Count;
- totalPages = (int)Math.Ceiling((double)totalRecords / searchDto.PageSize);
- dataList = dataList.Skip(skip).Take(searchDto.PageSize).ToList();
}
+
+ // 7. 璁$畻鎬昏褰曟暟鍜屽垎椤靛弬鏁帮紙鍩轰簬鏈�缁堢粨鏋滐級
+ var totalRecords = dataList.Count;
+ var totalPages = (int)Math.Ceiling((double)totalRecords / searchDto.PageSize);
+ var skip = (searchDto.PageIndex - 1) * searchDto.PageSize;
+
+ // 8. 瀵规渶缁堢粨鏋滆繘琛屽垎椤�
+ var pagedDataList = dataList.Skip(skip).Take(searchDto.PageSize).ToList();
// 9. 杩斿洖鍒嗛〉缁撴灉
return new PagedResult<ReturnableStockDto>
{
- TbBillList = dataList,
+ TbBillList = pagedDataList,
Pagination = new PaginationInfo
{
CurrentPage = searchDto.PageIndex,
@@ -339,7 +396,7 @@
.LeftJoin<MesItems>((stock, item) =>
stock.ItemId == item.Id)
.Where((stock, item) =>
- stock.ItemBarcode == barcode && stock.Quantity > 0)
+ (stock.ItemBarcode == barcode || stock.StackCode == barcode) && stock.Quantity > 0)
.GroupBy((stock, item) =>
new { stock.ItemId, stock.LotNo })
.Select((stock, item) => new
--
Gitblit v1.9.3