| | |
| | | /// <returns>更新是否成功</returns> |
| | | public bool ChangeMachineTime(MesOrderSta entity) |
| | | { |
| | | // 查询工单主表信息 |
| | | var womdaa = Db.Queryable<Womdaa>() |
| | | .Where(s => s.Id == entity.OrderId).First(); |
| | | if (womdaa == null) throw new Exception("工单不存在"); |
| | | |
| | | // 如果标记为1,需要处理首检相关逻辑 |
| | | if (entity.Flag == 1) |
| | | { |
| | | //调用存储过程执行自动首检 |
| | | Db.Ado.ExecuteCommand( |
| | | "BEGIN AUTOMATIC_IPQC_FIRST_CHECK(:BILL_NO); END;", |
| | | new SugarParameter("BILL_NO", womdaa.Daa001, System.Data.DbType.String)); |
| | | var automaticIpqcFirstCheck = |
| | | mesQaItemsDetect02Manager |
| | | .AutomaticIpqcFirstCheck(womdaa.Daa001); |
| | | if (!automaticIpqcFirstCheck) |
| | | // 幂等:先查是否已有首检 |
| | | var existsFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == "首检" && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .Any(); |
| | | |
| | | if (!existsFirst) |
| | | { |
| | | Console.WriteLine($"自动首检失败,工单号:{womdaa.Daa001}"); |
| | | throw new Exception("首检生成失败"); |
| | | // 行级锁防并发:锁工单行 |
| | | Db.Ado.ExecuteCommand("SELECT ID FROM WOMDAA WHERE DAA001 = :BILL_NO FOR UPDATE", |
| | | new SugarParameter("BILL_NO", womdaa.Daa001)); |
| | | |
| | | // 再次确认 |
| | | existsFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == "首检" && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .Any(); |
| | | |
| | | if (!existsFirst) |
| | | { |
| | | // 调用存储过程(单路径) |
| | | Db.Ado.ExecuteCommand( |
| | | "BEGIN AUTOMATIC_IPQC_FIRST_CHECK(:BILL_NO); END;", |
| | | new SugarParameter("BILL_NO", womdaa.Daa001, System.Data.DbType.String)); |
| | | } |
| | | } |
| | | |
| | | // 获取当前时间 |
| | | var s1 = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | // 生成首检备注信息 |
| | | var remeke = "工控机于" + s1 + "自动创建的首检单"; |
| | | |
| | | // 更新首检单备注信息 |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == remeke) |
| | | .Where(s => s.Ftype == "首检" && s.Aufnr == womdaa.Daa001) |
| | | .ExecuteCommand(); |
| | | // 统一更新最新首检备注 |
| | | var latestFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == "首检" && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .OrderBy(s => s.CreateDate, OrderByType.Desc) |
| | | .First(); |
| | | if (latestFirst != null) |
| | | { |
| | | var ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | var remark = $"工控机于{ts}自动创建的首检单"; |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == remark) |
| | | .Where(s => s.Id == latestFirst.Id) |
| | | .ExecuteCommand(); |
| | | } |
| | | } |
| | | |
| | | // 原逻辑保持... |
| | | var mesReporting = Db.Queryable<MesReporting>() |
| | | .Where(s => s.BillNo == womdaa.Daa001) |
| | | .OrderByDescending(s => s.Id) |