From 6561685f41cc0d0c1554d8ff2e3905e142af2fa0 Mon Sep 17 00:00:00 2001
From: chengsc <11752@DESKTOP-DS49RCP>
Date: 星期五, 06 六月 2025 11:02:45 +0800
Subject: [PATCH] Merge branch 'master' into csc

---
 Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs |  270 +++++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 198 insertions(+), 72 deletions(-)

diff --git a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
index a0e216c..fc62305 100644
--- a/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
+++ b/Wms/WMS.BLL/BllPdaServer/PdaCrServer.cs
@@ -6,11 +6,13 @@
 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;
@@ -689,7 +691,7 @@
             {
                 throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
             }
-            if (models.WareHouseNo != "W02")
+            if (models.WareHouseNo != "W04")
             {
                 throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!");
             }
@@ -719,7 +721,7 @@
                 {
                     throw Oops.Bah("鎵樼洏鍌ㄤ綅淇℃伅涓嶅瓨鍦�,璇锋鏌�!");
                 }
-                if (models.WareHouseNo != "W02")
+                if (models.WareHouseNo != "W04")
                 {
                     throw Oops.Bah("璇ユ墭鐩樻湭鍦ㄥ钩搴撳唴,璇锋鏌�!");
                 }
@@ -729,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;
         }
@@ -817,7 +814,7 @@
                     {
                         throw Oops.Bah("鎵�閫夊尯鍩熶俊鎭笉瀛樺湪,璇锋鏌�!");
                     }
-                    EndLocat = await GetLocat(areaNo, stockDetail.SkuNo, stockDetail.LotNo, palletNo);
+                    EndLocat = await GetLocat(areaNo);
                 }
                 else
                 {
@@ -843,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" && w.Status == "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,//璧峰浣嶇疆
@@ -875,7 +871,7 @@
 
                     CreateTime = DateTime.Now
                 };
-                await Db.Insertable(exTask).ExecuteCommandAsync();
+                await Db.Insertable(moveTask).ExecuteCommandAsync();
 
                 //淇敼搴撳瓨鏄庣粏淇℃伅
                 //stockDetail.Status = "4";//绉诲簱閿佸畾
@@ -898,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();
@@ -920,21 +919,21 @@
                 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)
                 {
@@ -1019,7 +1018,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("鍒嗛厤鐩爣鍌ㄤ綅澶辫触,璇锋鏌�!");
@@ -1101,35 +1100,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
@@ -1216,7 +1210,7 @@
         }
         #endregion
 
-        #region 绠辩爜鎷嗙璐存爣
+        #region 绠辩爜鎷嗙璐存爣銆佷汉宸ョ‘璁ゆ敹璐�
         /// <summary>
         /// 鎷嗙娣诲姞鏍囩
         /// </summary>
@@ -1252,7 +1246,18 @@
                 Db.Updateable(boxInfo).ExecuteCommand();
 
                 var boxStr = boxInfo.BoxNo.Substring(0, boxInfo.BoxNo.Length - 6);//鑾峰彇绠辩爜鍓嶇紑-闄ゅ悗鍏綅娴佹按澶�
-                var maxBoxCode = Db.Queryable<BllBoxInfo>().Where(m => m.BoxNo.Contains(boxStr) && m.IsDel == "0" && m.Origin == "WMS鐢熸垚").Max(a => a.BoxNo);
+                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');
 
                 // 娣诲姞鏂扮鐮佷俊鎭�
@@ -1296,6 +1301,127 @@
                 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
 
     }

--
Gitblit v1.8.0