| | |
| | | using Masuit.Tools.Models; |
| | | using Microsoft.AspNetCore.SignalR.Protocol; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.entity; |
| | |
| | | using NewPdaSqlServer.util; |
| | | using Newtonsoft.Json; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Data; |
| | | using System.Data.SqlClient; |
| | | using static Microsoft.EntityFrameworkCore.DbLoggerCategory; |
| | | |
| | | namespace NewPdaSqlServer.service.Warehouse; |
| | |
| | | { |
| | | //当前类已经继承了 Repository 增、删、查、改的方法 |
| | | |
| | | |
| | | public ItemInBaseModel SaveBarCodes(WarehouseQuery entity) |
| | | { |
| | | ItemInBaseModel res = new ItemInBaseModel(); |
| | | string connectionString = DB.DbHelperSQL.strConn; |
| | | |
| | | // 参数验证 |
| | | if (entity == null) |
| | | throw new ArgumentNullException(nameof(entity), "参数对象不能为空"); |
| | | 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), "条码不允许为空"); |
| | | |
| | | if (string.IsNullOrEmpty(entity.userName)) |
| | | throw new ArgumentException("用户名不能为空", nameof(entity.userName)); |
| | | using (var conn = new SqlConnection(connectionString)) |
| | | { |
| | | using (var cmd = new SqlCommand("[prc_pda_inv_cgrk]", conn)) |
| | | { |
| | | //try |
| | | //{ |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | |
| | | if (string.IsNullOrEmpty(entity.barcode)) |
| | | throw new ArgumentException("条码不能为空", nameof(entity.barcode)); |
| | | // 设置存储过程参数 |
| | | 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_cgrkType", SqlDbType.NVarChar, 30) { Value = "正常入库" }, |
| | | 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[5].Value?.ToString(); |
| | | string? outSum = parameters[6].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, |
| | | sectionCode = entity.sectionCode, |
| | |
| | | if (string.IsNullOrEmpty(sectionCode)) |
| | | throw new Exception("请扫库位条码!"); |
| | | |
| | | MesInvItemBarcodes itemBarcodeDetails; |
| | | try |
| | | { |
| | | itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>() |
| | | var itemBarcodeDetails = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(it => it.ItemBarcode == itemBarcode) |
| | | .First(); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | if (itemBarcodeDetails == null) |
| | | throw new Exception("条码不存在,请核对!"); |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(itemBarcodeDetails.Memo) || itemBarcodeDetails.Memo != "采购入库") |
| | | throw new Exception("此条码不属于到货条码,无法用采购入库!"); |
| | | |
| | | MesInvItemArn inventory; |
| | | try |
| | | { |
| | | inventory = Db.Queryable<MesInvItemArn>() |
| | | var inventory = Db.Queryable<MesInvItemArn>() |
| | | .Where(it => it.BillNo == itemBarcodeDetails.BillNo && it.Fstatus == true ) |
| | | .First(); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | if (inventory == null) |
| | | throw new Exception("此条码找不到对应收货单或未审核!"); |
| | | } |
| | | |
| | | // var inventoryDetails = Db.Queryable<MesInvItemArnDetail>() |
| | | // .Where(it => it.ParentGuid == inventory.Guid |
| | |
| | | // && it.Ebeln == itemBarcodeDetails.WorkNo) |
| | | // .First(); |
| | | |
| | | MesInvItemArnDetail inventoryDetails; |
| | | try |
| | | { |
| | | inventoryDetails = Db.Queryable<MesInvItemArnDetail>() |
| | | var inventoryDetails = Db.Queryable<MesInvItemArnDetail>() |
| | | .Where(it => it.Guid == itemBarcodeDetails.AboutGuid) |
| | | .First(); |
| | | } |
| | | catch |
| | | { |
| | | throw new Exception("此条码找不到对应收货单明细!"); |
| | | } |
| | | |
| | | MesRohInData cgddDetails; |
| | | try |
| | | { |
| | | cgddDetails = Db.Queryable<MesRohInData>() |
| | | var cgddDetails = Db.Queryable<MesRohInData>() |
| | | .Where(it => it.EbelnK3id == inventoryDetails.LineK3id) |
| | | .First(); |
| | | } |
| | | catch |
| | | { |
| | | |
| | | if (cgddDetails == null) |
| | | throw new Exception("此条码找不到对应采购订单明细!"); |
| | | } |
| | | |
| | | if (inventoryDetails == null) |
| | | throw new Exception("此条码找不到对应收货单明细!"); |
| | | |
| | | //获取到货检验明细 |
| | | var sqlParams = new List<SugarParameter> { new("@dhmxGuid", itemBarcodeDetails.AboutGuid) }; |
| | | var sql1 = @"SELECT *FROM v_dhmx WHERE dhmxGuid = @dhmxGuid "; |
| | | vDhmx dhjymx; |
| | | try |
| | | { |
| | | dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First(); |
| | | } |
| | | catch |
| | | { |
| | | throw new Exception("该条码找不到对应的检验明细!"); |
| | | } |
| | | |
| | | var dhjymx = Db.Ado.SqlQuery<vDhmx>(sql1, sqlParams).First(); |
| | | //判定检验能否入库 |
| | | if (dhjymx.CanStore!= 1) |
| | | { |
| | | throw new Exception($"该条码对应的收料单检验结果:【{dhjymx.InspectionResult}】,判定结果:【{dhjymx.JudgmentResult}】,处理意见:【{dhjymx.HandlingSuggestion}】,无法入库"); |
| | | } |
| | | |
| | | string depotCode; |
| | | try |
| | | { |
| | | depotCode = Db.Queryable<MesDepotSections>() |
| | | var depotCode = Db.Queryable<MesDepotSections>() |
| | | .Where(it => it.DepotSectionCode == sectionCode) |
| | | .Select(it => it.DepotGuid) |
| | | .First(); |
| | | } |
| | | catch |
| | | { |
| | | throw new Exception("库位编码 " + sectionCode + " 不存在,请确认!"); |
| | | } |
| | | |
| | | var depotCode2 = Db.Queryable<MesInvItemArn>() |
| | | .Where(it => it.BillNo == itemBarcodeDetails.BillNo) |
| | | .Select(it => it.DepotsId) |
| | | .First(); |
| | | |
| | | MesDepots mesDepost = null; |
| | | |
| | | var checkGuid = UtilityHelper.CheckGuid(depotCode); |
| | | if (checkGuid && depotCode != null) |
| | | { |
| | | try |
| | | { |
| | | mesDepost = Db.Queryable<MesDepots>() |
| | | .Where(s => s.Guid == depotCode).First(); |
| | | } |
| | | catch |
| | | { |
| | | throw new Exception("库位编码 " + sectionCode + " 对应的仓库不存在,请确认!"); |
| | | } |
| | | .Where(s => s.DepotId.ToString() == depotCode).First(); |
| | | |
| | | // if (depotCode != mesDepost.Guid) |
| | | // throw new Exception("扫描库位与采购入库库位不一致!"); |
| | |
| | | billNo: "", // 根据实际单据号传值 |
| | | transactionNo: "101" // 事务类型与存储过程匹配 |
| | | ); |
| | | |
| | | if (checkResult == null) |
| | | throw new Exception("入库校验失败:返回结果为空"); |
| | | |
| | | if (Convert.ToInt32(checkResult.result) < 1) |
| | | throw new Exception($"入库校验失败:{checkResult.strMsg}"); |
| | |
| | | it.Guid, |
| | | it.BillNo |
| | | }) |
| | | .ToList() |
| | | .FirstOrDefault(); |
| | | .First(); |
| | | |
| | | var cId = Guid.Empty; |
| | | string cBillNo = null; |
| | |
| | | cId = Guid.NewGuid(); |
| | | cBillNo = BillNo.GetBillNo("CGRK(采购入库)"); |
| | | |
| | | MesSupplier suppNo; |
| | | try |
| | | { |
| | | suppNo = db.Queryable<MesSupplier>() |
| | | var suppNo = db.Queryable<MesSupplier>() |
| | | .Where(s => s.Id.ToString() == inventory.SuppId).First(); |
| | | } |
| | | catch |
| | | { |
| | | throw new Exception("找不到对应的供应商信息!"); |
| | | } |
| | | |
| | | db.Insertable(new MesInvItemIns |
| | | { |
| | |
| | | }).IgnoreColumns(true).ExecuteCommand(); |
| | | } |
| | | |
| | | cSyQty = itemBarcodeDetails.Quantity ?? 0; |
| | | |
| | | if (cSyQty <= 0) |
| | | throw new Exception("条码数量无效,请检查条码信息!"); |
| | | cSyQty = itemBarcodeDetails.Quantity.Value; |
| | | |
| | | entity.id = cId.ToString(); |
| | | entity.PageIndex = 1; |
| | |
| | | |
| | | return result; |
| | | } |
| | | |
| | | */ |
| | | public ItemInBaseModel getPurchaseInventory(WarehouseQuery query) |
| | | { |
| | | return new ItemInBaseModel |
| | |
| | | |
| | | return encodedUrl; |
| | | } |
| | | |
| | | // 验退扫码 |
| | | public ItemInBaseModel GetReturnBarcodeInfo(WarehouseQuery entity) |
| | | { |
| | | ItemInBaseModel res = new ItemInBaseModel(); |
| | | |
| | | // 参数验证 |
| | | 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.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "条码不允许为空"); |
| | | |
| | | //try |
| | | //{ |
| | | // 检查条码是否已入库 |
| | | var isInStock = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode == entity.returnBarcode) |
| | | .Any(); |
| | | |
| | | if (isInStock) |
| | | throw new Exception($"该条码物料[{entity.returnBarcode}]已入库,不能再次扫描!"); |
| | | |
| | | // 检查条码是否已扫描验退 |
| | | var sqlParams = new List<SugarParameter> { new("@barcode", entity.returnBarcode) }; |
| | | var isReturnScanned = Db.Ado.SqlQuery<dynamic>( |
| | | "SELECT 1 FROM MES_INV_ITEM_CGYT_C_DETAILS WHERE ITEM_BARCODE = @barcode", |
| | | sqlParams); |
| | | |
| | | |
| | | if (isReturnScanned.Count > 0) |
| | | throw new Exception($"该条码物料[{entity.returnBarcode}]已扫描验退,请核对!"); |
| | | // 使用参数化查询并忽略大小写(适用于支持的数据库) |
| | | var itemBarcode = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(it => it.ItemBarcode.Trim().ToLower() == entity.returnBarcode.Trim().ToLower()) |
| | | .First() ?? throw new InvalidOperationException($"未找到条码 '{entity.returnBarcode}' 的匹配信息"); |
| | | |
| | | // 获取到货明细ID(假设从条码信息中可以获取到dhmxGuid) |
| | | var dhmxGuid = itemBarcode.AboutGuid; |
| | | |
| | | // 查询检验信息(对应SQL中的视图查询逻辑) |
| | | var checkParams = new List<SugarParameter> |
| | | { |
| | | new("@dHdMx", dhmxGuid), |
| | | new("@JYZT", null, true), // 输出参数:检验状态 |
| | | new("@JYJG", null, true), // 输出参数:检验结果 |
| | | new("@PDJG", null, true), // 输出参数:判定结果 |
| | | new("@ISRK", null, true), // 输出参数:是否能入库 |
| | | new("@CLYS", null, true) // 输出参数:处理意见 |
| | | }; |
| | | |
| | | // 执行查询获取检验信息 |
| | | Db.Ado.ExecuteCommand(@" |
| | | SELECT @JYZT = ISNULL(检验状态, '未知'), |
| | | @JYJG = ISNULL(检验结果, '未知'), |
| | | @PDJG = ISNULL(判定结果, '未知'), |
| | | @ISRK = ISNULL(是否能入库, 0), |
| | | @CLYS = ISNULL(处理意见, '无') |
| | | FROM v_dhmx |
| | | WHERE dhmxGuid = @dHdMx", checkParams); |
| | | |
| | | // 解析输出参数 |
| | | var jyzt = checkParams[1].Value?.ToString() ?? "未知"; |
| | | var jyjg = checkParams[2].Value?.ToString() ?? "未知"; |
| | | var pdjg = checkParams[3].Value?.ToString() ?? "未知"; |
| | | var isRk = checkParams[4].Value != DBNull.Value ? Convert.ToInt32(checkParams[4].Value) : 0; |
| | | var clys = checkParams[5].Value?.ToString() ?? "无"; |
| | | |
| | | // 检查是否查询到检验记录 |
| | | if (string.IsNullOrEmpty(jyzt) && string.IsNullOrEmpty(jyjg)) |
| | | throw new Exception($"未找到到货明细id为[{dhmxGuid}]的检验记录"); |
| | | // 检查是否允许验退(异常直接抛出) |
| | | if (isRk != 1) |
| | | throw new Exception($"该条码对应的收料单检验结果:[{jyjg}],判定结果:[{pdjg}],处理意见:[{clys}],不能进行验退操作"); |
| | | |
| | | |
| | | |
| | | |
| | | // 将查询到的条码信息赋值给返回模型 |
| | | res.itemBarcodeDetails = itemBarcode; |
| | | res.Message = "查询成功"; |
| | | return res; |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // // 记录异常日志(建议补充具体日志记录代码) |
| | | // res.Message = $"操作失败: {ex.Message}"; |
| | | // res.SumQuantity = -1; |
| | | // return res; |
| | | //} |
| | | } |
| | | |
| | | // 验退 |
| | | public ItemInBaseModel ConfirmReturn(WarehouseQuery entity) |
| | | { |
| | | ItemInBaseModel res = new ItemInBaseModel(); |
| | | |
| | | // 参数验证 |
| | | 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.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "条码不允许为空"); |
| | | if (entity.returnQuantity <= 0) throw new ArgumentException("验退数量必须大于0", nameof(entity.returnQuantity)); |
| | | |
| | | //try |
| | | //{ |
| | | // 检查条码是否已入库 |
| | | var isInStock = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode == entity.returnBarcode) |
| | | .Any(); |
| | | |
| | | if (isInStock) |
| | | throw new Exception($"该条码物料[{entity.returnBarcode}]已入库,不能再次扫描!"); |
| | | |
| | | // 检查条码是否已扫描验退 |
| | | var sqlParams = new List<SugarParameter> { new("@barcode", entity.returnBarcode) }; |
| | | var isReturnScanned = Db.Ado.SqlQuery<dynamic>( |
| | | "SELECT 1 FROM MES_INV_ITEM_CGYT_C_DETAILS WHERE ITEM_BARCODE = @barcode", |
| | | sqlParams); |
| | | |
| | | // 使用参数化查询并忽略大小写(适用于支持的数据库) |
| | | var itemBarcode = Db.Queryable<MesInvItemBarcodes>() |
| | | .Where(it => it.ItemBarcode.Trim().ToLower() == entity.returnBarcode.Trim().ToLower()) |
| | | .First() ?? throw new InvalidOperationException($"未找到条码 '{entity.returnBarcode}' 的匹配信息"); |
| | | |
| | | // 判断验退数量是否大于条码的数量(假设条码数量字段为Quantity) |
| | | if (entity.returnQuantity > itemBarcode.Quantity) |
| | | { |
| | | throw new ArgumentException($"验退数量不能大于条码的数量,当前条码数量为: {itemBarcode.Quantity}", nameof(entity.returnQuantity)); |
| | | } |
| | | // 将查询到的条码信息赋值给返回模型 |
| | | res.itemBarcodeDetails = itemBarcode; |
| | | |
| | | // 调用存储过程 prc_pda_bar_cf_before |
| | | string strMsg = ""; |
| | | string intSum = ""; |
| | | string cfBar = ""; |
| | | |
| | | using (var conn = new SqlConnection(DB.DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("[prc_pda_bar_cf_before]", conn)) |
| | | { |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | SqlParameter[] parameters = |
| | | { |
| | | new("@outMsg", SqlDbType.NVarChar, 300), |
| | | new("@outSum", SqlDbType.NVarChar, 300), |
| | | new("@barcode_new", SqlDbType.NVarChar, 300), |
| | | new("@c_user", entity.userName), |
| | | new("@p_old_barcode", entity.returnBarcode), |
| | | new("@p_qty", entity.returnQuantity), |
| | | }; |
| | | parameters[0].Direction = ParameterDirection.Output; |
| | | parameters[1].Direction = ParameterDirection.Output; |
| | | parameters[2].Direction = ParameterDirection.Output; |
| | | |
| | | foreach (var parameter in parameters) |
| | | cmd.Parameters.Add(parameter); |
| | | cmd.ExecuteNonQuery(); |
| | | strMsg = parameters[0].Value.ToString(); |
| | | intSum = parameters[1].Value.ToString(); |
| | | cfBar = parameters[2].Value.ToString(); |
| | | |
| | | var result = Convert.ToInt32(intSum); |
| | | if (result <= 0) throw new Exception(strMsg); |
| | | } |
| | | } |
| | | |
| | | // 调用验退存储过程 prc_pda_scan_CGYT,使用拆分后的新条码 |
| | | string ytMsg = ""; |
| | | string ytSum = ""; |
| | | string ytdh = ""; |
| | | |
| | | using (var conn = new SqlConnection(DB.DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("prc_pda_scan_CGYT", conn)) |
| | | { |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | SqlParameter[] ytParameters = |
| | | { |
| | | new("@pi_user", SqlDbType.NVarChar, 100) { Value = entity.userName }, |
| | | new("@pi_barcode", SqlDbType.NVarChar, 100) { Value = cfBar }, // 使用拆分后的新条码 |
| | | new("@po_outMsg", SqlDbType.NVarChar, 2000) { Direction = ParameterDirection.Output }, |
| | | new("@po_outSum", SqlDbType.Int) { Direction = ParameterDirection.Output }, |
| | | new("@po_ygdh", SqlDbType.NVarChar, 200) { Direction = ParameterDirection.Output } |
| | | }; |
| | | |
| | | cmd.Parameters.AddRange(ytParameters); |
| | | cmd.ExecuteNonQuery(); |
| | | |
| | | ytMsg = ytParameters[2].Value.ToString(); |
| | | ytSum = ytParameters[3].Value.ToString(); |
| | | ytdh = ytParameters[4].Value.ToString(); |
| | | |
| | | if (ytSum == "-1") throw new Exception(ytMsg); |
| | | } |
| | | } |
| | | |
| | | // 调用入库存储过程 prc_pda_inv_cgrk,使用原始条码 |
| | | string rkMsg = ""; |
| | | string rkSum = ""; |
| | | |
| | | using (var conn = new SqlConnection(DB.DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("prc_pda_inv_cgrk", conn)) |
| | | { |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | SqlParameter[] rkParameters = |
| | | { |
| | | 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_cgrkType", SqlDbType.NVarChar, 30) { Value = "正常入库" }, |
| | | 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 } |
| | | }; |
| | | |
| | | cmd.Parameters.AddRange(rkParameters); |
| | | cmd.ExecuteNonQuery(); |
| | | |
| | | rkMsg = rkParameters[5].Value.ToString(); |
| | | rkSum = rkParameters[6].Value.ToString(); |
| | | |
| | | if (rkSum == "-1") throw new Exception(rkMsg); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | // 优化查询(去除空格并忽略大小写) |
| | | var mesInvItemInCDetails = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode.Trim().ToLower() == entity.returnBarcode.Trim().ToLower()) |
| | | .First() ?? throw new InvalidOperationException($"未找到条码 '{entity.returnBarcode}' 的匹配的入库信息"); |
| | | |
| | | // 从入库条码中获取有效的ItemInId |
| | | var cId = mesInvItemInCDetails.ItemInId; // 假设存在ItemInId属性 |
| | | |
| | | // 查询物料汇总明细(使用参数化查询防止SQL注入) |
| | | var sql = @" |
| | | 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 = @cId AND a.Item_Id = @itemId"; |
| | | |
| | | res.ItemInDetails = Db.Ado.SqlQuery<dynamic>(sql, new { cId, itemId = itemBarcode.ItemId }); |
| | | |
| | | // 查询入库条码明细(使用参数化查询防止SQL注入) |
| | | var sql2 = @" |
| | | 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 = @cId AND a.Item_Id = @itemId"; |
| | | |
| | | res.ItemBarCDetails = Db.Ado.SqlQuery<dynamic>(sql2, new { cId, itemId = itemBarcode.ItemId }); |
| | | |
| | | |
| | | //查询已入库总数 |
| | | 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) |
| | | //{ |
| | | // // 记录异常日志(建议补充具体日志记录代码) |
| | | // res.Message = $"操作失败: {ex.Message}"; |
| | | // res.SumQuantity = -1; |
| | | // return res; |
| | | //} |
| | | } |
| | | |
| | | } |