From 1be2fc056943ba8b9e62328430e15beee03e8a9f Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期一, 02 六月 2025 13:46:48 +0800
Subject: [PATCH] 1.生产补料优化 2.首检开发-v1

---
 service/Warehouse/MesItemBlManager.cs |  303 ++++++++++++++++++++++++++++++++++----------------
 1 files changed, 204 insertions(+), 99 deletions(-)

diff --git a/service/Warehouse/MesItemBlManager.cs b/service/Warehouse/MesItemBlManager.cs
index 2d70ca7..ca78cba 100644
--- a/service/Warehouse/MesItemBlManager.cs
+++ b/service/Warehouse/MesItemBlManager.cs
@@ -1,6 +1,8 @@
-锘縰sing NewPdaSqlServer.DB;
+锘縰sing Masuit.Tools;
+using NewPdaSqlServer.DB;
 using NewPdaSqlServer.Dto.service;
 using NewPdaSqlServer.entity;
+using NewPdaSqlServer.entity.Base;
 using NewPdaSqlServer.util;
 using SqlSugar;
 
@@ -14,12 +16,13 @@
     ///     鑾峰彇鐢熶骇琛ユ枡鍗曞彿鍒楄〃
     /// </summary>
     /// <returns>琛ユ枡鍗曞彿鍒楄〃</returns>
-    public List<string> GetSCBLBillNo()
+    public List<string> GetSCBLBillNo(WarehouseQuery query)
     {
         var list = Db.Queryable<MesItemBl>()
             .Where(s => (s.Bl018 ?? false) == true
-                        && (s.Bl019 ?? false) == false
-                        && s.Bl008 == "鐢熶骇琛ユ枡")
+                        //&& (s.Bl019 ?? false) == false
+                        && s.Bl008 == query.Type)
+            .OrderByDescending(s => s.Bl006)
             .Select(s => s.BlNo)
             .ToList();
         return list;
@@ -30,7 +33,7 @@
     /// </summary>
     /// <param name="billNo">琛ユ枡鍗曞彿</param>
     /// <returns>琛ユ枡鍗曟槑缁嗗垪琛�</returns>
-    public (string bl001, List<MesItemBlDetail> item)
+    public ProductionPickDto
         GetMesItemBlDetailByBillNo(
             WarehouseQuery query)
     {
@@ -39,35 +42,60 @@
 
         // 妫�鏌ヨˉ鏂欏崟鏄惁瀛樺湪涓斾负鐢熶骇琛ユ枡绫诲瀷
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.billNo && a.Bl008 == "鐢熶骇琛ユ枡")
+            .Where(a => a.BlNo == query.billNo && a.Bl008 == query.Type && a.Bl018 == true)
             .First();
 
         if (mesItemBl == null)
-            throw new Exception("鍗曟嵁鍙蜂笉姝g‘锛�");
+            throw new Exception("鍗曟嵁鍙蜂笉瀛樺湪鎴栨湭瀹℃牳锛�");
 
-        if (mesItemBl.Bl019 == true)
-            throw new Exception("鍗曟嵁鍙峰凡瀹屾垚锛�");
+        //if (mesItemBl.Bl019 == true)
+        //    throw new Exception("鍗曟嵁鍙峰凡瀹屾垚锛�");
 
-        // 鑾峰彇鏈畬鎴愮殑琛ユ枡鍗曟槑缁�
-        var blDetails = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) =>
-                new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
-            .Where((a, b) => a.BlNo == query.billNo
-                             && (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 blDetails = Db.Queryable<MesItemBl, MesItemBlDetail>((a, b) =>
+        //        new JoinQueryInfos(JoinType.Left, a.Id == b.Mid))
+        //    .Where((a, b) => a.BlNo == query.billNo
+        //                     && (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();
 
-        return (mesItemBl.Bl001, blDetails);
+        //return (mesItemBl.Bl001, blDetails);
+        var sql = string.Format(@"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,A.BLD007 FQty,A.BLD008 SQty,A.BLD007 - A.BLD008 DSQty,
+       dbo.F_QX_GETRECODEPOTSE(A.bld012) as RecoKw,D.daa001
+fROM MES_ITEM_BL_DETAIL A
+         LEFT JOIN MES_ITEM_BL B ON A.MID = B.ID
+         LEFT JOIN MES_ITEMS C ON A.bld012 = CAST(C.item_id AS VARCHAR(50))
+         LEFT JOIN WOMDAA D ON B.about_guid = D.guid
+WHERE B.bl_no = '{0}'", query.billNo);
+
+        var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql);
+
+
+        var DS_list = womdabs.Where(s => s.DSQty > 0).ToList();
+
+        var YS_list = womdabs.Where(s => s.SQty > 0).ToList();
+
+        var dto = new ProductionPickDto
+        {
+            daa001 = womdabs[0].DAA001,
+            //PlanNo = womcaa.Caa020,
+            items = DS_list,
+            Ysitems = YS_list
+        };
+
+        return dto;
     }
 
     /// <summary>
+    /// 鐢熶骇宸ュ崟琛ユ枡鎵爜
     ///     鎵弿鏉$爜  prc_rf_pda_scan_zout_barcode3
     /// </summary>
     /// <param name="query">鏌ヨ鍙傛暟</param>
@@ -80,11 +108,11 @@
     ///     - blNo: 琛ユ枡鍗曞彿(蹇呭~)
     /// </remarks>
     public (WarehouseQuery item, List<MesItemBlDetail> pendingList)
-        SctlScanBarcode(
+        ScblScanBarcode(
             WarehouseQuery query)
     {
-        if (string.IsNullOrEmpty(query.billNo))
-            throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
+        //if (string.IsNullOrEmpty(query.billNo))
+        //    throw new Exception("璇烽�夊彇鍗曟嵁鍙凤紒");
 
         if (string.IsNullOrEmpty(query.barcode))
             throw new Exception("璇锋壂鎻忔潯鐮侊紒");
@@ -93,7 +121,7 @@
             throw new Exception("鐢ㄦ埛鍚嶄笉鑳戒负绌猴紒");
 
         if (string.IsNullOrEmpty(query.blNo))
-            throw new Exception("琛ユ枡鍗曞彿涓嶈兘涓虹┖锛�");
+            throw new Exception("鐢宠鍗曞彿涓嶈兘涓虹┖锛�");
 
 
         // 妫�楠屾槸鍚﹂噸澶嶆壂鎻�
@@ -112,9 +140,13 @@
         if (stockBarcode == null)
             throw new Exception($"搴撳瓨涓棤姝ゆ潯鐮�,璇锋牳瀵癸紒{query.barcode}");
 
+        var depots = Db.Queryable<MesDepots>()
+            .Where(t => t.DepotId == stockBarcode.DepotId)
+            .First();
+
         // 妫�鏌ヨˉ鏂欏崟鐘舵��
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false)
+            .Where(a => a.BlNo == query.blNo)
             .First();
 
         if (mesItemBl == null)
@@ -139,6 +171,16 @@
         var quantity = (blDetail.Bld007 ?? 0) - (blDetail.Bld008 ?? 0);
         if (quantity == 0)
             throw new Exception("鐗╂枡宸叉壂鐮佸畬鎴愶紝璇锋牳瀵癸紒");
+
+
+        if(stockBarcode.Quantity >  quantity)
+        {
+            query.status = 2;
+            query.message = "鏉$爜搴撳瓨澶т簬闇�棰嗭紝璇锋媶鍒嗭紒";
+            query.CfNum = quantity;
+            query.Num = stockBarcode.Quantity;
+            return (query, []);
+        }
 
         // 妫�鏌ュ伐鍗曚俊鎭�
         var womdaa = Db.Queryable<Womdaa>()
@@ -184,13 +226,21 @@
         // 寮�鍚簨鍔″鐞�
         var success = UseTransaction(db =>
         {
+            var outNoType = "";
+            if(query.Type == "鐢熶骇琛ユ枡")
+            {
+                outNoType = "SCBL(鐢熶骇琛ユ枡)";
+            }else 
+            {
+                outNoType = "SCCL(鐢熶骇瓒呴)";
+            }
             // 鑾峰彇鎴栧垱寤哄嚭搴撳崟
             var outId = Guid.NewGuid();
-            var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)");
+            var outNo = BillNo.GetBillNo(outNoType);
 
             var existingOut = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .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
@@ -218,8 +268,9 @@
                     BillTypeId = 200,
                     TransactionNo = 209,
                     Remark = mesItemBl.Bl007,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     OutPart = womdaa.Daa013,
+                    OutType = query.Type,
                     FType = 0,
                     Factory = stockBarcode.Factory,
                     Company = stockBarcode.Company,
@@ -228,23 +279,25 @@
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
                     Status = 0,
-                    BbillNo = query.blNo
+                    DepotId = stockBarcode.DepotId,
+                    THORGID = stockBarcode.StockOrgId,
+                    //BbillNo = query.billNo
                 }).IgnoreColumns(true).ExecuteCommand();
             }
 
             // 妫�鏌ュ苟鏇存柊鍑哄簱鍗曠墿鏂欐槑缁�
             var itemCount = db.Queryable<MesInvItemOutItems>()
                 .Where(i =>
-                    i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId)
+                    i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
                 .Count();
 
             if (itemCount > 0)
                 // 鏇存柊宸插瓨鍦ㄧ殑鐗╂枡鏄庣粏鏁伴噺
                 db.Updateable<MesInvItemOutItems>()
                     .SetColumns(i =>
-                        i.Quantity == i.Quantity + stockBarcode.Quantity)
+                        i.TlQty == i.TlQty + stockBarcode.Quantity)
                     .Where(i =>
-                        i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId)
+                        i.ItemOutId == outId && i.ItemId == stockBarcode.ItemId && i.ItemOutId == outId && i.DepotId == stockBarcode.DepotsId.ToString())
                     .ExecuteCommand();
             else
                 // 鎻掑叆鏂扮殑鐗╂枡鏄庣粏璁板綍
@@ -254,13 +307,14 @@
                     ItemOutId = outId,
                     ItemNo = blDetail.Bld002,
                     Quantity = stockBarcode.Quantity,
+                    TlQty = stockBarcode.Quantity,
                     CreateBy = query.userName,
                     CreateDate = DateTime.Now,
                     LastupdateBy = query.userName,
                     LastupdateDate = DateTime.Now,
                     Factory = stockBarcode.Factory,
                     Company = stockBarcode.Company,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     TaskNo = query.blNo,
                     WorkNo = womdaa.Daa021,
                     WorkLine = blDetail.Bld013,
@@ -268,7 +322,9 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotsId.ToString(),
+                    ItemDabid = blDetail.Id,
                     // Unit = blDetail.Bld009,
                     // DepotId = (int)stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
@@ -287,7 +343,7 @@
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
                 LastupdateDate = DateTime.Now,
-                DepotCode = stockBarcode.DepotsCode,
+                DepotCode = depots.DepotCode,
                 DepotSectionCode = stockBarcode.DepotSectionsCode,
                 Remark = blDetail.Bld010,
                 Factory = stockBarcode.Factory,
@@ -301,7 +357,7 @@
                 PbillNo = query.billNo,
                 ItemId = blDetail.Bld012,
                 Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId,
+                DepotId = (int)stockBarcode.DepotId,
                 EbelnK3id = womdab.Eid,
                 LineK3id = womdab.Erpid
             }).IgnoreColumns(true).ExecuteCommand();
@@ -312,7 +368,7 @@
                 Guid = Guid.NewGuid(),
                 Status = 1,
                 BillTypeId = 200, // p_bill_type_id
-                TransactionCode = "210", // p_transaction_no
+                TransactionCode = "209", // p_transaction_no
                 BusinessType = -1,
                 ItemBarcode = stockBarcode.ItemBarcode,
                 ItemNo = stockBarcode.ItemNo,
@@ -345,7 +401,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab021 = (it.Dab021 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
+                .Where(it => it.Guid == womdab.DaaGuid && it.Dab003 == womdab.Dab003)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
@@ -443,7 +499,7 @@
         if (string.IsNullOrEmpty(query.barcode))
             throw new Exception("璇锋壂鎻忔潯鐮侊紒");
 
-        if (query.Num <= 0)
+        if ((query.Num ?? 0) <= 0)
             throw new Exception("璇疯緭鍏ユ纭殑鍙戞枡鏁伴噺锛�");
 
         if (string.IsNullOrEmpty(query.blNo))
@@ -469,6 +525,16 @@
         var totalQty = stockBarcode.Quantity;
         string newBarcode = null;
 
+        var outNoType = "";
+        if (query.Type == "鐢熶骇琛ユ枡")
+        {
+            outNoType = "SCBL(鐢熶骇琛ユ枡)";
+        }
+        else
+        {
+            outNoType = "SCCL(鐢熶骇瓒呴)";
+        }
+
         // 寮�鍚簨鍔″鐞�
         var success = UseTransaction(db =>
         {
@@ -481,7 +547,7 @@
                     .Where(s => s.Id == stockBarcode.ItemId).First();
 
                 // 鐢熸垚鏂版潯鐮佸彿
-                newBarcode = BillNo.GetBillNo("TMBH(鏉$爜缂栧彿)", mesItems.ItemNo);
+                newBarcode = BillNo.GetBillNo("TM(鏉$爜)", mesItems.ItemNo);
 
                 // 鍐欏叆鏂版潯鐮�
                 executeCommand += db.Insertable(new MesInvItemBarcodes
@@ -505,8 +571,8 @@
                     // Mblnr = stockBarcode.Mblnr,
                     // Zeile = stockBarcode.Zeile,
                     // RohInId = stockBarcode.RohInId,
-                    // BarcodeStatus = 0,
-                    // OldQty = query.Num,
+                    Barcodestatus = false,
+                    Oldqty = query.Num as long?,
                     // Unit = stockBarcode.Unit,
                     // WeightUnit = stockBarcode.WeightUnit,
                     Factory = stockBarcode.Factory,
@@ -519,32 +585,39 @@
                     // MemoBad = stockBarcode.MemoBad,
                     ComeFlg = 5,
                     // Memo = stockBarcode.Memo,
+                    SuppId = stockBarcode.SuppId,
                     SuppNo = stockBarcode.SuppNo,
-                    // InsDate = stockBarcode.InsDate, // Added InsDate
+                    InsDate = stockBarcode.IndepDate, // Added InsDate
                     ItemId = stockBarcode.ItemId
                     // ItemUnit = stockBarcode.ItemUnit // Added ItemUnit
                 }).IgnoreColumns(true).ExecuteCommand();
 
                 // 鏇存柊鍘熸潯鐮佹暟閲�
                 executeCommand += db.Updateable<MesInvItemBarcodes>()
-                    .SetColumns(it => it.Quantity == totalQty - query.Num)
+                    .SetColumns(it => it.Quantity == it.Quantity - query.Num)
                     .Where(it => it.ItemBarcode == query.barcode)
                     .ExecuteCommand();
 
-                // 鍒犻櫎鍘熸潯鐮佸簱瀛樿褰�
-                executeCommand += db.Deleteable<MesInvItemStocks>()
+                // 鏇存柊鍘熸潯鐮佹暟閲�
+                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 = stockBarcode.ItemBarcode,
+                    ItemBarcode = newBarcode,
                     ItemNo = stockBarcode.ItemNo,
                     LotNo = stockBarcode.LotNo,
-                    Quantity = totalQty - query.Num,
+                    Quantity = query.Num,
                     EpFlag = stockBarcode.EpFlag,
                     CustomerNo = stockBarcode.CustomerNo,
                     ItemWt = stockBarcode.ItemWt,
@@ -572,7 +645,7 @@
                     Status = 1,
                     BillTypeId = 200, // p_bill_type_id
                     TransactionCode = "209", // p_transaction_no
-                    BusinessType = -1,
+                    BusinessType = 0,
                     ItemBarcode = newBarcode,
                     ItemNo = stockBarcode.ItemNo,
                     LotNo = stockBarcode.LotNo,
@@ -582,7 +655,7 @@
                     FromInvDepotSectionsCode = null,
                     ToInvDepotsCode = stockBarcode.DepotsCode,
                     ToInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                    Description = null,
+                    Description = query.Type + "鎷嗗垎鐢熸垚",
                     CreateBy = query.userName,
                     CreateDate = DateTime.Now,
                     LastupdateBy = query.userName,
@@ -604,11 +677,11 @@
                 throw new Exception("鍙戞枡鏁伴噺澶т簬鏉$爜鏁�,璇锋牳瀵癸紒");
             }
 
-            if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
+            //if (string.IsNullOrEmpty(newBarcode)) newBarcode = query.barcode;
 
             // 妫�鏌ヨˉ鏂欏崟鐘舵��
             var mesItemBl = Db.Queryable<MesItemBl>()
-                .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == false)
+                .Where(a => a.BlNo == query.blNo && (a.Bl018 ?? false) == true)
                 .First();
 
             if (mesItemBl == null)
@@ -659,14 +732,19 @@
                     it.TaskNo == query.blNo && it.ItemId == stockBarcode.ItemId)
                 .Sum(it => it.Quantity);
 
-            if (sumQty > remainingQty)
-                throw new Exception(
-                    $"鎷嗗垎鏁伴噺锛歿sumQty} 澶т簬寰呭彂鏂欐暟閲忥細{remainingQty}锛岃鏍稿锛�");
+            //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.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .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
@@ -674,11 +752,13 @@
                             && a.Status == 0)
                 .First();
 
+            var outId = new Guid();
+            var outNo = "";
             if (itemOut == null)
             {
                 // 鍒涘缓鏂扮殑鍑哄簱鍗�
-                var outId = Guid.NewGuid();
-                var outNo = BillNo.GetBillNo("BL(宸ュ崟琛ユ枡)");
+                outId = Guid.NewGuid();
+                outNo = BillNo.GetBillNo(outNoType);
 
                 // 鎻掑叆鍑哄簱鍗曚富琛�
                 executeCommand += db.Insertable(new MesInvItemOuts
@@ -693,7 +773,7 @@
                     BillTypeId = 200,
                     TransactionNo = 209,
                     Remark = mesItemBl.Bl007,
-                    DepotCode = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     OutPart = womdaa.Daa013,
                     FType = 0,
                     Factory = stockBarcode.Factory,
@@ -703,15 +783,24 @@
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
                     Status = 0,
-                    BbillNo = query.blNo
+                    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 == itemOut.Guid &&
-                    it.ItemId == stockBarcode.ItemId)
+                    it.ItemOutId == outId &&
+                    it.ItemId == stockBarcode.ItemId && 
+                    it.DepotId == stockBarcode.DepotId.ToString())
                 .Count();
 
             if (itemOutItemCount == 0)
@@ -719,16 +808,17 @@
                 executeCommand += db.Insertable(new MesInvItemOutItems
                 {
                     Guid = Guid.NewGuid(),
-                    ItemOutId = itemOut.Guid,
+                    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 = womdab.Dab017,
+                    DepotCode = depots.DepotCode,
                     TaskNo = query.blNo,
                     WorkNo = womdaa.Daa021,
                     WorkLine = blDetail.Bld013,
@@ -736,24 +826,27 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotId.ToString(),
+                    ItemDabid = blDetail.Id,
                     // Unit = blDetail.Bld009,
                     // DepotId = (int)stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
             else
                 // 鏇存柊宸叉湁鍑哄簱鍗曟槑缁嗘暟閲�
                 executeCommand += db.Updateable<MesInvItemOutItems>()
-                    .SetColumns(it => it.Quantity == it.Quantity + query.Num)
+                    .SetColumns(it => it.TlQty == (it.TlQty ?? 0) + query.Num)
                     .Where(it =>
-                        it.ItemOutId == itemOut.Guid &&
-                        it.ItemId == stockBarcode.ItemId)
+                    it.ItemOutId == outId &&
+                    it.ItemId == stockBarcode.ItemId &&
+                    it.DepotId == stockBarcode.DepotId.ToString())
                     .ExecuteCommand();
 
             // 鎻掑叆鍑哄簱鏉$爜鏄庣粏
             executeCommand += db.Insertable(new MesInvItemOutCDetails
             {
                 Guid = Guid.NewGuid(),
-                ItemOutId = itemOut.Guid,
+                ItemOutId = outId,
                 ItemBarcode = newBarcode ?? query.barcode,
                 ItemNo = stockBarcode.ItemNo,
                 LotNo = stockBarcode.LotNo,
@@ -763,7 +856,7 @@
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
                 LastupdateDate = DateTime.Now,
-                DepotCode = stockBarcode.DepotsCode,
+                DepotCode = depots.DepotCode,
                 DepotSectionCode = stockBarcode.DepotSectionsCode,
                 Remark = blDetail.Bld010,
                 Factory = stockBarcode.Factory,
@@ -777,7 +870,8 @@
                 PbillNo = query.billNo,
                 ItemId = blDetail.Bld012,
                 Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId
+                DepotId = (int)stockBarcode.DepotId,
+                Dabid = womdab.Guid,
             }).IgnoreColumns(true).ExecuteCommand();
 
             // 鎻掑叆涓氬姟娴佹按
@@ -786,7 +880,7 @@
                 Guid = Guid.NewGuid(),
                 Status = 1,
                 BillTypeId = 200, // p_bill_type_id
-                TransactionCode = "210", // p_transaction_no 
+                TransactionCode = "209", // p_transaction_no 
                 BusinessType = 1,
                 ItemBarcode = newBarcode ?? query.barcode,
                 ItemNo = stockBarcode.ItemNo,
@@ -795,7 +889,7 @@
                 Quantity = query.Num,
                 FromInvDepotsCode = stockBarcode.DepotsCode,
                 FromInvDepotSectionsCode = stockBarcode.DepotSectionsCode,
-                Description = null,
+                Description = query.Type,
                 CreateBy = query.userName,
                 CreateDate = DateTime.Now,
                 LastupdateBy = query.userName,
@@ -819,8 +913,7 @@
                     Dab020 = (it.Dab020 ?? 0) + query.Num, // 宸插彂鏂欐暟閲�
                     Dab021 = (it.Dab021 ?? 0) + query.Num // 宸插彂鏂欐暟閲�
                 })
-                .Where(it => it.Id == womdab.Id && it.Dab003 == womdab.Dab003)
-                .IgnoreColumns(true)
+                .Where(it => it.Guid == womdab.DaaGuid && it.Dab003 == womdab.Dab003)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
@@ -865,6 +958,13 @@
 
             if (executeCommand <= 1) throw new Exception("鏇存柊澶辫触");
 
+
+            // 鍒涘缓 鎻掑叆鏃ュ織
+            var logService = new LogService();
+            var LogMsg = "[PDA]" + query.Type + "銆傛潯鐮併��" + query.barcode + "銆� 鍑哄簱鍗曞彿銆�" + outNo + "銆�";
+            logService.CreateLog(db, query.userName, womdaa.Guid.ToString(), "WOMDAA", LogMsg, womdaa.Daa001);
+
+
             return executeCommand;
         }) > 0;
 
@@ -891,12 +991,12 @@
 
     #region 鐢熶骇瓒呴
 
-    public List<string> GetSccList()
+    public List<string> GetSccList(WarehouseQuery query)
     {
         var list = Db.Queryable<MesItemBl>()
             .Where(s => (s.Bl018 ?? false) == true
                         && (s.Bl019 ?? false) == false
-                        && s.Bl008 == "鐢熶骇瓒呴")
+                        && s.Bl008 == query.Type)
             .Select(s => s.BlNo)
             .ToList();
         return list;
@@ -914,9 +1014,9 @@
         if (string.IsNullOrEmpty(query.billNo))
             throw new Exception("璇烽�夊崟鎹彿锛�");
 
-        // 妫�鏌ヨ秴棰嗗崟鏄惁瀛樺湪涓斾负鐢熶骇瓒呴绫诲瀷
+        // 妫�鏌ヨ秴棰嗗崟鏄惁瀛樺湪涓斾负鐢熶骇瓒呴/濮斿瓒呴绫诲瀷
         var mesItemBl = Db.Queryable<MesItemBl>()
-            .Where(a => a.BlNo == query.billNo && a.Bl008 == "鐢熶骇瓒呴")
+            .Where(a => a.BlNo == query.billNo && a.Bl008 == query.Type)
             .First();
 
         if (mesItemBl == null)
@@ -1099,8 +1199,8 @@
             var outId = Guid.Empty;
             var outNo = "";
             var outRecord = db.Queryable<MesInvItemOuts>()
-                .Where(a => a.BbillNo == query.blNo
-                            && a.DepotCode == womdab.Dab017
+                .Where(a => a.TaskNo == query.blNo
+                            && a.DepotId == stockBarcode.DepotId
                             && a.OutDate.Value.Date == DateTime.Now.Date
                             && a.BillTypeId == 200
                             && a.TransactionNo == 210
@@ -1129,7 +1229,7 @@
                     OutPart = womdaa.Daa013,
                     FType = 0,
                     WorkNo = womdaa.Daa021,
-                    OutType = "鐢熶骇瓒呴鍗�",
+                    OutType = query.Type,
                     BoardItem = womdaa.Daa002,
                     PbillNo = womdaa.Daa001,
                     OutDate = DateTime.Now,
@@ -1169,7 +1269,8 @@
                     ErpId = womdab.Eid,
                     ErpAutoid = womdab.Erpid,
                     PbillNo = query.billNo,
-                    ItemId = blDetail.Bld012
+                    ItemId = blDetail.Bld012,
+                    DepotId = stockBarcode.DepotId.ToString(),
                     // Unit = blDetail.Bld009,
                     // DepotId = stockBarcode.DepotsId
                 }).IgnoreColumns(true).ExecuteCommand();
@@ -1208,7 +1309,8 @@
                 PbillNo = query.billNo,
                 ItemId = blDetail.Bld012,
                 Unit = blDetail.Bld009,
-                DepotId = (int)stockBarcode.DepotsId
+                DepotId = (int)stockBarcode.DepotsId,
+                Dabid = womdab.Guid,
             }).IgnoreColumns(true).ExecuteCommand();
 
             // 鎻掑叆涓氬姟娴佹按
@@ -1247,7 +1349,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab023 = (it.Dab023 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == womdab.Id)
+                .Where(it => it.Guid == womdab.Guid)
                 .ExecuteCommand();
 
             // 鏇存柊瓒呴鍗曟槑缁�
@@ -1651,7 +1753,7 @@
                     Dab020 = (it.Dab020 ?? 0) + stockBarcode.Quantity,
                     Dab023 = (it.Dab023 ?? 0) + stockBarcode.Quantity
                 })
-                .Where(it => it.Id == workOrderDetail.Id)
+                .Where(it => it.Guid == workOrderDetail.Guid)
                 .ExecuteCommand();
 
             // 鏇存柊琛ユ枡鍗曟槑缁嗗凡琛ユ暟閲�
@@ -1692,18 +1794,21 @@
 
 
         // 鑾峰彇鏈�缁堢殑寰呭鐞嗗垪琛�
+        // 鑾峰彇琛ユ枡鍗曟槑缁嗕腑鏈畬鎴愮殑璁板綍
+        // 閫氳繃宸﹁繛鎺ユ煡璇㈣ˉ鏂欏崟(MesItemBl)鍜岃ˉ鏂欏崟鏄庣粏(MesItemBlDetail)琛�
+        // 鏉′欢: 1.琛ユ枡鍗曞彿鍖归厤 2.璁″垝鏁伴噺(Bld007)鍑忓幓宸茶ˉ鏁伴噺(Bld008)澶т簬0(鍗虫湭瀹屾垚鐨�)
         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
+                Bld012 = b.Bld012, // 鐗╂枡ID
+                Bld002 = b.Bld002, // 鐗╂枡缂栧彿
+                Bld003 = b.Bld003, // 鐗╂枡鍚嶇О
+                Bld004 = b.Bld004, // 鐗╂枡瑙勬牸
+                Bld007 = b.Bld007, // 璁″垝鏁伴噺
+                Bld008 = b.Bld008 // 宸茶ˉ鏁伴噺
             })
             .ToList();
 

--
Gitblit v1.9.3