From fbd1dae61bb8eeccd303341ff3b5290d805a8155 Mon Sep 17 00:00:00 2001
From: tjx <t2856754968@163.com>
Date: 星期五, 19 十二月 2025 18:40:25 +0800
Subject: [PATCH] 111
---
StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs | 540 +++++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 409 insertions(+), 131 deletions(-)
diff --git a/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs b/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
index 0e10efd..ab4db63 100644
--- a/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
+++ b/StandardPda/MES.Service/service/Warehouse/MesInvItemStocksManager.cs
@@ -4,6 +4,8 @@
using SqlSugar;
using Newtonsoft.Json;
using System.Text;
+using OfficeOpenXml;
+using OfficeOpenXml.Style;
namespace MES.Service.service.Warehouse;
@@ -14,27 +16,27 @@
/// </summary>
/// <param name="searchDto">鎼滅储璇锋眰鍙傛暟</param>
/// <returns>鍒嗛〉缁撴灉</returns>
- public PagedResult<ReturnableStockDto> GetReturnableStocks(ReturnableStockSearchDto searchDto)
+ public PagedResult<ReturnableStockDto> GetReturnableStocks(
+ ReturnableStockSearchDto searchDto)
{
- // 鍙傛暟鏍¢獙
if (searchDto.PageIndex < 1)
{
throw new Exception("椤电爜蹇呴』澶т簬0");
}
- if (!new[] { 10, 20, 50 }.Contains(searchDto.PageSize))
- {
- throw new Exception("姣忛〉鏉℃暟蹇呴』涓�10銆�20鎴�50");
- }
+ // 浼樺寲鐐�1: 浣跨敤鍘熺敓SQL ROW_NUMBER()鍦ㄦ暟鎹簱绔畬鎴愬幓閲嶅拰鎺掑簭
+ var rackingTaskSql = @"
+ SELECT ITEM_BARCODE AS ItemBarcode, PALLETCODE AS PalletCode, CODE AS Code, TASKTYPE AS TaskType
+ FROM (
+ SELECT ITEM_BARCODE, PALLETCODE, CODE, TASKTYPE,
+ ROW_NUMBER() OVER (PARTITION BY ITEM_BARCODE ORDER BY ID DESC) AS RN
+ FROM XB_RACKING_TASK_SYXT_LOG
+ WHERE ITEM_BARCODE IS NOT NULL AND (CODE IS NULL OR CODE != '500')
+ ) WHERE RN = 1";
- // 1. 鏌ヨXB_RACKING_TASK_SYXT_LOG涓墍鏈夌殑鏉$爜骞跺幓閲�
- var distinctBarcodes = Db.Queryable<XbRackingTaskSyxtLog>()
- .Where(x => !string.IsNullOrEmpty(x.ItemBarcode))
- .Select(x => x.ItemBarcode)
- .Distinct()
- .ToList();
+ var rackingTaskData = Db.Ado.SqlQuery<RackingTaskDto>(rackingTaskSql);
- if (distinctBarcodes == null || !distinctBarcodes.Any())
+ if (rackingTaskData == null || !rackingTaskData.Any())
{
return new PagedResult<ReturnableStockDto>
{
@@ -49,98 +51,139 @@
};
}
- // 2. 鏋勫缓鏌ヨ鏉′欢
+ // 浼樺寲鐐�2: 杩囨护null鍊煎苟浣跨敤瀛楀吀鎻愰珮鏌ユ壘鏁堢巼
+ var validRackingData = rackingTaskData.Where(x => !string.IsNullOrEmpty(x.ItemBarcode)).ToList();
+
+ if (!validRackingData.Any())
+ {
+ return new PagedResult<ReturnableStockDto>
+ {
+ TbBillList = new List<ReturnableStockDto>(),
+ Pagination = new PaginationInfo
+ {
+ CurrentPage = searchDto.PageIndex,
+ PageSize = searchDto.PageSize,
+ TotalRecords = 0,
+ TotalPages = 0
+ }
+ };
+ }
+
+ var rackingTaskDict = validRackingData.ToDictionary(x => x.ItemBarcode);
+ var distinctBarcodes = validRackingData.Select(x => x.ItemBarcode).ToList();
+
+ // 浼樺寲鐐�3: 鏋勫缓鏌ヨ鏉′欢
var query = Db.Queryable<MesInvItemStocks>()
.LeftJoin<MesItems>((stock, item) => stock.ItemId == item.Id)
- .LeftJoin<MesDepots>((stock, item, depot) => stock.DepotsCode == depot.DepotCode)
- .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) &&
+ .LeftJoin<MesDepots>((stock, item, depot) =>
+ stock.DepotsCode == depot.DepotCode)
+ .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.StackCode)) &&
stock.Quantity > 0);
- // 3. 搴旂敤鎼滅储鏉′欢
var conditions = searchDto.Conditions;
if (conditions != null)
{
- // 绮剧‘鍖归厤鏉′欢
if (!string.IsNullOrEmpty(conditions.IqcStatus))
{
- query = query.Where((stock, item, depot, org, unit) => stock.IqcStatus == conditions.IqcStatus);
+ if (conditions.IqcStatus == "1")
+ {
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.IqcStatus == "鐗归噰鐩存帴浣跨敤" ||
+ stock.IqcStatus == "宸叉" ||
+ stock.IqcStatus == "鍏嶆");
+ }
+ else
+ {
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.IqcStatus == conditions.IqcStatus);
+ }
}
if (conditions.Quantity.HasValue)
{
- query = query.Where((stock, item, depot, org, unit) => stock.Quantity == conditions.Quantity.Value);
- }
-
- // 妯$硦鍖归厤鏉′欢
- if (!string.IsNullOrEmpty(conditions.StackCode))
- {
- query = query.Where((stock, item, depot, org, unit) =>
- stock.StackCode != null && stock.StackCode.Contains(conditions.StackCode));
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.Quantity == conditions.Quantity.Value);
}
if (!string.IsNullOrEmpty(conditions.DepotName))
{
- query = query.Where((stock, item, depot, org, unit) =>
- depot.DepotName != null && depot.DepotName.Contains(conditions.DepotName));
+ query = query.Where((stock, item, depot, org, unit) =>
+ depot.DepotName != null &&
+ depot.DepotName.Contains(conditions.DepotName));
}
if (!string.IsNullOrEmpty(conditions.DepotSectionsCode))
{
- query = query.Where((stock, item, depot, org, unit) =>
- stock.DepotSectionsCode != null && stock.DepotSectionsCode.Contains(conditions.DepotSectionsCode));
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.DepotSectionsCode != null &&
+ stock.DepotSectionsCode.Contains(conditions
+ .DepotSectionsCode));
}
if (!string.IsNullOrEmpty(conditions.ItemNo))
{
- query = query.Where((stock, item, depot, org, unit) =>
- item.ItemNo != null && item.ItemNo.Contains(conditions.ItemNo));
+ query = query.Where((stock, item, depot, org, unit) =>
+ item.ItemNo != null &&
+ item.ItemNo.Contains(conditions.ItemNo));
}
if (!string.IsNullOrEmpty(conditions.ItemName))
{
- query = query.Where((stock, item, depot, org, unit) =>
- item.ItemName != null && item.ItemName.Contains(conditions.ItemName));
+ query = query.Where((stock, item, depot, org, unit) =>
+ item.ItemName != null &&
+ item.ItemName.Contains(conditions.ItemName));
}
if (!string.IsNullOrEmpty(conditions.ItemModel))
{
- query = query.Where((stock, item, depot, org, unit) =>
- item.ItemModel != null && item.ItemModel.Contains(conditions.ItemModel));
+ query = query.Where((stock, item, depot, org, unit) =>
+ item.ItemModel != null &&
+ item.ItemModel.Contains(conditions.ItemModel));
}
if (!string.IsNullOrEmpty(conditions.ItemUnitName))
{
- query = query.Where((stock, item, depot, org, unit) =>
- unit.Fname != null && unit.Fname.Contains(conditions.ItemUnitName));
+ query = query.Where((stock, item, depot, org, unit) =>
+ unit.Fname != null &&
+ unit.Fname.Contains(conditions.ItemUnitName));
}
if (!string.IsNullOrEmpty(conditions.OrgCode))
{
- query = query.Where((stock, item, depot, org, unit) =>
- org.Fnumber != null && org.Fnumber.Contains(conditions.OrgCode));
+ query = query.Where((stock, item, depot, org, unit) =>
+ org.Fnumber != null &&
+ org.Fnumber.Contains(conditions.OrgCode));
}
if (!string.IsNullOrEmpty(conditions.OrgName))
{
- query = query.Where((stock, item, depot, org, unit) =>
- org.Fname != null && org.Fname.Contains(conditions.OrgName));
+ query = query.Where((stock, item, depot, org, unit) =>
+ org.Fname != null &&
+ org.Fname.Contains(conditions.OrgName));
}
if (!string.IsNullOrEmpty(conditions.ItemBarcode))
{
- query = query.Where((stock, item, depot, org, unit) =>
- stock.ItemBarcode != null && stock.ItemBarcode.Contains(conditions.ItemBarcode));
+ query = query.Where((stock, item, depot, org, unit) =>
+ (stock.ItemBarcode != null &&
+ stock.ItemBarcode.Contains(conditions.ItemBarcode)) ||
+ (stock.StackCode != null &&
+ stock.StackCode.Contains(conditions.ItemBarcode)));
}
- // 鏃ユ湡鑼冨洿鏉′欢
if (!string.IsNullOrEmpty(conditions.IndepDateStart))
{
- if (DateTime.TryParse(conditions.IndepDateStart, out var startDate))
+ if (DateTime.TryParse(conditions.IndepDateStart,
+ out var startDate))
{
- query = query.Where((stock, item, depot, org, unit) => stock.IndepDate >= startDate);
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.IndepDate >= startDate);
}
}
@@ -148,25 +191,19 @@
{
if (DateTime.TryParse(conditions.IndepDateEnd, out var endDate))
{
- query = query.Where((stock, item, depot, org, unit) => stock.IndepDate <= endDate);
+ query = query.Where((stock, item, depot, org, unit) =>
+ stock.IndepDate <= endDate);
}
}
}
- // 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)
+ .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 +216,127 @@
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: 浣跨敤瀛楀吀鏌ユ壘鏇夸唬Where().FirstOrDefault()
+ 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
+ var barcodeToMatch = !string.IsNullOrEmpty(x.StockStackCode)
+ ? x.StockStackCode
+ : x.ItemBarcode;
+
+ rackingTaskDict.TryGetValue(barcodeToMatch, out var rackingTask);
+
+ string stockStatus;
+ if (rackingTask?.TaskType == "绔嬪簱鍑哄簱璇锋眰")
+ {
+ // 鍑哄簱璇锋眰锛欳ode=200琛ㄧず宸插嚭搴擄紝Code=null琛ㄧず鍑哄簱璺笂
+ stockStatus = rackingTask.Code == "200" ? "宸插嚭绔嬪簱" : "鍑虹珛搴撹矾涓�";
+ }
+ else
+ {
+ // 鍥炲簱璇锋眰锛堥粯璁わ級锛欳ode=200琛ㄧず宸插湪绔嬪簱涓紝Code=null琛ㄧず杩涘叆绔嬪簱鐨勮矾涓�
+ stockStatus = rackingTask?.Code == "200" ? "宸插湪绔嬪簱涓�" : "杩涘叆绔嬪簱鐨勮矾涓�";
+ }
+
+ return new
+ {
+ IqcStatus = x.IqcStatus == "宸叉" ? "1" : "0",
+ ItemType = x.DepotName == "鍘熸潗鏂欎粨" ? "0" : "1",
+ StackCode = rackingTask?.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,
+ StockStatus = stockStatus
+ };
}).ToList();
- // 8. 搴旂敤ItemType绛涢��(鍦ㄥ唴瀛樹腑杩囨护)
- if (conditions?.ItemType != null)
+ if (conditions != null && !string.IsNullOrEmpty(conditions.StackCode))
{
- 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();
+ tempDataList = tempDataList
+ .Where(x =>
+ x.StackCode != null &&
+ x.StackCode.Contains(conditions.StackCode))
+ .ToList();
}
- // 9. 杩斿洖鍒嗛〉缁撴灉
+ if (conditions != null && !string.IsNullOrEmpty(conditions.StockStatus))
+ {
+ tempDataList = tempDataList
+ .Where(x => x.StockStatus == conditions.StockStatus)
+ .ToList();
+ }
+
+ 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,
+ x.StockStatus
+ })
+ .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,
+ StockStatus = g.Key.StockStatus
+ }).ToList();
+
+ if (conditions?.ItemType != null)
+ {
+ dataList = dataList.Where(x => x.ItemType == conditions.ItemType)
+ .ToList();
+ }
+
+ var totalRecords = dataList.Count;
+ var totalPages =
+ (int)Math.Ceiling((double)totalRecords / searchDto.PageSize);
+ var skip = (searchDto.PageIndex - 1) * searchDto.PageSize;
+
+ var pagedDataList =
+ dataList.Skip(skip).Take(searchDto.PageSize).ToList();
+
return new PagedResult<ReturnableStockDto>
{
- TbBillList = dataList,
+ TbBillList = pagedDataList,
Pagination = new PaginationInfo
{
CurrentPage = searchDto.PageIndex,
@@ -236,19 +353,30 @@
/// <returns>鍙��璐х墿鏂欏簱瀛樺垪琛�</returns>
public List<ReturnableStockDto> GetReturnableStocks()
{
- // 1. 鏌ヨXB_RACKING_TASK_SYXT_LOG涓墍鏈夌殑鏉$爜骞跺幓閲�
- var distinctBarcodes = Db.Queryable<XbRackingTaskSyxtLog>()
- .Where(x => !string.IsNullOrEmpty(x.ItemBarcode))
- .Select(x => x.ItemBarcode)
- .Distinct()
- .ToList();
+ // 浼樺寲鐐�1: 浣跨敤鍘熺敓SQL鍦ㄦ暟鎹簱绔畬鎴愬幓閲嶅拰鎺掑簭锛岄伩鍏嶅叏琛ㄥ姞杞藉埌鍐呭瓨
+ // Oracle 11g浣跨敤ROW_NUMBER()绐楀彛鍑芥暟鑾峰彇姣忎釜鏉$爜鐨勬渶鏂拌褰�
+ var rackingTaskSql = @"
+ SELECT ITEM_BARCODE AS ItemBarcode, PALLETCODE AS PalletCode, CODE AS Code
+ FROM (
+ SELECT ITEM_BARCODE, PALLETCODE, CODE,
+ ROW_NUMBER() OVER (PARTITION BY ITEM_BARCODE ORDER BY ID DESC) AS RN
+ FROM XB_RACKING_TASK_SYXT_LOG
+ WHERE ITEM_BARCODE IS NOT NULL AND (CODE IS NULL OR CODE != '500')
+ ) WHERE RN = 1";
- if (distinctBarcodes == null || !distinctBarcodes.Any())
+ var rackingTaskData = Db.Ado.SqlQuery<RackingTaskDto>(rackingTaskSql);
+
+ if (rackingTaskData == null || !rackingTaskData.Any())
{
return new List<ReturnableStockDto>();
}
- // 2. 浣跨敤鏉$爜鏌ヨMES_INV_ITEM_STOCKS涓殑鏁版嵁,鍏宠仈MES_ITEMS銆丮ES_DEPOTS銆丱RGANIZE銆丮ES_UNIT琛�
+ // 浼樺寲鐐�2: 杩囨护null鍊煎苟浣跨敤瀛楀吀鎻愰珮鏉$爜鍖归厤鏁堢巼锛屼粠O(n)闄嶄綆鍒癘(1)
+ var validRackingData = rackingTaskData.Where(x => !string.IsNullOrEmpty(x.ItemBarcode)).ToList();
+ var rackingTaskDict = validRackingData.ToDictionary(x => x.ItemBarcode);
+ var distinctBarcodes = validRackingData.Select(x => x.ItemBarcode).ToList();
+
+ // 浼樺寲鐐�3: 鍦ㄦ暟鎹簱灞傞潰瀹屾垚鍏宠仈鏌ヨ锛屼竴娆℃�ц幏鍙栨墍鏈夐渶瑕佺殑鏁版嵁
var queryResult = Db.Queryable<MesInvItemStocks>()
.LeftJoin<MesItems>((stock, item) => stock.ItemId == item.Id)
.LeftJoin<MesDepots>((stock, item, depot) =>
@@ -280,28 +408,48 @@
})
.ToList();
- // 3. 鍦ㄥ唴瀛樹腑杩涜鏁版嵁杞崲
- var result = queryResult.Select(x => new ReturnableStockDto
+ // 浼樺寲鐐�4: 浣跨敤瀛楀吀鏌ユ壘鏇夸唬Where().FirstOrDefault()锛屾彁楂樺尮閰嶆�ц兘
+ var result = 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
+ rackingTaskDict.TryGetValue(x.ItemBarcode, out var rackingTask);
+
+ string stockStatus = "0";
+ if (rackingTask?.Code != null)
+ {
+ stockStatus = rackingTask.Code == "200" ? "1" : "2";
+ }
+
+ return new ReturnableStockDto
+ {
+ 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,
+ StockStatus = stockStatus
+ };
}).ToList();
return result;
+ }
+
+ private class RackingTaskDto
+ {
+ public string ItemBarcode { get; set; }
+ public string PalletCode { get; set; }
+ public string Code { get; set; }
+ public string TaskType { get; set; }
}
/// <summary>
@@ -324,8 +472,43 @@
// 瀵规瘡涓潯鐮佸崟鐙鐞�
foreach (var barcode in dto.ItemBarcodes)
{
+ // 妫�鏌ユ渶杩戜袱鍒嗛挓鍐呮槸鍚﹀凡缁忓瓨鍦ㄧ浉鍚岀殑 barcode 琚鐞嗚繃
+ var twoMinutesAgo = DateTime.Now.AddMinutes(-2);
+ var recentTask = Db.Queryable<XbRackingTaskSyxtLog>()
+ .Where(x =>
+ x.ItemBarcode == barcode &&
+ x.CreateDate >= twoMinutesAgo)
+ .First();
+
+ if (recentTask != null)
+ {
+ throw new Exception(
+ $"鐗╂枡鏉$爜 {barcode} 鍦ㄤ袱鍒嗛挓鍐呭凡琚壂鎻忓鐞嗭紝璇峰嬁閲嶅鎿嶄綔銆備负閬垮厤绔嬪簱绯荤粺浠诲姟閲嶅涓嬪彂锛岀郴缁熼檺鍒跺悓涓�鐗╂枡鏉$爜鍦ㄤ袱鍒嗛挓鍐呭彧鑳藉鐞嗕竴娆°��");
+ }
+
decimal messageId = 0;
string taskCode = "";
+
+ // 鏍规嵁鏉$爜鏌ヨXB_RACKING_TASK_SYXT_LOG琛紝鏌ヨmax(PALLETCODE)鍜屽搴旂殑widthType
+ var rackingTaskInfo = Db.Queryable<XbRackingTaskSyxtLog>()
+ .Where(x => x.ItemBarcode == barcode)
+ .OrderByDescending(x => x.Id)
+ .Select(x => new { x.PalletCode, x.WidthType })
+ .First();
+
+ // 妫�鏌ユ槸鍚﹀瓨鍦ㄦ湭瀹屾垚鐨勪换鍔★紙鍩轰簬PalletCode锛孋ode涓簄ull锛�
+ if (!string.IsNullOrEmpty(rackingTaskInfo?.PalletCode))
+ {
+ var pendingTask = Db.Queryable<XbRackingTaskSyxtLog>()
+ .Where(x => x.PalletCode == rackingTaskInfo.PalletCode && x.Code == null)
+ .OrderByDescending(x => x.Id)
+ .First();
+
+ if (pendingTask != null)
+ {
+ throw new Exception($"鎵樼洏缂栧彿 {rackingTaskInfo.PalletCode} 宸插瓨鍦ㄦ湭瀹屾垚鐨勭珛搴撲换鍔★紝璇风瓑寰呬换鍔″畬鎴愬悗鍐嶆搷浣溿��");
+ }
+ }
try
{
@@ -334,7 +517,8 @@
.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
@@ -343,7 +527,8 @@
ItemName = SqlFunc.AggregateMax(item.ItemName),
LotNo = stock.LotNo ?? "",
Quantity = SqlFunc.AggregateSum(stock.Quantity),
- StackCode = SqlFunc.AggregateMax(stock.DepotSectionsCode)
+ StackCode =
+ SqlFunc.AggregateMax(stock.DepotSectionsCode)
})
.ToList();
@@ -365,17 +550,18 @@
{
taskCode = taskCode,
taskType = "1",
- palletCode = firstStock.StackCode ?? "",
- widthType = "180",
- station = "3"
+ palletCode = rackingTaskInfo?.PalletCode ?? "",
+ widthType = rackingTaskInfo?.WidthType?.ToString() ??
+ "2000",
+ station = dto.Station
};
var requestList = new[] { requestData };
var jsonRequest = JsonConvert.SerializeObject(requestList);
// 5. 璁板綍鍒癕essageCenter琛�(璇锋眰鍓�)
-
+
var messageCenter = new MessageCenter
- {
+ {
TableName = "XB_RACKING_TASK_SYXT_LOG",
Url =
"http://172.20.5.5:50080/Services/Wmcs/RetrieveTask",
@@ -389,7 +575,8 @@
Data = jsonRequest,
DataInserted = jsonRequest
};
- messageId = Db.Insertable(messageCenter).ExecuteReturnIdentity();
+ messageId = Db.Insertable(messageCenter)
+ .ExecuteReturnIdentity();
// 6. 璋冪敤HTTP鎺ュ彛
var apiUrl =
@@ -432,17 +619,15 @@
CreateDate = DateTime.Now,
TaskCode = taskCode,
TaskType = "绔嬪簱鍑哄簱璇锋眰",
- PalletCode = firstStock.StackCode,
- WidthType = 180,
+ PalletCode = rackingTaskInfo?.PalletCode ?? "",
+ WidthType = rackingTaskInfo?.WidthType ?? 2000,
MaterialName = firstStock.ItemName,
MaterialCode = firstStock.ItemNo,
BatchNo = firstStock.LotNo,
Quantity = firstStock.Quantity,
WarehousingJson = responseStr,
QcStatus = 2,
- ItemBarcode = barcode,
- Code = "200",
- JsonMessage = jsonMessage ?? "鎴愬姛"
+ ItemBarcode = barcode
};
Db.Insertable(taskLog).ExecuteCommand();
@@ -505,4 +690,97 @@
throw;
}
}
+
+ /// <summary>
+ /// 瀵煎嚭鍙��璐х墿鏂欏簱瀛樹负Excel
+ /// </summary>
+ /// <param name="searchDto">鎼滅储璇锋眰鍙傛暟</param>
+ /// <returns>Excel鏂囦欢瀛楄妭鏁扮粍</returns>
+ public byte[] ExportReturnableStocksToExcel(
+ ReturnableStockSearchDto searchDto)
+ {
+ // 璁剧疆 EPPlus 璁稿彲璇佷笂涓嬫枃(闈炲晢涓氱敤閫�)
+ ExcelPackage.LicenseContext = LicenseContext.NonCommercial;
+
+ // 鑾峰彇鎵�鏈夋暟鎹�(涓嶅垎椤�)
+ var tempSearchDto = new ReturnableStockSearchDto
+ {
+ PageIndex = 1,
+ PageSize = int.MaxValue, // 鑾峰彇鎵�鏈夋暟鎹�
+ Conditions = searchDto.Conditions
+ };
+
+ // 璋冪敤鏌ヨ鏂规硶鑾峰彇鏁版嵁
+ var result = GetReturnableStocks(tempSearchDto);
+ var dataList = result.TbBillList;
+
+ // 鍒涘缓 Excel 鏂囦欢
+ using var package = new ExcelPackage();
+ var worksheet = package.Workbook.Worksheets.Add("鍙��璐х墿鏂欏簱瀛�");
+
+ // 璁剧疆琛ㄥご
+ var headers = new[]
+ {
+ "鑹搧鐘舵��",
+ "鏄惁鎴愬搧",
+ "姣嶆墭鐩樼紪鍙�",
+ "浠撳簱缂栫爜",
+ "浠撳簱鍚嶇О",
+ "铏氭嫙搴撲綅",
+ "鐗╂枡缂栧彿",
+ "鐗╂枡鍚嶇О",
+ "鐗╂枡瑙勬牸",
+ "鐗╂枡鏁伴噺",
+ "鐗╂枡鍗曚綅",
+ "鍏ュ簱鏃堕棿",
+ "缁勭粐缂栫爜",
+ "缁勭粐鍚嶇О",
+ "鐗╂枡鏉$爜",
+ "搴撳瓨鐘舵��"
+ };
+
+ // 鍐欏叆琛ㄥご
+ for (int i = 0; i < headers.Length; i++)
+ {
+ worksheet.Cells[1, i + 1].Value = headers[i];
+ worksheet.Cells[1, i + 1].Style.Font.Bold = true;
+ worksheet.Cells[1, i + 1].Style.Fill.PatternType =
+ ExcelFillStyle.Solid;
+ worksheet.Cells[1, i + 1].Style.Fill.BackgroundColor
+ .SetColor(System.Drawing.Color.LightGray);
+ worksheet.Cells[1, i + 1].Style.HorizontalAlignment =
+ ExcelHorizontalAlignment.Center;
+ }
+
+ // 鍐欏叆鏁版嵁
+ int row = 2;
+ foreach (var item in dataList)
+ {
+ worksheet.Cells[row, 1].Value =
+ item.IqcStatus == "1" ? "鑹搧" : "涓嶈壇鍝�";
+ worksheet.Cells[row, 2].Value = item.ItemType == "1" ? "鎴愬搧" : "闈炴垚鍝�";
+ worksheet.Cells[row, 3].Value = item.StackCode;
+ worksheet.Cells[row, 4].Value = item.DepotCode;
+ worksheet.Cells[row, 5].Value = item.DepotName;
+ worksheet.Cells[row, 6].Value = item.DepotSectionsCode;
+ worksheet.Cells[row, 7].Value = item.ItemNo;
+ worksheet.Cells[row, 8].Value = item.ItemName;
+ worksheet.Cells[row, 9].Value = item.ItemModel;
+ worksheet.Cells[row, 10].Value = item.Quantity;
+ worksheet.Cells[row, 11].Value = item.ItemUnitName;
+ worksheet.Cells[row, 12].Value =
+ item.IndepDate?.ToString("yyyy-MM-dd HH:mm:ss");
+ worksheet.Cells[row, 13].Value = item.OrgCode;
+ worksheet.Cells[row, 14].Value = item.OrgName;
+ worksheet.Cells[row, 15].Value = item.ItemBarcode;
+ worksheet.Cells[row, 16].Value = item.StockStatus;
+ row++;
+ }
+
+ // 鑷姩璋冩暣鍒楀
+ worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
+
+ // 杩斿洖 Excel 鏂囦欢瀛楄妭鏁扮粍
+ return package.GetAsByteArray();
+ }
}
\ No newline at end of file
--
Gitblit v1.9.3