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 |   89 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 74 insertions(+), 15 deletions(-)

diff --git a/Tiger.Business.MES/Common/WoContext.cs b/Tiger.Business.MES/Common/WoContext.cs
index fda4192..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>
         /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鑾峰彇涓�涓伐鍗曟壒娆″璞�
@@ -31,11 +31,12 @@
         /// <param name="workorder"></param>
         /// <param name="lineCode"></param>
         /// <returns></returns>
-        public static WorkBatch GetBatch(string workorder, string lineCode, string batchNo = "")
+        public static WorkBatch GetBatch(string workorder, string lineCode, string batchNo = "", bool canDoWork = true)
         {
             if (ExistsBatch(workorder, lineCode, batchNo))
             {
-                return WoBatchDic.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 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;
         }
@@ -51,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
             {
@@ -77,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
             {
@@ -97,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>
@@ -128,6 +187,7 @@
                                 BATCH_NO = woSN.BATCH_NO,
                                 HOLD_FLAG = "N",
                                 FINISHED_FLAG = "N",
+                                UNBIND_FLAG = "N",
                                 INV_FLAG = "N",
                                 DFT_FLAG = "N",
                                 DFT_COUNT = 0,
@@ -146,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());
@@ -188,6 +247,7 @@
                                 BATCH_NO = woSN.BATCH_NO,
                                 HOLD_FLAG = "N",
                                 FINISHED_FLAG = "N",
+                                UNBIND_FLAG = "N",
                                 INV_FLAG = "N",
                                 DFT_FLAG = "N",
                                 DFT_COUNT = 0,
@@ -206,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