| | |
| | | using Masuit.Tools.Models; |
| | | using Microsoft.AspNetCore.SignalR.Protocol; |
| | | using NewPdaSqlServer.DB; |
| | | using NewPdaSqlServer.Dto.service; |
| | | using NewPdaSqlServer.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), "条码不允许为空"); |
| | | |
| | | |
| | | using (var conn = new SqlConnection(connectionString)) |
| | | { |
| | | using (var cmd = new SqlCommand("[prc_pda_inv_cgrk]", conn)) |
| | | { |
| | | try |
| | | { |
| | | //try |
| | | //{ |
| | | conn.Open(); |
| | | cmd.CommandType = CommandType.StoredProcedure; |
| | | |
| | |
| | | string? outMessage = parameters[4].Value?.ToString(); |
| | | string? outSum = parameters[5].Value?.ToString(); |
| | | |
| | | |
| | | // 检查参数是否为空,并在异常中显示实际值 |
| | | if (string.IsNullOrEmpty(outMessage) || string.IsNullOrEmpty(outSum)) |
| | | throw new InvalidOperationException("存储过程返回参数异常"); |
| | | { |
| | | // 拼接参数实际值(处理 null 的情况) |
| | | string messageValue = outMessage ?? "null"; |
| | | string sumValue = outSum ?? "null"; |
| | | throw new InvalidOperationException( |
| | | $"存储过程返回参数异常:输出消息为【{messageValue}】,输出数量为【{sumValue}】" |
| | | ); |
| | | } |
| | | |
| | | // 验证结果 |
| | | if (!int.TryParse(outSum, out int result) || result <= 0) |
| | |
| | | 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; |
| | | res.SumQuantity = result; |
| | | |
| | | |
| | | return res; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | |
| | | |
| | | // 记录异常日志(建议添加日志记录) |
| | | res.Message = $"操作失败: {ex.Message}"; |
| | | res.SumQuantity = -1; |
| | | return res; |
| | | } |
| | | // // 记录异常日志(建议添加日志记录) |
| | | // res.Message = $"操作失败: {ex.Message}"; |
| | | // res.SumQuantity = -1; |
| | | // return res; |
| | | //} |
| | | } |
| | | } |
| | | } |
| | |
| | | if (string.IsNullOrEmpty(entity.sectionCode)) throw new ArgumentNullException(nameof(entity.sectionCode), "库位编号不允许为空"); |
| | | if (string.IsNullOrEmpty(entity.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "条码不允许为空"); |
| | | |
| | | try |
| | | { |
| | | //try |
| | | //{ |
| | | // 检查条码是否已入库 |
| | | var isInStock = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode == entity.returnBarcode) |
| | |
| | | .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; |
| | | } |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // // 记录异常日志(建议补充具体日志记录代码) |
| | | // res.Message = $"操作失败: {ex.Message}"; |
| | | // res.SumQuantity = -1; |
| | | // return res; |
| | | //} |
| | | } |
| | | |
| | | // 验退 |
| | |
| | | if (string.IsNullOrEmpty(entity.returnBarcode)) throw new ArgumentNullException(nameof(entity.returnBarcode), "条码不允许为空"); |
| | | if (entity.returnQuantity <= 0) throw new ArgumentException("验退数量必须大于0", nameof(entity.returnQuantity)); |
| | | |
| | | try |
| | | { |
| | | //try |
| | | //{ |
| | | // 检查条码是否已入库 |
| | | var isInStock = Db.Queryable<MesInvItemInCDetails>() |
| | | .Where(it => it.ItemBarcode == entity.returnBarcode) |
| | |
| | | string strMsg = ""; |
| | | string intSum = ""; |
| | | string cfBar = ""; |
| | | |
| | | |
| | | using (var conn = new SqlConnection(DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("[prc_pda_bar_cf_before]", conn)) |
| | |
| | | string ytMsg = ""; |
| | | string ytSum = ""; |
| | | string ytdh = ""; |
| | | |
| | | |
| | | using (var conn = new SqlConnection(DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("prc_pda_scan_CGYT", conn)) |
| | |
| | | |
| | | cmd.Parameters.AddRange(ytParameters); |
| | | cmd.ExecuteNonQuery(); |
| | | |
| | | |
| | | ytMsg = ytParameters[2].Value.ToString(); |
| | | ytSum = ytParameters[3].Value.ToString(); |
| | | ytdh = ytParameters[4].Value.ToString(); |
| | |
| | | // 调用入库存储过程 prc_pda_inv_cgrk,使用原始条码 |
| | | string rkMsg = ""; |
| | | string rkSum = ""; |
| | | |
| | | |
| | | using (var conn = new SqlConnection(DbHelperSQL.strConn)) |
| | | { |
| | | using (var cmd = new SqlCommand("prc_pda_inv_cgrk", conn)) |
| | |
| | | |
| | | cmd.Parameters.AddRange(rkParameters); |
| | | cmd.ExecuteNonQuery(); |
| | | |
| | | rkMsg = rkParameters[3].Value.ToString(); |
| | | rkSum = rkParameters[4].Value.ToString(); |
| | | |
| | | rkMsg = rkParameters[4].Value.ToString(); |
| | | rkSum = rkParameters[5].Value.ToString(); |
| | | |
| | | if (rkSum == "-1") throw new Exception(rkMsg); |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | // 优化查询(去除空格并忽略大小写) |
| | | var mesInvItemInCDetails = Db.Queryable<MesInvItemInCDetails>() |
| | |
| | | |
| | | 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) |
| | | { |
| | | // 记录异常日志(建议补充具体日志记录代码) |
| | | res.Message = $"操作失败: {ex.Message}"; |
| | | res.SumQuantity = -1; |
| | | return res; |
| | | } |
| | | //} |
| | | //catch (Exception ex) |
| | | //{ |
| | | // // 记录异常日志(建议补充具体日志记录代码) |
| | | // res.Message = $"操作失败: {ex.Message}"; |
| | | // res.SumQuantity = -1; |
| | | // return res; |
| | | //} |
| | | } |
| | | |
| | | } |