From 88604ff346c6dc6caf07612aa99a688d3f0428c1 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期五, 07 三月 2025 09:37:25 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.BLL/BllTransServer/NoticeServer.cs | 649 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 645 insertions(+), 4 deletions(-) diff --git a/Wms/WMS.BLL/BllTransServer/NoticeServer.cs b/Wms/WMS.BLL/BllTransServer/NoticeServer.cs index 28ead5b..59d0c0c 100644 --- a/Wms/WMS.BLL/BllTransServer/NoticeServer.cs +++ b/Wms/WMS.BLL/BllTransServer/NoticeServer.cs @@ -1,12 +1,22 @@ 锘縰sing Model.InterFaceModel; +using Newtonsoft.Json; using SqlSugar; using System; using System.Collections.Generic; +using System.Linq; using System.Text; +using Utility.Tools; +using WMS.BLL.LogServer; using WMS.DAL; using WMS.Entity.BllAsnEntity; +using WMS.Entity.BllQualityEntity; +using WMS.Entity.BllSoEntity; using WMS.Entity.Context; +using WMS.Entity.DataEntity; +using WMS.Entity.LogEntity; +using WMS.Entity.SysEntity; using WMS.IBLL.IBllTransServer; +using static Model.InterFaceModel.RCSModel; namespace WMS.BLL.BllTransServer { @@ -16,8 +26,12 @@ public NoticeServer() : base(Db) { } - - public ErpModel CreateAsn(AsnInfo model) + /// <summary> + /// 涓嬪彂鍏ュ簱鍗� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + public ErpModel CreateAsnWork(AsnInfo model) { try { @@ -43,7 +57,7 @@ Origin = string.IsNullOrEmpty(model.Origin) ? "MES" : model.Origin, CustomerNo = model.Customer, CustomerName = "", - OrderCode = model.OrderCode, + OrderCode = model.OrderCode }; // 鍏ュ簱鏄庣粏琛ㄤ俊鎭� @@ -78,7 +92,7 @@ SkuName = asnDetailModel.SkuName, LotNo = asnDetailModel.LotNo, LotText = "", - Qty = (decimal)asnDetailModel.Qty, + Qty = (decimal)asnDetailModel.Qty,//杩欓噷鏄《鏁伴噺 FactQty = 0, CompleteQty = 0, SupplierLot = asnDetailModel.SupplierLot, @@ -108,5 +122,632 @@ throw ex; } } + + /// <summary> + /// 浠诲姟瀹屾垚 + /// </summary> + /// <param name="TaskNo"></param> + /// <param name="Status"></param> + /// <returns></returns> + public ErpModel RCSFinishTask(string TaskNo,string Status) + { + try + { + #region 鏉′欢鍒ゆ柇 + var resultModel = new ErpModel() { Success = -1, Message = "" }; + if (string.IsNullOrEmpty(TaskNo)) + { + resultModel.Message = "浠诲姟鍙蜂笉鍙负绌�!"; + return resultModel; + } + //浠诲姟淇℃伅 + var taskInfo = Db.Queryable<LogTask>().First(w => w.TaskNo == TaskNo); + if (taskInfo == null) + { + resultModel.Message = $"浠诲姟鍙蜂负:{TaskNo}鐨勪换鍔′笉瀛樺湪!"; + return resultModel; + } + if (taskInfo.Status != "1") + { + resultModel.Message = $"浠诲姟鍙蜂负:{TaskNo}鐨勪换鍔$姸鎬佸紓甯�!"; + return resultModel; + } + #endregion + //寮�鍚簨鍔� + Db.BeginTran(); + var comTime = DateTime.Now; + + if (Status == "0") + { + taskInfo.Status = "3";//寮傚父缁撴潫 + //淇敼浠诲姟鐘舵�� + Db.Updateable(taskInfo).ExecuteCommand(); + + resultModel.Success = 0; + resultModel.Message = "鎴愬姛"; + + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + return resultModel; + } + switch (taskInfo.OrderType) + { + #region 鍏ュ簱瀹屾垚 + case "0": + + //鐩爣鍌ㄤ綅淇℃伅 + var locatInfo = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.EndLocat && w.IsDel == "0"); + if (locatInfo == null) + { + resultModel.Message = "鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + + //搴撳瓨鏄庣粏 + var sd1 = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo); + if (sd1 == null) + { + resultModel.Message = $"璇ユ《瀵瑰簲鐨勫簱瀛樹俊鎭笉瀛樺湪锛屾《鍙凤細{taskInfo.PalletNo}!"; + return resultModel; + } + else + { + sd1.Qty = 1; + sd1.LockQty = 0; + sd1.FrozenQty = 0; + sd1.InspectQty = 0; + sd1.WareHouseNo = locatInfo.WareHouseNo;//鎵�灞炰粨搴� + sd1.RoadwayNo = locatInfo.RoadwayNo;//鎵�灞炲贩閬� + sd1.AreaNo = locatInfo.AreaNo;//鎵�灞炲尯鍩� + sd1.LocatNo = locatInfo.LocatNo;//鍌ㄤ綅鍦板潃 + sd1.CompleteTime = comTime; + sd1.InspectStatus = "0";//寰呮楠� + sd1.PalletStatus = "2";//鍗婃垚鍝� + + //淇敼搴撳瓨鏄庣粏 + Db.Updateable(sd1).ExecuteCommand(); + } + locatInfo.Status = "1";//鏈夌墿鍝� + //鏇存柊鍌ㄤ綅鐘舵�� + Db.Updateable(locatInfo).ExecuteCommand(); + + //鍏ュ簱鍗曟槑缁嗕俊鎭� + var noticeDetail = Db.Queryable<BllArrivalNoticeDetail>().First(w => w.Id == taskInfo.NoticeDetailNo); + if (noticeDetail != null) + { + //鍏ュ簱鍗曚俊鎭� + var notice = Db.Queryable<BllArrivalNotice>().First(w => w.ASNNo == noticeDetail.ASNNo); + if (notice == null) + { + resultModel.Message = "璇ヤ换鍔″搴旂殑鍏ュ簱鍗曚笉瀛樺湪!"; + return resultModel; + } + if (notice.Status == "3" || notice.Status == "4") + { + resultModel.Message = "璇ヤ换鍔″搴旂殑鍏ュ簱鍗曞凡鎵ц瀹屾垚!"; + return resultModel; + } + noticeDetail.CompleteQty += 1;//瀹屾垚鏁伴噺 + noticeDetail.Status = "1";//0锛氱瓑寰呮墽琛� 1锛氭鍦ㄦ墽琛� 2锛氭墽琛屽畬鎴� + if (noticeDetail.CompleteQty >= noticeDetail.Qty) + { + noticeDetail.Status = "2"; + noticeDetail.CompleteTime = comTime; + } + noticeDetail.UpdateUser = 0; + noticeDetail.UpdateTime = comTime; + //鏇存柊鍏ュ簱鍗曟槑缁� + Db.Updateable(noticeDetail).ExecuteCommand(); + + notice.UpdateUser = 0; + notice.UpdateTime = comTime; + if (notice.Status == "0") + { + notice.Status = "1"; + } + var asnDetailNum = Db.Queryable<BllArrivalNoticeDetail>().Count(m => m.IsDel == "0" && m.ASNNo == noticeDetail.ASNNo && m.Status != "2"); + if (asnDetailNum == 0) + { + notice.Status = "2"; + notice.CompleteTime = comTime;//瀹屾垚鏃堕棿 + } + //鏇存柊鍏ュ簱鍗� + Db.Updateable(notice).ExecuteCommand(); + } + + #region 璐ㄦ璇烽獙锛屽幓鎺塎ES + //var qualityRequest = Db.Queryable<BllQualityInspectionRequest>().First(m => m.IsDel == "0" && m.SkuNo == noticeDetail.SkuNo && m.LotNo == noticeDetail.LotNo && m.SupplierLot == noticeDetail.SupplierLot); + //if (qualityRequest == null) + //{ + // //璐ㄦ璇烽獙鍗曚俊鎭� + // string qcNo = new Common().GetMaxNo("QC"); + // qualityRequest = new BllQualityInspectionRequest(); + // qualityRequest.QcNo = qcNo; + // qualityRequest.Status = "0"; + // qualityRequest.SkuNo = noticeDetail.SkuNo; + // qualityRequest.SkuName = noticeDetail.SkuName; + // qualityRequest.LotNo = noticeDetail.LotNo; + // qualityRequest.SupplierLot = noticeDetail.SupplierLot; + // qualityRequest.Qty = noticeDetail.Qty; + // qualityRequest.SamplingQty = 0; + // qualityRequest.ASNNo = noticeDetail.ASNNo; + // qualityRequest.CreateUser = 0; + // qualityRequest.CreateTime = comTime; + + // // 璁板綍浠诲姟鏃ュ織 + // var taskNo = new Common().GetMaxNo("TK"); + // var exTask = new LogTask() + // { + // TaskNo = taskNo, + // Sender = "WMS", + // Receiver = "Limes", + // IsSuccess = 0,//鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + // StartLocat = "",//璧峰浣嶇疆 + // PalletNo = "",//鎵樼洏鐮� + // IsSend = 1,//鏄惁鍙啀娆′笅鍙� + // IsCancel = 1,//鏄惁鍙彇娑� + // IsFinish = 1,//鏄惁鍙畬鎴� + // Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + // OrderType = "5",//0 鍏ュ簱鍗� 1 鍑哄簱鍗� 2 鐩樼偣鍗� 3 绉诲簱鍗� 4 鍙栨牱鍑哄簱鍗� 5 鍏朵粬 + // EndLocat = "",//鐩爣浣嶇疆 + // Type = "3",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + // Msg = "璇烽獙浠诲姟" + // }; + // // 鎻掑叆浠诲姟鏃ュ織 + // Db.Insertable(exTask).ExecuteCommand(); + + // // 璋冪敤Limes鎺ュ彛鍙戣捣璇烽獙 + // var sendModel = new SendLimesModel() + // { + // QcNo = qualityRequest.QcNo, + // SkuNo = qualityRequest.SkuNo, + // Qty = qualityRequest.Qty.ToString(), + // LotNo = qualityRequest.LotNo, + // SupplierLot = qualityRequest.SupplierLot, + // RequestUser = "", // 璇烽獙浜� + // }; + // var jsonData = JsonConvert.SerializeObject(sendModel); + // string response = ""; + // try + // { + // var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss") + // //response = HttpHelper.DoPost(url, jsonData, "涓婁紶Limes绯荤粺鍙戣捣璇烽獙", "Limes"); + // var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss") + + // ////瑙f瀽杩斿洖鏁版嵁 + // //var limesModel = JsonConvert.DeserializeObject<LimesModel>(response); + // List<string> list1 = new List<string>(); + // list1.Add(taskNo); + // //if (limesModel.Success == 0) + // //{ + // //鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�// + // new TaskServer().EditTaskIssueOk(list1, time1, time2); + + // // 鏇存柊璇烽獙鍗曚俊鎭� + // qualityRequest.Status = "1"; + // qualityRequest.SamplingQty = 10;//decimal.Parse(limesModel.SamplingQty); + // qualityRequest.RequestUser = 0; + // qualityRequest.RequestTime = DateTime.Now; + // qualityRequest.UpdateTime = DateTime.Now; + // qualityRequest.UpdateUser = 0; + // //娣诲姞璐ㄦ璇烽獙鍗� + // Db.Insertable(qualityRequest).ExecuteCommand(); + // //} + // //if (limesModel.Success == -1) + // //{ + // // new TaskServer().EditTaskIssueNo(list1, time1, time2,limesModel.Message); + // // throw new Exception(limesModel.Message); + // //} + // } + // catch (Exception ex) + // { + // throw new Exception(ex.Message); + // } + //} + #endregion + + break; + #endregion + + #region 鍑哄簱瀹屾垚 + case "1": + + //璧峰鍌ㄤ綅淇℃伅 + var startLocatInfo = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.StartLocat && w.IsDel == "0"); + if (startLocatInfo == null) + { + resultModel.Message = "璧峰鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + //搴撳瓨鏄庣粏 + var sd2 = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo); + if (sd2 == null) + { + resultModel.Message = "搴撳瓨淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + sd2.Qty = 0; + sd2.LockQty = 0; + sd2.FrozenQty = 0; + sd2.InspectQty = 0; + sd2.ASNNo = ""; + sd2.ASNDetailNo = null; + sd2.WareHouseNo = "";//鎵�灞炰粨搴� + sd2.RoadwayNo = "";//鎵�灞炲贩閬� + sd2.AreaNo = "";//鎵�灞炲尯鍩� + sd2.LocatNo = "";//鍌ㄤ綅鍦板潃 + sd2.CompleteTime = comTime; + //淇敼搴撳瓨鏄庣粏 + Db.Updateable(sd2).ExecuteCommand(); + + startLocatInfo.Status = "0";//绌哄偍浣� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(startLocatInfo).ExecuteCommand(); + //鍑哄簱鍗曟槑缁嗕俊鎭� + var exNoticeDetail = Db.Queryable<BllExportNoticeDetail>().First(w => w.Id == taskInfo.NoticeDetailNo); + if (exNoticeDetail != null) + { + //鍑哄簱鍗曚俊鎭� + var exNotice = Db.Queryable<BllExportNotice>().First(w => w.SONo == exNoticeDetail.SONo); + if (exNotice == null) + { + resultModel.Message = "璇ヤ换鍔″搴旂殑鍑哄簱鍗曚笉瀛樺湪!"; + return resultModel; + } + if (exNotice.Status == "4" || exNotice.Status == "5") + { + resultModel.Message = "璇ヤ换鍔″搴旂殑鍑哄簱鍗曞凡鎵ц瀹屾垚!"; + return resultModel; + } + exNotice.UpdateUser = 0; + exNotice.UpdateTime = comTime; + if (exNotice.Status == "0" || exNotice.Status == "1" || exNotice.Status == "2") + { + exNotice.Status = "3";//鏇存敼涓烘鍦ㄦ墽琛� + } + var num = Db.Queryable<BllExportNoticeDetail>().Count(m => m.IsDel == "0" && m.SONo == exNoticeDetail.SONo && m.CompleteQty < m.Qty); + if (num <= 0) + { + exNotice.Status = "4"; //鏇存敼涓烘墽琛屽畬鎴� + } + //淇敼鍑哄簱鍗曚俊鎭� + Db.Updateable(exNotice).ExecuteCommand(); + + //淇敼鍑哄簱鍗曟槑缁嗘嫞璐ф暟閲� + exNoticeDetail.CompleteQty += sd2.Qty; + Db.Updateable(exNoticeDetail).ExecuteCommand(); + } + break; + #endregion + + #region 绉诲簱瀹屾垚 + case "3": + //搴撳瓨鏄庣粏 + var sd3 = Db.Queryable<DataStockDetail>().First(w => w.PalletNo == taskInfo.PalletNo); + if (sd3 == null) + { + resultModel.Message = "搴撳瓨淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + if (taskInfo.Type == "0")//鍏ュ簱浠诲姟 + { + //鐩爣鍌ㄤ綅淇℃伅 + var endLocatInfo2 = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.EndLocat && w.IsDel == "0"); + if (endLocatInfo2 == null) + { + resultModel.Message = "鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + endLocatInfo2.Status = "1";//鏈夌墿鍝� + //淇敼鐩爣鍌ㄤ綅鐘舵�� + Db.Updateable(endLocatInfo2).ExecuteCommand(); + + sd3.WareHouseNo = endLocatInfo2.WareHouseNo;//鎵�灞炰粨搴� + sd3.RoadwayNo = endLocatInfo2.RoadwayNo;//鎵�灞炲贩閬� + sd3.AreaNo = endLocatInfo2.AreaNo;//鎵�灞炲尯鍩� + sd3.LocatNo = endLocatInfo2.LocatNo;//鍌ㄤ綅鍦板潃 + if (endLocatInfo2.AreaNo.Contains("01"))//鍑�妗跺尯 + { + sd3.PalletStatus = "0"; + } + else if (endLocatInfo2.AreaNo.Contains("02"))//棰勬贩鍖� + { + sd3.PalletStatus = "1"; + } + else if (endLocatInfo2.AreaNo.Contains("03"))//鍗婃垚鍝佸尯 + { + sd3.PalletStatus = "2"; + } + else if (endLocatInfo2.AreaNo.Contains("04"))//鑴忔《鍖� + { + sd3.PalletStatus = "3"; + sd3.LotNo = "";//鎵规 + sd3.SkuNo = ""; + sd3.SkuName = ""; + sd3.InspectStatus = "0";//寰呮楠� + } + } + else if (taskInfo.Type == "1")//鍑哄簱浠诲姟 + { + //璧峰鍌ㄤ綅淇℃伅 + var startLocatInfo2 = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.StartLocat && w.IsDel == "0"); + if (startLocatInfo2 == null) + { + resultModel.Message = "璧峰鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + startLocatInfo2.Status = "0";//绌哄偍浣� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(startLocatInfo2).ExecuteCommand(); + + sd3.WareHouseNo = "";//鎵�灞炰粨搴� + sd3.RoadwayNo = "";//鎵�灞炲贩閬� + sd3.AreaNo = "";//鎵�灞炲尯鍩� + sd3.LocatNo = "";//鍌ㄤ綅鍦板潃 + } + else if (taskInfo.Type == "2")//绉诲簱浠诲姟 + { + //璧峰鍌ㄤ綅淇℃伅 + var startLocatInfo2 = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.StartLocat && w.IsDel == "0"); + if (startLocatInfo2 == null) + { + resultModel.Message = "璧峰鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + startLocatInfo2.Status = "0";//绌哄偍浣� + //淇敼璧峰鍌ㄤ綅鐘舵�� + Db.Updateable(startLocatInfo2).ExecuteCommand(); + + //鐩爣鍌ㄤ綅淇℃伅 + var endLocatInfo2 = Db.Queryable<SysStorageLocat>().First(w => w.LocatNo == taskInfo.EndLocat && w.IsDel == "0"); + if (endLocatInfo2 == null) + { + resultModel.Message = "鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�!"; + return resultModel; + } + endLocatInfo2.Status = "1";//鏈夌墿鍝� + //淇敼鐩爣鍌ㄤ綅鐘舵�� + Db.Updateable(endLocatInfo2).ExecuteCommand(); + + sd3.WareHouseNo = endLocatInfo2.WareHouseNo;//鎵�灞炰粨搴� + sd3.RoadwayNo = endLocatInfo2.RoadwayNo;//鎵�灞炲贩閬� + sd3.AreaNo = endLocatInfo2.AreaNo;//鎵�灞炲尯鍩� + sd3.LocatNo = endLocatInfo2.LocatNo;//鍌ㄤ綅鍦板潃 + sd3.Status = "0"; + if (endLocatInfo2.AreaNo.Contains("01"))//娲佸噣鍖� + { + sd3.PalletStatus = "0"; + sd3.Status = "0"; + } + else if (endLocatInfo2.AreaNo.Contains("02"))//棰勬贩鍖� + { + sd3.PalletStatus = "1"; + } + else if (endLocatInfo2.AreaNo.Contains("03"))//鍗婃垚鍝佸尯 + { + sd3.PalletStatus = "2"; + } + else if (endLocatInfo2.AreaNo.Contains("04"))//鑴忔《鍖� + { + sd3.PalletStatus = "3"; + sd3.LotNo = "";//鎵规 + sd3.SkuNo = ""; + sd3.SkuName = ""; + sd3.InspectStatus = "0";//寰呮楠� + } + } + //淇敼搴撳瓨鏄庣粏 + Db.Updateable(sd3).ExecuteCommand(); + + #region 鍘绘帀MES + //鍥炰紶妗剁姸鎬佺粰MES + //BackPalletStatus(taskInfo.PalletNo, sd3.PalletStatus); + #endregion + + break; + #endregion + } + taskInfo.Status = "2";//鎵ц瀹屾垚 + //淇敼浠诲姟鐘舵�� + Db.Updateable(taskInfo).ExecuteCommand(); + + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + resultModel.Success = 0; + resultModel.Message = "鎴愬姛"; + return resultModel; + } + catch (Exception ex) + { + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + throw ex; + } + } + + /// <summary> + /// 鍥炰紶妗剁姸鎬佺粰MES + /// </summary> + /// <param name="PalletNo">妗跺彿</param> + /// <param name="Status">0锛氬噣妗� 1锛氶娣� 2锛氬崐鎴愬搧 3锛氳剰妗�</param> + /// <param name="url"></param> + public void BackPalletStatus(string PalletNo, string Status,string url="") + { + try + { + var obj = new + { + PalletNo = PalletNo, + Status = Status + }; + string jsonReq = JsonConvert.SerializeObject(obj); + var response = HttpHelper.DoPost(url, jsonReq, "鍥炰紶MES妗剁姸鎬�", "MES").ToString(); + var result = JsonConvert.DeserializeObject<ReMes>(response);//瑙f瀽杩斿洖鏁版嵁 + } + catch (Exception ex) + { + throw ex; + } + } + + /// <summary> + /// 涓嬪彂鍑哄簱鍗� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + public SoResInfo CreateSoWork(SoInfo model) + { + try + { + if (string.IsNullOrEmpty(model.OrderCode)) + { + throw new Exception("涓婃父绯荤粺鍗曞彿涓嶅彲涓虹┖!"); + } + if (model.SoDetails.Count <= 0) + { + throw new Exception("鍑哄簱鍗曟槑缁嗕笉鍙负绌�!"); + } + //杩斿洖淇℃伅 + SoResInfo result = new SoResInfo(); + + var skuNos = model.SoDetails.Select(a => a.SkuNo).Distinct().ToList(); + //鑾峰彇搴撳瓨鏄庣粏 + var stockDetailList = Db.Queryable<DataStockDetail>().Where(s => skuNos.Contains(s.SkuNo) && (s.Qty - s.FrozenQty - s.LockQty) > 0 && s.InspectStatus == "1").ToList(); + var billNo = ""; + var bl = true; + do + { + //鑾峰彇鑷鍗曟嵁鍙� + billNo = new Common().GetMaxNo("SO"); + var no = billNo; + bl = Db.Queryable<BllExportNotice>().Any(m => m.SONo == no); + } while (bl); + + List<SoDetailInfo> soDetailList = new List<SoDetailInfo>(); + //寮�鍚簨鍔� + Db.BeginTran(); + + var list = new List<BllExportNoticeDetail>(); + //娣诲姞鍑哄簱鍗� + foreach (var d in model.SoDetails) + { + if (d.Qty < 1) + { + throw new Exception("鍑哄簱鏁伴噺蹇呴』澶т簬0"); + } + if (string.IsNullOrWhiteSpace(d.LotNo)) + { + throw new Exception("鎵规涓嶅彲涓虹┖!"); + } + //搴撳瓨鏄庣粏 + List<DataStockDetail> stockDetails = stockDetailList.Where(s => s.SkuNo == d.SkuNo && s.LotNo == d.LotNo).OrderByDescending(o => o.CompleteTime).ToList(); + if (stockDetails.Count < 1) + { + throw new Exception($"搴撳瓨涓湭鏌ヨ鍒板嚭搴撶墿鏂欎俊鎭�:{d.SkuNo}"); + } + //鍒ゆ柇鏁伴噺 + var qty = stockDetails.Sum(s => s.Qty - s.FrozenQty - s.LockQty); + if (d.Qty > qty) + { + throw new Exception($"搴撳瓨涓嚭搴撶墿鏂欎俊鎭�:{d.SkuNo}銆亄d.LotNo} 搴撳瓨鏁伴噺涓嶈冻"); + } + //娣诲姞鍑哄簱鍗曟槑缁� + var noticeDetail = new BllExportNoticeDetail() + { + SONo = billNo, + SkuNo = d.SkuNo, + SkuName = d.SkuName, + Standard = "", + LotNo = d.LotNo, + LotText = "", + Qty = d.Qty, + AllotQty = 0, + FactQty = 0, + CompleteQty = 0, + PackagNo = "", + Price = 0, + Money = 0, + IsBale = "", + IsBelt = "", + SupplierLot = "", + IsWave = "0", + WaveNo = "", + IsIssueLotNo = "1", + + OrderDetailCode = d.OrderDetailCode, + + CreateUser = 0, + }; + list.Add(noticeDetail); + //閿佸畾搴撳瓨鏁伴噺 + decimal lockQty = 0; + foreach (var item in stockDetails) + { + if (lockQty >= d.Qty) + { + break; + } + if (item.Qty - item.LockQty - item.FrozenQty <= d.Qty - lockQty) + { + item.LockQty += item.Qty - item.LockQty - item.FrozenQty; + lockQty += (decimal)(item.Qty - item.LockQty - item.FrozenQty); + } + else + { + item.LockQty += d.Qty - lockQty; + lockQty += d.Qty - lockQty; + } + Db.Updateable(item).UpdateColumns(it => new { it.LockQty }).ExecuteCommand(); + } + + SoDetailInfo soDetail = new SoDetailInfo(); + soDetail.OrderDetailCode = d.OrderDetailCode; + soDetail.LockQty = d.Qty; + soDetail.LotNo = d.LotNo; + + soDetailList.Add(soDetail); + } + //鍑哄簱鍗曚俊鎭� + var notice = new BllExportNotice() + { + SONo = billNo, + OrderCode = model.OrderCode, + Type = model.SoType, + Status = "0", + Origin = "WMS", + CustomerNo = model.Customer, + CustomerName = "", + LogisticsId = null, + IsWave = "0", + WaveNo = "", + IsDespatch = "0", + + CreateUser = 0, + }; + + var n = Db.Insertable<BllExportNotice>(notice).ExecuteCommand(); + var m = Db.Insertable<BllExportNoticeDetail>(list).ExecuteCommand(); + + if (n <= 0 || m <= 0) + { + Db.RollbackTran(); + throw new Exception("鎿嶄綔澶辫触"); + } + //鎻愪氦浜嬪姟 + Db.CommitTran(); + //鍥炰紶涓婃父绯荤粺閿佸畾鏁伴噺淇℃伅 + result.Success = "0"; + result.Message = "鎿嶄綔鎴愬姛"; + result.SoDetails = soDetailList; + return result; + } + catch (Exception ex) + { + Db.RollbackTran(); + throw new Exception(ex.Message); + } + } } } -- Gitblit v1.8.0