From 4910c0fa81d93635e19a57c073c3a62c76053320 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期五, 25 七月 2025 13:24:18 +0800
Subject: [PATCH] 1.巡检扫描工位

---
 service/Warehouse/MesItemQtrkManager.cs |  102 +++++++++++++++++++++++++++++++++++---------------
 1 files changed, 71 insertions(+), 31 deletions(-)

diff --git a/service/Warehouse/MesItemQtrkManager.cs b/service/Warehouse/MesItemQtrkManager.cs
index 14e0390..2ef12c8 100644
--- a/service/Warehouse/MesItemQtrkManager.cs
+++ b/service/Warehouse/MesItemQtrkManager.cs
@@ -12,10 +12,17 @@
 {
     public List<string> GetQtckList()
     {
-        return Db.Queryable<MesItemQtrk>()
-            .Where(x => (x.Qt015 ?? 0) == 1 && (x.Qt014 ?? 0) == 0)
-            .Select(x => x.Qtck)
-            .ToList();
+        //return Db.Queryable<MesItemQtrk>()
+        //    .Where(x => (x.Qt015 ?? 0) == 1 && (x.Qt014 ?? 0) == 0)
+        //    .Select(x => x.Qtck)
+        //    .ToList();
+
+        const string sql = @"SELECT qtck 
+                        FROM MES_ITEM_QTRK 
+                        WHERE  QT015 = 1 AND QT028 = 1 AND QT032 = 1
+                          AND QT014 = 0  ";
+
+        return Db.Ado.SqlQuery<string>(sql);
     }
 
     public ProductionPickDto GetQtckDetailList(WarehouseQuery query)
@@ -27,11 +34,12 @@
         if (mesInvItemOuts == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪");
 
         var sql = @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,
-                    A.qd007 FQty,A.qd008 SQty,A.qd007 - A.qd008 DSQty
+                    ISNULL(A.qd007,0) FQty,ISNULL(A.qd008,0) SQty,ISNULL(A.qd007,0) - ISNULL(A.qd008,0) DSQty
                     FROM MES_ITEM_QTRR_DETAIL A
                     LEFT JOIN MES_ITEM_QTRK B ON A.qtrkGuid = B.guid
                     LEFT JOIN MES_ITEMS C ON A.itemId = C.item_id
-                    WHERE B.qtck = @billNo";
+                    WHERE B.qtck = @billNo AND QT015 = 1 AND QT028 = 1 AND QT032 = 1  ";
+        //AND QT014 = 0
 
         var sqlParams = new List<SugarParameter> {
             new("@billNo", query.billNo)
@@ -39,6 +47,8 @@
 
         var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql, sqlParams);
 
+        if (womdabs.Count < 1)
+            throw new Exception($"璇ュ叾浠栧叆搴撶敵璇峰崟 {query.billNo} 鏈叏閮ㄥ鏍告垨宸插畬缁擄紝璇风‘璁わ紒");
 
         var DS_list = womdabs.Where(s => s.DSQty > 0).ToList();
 
@@ -55,7 +65,7 @@
         return dto;
     }
 
-    public string ScanInDepotsQT(WarehouseQuery query)
+    public dynamic ScanInDepotsQT(WarehouseQuery query)
     {
       var sectionCode = query.sectionCode;
         var billNo = query.billNo;
@@ -63,31 +73,24 @@
         // 1. 楠岃瘉搴撲綅鏉$爜鏄惁涓虹┖
         if (string.IsNullOrEmpty(sectionCode)) throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
 
-        // 2. 鏌ヨ搴撲綅瀵瑰簲鐨勪粨搴撶紪鐮�
-        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.DepotId)
-            .First();
+        var sqlParams = new List<SugarParameter> { new("@sectionCode", sectionCode) };
 
-        if (depotId == null)
+        var sql2 = @"        SELECT TOP 1  b.depot_code,
+                      b.depot_id,
+                     B.FSubsidiary,
+                     B.depot_name
+        FROM MES_DEPOT_SECTIONS a
+                 INNER JOIN
+             MES_DEPOTS b ON a.depot_guid = b.Guid
+        WHERE a.depot_section_code = @sectionCode;";
+
+        var depotInfo = Db.Ado.SqlQuery<dynamic>(sql2, sqlParams).First();
+
+        if (depotInfo is  null)
             throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
 
-        // 3. 鏌ヨ鐢宠鍗曞搴旂殑浠撳簱
-        var qtrk = Db.Queryable<MesItemQtrk>()
-            .Where(x => x.Qtck == billNo)
-            .Select(x => x.Qt008)
-            .First();
-
-        if (qtrk == null) throw new Exception($"搴撲綅缂栫爜 {sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
-
-        // 4. 楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱
-        if (depotId != Convert.ToInt32(qtrk))
-            throw new Exception($"鎵爜搴撲綅 {sectionCode} 涓嶅睘浜庣敵璇蜂粨搴�!");
-
         // 5. 杩斿洖鎴愬姛淇℃伅
-        return $"浠撳簱锛歿qtrk} 搴撲綅锛歿sectionCode}";
+        return depotInfo;
     }
 
     public (WarehouseQuery form, List<MesItemQtrrDetail> item)
@@ -118,6 +121,21 @@
 
         var c_depot_code = depotInfo.DepotCode;
         var c_depot_id = depotInfo.DepotId;
+
+        var sqlParams = new List<SugarParameter> { new("@barcode", p_item_barcode), new("@billNo", p_bill_no) };
+
+        var sql1 = @"   SELECT TOP 1 A.rkCkId
+FROM MES_QA_ITEMS_DETECT_01 A
+         LEFT JOIN MES_INV_ITEM_BARCODES B ON A.item_id = B.ITEM_ID
+WHERE order_type = '鍏跺畠鍏ュ簱妫�'
+  AND A.lot_no = @billNo
+  AND ITEM_BARCODE = @barcode   ";
+
+        var appDepotInfo = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams).First();
+
+        if(appDepotInfo.rkCkId != c_depot_id)
+            throw new Exception($"璇� {p_section_code} 瀵瑰簲鐨勪粨搴� 涓� 妫�楠屽垽瀹氱殑鍏ュ簱浠撳簱涓嶄竴鑷达紝璇风‘璁わ紒");
+
 
         var mesDepost = Db.Queryable<MesDepots>()
                 .Where(s => s.DepotId == c_depot_id).First();
@@ -155,9 +173,26 @@
 
         if (qtrk == null) throw new Exception("鍏朵粬鍏ュ簱鐢宠鍗曚笉瀛樺湪锛�");
 
-        //  楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱
-        if (c_depot_id != Convert.ToInt32(qtrk.Qt008))
-            throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!");
+        var sql = @"SELECT c.item_no ItemNo,c.item_name ItemName,c.item_model ItemModel,
+                    ISNULL(A.qd007,0) FQty,ISNULL(A.qd008,0) SQty,ISNULL(A.qd007,0) - ISNULL(A.qd008,0) DSQty
+                    FROM MES_ITEM_QTRR_DETAIL A
+                    LEFT JOIN MES_ITEM_QTRK B ON A.qtrkGuid = B.guid
+                    LEFT JOIN MES_ITEMS C ON A.itemId = C.item_id
+                    WHERE B.qtck = @billNo AND QT015 = 1 AND QT028 = 1 AND QT032 = 1 AND QT014 = 0 ";
+        //AND QT014 = 0
+
+        var sqlParams1 = new List<SugarParameter> {
+            new("@billNo", p_bill_no)
+        };
+
+        var womdabs = Db.Ado.SqlQuery<ItemDetailModel>(sql, sqlParams1);
+
+        if (womdabs.Count < 1)
+            throw new Exception($"璇ュ叾浠栧叆搴撶敵璇峰崟 {query.billNo} 鏈叏閮ㄥ鏍告垨宸插畬缁擄紝璇风‘璁わ紒");
+
+        ////  楠岃瘉搴撲綅鏄惁灞炰簬鐢宠浠撳簱
+        //if (c_depot_id != Convert.ToInt32(qtrk.Qt008))
+        //    throw new Exception($"鎵爜搴撲綅 {p_section_code} 涓嶅睘浜庣敵璇蜂粨搴�!");
 
         // 6. 鏌ヨ鐢宠鍗曟槑缁�
         var detail = Db.Queryable<MesItemQtrrDetail>()
@@ -458,6 +493,11 @@
                     .Where(x => x.Qtck == p_bill_no)
                     .ExecuteCommand();
 
+            // 鍒涘缓 鎻掑叆鏃ュ織
+            var logService = new LogService();
+            var LogMsg = "銆怭DA銆戝叾浠栧叆搴撱�傛潯鐮併��" + query.barcode + "銆戞暟閲忋��" + barcode.Quantity.ToString() + "銆� 鍏ュ簱鍗曞彿銆�" + billNo + "銆�";
+            logService.CreateLog(db, query.userName, qtrk.Guid.ToString(), "MES_ITEM_QTRK", LogMsg, qtrk.Qtck);
+
             if (res < 5) throw new Exception("鎻掑叆鎴栨洿鏂板け璐�");
 
             return res;

--
Gitblit v1.9.3