| | |
| | | /// 更新机器时间并处理首检 |
| | | /// 变更说明: |
| | | /// 1) 最新首检结果为“不合格”时:只清空 MA_SHOUT_TIME(送检呼叫时间),不重建首检单 |
| | | /// 2) 若不存在首检单或最新首检结果为“不合格”时:允许继续创建(重建)首检单 |
| | | /// 3) 首检合格且送检时间 >= 调机开始时间时:写入调机完成时间与开工时间(沿用原逻辑) |
| | | /// 2) 若不存在首检单时:允许创建(重建)首检单 |
| | | /// 3) 首检合格且送检时间 >= 调机开始时间时:写入调机完成时间与开工时间 |
| | | /// </summary> |
| | | public bool ChangeMachineTime(MesOrderSta entity) |
| | | { |
| | | const string FirstCheckType = "首检"; |
| | | const string FirstCheckResultOK = "合格"; |
| | | const string FirstCheckResultNG = "不合格"; |
| | | |
| | | var womdaa = Db.Queryable<Womdaa>() |
| | | .Where(s => s.Id == entity.OrderId).First(); |
| | | if (womdaa == null) throw new Exception("工单不存在"); |
| | | |
| | | MesQaItemsDetect02 latestFirst = null; |
| | | var clearMaShout = false; // 标记:是否需要清空送检时间 |
| | | |
| | | if (entity.Flag == 1) |
| | | { |
| | |
| | | |
| | | // 当前最新首检 |
| | | latestFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == "首检" && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == FirstCheckType && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .OrderBy(s => s.CreateDate, OrderByType.Desc) |
| | | .First(); |
| | | |
| | | // 不存在 或 最新结果为“不合格” => 允许创建首检单(新增逻辑,保留注释) |
| | | var needCreate = latestFirst == null || latestFirst.FcheckResu == "不合格"; |
| | | // 仅在不存在首检单时创建(原“ 不合适 ”已统一改为“ 不合格 ”,且不合格不再触发重建) |
| | | var needCreate = latestFirst == null; |
| | | |
| | | if (needCreate) |
| | | { |
| | | // 不存在 或 “不合格” => 重新创建首检单 |
| | | Db.Ado.ExecuteCommand( |
| | | "BEGIN AUTOMATIC_IPQC_FIRST_CHECK(:BILL_NO); END;", |
| | | new SugarParameter("BILL_NO", womdaa.Daa001, System.Data.DbType.String)); |
| | | |
| | | // 重新获取最新首检单 |
| | | latestFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == "首检" && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == FirstCheckType && (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 trigger = latestFirst.FcheckResu == "不合格" ? "不合格重建" : "首次创建"; |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}自动创建的首检单({trigger})") |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}自动创建的首检单(首次创建)") |
| | | .Where(s => s.Id == latestFirst.Id) |
| | | .ExecuteCommand(); |
| | | } |
| | |
| | | else |
| | | { |
| | | // 最新结果为“不合格” => 仅清空送检时间,不重建 |
| | | if (latestFirst != null && latestFirst.FcheckResu == "不合格") |
| | | if (latestFirst != null && latestFirst.FcheckResu == FirstCheckResultNG) |
| | | { |
| | | Db.Updateable<MesOrderSta>() |
| | | .SetColumns(s => s.MaShoutTime == null) |
| | | .Where(s => s.Id == entity.Id) |
| | | .ExecuteCommand(); |
| | | |
| | | clearMaShout = true; |
| | | entity.MaShoutTime = null; |
| | | entity.remark = $"最新首检结果“不合格”,已清空送检时间,待再次送检"; |
| | | entity.remark = $"最新首检结果“{FirstCheckResultNG}”,已清空送检时间,待再次送检"; |
| | | } |
| | | else if (latestFirst != null) |
| | | { |
| | | // 其它结果仅更新备注 |
| | | // 其它结果(如合格)更新备注 |
| | | var ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}首检结果:{latestFirst.FcheckResu}") |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | // 记录异常但不阻止流程(保留原注释) |
| | | Console.WriteLine($"发送数据刷新请求时出错: {ex.Message}"); |
| | | } |
| | | |
| | |
| | | Db.Insertable<MesAnchors>(eAnchors).ExecuteCommand(); |
| | | |
| | | // 若送检时间存在且最新首检合格 => 写调机完成与开工时间 |
| | | if (!string.IsNullOrEmpty(entity.MaShoutTime)) |
| | | if (!clearMaShout && !string.IsNullOrEmpty(entity.MaShoutTime)) |
| | | { |
| | | if (DateTime.TryParse(entity.MaShoutTime, out var sjTime) && |
| | | DateTime.TryParse(entity.MaStartTime, out var startTime) && |
| | |
| | | { |
| | | var sjRecord = latestFirst ?? |
| | | Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(x => x.Aufnr == womdaa.Daa001 && x.Ftype == "首检" && (x.Fcancel == null || x.Fcancel != "Y")) |
| | | .Where(x => x.Aufnr == womdaa.Daa001 && x.Ftype == FirstCheckType && (x.Fcancel == null || x.Fcancel != "Y")) |
| | | .OrderBy(x => x.CreateDate, OrderByType.Desc) |
| | | .First(); |
| | | |
| | | if (sjRecord != null && sjRecord.FcheckResu == "合格") |
| | | if (sjRecord != null && sjRecord.FcheckResu == FirstCheckResultOK) |
| | | { |
| | | QualifiedInspection(new OrderMachineDto |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | // 更新工单状态表(保留原注释) |
| | | return Db.Updateable<MesOrderSta>() |
| | | .SetColumnsIF(entity.MaShoutTime != null, s => s.MaShoutTime == entity.MaShoutTime) |
| | | // 更新工单状态表 |
| | | var upd = Db.Updateable<MesOrderSta>() |
| | | .SetColumnsIF(clearMaShout, s => s.MaShoutTime == null) |
| | | .SetColumnsIF(!clearMaShout && entity.MaShoutTime != null, s => s.MaShoutTime == entity.MaShoutTime) |
| | | .SetColumnsIF(entity.MaStartTime != null, s => s.MaStartTime == entity.MaStartTime) |
| | | .SetColumnsIF(entity.MaEndTime != null, s => s.MaEndTime == entity.MaEndTime) |
| | | .SetColumnsIF(entity.StartTime != null, s => s.StartTime == entity.StartTime) |
| | | .SetColumnsIF(entity.Flag == 1 && entity.remark != null, s => s.remark == entity.remark) |
| | | .Where(s => s.Id == entity.Id) |
| | | .ExecuteCommand() > 0; |
| | | .Where(s => s.Id == entity.Id); |
| | | |
| | | return upd.ExecuteCommand() > 0; |
| | | } |
| | | |
| | | /// <summary> |