From 54f23d618095bf49edc77a45ad489a555701b688 Mon Sep 17 00:00:00 2001
From: 南骏 池 <chiffly@163.com>
Date: 星期二, 27 五月 2025 16:54:58 +0800
Subject: [PATCH] 1.起初条码pda生成自动入库,无线打印条码。

---
 service/Warehouse/InventoryManager.cs        |   85 ++++++++++++++++++++++++++++++++++++++++++
 Controllers/Warehouse/InventoryController.cs |   27 +++++++++++++
 2 files changed, 112 insertions(+), 0 deletions(-)

diff --git a/Controllers/Warehouse/InventoryController.cs b/Controllers/Warehouse/InventoryController.cs
index c732b8a..ae03c9d 100644
--- a/Controllers/Warehouse/InventoryController.cs
+++ b/Controllers/Warehouse/InventoryController.cs
@@ -1,6 +1,7 @@
 锘縰sing System.Dynamic;
 using Microsoft.AspNetCore.Mvc;
 using NewPdaSqlServer.Dto.service;
+using NewPdaSqlServer.service.@base;
 using NewPdaSqlServer.service.Warehouse;
 using NewPdaSqlServer.util;
 
@@ -11,6 +12,8 @@
 public class InventoryController : ControllerBase
 {
     private readonly InventoryManager m = new();
+
+    private readonly MesPrintMangeer _mCf = new();
 
     /// <summary>
     ///     鎵弿搴撲綅鏉$爜鐨勬帶鍒跺櫒鏂规硶
@@ -128,4 +131,28 @@
             return ResponseResult.ResponseError(ex);
         }
     }
+    
+    [HttpPost("printBeginBar")]
+    public ResponseResult PrintBeginBar([FromBody] dynamic query)
+    {
+        try
+        {
+            dynamic resultInfos = new ExpandoObject();
+            resultInfos.tbBillList = new ExpandoObject();
+            resultInfos.tbBillList.printInfo = _mCf.getPrintInfo(query);
+            //var scanResult = m.BarCF(unity);
+            resultInfos.tbBillList.cfBarInfo = m.ExecuteBeginBar(query); 
+            //resultInfos.tbBillList = m.ExecuteBeginBar(query);
+            return new ResponseResult
+            {
+                status = 0,
+                message = "OK",
+                data = resultInfos
+            };
+        }
+        catch (Exception ex)
+        {
+            return ResponseResult.ResponseError(ex);
+        }
+    }
 }
\ No newline at end of file
diff --git a/service/Warehouse/InventoryManager.cs b/service/Warehouse/InventoryManager.cs
index 4a876e6..7fab709 100644
--- a/service/Warehouse/InventoryManager.cs
+++ b/service/Warehouse/InventoryManager.cs
@@ -5,6 +5,10 @@
 using NewPdaSqlServer.util;
 using SqlSugar;
 using System.Text;
+using System.Data;
+using System.Data.SqlClient;
+using System.Dynamic;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
 
 namespace NewPdaSqlServer.service.Warehouse;
 
@@ -326,4 +330,85 @@
 
         return XcslItem;
     }
+
+    public List<dynamic> ExecuteBeginBar(dynamic query)
+    {
+        if (query == null)
+            throw new ArgumentNullException(nameof(query), "鍙傛暟瀵硅薄涓嶈兘涓簄ull");
+
+        // 澧炲己鍙傛暟鏍¢獙
+        if (string.IsNullOrEmpty(query.userName?.ToString()))
+            throw new ArgumentException("鐢ㄦ埛璐﹀彿涓嶈兘涓虹┖", nameof(query.userName));
+
+        if (string.IsNullOrEmpty(query.itemid?.ToString()))
+            throw new ArgumentException("鐗╂枡ID涓嶈兘涓虹┖", nameof(query.itemid));
+
+        var resultList = new List<dynamic>();
+
+        using (var conn = new SqlConnection(DbHelperSQL.strConn))
+        using (var cmd = new SqlCommand("rpt_BeginBar", conn))
+        {
+            cmd.CommandType = CommandType.StoredProcedure;
+            cmd.Parameters.AddRange(new[]
+            {
+                new SqlParameter("@inUser", SqlDbType.NVarChar, 50) { Value = query.userName },
+                new SqlParameter("@inItemId", SqlDbType.NVarChar, 50) { Value = query.itemid },
+                new SqlParameter("@isDesign", SqlDbType.Int) { Value = 0 },
+                new SqlParameter("@in4", SqlDbType.NVarChar, 20) { Value = query.in4 ?? DBNull.Value },
+                new SqlParameter("@in5", SqlDbType.NVarChar, 20) { Value = query.num ?? DBNull.Value }
+            });
+
+            try
+            {
+                conn.Open();
+                using (var reader = cmd.ExecuteReader())
+                {
+                    while (reader.Read())
+                    {
+                        var barcode = reader.GetString(0);
+                        
+                        // 鏋勫缓绗﹀悎鏂规硶绛惧悕鐨勫弬鏁板璞�
+                        var scanQuery = new WarehouseQuery 
+                        {
+                            barcode = barcode,
+                            DepotCode = query.sectionCode, // 浠庡師濮媞uery鑾峰彇搴撲綅缂栫爜
+                            userName = query.userName // 浠庡師濮媞uery鑾峰彇鐢ㄦ埛璐﹀彿
+                        };
+                        
+                        try
+                        {
+                            // 璋冪敤姝e紡绛惧悕鏂规硶
+                            ScanBarcode(scanQuery);
+                            var printData = GetPrintBar(barcode); 
+                            resultList.Add(printData);
+                        }
+                        catch (Exception ex)
+                        {
+                            throw new Exception($"鏈熷垵鏉$爜鎵撳嵃鍏ュ簱瀛樺湪寮傚父{ex.Message}锛岃閲嶆柊鎵撳嵃锛�");
+                        }
+                    }
+                }
+                return resultList;
+            }
+            catch (Exception ex)
+            {
+                throw new Exception($"鐢熸垚鏈熷垵鏉$爜澶辫触锛歿ex.Message}");
+            }
+        }
+    }
+
+    public dynamic GetPrintBar(string barcode)
+    {
+        var sqlParams = new List<SugarParameter> { new("@barcode", barcode) };
+
+        var sql1 = @"    SELECT TOP 1 C.ITEM_NO,C.item_name,C.item_model,B.OLDQTY as QUANTITY,B.CREATE_DATE, '鏈熷垵鏉$爜' AS BarType,A.ITEM_BARCODE,GETDATE() as print_date
+            FROM MES_INV_ITEM_STOCKS A
+            LEFT JOIN MES_INV_ITEM_BARCODES B ON A.ITEM_BARCODE = B.ITEM_BARCODE
+            LEFT JOIN MES_ITEMS C ON C.item_id = B.ITEM_ID
+            WHERE B.ITEM_BARCODE = @barcode";
+
+        var XcslItem = Db.Ado.SqlQuery<dynamic>(sql1, sqlParams).First();
+
+        return XcslItem;
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3