From 3f364634b79a0f97a550c54f67313dfc0cfd4cb5 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 27 十一月 2024 22:16:01 +0800
Subject: [PATCH] 一大波签入来了

---
 Tiger.Business.MES/WorkAction/PrintLabel.cs |  130 +++++++++++++++++++++++++++----------------
 1 files changed, 82 insertions(+), 48 deletions(-)

diff --git a/Tiger.Business.MES/WorkAction/PrintLabel.cs b/Tiger.Business.MES/WorkAction/PrintLabel.cs
index eef9e77..29a1b6b 100644
--- a/Tiger.Business.MES/WorkAction/PrintLabel.cs
+++ b/Tiger.Business.MES/WorkAction/PrintLabel.cs
@@ -1,5 +1,4 @@
-锘縰sing MailKit.Search;
-using Rhea.Common;
+锘縰sing Rhea.Common;
 using SqlSugar;
 using System;
 using System.Collections.Generic;
@@ -7,6 +6,7 @@
 using System.Text;
 using System.Threading.Tasks;
 using Tiger.IBusiness;
+using Tiger.IBusiness.MES.WorkAction;
 using Tiger.Model;
 using Tiger.Model.Entitys.MES.Position;
 
@@ -16,6 +16,7 @@
     {
         #region Propertys & Variables
         #region 鍥哄畾鍐欐硶锛屽伐搴忎腑鐨勫繀瑕佷俊鎭�
+        public DbClient MainDB { get; set; }
         public bool IsFinished { get; set; } = false;
         public IWorkStep CurStep { get; set; }
         public IPosition CurPosition { get; set; }
@@ -34,14 +35,18 @@
         public void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting)
         {
             #region 鍥哄畾鍐欐硶锛岀粰榛樿鍙橀噺璧嬪��
+            MainDB = position.MainDB;
             CurStep = curStep;
             CurPosition = position;
             NodeAct = nodeAct;
             Setting = setting;
             #endregion
 
-            Label = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First();
-            LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
+            Label = MainDB.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First();
+            LabelPV = MainDB.Queryable<BAS_LABEL_PV>().ToList();
+
+            CurStep.Message = Biz.L("绛夊緟鏍囩鎵撳嵃");
+            CurStep.Status = StepStatus.Normal;
         }
 
         /// <summary>
@@ -50,7 +55,7 @@
         /// <returns></returns>
         public Locale GetBeginMsg()
         {
-            var msg = new Locale("MES.WorkAction.PrintLabel.BeginMsg", CurPosition.CurWipSN.SN, Label.LABEL_CODE, Label.LABEL_NAME);
+            var msg = new Locale("MES.WorkAction.PrintLabel.BeginMsg", CurPosition.CurSN, Label?.LABEL_CODE, Label?.LABEL_NAME);
             //var msg = new Locale($"寮�濮嬫墦鍗版潯鐮乕{CurPosition.CurWipSN.SN}]鐨勬爣绛綶{Label.LABEL_CODE}: {Label.LABEL_NAME}]");
             return msg;
         }
@@ -63,12 +68,22 @@
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
 
-            //璁剧疆鎵撳嵃鍙橀噺鍊�
-            Label = CurPosition.SetLabelVariables(LabelPV, Label);
-            action.Data.Data = Label;
+            if (Label.IsNullOrEmpty())
+            {
+                action = End(input);
+            }
+            else
+            {
+                //璁剧疆鎵撳嵃鍙橀噺鍊�
+                Label = CurPosition.SetLabelVariables(LabelPV, Label, this);
+                action.Data.Data = Label;
 
-            //濡傛灉杩斿洖鎴愬姛鍒欒涓哄綋鍓嶈涓哄彲浠ュ紑濮嬫墽琛岋紝鍚﹀垯杩斿洖澶辫触
-            action.IsSuccessed = true;
+                //濡傛灉杩斿洖鎴愬姛鍒欒涓哄綋鍓嶈涓哄彲浠ュ紑濮嬫墽琛岋紝鍚﹀垯杩斿洖澶辫触
+                CurStep.Message = Biz.L("鎵撳嵃寮�濮�");
+                CurStep.Status = StepStatus.Normal;
+                action.IsSuccessed = true;
+                action.Data.ShortMsg = new("鎵撳嵃寮�濮�", ShortMessage.Types.Success);
+            }
             return action;
         }
 
@@ -82,18 +97,21 @@
             //鎻愪氦鏁版嵁鎵ц鎴愬姛
             if (input.Data.ToBoolean())
             {
-                action = End();
+                action = End(input);
             }
             //鎻愪氦鏁版嵁鎵ц澶辫触
             else
             {
+                CurStep.Message = Biz.L("鎵撳嵃澶辫触");
+                CurStep.Status = StepStatus.Error;
+                action.Data.ShortMsg = new("鎵撳嵃澶辫触", ShortMessage.Types.Failed);
                 action.IsSuccessed = false;
                 //action.LocaleMsg = new($"鏍囩{Label.LABEL_NAME}[{Label.LABEL_CODE}]鎵撳嵃澶辫触", Label.LABEL_NAME);
-                action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintFail", Label.LABEL_NAME, Label.LABEL_CODE);
+                action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintFail", Label?.LABEL_NAME, Label?.LABEL_CODE);
                 //濡傛灉琛屼负璁剧疆涓哄嚭閿欓渶瑕侀噸缃伐搴忔搷浣�
                 if (NodeAct.NEED_RESET == "Y")
                 {
-                    CurPosition.ResetSteps();
+                    CurPosition.ResetNode();
                 }
             }
             return action;
@@ -102,55 +120,71 @@
         /// 缁撴潫鎵ц宸ュ簭琛屼负
         /// </summary>
         /// <returns></returns>
-        public ApiAction<SubmitOutput> End()
+        public ApiAction<SubmitOutput> End(SubmitInput input)
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
 
             //璁板綍琛屼负鎿嶄綔璁板綍
-            var wipAct = new MES_WIP_ACT()
+            var wipActs = new List<MES_WIP_ACT>();
+            foreach (var wipSn in CurPosition.CurWipSNs)
             {
-                AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
-                AUTH_PROD = CurPosition.CurLine.LINE_CODE,
-                HIS_ID = CurPosition.CurWipSNHis.ID,
-                SN = CurPosition.CurWipSN.SN,
-                STATUS = CurPosition.CurWipSN.STATUS,
-                ITEM_CODE = CurPosition.CurWipSN.ITEM_CODE,
-                WORK_ORDER = CurPosition.CurWipSN.WORK_ORDER,
-                BATCH_NO = CurPosition.CurWipSN.BATCH_NO,
-                ROT_CODE = CurPosition.CurWipSN.ROT_CODE,
-                NODE_ID = CurPosition.CurWipSN.NODE_ID,
-                NODE_NAME = CurPosition.CurWipSN.NODE_NAME,
-                ACT_ID = NodeAct.ID,
-                ACT_NAME = NodeAct.ACT_NAME,
-                FTY_CODE = CurPosition.CurWipSN.FTY_CODE,
-                WS_CODE = CurPosition.CurWipSN.WS_CODE,
-                LINE_CODE = CurPosition.CurWipSN.LINE_CODE,
-                POST_CODE = CurPosition.CurWipSN.POST_CODE,
-                OPER_CODE = CurPosition.CurWipSN.OPER_CODE,
-                SEGMENT = CurPosition.CurWipSN.SEGMENT,
-                TRAY_SN = CurPosition.CurWipSN.TRAY_SN,
-                OPERATION_TIME = DateTime.Now,
-                SFTS_CODE = CurPosition.CurWipSN.SFTS_CODE,
-                SFT_CODE = CurPosition.CurWipSN.SFT_CODE,
-                PRD_CODE = CurPosition.CurWipSN.PRD_CODE,
-                ACT_TYPE = NodeAct.ACT_TYPE,
-                ACT_SN = CurPosition.CurWipSN.SN,
-                ACT_VALUE_1 = Label.LABEL_CODE,
-                ACT_VALUE_2 = Label.Variables.ToJson(),
-                ACT_RESULT = "Y",
-                TRACE_INFO = $"鏍囩{Label.LABEL_NAME}[{Label.LABEL_CODE}]鎵撳嵃鎴愬姛",
-            };
+                var wipAct = new MES_WIP_ACT()
+                {
+                    AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
+                    AUTH_PROD = CurPosition.CurLine.LINE_CODE,
+                    HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID,
+                    WIP_ID = wipSn.ID,
+                    SN = wipSn.SN,
+                    STATUS = wipSn.STATUS,
+                    ITEM_CODE = wipSn.ITEM_CODE,
+                    WORK_ORDER = wipSn.WORK_ORDER,
+                    BATCH_NO = wipSn.BATCH_NO,
+                    ROT_CODE = wipSn.ROT_CODE,
+                    NODE_ID = wipSn.NODE_ID,
+                    NODE_NAME = wipSn.NODE_NAME,
+                    ACT_ID = NodeAct.ID,
+                    ACT_NAME = NodeAct.ACT_NAME,
+                    FTY_CODE = wipSn.FTY_CODE,
+                    WS_CODE = wipSn.WS_CODE,
+                    LINE_CODE = wipSn.LINE_CODE,
+                    POST_CODE = wipSn.POST_CODE,
+                    OPER_CODE = wipSn.OPER_CODE,
+                    SEGMENT = wipSn.SEGMENT,
+                    FLOW_SN = wipSn.FLOW_SN,
+                    TRAY_SN = wipSn.TRAY_SN,
+                    INNER_SN = wipSn.INNER_SN,
+                    CARTON_SN = wipSn.CARTON_SN,
+                    PALLET_SN = wipSn.PALLET_SN,
+                    OPERATION_TIME = DateTime.Now,
+                    SFTS_CODE = wipSn.SFTS_CODE,
+                    SFT_CODE = wipSn.SFT_CODE,
+                    PRD_CODE = wipSn.PRD_CODE,
+                    ACT_TYPE = NodeAct.ACT_TYPE,
+                    ACT_SN = wipSn.SN,
+                    ACT_VALUE_1 = Label?.LABEL_CODE,
+                    ACT_VALUE_2 = Label?.ToJson(),
+                    ACT_RESULT = "Y",
+                    ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(),
+                    TRACE_INFO = $"鏍囩{Label?.LABEL_NAME}[{Label?.LABEL_CODE}]鎵撳嵃鎴愬姛",
+                };
+                wipActs.Add(wipAct);
+            }
 
+            //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊�
+            var _wipActs = wipActs.Clone();
             //淇濆瓨鏁版嵁
             CurStep.DBSubmitAction = () =>
             {
                 var db = CurPosition.GetCommitDB();
-                db.Storageable(wipAct, CurPosition.UserCode).ExecuteCommand();
+                db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand();
             };
 
             IsFinished = true;
+            CurStep.Message = Biz.L("鎵撳嵃瀹屾垚");
+            CurStep.Status = StepStatus.Finished;
+            action.Data.ShortMsg = new("鎵撳嵃瀹屾垚", ShortMessage.Types.Success);
             //action.LocaleMsg = new($"鏍囩{Label.LABEL_NAME}[{Label.LABEL_CODE}]鎵撳嵃鎴愬姛", Label.LABEL_NAME);
-            action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintSuccess", Label.LABEL_NAME, Label.LABEL_CODE);
+            action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintSuccess", Label?.LABEL_NAME, Label?.LABEL_CODE);
             return action;
         }
 

--
Gitblit v1.9.3