From 86e443e42c4bee972c5b795def4917e02f98ce40 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期五, 11 七月 2025 16:45:08 +0800 Subject: [PATCH] 修改问题 --- Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs | 1002 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 868 insertions(+), 134 deletions(-) diff --git a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs index 2c3e986..0c2ac49 100644 --- a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs +++ b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs @@ -1,12 +1,18 @@ 锘縰sing System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Tasks; +using Dm; +using Model.InterFaceModel; +using Model.ModelDto; using Model.ModelDto.BllCheckDto; using Model.ModelDto.PdaDto; +using Newtonsoft.Json; using SqlSugar; using Utility; +using Utility.Tools; using WMS.BLL.LogServer; using WMS.DAL; using WMS.Entity.BllAsnEntity; @@ -414,7 +420,7 @@ public async Task<List<DataStockDetail>> GetStockQueryList(string locatNo, string palletNo) { return await Db.Queryable<DataStockDetail>() - .Where(s => s.IsDel == "0" && s.LocatNo.Contains(locatNo) && s.PalletNo.Contains(palletNo)) + .Where(s => s.IsDel == "0" && s.LocatNo.Contains(locatNo) || s.PalletNo.Contains(palletNo)) .OrderBy(s => new { s.LotNo, s.LocatNo, s.PalletNo }) .ToListAsync(); @@ -685,7 +691,7 @@ { throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); } - if (models.WareHouseNo != "W02") + if (models.WareHouseNo != "W04") { throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!"); } @@ -715,7 +721,7 @@ { throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); } - if (models.WareHouseNo != "W02") + if (models.WareHouseNo != "W04") { throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!"); } @@ -725,14 +731,9 @@ throw Oops.Bah("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); } - if (storageLocat.AreaNo.Contains("B0")) - { - storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B0") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToListAsync(); - } - else - { - storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo.Contains("B1") && w.WareHouseNo == "W02").OrderBy(o => o.AreaNo).ToListAsync(); - } + + storageArea = await Db.Queryable<SysStorageArea>().Where(w => w.IsDel == "0" && w.Status == "0" && w.AreaNo != storageLocat.AreaNo && w.WareHouseNo == "W04").OrderBy(o => o.AreaNo).ToListAsync(); + } return storageArea; } @@ -778,123 +779,332 @@ /// <param name="palletNo"></param> /// <param name="areaNo"></param> /// <param name="ruku"></param> - public async Task AgvTransport(string palletNo, string areaNo, string ruku, int userId) + public async Task AgvTransport(string palletNo, string areaNo, string ruku, string url, int userId) { - if (string.IsNullOrEmpty(palletNo)) + try { - throw Oops.Bah("璇锋壂鎻忔墭鐩樻潯鐮侊紒"); - } - if (string.IsNullOrEmpty(areaNo) && string.IsNullOrEmpty(ruku)) - { - throw Oops.Bah("璇烽�夋嫨鐩爣鍖哄煙鎴栧叆搴撳彛锛�"); - } - if (!string.IsNullOrEmpty(areaNo) && !string.IsNullOrEmpty(ruku)) - { - throw Oops.Bah("鐩爣鍖哄煙鍜屽叆搴撳彛涓嶈兘鍚屾椂閫夋嫨锛�"); - } - string EndLocat = string.Empty;//鐩爣浣嶇疆 + if (string.IsNullOrEmpty(palletNo)) + { + throw Oops.Bah("璇锋壂鎻忔墭鐩樻潯鐮侊紒"); + } + if (string.IsNullOrEmpty(areaNo) && string.IsNullOrEmpty(ruku)) + { + throw Oops.Bah("璇烽�夋嫨鐩爣鍖哄煙鎴栧叆搴撳彛锛�"); + } + if (!string.IsNullOrEmpty(areaNo) && !string.IsNullOrEmpty(ruku)) + { + throw Oops.Bah("鐩爣鍖哄煙鍜屽叆搴撳彛涓嶈兘鍚屾椂閫夋嫨锛�"); + } + string EndLocat = string.Empty;//鐩爣浣嶇疆 - var log = await Db.Queryable<LogTask>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1")); - if (log != null) - { - throw Oops.Bah("璇ユ墭鐩樺凡鏈夊皬杞︾瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�!"); + var log = await Db.Queryable<LogTask>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1")); + if (log != null) + { + throw Oops.Bah("璇ユ墭鐩樺凡鏈夌瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�!"); + } + var stockDetail = await Db.Queryable<DataStockDetail>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo); + if (stockDetail == null) + { + throw Oops.Bah("鎵樼洏涓婄墿鏂欏簱瀛樻槑缁嗕俊鎭笉瀛樺湪,璇锋鏌�!"); + } + if (!string.IsNullOrEmpty(areaNo)) + { + var storageArea = await Db.Queryable<SysStorageArea>().FirstAsync(w => w.IsDel == "0" && w.AreaNo == areaNo); + if (storageArea == null) + { + throw Oops.Bah("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!"); + } + EndLocat = await GetLocat(areaNo); + } + else + { + EndLocat = ruku; + } + var stock = await Db.Queryable<DataStock>().FirstAsync(w => w.IsDel == "0" && w.SkuNo == stockDetail.SkuNo && w.LotNo == stockDetail.LotNo); + if (stock == null) + { + throw Oops.Bah("鎵樼洏涓婄墿鏂欏簱瀛樹俊鎭笉瀛樺湪,璇锋鏌�!"); + } + if (string.IsNullOrEmpty(stockDetail.LocatNo)) + { + throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); + } + if (stockDetail.WareHouseNo != "W04") + { + throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!"); + } + //璧峰鍌ㄤ綅淇℃伅 + var storageLocat = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == stockDetail.LocatNo); + if (storageLocat == null) + { + throw Oops.Bah("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); + } + //鐩爣鍌ㄤ綅淇℃伅 + //var storageLocatEnd = new SysStorageLocat(); + + var storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0"); + if (storageLocatEnd == null) + { + throw Oops.Bah("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); + } + + + //娣诲姞鍑哄簱浠诲姟 + var taskNo = new Common().GetMaxNo("TK"); + var moveTask = new LogTask + { + TaskNo = taskNo, + Sender = "WMS", + Receiver = "WCS", + IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + + StartLocat = stockDetail.LocatNo,//璧峰浣嶇疆 + EndLocat = EndLocat,//鐩爣浣嶇疆 + PalletNo = palletNo,//鎵樼洏鐮� + Msg = string.Format("杞繍浠诲姟锛歿0}=>>{1}", stockDetail.LocatNo, EndLocat), + IsSend = 1,//鏄惁鍙啀娆′笅鍙� + IsCancel = 1,//鏄惁鍙彇娑� + IsFinish = 1,//鏄惁鍙畬鎴� + Type = "2",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗� 2 鐩樼偣鍗� 3 绉诲簱鍗� + + CreateTime = DateTime.Now + }; + await Db.Insertable(moveTask).ExecuteCommandAsync(); + + //淇敼搴撳瓨鏄庣粏淇℃伅 + //stockDetail.Status = "4";//绉诲簱閿佸畾 + //stockDetail.LockQty = stockDetail.Qty;//閿佸畾搴撳瓨鏁伴噺 + //await Db.Updateable(stockDetail).ExecuteCommandAsync(); + ////淇敼搴撳瓨淇℃伅 + //stock.LockQty += (decimal)stockDetail.Qty; + //await Db.Updateable(stock).ExecuteCommandAsync(); + + //淇敼璧峰鍌ㄤ綅鍦板潃鐘舵�� + storageLocat.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 + await Db.Updateable(storageLocat).ExecuteCommandAsync(); + + //淇敼鐩爣鍌ㄤ綅鍦板潃鐘舵�� + if (storageLocatEnd != null) + { + storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 + await Db.Updateable(storageLocatEnd).ExecuteCommandAsync(); + } + //娣诲姞鎿嶄綔鏃ュ織璁板綍 + var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId); + + var outDto = new List<OutCommandDto> + { + new OutCommandDto() + { + TaskNo = moveTask.TaskNo, // 浠诲姟鍙� + TaskType = "2",// 浠诲姟绫诲瀷 0鍏� 1鍑� 2绉� + PalletNo = moveTask.PalletNo,//鎵樼洏鍙� + + StartLocate = moveTask.StartLocat, // 璧峰浣嶇疆 + EndLocate = EndLocat, // 鐩爣浣嶇疆 + + Order = 999, + Type = PLCTypeEnum.AGV + + } + }; + + // 姝e紡杩愯绋嬪簭鏀惧紑 + var list2 = outDto.Select(m => m.TaskNo).ToList(); + var jsonData = JsonConvert.SerializeObject(outDto); + string response = ""; + + try + { + var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss") + response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橶CS鍑哄簱鍛戒护", "WCS"); + var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss") + + //瑙f瀽杩斿洖鏁版嵁 + var wcsModel = JsonConvert.DeserializeObject<WcsModel2>(response); + if (wcsModel.code == 200) + { + // 鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�// + new TaskServer().EditTaskIssueOk(list2, time1, time2); + } + else + { + new TaskServer().EditTaskIssueNo(list2, time1, time2, wcsModel.message); + throw new Exception(wcsModel.message); + } + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + } - var stockDetail = await Db.Queryable<DataStockDetail>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo); - if (stockDetail == null) + catch (Exception e) { - throw Oops.Bah("鎵樼洏涓婄墿鏂欏簱瀛樻槑缁嗕俊鎭笉瀛樺湪,璇锋鏌�!"); + throw new Exception(e.Message); } - if (!string.IsNullOrEmpty(areaNo)) + } + /// <summary> + /// 鍛煎彨agv杞繍绌烘墭鐩� + /// </summary> + /// <param name="palletNo"></param> + /// <param name="areaNo"></param> + /// <param name="locatNo"></param> + /// <param name="url"></param> + /// <param name="userId"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public async Task AgvNullPallet(string palletNo, string areaNo, string locatNo, string url, int userId) + { + try { + if (string.IsNullOrEmpty(palletNo)) + { + throw Oops.Bah("璇锋壂鎻忔墭鐩樻潯鐮侊紒"); + } + if (string.IsNullOrEmpty(locatNo)) + { + throw Oops.Bah("璇锋壂鎻忚捣濮嬪湴鐮侊紒"); + } + if (string.IsNullOrEmpty(areaNo)) + { + throw Oops.Bah("璇烽�夋嫨鐩爣鍖哄煙锛�"); + } + string EndLocat = string.Empty;//鐩爣浣嶇疆 + + var log = await Db.Queryable<LogTask>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo && (w.Status == "0" || w.Status == "1")); + if (log != null) + { + throw Oops.Bah("璇ユ墭鐩樺凡鏈夌瓑寰呮墽琛屾垨姝e湪鎵ц鐨勪换鍔�!"); + } + var stockDetail = await Db.Queryable<DataStockDetail>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo); + if (stockDetail != null) + { + throw Oops.Bah("鎵樼洏涓婄墿鏂欏瓨鍦ㄥ簱瀛樻槑缁嗕俊鎭�,璇锋鏌�!"); + } + var storageArea = await Db.Queryable<SysStorageArea>().FirstAsync(w => w.IsDel == "0" && w.AreaNo == areaNo); if (storageArea == null) { throw Oops.Bah("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!"); } - EndLocat = await GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo, palletNo); - } - else - { - EndLocat = ruku; - } - var stock = await Db.Queryable<DataStock>().FirstAsync(w => w.IsDel == "0" && w.SkuNo == stockDetail.SkuNo && w.LotNo == stockDetail.LotNo); - if (stock == null) - { - throw Oops.Bah("鎵樼洏涓婄墿鏂欏簱瀛樹俊鎭笉瀛樺湪,璇锋鏌�!"); - } - if (string.IsNullOrEmpty(stockDetail.LocatNo)) - { - throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); - } - if (stockDetail.WareHouseNo != "W02") - { - throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!"); - } - //璧峰鍌ㄤ綅淇℃伅 - var storageLocat = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == stockDetail.LocatNo); - if (storageLocat == null) - { - throw Oops.Bah("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); - } - //鐩爣鍌ㄤ綅淇℃伅 - var storageLocatEnd = new SysStorageLocat(); - if (!string.IsNullOrEmpty(areaNo)) - { - storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0" && w.Status == "0"); + var palletInfo = await Db.Queryable<SysPallets>().FirstAsync(w => w.IsDel == "0" && w.PalletNo == palletNo); + if (palletInfo == null) + { + throw Oops.Bah("璇ユ墭鐩樹俊鎭笉瀛樺湪!"); + } + if (palletInfo.Status!="0") + { + throw Oops.Bah("璇ユ墭鐩樹笉鏄┖鎵樼洏!"); + } + //鏍规嵁鐩爣鍖哄煙鑾峰彇鐩爣鍌ㄤ綅鍦板潃 + EndLocat = await GetLocat(areaNo); + + //璧峰鍌ㄤ綅淇℃伅 + var storageLocat = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == locatNo); + if (storageLocat == null) + { + throw Oops.Bah("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); + } + //鐩爣鍌ㄤ綅淇℃伅 + //var storageLocatEnd = new SysStorageLocat(); + + var storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0"); if (storageLocatEnd == null) { throw Oops.Bah("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); } + + //娣诲姞鍑哄簱浠诲姟 + var taskNo = new Common().GetMaxNo("TK"); + var moveTask = new LogTask + { + TaskNo = taskNo, + Sender = "WMS", + Receiver = "WCS", + IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 + + StartLocat = storageLocat.LocatNo,//璧峰浣嶇疆 + EndLocat = EndLocat,//鐩爣浣嶇疆 + PalletNo = palletNo,//鎵樼洏鐮� + Msg = string.Format("杞繍浠诲姟锛歿0}=>>{1}", storageLocat.LocatNo, EndLocat), + IsSend = 1,//鏄惁鍙啀娆′笅鍙� + IsCancel = 1,//鏄惁鍙彇娑� + IsFinish = 1,//鏄惁鍙畬鎴� + Type = "2",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 + Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 + OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗� 2 鐩樼偣鍗� 3 绉诲簱鍗� + + CreateTime = DateTime.Now + }; + await Db.Insertable(moveTask).ExecuteCommandAsync(); + + //淇敼璧峰鍌ㄤ綅鍦板潃鐘舵�� + storageLocat.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 + await Db.Updateable(storageLocat).ExecuteCommandAsync(); + + //淇敼鐩爣鍌ㄤ綅鍦板潃鐘舵�� + //if (storageLocatEnd != null) + //{ + // storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 + // await Db.Updateable(storageLocatEnd).ExecuteCommandAsync(); + //} + //娣诲姞鎿嶄綔鏃ュ織璁板綍 + var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV绌烘墭杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId); + + var outDto = new List<OutCommandDto> + { + new OutCommandDto() + { + TaskNo = moveTask.TaskNo, // 浠诲姟鍙� + TaskType = "2",// 浠诲姟绫诲瀷 0鍏� 1鍑� 2绉� + PalletNo = moveTask.PalletNo,//鎵樼洏鍙� + + StartLocate = moveTask.StartLocat, // 璧峰浣嶇疆 + EndLocate = EndLocat, // 鐩爣浣嶇疆 + + Order = 999, + Type = PLCTypeEnum.AGV + + } + }; + + // 姝e紡杩愯绋嬪簭鏀惧紑 + var list2 = outDto.Select(m => m.TaskNo).ToList(); + var jsonData = JsonConvert.SerializeObject(outDto); + string response = ""; + + try + { + var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss") + response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橶CS鍑哄簱鍛戒护", "WCS"); + var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss") + + //瑙f瀽杩斿洖鏁版嵁 + var wcsModel = JsonConvert.DeserializeObject<WcsModel2>(response); + if (wcsModel.code == 200) + { + // 鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�// + new TaskServer().EditTaskIssueOk(list2, time1, time2); + } + else + { + new TaskServer().EditTaskIssueNo(list2, time1, time2, wcsModel.message); + throw new Exception(wcsModel.message); + } + } + catch (Exception ex) + { + throw new Exception(ex.Message); + } + } - - //娣诲姞鍑哄簱浠诲姟 - var taskNo = new Common().GetMaxNo("TK"); - var exTask = new LogTask + catch (Exception e) { - TaskNo = taskNo, - Sender = "WMS", - Receiver = "AGV", - IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛 - - StartLocat = stockDetail.LocatNo,//璧峰浣嶇疆 - EndLocat = EndLocat,//鐩爣浣嶇疆 - PalletNo = palletNo,//鎵樼洏鐮� - Msg = string.Format("杞繍浠诲姟锛歿0}=>>{1}", stockDetail.LocatNo, EndLocat), - IsSend = 1,//鏄惁鍙啀娆′笅鍙� - IsCancel = 1,//鏄惁鍙彇娑� - IsFinish = 1,//鏄惁鍙畬鎴� - Type = "2",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟 2 绉诲簱浠诲姟 - Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚 - OrderType = "3",//0 鍏ュ簱鍗� 1 鍑哄簱鍗� 2 鐩樼偣鍗� 3 绉诲簱鍗� - - CreateTime = DateTime.Now - }; - await Db.Insertable(exTask).ExecuteCommandAsync(); - - //淇敼搴撳瓨鏄庣粏淇℃伅 - stockDetail.Status = "4";//绉诲簱閿佸畾 - stockDetail.LockQty = stockDetail.Qty;//閿佸畾搴撳瓨鏁伴噺 - await Db.Updateable(stockDetail).ExecuteCommandAsync(); - //淇敼搴撳瓨淇℃伅 - stock.LockQty += (decimal)stockDetail.Qty; - await Db.Updateable(stock).ExecuteCommandAsync(); - - //淇敼璧峰鍌ㄤ綅鍦板潃鐘舵�� - storageLocat.Status = "5";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 - await Db.Updateable(storageLocat).ExecuteCommandAsync(); - - //淇敼鐩爣鍌ㄤ綅鍦板潃鐘舵�� - if (storageLocatEnd != null) - { - storageLocatEnd.Status = "4";//0锛氱┖鍌ㄤ綅 1锛氭湁鐗╁搧 2锛氬叆搴撲腑 3锛氬嚭搴撲腑 4锛氱Щ鍏ヤ腑 5锛氱Щ鍑轰腑 - await Db.Updateable(storageLocatEnd).ExecuteCommandAsync(); + throw new Exception(e.Message); } - //娣诲姞鎿嶄綔鏃ュ織璁板綍 - var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId); - - #region 鍛煎彨灏忚溅浠g爜 - - #endregion } /// <summary> /// agv杞繍鍛煎彨灏忚溅鍙栬揣 @@ -968,7 +1178,7 @@ throw Oops.Bah($"鎵樼洏鍙凤細{item.PalletNo}鎵�鍦ㄧ殑鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!"); } //鑾峰彇鐩爣鍌ㄤ綅 - EndLocat = await GetLocat(areaNo, item.SkuNo, item.LotNo, palletNo); + EndLocat = await GetLocat(areaNo); if (string.IsNullOrEmpty(EndLocat)) { throw Oops.Bah("鍒嗛厤鐩爣鍌ㄤ綅澶辫触,璇锋鏌�!"); @@ -1050,35 +1260,30 @@ /// <param name="skuNo"></param> /// <param name="lotNo"></param> /// <returns></returns> - private async Task<string> GetLocat(string areaNo, string skuNo, string lotNo, string palletNo, string hasLocatNoList = "") + private async Task<string> GetLocat(string areaNo) { string endLocat = string.Empty;//鐩爣鍌ㄤ綅 - //褰撶劧鍖哄煙鎵�鏈夊偍浣嶄俊鎭� - var storageLocatList = await Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W02" && w.AreaNo == areaNo).ToListAsync(); - //鍚屽尯鍩熷悓鎵规鐗╂枡鐨勫偍浣嶄俊鎭� - List<string> locatList = await Db.Queryable<DataStockDetail>().Where(w => w.IsDel == "0" && w.SkuNo == skuNo && w.LotNo == lotNo && w.WareHouseNo == "W02" && w.AreaNo == areaNo && w.PalletNo != palletNo) - .OrderByDescending(o => o.LocatNo).Select(s => s.LocatNo).Distinct().ToListAsync(); - foreach (var item in locatList) - { - var locatInfo = storageLocatList.Where(w => w.LocatNo == item).First(); + //褰撳墠鍖哄煙鎵�鏈夊偍浣嶄俊鎭� + var storageLocatList = await Db.Queryable<SysStorageLocat>().Where(w => w.WareHouseNo == "W04" && w.AreaNo == areaNo).ToListAsync(); + + var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0") + .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); - var locatInfo2 = storageLocatList.Where(w => w.IsDel == "0" && w.Status == "0" && w.Flag == "0" && w.LocatNo != locatInfo.LocatNo && w.Row == locatInfo.Row && !hasLocatNoList.Contains(w.LocatNo)) - .OrderByDescending(o => o.Column).First(); - if (locatInfo2 != null) - { - endLocat = locatInfo2.LocatNo; - } - } - if (string.IsNullOrEmpty(endLocat)) + if (locatInfo2 != null) { - var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0" && w.Status == "0" && !hasLocatNoList.Contains(w.LocatNo)) - .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); - - if (locatInfo3 != null) - { - endLocat = locatInfo3.LocatNo; - } + endLocat = locatInfo2.LocatNo; } + + //if (string.IsNullOrEmpty(endLocat)) + //{ + // var locatInfo3 = storageLocatList.Where(w => w.IsDel == "0" && w.Flag == "0") + // .OrderByDescending(m => m.Layer).OrderByDescending(m => m.Column).OrderByDescending(m => m.Row).First(); + + // if (locatInfo3 != null) + // { + // endLocat = locatInfo3.LocatNo; + // } + //} return endLocat; } #endregion @@ -1164,5 +1369,534 @@ } } #endregion + + #region 绠辩爜鎷嗙璐存爣銆佷汉宸ョ‘璁ゆ敹璐� + /// <summary> + /// 鎷嗙娣诲姞鏍囩 + /// </summary> + /// <param name="boxNo"></param> + /// <param name="devanQty"></param> + /// <param name="userId"></param> + public BoxListInfoDto AddLableByDevanning(string boxNo, decimal devanQty, int userId) + { + try + { + if (string.IsNullOrEmpty(boxNo)) + { + throw new Exception("绠辩爜涓嶈兘涓虹┖"); + } + //寮�鍚簨鍔� + Db.BeginTran(); + + //搴撳瓨绠辨敮鏄庣粏淇℃伅 + var boxList = Db.Queryable<DataBoxInfo>().Where(w => w.IsDel == "0" && w.BoxNo == boxNo).ToList(); + if (boxList.Count != 1) + { + throw new Exception("璇ョ鐮佷俊鎭敊璇紝瀛樺湪澶氫釜姝ょ鐮佷俊鎭�"); + } + var boxInfo = boxList.First(); + if (boxInfo.Qty<=devanQty) + { + throw new Exception("鎷嗙鏁伴噺澶х瓑浜庡綋鍓嶇鍐呮暟閲�"); + } + + boxInfo.Qty -= devanQty; + boxInfo.BitBoxMark = "1"; + //鏇存柊绠辩爜搴撳瓨琛� + Db.Updateable(boxInfo).ExecuteCommand(); + + var boxStr = boxInfo.BoxNo.Substring(0, boxInfo.BoxNo.Length - 6);//鑾峰彇绠辩爜鍓嶇紑-闄ゅ悗鍏綅娴佹按澶� + var maxBoxCode1 = Db.Queryable<BllBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0" && m.Origin == "WMS鐢熸垚").Max(a => a.BoxNo); + + var maxBoxCode2 = Db.Queryable<DataBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0").Max(a => a.BoxNo); + //濡傛灉缁撴灉涓�0锛屽垯璇存槑涓や釜瀛楃涓茬浉绛夛紱 ABC BCE + //濡傛灉缁撴灉灏忎簬0锛屽垯璇存槑绗竴涓瓧绗︿覆灏忎簬绗簩涓瓧绗︿覆锛� + //濡傛灉缁撴灉澶т簬0锛屽垯璇存槑绗竴涓瓧绗︿覆澶т簬绗簩涓瓧绗︿覆銆� + var maxBoxCode = maxBoxCode1; + var bol = String.CompareOrdinal(maxBoxCode1, maxBoxCode2); + if (bol<0) + { + maxBoxCode = maxBoxCode2; + } + var boxNoNew = maxBoxCode.Substring(0, maxBoxCode.Length - 6) + (int.Parse(maxBoxCode.Substring(maxBoxCode.Length - 6, 6)) + 1).ToString().PadLeft(6, '0'); + + // 娣诲姞鏂扮鐮佷俊鎭� + var boxModel = new DataBoxInfo() + { + StockDetailId = boxInfo.StockDetailId, + PalletNo = boxInfo.PalletNo, + BoxNo = boxNoNew, + Qty = devanQty, + FullQty = boxInfo.FullQty, + + Status = "2",//0锛氭湭缁勬墭 1锛氬凡缁勬墭 2锛氬凡鍏ュ簱 3锛氬凡鍑哄簱 4:宸插垎閰� 5锛氬凡鎷h揣 + LotNo = boxInfo.LotNo, + LotText = boxInfo.LotText, + SkuNo = boxInfo.SkuNo, + SkuName = boxInfo.SkuName, + Standard = boxInfo.Standard, + + SupplierLot = boxInfo.SupplierLot, + InspectStatus = boxInfo.InspectStatus, + InspectMark = boxInfo.InspectMark, + BitBoxMark = "1", + ProductionTime = boxInfo.ProductionTime, + ExpirationTime = boxInfo.ExpirationTime, + + CreateUser = 0, + CreateTime = DateTime.Now + }; + + Db.Insertable(boxModel).ExecuteCommand(); + + //娣诲姞鎿嶄綔鏃ュ織 + new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "鎿嶄綔鏃ュ織", boxNo, "缂栬緫", $"鎷嗙璐存爣锛氬師绠辩爜锛歿boxNo}鎷嗙锛屾坊鍔犳柊绠辩爜{boxNoNew}", userId); + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + #region 鑾峰彇鎷嗙鐨勪俊鎭墦鍗� + + + var data = new BoxListInfoDto() + { + SkuNo = boxInfo.SkuNo, + SkuName = boxInfo.SkuName, + LotNo = boxInfo.LotNo, + BoxNoList = new List<string>() { boxNoNew } , + Date1 = boxInfo.ProductionTime == null ? "" : Convert.ToDateTime(boxInfo.ProductionTime).ToString("yyyy-MM-dd"), + Date2 = boxInfo.ExpirationTime == null ? "" : Convert.ToDateTime(boxInfo.ExpirationTime).ToString("yyyy-MM-dd"), + }; + + #endregion + + return data; + } + catch (Exception e) + { + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + throw new Exception(e.Message); + } + } + + + public string GetReceiptSoNoByPallet(string palletNo) + { + try + { + var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.PalletNo == palletNo).GroupBy(m=>m.SONo).Select(m=>m.SONo).ToList(); + if (stockDetail.Count == 0) + { + throw new Exception("娌℃湁鏌ヨ鍒版墭鐩樺簱瀛樹俊鎭�"); + } + if (stockDetail.Count != 1) + { + throw new Exception("搴撳瓨鎵樼洏涓嶆槸鍞竴鍑哄簱鍗�"); + } + var detail = stockDetail.First(); + if (string.IsNullOrWhiteSpace(detail)) + { + throw new Exception("鎵樼洏娌℃湁鍑哄簱鍗曚俊鎭�"); + } + //var task = Db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "5"); + //if (task == null) + //{ + // throw new Exception("娌℃湁鏌ヨ鍒版墭鐩樹换鍔′俊鎭�"); + //} + //if (task.Status != "5") + //{ + // throw new Exception("浠诲姟鐘舵�佷笉鏄瓑寰呯‘璁�"); + //} + return detail; + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + + /// <summary> + /// 浜哄伐纭鏀惰揣 + /// </summary> + /// <param name="palletNo"></param> + /// <param name="userId"></param> + public void ConfirmReceipt(string palletNo, int userId) + { + try + { + Db.BeginTran(); + //var task = Db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "5"); + //if (task == null) + //{ + // throw new Exception("娌℃湁鏌ヨ鍒版墭鐩樹换鍔′俊鎭�"); + //} + //if (task.Status != "5") + //{ + // throw new Exception("浠诲姟鐘舵�佷笉鏄瓑寰呯‘璁�"); + //} + ////浠诲姟鐘舵�佸彉鏇翠负鎵ц瀹屾垚 + //task.Status = "2"; + //Db.Updateable(task).ExecuteCommand(); + var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).ToList(); + if (stockDetail.Count == 0) + { + throw new Exception("搴撳瓨鎵樼洏娌℃湁淇℃伅"); + } + var locate = stockDetail.First().LocatNo; + var locatList = Db.Queryable<SysStorageLocat>().Where(m=>m.WareHouseNo == "W04" && (m.AreaNo == "B06" || m.AreaNo == "B07" || m.AreaNo == "B09") && m.IsDel == "0").ToList(); + var locat = locatList.FirstOrDefault(m => m.LocatNo == locate); + //鍒ゆ柇鎵樼洏鍌ㄤ綅鏄惁鍦ㄨ溅闂� + if (locat == null) + { + throw new Exception("鍌ㄤ綅淇℃伅娌℃湁鍦ㄨ溅闂村伐浣嶄笂"); + } + locat.Status = "0"; + Db.Updateable(locat).ExecuteCommand(); + //鍒ゆ柇鎵樼洏淇℃伅 + + foreach (var item in stockDetail) + { + if (item.UDF5 != "1" || string.IsNullOrWhiteSpace(item.SONo)) + { + continue; + } + + //item.WareHouseNo = ""; + //item.RoadwayNo = ""; + //item.AreaNo = ""; + item.LocatNo = ""; + //item.PalletNo = ""; + item.LockQty = 0; // 閿佸畾鏁伴噺鏇翠负0 + item.Status = "0"; // 鐘舵�佸彉涓哄緟鍒嗛厤 + var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.StockDetailId == item.Id).ToList(); + foreach (var item2 in boxInfo) + { + item2.Status = "2"; //鐘舵�佸彉涓哄凡鍏ュ簱 + } + + Db.Updateable(boxInfo).ExecuteCommand(); + } + Db.Updateable(stockDetail).ExecuteCommand(); + //鎵樼洏鍙樻洿鐘舵�� + //var pallet = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo); + //if (pallet == null) + //{ + // throw new Exception("娌℃湁鏌ヨ鍒版墭鐩樹俊鎭�"); + //} + //pallet.Status = "0"; + //Db.Updateable(pallet).ExecuteCommand(); + //娣诲姞鎿嶄綔鏃ュ織 + new OperationCrServer().AddLogOperationCr("PDA妯″潡", "杞﹂棿鏀惰揣", palletNo, "瀹屾垚", $"杞﹂棿鏀惰揣锛歿palletNo}鎵樼洏鏀惰揣", userId); + Db.CommitTran(); + } + catch (Exception e) + { + Db.RollbackTran(); + throw new Exception(e.Message); + } + } + + + + #endregion + + #region 鐗╂枡鎷嗘墭 锛堟爣绛俱�佹暟閲忥級 + + /// <summary> + /// 鏌ヨ绠变俊鎭� + /// </summary> + /// <param name="boxNo"></param> + /// <param name="pallNo"></param> + public void GetBoxInfo(string boxNo,string pallNo) + { + try + { + var boxInfo = Db.Queryable<DataBoxInfo>().Where(m=>m.IsDel == "0" && m.BoxNo == boxNo).ToList(); + if (!string.IsNullOrWhiteSpace(pallNo)) + { + boxInfo = boxInfo.Where(m=>m.PalletNo == pallNo).ToList(); + } + if (boxInfo.Count!=1) + { + throw new Exception("鏍囩淇℃伅閿欒锛岃鑱旂郴绠$悊鍛�"); + } + + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + public void UpPalletByBox(string boxNo,string pallet,string palletNew,int userId) + { + try + { + Db.BeginTran(); + if (string.IsNullOrWhiteSpace(boxNo) || string.IsNullOrWhiteSpace(pallet) || string.IsNullOrWhiteSpace(palletNew)) + { + throw new Exception("鍙傛暟閿欒锛屾墭鐩樸�佹柊鎵樼洏銆佺鐮佸潎涓嶈兘涓虹┖"); + } + var boxInfoList = Db.Queryable<DataBoxInfo>().Where(m=>m.IsDel == "0" && m.BoxNo == boxNo).ToList(); + if (boxInfoList.Count != 1) + { + throw new Exception("鏍囩淇℃伅鏁伴噺涓嶆槸1鏉�"); + } + var boxInfo = boxInfoList.First(); + var detail1 = Db.Queryable<DataStockDetail>().First(m=>m.IsDel == "0" && m.PalletNo == pallet && m.Id == boxInfo.StockDetailId ); + if (detail1 == null) + { + throw new Exception("鏈煡璇㈠埌鎵樼洏鍜岀鐮佺殑搴撳瓨鏄庣粏"); + } + var palletInfoNew = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNew); + if (palletInfoNew == null) + { + throw new Exception("鏈煡璇㈠埌鏂版墭鐩樹俊鎭�"); + } + var detailNewBl = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNew && (m.SkuNo != boxInfo.SkuNo || m.LotNo != boxInfo.LotNo)); + if (detailNewBl!=null) + { + throw new Exception("鏂版墭鐩樹笂宸叉湁鍏朵粬鐗╂枡绠变俊鎭�"); + } + //娣诲姞/鏇存柊搴撳瓨鎵樼洏淇℃伅 + var detailNew1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNew && m.SkuNo == boxInfo.SkuNo && m.LotNo == boxInfo.LotNo); + var newId = 0; + if (detailNew1 == null)//add + { + var detailNew = new DataStockDetail(); + detailNew.SkuNo = detail1.SkuNo; + detailNew.SkuName = detail1.SkuName; + detailNew.LotNo = detail1.LotNo; + detailNew.LotText = detail1.LotText; + detailNew.SupplierLot = detail1.SupplierLot; + detailNew.SupplierNo = detail1.SupplierNo; + detailNew.SupplierName = detail1.SupplierName; + detailNew.Standard = detail1.Standard; + detailNew.Qty = boxInfo.Qty; + detailNew.LockQty = 0; + detailNew.FrozenQty = 0; + detailNew.InspectQty = 0; + detailNew.ASNNo = ""; + + detailNew.PalletNo = palletNew; + detailNew.ProductionTime = detail1.ProductionTime; + detailNew.ExpirationTime = detail1.ExpirationTime; + detailNew.PalletTags = "0"; + detailNew.CompleteTime = DateTime.Now; + detailNew.Status = "0"; + detailNew.InspectMark = detail1.InspectMark; + detailNew.BitPalletMark = "1"; + detailNew.InspectStatus = detail1.InspectStatus; + detailNew.PackagNo = detail1.PackagNo; + detailNew.IsBale = detail1.IsBale; + detailNew.IsBelt = detail1.IsBelt; + detailNew.IsDel = "0"; + detailNew.CreateTime = DateTime.Now; + detailNew.CreateUser = 0; + + + newId = Db.Insertable(detailNew).ExecuteReturnIdentity(); + } + else //update + { + detailNew1.Qty += boxInfo.Qty; + detailNew1.PalletNo = palletNew; + + Db.Updateable(detailNew1).ExecuteCommand(); + newId = detailNew1.Id; + } + //鏇存柊鎵樼洏鐘舵�� + palletInfoNew.Status = "1"; + Db.Updateable(palletInfoNew).ExecuteCommand(); + + //鏇存敼鍘熸墭鐩樹俊鎭� + detail1.Qty -= boxInfo.Qty; + detail1.BitPalletMark = "1"; + if (detail1.Qty <= 0) + { + //鏇存柊鍘熸墭鐩樼姸鎬� + var palletInfo = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == pallet); + palletInfo.Status = "0"; + Db.Updateable(palletInfo).ExecuteCommand(); + + Db.Deleteable(detail1).ExecuteCommand(); + } + else + { + Db.Updateable(detail1).ExecuteCommand(); + } + + //鏇存柊搴撳瓨绠变俊鎭� + boxInfo.StockDetailId = newId; + boxInfo.BindNo = 0; + boxInfo.PalletNo = palletNew; + Db.Updateable(boxInfo).ExecuteCommand(); + //娣诲姞鎿嶄綔鏃ュ織 + new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "鎿嶄綔鏃ュ織", boxNo, "缂栬緫", $"鐗╂枡鎷嗘墭锛氱鐮侊細{boxNo}鎹㈡墭锛屽師鎵樼洏{pallet}锛屾柊鎵樼洏{palletNew}", userId); + + Db.CommitTran(); + } + catch (Exception e) + { + Db.RollbackTran(); + throw new Exception(e.Message); + } + } + + //鏁伴噺椤电----------------------------------------------------------------------------------------------------------------------------------------- + + /// <summary> + /// 鏍规嵁鎵樼洏鑾峰彇鎵樼洏涓婄殑鐗╂枡鎵规淇℃伅 + /// </summary> + /// <param name="palletNo"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public List<SelectSkuLotNo> GetSelectSkuLotNo(string palletNo) + { + try + { + var data = new List<SelectSkuLotNo>(); + var detailList = Db.Queryable<DataStockDetail>().Where(m=>m.IsDel == "0" && m.PalletNo == palletNo).ToList(); + + foreach (var item in detailList) + { + if (data.Count(m=>m.DetailId == item.Id.ToString()) == 0) + { + data.Add(new SelectSkuLotNo() + { + SkuNo = item.SkuNo, + SkuName = item.SkuName, + LotNo = item.LotNo, + DetailId = item.Id.ToString(), + }); + } + } + return data; + + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + + /// <summary> + /// 鎷嗘墭-鏁伴噺 + /// </summary> + /// <param name="palletNo"></param> + /// <param name="palletNoNew"></param> + /// <param name="detailId"></param> + /// <param name="qty"></param> + /// <param name="userId"></param> + /// <exception cref="Exception"></exception> + public void UpPalletByQty(string palletNo,string palletNoNew,string detailId,decimal qty,int userId) + { + try + { + Db.BeginTran(); + if (string.IsNullOrWhiteSpace(detailId) || string.IsNullOrWhiteSpace(palletNo) || string.IsNullOrWhiteSpace(palletNoNew)) + { + throw new Exception("鍙傛暟閿欒锛屾墭鐩樸�佹柊鎵樼洏銆佺墿鏂欐壒娆″潎涓嶈兘涓虹┖"); + } + if (qty<=0) + { + throw new Exception("鍙傛暟鏁伴噺涓嶈兘涓哄皬绛�0"); + } + var detailId2 = int.Parse(detailId); + var detail1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNo && m.Id == detailId2); + if (detail1 == null) + { + throw new Exception("鏈煡璇㈠埌鎵樼洏搴撳瓨鏄庣粏"); + } + var palletInfoNew = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew); + if (palletInfoNew == null) + { + throw new Exception("鏈煡璇㈠埌鏂版墭鐩樹俊鎭�"); + } + + //娣诲姞/鏇存柊搴撳瓨鎵樼洏淇℃伅 + var detailNew1 = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.PalletNo == palletNoNew && m.SkuNo == detail1.SkuNo && m.LotNo == detail1.LotNo); + var newId = 0; + if (detailNew1 == null)//add + { + var detailNew = new DataStockDetail(); + detailNew.SkuNo = detail1.SkuNo; + detailNew.SkuName = detail1.SkuName; + detailNew.LotNo = detail1.LotNo; + detailNew.LotText = detail1.LotText; + detailNew.SupplierLot = detail1.SupplierLot; + detailNew.SupplierNo = detail1.SupplierNo; + detailNew.SupplierName = detail1.SupplierName; + detailNew.Standard = detail1.Standard; + detailNew.Qty = qty; + detailNew.LockQty = 0; + detailNew.FrozenQty = 0; + detailNew.InspectQty = 0; + detailNew.ASNNo = ""; + + detailNew.PalletNo = palletNoNew; + detailNew.ProductionTime = detail1.ProductionTime; + detailNew.ExpirationTime = detail1.ExpirationTime; + detailNew.PalletTags = "0"; + detailNew.CompleteTime = DateTime.Now; + detailNew.Status = "0"; + detailNew.InspectMark = detail1.InspectMark; + detailNew.BitPalletMark = "1"; + detailNew.InspectStatus = detail1.InspectStatus; + detailNew.PackagNo = detail1.PackagNo; + detailNew.IsBale = detail1.IsBale; + detailNew.IsBelt = detail1.IsBelt; + detailNew.IsDel = "0"; + detailNew.CreateTime = DateTime.Now; + detailNew.CreateUser = 0; + + + newId = Db.Insertable(detailNew).ExecuteReturnIdentity(); + } + else //update + { + detailNew1.Qty += qty; + detailNew1.PalletNo = palletNoNew; + + Db.Updateable(detailNew1).ExecuteCommand(); + newId = detailNew1.Id; + } + //鏇存柊鎵樼洏鐘舵�� + palletInfoNew.Status = "1"; + Db.Updateable(palletInfoNew).ExecuteCommand(); + + //鏇存敼鍘熸墭鐩樹俊鎭� + detail1.Qty -= qty; + detail1.BitPalletMark = "1"; + if (detail1.Qty <= 0) + { + //鏇存柊鍘熸墭鐩樼姸鎬� + var palletInfo = Db.Queryable<SysPallets>().First(m => m.IsDel == "0" && m.PalletNo == palletNo); + palletInfo.Status = "0"; + Db.Updateable(palletInfo).ExecuteCommand(); + + Db.Deleteable(detail1).ExecuteCommand(); + } + else + { + Db.Updateable(detail1).ExecuteCommand(); + } + + + //娣诲姞鎿嶄綔鏃ュ織 + new OperationCrServer().AddLogOperationCr("搴撳唴浣滀笟", "鎿嶄綔鏃ュ織", palletNo, "缂栬緫", $"鐗╂枡鎷嗘墭:{detail1.SkuName}鐗╂枡鎹㈡墭锛屽師鎵樼洏{palletNo}锛屾柊鎵樼洏{palletNoNew}", userId); + + Db.CommitTran(); + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } + + #endregion + } } -- Gitblit v1.8.0