From 420ec0dec8cd0c17eb18ce6ecd5d03eed0266541 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期一, 23 九月 2024 01:14:07 +0800
Subject: [PATCH] 优化三码合一行为,增加包装工单首站投入验证行为

---
 Tiger.Business/MES/WoContext.cs |  194 ++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 187 insertions(+), 7 deletions(-)

diff --git a/Tiger.Business/MES/WoContext.cs b/Tiger.Business/MES/WoContext.cs
index feb5542..6829945 100644
--- a/Tiger.Business/MES/WoContext.cs
+++ b/Tiger.Business/MES/WoContext.cs
@@ -1,10 +1,15 @@
 锘縰sing Microsoft.AspNetCore.Http;
+using Rhea.Common;
+using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
+using System.Net.WebSockets;
 using System.Text;
 using System.Threading.Tasks;
 using Tiger.IBusiness;
+using Tiger.Model;
+using Tiger.Model.Entitys.MES.Position;
 using static Tiger.Business.Biz;
 
 namespace Tiger.Business.MES
@@ -16,30 +21,205 @@
     {
         #region 宸ュ崟绠$悊
         /// <summary>
-        /// 宸ュ崟鎵规瀛楀吀
+        /// 
         /// </summary>
         public static Dictionary<string, WorkBatch> WoBatchDic { get; set; } = new Dictionary<string, WorkBatch>();
 
         /// <summary>
         /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鑾峰彇涓�涓伐鍗曟壒娆″璞�
         /// </summary>
-        /// <param name="workOrder"></param>
+        /// <param name="workorder"></param>
         /// <param name="lineCode"></param>
         /// <returns></returns>
-        public static WorkBatch GetBatch(string workOrder, string lineCode)
+        public static WorkBatch GetBatch(string workorder, string lineCode)
         {
-            return WoBatchDic.FirstOrDefault(q => q.Value.Batch.ORDER_NO == workOrder && q.Value.Batch.ACT_LINE == lineCode).Value;
+            if (ExistsBatch(workorder, lineCode))
+            {
+                return WoBatchDic.FirstOrDefault(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode).Value;
+            }
+            return null;
         }
 
         /// <summary>
         /// 鍒ゆ柇宸ュ崟鎵规鏄惁瀛樺湪浜庡伐鍗曟壒娆″瓧鍏镐腑
         /// </summary>
-        /// <param name="workOrder"></param>
+        /// <param name="workorder"></param>
         /// <param name="lineCode"></param>
         /// <returns></returns>
-        public static bool ExistsBatch(string workOrder, string lineCode)
+        public static bool ExistsBatch(string workorder, string lineCode)
         {
-            return WoBatchDic.Any(q => q.Value.Batch.ORDER_NO == workOrder && q.Value.Batch.ACT_LINE == lineCode);
+            return WoBatchDic.Any(q => q.Value.Batch.ORDER_NO == workorder && q.Value.Batch.ACT_LINE == lineCode);
+        }
+
+        /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞�
+        /// </summary>
+        /// <param name="batchNo"></param>
+        /// <param name="lineCode"></param>
+        /// <returns></returns>
+        public static bool RemoveWo(string workorder)
+        {
+            try
+            {
+                var list = WoBatchDic.Keys.ToList().Where(q => q.Contains(workorder));
+                foreach (var batch in list)
+                {
+                    WoBatchDic.Remove(batch);
+                }
+                return true;
+            }
+            catch (Exception ex)
+            {
+                Logger.Default.Fatal(ex, $"浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗昜{workorder}]瀵硅薄寮傚父");
+                return false;
+            }
+        }
+
+        /// 浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆″璞�
+        /// </summary>
+        /// <param name="batchNo"></param>
+        /// <param name="lineCode"></param>
+        /// <returns></returns>
+        public static bool RemoveBatch(string batchNo)
+        {
+            try
+            {
+                if (WoBatchDic.ContainsKey(batchNo))
+                {
+                    WoBatchDic.Remove(batchNo);
+                }
+                return true;
+            }
+            catch (Exception ex)
+            {
+                Logger.Default.Fatal(ex, $"浠庡伐鍗曟壒娆″瓧鍏镐腑鍒犻櫎涓�涓伐鍗曟壒娆{batchNo}]瀵硅薄寮傚父");
+                return false;
+            }
+        }
+
+        /// <summary>
+        /// 鑾峰彇SN鐨勪笅涓�涓伐搴忚妭鐐瑰垪琛�
+        /// </summary>
+        /// <param name="sn"></param>
+        /// <returns></returns>
+        public static ApiAction<List<MES_WO_NODE>> GetSnNextNodes(string sn)
+        {
+            var action = new ApiAction<List<MES_WO_NODE>>(new List<MES_WO_NODE>());
+            try
+            {
+                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => (q.SN == sn || q.FLOW_SN == sn || q.TRAY_SN == sn || q.INNER_SN == sn || q.CARTON_SN == sn || q.PALLET_SN == sn)).ToList();
+                if (wipSNs.IsNullOrEmpty())
+                {
+                    var woSNs = Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => (q.SN == sn || q.TRAY_SN == sn || q.OUTER_SN == sn)).ToList();
+                    //鏌ユ壘鍒版潯鐮佸凡缁戝畾鐨勫伐鍗�
+                    if (!woSNs.IsNullOrEmpty())
+                    {
+                        foreach (var woSN in woSNs)
+                        {
+                            var wipSN = new MES_WIP_DATA()
+                            {
+                                SN = sn,
+                                FLOW_SN = sn,
+                                STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(),
+                                ITEM_CODE = woSN.ITEM_CODE,
+                                WORK_ORDER = woSN.WORK_ORDER,
+                                BATCH_NO = woSN.BATCH_NO,
+                                HOLD_FLAG = "N",
+                                FINISHED_FLAG = "N",
+                                INV_FLAG = "N",
+                                DFT_FLAG = "N",
+                                DFT_COUNT = 0,
+                            };
+                            wipSNs.Add(wipSN);
+                        }
+                    }
+                }
+                if (wipSNs.IsNullOrEmpty())
+                {
+                    action.IsSuccessed = false;
+                    //action.LocaleMsg = new($"鎵句笉鍒版潯鐮乕{sn}]鐨勭敓浜т俊鎭�", sn);
+                    action.LocaleMsg = new("MES.WoContext.SnNotFound", sn);
+                }
+                else
+                {
+                    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);
+                    }
+                    var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value;
+                    action.Data = wo.GetNextNodes(wipSNs.First());
+                }
+            }
+            catch (Exception ex)
+            {
+                //action.CatchExceptionWithLog(ex, $"鑾峰彇鏉$爜[{sn}]鐨勪笅涓�涓伐搴忚妭鐐瑰垪琛ㄥ紓甯�");
+                action.CatchExceptionWithLog(ex, Biz.L("MES.WoContext.GetSnNextNodesException", sn));
+            }
+            return action;
+        }
+
+        /// <summary>
+        /// 璁剧疆褰撳墠鏉$爜鐨勫伐搴忎俊鎭�
+        /// </summary>
+        public static ApiAction<OperInfo> GetSnOperInfo(string sn)
+        {
+            var action = new ApiAction<OperInfo>(new OperInfo());
+            try
+            {
+                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => (q.SN == sn || q.FLOW_SN == sn || q.TRAY_SN == sn || q.INNER_SN == sn || q.CARTON_SN == sn || q.PALLET_SN == sn)).ToList();
+                if (wipSNs.IsNullOrEmpty())
+                {
+                    var woSNs = Biz.Db.Queryable<BIZ_MES_WO_SN>().Where(q => (q.SN == sn || q.TRAY_SN == sn || q.OUTER_SN == sn)).ToList();
+                    //鏌ユ壘鍒版潯鐮佸凡缁戝畾鐨勫伐鍗�
+                    if (!woSNs.IsNullOrEmpty())
+                    {
+                        foreach (var woSN in woSNs)
+                        {
+                            var wipSN = new MES_WIP_DATA()
+                            {
+                                SN = sn,
+                                FLOW_SN = sn,
+                                STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(),
+                                ITEM_CODE = woSN.ITEM_CODE,
+                                WORK_ORDER = woSN.WORK_ORDER,
+                                BATCH_NO = woSN.BATCH_NO,
+                                HOLD_FLAG = "N",
+                                FINISHED_FLAG = "N",
+                                INV_FLAG = "N",
+                                DFT_FLAG = "N",
+                                DFT_COUNT = 0,
+                            };
+                            wipSNs.Add(wipSN);
+                        }
+                    }
+                }
+                if (wipSNs.IsNullOrEmpty())
+                {
+                    action.IsSuccessed = false;
+                    //action.LocaleMsg = new($"鎵句笉鍒版潯鐮乕{sn}]鐨勭敓浜т俊鎭�", sn);
+                    action.LocaleMsg = new("MES.WoContext.SnNotFound", sn);
+                }
+                else
+                {
+                    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);
+                    }
+                    var wo = WoBatchDic.FirstOrDefault(q => q.Value.WO.ORDER_NO == wipSNs.First().WORK_ORDER).Value;
+                    action.Data = new()
+                    {
+                        CurNode = wipSNs.First().NODE_NAME,
+                        NextNode = string.Join(",", wo.GetNextNodes(wipSNs.First()).Select(q => q.NODE_NAME)),
+                    };
+                }
+            }
+            catch (Exception ex)
+            {
+                //action.CatchExceptionWithLog(ex, $"鑾峰彇鏉$爜[{sn}]鐨勫伐搴忎俊鎭紓甯�");
+                action.CatchExceptionWithLog(ex, Biz.L("MES.WoContext.GetSnOperInfoException", sn));
+            }
+            return action;
         }
         #endregion
     }

--
Gitblit v1.9.3