From d48e486d63ae2a0fc454c27c79b8f12115e4bcbe Mon Sep 17 00:00:00 2001
From: yanjinhui <3306209981@qq.com>
Date: 星期六, 18 十月 2025 16:20:45 +0800
Subject: [PATCH] 修改
---
新建文件夹/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs | 369 +++++++++-------------------------------------------
1 files changed, 66 insertions(+), 303 deletions(-)
diff --git "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs" "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
index 2b13edc..8a41ce8 100644
--- "a/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
+++ "b/\346\226\260\345\273\272\346\226\207\344\273\266\345\244\271/WIDESEA_WMSServer/WIDESEA_SquareCabinServices/DeliveryOrderServices.cs"
@@ -176,288 +176,11 @@
//}
-
- public WebResponseContent GetUpstreamOutOrder()
- {
- var responseContent = new WebResponseContent();
- try
- {
- var url = "http://121.37.118.63:80/GYZ2/95fck/outOrder";
-
- var requestData = new
- {
- searchDate = "2022-10-10 20:45:16"
- };
-
- var result = HttpHelper.Post(url, requestData.ToJsonString());
- var response = JsonConvert.DeserializeObject<UpstreamResponse<UpstramOutOrderInfo>>(result);
-
- if (response.resultCode != "0")
- {
- SendErrorToUpstream(3, "", response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触", "");
- return responseContent.Error(response.resultMsg ?? "涓婃父鎺ュ彛杩斿洖澶辫触");
- }
-
- if (response.data == null || !response.data.Any())
- {
- return responseContent.OK("鏃犳柊鍑哄簱鍗曟暟鎹�");
- }
-
- // 宸插瓨鍦ㄥ嚭搴撳崟鍙�
- var existingOutOrderNos = BaseDal.Db.Queryable<Dt_DeliveryOrder>()
- .Select(x => x.Out_no)
- .ToList();
-
- // 鏂板嚭搴撳崟
- var newOutOrders = response.data
- .Where(outorder => !existingOutOrderNos.Contains(outorder.order_no))
- .ToList();
-
- if (!newOutOrders.Any())
- {
- return responseContent.OK("鎵�鏈夊嚭搴撳崟宸插瓨鍦紝鏃犻渶鏂板");
- }
-
- Db.Ado.BeginTran();
- try
- {
- List<Dt_DeliveryOrder> _DeliveryOrders = new List<Dt_DeliveryOrder>();
-
- foreach (var outorder in newOutOrders)
- {
- var entityOrder = new Dt_DeliveryOrder
- {
- Out_no = outorder.order_no,
- Out_type = outorder.order_type,
- Client_no = outorder.client_no,
- Client_name = outorder.client_name,
- Account_time = outorder.account_time,
- Warehouse_no = outorder.warehouse_no,
- OutStatus = "鏈畬鎴�",
- Details = new List<Dt_DeliveryOrderDetail>()
- };
-
- // 閬嶅巻鍑哄簱鏄庣粏
- foreach (var item in outorder.details)
- {
- // 1锔忊儯 杞负姝f暟锛堜笂娓稿彲鑳戒紶璐熸暟锛�
- item.order_qty = Math.Abs(item.order_qty);
- decimal orderQty = (decimal)item.order_qty;
-
- // 2锔忊儯 鏌ョ墿鏂欏熀纭�淇℃伅锛堣幏鍙栫瑙勶級
- var medication = BaseDal.Db.Queryable<Dt_MedicineGoods>()
- .Where(m => m.Goods_no == item.goods_no)
- .First();
-
- if (medication == null)
- {
- SendErrorToUpstream(3, "", $"鎵句笉鍒扮墿鏂欎俊鎭細{item.goods_no}", "");
- continue;
- }
-
- decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty;
-
- // 3锔忊儯 璁$畻鏁翠欢涓庢暎浠舵暟閲�
- var fullBoxes = (int)(orderQty / boxQty); // 鏁翠欢绠辨暟
- var partialQty = orderQty % boxQty; // 鏁d欢鏁伴噺
-
- // 鑻ヤ笂娓哥粰浜嗘壒娆″彿锛屽垯浼樺厛鍖归厤
- string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num;
-
- // helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
- Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
- {
- var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
- .Where(i => i.MaterielCode == item.goods_no &&
- (i.StockQuantity - i.OutboundQuantity) > 0 &&
- i.StockStatus == stockStatus);
-
- if (!string.IsNullOrEmpty(requestedBatch))
- q = q.Where(i => i.BatchNo == requestedBatch);
-
- return q.OrderBy(i => i.InDate).ToList();
- };
-
- // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=0锛�
- decimal remainingPartial = partialQty;
- if (remainingPartial > 0)
- {
- var invList_ly = queryInventoryByStockStatus(1);
- foreach (var inv in invList_ly)
- {
- if (remainingPartial <= 0) break;
-
- decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
- if (available <= 0) continue;
-
- decimal use = Math.Min(available, remainingPartial);
-
- var detail = new Dt_DeliveryOrderDetail
- {
- Goods_no = item.goods_no,
- Order_qty = use,
- Batch_num = inv.BatchNo,
- Exp_date = inv.ValidityPeriod,
- OotDetailStatus = "鏂板缓",
- Status = 0, //绔嬪簱
- Reservoirarea = inv.LocationCode
- };
- entityOrder.Details.Add(detail);
-
- inv.OutboundQuantity += use;
- BaseDal.Db.Updateable(inv).ExecuteCommand();
-
- remainingPartial -= use;
- }
-
- // 绔嬪簱涓嶅 鈫� 骞冲簱琛� (Status=2)
- if (remainingPartial > 0)
- {
- var invList_pk = queryInventoryByStockStatus(2);
- foreach (var inv in invList_pk)
- {
- if (remainingPartial <= 0) break;
-
- decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
- if (available <= 0) continue;
-
- decimal use = Math.Min(available, remainingPartial);
-
- var detail = new Dt_DeliveryOrderDetail
- {
- Goods_no = item.goods_no,
- Order_qty = use,
- Batch_num = inv.BatchNo,
- Exp_date = inv.ValidityPeriod,
- OotDetailStatus = "鏂板缓",
- Status = 2, //骞冲簱
- Reservoirarea = inv.LocationCode
- };
- entityOrder.Details.Add(detail);
-
- inv.OutboundQuantity += use;
- BaseDal.Db.Updateable(inv).ExecuteCommand();
-
- remainingPartial -= use;
- }
- }
-
- if (remainingPartial > 0)
- {
- SendErrorToUpstream(3, "", $"鍑哄簱鍗昜{outorder.order_no}]鐗╂枡[{item.goods_no}]鏁d欢搴撳瓨涓嶈冻锛屾湭鍒嗛厤锛歿remainingPartial}", "");
- }
- }
-
- //鍒嗛厤鏁翠欢锛堜紭鍏堝钩搴� Status=2锛�
- int remainingFullBoxes = fullBoxes;
- if (remainingFullBoxes > 0)
- {
- var invList_pk = queryInventoryByStockStatus(2);
- foreach (var inv in invList_pk)
- {
- if (remainingFullBoxes <= 0) break;
-
- decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
- if (available < boxQty) continue;
-
- int canProvideBoxes = (int)(available / boxQty);
- if (canProvideBoxes <= 0) continue;
-
- int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes);
- decimal useQty = useBoxes * boxQty;
-
- var detail = new Dt_DeliveryOrderDetail
- {
- Goods_no = item.goods_no,
- Order_qty = useQty,
- Batch_num = inv.BatchNo,
- Exp_date = inv.ValidityPeriod,
- OotDetailStatus = "鏂板缓",
- Status = 2, //骞冲簱
- Reservoirarea = inv.LocationCode
- };
- entityOrder.Details.Add(detail);
-
- inv.OutboundQuantity += useQty;
- BaseDal.Db.Updateable(inv).ExecuteCommand();
-
- remainingFullBoxes -= useBoxes;
- }
-
- // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=1)
- if (remainingFullBoxes > 0)
- {
- var invList_ly = queryInventoryByStockStatus(1);
- foreach (var inv in invList_ly)
- {
- if (remainingFullBoxes <= 0) break;
-
- decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
- if (available < boxQty) continue;
-
- int canProvideBoxes = (int)(available / boxQty);
- if (canProvideBoxes <= 0) continue;
-
- int useBoxes = Math.Min(canProvideBoxes, remainingFullBoxes);
- decimal useQty = useBoxes * boxQty;
-
- var detail = new Dt_DeliveryOrderDetail
- {
- Goods_no = item.goods_no,
- Order_qty = useQty,
- Batch_num = inv.BatchNo,
- Exp_date = inv.ValidityPeriod,
- OotDetailStatus = "鏂板缓",
- Status = 0, //绔嬪簱锛堣ˉ鏁寸锛�
- Reservoirarea = inv.LocationCode
- };
- entityOrder.Details.Add(detail);
-
- inv.OutboundQuantity += useQty;
- BaseDal.Db.Updateable(inv).ExecuteCommand();
-
- remainingFullBoxes -= useBoxes;
- }
- }
-
- if (remainingFullBoxes > 0)
- {
- decimal unfilledQty = remainingFullBoxes * boxQty;
- SendErrorToUpstream(3, "", $"鍑哄簱鍗昜{outorder.order_no}]鐗╂枡[{item.goods_no}]鏁寸搴撳瓨涓嶈冻锛屾湭鍒嗛厤鏁伴噺锛歿unfilledQty}", "");
- }
- }
- }
-
- _DeliveryOrders.Add(entityOrder);
- }
-
- // 鎻掑叆涓昏〃+鏄庣粏
- BaseDal.Db.InsertNav(_DeliveryOrders)
- .Include(x => x.Details)
- .ExecuteCommand();
-
- Db.Ado.CommitTran();
- return responseContent.OK("鍚屾鍑哄簱鍗曟垚鍔�");
- }
- catch (Exception ex)
- {
- Db.Ado.RollbackTran();
- SendErrorToUpstream(3, "", ex.Message, "");
- return responseContent.Error("鍚屾澶辫触: " + ex.Message);
- }
- }
- catch (Exception ex)
- {
- SendErrorToUpstream(3, "", ex.Message, "");
- return responseContent.Error("鍚屾澶辫触: " + ex.Message);
- }
- }
-
/// <summary>
/// 杩囨护娌℃湁瀵瑰晢鍝佽繘琛岀淮鎶ょ殑鍑哄簱鍗曡繘琛岃繃婊�
/// </summary>
/// <returns></returns>
- public WebResponseContent GetUpstreamOutOrder2()
+ public WebResponseContent GetUpstreamOutOrder()
{
var responseContent = new WebResponseContent();
try
@@ -525,12 +248,15 @@
{
// 1锔忊儯 杞负姝f暟锛堜笂娓稿彲鑳戒紶璐熸暟锛�
item.order_qty = Math.Abs(item.order_qty);
+
+ //鍑哄簱鏁伴噺
decimal orderQty = (decimal)item.order_qty;
// 2锔忊儯 鏌ョ墿鏂欏熀纭�淇℃伅锛堣幏鍙栫瑙勶級
var medication = BaseDal.Db.Queryable<Dt_MaterielInfo>()
.Where(m => m.MaterielCode == item.goods_no)
.First();
+ #region 妫�鏌ヨ繖涓嚭搴撳崟涓殑鐗╂枡淇℃伅鏄惁瀛樺湪
//濡傛灉鐗╂枡淇℃伅涓嶅瓨鍦紝璺宠繃鏁翠釜鍏ュ簱鍗�
if (medication == null)
{
@@ -547,12 +273,15 @@
break;
}
+
if (medication == null)
{
SendErrorToUpstream(3, "", $"鎵句笉鍒扮墿鏂欎俊鎭細{item.goods_no}", "");
continue;
}
+ #endregion
+ // 濡傛灉绠辫灏忎簬绛変簬0锛屼娇鐢ㄩ粯璁ゅ��1,鍚﹀垯灏辩敤瀹為檯鏁伴噺
decimal boxQty = medication.BoxQty <= 0 ? 1 : medication.BoxQty;
// 3锔忊儯 璁$畻鏁翠欢涓庢暎浠舵暟閲�
@@ -563,34 +292,61 @@
string requestedBatch = string.IsNullOrEmpty(item.batch_num) ? null : item.batch_num;
// helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
+ #region 浣跨敤搴撳瓨淇℃伅涓殑stockStatus鏉ュ尯鍒嗗钩搴撳拰绔嬪簱
// 瀹氫箟涓�涓鎵樺彉閲忥細杈撳叆int鍙傛暟锛岃繑鍥濴ist<Dt_InventoryInfo>
- Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
- {
- // 1. 鍒涘缓鍩虹鏌ヨ
- var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
- .Where(i => i.MaterielCode == item.goods_no && // 鐗╂枡缂栧彿鍖归厤
- (i.StockQuantity - i.OutboundQuantity) > 0 && // 鍙敤搴撳瓨>0
- i.StockStatus == stockStatus); // 搴撳瓨鐘舵�佸尮閰�
+ //Func<int, List<Dt_InventoryInfo>> queryInventoryByStockStatus = (stockStatus) =>
+ //{
+ // // 1. 鍒涘缓鍩虹鏌ヨ
+ // var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
+ // .Where(i => i.MaterielCode == item.goods_no && // 鐗╂枡缂栧彿鍖归厤
+ // (i.StockQuantity - i.OutboundQuantity) > 0 && // 鍙敤搴撳瓨>0
+ // i.StockStatus == stockStatus); // 搴撳瓨鐘舵�佸尮閰�
- // 2. 鏉′欢绛涢�夛紙濡傛灉鏈夋壒娆″彿瑕佹眰锛�
+ // // 2. 鏉′欢绛涢�夛紙濡傛灉鏈夋壒娆″彿瑕佹眰锛�
+ // if (!string.IsNullOrEmpty(requestedBatch))
+ // q = q.Where(i => i.BatchNo == requestedBatch);
+
+ // // 3. 鎵ц鏌ヨ骞惰繑鍥炵粨鏋�
+ // return q.OrderBy(i => i.InDate).ToList(); // 鎸夊叆搴撴椂闂存帓搴�
+ //};
+ #endregion
+
+ #region 浣跨敤搴撴埧缂栧彿鏉ュ尯鍒嗘槸骞冲簱鍜岀珛搴�
+ // helper: 鏌ヨ搴撳瓨鍑芥暟锛堟寜鍏ュ簱鏃堕棿鍗囧簭锛�
+ // 鐢ㄥ簱鎴跨紪鍙峰尯鍒嗙珛搴撳拰骞冲簱锛氱珛搴� WarehouseCode == "001" 杈撳叆true灏辨槸绔嬪簱鍚﹀垯灏辨槸骞冲簱
+ Func<bool, List<Dt_InventoryInfo>> queryInventoryByWarehouseType = (isLiku) =>
+ {
+ var q = BaseDal.Db.Queryable<Dt_InventoryInfo>()
+ .Where(i => i.MaterielCode == item.goods_no &&
+ (i.StockQuantity - i.OutboundQuantity) > 0);
+
+ if (isLiku)
+ q = q.Where(i => i.WarehouseCode == "001"); // 绔嬪簱
+ else
+ q = q.Where(i => i.WarehouseCode != "001"); // 骞冲簱
+
if (!string.IsNullOrEmpty(requestedBatch))
q = q.Where(i => i.BatchNo == requestedBatch);
- // 3. 鎵ц鏌ヨ骞惰繑鍥炵粨鏋�
- return q.OrderBy(i => i.InDate).ToList(); // 鎸夊叆搴撴椂闂存帓搴�
+ return q.OrderBy(i => i.InDate).ToList();
};
- // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� Status=0锛�
- decimal remainingPartial = partialQty;
+ #endregion
+ // 4锔忊儯鍒嗛厤鏁d欢锛堜紭鍏堢珛搴� WarehouseCode == "001锛�
+ decimal remainingPartial = partialQty; //鏁d欢
if (remainingPartial > 0)
{
- var invList_ly = queryInventoryByStockStatus(0);
+ //杩斿洖涓�涓狶ist<Dt_InventoryInfo>stockStatus==0鐨勫簱瀛樺垪琛�
+ var invList_ly = queryInventoryByWarehouseType(true); //绔嬪簱 WarehouseCode == "001"
foreach (var inv in invList_ly)
{
if (remainingPartial <= 0) break;
+ //鍙敤搴撳瓨鏁伴噺
decimal available = (decimal)(inv.StockQuantity - inv.OutboundQuantity);
+
if (available <= 0) continue;
+ //琛ㄧず銆屽綋鍓嶈繕闇�瑕佸嚭搴撶殑鏁伴噺銆嶆垨銆屽緟鍒嗛厤鏁伴噺銆嶃��
decimal use = Math.Min(available, remainingPartial);
var detail = new Dt_DeliveryOrderDetail
@@ -601,7 +357,7 @@
Exp_date = inv.ValidityPeriod,
OotDetailStatus = "鏂板缓",
Status = 0, //绔嬪簱
- Reservoirarea = inv.LocationCode
+ Reservoirarea = inv.WarehouseCode
};
entityOrder.Details.Add(detail);
@@ -614,7 +370,7 @@
// 绔嬪簱涓嶅 鈫� 骞冲簱琛� (Status=2)
if (remainingPartial > 0)
{
- var invList_pk = queryInventoryByStockStatus(2);
+ var invList_pk = queryInventoryByWarehouseType(false); //骞冲簱
foreach (var inv in invList_pk)
{
if (remainingPartial <= 0) break;
@@ -632,7 +388,7 @@
Exp_date = inv.ValidityPeriod,
OotDetailStatus = "鏂板缓",
Status = 2, //骞冲簱
- Reservoirarea = inv.LocationCode
+ Reservoirarea = inv.WarehouseCode
};
entityOrder.Details.Add(detail);
@@ -650,10 +406,10 @@
}
//鍒嗛厤鏁翠欢锛堜紭鍏堝钩搴� Status=2锛�
- int remainingFullBoxes = fullBoxes;
+ int remainingFullBoxes = fullBoxes;//鏁翠欢绠辨暟
if (remainingFullBoxes > 0)
{
- var invList_pk = queryInventoryByStockStatus(2);
+ var invList_pk = queryInventoryByWarehouseType(true);
foreach (var inv in invList_pk)
{
if (remainingFullBoxes <= 0) break;
@@ -675,7 +431,7 @@
Exp_date = inv.ValidityPeriod,
OotDetailStatus = "鏂板缓",
Status = 2, //骞冲簱
- Reservoirarea = inv.LocationCode
+ Reservoirarea = inv.WarehouseCode
};
entityOrder.Details.Add(detail);
@@ -685,10 +441,10 @@
remainingFullBoxes -= useBoxes;
}
- // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=1)
+ // 骞冲簱涓嶅 鈫� 绔嬪簱琛� (Status=0)
if (remainingFullBoxes > 0)
{
- var invList_ly = queryInventoryByStockStatus(1);
+ var invList_ly = queryInventoryByWarehouseType(true); //绔嬪簱
foreach (var inv in invList_ly)
{
if (remainingFullBoxes <= 0) break;
@@ -843,7 +599,6 @@
.SetColumns(d => new Dt_DeliveryOrderDetail { Status = 1, OotDetailStatus = "宸插畬鎴�" })
.Where(d => d.DeliveryOrderId == order.Id && d.Status == 0)
.ExecuteCommand();
-
Console.WriteLine($"璁㈠崟 {order.Out_no} 鎺ㄩ�佹垚鍔�");
}
else
@@ -1132,8 +887,9 @@
}
return content;
}
+
/// <summary>
- /// 鏌ヨ鍑哄簱/鐩樼偣鍗曡鎯�
+ /// 鏌ヨ鍑哄簱/鐩樼偣鍗曡鎯� 鐪嬪嚭搴撳崟鏄庣粏銆�
/// </summary>
/// <param name="pageNo"></param>
/// <param name="orderNo"></param>
@@ -1147,10 +903,11 @@
cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type == "3");
else
cabinOrder = Db.Queryable<Dt_DeliveryOrder>().Includes(x => x.Details).First(x => x.Out_no == orderNo && x.Out_type != "3");
- List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList();
- content.OK(data: cabinOrderDetails);
+ List<Dt_DeliveryOrderDetail>? cabinOrderDetails = cabinOrder.Details?.Where(x => x.Reservoirarea == pageNo.ToString()).ToList();
+ content.OK(data: cabinOrderDetails);
return content;
}
+
public WebResponseContent OutFinish(SaveModel saveModel)
{
WebResponseContent content = new WebResponseContent();
@@ -1244,6 +1001,12 @@
return content;
}
+
+ /// <summary>
+ /// 骞冲簱浜哄伐鎷f枡鍑哄簱澶勭悊锛堝嵆浜哄伐鎵爜鍑哄簱鏃惰皟鐢級
+ /// </summary>
+ /// <param name="saveModel"></param>
+ /// <returns></returns>
public WebResponseContent MatPicking(SaveModel saveModel)
{
WebResponseContent content = new WebResponseContent();
--
Gitblit v1.9.3