From 87f516dbb2e9a10d0e6bb1cb15587c82c709e130 Mon Sep 17 00:00:00 2001
From: lg <999544862qq.com>
Date: 星期五, 16 八月 2024 08:34:33 +0800
Subject: [PATCH] 增加注释

---
 MES.Service/service/Warehouse/MesInvItemMovesManager.cs |  233 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 232 insertions(+), 1 deletions(-)

diff --git a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
index 0da91c7..5e1cb86 100644
--- a/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
+++ b/MES.Service/service/Warehouse/MesInvItemMovesManager.cs
@@ -12,6 +12,149 @@
 
     //杩欓噷闈㈠啓鐨勪唬鐮佷笉浼氱粰瑕嗙洊,濡傛灉瑕侀噸鏂扮敓鎴愯鍒犻櫎 MesInvItemMovesManager.cs
 
+    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))
+            .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 &&
+                             a.Status == 1 && SqlFunc.IsNull(b.MoveOk, 0) != 1)
+            .Select((a, b) => new { a.Id, a.BillNo, a.InvDepotsCode })
+            .First();
+
+        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)
     {
         query.Factory = "1000";
@@ -48,7 +191,7 @@
     private List<MesInvItemOutItems> GetItemOutItems(WarehouseQuery query)
     {
         var sql = string.Format(
-            "SELECT C.ITEM_NO,        C.QUANTITY,        C.REMARK,        C.REMARK,        S.ITEM_NAME,        S.ITEM_MODEL,        U.FNAME ITEM_UNIT,        D.QUANTITY_OK FROM MES_INV_ITEM_OUT_ITEMS C JOIN MES_ITEMS S ON C.ITEM_ID = S.ID          LEFT JOIN MES_UNIT U ON U.ID = S.ITEM_UNIT LEFT JOIN (SELECT ITEM_MOVE_ID, ITEM_NO, SUM(QUANTITY) QUANTITY_OK                     FROM MES_INV_ITEM_MOVES_C_DETAILS                     GROUP BY ITEM_MOVE_ID, ITEM_NO) D ON D.ITEM_MOVE_ID = C.ITEM_OUT_ID AND D.ITEM_NO = C.ITEM_NO where C.ITEM_OUT_ID= {0}",
+            "SELECT C.ITEM_NO, C.QUANTITY, C.REMARK,         C.REMARK,         S.ITEM_NAME, S.ITEM_MODEL, U.FNAME ITEM_UNIT, D.QUANTITY_OK,         NVL(ST.QUANTITY, 0)      WLKC  FROM MES_INV_ITEM_OUT_ITEMS C           JOIN MES_ITEMS S ON C.ITEM_ID = S.ID           LEFT JOIN MES_UNIT U                     ON U.ID = S.ITEM_UNIT           LEFT JOIN MES_DEPOTS P ON P.DEPOT_CODE = C.DEPOT_CODE           LEFT JOIN MES_DEPOT_SECTIONS E ON E.DEPOT_SECTION_CODE = C.DEPOT_SECTION_CODE           LEFT JOIN (SELECT ITEM_MOVE_ID, ITEM_NO, SUM(QUANTITY) QUANTITY_OK                      FROM MES_INV_ITEM_MOVES_C_DETAILS                   GROUP BY ITEM_MOVE_ID, ITEM_NO) D ON D.ITEM_MOVE_ID = C.ITEM_OUT_ID AND D.ITEM_NO = C.ITEM_NO         LEFT JOIN MES_INV_ITEM_MOVES A         ON A.ID = C.ITEM_OUT_ID       left join (SELECT ITEM_ID, SUM(QUANTITY) QUANTITY, DEPOTS_CODE                 FROM MES_INV_ITEM_STOCKS GROUP BY ITEM_ID, DEPOTS_CODE) ST ON C.ITEM_ID = ST.ITEM_ID AND ST.DEPOTS_CODE = A.FROM_DEPOTS_CODE where C.ITEM_OUT_ID = {0}",
             query.id);
 
         return Db.Ado.SqlQuery<MesInvItemOutItems>(sql);
@@ -290,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