| | |
| | | /// <summary> |
| | | /// 更新机器时间并处理首检 |
| | | /// 变更说明: |
| | | /// 1) 最新首检结果为“不合格”时:只清空 MA_SHOUT_TIME(送检呼叫时间),不重建首检单 |
| | | /// 2) 若不存在首检单时:允许创建(重建)首检单 |
| | | /// 1) 最新首检结果为“不合格”时:清空 MA_SHOUT_TIME(送检呼叫时间) |
| | | /// 2) 若不存在首检单时或者首检单结果为“不合格”时:创建首检单 |
| | | /// 3) 首检合格且送检时间 >= 调机开始时间时:写入调机完成时间与开工时间 |
| | | /// </summary> |
| | | public bool ChangeMachineTime(MesOrderSta entity) |
| | |
| | | .Where(s => s.Id == entity.OrderId).First(); |
| | | if (womdaa == null) throw new Exception("工单不存在"); |
| | | |
| | | MesQaItemsDetect02 latestFirst = null; |
| | | var clearMaShout = false; |
| | | // 读取当前状态行 |
| | | var currentSta = Db.Queryable<MesOrderSta>() |
| | | .Where(s => s.Id == entity.Id).First(); |
| | | |
| | | // 原来限制 entity.Flag == 1,这里取消限制:任何保存动作都评估首检结果 |
| | | // 行级锁防并发 |
| | | // 行级锁:串行化首检重建 |
| | | Db.Ado.ExecuteCommand("SELECT ID FROM WOMDAA WHERE DAA001 = :BILL_NO FOR UPDATE", |
| | | new SugarParameter("BILL_NO", womdaa.Daa001)); |
| | | |
| | | // 当前最新首检 |
| | | latestFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | // 最新首检 |
| | | var latestFirst = Db.Queryable<MesQaItemsDetect02>() |
| | | .Where(s => s.Aufnr == womdaa.Daa001 && s.Ftype == FirstCheckType && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .OrderBy(s => s.CreateDate, OrderByType.Desc) |
| | | .First(); |
| | | |
| | | // 结果归一(防止尾部空格或大小写):可能来源于接口/用户录入 |
| | | var latestResult = latestFirst?.FcheckResu?.Trim(); |
| | | var needRebuild = latestFirst == null || string.Equals(latestResult, FirstCheckResultNG, StringComparison.OrdinalIgnoreCase); |
| | | var clearMaShout = false; |
| | | |
| | | // 仅在不存在首检单时创建 |
| | | if (latestFirst == null) |
| | | if (needRebuild) |
| | | { |
| | | // 若已有首检且结果不合格 => 先清空送检时间 |
| | | if (latestFirst != null && string.Equals(latestResult, FirstCheckResultNG, StringComparison.OrdinalIgnoreCase)) |
| | | { |
| | | clearMaShout = true; |
| | | entity.MaShoutTime = null; |
| | | entity.remark = $"最新首检结果“{FirstCheckResultNG}”,已清空送检时间并重建首检单"; |
| | | } |
| | | |
| | | // 调用存储过程重建 / 首次创建 |
| | | 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 == FirstCheckType && (s.Fcancel == null || s.Fcancel != "Y")) |
| | | .OrderBy(s => s.CreateDate, OrderByType.Desc) |
| | |
| | | if (latestFirst != null) |
| | | { |
| | | var ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | var remarkTag = latestResult == null ? "首次创建" : (latestResult == FirstCheckResultNG ? "不合格重建" : "重建"); |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}自动创建的首检单(首次创建)") |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}自动创建的首检单({remarkTag})") |
| | | .Where(s => s.Id == latestFirst.Id) |
| | | .ExecuteCommand(); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | // 最新结果为“不合格” => 清空送检时间,不重建 |
| | | if (string.Equals(latestResult, FirstCheckResultNG, StringComparison.OrdinalIgnoreCase)) |
| | | // 不需要重建:如果前端主动清空(传空且原值有内容)也允许清空 |
| | | var requestWantClear = string.IsNullOrEmpty(entity.MaShoutTime) && !string.IsNullOrEmpty(currentSta?.MaShoutTime); |
| | | if (requestWantClear) |
| | | { |
| | | clearMaShout = true; |
| | | entity.MaShoutTime = null; |
| | | entity.remark = $"最新首检结果“{FirstCheckResultNG}”,已清空送检时间,待再次送检"; |
| | | entity.remark = "前端请求手动清空送检时间"; |
| | | } |
| | | else |
| | | { |
| | | // 其它结果更新备注 |
| | | var ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}首检结果:{latestResult}") |
| | | .Where(s => s.Id == latestFirst.Id) |
| | | .ExecuteCommand(); |
| | | // 正常备注(保持最新结果说明) |
| | | if (latestFirst != null) |
| | | { |
| | | var ts = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | Db.Updateable<MesQaItemsDetect02>() |
| | | .SetColumns(s => s.Remeke == $"工控机于{ts}首检结果:{latestFirst.FcheckResu}") |
| | | .Where(s => s.Id == latestFirst.Id) |
| | | .ExecuteCommand(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 后续逻辑保持 |
| | | // 后续报工锚点逻辑保持 |
| | | var mesReporting = Db.Queryable<MesReporting>() |
| | | .Where(s => s.BillNo == womdaa.Daa001) |
| | | .OrderByDescending(s => s.Id) |
| | |
| | | }; |
| | | Db.Insertable<MesAnchors>(eAnchors).ExecuteCommand(); |
| | | |
| | | // 若送检时间存在且最新首检合格 => 写调机完成与开工时间 |
| | | // 合格 & 调机逻辑 |
| | | if (!clearMaShout && !string.IsNullOrEmpty(entity.MaShoutTime)) |
| | | { |
| | | if (DateTime.TryParse(entity.MaShoutTime, out var sjTime) && |
| | |
| | | } |
| | | } |
| | | |
| | | // 最终更新(优先清空) |
| | | var upd = Db.Updateable<MesOrderSta>() |
| | | .SetColumnsIF(clearMaShout, s => s.MaShoutTime == null) |
| | | .SetColumnsIF(!clearMaShout && entity.MaShoutTime != null, s => s.MaShoutTime == entity.MaShoutTime) |