From 6e1296126a4a9b1b808796a5ff2bfadf50da8bcc Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期二, 08 十月 2024 22:54:47 +0800
Subject: [PATCH] 保存工步的数据库提交操作到数据库,增加可以保存完工步数据后,保存附加的内容

---
 Tiger.Business.MES/Transaction/Position.cs |  139 +++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 123 insertions(+), 16 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index 06c902b..ad4824e 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/Tiger.Business.MES/Transaction/Position.cs
@@ -12,6 +12,7 @@
 using static Tiger.Business.Biz;
 using Tiger.Model.Entitys.MES.Position;
 using System.Globalization;
+using Tiger.Business.MES.WorkAction;
 
 namespace Tiger.Business.MES.Transaction
 {
@@ -394,15 +395,45 @@
         /// <summary>
         /// 淇濆瓨宸ユ鐨勬暟鎹簱鎻愪氦鎿嶄綔鍒版暟鎹簱
         /// </summary>
-        protected void SaveStepsCommitActionToDB()
+        /// <param name="appendToSave">鎻愪氦瀹屽伐姝ユ暟鎹悗锛屾彁浜ら檮鍔犵殑淇濆瓨鍐呭</param>
+        public void SaveStepsCommitActionToDB(Action appendToSave = null)
         {
             //淇濆瓨宸ユ鐨勬暟鎹簱鎻愪氦鎿嶄綔鍒版彁浜ゆ搷浣滃垪琛�
-            var commitList = new List<Action>();
-            foreach (var step in Steps.OrderBy(q => q.Sequence))
+            if (!Steps.IsNullOrEmpty())
             {
-                commitList.Add(step.DBSubmitAction);
+	            var commitList = new List<Action>();
+	            foreach (var step in Steps.OrderBy(q => q.Sequence))
+	            {
+	                commitList.Add(step.DBSubmitAction);
+	            }
+	            //璁板綍宸ュ簭鑰楁椂
+	            commitList.Add(() =>
+	            {
+	                EndAt = DateTime.Now;
+	                var ids = CurWipSNHiss.Select(q => q.ID).ToList();
+	                GetCommitDB().Updateable<MES_WIP_HIS>().SetColumns(q => q.ELAPSED_TIME == ElapsedTime.TotalMilliseconds.ToInt64()).Where(q => ids.Contains(q.ID)).ExecuteCommand();
+	            });
+                //澧炲姞闄勫姞鐨勪繚瀛樺唴瀹�
+                if (!appendToSave.IsNullOrEmpty())
+                {
+                    commitList.Add(appendToSave);
+                }
+	            DBCommitList.Add(CurSN, commitList);
             }
-            DBCommitList.Add(CurSN, commitList);
+            else
+            {
+                //澧炲姞闄勫姞鐨勪繚瀛樺唴瀹�
+                if (!appendToSave.IsNullOrEmpty())
+                {
+                    if (!DBCommitList.ContainsKey("AppendSaveAction"))
+                    {
+                        DBCommitList.Add("AppendSaveAction", new List<Action>());
+                    }
+                    var commitList = DBCommitList["AppendSaveAction"];
+                    commitList.Add(appendToSave);
+                }
+            }
+
             //濡傛灉涓嶉渶瑕佷复鏃跺瓨鍌ㄦ暟鎹簱鎻愪氦鎿嶄綔锛屽垯鎶婃彁浜ゆ搷浣滃垪琛ㄦ彁浜ゅ埌鏁版嵁搴�
             if (!NeedTemporaryStoreDBCommitAction)
             {
@@ -412,17 +443,21 @@
                 var dbTran = GetCommitDB().UseTran(() =>
                 {
                     //鍦ㄥ悓涓�涓簨鍔′腑淇濆瓨鎵�鏈夊伐姝ョ殑鏁版嵁
-                    foreach (var wipSn in DBCommitList.Keys)
+                    foreach (var wipSn in DBCommitList.Keys.Where(q => q != "AppendSaveAction"))
                     {
                         foreach (var action in DBCommitList[wipSn])
                         {
                             action.Invoke();
                         }
                     }
-                    //璁板綍宸ュ簭鑰楁椂
-                    EndAt = DateTime.Now;
-                    var ids = CurWipSNHiss.Select(q => q.ID).ToList();
-                    GetCommitDB().Updateable<MES_WIP_HIS>().SetColumns(q => q.ELAPSED_TIME == ElapsedTime.TotalMilliseconds.ToInt64()).Where(q => ids.Contains(q.ID)).ExecuteCommand();
+                    //闄勫姞鐨勪繚瀛樺唴瀹�
+                    if (DBCommitList.ContainsKey("AppendSaveAction"))
+                    {
+                        foreach (var action in DBCommitList["AppendSaveAction"])
+                        {
+                            action.Invoke();
+                        }
+                    }
                 });
                 if (dbTran.IsSuccess)
                 {
@@ -463,7 +498,7 @@
         /// <returns></returns>
         public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action)
         {
-            foreach (var item in label.Variables)
+            foreach (var item in label.Variables.OrderBy(q => q.VAR_TYPE == BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate.GetValue() ? 0 : 1))
             {
                 switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>())
                 {
@@ -471,7 +506,7 @@
                         item.Value = item.VAR_VALUE;
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable:
-                        item.Value = GetPrintProcessValue(labelPVs, item, action);
+                        item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action);
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.DateVariable:
                         item.Value = DateTime.Now.ToString(item.VAR_VALUE);
@@ -494,7 +529,7 @@
         /// <param name="labelPVs">杩囩▼鍙橀噺鍒楄〃</param>
         /// <param name="lv">鏍囩妯℃澘鍙橀噺</param>
         /// <returns></returns>
-        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, IWorkAction action)
+        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction action)
         {
             var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE);
             if (!pv.IsNullOrEmpty())
@@ -508,9 +543,31 @@
                                 case "GetSN":
                                     return CurSN;
                                 case "GetBAS_ITEM":
-                                    return WorkBatch.Product.ToJson();
+                                    return WorkBatch.Product.CUST_PROD_CODE;
                                 case "GetCustomer":
-                                    return WorkBatch.Batch.ToJson();
+                                    return WorkBatch.Batch.Customer.ToJson();
+                                case "GetBoxQR":
+                                    return action is PackingAction ? GetBoxCode(lvars, action as PackingAction) : "";
+                                case "GetCardQR":
+                                    return action is PackingAction ? GetCardCode(lvars, action as PackingAction) : "";
+                                case "GetDescription":
+                                    return WorkBatch.Product.ITEM_DESC;
+                                case "GetPAndO":
+                                    return WorkBatch.WO.SALES_CONTRACT;
+                                case "GetLTD":
+                                    return WorkBatch.Batch.Customer.SHORT_NAME;
+                                case "GetHWDate":
+                                    List<string> list = new List<string>();
+                                    var _action = action is PackingAction ? action as PackingAction : null;
+                                    if (_action.CurPkg.Item.PKG_LEVEL == 1)
+                                    {
+                                        list.Add(CurSN);
+                                    }
+                                    else
+                                    {
+                                        list = _action != null ? _action.GetMinPackageList(_action.CurPkg.Item).Select(q => q.SN).ToList() : new List<string>();
+                                    }
+                                    return GetHuaWeiWeek(WorkBatch.Batch.ORDER_NO, list);
                                 case "GetModel":
                                     return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Model);
                                 case "GetInput":
@@ -591,6 +648,55 @@
         }
 
         /// <summary>
+        /// 鑾峰彇鐧界洅鏉$爜
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        private string GetBoxCode(List<BAS_LABEL_VAR> lvars, PackingAction action)
+        {
+            var boxCode = Biz.CodeRule["WhiteBoxNo"]?.Generate("W", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "";
+            return GetCardOrBoxQR(boxCode, lvars, action);
+        }
+
+        /// <summary>
+        /// 鑾峰彇绠辨潯鐮�
+        /// </summary>
+        /// <param name="lvars"></param>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        private string GetCardCode(List<BAS_LABEL_VAR> lvars, PackingAction action)
+        {
+            var cardCode = Biz.CodeRule["CartonNo"]?.Generate("B", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "" ;
+            return GetCardOrBoxQR(cardCode, lvars, action);
+        }
+
+        /// <summary>
+        /// 鑾峰彇鐧界洅鎴栬�呯浜岀淮鐮�
+        /// </summary>
+        /// <param name="code"></param>
+        /// <param name="lvars"></param>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        private string GetCardOrBoxQR(string code, List<BAS_LABEL_VAR> lvars, PackingAction action)
+        {
+            var itemCode = WorkBatch.Product.CUST_PROD_CODE;
+            var wo = WorkBatch.Batch.ORDER_NO;
+            var snList = string.Join("\r\n", action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN));
+            if (snList.IsNullOrEmpty()) { snList = $"{CurSN}"; }
+            var weight = action.CurPkg.WeightInfo.Weight;
+            var unit = action.CurPkg.WeightInfo.Unit.ToUpper();
+            var model = WorkBatch.Product.ExtInfo.Model;
+            var Input = WorkBatch.Product.ExtInfo.Input;
+            var OutPut = WorkBatch.Product.ExtInfo.OutPut;
+            var Power = WorkBatch.Product.ExtInfo.Power;
+            var Accuracy = WorkBatch.Product.ExtInfo.Accuracy;
+            var Display = WorkBatch.Product.ExtInfo.Display;
+            var Remark = WorkBatch.Product.ExtInfo.Remark;
+
+            return $"{code}|{itemCode}|{wo}|\r\n{snList}|{weight}{unit}|鍨嬪彿:{model},杈撳叆:{Input},鏄剧ず:{Display},杈撳嚭:{OutPut},鐢垫簮:{Power},绮惧害:{Accuracy},澶囨敞:{Remark}";
+        }
+
+        /// <summary>
         /// 鏍规嵁鍖呰宸ュ崟鍜屾潯鐮佽幏鍙栧崕涓鸿姹傜殑鐢熶骇鍛ㄦ湡
         /// </summary>
         /// <param name="snList"></param>
@@ -606,7 +712,7 @@
                 var item = snOrder.FirstOrDefault(q => q.FLOW_SN == sn || q.CUST_SN == sn);
                 if (!item.IsNullOrEmpty())
                 {
-                    var date = item.ACT_START_TIME < new DateTime(2000, 1, 1) ? item.PLAN_START_TIME : item.ACT_START_TIME; ;
+                    var date = item.ACT_START_TIME < new DateTime(2000, 1, 1) ? item.PLAN_START_TIME : item.ACT_START_TIME;
                     var firstDay = new DateTime(date.Year, 1, 1);
                     int daysOffset = firstDay.DayOfWeek.GetValue() > 3 ? (firstDay.DayOfWeek.GetValue() - 7) : 0;
                     int year = date.Year + ((date - firstDay).TotalDays + daysOffset < 0 ? -1 : 0);
@@ -643,5 +749,6 @@
             this.IsFinished = true;
             return IsFinished ? base.Close(needSaveHistoryLog) : IsFinished;
         }
+
     }//endClass
 }
\ No newline at end of file

--
Gitblit v1.9.3