namespace NewPdaSqlServer.service.@base
|
{
|
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;
|
|
using (var conn = new SqlConnection(DbHelperSQL.strConn))
|
using (var cmd = new SqlCommand("prc_pda_inv_JY", conn))
|
{
|
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
|
{
|
barcode = barcode,
|
strMsg = outputMsg,
|
result = outputStatus.ToString(),
|
// 其他需要映射的字段...
|
};
|
}
|
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("该条码库存不存在!");
|
|
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("该条码对应物料信息不存在或已禁用!");
|
|
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));
|
|
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("无法确定货主类型,请检查货主ID是否正确!");
|
}
|
|
|
}
|
}
|