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 |  635 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 files changed, 559 insertions(+), 76 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
index 142058b..0c2ac49 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -12,6 +12,7 @@
 using Newtonsoft.Json;
 using SqlSugar;
 using Utility;
+using Utility.Tools;
 using WMS.BLL.LogServer;
 using WMS.DAL;
 using WMS.Entity.BllAsnEntity;
@@ -419,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();
 
@@ -839,23 +840,22 @@
                     throw Oops.Bah("鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
                 }
                 //鐩爣鍌ㄤ綅淇℃伅
-                var storageLocatEnd = new SysStorageLocat();
-                if (!string.IsNullOrEmpty(areaNo))
+                //var storageLocatEnd = new SysStorageLocat();
+
+                var storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0");
+                if (storageLocatEnd == null)
                 {
-                    storageLocatEnd = await Db.Queryable<SysStorageLocat>().FirstAsync(w => w.IsDel == "0" && w.LocatNo == EndLocat && w.Flag == "0");
-                    if (storageLocatEnd == null)
-                    {
-                        throw Oops.Bah("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
-                    }
+                    throw Oops.Bah("鐩爣鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
                 }
+                
 
                 //娣诲姞鍑哄簱浠诲姟
                 var taskNo = new Common().GetMaxNo("TK");
-                var exTask = new LogTask
+                var moveTask = new LogTask
                 {
                     TaskNo = taskNo,
                     Sender = "WMS",
-                    Receiver = "AGV",
+                    Receiver = "WCS",
                     IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
 
                     StartLocat = stockDetail.LocatNo,//璧峰浣嶇疆
@@ -871,7 +871,7 @@
 
                     CreateTime = DateTime.Now
                 };
-                await Db.Insertable(exTask).ExecuteCommandAsync();
+                await Db.Insertable(moveTask).ExecuteCommandAsync();
 
                 //淇敼搴撳瓨鏄庣粏淇℃伅
                 //stockDetail.Status = "4";//绉诲簱閿佸畾
@@ -894,19 +894,22 @@
                 //娣诲姞鎿嶄綔鏃ュ織璁板綍
                 var k = new OperationCrServer().AddLogOperationCr("PDA妯″潡", "AGV杞繍", palletNo, "绉诲簱", $"PDA鍛煎彨灏忚溅瀵规墭鐩樺彿锛歿palletNo}鍙戣捣杞繍", userId);
 
-                var outDto = new List<OutCommandDto>();
-                outDto.Add(new OutCommandDto()
+                var outDto = new List<OutCommandDto>
                 {
-                    PalletNo = exTask.PalletNo,//鎵樼洏鍙�
-                    StartLocate = exTask.StartLocat, // 璧峰浣嶇疆
-                    StartRoadway = storageLocat.RoadwayNo,//鍏跺疄宸烽亾
-                    EndLocate = EndLocat, // 鐩爣浣嶇疆 
-                    TaskNo = exTask.TaskNo, // 浠诲姟鍙�
-                    TaskType = "2",// 浠诲姟绫诲瀷 (鍑哄簱)0鍏� 1鍑� 2绉� 
-                    OutMode = "",  //鍑哄簱鍙� 
-                    Order = 1
+                    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();
@@ -916,21 +919,181 @@
                 try
                 {
                     var time1 = DateTime.Now;//鍙戦�佹椂闂� .ToString("yyyy-MM-dd HH:mm:ss")
-                    //response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橶CS鍑哄簱鍛戒护", "WCS");
+                    response = HttpHelper.DoPost(url, jsonData, "涓嬪彂缁橶CS鍑哄簱鍛戒护", "WCS");
                     var time2 = DateTime.Now;//杩斿洖鏃堕棿 .ToString("yyyy-MM-dd HH:mm:ss")
 
-                    //////瑙f瀽杩斿洖鏁版嵁 
-                    //var wcsModel = JsonConvert.DeserializeObject<WcsModel>(response);
-                    //if (wcsModel.StatusCode == 0)
-                    //{
-                    //    //鏇存敼浠诲姟鐨勫彂閫佽繑鍥炴椂闂�//
-                    new TaskServer().EditTaskIssueOk(list2, time1, time2);
-                    //}
-                    //if (wcsModel.StatusCode == -1)
-                    //{
-                    //    new TaskServer().EditTaskIssueNo(list2, time1, time2, wcsModel.Msg);
-                    //    throw new Exception(wcsModel.Msg);
-                    //}
+                    //瑙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);
+                }
+
+            }
+            catch (Exception e)
+            {
+                throw new Exception(e.Message);
+            }
+        }
+        /// <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("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!");
+                }
+                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)
                 {
@@ -1111,16 +1274,16 @@
                 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 (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;
-                }
-            }
+            //    if (locatInfo3 != null)
+            //    {
+            //        endLocat = locatInfo3.LocatNo;
+            //    }
+            //}
             return endLocat;
         }
         #endregion
@@ -1214,7 +1377,7 @@
         /// <param name="boxNo"></param>
         /// <param name="devanQty"></param>
         /// <param name="userId"></param>
-        public void AddLableByDevanning(string boxNo, decimal devanQty, int userId)
+        public BoxListInfoDto AddLableByDevanning(string boxNo, decimal devanQty, int userId)
         {
             try
             {
@@ -1290,6 +1453,23 @@
                 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)
             {
@@ -1318,15 +1498,15 @@
                 {
                     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("浠诲姟鐘舵�佷笉鏄瓑寰呯‘璁�");
-                }
+                //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)
@@ -1346,20 +1526,26 @@
             try
             {
                 Db.BeginTran();
-                var task = Db.Queryable<LogTask>().First(m => m.PalletNo == palletNo && m.IsDel == "0" && m.Status == "5");
-                if (task == null)
+                //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("娌℃湁鏌ヨ鍒版墭鐩樹换鍔′俊鎭�");
+                    throw new Exception("搴撳瓨鎵樼洏娌℃湁淇℃伅");
                 }
-                if (task.Status != "5")
-                {
-                    throw new Exception("浠诲姟鐘舵�佷笉鏄瓑寰呯‘璁�");
-                }
-                //浠诲姟鐘舵�佸彉鏇翠负鎵ц瀹屾垚
-                task.Status = "2";
-                Db.Updateable(task).ExecuteCommand();
-                var locatList = Db.Queryable<SysStorageLocat>().Where(m=>m.WareHouseNo == "W04" && (m.AreaNo == "B06" || m.AreaNo == "B07") && m.IsDel == "0").ToList();
-                var locat = locatList.FirstOrDefault(m => m.LocatNo == task.EndLocat);
+                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)
                 {
@@ -1368,7 +1554,7 @@
                 locat.Status = "0";
                 Db.Updateable(locat).ExecuteCommand();
                 //鍒ゆ柇鎵樼洏淇℃伅
-                var stockDetail = Db.Queryable<DataStockDetail>().Where(m => m.IsDel == "0" && m.PalletNo == palletNo).ToList();
+                
                 foreach (var item in stockDetail)
                 {
                     if (item.UDF5 != "1" || string.IsNullOrWhiteSpace(item.SONo))
@@ -1380,7 +1566,7 @@
                     //item.RoadwayNo = "";
                     //item.AreaNo = "";
                     item.LocatNo = "";
-                    item.PalletNo = "";
+                    //item.PalletNo = "";
                     item.LockQty = 0; // 閿佸畾鏁伴噺鏇翠负0
                     item.Status = "0"; // 鐘舵�佸彉涓哄緟鍒嗛厤
                     var boxInfo = Db.Queryable<DataBoxInfo>().Where(m => m.StockDetailId == item.Id).ToList();
@@ -1393,15 +1579,15 @@
                 }
                 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();
+                //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("搴撳唴浣滀笟", "鎿嶄綔鏃ュ織", palletNo, "缂栬緫", $"杞﹂棿鏀惰揣锛歿palletNo}鎵樼洏鏀惰揣", userId);
+                new OperationCrServer().AddLogOperationCr("PDA妯″潡", "杞﹂棿鏀惰揣", palletNo, "瀹屾垚", $"杞﹂棿鏀惰揣锛歿palletNo}鎵樼洏鏀惰揣", userId);
                 Db.CommitTran();
             }
             catch (Exception e)
@@ -1415,5 +1601,302 @@
 
         #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