From 004a418bd6674d62d06587030e29897ce430f0f2 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期三, 30 四月 2025 15:57:04 +0800
Subject: [PATCH] 1.异常处置单推送OA 2.现场管理新增现场收料的条码查询功能

---
 service/Warehouse/MesItemQtrkManager.cs |   93 ++++++++++++++++++++++++++++++++++------------
 1 files changed, 68 insertions(+), 25 deletions(-)

diff --git a/service/Warehouse/MesItemQtrkManager.cs b/service/Warehouse/MesItemQtrkManager.cs
index b5d74c2..73d3026 100644
--- a/service/Warehouse/MesItemQtrkManager.cs
+++ b/service/Warehouse/MesItemQtrkManager.cs
@@ -3,6 +3,7 @@
 using NewPdaSqlServer.entity;
 using NewPdaSqlServer.util;
 using SqlSugar;
+using System.Text.RegularExpressions;
 
 namespace NewPdaSqlServer.service.Warehouse;
 
@@ -56,34 +57,34 @@
 
     public string ScanInDepotsQT(WarehouseQuery query)
     {
-        var sectionCode = query.sectionCode;
+      var sectionCode = query.sectionCode;
         var billNo = query.billNo;
 
         // 1. 楠岃瘉搴撲綅鏉$爜鏄惁涓虹┖
         if (string.IsNullOrEmpty(sectionCode)) throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
 
         // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮�
-        var depotCode = Db.Queryable<MesDepotSections, MesDepots>(
+        var depotId = Db.Queryable<MesDepotSections, MesDepots>(
                 (a, b) => new JoinQueryInfos(
                     JoinType.Inner, a.DepotGuid == b.Guid))
             .Where((a, b) => a.DepotSectionCode == sectionCode)
-            .Select((a, b) => b.DepotCode)
+            .Select((a, b) => b.DepotId)
             .First();
 
-        if (depotCode == null)
+        if (depotId == null)
             throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
 
         // 3. 鏌ヨ鐢宠鍗曞搴旂殑浠撳簱
         var qtrk = Db.Queryable<MesItemQtrk>()
             .Where(x => x.Qtck == billNo)
-            .Select(x => x.Qt011)
+            .Select(x => x.Qt008)
             .First();
 
         if (qtrk == null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
 
         // 4. 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱
-        if (depotCode != qtrk)
-            throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇锋浠撳簱!");
+        if (depotId != Convert.ToInt32(qtrk))
+            throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇蜂粨搴�!");
 
         // 5. 杩斿洖鎴愬姛淇℃伅
         return $"浠撳簱锛歿qtrk} 搴撲綅锛歿sectionCode}";
@@ -118,6 +119,13 @@
         var c_depot_code = depotInfo.DepotCode;
         var c_depot_id = depotInfo.DepotId;
 
+        var mesDepost = Db.Queryable<MesDepots>()
+                .Where(s => s.DepotId == c_depot_id).First();
+
+        
+
+
+
         // 3. 楠岃瘉鏉$爜鏄惁宸插叆搴�
         var existsInStock = Db.Queryable<MesInvItemInCDetails>()
             .Any(x => x.ItemBarcode == p_item_barcode);
@@ -131,7 +139,7 @@
 
         if (barcode == null) throw new Exception("鏉$爜涓嶅瓨鍦�,璇锋牳瀵癸紒");
 
-        if (barcode.ComeFlg != 3) throw new Exception("鏉$爜涓嶆槸鍏朵粬鍏ュ簱鏉$爜,鏃犳硶鐢ㄥ叾浠栧叆搴擄紒");
+        //if (barcode.ComeFlg != 3) throw new Exception("鏉$爜涓嶆槸鍏朵粬鍏ュ簱鏉$爜,鏃犳硶鐢ㄥ叾浠栧叆搴擄紒");
 
         // 楠岃瘉鏉$爜鏄惁宸插湪搴撳瓨涓�
         var stockCount = Db.Queryable<MesInvItemStocks>()
@@ -146,6 +154,10 @@
             .First();
 
         if (qtrk == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪锛�");
+
+        //  楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱
+        if (c_depot_id != Convert.ToInt32(qtrk.Qt008))
+            throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!");
 
         // 6. 鏌ヨ鐢宠鍗曟槑缁�
         var detail = Db.Queryable<MesItemQtrrDetail>()
@@ -163,18 +175,37 @@
 
         var details = new List<MesItemQtrrDetail>();
 
-        // 8. 鎵ц鍏ュ簱浜嬪姟
+        string pattern = @"\(([^)]+)\)";
+        Match match = Regex.Match(qtrk.Qt023, pattern);
+        var owner_type = "";
+
+        // 8.鑾峰彇璐т富绫诲瀷
+        if (match.Success)
+        {
+            owner_type = match.Groups[1].Value;
+        }
+        else
+        {
+            throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曡揣涓荤被鍨嬫湁璇�,璇锋牳瀵癸紒");
+        }
+
+
+
+        // 10. 鎵ц鍏ュ簱浜嬪姟
         UseTransaction(db =>
         {
             var res = 0;
             // 鏌ヨ鏄惁瀛樺湪鏈叆搴撶殑鍏ュ簱鍗�
             var existingInv = db.Queryable<MesInvItemIns>()
                 .Where(x => x.Status == 0
+                            && x.InsDate.Value.ToString("yyyy-MM-dd") == DateTime.Now.ToString("yyyy-MM-dd")
                             && x.TransctionNo == transactionNo.ToString()
-                            && x.CbillNo == p_bill_no
-                            && x.SuppNo == barcode.SuppNo
+                            && x.TaskNo == p_bill_no
+                            //&& x.CbillNo == p_bill_no
+                            && x.BillTypeId == billTypeId
+                            && x.DepotsId == Convert.ToInt64(c_depot_id))
                             // && x.DepotsCode == c_depot_code)
-                            && x.DepotsId == c_depot_id)
+                            //&& x.SuppNo == barcode.SuppNo)
                 .First();
 
             var newId = Guid.Empty;
@@ -183,7 +214,7 @@
             if (existingInv == null)
             {
                 newId = Guid.NewGuid();
-                billNo = BillNo.GetBillNo("INV_IN_OTHER");
+                billNo = BillNo.GetBillNo("QTRK(鍏朵粬鍏ュ簱)");
 
                 barcode.UrgentFlag ??= false;
 
@@ -200,11 +231,16 @@
                     CreateDate = DateTime.Now,
                     LastupdateBy = c_user,
                     LastupdateDate = DateTime.Now,
-                    UrgentFlag = barcode.UrgentFlag.Value ? (byte)1 : (byte)0,
-                    CbillNo = p_bill_no,
+                    UrgentFlag = barcode.UrgentFlag.Value ? "1" : "0",
+                    //CbillNo = p_bill_no,
                     Fstatus = 0,
                     Status = 0,
-                    Reason = qtrk.Qt010
+                    Reason = qtrk.Qt010,
+                    TaskNo = p_bill_no,
+                    DepotsId = Convert.ToInt64(c_depot_id) ,
+                    InType = "鍏朵粬鍏ュ簱",
+                    ReceiveOrgId = qtrk.Qt022
+
                 }).IgnoreColumns(true).ExecuteCommand();
             }
             else
@@ -217,8 +253,9 @@
             var existingItem = db.Queryable<MesInvItemInCItems>()
                 .Where(x => x.ItemInId == newId
                             && x.ItemId == barcode.ItemId
-                            && x.WorkNo == barcode.WorkNo
-                            && x.WorkLine == barcode.WorkLine)
+                            && x.DepotId == c_depot_id.ToString()
+                             )
+                //&& x.DepotCode =
                 .First();
 
             if (existingItem == null)
@@ -246,7 +283,9 @@
                     Remark = barcode.Memo,
                     EbelnK3id = barcode.EbelnK3id,
                     LineK3id = barcode.LineK3id,
-                    ItemId = barcode.ItemId
+                    ItemId = barcode.ItemId,
+                    DepotId = c_depot_id.ToString(),
+                    itemDabid = barcode.AboutGuid.ToString(),
                 }).IgnoreColumns(true).ExecuteCommand();
             else
                 // 瀛樺湪鍒欐洿鏂版暟閲�
@@ -254,9 +293,8 @@
                     .SetColumns(
                         x => x.Quantity == x.Quantity + barcode.Quantity)
                     .Where(x => x.ItemInId == newId
-                                && x.ItemId == barcode.ItemId
-                                && x.WorkNo == barcode.WorkNo
-                                && x.WorkLine == barcode.WorkLine)
+                            && x.ItemId == barcode.ItemId
+                            && x.DepotId == c_depot_id.ToString())
                     .ExecuteCommand();
 
 
@@ -274,7 +312,7 @@
                 LotNo = barcode.LotNo,
                 SuppId = barcode.SuppId,
                 SuppNo = barcode.SuppNo,
-                DepotId = c_depot_id,
+                DepotId = Convert.ToInt64(c_depot_id),
                 DepotCode = c_depot_code,
                 DepotSectionCode = p_section_code,
                 ItemSname = barcode.ItemSname,
@@ -361,7 +399,11 @@
                 EbelnK3id = barcode.EbelnK3id,
                 LineK3id = barcode.LineK3id,
                 ItemId = barcode.ItemId,
-                BillNo = barcode.BillNo
+                BillNo = barcode.BillNo,
+                OwnerId = qtrk.Qt024,
+                OwnerType = owner_type,
+                StockOrgId = qtrk.Qt022,
+                IndepUserCode = c_user
                 // SalesOrder = barcode.SalesOrder,
                 // IsZy = barcode.IsZy,
                 // Visable = 0,
@@ -377,7 +419,8 @@
             // 鏇存柊鐢宠鍗曟槑缁嗗凡鍏ュ簱鏁伴噺
             res += db.Updateable<MesItemQtrrDetail>()
                 .SetColumns(x => x.Qd008 == (x.Qd008 ?? 0) + barcode.Quantity)
-                .Where(x => x.Guid == barcode.Guid)
+                .Where(x => x.QtrkGuid == qtrk.Guid &&
+                x.ItemId == barcode.ItemId.ToString())
                 .ExecuteCommand();
 
             // 妫�鏌ユ槸鍚﹀畬鍏ㄥ叆搴撳苟鏇存柊鐘舵��

--
Gitblit v1.9.3