From 30846c0d13ee4136d68ba509b05281378db951c6 Mon Sep 17 00:00:00 2001
From: 啊鑫 <t2856754968@163.com>
Date: 星期四, 19 九月 2024 14:14:27 +0800
Subject: [PATCH] 生成委外订单接口

---
 MES.Service/service/Warehouse/MesInvItemBarcodesManager.cs |  139 +++++++++++-----------------------------------
 1 files changed, 33 insertions(+), 106 deletions(-)

diff --git a/MES.Service/service/Warehouse/MesInvItemBarcodesManager.cs b/MES.Service/service/Warehouse/MesInvItemBarcodesManager.cs
index d1a6bea..9f59fba 100644
--- a/MES.Service/service/Warehouse/MesInvItemBarcodesManager.cs
+++ b/MES.Service/service/Warehouse/MesInvItemBarcodesManager.cs
@@ -20,62 +20,40 @@
         try
         {
             // 1. 妫�鏌ユ潯鐮佹槸鍚︿负绌�
-            if (string.IsNullOrEmpty(cBarcode))
-            {
-                throw new Exception("璇疯緭鍏ユ潯鐮侊紒");
-            }
+            if (string.IsNullOrEmpty(cBarcode)) throw new Exception("璇疯緭鍏ユ潯鐮侊紒");
 
             // 2. 妫�鏌ユ潯鐮佹槸鍚﹀瓨鍦ㄤ簬 MesInvItemBarcodes 琛ㄤ腑
-            int tempNum = Db.Queryable<MesInvItemBarcodes>()
+            var tempNum = Db.Queryable<MesInvItemBarcodes>()
                 .Where(it => it.ItemBarcode == cBarcode)
                 .Count();
-            if (tempNum == 0)
-            {
-                throw new Exception("鏉$爜涓嶅瓨鍦紒");
-            }
+            if (tempNum == 0) throw new Exception("鏉$爜涓嶅瓨鍦紒");
 
             // 3. 妫�鏌ユ潯鐮佹槸鍚﹀瓨鍦ㄤ簬 MesInvItemStocks 琛ㄤ腑
             tempNum = Db.Queryable<MesInvItemStocks>()
                 .Where(it => it.ItemBarcode == cBarcode)
                 .Count();
-            if (tempNum == 0)
-            {
-                throw new Exception("搴撳瓨涓棤姝ゆ潯鐮侊紒");
-            }
+            if (tempNum == 0) throw new Exception("搴撳瓨涓棤姝ゆ潯鐮侊紒");
 
             // 4. 鑾峰彇 MesInvItemBarcodes 鐨勬暟鎹�
             var mesInvItemBarcodes = Db.Queryable<MesInvItemBarcodes>()
                 .Where(it => it.ItemBarcode == cBarcode)
                 .First();
-            if (mesInvItemBarcodes == null)
-            {
-                throw new Exception("鏉$爜涓嶅瓨鍦紒");
-            }
+            if (mesInvItemBarcodes == null) throw new Exception("鏉$爜涓嶅瓨鍦紒");
 
             // 5. 妫�鏌ユ潯鐮佹暟閲忔槸鍚︿负 0
             if (mesInvItemBarcodes.Quantity == 0)
-            {
                 throw new Exception("姝ゆ潯鐮佹暟閲忎负0锛�");
-            }
 
             // 6. 妫�鏌ユ潯鐮佺姸鎬�
             if (mesInvItemBarcodes.Barcodestatus == 1 ||
                 mesInvItemBarcodes.Hbdytm == 1)
-            {
                 throw new Exception("鏃犳晥鏉$爜锛�");
-            }
 
             // 7. 妫�鏌ユ潯鐮佹槸鍚﹁鍐荤粨
-            if (mesInvItemBarcodes.Visable == 1)
-            {
-                throw new Exception("鏉$爜鍐荤粨锛�");
-            }
+            if (mesInvItemBarcodes.Visable == 1) throw new Exception("鏉$爜鍐荤粨锛�");
 
             // 8. 妫�鏌ユ潯鐮佹槸鍚︿綔搴�
-            if (mesInvItemBarcodes.Location == 2)
-            {
-                throw new Exception("鏉$爜浣滃簾锛�");
-            }
+            if (mesInvItemBarcodes.Location == 2) throw new Exception("鏉$爜浣滃簾锛�");
 
             // 9. 妫�鏌ユ姇鏂欏崟鏄惁闇�瑕佹鐗╂枡
             tempNum = Db.Queryable<Womdab>()
@@ -83,12 +61,9 @@
                     it.Dab001 == cDaa001 && it.Dab003 ==
                     mesInvItemBarcodes.ItemId.ToString())
                 .Count();
-            if (tempNum == 0)
-            {
-                throw new Exception("鎶曟枡鍗曚笉闇�瑕佹鐗╂枡锛�");
-            }
+            if (tempNum == 0) throw new Exception("鎶曟枡鍗曚笉闇�瑕佹鐗╂枡锛�");
 
-            string sql =
+            var sql =
                 "SELECT COUNT(1) FROM WOMDAB WHERE DAB001='" + cDaa001 +
                 "' AND  DAB003='" + mesInvItemBarcodes.ItemId +
                 "' AND DAB017=(SELECT DEPOTS_CODE    FROM MES_INV_ITEM_STOCKS WHERE ITEM_BARCODE='" +
@@ -96,10 +71,7 @@
 
             // 10. 妫�鏌ュ彂鏂欎粨搴撴槸鍚︽纭�
             tempNum = Db.Ado.SqlQuerySingle<int>(sql);
-            if (tempNum == 0)
-            {
-                throw new Exception("鍙戞枡浠撳簱鏈夎锛�");
-            }
+            if (tempNum == 0) throw new Exception("鍙戞枡浠撳簱鏈夎锛�");
 
             // 11. 鎴愬姛锛岃繑鍥炵粨鏋�
             return true;
@@ -113,18 +85,12 @@
 
     public decimal? GetBarCodesQuan(WarehouseQuery query)
     {
-        if (!PdaProdPickItemCkBar(query.barcode, query.daa001))
-        {
-            return null;
-        }
+        if (!PdaProdPickItemCkBar(query.barcode, query.daa001)) return null;
 
         var invItemBarcodes = Db.Queryable<MesInvItemBarcodes>()
             .Where(s => s.ItemBarcode == query.barcode).First();
 
-        if (invItemBarcodes == null)
-        {
-            throw new Exception("鏉$爜涓嶅瓨鍦紒");
-        }
+        if (invItemBarcodes == null) throw new Exception("鏉$爜涓嶅瓨鍦紒");
 
         return invItemBarcodes.Quantity;
     }
@@ -144,57 +110,37 @@
         };
 
         // 妫�鏌ュ彂鏂欐暟閲忔槸鍚﹀悎娉�
-        if (param.CNum <= 0)
-        {
-            throw new Exception("鍙戞枡鏁伴噺涓嶈兘灏忎簬绛変簬0锛�");
-        }
+        if (param.CNum <= 0) throw new Exception("鍙戞枡鏁伴噺涓嶈兘灏忎簬绛変簬0锛�");
 
         // 妫�鏌ユ潯鐮佹槸鍚﹀瓨鍦�
         param.CInvItemBarcodes = Db.Queryable<MesInvItemBarcodes>()
             .Where(it => it.ItemBarcode == param.CBarcode)
             .First();
-        if (param.CInvItemBarcodes == null)
-        {
-            throw new Exception("鏉$爜涓嶅瓨鍦紒");
-        }
+        if (param.CInvItemBarcodes == null) throw new Exception("鏉$爜涓嶅瓨鍦紒");
 
         // 妫�鏌ユ潯鐮佹槸鍚﹀凡鍏ュ簱
         param.CInvItemStocks = Db.Queryable<MesInvItemStocks>()
             .Where(it => it.ItemBarcode == param.CBarcode)
             .First();
-        if (param.CInvItemStocks == null)
-        {
-            throw new Exception("鏉$爜鏈叆搴擄紒");
-        }
+        if (param.CInvItemStocks == null) throw new Exception("鏉$爜鏈叆搴擄紒");
 
         // 妫�鏌ュ伐鍗曞彿鏄惁瀛樺湪
         param.CWomdaa = Db.Queryable<Womdaa>()
             .Where(it => it.Daa001 == param.CDaa001)
             .First();
-        if (param.CWomdaa == null)
-        {
-            throw new Exception("涓嶅瓨鍦ㄦ宸ュ崟锛�");
-        }
+        if (param.CWomdaa == null) throw new Exception("涓嶅瓨鍦ㄦ宸ュ崟锛�");
 
         // 妫�鏌ュ彂鏂欐暟閲忔槸鍚﹁秴鍑烘潯鐮佹暟閲�
         if (param.CNum > param.CInvItemBarcodes.Quantity)
-        {
             throw new Exception("鍙戞枡鏁伴噺涓嶈兘澶т簬鏉$爜鏁伴噺锛�");
-        }
 
         // 妫�鏌ユ潯鐮佸悎娉曟��
-        if (!PdaProdPickItemCkBar(param.CBarcode, param.CDaa001))
-        {
-            return null;
-        }
+        if (!PdaProdPickItemCkBar(param.CBarcode, param.CDaa001)) return null;
 
         // 璁$畻鍓╀綑鍙彂鏁伴噺
-        decimal? tempNum = CalculateRemainingQuantity(param.CDaa001,
+        var tempNum = CalculateRemainingQuantity(param.CDaa001,
             param.CInvItemBarcodes.ItemId);
-        if (param.CNum > tempNum)
-        {
-            throw new Exception("鍙戞枡鏁伴噺涓嶈兘澶т簬瀵瑰簲鐗╂枡鐨勬湭鍙戞枡鏁伴噺锛�");
-        }
+        if (param.CNum > tempNum) throw new Exception("鍙戞枡鏁伴噺涓嶈兘澶т簬瀵瑰簲鐗╂枡鐨勬湭鍙戞枡鏁伴噺锛�");
 
         // 宸ュ崟閮ㄩ棬鍚嶇О
         param.CDepart = Db.Queryable<SysDepartment>()
@@ -319,14 +265,12 @@
     {
         string cSupName = null;
         if (!string.IsNullOrEmpty(param.CInvItemBarcodes.SuppNo))
-        {
             cSupName = db.Queryable<MesSupplier>()
                 .Where(it => it.SuppNo == param.CInvItemBarcodes.SuppNo)
                 .Select(it => it.SuppName)
                 .First();
-        }
 
-        int cId =
+        var cId =
             db.Ado.GetInt(
                 "SELECT F_GETSEQNEXTVALUE('MES_RF_PRNBARCODE') FROM dual");
 
@@ -381,16 +325,16 @@
             .Where(it => it.TaskNo == param.CDaa001 && it.Status == 0)
             .Count();
 
-        int cOutId = 0;
+        var cOutId = 0;
         string cOutBill;
 
         if (tempNum == 0)
         {
-            string sql =
+            var sql =
                 "SELECT COUNT(1) FROM MES_INV_ITEM_OUTS WHERE TRUNC(CREATE_DATE)=TRUNC(SYSDATE);";
-            int todayCount = db.Ado.SqlQuerySingle<int>(sql);
+            var todayCount = db.Ado.SqlQuerySingle<int>(sql);
 
-            cOutBill = $"P{DateTime.Now:yyyyMMdd}{(todayCount + 1):D4}";
+            cOutBill = $"P{DateTime.Now:yyyyMMdd}{todayCount + 1:D4}";
 
             // 鎻掑叆鏂扮殑鍑哄簱鍗�
             db.Insertable(new MesInvItemOuts
@@ -441,9 +385,9 @@
                 it.ItemOutId == cOutId)
             .Count();
 
-        decimal? cNumTemp = param.CNum;
+        var cNumTemp = param.CNum;
 
-        string sql =
+        var sql =
             "SELECT B.Id, NVL(A.YF, 0) yfl, B.DAB006 - NVL(A.YF, 0) Qty FROM WOMDAB B LEFT JOIN (SELECT SUM(QUANTITY) YF, ITEM_DABID FROM MES_INV_ITEM_OUT_ITEMS                GROUP BY ITEM_DABID) A ON A.ITEM_DABID = B.ID WHERE DAB003 = '" +
             param.CInvItemBarcodes.ItemId + "' AND DAB001 = '" + param.CDaa001 +
             "' ORDER BY TO_NUMBER(DAB002)";
@@ -457,7 +401,6 @@
             if (cNumTemp <= item.Qty)
             {
                 if (tempNum == 0)
-                {
                     // 鎻掑叆鏂扮殑鍙戞枡璁板綍
                     db.Insertable(new MesInvItemOutItems
                     {
@@ -480,9 +423,7 @@
                         DepotSectionCode =
                             param.CInvItemStocks.DepotSectionsCode
                     }).ExecuteCommand();
-                }
                 else
-                {
                     // 鏇存柊鐜版湁鍙戞枡璁板綍鐨勬暟閲�
                     db.Updateable<MesInvItemOutItems>()
                         .SetColumns(it => new MesInvItemOutItems
@@ -491,7 +432,6 @@
                             it.ItemOutId == cOutId &&
                             it.ItemDabid == itemDabid)
                         .ExecuteCommand();
-                }
 
                 // 鏇存柊 WOMDAB 琛ㄧ殑鍙戞枡鏁伴噺
                 db.Updateable<Womdab>()
@@ -538,7 +478,7 @@
     private string GenerateNewBarcode(string oldBarcode)
     {
         // 鐢熸垚鏂扮殑鏉$爜閫昏緫
-        int count = Db.Queryable<MesInvItemBarcodes>()
+        var count = Db.Queryable<MesInvItemBarcodes>()
             .Where(b => b.OldItemBarcode == oldBarcode).Count();
         return $"{oldBarcode}-{count + 1}";
     }
@@ -565,13 +505,10 @@
     {
         try
         {
-            if (pId == null)
-            {
-                return null;
-            }
+            if (pId == null) return null;
 
             // 鏌ヨ鐗╂枡鍚嶇О
-            string itemName = Db.Queryable<MesItems>()
+            var itemName = Db.Queryable<MesItems>()
                 .Where(it => it.Id == pId)
                 .Select(it => it.ItemName)
                 .First();
@@ -588,28 +525,22 @@
     {
         try
         {
-            if (string.IsNullOrEmpty(pId))
-            {
-                return null;
-            }
+            if (string.IsNullOrEmpty(pId)) return null;
 
             // 鏌ヨ鍗曚綅鍚嶇О鏄惁瀛樺湪
-            int tempNum = Db.Queryable<MesUnit>()
+            var tempNum = Db.Queryable<MesUnit>()
                 .Where(it => it.Id.ToString() == pId)
                 .Count();
 
             string unitName;
 
             if (tempNum != 0)
-            {
                 // 濡傛灉鍦� MES_UNIT 琛ㄤ腑鎵惧埌鍗曚綅鍚嶇О
                 unitName = Db.Queryable<MesUnit>()
                     .Where(it => it.Id.ToString() == pId)
                     .Select(it => it.Fname)
                     .First();
-            }
             else
-            {
                 // 濡傛灉鍦� MES_UNIT 琛ㄤ腑鎵句笉鍒帮紝鍦� MES_ITEMS 琛ㄤ腑鏌ユ壘鐩稿叧鑱旂殑鍗曚綅鍚嶇О
                 unitName = Db.Queryable<MesItems, MesUnit>((i, u) =>
                         new JoinQueryInfos(
@@ -617,7 +548,6 @@
                     .Where((i, u) => i.Id.ToString() == pId)
                     .Select((i, u) => u.Fname)
                     .First();
-            }
 
             return unitName;
         }
@@ -631,13 +561,10 @@
     {
         try
         {
-            if (pId == null)
-            {
-                return null;
-            }
+            if (pId == null) return null;
 
             // 鏌ヨ鐗╂枡瑙勬牸
-            string itemModel = Db.Queryable<MesItems>()
+            var itemModel = Db.Queryable<MesItems>()
                 .Where(it => it.Id == pId)
                 .Select(it => it.ItemModel)
                 .First();

--
Gitblit v1.9.3