From fe2b27527084667a15c424ffba00052cbf35ef7f Mon Sep 17 00:00:00 2001
From: bklLiudl <673013083@qq.com>
Date: 星期一, 15 七月 2024 11:45:30 +0800
Subject: [PATCH] Merge branch 'master' into Liudl

---
 Wms/WMS.BLL/BllCheckServer/WarehouseOutsidePalletsServer.cs |  310 +++++++++++++++++++++++----------------------------
 1 files changed, 138 insertions(+), 172 deletions(-)

diff --git a/Wms/WMS.BLL/BllCheckServer/WarehouseOutsidePalletsServer.cs b/Wms/WMS.BLL/BllCheckServer/WarehouseOutsidePalletsServer.cs
index 69e2368..9e2a432 100644
--- a/Wms/WMS.BLL/BllCheckServer/WarehouseOutsidePalletsServer.cs
+++ b/Wms/WMS.BLL/BllCheckServer/WarehouseOutsidePalletsServer.cs
@@ -4,6 +4,8 @@
 using System;
 using System.Collections.Generic;
 using System.Text;
+using System.Threading.Tasks;
+using Utility;
 using WMS.BLL.LogServer;
 using WMS.DAL;
 using WMS.Entity.BllAsnEntity;
@@ -18,8 +20,10 @@
     public class WarehouseOutsidePalletsServer : DbHelper<DataStockDetail>, IWarehouseOutsidePalletsServer
     {
         private static readonly SqlSugarScope Db = DataContext.Db;
-        public WarehouseOutsidePalletsServer() : base(Db)
+        private readonly UserManager _userManager;
+        public WarehouseOutsidePalletsServer(UserManager userManager) : base(Db)
         {
+            _userManager = userManager;
         }
 
         /// <summary>
@@ -30,196 +34,158 @@
         /// <param name="lotNo">鎵规</param>
         /// <param name="palletNo">鎵樼洏鍙�</param>
         /// <returns></returns>
-        public List<MateDataStockDto> GetPalletsOutside(string skuNo, string skuName, string lotNo, string palletNo, int page, int limit, out int count)
+        public async Task<List<MateDataStockDto>> GetPalletsOutside(string skuNo, string skuName, string lotNo, string palletNo, int page, int limit, RefAsync<int> count)
         {
-            string sqlCount = "SELECT DISTINCT COUNT(DataStockDetail.ID) " +
-                "FROM DataStockDetail " +
-                "where IsDel = 0 and isnull(LocatNo,'') = '' and isnull(WareHouseNo,'') = '' ";
-
-            string str = "select Id,LotNo,LotText,SupplierLot,SkuNo,SkuName,Standard,Qty,LockQty,FrozenQty,PalletNo," +
-                "Status,InspectMark,BitPalletMark,InspectStatus " +
-                "from DataStockDetail " +
-                "where IsDel = 0 and isnull(LocatNo,'') = '' and isnull(WareHouseNo,'') = ''";
-            //鍒ゆ柇鐗╂枡鍙锋槸鍚︿负绌�
-            if (!string.IsNullOrEmpty(skuNo))
-            {
-                str += $" and SkuNo like '%{skuNo}%'";
-            }
-            //鍒ゆ柇鐗╂枡鍚嶇О鏄惁涓虹┖
-            if (!string.IsNullOrEmpty(skuName))
-            {
-                str += $" and SkuName like '%{skuName}%'";
-            }
-            //鍒ゆ柇鎵规鏄惁涓虹┖
-            if (!string.IsNullOrEmpty(lotNo))
-            {
-                str += $" and LotNo like '%{lotNo}%'";
-            }
-            //鍒ゆ柇鎵樼洏鍙锋槸鍚︿负绌�
-            if (!string.IsNullOrEmpty(palletNo))
-            {
-                str += $" and PalletNo like '%{palletNo}%'";
-            }
-            //鎺掑簭
-            str += " order by LotNo,SkuNo,PalletNo";
-            if (page == 0)
-            {
-                page = 1;
-            }
-            str += $" offset {((page - 1) * limit)} rows fetch next {limit} rows only;";
-            List<MateDataStockDto> mateDataStockDtos = Db.Ado.SqlQuery<MateDataStockDto>(str);
-            var com = new Common();
-            count = com.GetRowCount(sqlCount);
-            return mateDataStockDtos;
+            var list = await Db.Queryable<DataStockDetail>()
+                              .Where(a => a.IsDel == "0" && SqlFunc.IsNullOrEmpty(a.LocatNo) && SqlFunc.IsNullOrEmpty(a.WareHouseNo))
+                              .WhereIF(!string.IsNullOrEmpty(skuNo), a => a.SkuNo.Contains(skuNo))
+                              .WhereIF(!string.IsNullOrEmpty(skuName), a => a.SkuName.Contains(skuName))
+                              .WhereIF(!string.IsNullOrEmpty(lotNo), a => a.LotNo.Contains(lotNo))
+                              .WhereIF(!string.IsNullOrEmpty(palletNo), a => a.PalletNo.Contains(palletNo))
+                              .OrderBy(a => new { a.LotNo, a.SkuNo, a.PalletNo })
+                              .Select<MateDataStockDto>()
+                              .ToPageListAsync(page, limit, count);
+            return list;
         }
 
 
         //淇濆瓨鎸囧畾鐨勫偍浣�
-        public void SaveAppointSlot(int stockDetailId, int locateId, int userId)
+        public async Task SaveAppointSlot(int stockDetailId, int locateId)
         {
+            //搴撳瓨鏄庣粏淇℃伅
+            var stockDetail = await Db.Queryable<DataStockDetail>().FirstAsync(m => m.IsDel == "0" && m.Id == stockDetailId);
+            if (stockDetail == null)
+            {
+                throw Oops.Bah("鏈煡璇㈠埌搴撳瓨搴撳鎵樼洏鐨勪俊鎭�");
+            }
+            if (!string.IsNullOrWhiteSpace(stockDetail.LocatNo))
+            {
+                throw Oops.Bah("璇ユ墭鐩樺凡鍦ㄥ偍浣嶄笂锛屼笉鑳芥寚瀹氬偍浣嶏紝璇锋牳瀹烇紒");
+            }
+            //鍌ㄤ綅
+            var locate = await Db.Queryable<SysStorageLocat>().FirstAsync(m => m.IsDel == "0" && m.Id == locateId);
+            if (locate == null)
+            {
+                throw Oops.Bah("鏈煡璇㈠埌鍌ㄤ綅鐨勪俊鎭�");
+            }
+            if (locate.Status != "0" || locate.Flag != "0")
+            {
+                throw Oops.Bah("璇ュ偍浣嶇姸鎬佷笉鏄┖鍌ㄤ綅鎴栨爣蹇椾笉鏄甯哥殑");
+            }
+
+            var logTask = await Db.Queryable<LogTask>().FirstAsync(m => m.IsDel == "0" && m.Type == "0" && m.PalletNo == stockDetail.PalletNo && m.Status == "1");
+            if (logTask != null)
+            {
+                throw Oops.Bah("褰撳墠鎵樼洏宸叉湁姝e湪鎵ц鐨勪换鍔★紝璇锋牳瀹炴煡鐪�");
+            }
+
+
+            //鑻ユ槸娣卞害1鐨� 鍒欏垽鏂繁搴�2鏄惁涓虹┖鍌ㄤ綅
+            if (locate.Depth == "01")
+            {
+                var locateDepth = await Db.Queryable<SysStorageLocat>().FirstAsync(a => a.IsDel == "0" && a.Row == locate.Row && a.Column == locate.Column && a.Layer == locate.Layer && a.Depth == "02");
+                if (locateDepth != null)
+                {
+                    if (locateDepth.Status != "1")
+                    {
+                        throw Oops.Bah("璇ュ偍浣嶆繁搴�2涓嶆槸鏈夌墿鍝侊紝涓嶅彲缁戝畾");
+                    }
+                }
+            }
+            //鍒ゆ柇鏄惁涓烘繁搴�2鐨� 鑻ヤ负娣卞害2 鍒欒幏鍙栨繁搴�1鍌ㄤ綅 鍒ゆ柇鏄惁涓虹┖鍌ㄤ綅
+            if (locate.Depth == "02")
+            {
+                var locateDepth = await Db.Queryable<SysStorageLocat>().FirstAsync(a => a.IsDel == "0" && a.Row == locate.Row && a.Column == locate.Column && a.Layer == locate.Layer && a.Depth == "01");
+                if (locateDepth.Status != "0" || locateDepth.Flag == "2")
+                {
+                    throw Oops.Bah("璇ュ偍浣嶆繁搴�1涓嶆槸绌哄偍浣嶆垨鏍囧織涓嶆槸姝e父鐨�");
+                }
+            }
+
+            // 鑾峰彇姝ゆ墭鐩樼殑浠诲姟鍙�
+            var taskModel = await Db.Queryable<LogTask>().FirstAsync(m => m.IsDel == "0" && m.PalletNo == stockDetail.PalletNo && m.IsSuccess == 0 && m.Status == "0");
+
+            Db.BeginTran();
             try
             {
-
-                //搴撳瓨鏄庣粏淇℃伅
-                var stockDetail = Db.Queryable<DataStockDetail>().First(m => m.IsDel == "0" && m.Id == stockDetailId);
-                if (stockDetail == null)
+                var time = DateTime.Now;
+                var taskNo = string.Empty;
+                if (taskModel == null)          // 涔嬪墠鏈寚瀹氭墭鐩�
                 {
-                    throw new Exception("鏈煡璇㈠埌搴撳瓨搴撳鎵樼洏鐨勪俊鎭�");
-                }
-                if (!string.IsNullOrWhiteSpace(stockDetail.LocatNo))
-                {
-                    throw new Exception("璇ユ墭鐩樺凡鍦ㄥ偍浣嶄笂锛屼笉鑳芥寚瀹氬偍浣嶏紝璇锋牳瀹烇紒");
-                }
-                //鍌ㄤ綅
-                var locate = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.Id == locateId);
-                if (locate == null)
-                {
-                    throw new Exception("鏈煡璇㈠埌鍌ㄤ綅鐨勪俊鎭�");
-                }
-                if (locate.Status != "0" || locate.Flag != "0")
-                {
-                    throw new Exception("璇ュ偍浣嶇姸鎬佷笉鏄┖鍌ㄤ綅鎴栨爣蹇椾笉鏄甯哥殑");
-                }
-
-                var logTask = Db.Queryable<LogTask>().First(m => m.IsDel == "0" && m.Type == "0" && m.PalletNo == stockDetail.PalletNo && m.Status == "1");
-                if (logTask != null)
-                {
-                    throw new Exception("褰撳墠鎵樼洏宸叉湁姝e湪鎵ц鐨勪换鍔★紝璇锋牳瀹炴煡鐪�");
-                }
-
-
-                //鑻ユ槸娣卞害1鐨� 鍒欏垽鏂繁搴�2鏄惁涓虹┖鍌ㄤ綅
-                if (locate.Depth == "01")
-                {
-                    var locateDepth = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.Row == locate.Row && a.Column == locate.Column && a.Layer == locate.Layer && a.Depth == "02");
-                    if (locateDepth != null)
+                    // 娣诲姞鍏ュ簱鏃ュ織璁板綍
+                    taskNo = new Common().GetMaxNo("TK");
+                    var task = new LogTask    //鍏ュ簱浠诲姟
                     {
-                        if (locateDepth.Status != "1")
+                        TaskNo = taskNo,
+                        Sender = "WMS",
+                        Receiver = "WCS",
+                        IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
+                        SendDate = time,  //鍙戦�佹椂闂�
+                        BackDate = time,  //杩斿洖鏃堕棿
+                        StartRoadway = "",            // 璧峰宸烽亾
+                        StartLocat = "",//璧峰浣嶇疆
+                        EndLocat = locate.LocatNo,//鐩爣浣嶇疆
+                        EndRoadway = locate.RoadwayNo,  // 鐩爣宸烽亾
+                        PalletNo = stockDetail.PalletNo,//鎵樼洏鐮�
+                        IsSend = 1,//鏄惁鍙啀娆′笅鍙�
+                        IsCancel = 1,//鏄惁鍙彇娑�
+                        IsFinish = 1,//鏄惁鍙畬鎴�
+                        Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
+                        Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
+                        OrderType = "0",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
+                        Msg = "鍏ュ簱鍙e埌=>>" + locate.LocatNo + "鍌ㄤ綅鐨勫叆搴撲换鍔�", //鍏抽敭淇℃伅
+
+                    };
+                    await Db.Insertable(task).ExecuteCommandAsync();
+
+                    locate.Status = "2";
+                    await Db.Updateable(locate).ExecuteCommandAsync();
+                }
+                else                           // 宸叉寚瀹氳繃鎵樼洏闇�鍙樻洿 
+                {
+                    // 鑾峰彇涓婃鎸囧畾鐨勫偍浣嶅湴鍧�
+                    var locateOld = await Db.Queryable<SysStorageLocat>().FirstAsync(m => m.IsDel == "0" && m.LocatNo == taskModel.EndLocat);
+                    if (locateOld != null)
+                    {
+                        if (locateOld.LocatNo == locate.LocatNo) // 鍒ゆ柇褰撳墠鎸囧畾鐨勫湴鍧�鍜屼笂娆$殑鏄惁涓�鑷达紝鑻ヤ竴鑷翠笉鍋氭洿鏀� 
                         {
-                            throw new Exception("璇ュ偍浣嶆繁搴�2涓嶆槸鏈夌墿鍝侊紝涓嶅彲缁戝畾");
+                            throw new Exception("宸叉寚瀹氱浉鍚屽偍浣嶅湴鍧�");
+                        }
+                        else // 鑻ヤ笉涓�鑷� 閲婃斁涓婃鎸囧畾鐨勫偍浣嶅湴鍧�
+                        {
+                            locateOld.Status = "0";
+                            await Db.Updateable(locateOld).ExecuteCommandAsync();
                         }
                     }
+                    locate.Status = "2";
+                    await Db.Updateable(locate).ExecuteCommandAsync();
+                    // 鏇存柊浠诲姟鍙锋寚瀹氬湴鍧�淇℃伅
+                    taskModel.EndLocat = locate.LocatNo;//鐩爣鍌ㄤ綅
+                    taskModel.EndRoadway = locate.RoadwayNo;//鐩爣宸烽亾
+                    await Db.Updateable(taskModel).ExecuteCommandAsync();
+
+                    taskNo = taskModel.TaskNo;
                 }
-                //鍒ゆ柇鏄惁涓烘繁搴�2鐨� 鑻ヤ负娣卞害2 鍒欒幏鍙栨繁搴�1鍌ㄤ綅 鍒ゆ柇鏄惁涓虹┖鍌ㄤ綅
-                if (locate.Depth == "02")
+                // 鏇存柊缁勭洏琛ㄥ贩閬撳湴鍧�鍜屽偍浣嶅湴鍧�
+                var bindModel = await Db.Queryable<BllPalletBind>().FirstAsync(m => m.IsDel == "0"
+                && m.PalletNo == stockDetail.PalletNo && m.ASNDetailNo == stockDetail.ASNDetailNo && m.ASNNo == stockDetail.ASNNo);
+                if (string.IsNullOrWhiteSpace(bindModel.TaskNo) || bindModel.TaskNo == taskNo)
                 {
-                    var locateDepth = Db.Queryable<SysStorageLocat>().First(a => a.IsDel == "0" && a.Row == locate.Row && a.Column == locate.Column && a.Layer == locate.Layer && a.Depth == "01");
-                    if (locateDepth.Status != "0" || locateDepth.Flag == "2")
-                    {
-                        throw new Exception("璇ュ偍浣嶆繁搴�1涓嶆槸绌哄偍浣嶆垨鏍囧織涓嶆槸姝e父鐨�");
-                    }
+                    bindModel.TaskNo = taskNo;
+                    bindModel.WareHouseNo = locate.WareHouseNo;
+                    bindModel.RoadwayNo = locate.RoadwayNo;
+                    bindModel.LocatNo = locate.LocatNo;
+                    await Db.Updateable(bindModel).ExecuteCommandAsync();
                 }
-
-                // 鑾峰彇姝ゆ墭鐩樼殑浠诲姟鍙�
-                var taskModel = Db.Queryable<LogTask>().First(m=>m.IsDel=="0" && m.PalletNo == stockDetail.PalletNo && m.IsSuccess ==0 && m.Status =="0");
-
-                Db.BeginTran();
-                try
-                {
-                    var time = DateTime.Now;
-                    var taskNo = string.Empty;
-                    if (taskModel == null)          // 涔嬪墠鏈寚瀹氭墭鐩�
-                    {
-                        // 娣诲姞鍏ュ簱鏃ュ織璁板綍
-                        taskNo = new Common().GetMaxNo("TK");
-                        var task = new LogTask    //鍏ュ簱浠诲姟
-                        {
-                            TaskNo = taskNo,
-                            Sender = "WMS",
-                            Receiver = "WCS",
-                            IsSuccess = 0, //鏄惁涓嬪彂鎴愬姛 0澶辫触 1鎴愬姛
-                            SendDate = time,  //鍙戦�佹椂闂�
-                            BackDate = time,  //杩斿洖鏃堕棿
-                            StartRoadway = "",            // 璧峰宸烽亾
-                            StartLocat = "",//璧峰浣嶇疆
-                            EndLocat = locate.LocatNo,//鐩爣浣嶇疆
-                            EndRoadway = locate.RoadwayNo,  // 鐩爣宸烽亾
-                            PalletNo = stockDetail.PalletNo,//鎵樼洏鐮�
-                            IsSend = 1,//鏄惁鍙啀娆′笅鍙�
-                            IsCancel = 1,//鏄惁鍙彇娑�
-                            IsFinish = 1,//鏄惁鍙畬鎴�
-                            Type = "0",//浠诲姟绫诲瀷 0 鍏ュ簱浠诲姟 1 鍑哄簱浠诲姟  2 绉诲簱浠诲姟
-                            Status = "0",//浠诲姟鐘舵��0锛氱瓑寰呮墽琛�1姝e湪鎵ц2鎵ц瀹屾垚
-                            OrderType = "0",//0 鍏ュ簱鍗� 1 鍑哄簱鍗�  2 鐩樼偣鍗�  3 绉诲簱鍗�
-                            Msg = "鍏ュ簱鍙e埌=>>" + locate.LocatNo + "鍌ㄤ綅鐨勫叆搴撲换鍔�", //鍏抽敭淇℃伅
-
-                        };
-                        Db.Insertable(task).ExecuteCommand();
-
-                        locate.Status = "2";
-                        Db.Updateable(locate).ExecuteCommand();
-                    }
-                    else                           // 宸叉寚瀹氳繃鎵樼洏闇�鍙樻洿 
-                    {
-                        // 鑾峰彇涓婃鎸囧畾鐨勫偍浣嶅湴鍧�
-                        var locateOld = Db.Queryable<SysStorageLocat>().First(m => m.IsDel == "0" && m.LocatNo == taskModel.EndLocat);
-                        if (locateOld != null)
-                        {
-                            if (locateOld.LocatNo == locate.LocatNo) // 鍒ゆ柇褰撳墠鎸囧畾鐨勫湴鍧�鍜屼笂娆$殑鏄惁涓�鑷达紝鑻ヤ竴鑷翠笉鍋氭洿鏀� 
-                            {
-                                throw new Exception("宸叉寚瀹氱浉鍚屽偍浣嶅湴鍧�");
-                            }
-                            else // 鑻ヤ笉涓�鑷� 閲婃斁涓婃鎸囧畾鐨勫偍浣嶅湴鍧�
-                            {
-                                locateOld.Status = "0";
-                                Db.Updateable(locateOld).ExecuteCommand();
-                            }
-                        }
-                        locate.Status = "2";
-                        Db.Updateable(locate).ExecuteCommand();
-                        // 鏇存柊浠诲姟鍙锋寚瀹氬湴鍧�淇℃伅
-                        taskModel.EndLocat = locate.LocatNo;//鐩爣鍌ㄤ綅
-                        taskModel.EndRoadway = locate.RoadwayNo;//鐩爣宸烽亾
-                        Db.Updateable(taskModel).ExecuteCommand();
-
-                        taskNo = taskModel.TaskNo;
-                    }
-                    // 鏇存柊缁勭洏琛ㄥ贩閬撳湴鍧�鍜屽偍浣嶅湴鍧�
-                    var bindModel = Db.Queryable<BllPalletBind>().First(m => m.IsDel == "0"
-                    && m.PalletNo == stockDetail.PalletNo && m.ASNDetailNo == stockDetail.ASNDetailNo && m.ASNNo == stockDetail.ASNNo);
-                    if (string.IsNullOrWhiteSpace(bindModel.TaskNo) || bindModel.TaskNo == taskNo)
-                    {
-                        bindModel.TaskNo = taskNo;
-                        bindModel.WareHouseNo = locate.WareHouseNo;
-                        bindModel.RoadwayNo = locate.RoadwayNo;
-                        bindModel.LocatNo = locate.LocatNo;
-                        Db.Updateable(bindModel).ExecuteCommand();
-                    }
-                    // 鎻掑叆鎿嶄綔鏃ュ織
-                    new OperationASNServer().AddLogOperationAsn("搴撳唴浣滀笟", "搴撳鎵樼洏", stockDetail.PalletNo, "缂栬緫",
-                            $"鎸囧畾浜嗗偍浣嶏細{locate.LocatNo}銆佸崟鎹彿锛歿stockDetail.ASNNo}銆佹墭鐩樼爜锛歿stockDetail.PalletNo}鐨勪俊鎭�", userId);
-                    //鎻愪氦浜嬪姟
-                    Db.CommitTran();
-                }
-                catch (Exception e)
-                {
-                    Db.RollbackTran();
-                    throw new Exception(e.Message);
-                }
-
+                // 鎻掑叆鎿嶄綔鏃ュ織
+                new OperationASNServer().AddLogOperationAsn("搴撳唴浣滀笟", "搴撳鎵樼洏", stockDetail.PalletNo, "缂栬緫",
+                        $"鎸囧畾浜嗗偍浣嶏細{locate.LocatNo}銆佸崟鎹彿锛歿stockDetail.ASNNo}銆佹墭鐩樼爜锛歿stockDetail.PalletNo}鐨勪俊鎭�", _userManager.UserId);
+                //鎻愪氦浜嬪姟
+                Db.CommitTran();
             }
             catch (Exception e)
             {
+                Db.RollbackTran();
                 throw new Exception(e.Message);
             }
         }

--
Gitblit v1.8.0