| | |
| | | using Masuit.Tools.Models; |
| | | using Microsoft.AspNetCore.SignalR.Protocol; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.entity; |
| | |
| | | { |
| | | //当前类已经继承了 Repository 增、删、查、改的方法 |
| | | |
| | | |
| | | public ItemInBaseModel SaveBarCodes(WarehouseQuery entity) |
| | | { |
| | | ItemInBaseModel res = new ItemInBaseModel(); |
| | | string connectionString = DbHelperSQL.strConn; |
| | | |
| | | // 参数验证 |
| | | if (string.IsNullOrEmpty(entity.userName)) throw new ArgumentNullException(nameof(entity.userName), "用户名不允许为空"); |
| | | if (string.IsNullOrEmpty(entity.sectionCode)) throw new ArgumentNullException(nameof(entity.sectionCode), "库位编号不允许为空"); |
| | | if (string.IsNullOrEmpty(entity.barcode)) throw new ArgumentNullException(nameof(entity.barcode), "条码不允许为空"); |
| | | |
| | | using (var conn = new SqlConnection(connectionString)) |
| | | { |
| | | using (var cmd = new SqlCommand("[prc_pda_inv_cgrk]", conn)) |
| | | { |
| | | try |
| | | { |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | |
| | | // 设置存储过程参数 |
| | | SqlParameter[] parameters = |
| | | { |
| | | new SqlParameter("@pi_user", SqlDbType.NVarChar, 100) { Value = entity.userName }, |
| | | new SqlParameter("@pi_barcode", SqlDbType.NVarChar, 100) { Value = entity.barcode.Trim().ToLower() }, |
| | | new SqlParameter("@pi_sectionCode", SqlDbType.NVarChar, 30) { Value = entity.sectionCode }, |
| | | new SqlParameter("@pi_weight", SqlDbType.Decimal) { Value = entity.weight }, |
| | | new SqlParameter("@po_outMsg", SqlDbType.NVarChar, 300) { Direction = ParameterDirection.Output }, |
| | | new SqlParameter("@po_outSum", SqlDbType.NVarChar, 300) { Direction = ParameterDirection.Output } |
| | | }; |
| | | |
| | | cmd.Parameters.AddRange(parameters); |
| | | cmd.ExecuteNonQuery(); |
| | | |
| | | // 获取输出参数 |
| | | string? outMessage = parameters[4].Value?.ToString(); |
| | | string? outSum = parameters[5].Value?.ToString(); |
| | | |
| | | |
| | | // 检查参数是否为空,并在异常中显示实际值 |
| | | if (string.IsNullOrEmpty(outMessage) || string.IsNullOrEmpty(outSum)) |
| | | { |
| | | // 拼接参数实际值(处理 null 的情况) |
| | | string messageValue = outMessage ?? "null"; |
| | | string sumValue = outSum ?? "null"; |
| | | throw new InvalidOperationException( |
| | | $"存储过程返回参数异常:输出消息为【{messageValue}】,输出数量为【{sumValue}】" |
| | | ); |
| | | } |
| | | |
| | | // 验证结果 |
| | | if (!int.TryParse(outSum, out int result) || result <= 0) |
| | | throw new InvalidOperationException(outMessage); |
| | | |
| | | // 调试输出 |
| | | Console.WriteLine($"查询的条码值: '{entity.barcode}' (长度: {entity.barcode.Length})"); |
| | | |
| | | // 使用参数化查询并忽略大小写(适用于支持的数据库) |
| | | var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(it => it.ItemBarcode.Trim().ToLower() == entity.barcode.Trim().ToLower()) |
| | | .First() ?? throw new InvalidOperationException($"未找到条码 '{entity.barcode}' 的匹配信息"); |
| | | |
| | | // 调试输出(检查值和长度) |
| | | Console.WriteLine($"查询的条码值: '{entity.barcode}' (长度: {entity.barcode.Length})"); |
| | | |
| | | // 优化查询(去除空格并忽略大小写) |
| | | var MesInvItemInCDetails = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode.Trim().ToLower() == entity.barcode.Trim().ToLower()) |
| | | .First() ?? throw new InvalidOperationException($"未找到条码 '{entity.barcode}' 的匹配的入库信息"); |
| | | |
| | | // 从入库条码中获取有效的ItemInId |
| | | var cId = MesInvItemInCDetails.ItemInId; // 假设存在ItemInId属性 |
| | | |
| | | // 查询物料汇总明细 |
| | | var sql = string.Format(@" |
| | | SELECT |
| | | b.Item_No AS ItemNo, |
| | | b.Item_Name AS ItemName, |
| | | b.Item_Model AS ItemModel, |
| | | a.Quantity AS FQty, |
| | | b.Item_Id AS FMaterialId, |
| | | CONVERT(VARCHAR(36), b.Guid) AS Id |
| | | FROM MES_INV_ITEM_IN_C_ITEMS a |
| | | LEFT JOIN Mes_Items b ON a.Item_Id = b.Item_Id |
| | | WHERE a.Item_In_Id = '{0}' AND a.Item_Id = '{1}'", cId, itemBarcodeDetails.ItemId); |
| | | |
| | | res.ItemInDetails = Db.Ado.SqlQuery<dynamic>(sql); |
| | | |
| | | // 查询入库条码明细 |
| | | var sql2 = string.Format(@" |
| | | SELECT |
| | | b.Item_No AS ItemNo, |
| | | b.Item_Name AS ItemName, |
| | | b.Item_Model AS ItemModel, |
| | | a.Quantity AS FQty, |
| | | b.Item_Id AS FMaterialId, |
| | | CONVERT(VARCHAR(36), a.Guid) AS Id, |
| | | a.Depot_Section_Code AS kw, |
| | | a.Item_Barcode AS barcode |
| | | FROM Mes_Inv_Item_In_C_Details a |
| | | LEFT JOIN Mes_Items b ON a.Item_Id = b.Item_Id |
| | | WHERE a.Item_In_Id = '{0}' AND a.Item_Id = '{1}'", cId, itemBarcodeDetails.ItemId); |
| | | |
| | | res.ItemBarCDetails = Db.Ado.SqlQuery<dynamic>(sql2); |
| | | //查询已入库总数 |
| | | var totalCDetailsQuantity = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemInId == cId) |
| | | .Sum(it => it.Quantity); |
| | | |
| | | res.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity); |
| | | |
| | | // 设置返回信息 |
| | | res.Message = outMessage; |
| | | |
| | | |
| | | return res; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | |
| | | |
| | | // 记录异常日志(建议添加日志记录) |
| | | res.Message = $"操作失败: {ex.Message}"; |
| | | res.SumQuantity = -1; |
| | | return res; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /* public ItemInBaseModel SaveBarCodes(WarehouseQuery entity) |
| | | { |
| | | string functionName = "采购入库", fieldName = null, inFieldVal = null; |
| | | string user = entity.userName, |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | */ |
| | | public ItemInBaseModel getPurchaseInventory(WarehouseQuery query) |
| | | { |
| | | return new ItemInBaseModel |
| | |
| | | new("@pi_user", SqlDbType.NVarChar, 100) { Value = entity.userName }, |
| | | new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = entity.returnBarcode }, // 使用原始条码 |
| | | new("@pi_sectionCode", SqlDbType.NVarChar, 100) { Value = entity.sectionCode }, |
| | | new("@pi_weight", SqlDbType.Decimal) { Value = entity.weight }, |
| | | new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output }, |
| | | new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output } |
| | | }; |
| | |
| | | |
| | | res.ItemBarCDetails = Db.Ado.SqlQuery<dynamic>(sql2, new { cId, itemId = itemBarcode.ItemId }); |
| | | |
| | | res.Message = $"验退操作成功,拆分后条码:{cfBar},验退单号:{ytdh}"; |
| | | res.SumQuantity = res.ItemBarCDetails?.Count ?? 0; |
| | | |
| | | //查询已入库总数 |
| | | var totalCDetailsQuantity = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemInId == cId) |
| | | .Sum(it => it.Quantity); |
| | | |
| | | res.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity); |
| | | |
| | | |
| | | res.Message = $"验退操作成功,拆分后条码:{cfBar},验退单号:{ytdh}"; |
| | | // res.SumQuantity = res.ItemBarCDetails?.Count ?? 0; |
| | | res.SumQuantity = Convert.ToDecimal(totalCDetailsQuantity); |
| | | return res; |
| | | } |
| | | catch (Exception ex) |