From a5019b475f8620dba3b495da983f4db9e32f7ca8 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期四, 10 七月 2025 08:18:36 +0800
Subject: [PATCH] AOI

---
 MES.Service/service/Warehouse/MesInvItemMovesManager.cs |  221 +++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 198 insertions(+), 23 deletions(-)

diff --git a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
index 912ebd5..ce0d8ce 100644
--- a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
+++ b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
@@ -12,39 +12,128 @@
 
     //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 MesInvItemMovesManager.cs
 
-    public int ScanInBarcode(WarehouseQuery query)
+    public MovesDto ScanInBarcode(WarehouseQuery query)
     {
         if (string.IsNullOrEmpty(query.sectionCode))
-        {
             throw new Exception("璇锋壂搴撲綅鏉$爜锛�");
-        }
-        
-        int pBillTypeId = 300;
-        int pTransctionNo = 301;
-        
-        var depotQuery = Db.Queryable<MesDepotSections, MesDepots>((a, b) => new JoinQueryInfos(
-                JoinType.Inner, a.Zuid.ToString() == b.Zuid))
+
+        var pBillTypeId = 300;
+        var pTransctionNo = 301;
+
+        var depotQuery = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
+                new JoinQueryInfos(
+                    JoinType.Inner, a.Zuid.ToString() == b.Zuid))
             .Where((a, b) => a.DepotSectionCode == query.sectionCode)
             .Select((a, b) => new { b.DepotCode })
             .First();
-        
+
         if (depotQuery == null)
-        {
             throw new Exception($"002[搴撲綅缂栫爜 {query.sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
-        }
 
         var cDepotCode = depotQuery.DepotCode;
-        
+
         // 鏌ヨ璋冩嫈鍏ュ簱淇℃伅
-        var itemMoveQuery = Db.Queryable<MesInvItemMoves, MesInvItemMovesCDetails>((a, b) => new JoinQueryInfos(
-                JoinType.Inner, a.Id == b.ItemMoveId))
-            .Where((a, b) => b.ItemBarcode == query.barcode && a.BillTypeId == pBillTypeId && a.TransactionNo == pTransctionNo &&
+        var itemMoveQuery = Db
+            .Queryable<MesInvItemMoves, MesInvItemMovesCDetails>((a, b) =>
+                new JoinQueryInfos(
+                    JoinType.Inner, a.Id == b.ItemMoveId))
+            .Where((a, b) => b.ItemBarcode == query.barcode &&
+                             a.BillTypeId == pBillTypeId &&
+                             a.TransactionNo == pTransctionNo &&
                              a.Status == 1 && SqlFunc.IsNull(b.MoveOk, 0) != 1)
             .Select((a, b) => new { a.Id, a.BillNo, a.InvDepotsCode })
             .First();
-        
-        return 0;
+
+        if (itemMoveQuery == null) throw new Exception("鏉$爜鏈仛璋冩嫈鍑哄簱鎵爜锛岃鏍稿锛�");
+
+        var cBillNo = itemMoveQuery.BillNo;
+        var iDepotCode = itemMoveQuery.InvDepotsCode;
+
+        // 楠岃瘉搴撳尯涓庝粨搴�
+        var depotValidationQuery = Db.Queryable<MesDepotSections, MesDepots>(
+                (a, b) => new JoinQueryInfos(
+                    JoinType.Inner, a.Zuid.ToString() == b.Zuid))
+            .Where((a, b) => a.DepotSectionCode == query.sectionCode &&
+                             b.DepotCode == iDepotCode)
+            .Select((a, b) => new { b.DepotCode })
+            .First();
+
+        if (depotValidationQuery == null)
+            throw new Exception($"002[搴撲綅缂栫爜 {query.sectionCode} 涓嶅瓨鍦紝璇风‘璁わ紒");
+
+        if (iDepotCode != depotValidationQuery.DepotCode)
+            throw new Exception("瀹為檯浠撳簱涓庣敵璇疯皟鍏ヤ粨搴撲笉绗︼紝璇锋牳瀵癸紒");
+
+        var barcodeCount = Db.Queryable<MesInvItemMovesCDetails>()
+            .Where(b =>
+                b.ItemBarcode == query.barcode &&
+                b.ItemMoveId == itemMoveQuery.Id && b.MoveOk == 1)
+            .Count();
+
+        if (barcodeCount > 0) throw new Exception("鏉$爜璋冩嫈宸插畬鎴愶紝璇锋牳瀵癸紒");
+
+        var barcodeInfo = Db.Queryable<MesInvItemBarcodes>()
+            .Where(t => t.ItemBarcode == query.barcode)
+            .First();
+
+        if (barcodeInfo == null) throw new Exception("鏉$爜涓嶅瓨鍦紝璇锋牳瀵癸紒");
+
+        var isAudit = UseTransaction(db =>
+        {
+            // 鏇存柊涓氬姟銆佸簱瀛樺拰鏉$爜鏁版嵁
+            db.Updateable<MesInvBusiness2>()
+                .SetColumns(b => new MesInvBusiness2
+                {
+                    ToInvDepotsCode = cDepotCode,
+                    ToInvDepotSectionsCode = query.sectionCode
+                })
+                .Where(b =>
+                    b.BillNo == cBillNo && b.BillTypeId == pBillTypeId &&
+                    b.TransactionCode == pTransctionNo.ToString() &&
+                    b.ItemBarcode == query.barcode)
+                .ExecuteCommand();
+
+            db.Updateable<MesInvItemStocks>()
+                .SetColumns(b => new MesInvItemStocks
+                {
+                    DepotsCode = cDepotCode,
+                    DepotSectionsCode = query.sectionCode
+                })
+                .Where(b => b.ItemBarcode == query.barcode)
+                .ExecuteCommand();
+
+            db.Updateable<MesInvItemMovesCDetails>()
+                .SetColumns(b => new MesInvItemMovesCDetails
+                {
+                    MoveOk = 1,
+                    InvDepotsCode = cDepotCode,
+                    InvDepotSectionsCode = query.sectionCode
+                })
+                .Where(b =>
+                    b.ItemBarcode == query.barcode &&
+                    b.ItemMoveId == itemMoveQuery.Id)
+                .ExecuteCommand();
+
+            // 妫�鏌ユ槸鍚︽墍鏈夋潯鐮佸凡鎵爜绉诲簱
+            var totalQuantity = db.Queryable<MesInvItemOutItems>()
+                .Where(a => a.ItemOutId == itemMoveQuery.Id)
+                .Sum(a => SqlFunc.IsNull(a.Quantity, 0));
+
+            var scannedQuantity = db.Queryable<MesInvItemMovesCDetails>()
+                .Where(a => a.ItemMoveId == itemMoveQuery.Id && a.MoveOk == 1)
+                .Sum(a => SqlFunc.IsNull(a.Quantity, 0));
+
+            if (totalQuantity == scannedQuantity) return 1;
+
+            return 0;
+        });
+
+        var dto = new MovesDto();
+        dto.InAudit = isAudit == 1;
+        dto.BarcodesInfo = barcodeInfo;
+        return dto;
     }
+
 
     public List<MesInvItemMoves> GetBillNo(WarehouseQuery query)
     {
@@ -71,7 +160,7 @@
 
     public MovesDto GetItems(WarehouseQuery query)
     {
-        MovesDto dto = new MovesDto();
+        var dto = new MovesDto();
 
         dto.BarcodeList = GetItemMovesCDetails(query);
         dto.OutItems = GetItemOutItems(query);
@@ -179,8 +268,6 @@
             throw new Exception(
                 "宸叉壂鏉$爜鏁伴噺鎴栨湰娆℃壂鐮佹暟閲忥細" + sumqty + " 澶т簬鐢宠鏁伴噺锛�" + quantity + "锛岃鏍稿锛�");
 
-        List<InventoryItem> scanOutShowDb = null;
-
         UseTransaction(db =>
         {
             SaveMesInvItemMovesCDetails(db, query, mesInvItemMoves,
@@ -205,7 +292,7 @@
                     .Where(s => s.Id == mesInvItemStocks.Id)
                     .ExecuteCommand();
 
-            scanOutShowDb = ScanOutShowDb(query);
+            var scanOutShowDb = ScanOutShowDb(query);
             if (CollectionUtil.IsNullOrEmpty(scanOutShowDb))
                 db.Updateable<MesInvItemMoves>()
                     .SetColumns(s => s.Status == 1)
@@ -217,7 +304,7 @@
         });
 
         var itemDto = new OutItemDto();
-        itemDto.SumItem = scanOutShowDb;
+        //itemDto.SumItem = scanOutShowDb;
 
         if (TransctionNo == 201) itemDto.Quantity = mesInvItemStocks.Quantity;
 
@@ -324,4 +411,92 @@
 
         return results;
     }
+
+    public bool Audit(WarehouseQuery query)
+    {
+        return Db.Updateable<MesInvItemMoves>()
+            .SetColumns(a => new MesInvItemMoves { Ts = 1 })
+            .Where(a => a.Id == query.id)
+            .ExecuteCommand() > 0;
+    }
+
+    public MessageCenter SaveMessageCenter(WarehouseQuery query)
+    {
+        var message = MesToErpParam(query);
+
+        var executeReturnIdentity =
+            Db.Insertable(message).ExecuteReturnIdentity();
+        if (executeReturnIdentity > 0)
+        {
+            message.Id = executeReturnIdentity;
+            message.Pid = executeReturnIdentity;
+            return message;
+        }
+
+        throw new Exception("鑾峰彇鏁版嵁澶辫触");
+    }
+
+    public MessageCenter MesToErpParam(WarehouseQuery query)
+    {
+        var erpParameters = "";
+        var title = "";
+        var tableName = "MES_INV_ITEM_MOVES_" + query.Type;
+        if ("A".Equals(query.Type))
+        {
+            erpParameters = GetErpParameters(query.billNo);
+            title = "璋冩嫧鍏ュ簱鍗�" + query.billNo + "瀹℃牳";
+        }
+        else if ("B".Equals(query.Type))
+        {
+            erpParameters = GetDeApprovePam(query.id);
+            title = "璋冩嫧鍏ュ簱鍗�" + query.billNo + "鍙嶅鏍�";
+        }
+
+        var ErpUrl = AppsettingsUtility.Settings.ProductionErpUrl;
+        var message = new MessageCenter
+        {
+            TableName = tableName,
+            Url = ErpUrl,
+            Status = 1,
+            CreateBy = query.userName,
+            Route = query.billNo,
+            Title = title,
+            PageName = "Allocation/Add?id=" + query.id +
+                       "&billNo=" + query.billNo,
+            CreateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
+            Method = "POST",
+            Seq = 1,
+            Data = erpParameters,
+            IsMessage = 0,
+            ContentType = "application/x-www-form-urlencoded"
+        };
+        return message;
+    }
+
+    private string GetErpParameters(string? billNo)
+    {
+        // var invItemIns = Db.Queryable<MesInvItemOuts>()
+        //     .Single(x => x.ItemOutNo == billNo);
+        //
+        // //璋冪敤function鍑芥暟
+        // var sql =
+        //     $"SELECT F_GENERATE_DATA_INSERTED('{billNo}') FROM DUAL;";
+        // var jsonString = Db.Ado.SqlQuerySingle<string>(sql);
+        //
+        // var encodedUrl = "taskname=CGTL&mesid=" + invItemIns.Id +
+        //                  "&optype=create&datajson=" + jsonString;
+        //
+        // return encodedUrl;
+        return null;
+    }
+
+    private string GetDeApprovePam(decimal? id)
+    {
+        // var sid = (int)id;
+        // var encodedUrl = "taskname=CGTL&mesid=" + sid +
+        //                  "&optype=delete&datajson={}";
+        //
+        // return encodedUrl;
+        return null;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3