From 37fc700892a509346d5be0a1af2d3de1fe8d3a9e Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期二, 20 八月 2024 18:38:10 +0800
Subject: [PATCH] 一些更改

---
 Tiger.Business.MES/Transaction/Position.cs |  109 +++++++++++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 94 insertions(+), 15 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index ccd93fd..d4b8184 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/Tiger.Business.MES/Transaction/Position.cs
@@ -55,8 +55,10 @@
         public MES_SHIFT_SYS CurShiftSys { get; set; }
         public WorkBatch CurBatch { get; set; }
         public IWorkBatch WorkBatch => CurBatch;
-        public MES_WIP_DATA CurWipSN { get; set; }
-        public MES_WIP_HIS CurWipSNHis { get; set; }
+        public List<MES_WIP_DATA> CurWipSNs { get; set; } = new();
+        public string CurSN => (CurWipSNs.Any() ? (CurWipSNs.First().TRAY_SN.IsNullOrEmpty() ? CurWipSNs.First().SN : CurWipSNs.First().TRAY_SN) : "");
+        public List<MES_WIP_HIS> CurWipSNHiss { get; set; } = new();
+        public List<MES_WIP_DFT> CurDefects { get; set; } = new();
         public Dictionary<string, object> Context { get; set; } = new();
         public List<WorkStep> Steps { get; set; } = new();
         public WorkStep CurStep { get; set; }
@@ -70,7 +72,9 @@
         /// </summary>
         public bool NeedTemporaryStoreDBCommitAction { get; set; } = false;
         protected List<Action> DBCommitList { get; set; } = new();
-
+        protected List<Position> NodeCommitList { get; set; } = new();
+        protected Dictionary<string, OperInfo> OperInfoDic { get; set; } = new();
+        protected OperInfo CurOperInfo { get; set; }
         #endregion Propertys & Variables
 
         #region Functions
@@ -122,6 +126,11 @@
                     WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb);
                 }
                 CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE);
+                if (!OperInfoDic.ContainsKey(CurBatch.Batch.BATCH_NO))
+                {
+                    OperInfoDic.Add(CurBatch.Batch.BATCH_NO, new());
+                }
+                
                 action.Data = new { WorkOrder = CurBatch.WO, Bacth = CurBatch.Batch };
             }
             catch (Exception ex)
@@ -174,9 +183,28 @@
         public virtual void ResetNode()
         {
             Steps.Clear();
-            CurWipSN = null;
-            CurWipSNHis = null;
+            CurWipSNs.Clear();
+            CurWipSNHiss.Clear();
             CurStep = null;
+            CurDefects.Clear();
+        }
+
+        /// <summary>
+        /// 璁剧疆褰撳墠鏉$爜鐨勫伐搴忎俊鎭�
+        /// </summary>
+        public OperInfo SetOperNodeInfo(OperInfo info)
+        {
+            if (CurWipSNs.Any())
+            {
+                info.CurNode = CurWipSNs.First().NODE_NAME;
+                info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME));
+            }
+            else
+            {
+                info.CurNode = "   鈥�   ";
+                info.NextNode = "   鈥�   ";
+            }
+            return info;
         }
 
         /// <summary>
@@ -343,15 +371,15 @@
                 NeedTemporaryStoreDBCommitAction = false;
 
                 var dbTran = GetCommitDB().UseTran(() =>
-	            {
-	                //鍦ㄥ悓涓�涓簨鍔′腑淇濆瓨鎵�鏈夊伐姝ョ殑鏁版嵁
-	                foreach (var action in DBCommitList)
-	                {
+                {
+                    //鍦ㄥ悓涓�涓簨鍔′腑淇濆瓨鎵�鏈夊伐姝ョ殑鏁版嵁
+                    foreach (var action in DBCommitList)
+                    {
                         action.Invoke();
-	                }
-	            });
-	            if (dbTran.IsSuccess)
-	            {
+                    }
+                });
+                if (dbTran.IsSuccess)
+                {
                     //淇濆瓨鎴愬姛鍒欐竻绌烘彁浜ゆ搷浣滃垪琛�
                     DBCommitList.Clear();
                 }
@@ -360,6 +388,23 @@
                     //鎶涘嚭寮傚父
                     throw dbTran.ErrorException;
                 }
+            }
+        }
+
+        protected void DoSaveToDB()
+        {
+            var dbTran = GetCommitDB().UseTran(() =>
+            {
+                //鍦ㄥ悓涓�涓簨鍔′腑淇濆瓨鎵�鏈夊伐姝ョ殑鏁版嵁
+                foreach (var step in Steps.OrderBy(q => q.Sequence))
+                {
+                    step.DBSubmitAction.Invoke();
+                }
+            });
+            if (!dbTran.IsSuccess)
+            {
+                //鎶涘嚭寮傚父
+                throw dbTran.ErrorException;
             }
         }
 
@@ -383,6 +428,9 @@
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.DateVariable:
                         item.Value = DateTime.Now.ToString(item.VAR_VALUE);
+                        break;
+                    case BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate:
+                        item.Value = GetGeneratePValue(labelPVs, item);
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.CustomVariable:
                     default:
@@ -411,7 +459,7 @@
                             switch (pv.VAR_METHOD)
                             {
                                 case "GetSN":
-                                    return CurWipSN.SN;
+                                    return CurSN;
                                 case "GetBAS_ITEM":
                                     return WorkBatch.Product.ToJson();
                                 case "GetCustomer":
@@ -422,7 +470,7 @@
                                     return "";
                             }
                         }
-                    case BAS_LABEL_PV.VAR_TYPEs.WebApiWebApi:
+                    case BAS_LABEL_PV.VAR_TYPEs.WebApi:
                         break;
                     case BAS_LABEL_PV.VAR_TYPEs.StoredProcedure:
                         break;
@@ -432,6 +480,37 @@
             }
             return "";
         }
+
+        /// <summary>
+        /// 鑾峰彇鏍规嵁鏉$爜瑙勫垯鐢熸垚鏍囩妯℃澘鐨勮繃绋嬪彉閲忓��
+        /// </summary>
+        /// <param name="labelPVs"></param>
+        /// <param name="lv"></param>
+        /// <returns></returns>
+        public string GetGeneratePValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv)
+        {
+            var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE);
+            if (!pv.IsNullOrEmpty())
+            {
+                switch (pv.VAR_TYPE.GetEnum<BAS_LABEL_PV.VAR_TYPEs>())
+                {
+                    case BAS_LABEL_PV.VAR_TYPEs.BarcodeGenerate:
+                        {
+                            switch (pv.VAR_METHOD)
+                            {
+                                case "GetCartonGenerate":
+                                    return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate($"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "";
+                                default:
+                                    return "";
+                            }
+                        }
+                    default:
+                        break;
+                }
+            }
+            return "";
+        }
+
         /// <summary>
         /// 鑾峰彇宸ュ崟缁存姢鐨勬ā鏉垮彉閲�
         /// </summary>

--
Gitblit v1.9.3