| | |
| | | |
| | | private readonly WomcabManager _womcabManager = new(); |
| | | |
| | | /// <summary> |
| | | /// 验证BOM是否为空 |
| | | /// </summary> |
| | | /// <param name="erpCabs">BOM明细列表</param> |
| | | /// <param name="billNo">生产任务单号</param> |
| | | /// <exception cref="Exception">当BOM为空时抛出异常</exception> |
| | | private void ValidateBomNotEmpty(List<ErpCAB> erpCabs, string billNo) |
| | | { |
| | | if (erpCabs == null || erpCabs.Count == 0) |
| | | { |
| | | throw new Exception($"生产任务单 {billNo} 的BOM为空,不允许推送到MES系统"); |
| | | } |
| | | |
| | | // 检查是否有有效的BOM明细(物料编码不为空且需领用量大于0) |
| | | var validBomItems = erpCabs.Where(cab => |
| | | !string.IsNullOrWhiteSpace(cab.FMaterialID2) && |
| | | !string.IsNullOrWhiteSpace(cab.FNeedQty2) && |
| | | decimal.TryParse(cab.FNeedQty2, out decimal qty) && qty > 0).ToList(); |
| | | |
| | | if (validBomItems.Count == 0) |
| | | { |
| | | throw new Exception($"生产任务单 {billNo} 的BOM明细无效(物料编码为空或需领用量为0),不允许推送到MES系统"); |
| | | } |
| | | } |
| | | |
| | | public bool SaveList(List<ErpWOM> rohIns) |
| | | { |
| | | var result = rohIns.Select(Save).ToList(); |
| | |
| | | |
| | | public bool Save(ErpWOM wom) |
| | | { |
| | | var womErpCaa = wom.ErpCaa; |
| | | var womErpCaa = wom. ErpCaa; |
| | | var mesWomcaa = MapErpCAAtoWomcaa(womErpCaa); |
| | | var mesWomcabs = MapErpCABtoWomcab(wom.ErpCabs); |
| | | |
| | | // 验证BOM是否为空 |
| | | ValidateBomNotEmpty(wom.ErpCabs, womErpCaa.FBillNo); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | |
| | | |
| | | public bool Delete(YFDelete data) |
| | | { |
| | | if (data == null) |
| | | throw new ArgumentNullException(nameof(data)); |
| | | |
| | | if (string.IsNullOrWhiteSpace(data.FBillNo)) |
| | | throw new ArgumentException("FBillNo 不能为空", nameof(data.FBillNo)); |
| | | |
| | | if (string.IsNullOrWhiteSpace(data.FBillTypeID)) |
| | | throw new ArgumentException("FBillTypeID 不能为空", nameof(data.FBillTypeID)); |
| | | |
| | | return UseTransaction(db => |
| | | { |
| | | var update = db.Deleteable<Womcaa>() |
| | | .Where(it => it.Caa001 == data.FBillNo && |
| | | it.SrcBillType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | // 删除主表数据 |
| | | var deleteMain = db.Deleteable<Womcaa>() |
| | | .Where(it => it.Caa001 == data.FBillNo && it.SrcBillType == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | var insertOrUpdate = db.Deleteable<Womcab>() |
| | | .Where(it => it.Cab001 == data.FBillNo && |
| | | it.Cab002 == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | // 删除子表数据 |
| | | var deleteDetail = db.Deleteable<Womcab>() |
| | | .Where(it => it.Cab001 == data.FBillNo && it.Cab002 == data.FBillTypeID) |
| | | .ExecuteCommand() > 0; |
| | | |
| | | if (!deleteMain || !deleteDetail) |
| | | throw new Exception("删除失败:主表或子表记录不存在"); |
| | | |
| | | // 调用存储过程进行后续处理 |
| | | var inputParam1 = new SugarParameter("P_WORK_NO", data.FBillNo); |
| | | var inputParam2 = new SugarParameter("P_WORK_TYPE", data.FBillTypeID); |
| | | var outParam1 = new SugarParameter("C_RESULT", null, true); // 输出参数 |
| | | var outParam2 = new SugarParameter("C_MSG", null, true); // 输出参数 |
| | | |
| | | if (update && insertOrUpdate) return 1; |
| | | throw new NotImplementedException("删除失败"); |
| | | db.Ado.ExecuteCommand( |
| | | "BEGIN PRC_DELETE_DAA(:P_WORK_NO, :P_WORK_TYPE, :C_RESULT, :C_MSG); 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) |
| | | { |
| | | //存储过程失败则事务进行回滚 |
| | | db.Ado.RollbackTran(); |
| | | throw new Exception(message); |
| | | |
| | | } |
| | | |
| | | return 1; |
| | | }) > 0; |
| | | |
| | | |
| | | } |
| | | |
| | | |