From 43c87277110b8e92b89964dd547668c52ea46e95 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期四, 15 八月 2024 17:43:41 +0800
Subject: [PATCH] 调拨入库

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

diff --git a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
index 912ebd5..5e1cb86 100644
--- a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
+++ b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
@@ -12,39 +12,148 @@
 
     //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 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 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;
+        });
+
+        MovesDto dto = new MovesDto();
+        dto.InAudit = isAudit == 1;
+        dto.BarcodesInfo = barcodeInfo;
+        return dto;
     }
+
 
     public List<MesInvItemMoves> GetBillNo(WarehouseQuery query)
     {
@@ -324,4 +433,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