From 00a72fff219241eb5b0405a066cc859d07cf7735 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期三, 17 九月 2025 10:23:44 +0800
Subject: [PATCH] 1111

---
 service/Warehouse/MesXsckManager.cs |  636 ++++++++++-----------------------------------------------
 1 files changed, 116 insertions(+), 520 deletions(-)

diff --git a/service/Warehouse/MesXsckManager.cs b/service/Warehouse/MesXsckManager.cs
index d5da216..7c98c1b 100644
--- a/service/Warehouse/MesXsckManager.cs
+++ b/service/Warehouse/MesXsckManager.cs
@@ -9,6 +9,7 @@
 using SqlSugar.Extensions;
 using System.Data;
 using System.Data.SqlClient;
+using DbHelperSQL = NewPdaSqlServer.DB.DbHelperSQL;
 
 namespace NewPdaSqlServer.service.Warehouse;
 
@@ -20,57 +21,83 @@
     ///     鑾峰彇鐢熶骇鍙戣揣閫氱煡鍗曞彿鍒楄〃
     /// </summary>
     /// <returns>鍙戣揣閫氱煡鍗曞彿鍒楄〃</returns>
-    public List<string> GetFHTZBillNo(WarehouseQuery query)
+    public dynamic GetFHTZBillNo(dynamic query, dynamic RequestInfo)
     {
-        var list = Db.Queryable<SalesDeliver>()
-            .Where(s => (s.FApproverStatus ?? false) == true)
-            .Select(s => s.BillNo)
-            .ToList();
-        return list;
+        var orgId = RequestInfo.OrgId;
+
+        if (orgId == null)
+            throw new Exception("缁勭粐涓嶅瓨鍦紒");
+
+        // 鑾峰彇鏈畬鎴愮殑閫�鏂欏崟鍙峰垪琛�
+        var parameters = new[]
+        {
+        new SugarParameter("@pi_orgId", orgId),
+        new SugarParameter("@inP1", null),
+        new SugarParameter("@inP2", null),
+        new SugarParameter("@inP3", null),
+        new SugarParameter("@inP4", null)
+        };
+        try
+        {
+            // 杩斿洖鍗曞彿瀛楃涓插垪琛℅et_Qt_ck_List
+            var blDetails = Db.Ado.SqlQuery<string>(
+                "EXEC prc_pda_xsck_list @pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
+            return blDetails;
+        }
+        catch (Exception ex)
+        {
+            throw new Exception($"{ex.Message}");
+        }
     }
 
     /// <summary>
     ///     鏍规嵁鍙戣揣閫氱煡鍗曡幏鍙栧搴斾唬鍙戣揣鏄庣粏  prc_rf_pda_scan_zout_showbl
     /// </summary>
     /// <returns>鍙戣揣閫氱煡鍗曟槑缁嗗垪琛�</returns>
-    public List<ItemDetailModel> GetMesItemFHTZetailByBillNo(
-            WarehouseQuery query)
+    public dynamic GetMesItemFHTZetailByBillNo(dynamic query, dynamic RequestInfo)
     {
         if (string.IsNullOrEmpty(query.billNo))
             throw new Exception("璇烽�夊崟鎹彿锛�");
 
-        // 妫�鏌ュ彂璐ч�氱煡鍗曟槸鍚﹀瓨鍦ㄤ笖瀹℃牳
-        var mesItem = Db.Queryable<SalesDeliver>()
-            .Where(a => a.BillNo == query.billNo && a.FApproverStatus == true)
-            .First();
+        if (query == null)
+            throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓簄ull");
 
-        if (mesItem == null)
-            throw new Exception("鍗曟嵁鍙蜂笉瀛樺湪鎴栨湭瀹℃牳锛�");
+        if (string.IsNullOrEmpty(query.billNo?.ToString()))
+            throw new ArgumentException("鍗曟嵁鍙蜂笉鑳戒负绌�", nameof(query.billNo));
 
-        if (mesItem.FinishStatus == true)
-            throw new Exception("鍗曟嵁鍙峰凡瀹岀粨锛�");
+        var orgId = RequestInfo.OrgId;
+
+        if (orgId == null)
+            throw new Exception("缁勭粐涓嶅瓨鍦紒");
 
         // 鑾峰彇鏈畬鎴愮殑鍙戣揣閫氱煡鍗曟槑缁�
-        var blDetails = Db.Queryable<SalesDeliver, SalesDeliverDetail, SalesOrderDetail,MesItems>((a, b, c, d) =>
-                new JoinQueryInfos(JoinType.Left, a.Id == b.Pid,
-                JoinType.Left, b.SalesDetailId == c.Id,
-                JoinType.Left, c.MaterialId == d.ItemId.ToString()))
-            .Where((a, b) => a.BillNo == query.billNo
-                             && (b.FMustQty ?? 0) - (b.FRealQty ?? 0) > 0)
-            .Select((a, b, c, d) => new ItemDetailModel
+        var parameters = new[]
+{
+        new SugarParameter("@billNo", query.billNo),
+        new SugarParameter("@pi_orgId",orgId),
+        new SugarParameter("@inP1", null),
+        new SugarParameter("@inP2", null),
+        new SugarParameter("@inP3", null),
+        new SugarParameter("@inP4", null)
+    };
+        try
+        {
+            List<dynamic>? blDetails = Db.Ado.SqlQuery<dynamic>(
+                "EXEC prc_pda_xsck_detailList @billNo,@pi_orgId,@inP1,@inP2,@inP3,@inP4", parameters);
+            var items = blDetails.Where(x => x.DSQty > 0).ToList();    // 寰呮壂鐗╂枡
+            var ysitems = blDetails.Where(x => x.SQty > 0).ToList();   // 宸叉壂鐗╂枡
+            return new
             {
-                ItemNo = d.ItemNo,
-                ItemName = d.ItemName,
-                ItemModel = d.ItemModel,
-                FQty = b.FMustQty,
-                SQty = b.FRealQty,
-                FMaterialId = d.ItemId.ToString(),
-                Id = b.Id.ToString()
-
-            })
-            .ToList();
-
-        return  blDetails;
+                items = items,
+                ysitems = ysitems,
+                allList = blDetails
+            };
+        }
+        catch (Exception ex)
+        {
+            // 淇濈暀鍘熸湁寮傚父澶勭悊閫昏緫
+            throw new Exception($"{ex.Message}");
+        }
     }
 
     /// <summary>
@@ -93,7 +120,7 @@
         using (var conn = new SqlConnection(DbHelperSQL.strConn))
         {
             if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖");
-            if (query.daa001.IsNullOrEmpty()) throw new Exception("鍙戣揣閫氱煡鍗曞彿涓嶅厑璁镐负绌�");
+            if (query.billNo.IsNullOrEmpty()) throw new Exception("鍙戣揣閫氱煡鍗曞彿涓嶅厑璁镐负绌�");
             if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�");
 
             using (var cmd = new SqlCommand("[prc_pda_XSCK]", conn))
@@ -109,7 +136,7 @@
                         new("@barcode_num", SqlDbType.NVarChar, 300),
                         new("@split_num", SqlDbType.NVarChar, 300),
                         new("@c_User", query.userName),
-                        new("@p_biLL_no", query.daa001),
+                        new("@p_biLL_no", query.billNo),
                         new("@p_item_barcode", query.barcode)
                     };
                     parameters[0].Direction = ParameterDirection.Output;
@@ -165,499 +192,68 @@
     ///     - Num: 鍙戞枡鏁伴噺(蹇呭~,蹇呴』澶т簬0)
     ///     - blNo: 鍙戣揣閫氱煡鍗曞彿(蹇呭~)
     /// </remarks>
-    public (bool success, List<MesItemBlDetail> pendingList) SplitBarcode(
-        WarehouseQuery query)
+    public ProductionPickDto SplitBarcode(WarehouseQuery query)
     {
-        if (string.IsNullOrEmpty(query.userName))
-            throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
+        if (query.userName.IsNullOrEmpty()) throw new Exception("鐢ㄦ埛鍚嶄笉鍏佽涓虹┖");
+        if (query.billNo.IsNullOrEmpty()) throw new Exception("鐢宠鍗曞彿涓嶅厑璁镐负绌�");
+        if (query.barcode.IsNullOrEmpty()) throw new Exception("鏉$爜涓嶅厑璁镐负绌�");
 
-        if (string.IsNullOrEmpty(query.billNo))
-            throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
+        if (query.Num is null or 0) throw new Exception("鏉$爜鎷嗗垎鏁颁笉鍏佽涓虹┖鎴栬�呬负0");
 
-        if (string.IsNullOrEmpty(query.barcode))
-            throw new Exception("璇锋壂鎻忔潯鐮侊紒");
-
-        if ((query.Num ?? 0) <= 0)
-            throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�");
-
-        if (string.IsNullOrEmpty(query.blNo))
-            throw new Exception("鍙戣揣閫氱煡鍗曞彿涓嶈兘涓虹┖锛�");
-
-
-        // 妫�楠屾槸鍚﹂噸澶嶆壂鎻�
-        var exists = Db.Queryable<MesInvItemOutCDetails>()
-            .Where(b => b.ItemBarcode == query.barcode)
-            .Any();
-
-        if (exists)
-            throw new Exception("姝ゆ潯鐮佸凡鎵弿,鍕块噸澶嶆壂鐮侊紒");
-
-        // 鏌ヨ鏉$爜搴撳瓨淇℃伅
-        var stockBarcode = Db.Queryable<MesInvItemStocks>()
-            .Where(t => t.ItemBarcode == query.barcode && t.Quantity > 0)
-            .First();
-
-        if (stockBarcode == null)
-            throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}");
-
-        var totalQty = stockBarcode.Quantity;
-        string newBarcode = null;
-
-        var outNoType = "";
-        if (query.Type == "鐢熶骇琛ユ枡")
+        var _strMsg = "";
+        var _intSum = "";
+        var _cfBar = "";//鎷嗗垎鍚庢潯鐮�
+        using (var conn = new SqlConnection(DbHelperSQL.strConn))
         {
-            outNoType = "SCBL(鐢熶骇琛ユ枡)";
-        }
-        else
-        {
-            outNoType = "SCCL(鐢熶骇瓒呴)";
-        }
-
-        // 寮�鍚簨鍔″鐞�
-        var success = UseTransaction(db =>
-        {
-            var executeCommand = 0;
-
-            // 鎷嗗垎鏉$爜
-            if (totalQty > query.Num)
+            using (var cmd = new SqlCommand("[prc_pda_XSCK_CF_new]", conn))
             {
-                var mesItems = db.Queryable<MesItems>()
-                    .Where(s => s.Id == stockBarcode.ItemId).First();
-
-                // 鐢熸垚鏂版潯鐮佸彿
-                newBarcode = BillNo.GetBillNo("TM(鏉$爜)", mesItems.ItemNo);
-
-                // 鍐欏叆鏂版潯鐮�
-                executeCommand += db.Insertable(new MesInvItemBarcodes
+                try
                 {
-                    Guid = Guid.NewGuid(),
-                    ItemBarcode = newBarcode,
-                    CustNo = stockBarcode.CustomerNo,
-                    // ProductCode = stockBarcode.ProductCode, 
-                    // ItemBarcode2 = stockBarcode.ItemBarcode2,
-                    // ItemCode = stockBarcode.ItemCode,
-                    ItemNo = stockBarcode.ItemNo,
-                    LotNo = stockBarcode.LotNo,
-                    Quantity = query.Num,
-                    EpFlag = true,
-                    TaskNo = stockBarcode.TaskNo,
-                    CreateBy = query.userName,
-                    CreateDate = DateTime.Now,
-                    LastupdateBy = query.userName,
-                    LastupdateDate = DateTime.Now,
-                    OldItemBarcode = query.barcode,
-                    // Mblnr = stockBarcode.Mblnr,
-                    // Zeile = stockBarcode.Zeile,
-                    // RohInId = stockBarcode.RohInId,
-                    Barcodestatus = false,
-                    Oldqty = query.Num as long?,
-                    // Unit = stockBarcode.Unit,
-                    // WeightUnit = stockBarcode.WeightUnit,
-                    Factory = stockBarcode.Factory,
-                    Company = stockBarcode.Company,
-                    BillNo = stockBarcode.BillNo,
-                    BoardStyle = stockBarcode.BoardStyle,
-                    // ColorName = stockBarcode.ColorName,
-                    WorkNo = stockBarcode.WorkNo,
-                    WorkLine = stockBarcode.WorkLine,
-                    // MemoBad = stockBarcode.MemoBad,
-                    ComeFlg = 5,
-                    // Memo = stockBarcode.Memo,
-                    SuppId = stockBarcode.SuppId,
-                    SuppNo = stockBarcode.SuppNo,
-                    InsDate = stockBarcode.IndepDate, // Added InsDate
-                    ItemId = stockBarcode.ItemId
-                    // ItemUnit = stockBarcode.ItemUnit // Added ItemUnit
-                }).IgnoreColumns(true).ExecuteCommand();
-
-                // 鏇存柊鍘熸潯鐮佹暟閲�
-                executeCommand += db.Updateable<MesInvItemBarcodes>()
-                    .SetColumns(it => it.Quantity == it.Quantity - query.Num)
-                    .Where(it => it.ItemBarcode == query.barcode)
-                    .ExecuteCommand();
-
-                // 鏇存柊鍘熸潯鐮佹暟閲�
-                executeCommand += db.Updateable<MesInvItemStocks>()
-                    .SetColumns(it => it.Quantity == it.Quantity - query.Num)
-                    .Where(it => it.ItemBarcode == query.barcode)
-                    .ExecuteCommand();
-
-                //// 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰�
-                //executeCommand += db.Deleteable<MesInvItemStocks>()
-                //    .Where(it => it.ItemBarcode == query.barcode)
-                //    .ExecuteCommand();
-
-                // 鎻掑叆鍓╀綑鏉$爜鏁伴噺鐨勬柊搴撳瓨璁板綍
-                executeCommand += db.Insertable(new MesInvItemStocks
-                {
-                    Guid = Guid.NewGuid(),
-                    TaskNo = stockBarcode.TaskNo,
-                    ItemBarcode = newBarcode,
-                    ItemNo = stockBarcode.ItemNo,
-                    LotNo = stockBarcode.LotNo,
-                    Quantity = query.Num,
-                    EpFlag = stockBarcode.EpFlag,
-                    CustomerNo = stockBarcode.CustomerNo,
-                    ItemWt = stockBarcode.ItemWt,
-                    DepotsCode = stockBarcode.DepotsCode,
-                    DepotsId = stockBarcode.DepotsId,
-                    DepotSectionsCode = stockBarcode.DepotSectionsCode,
-                    CheckDate = stockBarcode.CheckDate,
-                    ItemType = stockBarcode.ItemType,
-                    IndepDate = stockBarcode.IndepDate,
-                    Factory = stockBarcode.Factory,
-                    Company = stockBarcode.Company,
-                    IqcStatus = stockBarcode.IqcStatus,
-                    BoardStyle = stockBarcode.BoardStyle,
-                    WorkNo = stockBarcode.WorkNo,
-                    WorkLine = stockBarcode.WorkLine,
-                    SuppNo = stockBarcode.SuppNo,
-                    ItemId = stockBarcode.ItemId
-                    // UnitId = stockBarcode.ItemUnit
-                }).IgnoreColumns(true).ExecuteCommand();
-
-                // 鍐欏叆鏂版潯鐮佺殑浜ゆ槗璁板綍
-                executeCommand += db.Insertable(new MesInvBusiness2
-                {
-                    Guid = Guid.NewGuid(),
-                    Status = 1,
-                    BillTypeId = 200, // p_bill_type_id
-                    TransactionCode = "209", // p_transaction_no
-                    BusinessType = 0,
-                    ItemBarcode = newBarcode,
-                    ItemNo = stockBarcode.ItemNo,
-                    LotNo = stockBarcode.LotNo,
-                    EpFlag = true,
-                    Quantity = query.Num,
-                    FromInvDepotsCode = null,
-                    FromInvDepotSectionsCode = null,
-                    ToInvDepotsCode = stockBarcode.DepotsCode,
-                    ToInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                    Description = query.Type + "鎷嗗垎鐢熸垚",
-                    CreateBy = query.userName,
-                    CreateDate = DateTime.Now,
-                    LastupdateBy = query.userName,
-                    LastupdateDate = DateTime.Now,
-                    Factory = stockBarcode.Factory,
-                    Company = stockBarcode.Company,
-                    TaskNo = stockBarcode.TaskNo,
-                    BillNo = stockBarcode.BillNo,
-                    WorkNo = stockBarcode.WorkNo,
-                    WorkLine = stockBarcode.WorkLine,
-                    SuppNo = stockBarcode.SuppNo,
-                    SuppId = stockBarcode.SuppId,
-                    ItemId = stockBarcode.ItemId
-                    // CkDepot = stockBarcode.DepotsId
-                }).IgnoreColumns(true).ExecuteCommand();
-            }
-            else if (totalQty < query.Num)
-            {
-                throw new Exception("鍙戞枡鏁伴噺澶т簬鏉$爜鏁�,璇锋牳瀵癸紒");
-            }
-
-            //if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
-
-            // 妫�鏌ュ彂璐ч�氱煡鍗曠姸鎬�
-            var mesItemBl = Db.Queryable<MesItemBl>()
-                .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == true)
-                .First();
-
-            if (mesItemBl == null)
-                throw new Exception($"鐢宠鍗� {query.blNo} 宸叉挙鍥烇紒");
-
-            if (mesItemBl.Bl018 != true)
-                throw new Exception($"鐢宠鍗� {query.blNo} 鏈鏍革紒");
-
-            if (mesItemBl.Bl019 == true)
-                throw new Exception($"鐢宠鍗� {query.blNo} 宸插畬缁擄紒");
-
-            // 鑾峰彇鍙戣揣閫氱煡鍗曟槑缁嗗苟鏍¢獙
-            var blDetail = Db.Queryable<MesItemBlDetail>()
-                .Where(b =>
-                    b.Mid == mesItemBl.Id && b.Bld012 == stockBarcode.ItemId)
-                .First();
-
-            if (blDetail == null)
-                throw new Exception($"鐢宠鍗曚笉瀛樺湪姝ょ墿鏂� {stockBarcode.ItemNo} 璇风‘璁わ紒");
-
-            var remainingQty = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0);
-            if (remainingQty == 0)
-                throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒");
-
-            if (query.Num > remainingQty)
-                throw new Exception(
-                    $"鎷嗗垎鏁伴噺锛歿query.Num} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
-
-            // 妫�鏌ュ伐鍗曚俊鎭�
-            var womdaa = Db.Queryable<Womdaa>()
-                .Where(a => a.Daa001 == query.billNo)
-                .First();
-
-            if (womdaa == null)
-                throw new Exception($"宸ュ崟 {query.billNo} 涓嶅瓨鍦紝璇风‘璁わ紒");
-
-            var womdab = Db.Queryable<Womdab>()
-                .Where(b =>
-                    b.Dab001 == query.billNo && b.Erpid == blDetail.Bld014)
-                .First();
-
-            if (womdab == null)
-                throw new Exception($"澶囨枡鏄庣粏涓嶅瓨鍦ㄦ鐗╂枡 {stockBarcode.ItemNo} 璇风‘璁わ紒");
-
-            // 妫�鏌ュ凡鍙戞枡鏁伴噺鏄惁瓒呰繃寰呭彂鏂欐暟閲�
-            var sumQty = db.Queryable<MesInvItemOutCDetails>()
-                .Where(it =>
-                    it.TaskNo == query.blNo && it.ItemId == stockBarcode.ItemId)
-                .Sum(it => it.Quantity);
-
-            //if (sumQty > remainingQty)
-            //    throw new Exception(
-            //        $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
-
-
-            var depots = Db.Queryable<MesDepots>()
-                .Where(t => t.DepotId == stockBarcode.DepotId)
-                .First();
-
-            // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
-            var itemOut = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.TaskNo == query.blNo
-                            && a.DepotId == stockBarcode.DepotId
-                            && a.OutDate.Value.Date.ToString("yyyy-MM-dd") ==
-                            DateTime.Now.Date.ToString("yyyy-MM-dd")
-                            && a.BillTypeId == 200
-                            && a.TransactionNo == 209
-                            && a.Status == 0)
-                .First();
-
-            var outId = new Guid();
-            var outNo = "";
-            if (itemOut == null)
-            {
-                // 鍒涘缓鏂扮殑鍑哄簱鍗�
-                outId = Guid.NewGuid();
-                outNo = BillNo.GetBillNo(outNoType);
-
-                // 鎻掑叆鍑哄簱鍗曚富琛�
-                executeCommand += db.Insertable(new MesInvItemOuts
-                {
-                    Guid = outId,
-                    ItemOutNo = outNo,
-                    TaskNo = query.blNo,
-                    CreateBy = query.userName,
-                    CreateDate = DateTime.Now,
-                    LastupdateBy = query.userName,
-                    LastupdateDate = DateTime.Now,
-                    BillTypeId = 200,
-                    TransactionNo = 209,
-                    Remark = mesItemBl.Bl007,
-                    DepotCode = depots.DepotCode,
-                    OutPart = womdaa.Daa013,
-                    FType = 0,
-                    Factory = stockBarcode.Factory,
-                    Company = stockBarcode.Company,
-                    WorkNo = womdaa.Daa021,
-                    BoardItem = womdaa.Daa002,
-                    PbillNo = womdaa.Daa001,
-                    OutDate = DateTime.Now,
-                    Status = 0,
-                    DepotId = stockBarcode.DepotId,
-                    THORGID = stockBarcode.StockOrgId,
-                    OutType = query.Type,
-                    //BbillNo = query.blNo
-                }).IgnoreColumns(true).ExecuteCommand();
-            }
-            else
-            {
-                outId = itemOut.Guid;
-                outNo = itemOut.ItemOutNo;
-            }
-
-            // 妫�鏌ユ槸鍚﹀凡瀛樺湪鍑哄簱鍗曟槑缁�
-            var itemOutItemCount = db.Queryable<MesInvItemOutItems>()
-                .Where(it =>
-                    it.ItemOutId == outId &&
-                    it.ItemId == stockBarcode.ItemId &&
-                    it.DepotId == stockBarcode.DepotId.ToString())
-                .Count();
-
-            if (itemOutItemCount == 0)
-                // 鎻掑叆鏂扮殑鍑哄簱鍗曟槑缁�
-                executeCommand += db.Insertable(new MesInvItemOutItems
-                {
-                    Guid = Guid.NewGuid(),
-                    ItemOutId = outId,
-                    ItemNo = blDetail.Bld002,
-                    Quantity = query.Num,
-                    TlQty = query.Num,
-                    CreateBy = query.userName,
-                    CreateDate = DateTime.Now,
-                    LastupdateBy = query.userName,
-                    LastupdateDate = DateTime.Now,
-                    Factory = stockBarcode.Factory,
-                    Company = stockBarcode.Company,
-                    DepotCode = depots.DepotCode,
-                    TaskNo = query.blNo,
-                    WorkNo = womdaa.Daa021,
-                    WorkLine = blDetail.Bld013,
-                    ErpItemNo = womdab.Dab003,
-                    ErpId = womdab.Eid,
-                    ErpAutoid = womdab.Erpid,
-                    PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012,
-                    DepotId = stockBarcode.DepotId.ToString(),
-                    ItemDabid = womdab.Guid,
-                    // Unit = blDetail.Bld009,
-                    // DepotId = (int)stockBarcode.DepotsId
-                }).IgnoreColumns(true).ExecuteCommand();
-            else
-                // 鏇存柊宸叉湁鍑哄簱鍗曟槑缁嗘暟閲�
-                executeCommand += db.Updateable<MesInvItemOutItems>()
-                    .SetColumns(it => it.TlQty == (it.TlQty ?? 0) + query.Num)
-                    .Where(it =>
-                    it.ItemOutId == outId &&
-                    it.ItemId == stockBarcode.ItemId &&
-                    it.DepotId == stockBarcode.DepotId.ToString())
-                    .ExecuteCommand();
-
-            // 鎻掑叆鍑哄簱鏉$爜鏄庣粏
-            executeCommand += db.Insertable(new MesInvItemOutCDetails
-            {
-                Guid = Guid.NewGuid(),
-                ItemOutId = outId,
-                ItemBarcode = newBarcode ?? query.barcode,
-                ItemNo = stockBarcode.ItemNo,
-                LotNo = stockBarcode.LotNo,
-                Quantity = query.Num,
-                ForceOutFlag = 0,
-                CreateBy = query.userName,
-                CreateDate = DateTime.Now,
-                LastupdateBy = query.userName,
-                LastupdateDate = DateTime.Now,
-                DepotCode = depots.DepotCode,
-                DepotSectionCode = stockBarcode.DepotSectionsCode,
-                Remark = blDetail.Bld010,
-                Factory = stockBarcode.Factory,
-                Company = stockBarcode.Company,
-                TaskNoy = mesItemBl.Bl013,
-                BoardStyle = mesItemBl.Bl002,
-                TaskNo = query.blNo,
-                WorkNo = blDetail.Bld001,
-                WorkLine = blDetail.Bld013,
-                SuppNo = stockBarcode.SuppNo,
-                PbillNo = query.billNo,
-                ItemId = blDetail.Bld012,
-                Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId,
-                Dabid = womdab.Guid,
-            }).IgnoreColumns(true).ExecuteCommand();
-
-            // 鎻掑叆涓氬姟娴佹按
-            executeCommand += db.Insertable(new MesInvBusiness2
-            {
-                Guid = Guid.NewGuid(),
-                Status = 1,
-                BillTypeId = 200, // p_bill_type_id
-                TransactionCode = "209", // p_transaction_no 
-                BusinessType = 1,
-                ItemBarcode = newBarcode ?? query.barcode,
-                ItemNo = stockBarcode.ItemNo,
-                LotNo = stockBarcode.LotNo,
-                EpFlag = true,
-                Quantity = query.Num,
-                FromInvDepotsCode = stockBarcode.DepotsCode,
-                FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                Description = query.Type,
-                CreateBy = query.userName,
-                CreateDate = DateTime.Now,
-                LastupdateBy = query.userName,
-                LastupdateDate = DateTime.Now,
-                Factory = stockBarcode.Factory,
-                Company = stockBarcode.Company,
-                TaskNo = mesItemBl.Bl012,
-                BillNo = query.blNo,
-                WorkNo = blDetail.Bld001,
-                WorkLine = blDetail.Bld013,
-                SuppNo = stockBarcode.SuppNo,
-                ItemId = stockBarcode.ItemId
-                // CkDepot = stockBarcode.DepotsId
-            }).IgnoreColumns(true).ExecuteCommand();
-
-            // 鏇存柊宸ュ崟琛ㄦ暟閲�
-            executeCommand += db.Updateable<Womdab>()
-                .SetColumns(it => new Womdab
-                {
-                    Dab007 = (it.Dab007 ?? 0) + query.Num, // 宸ュ崟鏁伴噺
-                    Dab020 = (it.Dab020 ?? 0) + query.Num, // 宸插彂鏂欐暟閲�
-                    Dab021 = (it.Dab021 ?? 0) + query.Num // 宸插彂鏂欐暟閲�
-                })
-                .Where(it => it.Guid == womdab.Guid && it.Dab003 == womdab.Dab003)
-                .ExecuteCommand();
-
-            // 鏇存柊鍙戣揣閫氱煡鍗曟槑缁嗗凡琛ユ暟閲�
-            executeCommand += db.Updateable<MesItemBlDetail>()
-                .SetColumns(it => new MesItemBlDetail
-                {
-                    Bld008 = (it.Bld008 ?? 0) + (int)query.Num
-                })
-                .Where(it => it.Id == blDetail.Id)
-                .ExecuteCommand();
-
-            // 鑾峰彇鏇存柊鍚庣殑鍙戣揣閫氱煡鍗曟槑缁嗘暟閲�
-            var updatedDetail = db.Queryable<MesItemBlDetail>()
-                .Where(it => it.Id == blDetail.Id)
-                .Select(it => new { it.Bld007, it.Bld008 })
-                .First();
-
-            if ((updatedDetail.Bld007 ?? 0) <= (updatedDetail.Bld008 ?? 0))
-                // 鏇存柊鏄庣粏瀹屾垚鐘舵��
-                executeCommand += db.Updateable<MesItemBlDetail>()
-                    .SetColumns(it => new MesItemBlDetail { Bld011 = 1 })
-                    .Where(it => it.Id == blDetail.Id)
-                    .ExecuteCommand();
-
-            // 妫�鏌ユ槸鍚﹁繕鏈夋湭瀹屾垚鐨勬槑缁�
-
-            var unfinishedDetail = db.Queryable<MesItemBlDetail>()
-                .Where(it => it.Mid == mesItemBl.Id && (it.Bld011 ?? 0) == 0)
-                .First();
-
-            if (unfinishedDetail == null)
-                // 濡傛灉娌℃湁鎵惧埌鏈畬鎴愭槑缁嗭紝鍒欐洿鏂板彂璐ч�氱煡鍗曠姸鎬佷负宸插畬鎴�
-                executeCommand += db.Updateable<MesItemBl>()
-                    .SetColumns(it => new MesItemBl
+                    conn.Open();
+                    cmd.CommandType = CommandType.StoredProcedure;
+                    SqlParameter[] parameters =
                     {
-                        Bl019 = true,
-                        WcUser = query.userName,
-                        WcTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
-                    })
-                    .Where(it => it.Id == mesItemBl.Id)
-                    .ExecuteCommand();
+                        new("@outMsg", SqlDbType.NVarChar, 2000),
+                        new("@outSum", SqlDbType.NVarChar, 300),
+                        new("@outCfBar", SqlDbType.NVarChar, 300),
+                        new("@c_user", query.userName),
+                        new("@p_biLL_no", query.billNo),
+                        new("@p_item_barcode", query.barcode),
+                        new("@NUM", query.Num)
+                    };
+                    parameters[0].Direction = ParameterDirection.Output;
+                    parameters[1].Direction = ParameterDirection.Output;
+                    parameters[2].Direction = ParameterDirection.Output;
+                    foreach (var parameter in parameters)
+                        cmd.Parameters.Add(parameter);
+                    cmd.ExecuteNonQuery();
+                    _strMsg = parameters[0].Value.ToString();
+                    _intSum = parameters[1].Value.ToString();
+                    _cfBar = parameters[2].Value.ToString();
 
-            if (executeCommand <= 1) throw new Exception("鏇存柊澶辫触");
 
-            return executeCommand;
-        }) > 0;
+                    var result = Convert.ToInt32(_intSum);
+                    if (result <= 0) throw new Exception(_strMsg);
 
-        // 鑾峰彇鏈�缁堢殑寰呭彂鏂欐槑缁嗗垪琛�
-        var pendingList = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) =>
-                new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
-            .Where((a, b) => a.BlNo == query.blNo
-                             && (b.Bld007 ?? 0) - (b.Bld008 ?? 0) > 0)
-            .Select((a, b) => new MesItemBlDetail
-            {
-                Bld012 = b.Bld012,
-                Bld002 = b.Bld002,
-                Bld003 = b.Bld003,
-                Bld004 = b.Bld004,
-                Bld007 = b.Bld007,
-                Bld008 = b.Bld008
-            })
-            .ToList();
+                    var dto = new ProductionPickDto
+                    {
+                        daa001 = query.billNo,
+                        barcode = query.barcode,//鍘熸潯鐮�
+                        cfBarcode = _cfBar//鎷嗗垎鍚庢潯鐮�
+                    };
 
-        return (success, pendingList);
+                    return dto;
+                }
+                catch (Exception ex)
+                {
+                    throw new Exception(ex.Message);
+                }
+                finally
+                {
+                    conn.Close();
+                }
+            }
+        }
     }
-
-    #endregion
-
+        #endregion
 }
\ No newline at end of file

--
Gitblit v1.9.3