啊鑫
昨天 00a72fff219241eb5b0405a066cc859d07cf7735
service/Warehouse/KwbgManager.cs
@@ -1,27 +1,30 @@
using System.Data;
using System.Data.SqlClient;
using Masuit.Tools;
using Masuit.Tools.Hardware;
using NewPdaSqlServer.DB;
using NewPdaSqlServer.Dto.service;
using NewPdaSqlServer.entity;
using NewPdaSqlServer.util;
using SqlSugar;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
/// <summary>
///     库位变更管理类,继承自通用仓储类Repository,操作采购退货申请表(MesCgthSq)
/// 库位变更管理类,继承自通用仓储类Repository,操作采购退货申请表(MesCgthSq)
/// </summary>
public class KwbgManager : Repository<MesCgthSq>
{
    /// <summary>
    ///     根据传入的WarehouseQuery对象(包含条码信息),查询物料库存表MES_INV_ITEM_STOCKS,获取对应的库存信息
    /// 根据传入的WarehouseQuery对象(包含条码信息),查询物料库存表MES_INV_ITEM_STOCKS,获取对应的库存信息
    /// </summary>
    /// <param name="unity">WarehouseQuery对象,包含条码编号等查询条件</param>
    /// <returns>
    ///     返回MES_INV_ITEM_STOCKS表中与条码匹配的第一条库存信息(MesInvItemStocks类型)。
    ///     如果未找到,则抛出异常提示“该条码库存不存在!”
    ///     resultInfos.tbBillList = m.GetBarInfo(unity);
    /// 返回MES_INV_ITEM_STOCKS表中与条码匹配的第一条库存信息(MesInvItemStocks类型)。
    /// 如果未找到,则抛出异常提示“该条码库存不存在!”
    /// resultInfos.tbBillList = m.GetBarInfo(unity);
    /// </returns>
    /// public MesInvItemStocks GetBarInfo(WarehouseQuery unity)
    ///public MesInvItemStocks GetBarInfo(WarehouseQuery unity)
    public dynamic GetBarInfo(dynamic query)
    {
        if (query == null)
@@ -31,19 +34,18 @@
            throw new ArgumentException("物料条码不能为空", nameof(query.barcode));
        var parameters = new[]
        {
            new SugarParameter("@pi_barcode", query.barcode),
            new SugarParameter("@inP1", null),
            new SugarParameter("@inP2", null),
            new SugarParameter("@inP3", null),
            new SugarParameter("@inP4", null)
        };
    {
        new SugarParameter("@pi_barcode", query.barcode),
        new SugarParameter("@inP1", null),
        new SugarParameter("@inP2", null),
        new SugarParameter("@inP3", null),
        new SugarParameter("@inP4", null)
    };
        try
        {
            var ZsBarInfo = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_kwbg_selKwInfoByBarcode @pi_barcode,@inP1,@inP2,@inP3,@inP4",
                parameters);
            List<dynamic>? ZsBarInfo = Db.Ado.SqlQuery<dynamic>(
                "EXEC prc_pda_kwbg_selKwInfoByBarcode @pi_barcode,@inP1,@inP2,@inP3,@inP4", parameters);
            return ZsBarInfo;
        }
@@ -55,13 +57,13 @@
    }
    /// <summary>
    ///     根据物料ID查询物料表MES_ITEMS,获取物料详细信息
    /// 根据物料ID查询物料表MES_ITEMS,获取物料详细信息
    /// </summary>
    /// <param name="strItemId">物料ID(decimal类型)</param>
    /// <returns>
    ///     返回MES_ITEMS表中与ID匹配且未禁用(Fforbidstatus为"A")的第一条物料信息(MesItems类型)。
    ///     如果未找到,则抛出异常提示“该条码对应物料信息不存在或已禁用!”
    ///     resultInfos.tbMesItems = m.GetItemNo(resultInfos.tbBillList.ItemId);
    /// 返回MES_ITEMS表中与ID匹配且未禁用(Fforbidstatus为"A")的第一条物料信息(MesItems类型)。
    /// 如果未找到,则抛出异常提示“该条码对应物料信息不存在或已禁用!”
    /// resultInfos.tbMesItems = m.GetItemNo(resultInfos.tbBillList.ItemId);
    /// </returns>
    public MesItems GetItemNo(decimal strItemId)
    {
@@ -77,15 +79,14 @@
        // 返回查询到的物料信息对象
        return itemInfo;
    }
    /// <summary>
    ///     仓库信息表
    /// 仓库信息表
    /// </summary>
    /// <param name="depot_id"></param>
    /// <returns></returns>
    public MesDepots GetDepot(decimal depot_id)
    {
        var depotInfo = Db.Queryable<MesDepots>()
        var depotInfo = Db.Queryable< MesDepots >()
            .Where(s => s.DepotId == depot_id)
            .First(); // 获取第一条匹配记录
        // 如果未查询到结果(itemInfo为null),则抛出异常,提示物料信息不存在或已禁用
@@ -94,8 +95,9 @@
    }
    /// <summary>
    ///     变更库位
    /// 变更库位
    /// </summary>
    /// <param name="unity"></param>
    /// <returns></returns>
@@ -114,15 +116,13 @@
        {
            //if (string.IsNullOrEmpty(query.barcode?.ToString()))
            //throw new ArgumentException("物料条码不能为空", nameof(query.barcode));
            if (string.IsNullOrEmpty(unity.userName?.ToString()))
                throw new ArgumentException("用户名不允许为空", nameof(unity.userName));
            if (string.IsNullOrEmpty(unity.OldDepotSectionCode?.ToString()))
                throw new ArgumentException("原库位不允许为空",
                    nameof(unity.OldDepotSectionCode));
                throw new ArgumentException("原库位不允许为空", nameof(unity.OldDepotSectionCode));
            if (string.IsNullOrEmpty(unity.NewDepotSectionCode?.ToString()))
                throw new ArgumentException("新库位不允许为空",
                    nameof(unity.NewDepotSectionCode));
                throw new ArgumentException("新库位不允许为空", nameof(unity.NewDepotSectionCode));
            if (string.IsNullOrEmpty(unity.barcode?.ToString()))
                throw new ArgumentException("物料条码不允许为空", nameof(unity.barcode));
@@ -144,31 +144,25 @@
                    // 构造存储过程参数数组
                    SqlParameter[] parameters =
                    {
                        // 输出参数:返回信息
                        new("@outMsg", SqlDbType.NVarChar, 2000),
                        // 输出参数:返回数量
                        new("@outSum", SqlDbType.Int),
                        // 输出参数:返回新库位代码
                        new("@new_depotSectionsCode", SqlDbType.NVarChar, 300),
                        // 输入参数:操作用户
                        new SqlParameter("@c_user",
                            unity.userName?.ToString() ?? ""),
                        // 输入参数:原条码
                        new SqlParameter("@p_barcode",
                            unity.barcode?.ToString() ?? ""),
                        // 输入参数:原库位代码
                        new("@old_depotSectionsCode",
                            unity.OldDepotSectionCode?.ToString() ?? ""),
                        // 输入参数:新库位代码
                        new("@new_depotSectionsCode_input",
                            unity.NewDepotSectionCode?.ToString() ?? ""),
                        // 输入参数:仓库代码
                        new("@DepotCode", unity.DepotCode)
                            { Value = unity.DepotCode ?? "" },
                        // 输入参数:仓库id
                        new("@DepotId",
                            (int?)unity.DepotId ?? (object)DBNull.Value)
                    };
                    // 输出参数:返回信息
                    new("@outMsg", SqlDbType.NVarChar, 2000),
                    // 输出参数:返回数量
                    new("@outSum", SqlDbType.Int),
                    // 输出参数:返回新库位代码
                    new("@new_depotSectionsCode", SqlDbType.NVarChar, 300),
                    // 输入参数:操作用户
                    new SqlParameter("@c_user", unity.userName?.ToString() ?? ""),
                    // 输入参数:原条码
                    new SqlParameter("@p_barcode", unity.barcode?.ToString() ?? ""),
                    // 输入参数:原库位代码
                    new("@old_depotSectionsCode", unity.OldDepotSectionCode?.ToString() ??""),
                    // 输入参数:新库位代码
                    new("@new_depotSectionsCode_input", unity.NewDepotSectionCode?.ToString() ??""),
                    // 输入参数:仓库代码
                    new("@DepotCode", unity.DepotCode) { Value = unity.DepotCode ?? "" },
                    // 输入参数:仓库id
                    new SqlParameter("@DepotId", (int?)unity.DepotId ?? (object)DBNull.Value)
                };
                    // 设置输出参数方向
                    parameters[0].Direction = ParameterDirection.Output;
                    parameters[1].Direction = ParameterDirection.Output;
@@ -182,10 +176,9 @@
                    cmd.ExecuteNonQuery();
                    // 获取存储过程输出参数的值
                    _strMsg = parameters[0].Value.ToString(); // 返回信息
                    _intSum = parameters[1].Value.ToString(); // 返回数量
                    _NewDepotSectionCode =
                        parameters[2].Value.ToString(); // 新库位代码
                    _strMsg = parameters[0].Value.ToString();    // 返回信息
                    _intSum = parameters[1].Value.ToString();    // 返回数量
                    _NewDepotSectionCode = parameters[2].Value.ToString();     // 新库位代码
                    // 判断变更结果,如果数量小于等于0,则表示变更失败,抛出异常并返回错误信息
                    var result = Convert.ToInt32(_intSum);
@@ -194,8 +187,8 @@
                    // 使用匿名对象而不是 dynamic? 更合适
                    var dto = new
                    {
                        unity.barcode,
                        unity.OldDepotSectionCode,
                        barcode = unity.barcode,
                        OldDepotSectionCode = unity.OldDepotSectionCode,
                        NewDepotSectionCode = _NewDepotSectionCode
                    };
@@ -221,4 +214,6 @@
    ProductionPickDto有过添加
    public int? DepotId { get; set; }    //仓库id
     */
}