kyy
2025-12-04 aa6c2ce07e6a8a99d3d861ce5fae8fa76f62d36f
1、期初入库库位判断
已修改3个文件
133 ■■■■ 文件已修改
service/QC/LljService.cs 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/Warehouse/InventoryManager.cs 126 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/base/MesPrintMangeer.cs 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/QC/LljService.cs
@@ -46,7 +46,10 @@
            .WhereIF(UtilityHelper.CheckGuid(parsedGuid),
                a => a.guid == parsedGuid )
            .Where(a => (a.fsubmit ?? 0) == 0)
            .OrderByDescending(a => a.CreateDate)
        // 使用 OrderBy 的多条件排序
        //.OrderBy(it => SqlFunc.IIF((it.fsubmit ?? 0) == 0, 0, 1))
        .OrderBy(it => SqlFunc.IIF((it.UrgentFlag ?? 0) == 1, 0, 1))
        .OrderByDescending(a => a.CreateDate)
            .ToPageList(queryObj.PageIndex, queryObj.Limit, ref totalCount);
        return (pageList, totalCount);
service/Warehouse/InventoryManager.cs
@@ -8,6 +8,7 @@
using System.Data;
using System.Data.SqlClient;
using System.Dynamic;
using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
namespace NewPdaSqlServer.service.Warehouse;
@@ -52,53 +53,108 @@
        var p_bill_type_id = 100;
        var p_transction_no = 601;
        // 检查库位代码是否为空
        // if (string.IsNullOrEmpty(p_section_code))
        //     throw new Exception("002[请扫库位条码!");
        // 查询库区库位信息
        var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
                new JoinQueryInfos(
                    JoinType.Inner, a.DepotGuid == b.Guid
                ))
            .Where((a, b) => a.DepotSectionCode == p_section_code)
            .Select((a, b) => new
                { a.DepotSectionName, b.DepotCode, b.DepotName, b.DepotId,b.FSubsidiary })
            .Single();
        /* var depotSection = Db.Queryable<MesDepotSections, MesDepots>((a, b) =>
                 new JoinQueryInfos(
                     JoinType.Inner, a.DepotGuid == b.Guid
                 ))
             .Where((a, b) => a.DepotSectionCode == p_section_code)
             .Select((a, b) => new
             {
                 a.DepotSectionName,
                 b.DepotCode,
                 b.DepotName,
                 b.DepotId,
                 b.FSubsidiary
             })
             .Single();*/
        // 如果库位代码不存在,则返回错误信息
        // if (depotSection == null)
        //     throw new Exception("库位编码 " + p_section_code + " 不存在,请确认!");
        // ============================
        // 替换:使用原生 SqlConnection + SqlCommand 调用存储过程(参考 SaveBarCodes 方法风格)
        // ============================
        string connectionString = DbHelperSQL.strConn; // 复用参考代码中的连接字符串获取方式
        int po_depotId = 0;
        string po_depotNo = string.Empty;
        string po_depotName = string.Empty;
        string po_fSubsidiary = string.Empty;
        string po_outMsg = string.Empty;
        int po_outSum = -1;
        // 检查是否已经收货
        // var c_num = Db.Queryable<MesInvItemIns, MesInvItemInCDetails>((a, b) =>
        //         new JoinQueryInfos(
        //             JoinType.Inner, a.Guid == b.ItemInId
        //         ))
        //     .Where((a, b) => b.ItemBarcode == p_item_barcode)
        //     .Count();
        // if (c_num > 0) throw new Exception("002[条码重复扫描,请核对!");
        // 查询条码信息
        // c_num = Db.Queryable<MesInvItemStocks>()
        //     .Where(t => t.ItemBarcode == p_item_barcode)
        //     .Count();
        // if (c_num > 0) throw new Exception("002[条码已在库存中,请核对!");
        // 查询条码详细信息
        var c_mes_inv_item_barcodes = Db.Queryable<MesInvItemBarcodes>()
            .Where(t => t.ItemBarcode == p_item_barcode)
            .Single();
        // if (c_mes_inv_item_barcodes == null)
        //     throw new Exception("002[条码不存在,请核对!");
        if (c_mes_inv_item_barcodes.Memo != "初期物料")
            throw new Exception("002[条码不是期初条码,无法用期初入库!");
        var wmsManager = new WmsBaseMangeer();
        using (var conn = new SqlConnection(connectionString))
        {
            using (var cmd = new SqlCommand("prc_pda_select_depot", conn))
            {
                try
                {
                    conn.Open();
                    cmd.CommandType = CommandType.StoredProcedure;
                    // 设置存储过程参数(输入+输出)
                    SqlParameter[] parameters =
                    {
                    // 输入参数
                    new SqlParameter("@pi_code", SqlDbType.NVarChar, 100) { Value = p_item_barcode },
                    new SqlParameter("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = p_section_code },
                    // 输出参数
                    new SqlParameter("@po_depotId", SqlDbType.Int) { Direction = ParameterDirection.Output },
                    new SqlParameter("@po_depotNo", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
                    new SqlParameter("@po_depotName", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
                    new SqlParameter("@po_fSubsidiary", SqlDbType.NVarChar, 80) { Direction = ParameterDirection.Output },
                    new SqlParameter("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output },
                    new SqlParameter("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }
                };
                    cmd.Parameters.AddRange(parameters);
                    cmd.ExecuteNonQuery();
                    // 获取输出参数值(注意:需判断 DBNull,避免空引用异常)
                    po_depotId = parameters[2].Value != DBNull.Value ? Convert.ToInt32(parameters[2].Value) : 0;
                    po_depotNo = parameters[3].Value != DBNull.Value ? parameters[3].Value.ToString() : string.Empty;
                    po_depotName = parameters[4].Value != DBNull.Value ? parameters[4].Value.ToString() : string.Empty;
                    po_fSubsidiary = parameters[5].Value != DBNull.Value ? parameters[5].Value.ToString() : string.Empty;
                    po_outMsg = parameters[6].Value != DBNull.Value ? parameters[6].Value.ToString() : string.Empty;
                    po_outSum = parameters[7].Value != DBNull.Value ? Convert.ToInt32(parameters[7].Value) : -1;
                }
                catch (Exception ex)
                {
                    throw new Exception($"调用存储过程 prc_pda_select_depot 失败:{ex.Message}");
                }
            }
        }
        // 验证存储过程执行结果
        if (po_outSum < 0 || string.IsNullOrEmpty(po_depotNo) || po_depotId <= 0)
        {
            throw new Exception(string.IsNullOrEmpty(po_outMsg) ? "获取仓库信息失败,请检查条码和库位是否正确" : po_outMsg);
        }
        // 构造与原 depotSection 结构一致的对象,确保后续代码兼容
        var depotSection = new
        {
            // DepotSectionName = string.Empty, // 存储过程未返回库位名称,如需使用可后续补充
            DepotCode = po_depotNo,          // 对应存储过程的 po_depotNo(仓库编码)
            DepotName = po_depotName,        // 对应存储过程的 po_depotName(仓库名称)
            DepotId = po_depotId,            // 对应存储过程的 po_depotId(仓库ID)
            FSubsidiary = po_fSubsidiary     // 对应存储过程的 po_fSubsidiary(组织)
        };
        //由于龙巍入库可不按仓位对应仓库来所以特此取消此校验
/*        var wmsManager = new WmsBaseMangeer();
        // 新增入库校验(调用存储过程)
        var checkResult = wmsManager.pdaInvJY(
            db: Db,
@@ -112,7 +168,7 @@
        );
        
        if ( Convert.ToInt32(checkResult.result) < 1) 
            throw new Exception($"入库校验失败:{checkResult.strMsg}");
            throw new Exception($"入库校验失败:{checkResult.strMsg}");*/
        UseTransaction(db =>
        {
service/base/MesPrintMangeer.cs
@@ -7,7 +7,7 @@
    using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
    using System.Data;
    using NewPdaSqlServer.DB;
    using System.Data;
    using System.Data.SqlClient;
    using Microsoft.EntityFrameworkCore.Metadata.Internal;