| | |
| | | using MES.Service.DB; |
| | | using MES.Service.Modes; |
| | | using MES.Service.Dto.webApi; |
| | | using System.Data; |
| | | |
| | | namespace MES.Service.service |
| | | { |
| | |
| | | var orUpdate = base.Insert(mesReturnware); |
| | | var baOrUpdate = ReturnwareDetailsManager.InsertRange(mesReturnwareDetails); |
| | | |
| | | if (orUpdate && baOrUpdate) return true; |
| | | if (orUpdate && baOrUpdate) |
| | | { |
| | | // 保存成功后,调用存储过程生成检验单 |
| | | GenerateInspectionOrder(db, mesReturnware, mesReturnwareDetails); |
| | | return true; |
| | | } |
| | | throw new NotImplementedException("插入或更新失败"); |
| | | |
| | | |
| | |
| | | var insertOrUpdate = db.Deleteable<MesReturnwareDetails>().Where(it => mesReturnwareDetail.Any(p => p.ReturnwareNo == it.ReturnNo && p.ReturnwareType == it.ReturnType)).ExecuteCommand() > 0; |
| | | |
| | | |
| | | if (update && insertOrUpdate) return true; |
| | | if (update && insertOrUpdate) |
| | | { |
| | | // 更新成功后,调用存储过程生成检验单 |
| | | GenerateInspectionOrder(db, mesReturnware, mesReturnwareDetails); |
| | | return true; |
| | | } |
| | | throw new NotImplementedException("更新失败"); |
| | | } |
| | | |
| | |
| | | |
| | | public bool Delete(YFDelete data) |
| | | { |
| | | |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | var update = db.Deleteable<MesReturnware>() |
| | | .Where(it => it.ReturnNo == data.FBillNo && |
| | | it.ReturnType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | var insertOrUpdate = db.Deleteable<MesReturnwareDetails>() |
| | | // 先删除退货通知单明细 |
| | | var detailsDeleted = db.Deleteable<MesReturnwareDetails>() |
| | | .Where(it => it.ReturnNo == data.FBillNo && |
| | | it.ReturnType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | // 再删除退货通知单主表 |
| | | var mainDeleted = db.Deleteable<MesReturnware>() |
| | | .Where(it => it.ReturnNo == data.FBillNo && |
| | | it.ReturnType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | |
| | | if (update && insertOrUpdate) return 1; |
| | | if (detailsDeleted && mainDeleted) |
| | | { |
| | | // 删除成功后,调用存储过程删除对应的检验单 |
| | | DeleteInspectionOrder(db, data.FBillTypeID, data.FBillNo); |
| | | return 1; |
| | | } |
| | | |
| | | throw new NotImplementedException("删除失败"); |
| | | }) > 0; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调用存储过程生成检验单 |
| | | /// </summary> |
| | | /// <param name="mesReturnware">退货通知单主表</param> |
| | | /// <param name="mesReturnwareDetails">退货通知单明细表</param> |
| | | private void GenerateInspectionOrder(SqlSugarScope db, MesReturnware mesReturnware, List<MesReturnwareDetails> mesReturnwareDetails) |
| | | { |
| | | try |
| | | { |
| | | // 定义输入参数 |
| | | var inputParam1 = new SugarParameter("P_RETURN_TYPE", mesReturnware.ReturnType ?? ""); |
| | | var inputParam2 = new SugarParameter("P_RETURN_NO", mesReturnware.ReturnNo ?? ""); |
| | | |
| | | // 定义输出参数 |
| | | var outParam1 = new SugarParameter("P_RESULT", null, true); |
| | | var outParam2 = new SugarParameter("P_MESSAGE", null, true); |
| | | |
| | | // 使用 SqlSugar 执行存储过程 |
| | | db.Ado.ExecuteCommand("BEGIN SP_GEN_RETURN_INSP(:P_RETURN_TYPE,:P_RETURN_NO,:P_RESULT,:P_MESSAGE); END;", |
| | | inputParam1, inputParam2, outParam1, outParam2); |
| | | |
| | | // 获取输出参数的值 |
| | | int result = int.Parse((string)outParam1.Value); |
| | | string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value; |
| | | |
| | | if (result != 1) |
| | | { |
| | | // 记录警告日志,但不影响退货通知单的保存 |
| | | Console.WriteLine($"生成检验单警告: {message}"); |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine($"生成检验单成功: {message}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录错误日志,但不影响退货通知单的保存 |
| | | Console.WriteLine($"生成检验单时发生错误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调用存储过程删除检验单 |
| | | /// </summary> |
| | | /// <param name="db">数据库连接</param> |
| | | /// <param name="returnType">退货单别</param> |
| | | /// <param name="returnNo">退货单号</param> |
| | | private void DeleteInspectionOrder(SqlSugarScope db, string returnType, string returnNo) |
| | | { |
| | | try |
| | | { |
| | | // 定义输入参数 |
| | | var inputParam1 = new SugarParameter("P_RETURN_TYPE", returnType ?? ""); |
| | | var inputParam2 = new SugarParameter("P_RETURN_NO", returnNo ?? ""); |
| | | |
| | | // 定义输出参数 |
| | | var outParam1 = new SugarParameter("P_RESULT", null, true); |
| | | var outParam2 = new SugarParameter("P_MESSAGE", null, true); |
| | | |
| | | // 使用 SqlSugar 执行存储过程 |
| | | db.Ado.ExecuteCommand("BEGIN SP_DEL_RETURN_INSP(:P_RETURN_TYPE,:P_RETURN_NO,:P_RESULT,:P_MESSAGE); END;", |
| | | inputParam1, inputParam2, outParam1, outParam2); |
| | | |
| | | // 获取输出参数的值 |
| | | int result = int.Parse((string)outParam1.Value); |
| | | string message = outParam2.Value == DBNull.Value ? string.Empty : (string)outParam2.Value; |
| | | |
| | | if (result != 1) |
| | | { |
| | | // 记录警告日志,但不影响退货通知单的删除 |
| | | Console.WriteLine($"删除检验单警告: {message}"); |
| | | } |
| | | else |
| | | { |
| | | Console.WriteLine($"删除检验单成功: {message}"); |
| | | } |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录错误日志,但不影响退货通知单的删除 |
| | | Console.WriteLine($"删除检验单时发生错误: {ex.Message}"); |
| | | } |
| | | } |
| | | |
| | | |