From 006c12987d7dc7c2081fbf6715ebea98b93fdca0 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期日, 08 十二月 2024 17:04:32 +0800 Subject: [PATCH] 增加工单批次缓存,不良代码缓存,岗位缓存 --- Tiger.Business.MES/Common/WoContext.cs | 84 +++++++++++++++++++++++++++++++++++------- 1 files changed, 70 insertions(+), 14 deletions(-) diff --git a/Tiger.Business.MES/Common/WoContext.cs b/Tiger.Business.MES/Common/WoContext.cs index be617d9..4592e38 100644 --- a/Tiger.Business.MES/Common/WoContext.cs +++ b/Tiger.Business.MES/Common/WoContext.cs @@ -10,20 +10,20 @@ using Tiger.IBusiness; using Tiger.Model; using Tiger.Model.Entitys.MES.Position; -using static Tiger.Business.Biz; namespace Tiger.Business { /// <summary> /// 宸ュ崟 涓婁笅鏂� /// </summary> - public class WoContext + public class WoContext : IWoContext { #region 宸ュ崟绠$悊 /// <summary> - /// + /// 宸ュ崟鎵规缂撳瓨瀛楀吀 /// </summary> public static Dictionary<string, WorkBatch> WoBatchDic { get; set; } = new Dictionary<string, WorkBatch>(); + public Dictionary<string, IWorkBatch> GetWoBatchDic() => WoBatchDic.ToDictionary(k => k.Key, v => v.Value as IWorkBatch); /// <summary> /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鑾峰彇涓�涓伐鍗曟壒娆″璞� @@ -35,7 +35,7 @@ { if (ExistsBatch(workorder, lineCode, batchNo)) { - return WoBatchDic.WhereIF(canDoWork, q => q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) + return WoBatchDic.WhereIF(canDoWork, q => q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch?.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) .FirstOrDefault(q => !q.Value.Batch.IsNullOrEmpty() && q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)).Value; } return null; @@ -52,15 +52,56 @@ public static bool ExistsBatch(string workorder, string lineCode, string batchNo = "", bool canDoWork = false) { return WoBatchDic.WhereIF(canDoWork, q => !q.Value.Batch.IsNullOrEmpty() && (q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() || q.Value.Batch.STATUS == BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())) - .Any(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch.BATCH_NO == batchNo)); + .Any(q => q.Value.Batch?.ORDER_NO == workorder && q.Value.Batch?.ACT_LINE == lineCode && (batchNo.IsNullOrEmpty() || q.Value.Batch?.BATCH_NO == batchNo)); } - /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// 鏍规嵁宸ュ崟鍙凤紝澧炲姞涓�涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� /// </summary> - /// <param name="batchNo"></param> + /// <param name="workorder"></param> + /// <returns></returns> + public static WorkBatch Add(string workorder) + { + var wb = new WorkBatch(workorder).Init(""); + WoBatchDic.Add(workorder, wb); + return wb; + } + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> /// <param name="lineCode"></param> /// <returns></returns> - public static bool RemoveWo(string workorder) + public static WorkBatch Add(string workorder, string linecode) + { + var wb = new WorkBatch(workorder).Init(linecode); + WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + return wb; + } + + /// 鏍规嵁宸ュ崟鍙凤紝澧炲姞涓�涓伐鍗曞璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public IWorkBatch AddWo(string workorder) + { + return Add(workorder); + } + + /// 鏍规嵁宸ュ崟鍙峰拰浜х嚎锛屽鍔犱竴涓伐鍗曟壒娆″璞″埌宸ュ崟鎵规瀛楀吀涓� + /// </summary> + /// <param name="workorder"></param> + /// <param name="lineCode"></param> + /// <returns></returns> + public IWorkBatch AddBatch(string workorder, string linecode) + { + return Add(workorder, linecode); + } + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曠殑鎵�鏈夋壒娆″璞� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public static bool RemoveAll(string workorder) { try { @@ -78,12 +119,20 @@ } } + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曠殑鎵�鏈夋壒娆″璞� + /// </summary> + /// <param name="workorder"></param> + /// <returns></returns> + public bool RemoveWo(string workorder) + { + return RemoveAll(workorder); + } + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� /// </summary> /// <param name="batchNo"></param> - /// <param name="lineCode"></param> /// <returns></returns> - public static bool RemoveBatch(string batchNo) + public static bool Remove(string batchNo) { try { @@ -98,6 +147,15 @@ Logger.Default.Fatal(ex, $"浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆{batchNo}]瀵硅薄寮傚父"); return false; } + } + + /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞� + /// </summary> + /// <param name="batchNo"></param> + /// <returns></returns> + public bool RemoveBatch(string batchNo) + { + return Remove(batchNo); } /// <summary> @@ -148,8 +206,7 @@ { if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) { - var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); - WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + Add(wipSNs.First().WORK_ORDER); } var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; action.Data = wo.GetNextNodes(wipSNs.First()); @@ -209,8 +266,7 @@ { if (!WoBatchDic.Any(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER)) { - var wb = new WorkBatch(wipSNs.First().WORK_ORDER).Init(""); - WoBatchDic.Add(wipSNs.First().BATCH_NO, wb); + Add(wipSNs.First().WORK_ORDER); } var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value; action.Data = new() -- Gitblit v1.9.3