From 0aa54059b26e6641196e9953490dd18616e916e3 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期三, 10 九月 2025 17:26:47 +0800 Subject: [PATCH] 精简修正代码 --- service/base/WmsBaseMangeer.cs | 256 +++++++++++++++++++++++++-------------------------- 1 files changed, 125 insertions(+), 131 deletions(-) diff --git a/service/base/WmsBaseMangeer.cs b/service/base/WmsBaseMangeer.cs index e3eadf8..ae7fa43 100644 --- a/service/base/WmsBaseMangeer.cs +++ b/service/base/WmsBaseMangeer.cs @@ -1,150 +1,144 @@ -锘縩amespace NewPdaSqlServer.service.@base +锘縰sing System.Data; +using System.Data.SqlClient; +using NewPdaSqlServer.DB; +using NewPdaSqlServer.Dto.service; +using NewPdaSqlServer.entity; +using NewPdaSqlServer.util; +using SqlSugar; + +namespace NewPdaSqlServer.service.@base; + +public class WmsBaseMangeer : Repository<dynamic> { - using NewPdaSqlServer.Dto.service; - using NewPdaSqlServer.entity; - using SqlSugar; - using System; - using static Microsoft.EntityFrameworkCore.DbLoggerCategory; - using System.Data; - using NewPdaSqlServer.DB; - using System.Data; - using System.Data.SqlClient; - using Microsoft.EntityFrameworkCore.Metadata.Internal; - - - public class WmsBaseMangeer : Repository<dynamic> + /// <summary> + /// 閫氱敤鍏ュ簱鏍¢獙 + /// </summary> + /// <param name="db">SqlSugar 鏁版嵁搴撲笂涓嬫枃</param> + /// <param name="edtUserNo">鎿嶄綔浜哄伐鍙�</param> + /// <param name="barcode">鐗╂枡鏉$爜</param> + /// <param name="sectionCode">搴撲綅缂栫爜</param> + /// <param name="stockId">浠撳簱ID</param> + /// <param name="stockOrgId">搴撳瓨缁勭粐ID</param> + /// <param name="billNo">鐢宠鍗曞彿</param> + /// <param name="transactionNo">浜嬪姟绫诲瀷</param> + /// <returns>鍖呭惈鏍¢獙缁撴灉鐨勬暟鎹紶杈撳璞�</returns> + public dynamic pdaInvJY(SqlSugarScope db, string edtUserNo, + string barcode, string sectionCode, string stockId, string stockOrgId, + string billNo, string transactionNo) { + var outputMsg = ""; + var outputStatus = -1; - /// <summary> - /// 閫氱敤鍏ュ簱鏍¢獙 - /// </summary> - /// <param name="db">SqlSugar 鏁版嵁搴撲笂涓嬫枃</param> - /// <param name="edtUserNo">鎿嶄綔浜哄伐鍙�</param> - /// <param name="barcode">鐗╂枡鏉$爜</param> - /// <param name="sectionCode">搴撲綅缂栫爜</param> - /// <param name="stockId">浠撳簱ID</param> - /// <param name="stockOrgId">搴撳瓨缁勭粐ID</param> - /// <param name="billNo">鐢宠鍗曞彿</param> - /// <param name="transactionNo">浜嬪姟绫诲瀷</param> - /// <returns>鍖呭惈鏍¢獙缁撴灉鐨勬暟鎹紶杈撳璞�</returns> - public dynamic pdaInvJY(SqlSugarScope db, string edtUserNo, - string barcode, string sectionCode, string stockId, string stockOrgId, - string billNo, string transactionNo) + using (var conn = new SqlConnection(DbHelperSQL.strConn)) + using (var cmd = new SqlCommand("prc_pda_inv_JY", conn)) { - var outputMsg = ""; - var outputStatus = -1; - - using (var conn = new SqlConnection(DbHelperSQL.strConn)) - using (var cmd = new SqlCommand("prc_pda_inv_JY", conn)) + cmd.CommandType = CommandType.StoredProcedure; + // 杈撳叆鍙傛暟閰嶇疆 + SqlParameter[] parameters = { - cmd.CommandType = CommandType.StoredProcedure; - // 杈撳叆鍙傛暟閰嶇疆 - SqlParameter[] parameters = + new("@pi_user", SqlDbType.NVarChar, 100) { Value = edtUserNo }, + new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = barcode }, + new("@pi_sectionCode", SqlDbType.NVarChar, 100) + { Value = sectionCode }, + new("@pi_stockId", SqlDbType.NVarChar, 100) { Value = stockId }, + new("@pi_stockOrgId", SqlDbType.NVarChar, 100) + { Value = stockOrgId }, + new("@pi_billno", SqlDbType.NVarChar, 100) { Value = billNo }, + new("@pi_transaction_no", SqlDbType.NVarChar, 10) + { Value = transactionNo }, + new("@pi_val1", SqlDbType.NVarChar, 100) + { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁 + new("@pi_val2", SqlDbType.NVarChar, 100) + { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁 + new("@po_outMsg", SqlDbType.NVarChar, 2000) + { Direction = ParameterDirection.Output }, + new("@po_outStatus", SqlDbType.Int) + { Direction = ParameterDirection.Output } + }; + + try + { + conn.Open(); + cmd.Parameters.AddRange(parameters); + cmd.ExecuteNonQuery(); + + // 鑾峰彇杈撳嚭鍙傛暟 + outputMsg = parameters[9].Value?.ToString() ?? ""; + outputStatus = Convert.ToInt32(parameters[10].Value); + + if (outputStatus <= 0) + throw new Exception(outputMsg); + + return new ProductionPickDto { - new("@pi_user", SqlDbType.NVarChar, 100) { Value = edtUserNo }, - new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = barcode }, - new("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = sectionCode }, - new("@pi_stockId", SqlDbType.NVarChar, 100) { Value = stockId }, - new("@pi_stockOrgId", SqlDbType.NVarChar, 100) { Value = stockOrgId }, - new("@pi_billno", SqlDbType.NVarChar, 100) { Value = billNo }, - new("@pi_transaction_no", SqlDbType.NVarChar, 10) { Value = transactionNo }, - new("@pi_val1", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁 - new("@pi_val2", SqlDbType.NVarChar, 100) { Value = DBNull.Value }, // 棰勭暀鎵╁睍瀛楁 - new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output }, - new("@po_outStatus", SqlDbType.Int) { Direction = ParameterDirection.Output } + barcode = barcode, + strMsg = outputMsg, + result = outputStatus.ToString() + // 鍏朵粬闇�瑕佹槧灏勭殑瀛楁... }; - - try - { - conn.Open(); - cmd.Parameters.AddRange(parameters); - cmd.ExecuteNonQuery(); - - // 鑾峰彇杈撳嚭鍙傛暟 - outputMsg = parameters[9].Value?.ToString() ?? ""; - outputStatus = Convert.ToInt32(parameters[10].Value); - - if (outputStatus <= 0) - throw new Exception(outputMsg); - - return new ProductionPickDto - { - barcode = barcode, - strMsg = outputMsg, - result = outputStatus.ToString(), - // 鍏朵粬闇�瑕佹槧灏勭殑瀛楁... - }; - } - catch (Exception ex) - { - throw new Exception($"鍏ュ簱鏍¢獙澶辫触: {ex.Message}"); - } + } + catch (Exception ex) + { + throw new Exception($"鍏ュ簱鏍¢獙澶辫触: {ex.Message}"); } } + } - /// <summary> - /// 鑾峰彇鏉$爜淇℃伅 - /// </summary> - /// <param name="unity"></param> - /// <returns></returns> - /// <exception cref="Exception"></exception> - public MesInvItemBarcodes GetBarInfo(WarehouseQuery unity) - { - var barInfo = Db.Queryable<MesInvItemBarcodes>() - .Where(s => s.ItemBarcode == unity.barcode) - .First(); - if (barInfo is null) throw new Exception("璇ユ潯鐮佸簱瀛樹笉瀛樺湪锛�"); + /// <summary> + /// 鑾峰彇鏉$爜淇℃伅 + /// </summary> + /// <param name="unity"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public MesInvItemBarcodes GetBarInfo(WarehouseQuery unity) + { + var barInfo = Db.Queryable<MesInvItemBarcodes>() + .Where(s => s.ItemBarcode == unity.barcode) + .First(); + if (barInfo is null) throw new Exception("璇ユ潯鐮佸簱瀛樹笉瀛樺湪锛�"); - return barInfo; // 杩斿洖绗竴琛屾暟鎹紝濡傛灉娌℃湁鍒欒繑鍥� null - } + return barInfo; // 杩斿洖绗竴琛屾暟鎹紝濡傛灉娌℃湁鍒欒繑鍥� null + } - /// <summary> - /// 鑾峰彇鐗╂枡淇℃伅 - /// </summary> - /// <param name="strItemId"></param> - /// <returns></returns> - /// <exception cref="Exception"></exception> - public MesItems GetItemNo(decimal strItemId) - { - var itemInfo = Db.Queryable<MesItems>() - .Where(s => s.Id == strItemId && s.Fforbidstatus == "A") - .First(); - if (itemInfo is null) throw new Exception("璇ユ潯鐮佸搴旂墿鏂欎俊鎭笉瀛樺湪鎴栧凡绂佺敤锛�"); + /// <summary> + /// 鑾峰彇鐗╂枡淇℃伅 + /// </summary> + /// <param name="strItemId"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public MesItems GetItemNo(decimal strItemId) + { + var itemInfo = Db.Queryable<MesItems>() + .Where(s => s.Id == strItemId && s.Fforbidstatus == "A") + .First(); + if (itemInfo is null) throw new Exception("璇ユ潯鐮佸搴旂墿鏂欎俊鎭笉瀛樺湪鎴栧凡绂佺敤锛�"); - return itemInfo; - } + return itemInfo; + } - /// <summary> - /// 鑾峰彇璐т富绫诲瀷 - /// </summary> - /// <param name="ownerId">璐т富ID</param> - /// <returns>璐т富绫诲瀷(BD_OwnerOrg/BD_Customer/BD_Supplier)</returns> - public string GetOwnerType(string ownerId) - { - if (string.IsNullOrEmpty(ownerId)) - throw new ArgumentNullException(nameof(ownerId)); + /// <summary> + /// 鑾峰彇璐т富绫诲瀷 + /// </summary> + /// <param name="ownerId">璐т富ID</param> + /// <returns>璐т富绫诲瀷(BD_OwnerOrg/BD_Customer/BD_Supplier)</returns> + public string GetOwnerType(string ownerId) + { + if (string.IsNullOrEmpty(ownerId)) + throw new ArgumentNullException(nameof(ownerId)); - if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId)) - { - return "BD_OwnerOrg"; - } - else if (Db.Queryable<MesCustomer>().Any(x => x.Id == Convert.ToInt32(ownerId))) - { - return "BD_Customer"; - } - else if (Db.Queryable<MesSupplier>().Any(x => x.Id == Convert.ToInt32(ownerId))) - { - return "BD_Supplier"; - } - else if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId)) - { - return "BD_OwnerOrg"; - } - - throw new Exception("鏃犳硶纭畾璐т富绫诲瀷锛岃妫�鏌ヨ揣涓籌D鏄惁姝g‘锛�"); - } + if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId)) + return "BD_OwnerOrg"; - + if (Db.Queryable<MesCustomer>() + .Any(x => x.Id == Convert.ToInt32(ownerId))) return "BD_Customer"; + + if (Db.Queryable<MesSupplier>() + .Any(x => x.Id == Convert.ToInt32(ownerId))) return "BD_Supplier"; + + if (Db.Queryable<SysOrganization>().Any(x => x.Fid == ownerId)) + return "BD_OwnerOrg"; + + throw new Exception("鏃犳硶纭畾璐т富绫诲瀷锛岃妫�鏌ヨ揣涓籌D鏄惁姝g‘锛�"); } } \ No newline at end of file -- Gitblit v1.9.3