From dc4c76b2b5e57d28e3c4bfff9ec86e11efe22d20 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期一, 23 九月 2024 19:49:23 +0800
Subject: [PATCH] 优化工序逻辑

---
 Tiger.Business.MES/Transaction/CollectNode.cs |  147 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 116 insertions(+), 31 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/CollectNode.cs b/Tiger.Business.MES/Transaction/CollectNode.cs
index 4856df7..0044c67 100644
--- a/Tiger.Business.MES/Transaction/CollectNode.cs
+++ b/Tiger.Business.MES/Transaction/CollectNode.cs
@@ -46,24 +46,39 @@
                     //鍏堝垽鏂綋鍓嶅伐鍗曚笉涓虹┖涓斿綋鍓嶅矖浣嶅湪褰撳墠宸ュ崟鏄笉鏄绔欙紝濡傛灉鏄垯涓嶅厑璁稿彉鏇村綋鍓嶅伐鍗曪紝灏濊瘯鎶婃潯鐮佺粦瀹氬埌褰撳墠宸ュ崟
                     if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                     {
+                        //鏇存柊CurBatch
+                        CurBatch?.Update();
+                        //鎻愪氦鏁版嵁
                         action = NodeSubmit(action, input);
-                        return action;
+                        //鏇存柊宸ュ簭淇℃伅
+                        if (!action.IsSuccessed)
+                        {
+                            var info = WoContext.GetSnOperInfo(input.SN).Data;
+                            info.InputQty = CurOperInfo(input.Locale).InputQty;
+                            action.Data.OperInfo = info;
+                        }
+                        else if (!IsFinishAllSteps)
+                        {
+                            action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
+                        }
                     }
                     //褰撳墠宀椾綅鍦ㄥ綋鍓嶅伐鍗曚笉鏄绔欙紝鍒欐煡鎵炬潯鐮佸凡缁戝畾鐨勫伐鍗曞綋浣滃綋鍓嶅伐鍗�
                     else
                     {
                         var wosns = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER))
-                                                        .ByAuth(input.AuthOption).Where((q, s) => s.SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
+                                                        .ByAuth(input.AuthOption).Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue())
+                                                        .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList();
 
                         //鏌ユ壘鍒版潯鐮佸凡缁戝畾鐨勫伐鍗�
                         if (!wosns.IsNullOrEmpty())
                         {
                             if (wosns.First().Batch.ACT_LINE != CurLine.LINE_CODE)
                             {
+                                action.Data.ShortMsg = new("浜х嚎閿欒", ShortMessage.Types.Error);
+                                action.Data.OperInfo = new();
                                 action.IsSuccessed = false;
                                 //action.LocaleMsg = new($"鏉$爜[{0}]宸插湪浜х嚎[{1}]鎶曞叆鐢熶骇锛岃鍦ㄦ纭矖浣嶆壂鎻�");
                                 action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotCorrectLine", input.SN, wosns.First().Batch.ACT_LINE);
-                                return action;
                             }
                             else
                             {
@@ -73,14 +88,27 @@
                                     var result = await SelectOrder(new() { AuthOption = input.AuthOption, OrderNo = wosns.First().Batch.ORDER_NO });
                                     if (!result.IsSuccessed)
                                     {
+                                        action.Data.ShortMsg = new("宸ュ崟寮傚父", ShortMessage.Types.Error);
+                                        action.Data.OperInfo = new();
                                         action.IsSuccessed = result.IsSuccessed;
                                         action.LocaleMsg = result.LocaleMsg;
                                         return action;
                                     }
                                 }
+                                //鏇存柊CurBatch
+                                CurBatch?.Update();
                                 //鏉$爜杩囩珯
                                 action = NodeSubmit(action, input);
-                                return action;
+                                if (!action.IsSuccessed && !CurWipSNs.Any())
+                                {
+                                    var info = WoContext.GetSnOperInfo(input.SN).Data;
+                                    info.InputQty = CurOperInfo(input.Locale).InputQty;
+                                    action.Data.OperInfo = info;
+                                }
+                                else if (!IsFinishAllSteps)
+                                {
+                                    action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
+                                }
                             }
                         }
                         //鏌ユ壘涓嶅埌鏉$爜宸茬粦瀹氱殑宸ュ崟
@@ -89,18 +117,20 @@
                             //娌℃湁褰撳墠宸ュ崟锛屽垯鍏堥�夋嫨宸ュ崟鍚庡啀鎵弿鏉$爜
                             if (CurBatch.IsNullOrEmpty())
                             {
+                                action.Data.ShortMsg = new("鏈�夋嫨宸ュ崟", ShortMessage.Types.Error);
+                                action.Data.OperInfo = new();
                                 action.IsSuccessed = false;
                                 //action.LocaleMsg = new($"鏈�夋嫨宸ュ崟锛岃鍏堥�夋嫨瑕佺敓浜х殑宸ュ崟");
                                 action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.NotSelectOrderException");
-                                return action;
                             }
                             //鏈夊綋鍓嶅伐鍗曚笖涓嶆槸鎶曞叆锛屽垯鎻愮ず鏉$爜鏈姇鍏ョ敓浜э紝璇峰厛鍘婚绔欐壂鎻�
                             else
                             {
+                                action.Data.ShortMsg = new("鏈姇鍏ョ敓浜�", ShortMessage.Types.Error);
+                                action.Data.OperInfo = new();
                                 action.IsSuccessed = false;
                                 //action.LocaleMsg = new($"鏉$爜[{input.SN}]灏氭湭鎶曞叆鐢熶骇锛岃鍏堝幓棣栫珯鎵弿", input.SN);
                                 action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.NotInputException", input.SN);
-                                return action;
                             }
                         }
                     }
@@ -108,19 +138,22 @@
                 //瀹屾垚宸ュ簭鑺傜偣宸ユ鍚庯紝鍚庡紑濮嬫墽琛屽綋鍓嶅伐搴忕殑琛屼负宸ユ
                 else if (IsFinishNodeSteps && !IsFinishAllSteps)
                 {
+                    //鏇存柊CurBatch
+                    CurBatch?.Update();
+
                     var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault();
+                    //濡傛灉瀹㈡埛绔繑鍥炵殑褰撳墠宸ユID鎵句笉鍒版湭瀹屾垚鐨勮涓哄伐姝ワ紝鍒欑洿鎺ュ紑濮嬩笅涓�涓涓哄伐姝�
                     if (submitStep.IsNullOrEmpty())
                     {
                         action = BeginNextActionStep(input);
-                        return action;
                     }
                     else
                     {
-                        var result = submitStep.Submit(input);
+                        action = submitStep.Submit(input);
                         //濡傛灉褰撳墠宸ユ宸插畬鎴愶紝寮�濮嬫墽琛屼笅涓�宸ユ
-                        if (result.IsSuccessed && submitStep.IsFinished)
+                        if (action.IsSuccessed && submitStep.IsFinished)
                         {
-                            result = BeginNextActionStep(input);
+                            action = BeginNextActionStep(input);
                         }
                         //濡傛灉褰撳墠宸ユ鏈畬鎴�
                         else
@@ -128,29 +161,40 @@
                             //琛屼负鎵ц鍑洪敊锛屽伐姝ヨ閲嶇疆
                             if (Steps.IsNullOrEmpty())
                             {
-                                result.LocaleMsg = new(Biz.T(result.LocaleMsg, input.Locale) + Biz.T(Biz.L("MES.Transaction.Position.RescanSN"), input.Locale));
+                                action.LocaleMsg = new(Biz.T(action.LocaleMsg, input.Locale) + Biz.T(Biz.L("MES.Transaction.Position.RescanSN"), input.Locale));
                             }
                             else
                             {
-                                result.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps);
+                                action.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps);
                             }
                         }
-                        //濡傛灉鎵�鏈夊伐姝ラ兘瀹屾垚
-                        if (IsFinishAllSteps)
-                        {
-                            return DoIfFinishAllSteps(result);
-                        }
-                        return result;
+                    }
+                    //濡傛灉鎵�鏈夊伐姝ラ兘瀹屾垚
+                    if (IsFinishAllSteps)
+                    {
+                        action = DoIfFinishAllSteps(action, input.Locale);
+                    }
+                    else
+                    {
+                        action.Data.OperInfo = CurOperInfo(input.Locale);
                     }
                 }
                 //娌℃湁鍙墽琛岀殑宸ユ
-                ResetNode();
-                action.IsSuccessed = false;
-                //action.LocaleMsg = new($"宀椾綅[{CurPosition.POST_CODE}]宸ユ鎵ц寮傚父锛岃閲嶆柊鎵弿浜у搧鏉$爜", CurPosition.POST_CODE);
-                action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.WorkStepException", CurPosition.POST_CODE);
+                else
+                {
+                    action.Data.ShortMsg = new("閲嶇疆鎵弿", ShortMessage.Types.Error);
+                    action.Data.OperInfo = CurOperInfo(input.Locale);
+                    ResetNode();
+	                action.IsSuccessed = false;
+	                //action.LocaleMsg = new($"宀椾綅[{CurPosition.POST_CODE}]宸ユ鎵ц寮傚父锛岃閲嶆柊鎵弿浜у搧鏉$爜", CurPosition.POST_CODE);
+	                action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.WorkStepException", CurPosition.POST_CODE);
+                }
             }
             catch (Exception ex)
             {
+                action.Data.ShortMsg = new("宸ュ簭寮傚父", ShortMessage.Types.Error);
+                action.Data.OperInfo = CurOperInfo(input.Locale);
+                ResetNode();
                 //action.CatchExceptionWithLog(ex, $"閲囬泦宸ュ簭锛氭彁浜ゆ搷浣滄暟鎹紓甯�");
                 action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.CollectNode.SubmitException"));
             }
@@ -172,10 +216,11 @@
                 var woStatus = CurBatch.CheckCanProduce(curNode);
                 if (!woStatus.IsSuccessed)
                 {
+                    woStatus.Data.ShortMsg = new("宸ュ崟寮傚父", ShortMessage.Types.Error);
                     return woStatus;
                 }
-                //闈炴硶杩囩珯闃插憜锛氳繘鍏ュ伐搴忔椂瑕佸鍔犲垽鏂潯鐮佹槸鍚︽寜娴佺▼杩囩珯
-                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => (q.SN == input.SN || q.TRAY_SN == input.SN) && q.WORK_ORDER == CurBatch.WO.ORDER_NO).ToList();
+                
+                var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN || q.TRAY_SN == input.SN).ToList();
                 if (wipSNs.IsNullOrEmpty())
                 {
                     var wipSN = new MES_WIP_DATA()
@@ -186,6 +231,10 @@
                         ITEM_CODE = CurBatch.WO.ITEM_CODE,
                         WORK_ORDER = CurBatch.Batch.ORDER_NO,
                         BATCH_NO = CurBatch.Batch.BATCH_NO,
+                        FTY_CODE = CurFactory.FTY_CODE,
+                        WS_CODE = CurWorkshop.WS_CODE,
+                        LINE_CODE = CurLine.LINE_CODE,
+                        POST_CODE = CurPosition.POST_CODE,
                         HOLD_FLAG = "N",
                         REWORK_FLAG = CurBatch.WO.ORDER_TYPE == BIZ_MES_WO.ORDER_TYPEs.Rework.GetValue() ? "Y" : "N",
                         FINISHED_FLAG = "N",
@@ -195,9 +244,33 @@
                     };
                     wipSNs.Add(wipSN);
                 }
+
+                //濡傛灉鏉$爜涓嶆槸褰撳墠宸ュ崟鎴栬�呬骇绾跨殑鍒欐姤閿�
+                if (wipSNs.Any(q => q.WORK_ORDER != CurBatch.WO.ORDER_NO || q.LINE_CODE != CurLine.LINE_CODE))
+                {
+                    if (wipSNs.First().LINE_CODE == CurLine.LINE_CODE)
+                    {
+                        action.Data.ShortMsg = new("宸ュ崟閿欒", ShortMessage.Types.Error);
+                        action.IsSuccessed = false;
+                        //action.LocaleMsg = new($"浜у搧[{CurSN}]涓嶅睘浜庡綋鍓嶅伐鍗曪紝璇峰垏鎹㈠埌宸ュ崟[{wipSNs.First().WORK_ORDER}]鍚庡啀鎵弿");
+                        action.LocaleMsg = new("MES.Transaction.CollectNode.NodeSubmit.WoError", input.SN, wipSNs.First().WORK_ORDER);
+                        return action;
+                    }
+                    else
+                    {
+                        action.Data.ShortMsg = new("浜х嚎閿欒", ShortMessage.Types.Error);
+                        action.IsSuccessed = false;
+                        //action.LocaleMsg = new($"浜у搧[{CurSN}]宸插湪浜х嚎[{wipSNs.First().LINE_CODE}]鎶曚骇锛岃鍒颁骇绾縖{wipSNs.First().LINE_CODE}]鎵弿");
+                        action.LocaleMsg = new("MES.Transaction.CollectNode.NodeSubmit.LineError", input.SN, wipSNs.First().LINE_CODE);
+                        return action;
+                    }
+                }
+
+                //闈炴硶杩囩珯闃插憜锛氳繘鍏ュ伐搴忔椂瑕佸鍔犲垽鏂潯鐮佹槸鍚︽寜娴佺▼杩囩珯
                 var canGotoNext = CurBatch.CanGotoNext(input, wipSNs.First(), curNode);
                 if (!canGotoNext.IsSuccessed)
                 {
+                    woStatus.Data.ShortMsg = new("杩涚珯閿欒", ShortMessage.Types.Error);
                     return canGotoNext;
                 }
 
@@ -214,6 +287,7 @@
                                 WORK_ORDER = CurBatch.Batch.ORDER_NO,
                                 WIP_ID = wipSN.ID,
                                 SN = wipSN.SN,
+                                FLOW_SN = wipSN.SN,
                                 TRAY_SN = wipSN.TRAY_SN,
                                 STATUS = BIZ_MES_WO_SN.STATUSs.NotInput.GetValue(),
                             });
@@ -280,6 +354,7 @@
                             {
                                 AUTH_ORG = wipSN.AUTH_ORG,
                                 AUTH_PROD = wipSN.LINE_CODE,
+                                WIP_ID = wipSN.ID,
                                 SN = wipSN.SN,
                                 STATUS = MES_WIP_DFT.STATUSs.WaitHandle.GetValue(),
                                 ITEM_CODE = wipSN.ITEM_CODE,
@@ -322,7 +397,9 @@
                     CurWipSNHiss.Clear();
                     foreach (var wipSN in wipSNs)
                     {
-                        CurWipSNHiss.Add(new MES_WIP_HIS(wipSN, $"宸ュ崟[{wipSN.WORK_ORDER}]鏉$爜[{wipSN.SN}]鍦ㄥ矖浣峓{wipSN.POST_CODE}]杩囩珯宸ュ簭[{wipSN.NODE_NAME}]鎴愬姛"));
+                        var his = new MES_WIP_HIS(wipSN, $"宸ュ崟[{wipSN.WORK_ORDER}]鏉$爜[{wipSN.SN}]鍦ㄥ矖浣峓{wipSN.POST_CODE}]杩囩珯宸ュ簭[{wipSN.NODE_NAME}]鎴愬姛");
+                        wipSN.History.Add(his);
+                        CurWipSNHiss.Add(his);
                     }
 
                     //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊�
@@ -335,10 +412,12 @@
 
                     //鍒濆鍖栧伐姝ュ垪琛�
                     Steps.Clear();
-                    var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this)
+                    var curStep = new Biz.WorkStep(IWorkStep.NodeTypes.Node, this)
                     {
+                        Name = "鎵弿浜у搧",
                         Sequence = Steps.Count + 1,
                         Node = curNode,
+                        OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID),
                         DBSubmitAction = () =>
                         {
                             //浣跨敤缁熶竴鐨勪簨鍔B瀵硅薄
@@ -384,14 +463,16 @@
 
                     //瀹屾垚绗竴涓伐搴忚妭鐐瑰伐姝�
                     curStep.IsFinished = true;
+                    curStep.Status = StepStatus.Finished;
                     CurStep = curStep;
                 }
                 else if (!IsFinishNodeSteps)
                 {
-                    var curStep = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
+                    var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
 
                     //瀹屾垚褰撳墠宸ュ簭鑺傜偣宸ユ
                     curStep.IsFinished = true;
+                    curStep.Status = StepStatus.Finished;
                     CurStep = curStep;
                 }
 
@@ -401,7 +482,7 @@
                     //鏈畬鎴愭墍鏈夊伐搴忚妭鐐瑰伐姝�
                     if (!IsFinishNodeSteps)
                     {
-                        var next = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
+                        var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First();
                         //璁剧疆鍚庣画鍙墽琛岀殑宸ユ鍒楄〃
                         NextSteps.Clear();
                         NextSteps.Add(next);
@@ -429,13 +510,13 @@
                 if (IsFinishAllSteps)
                 {
                     action.Data.SetValue(CurBatch, CurStep, "", IsFinishAllSteps);
-                    action = DoIfFinishAllSteps(action);
+                    action = DoIfFinishAllSteps(action, input.Locale);
                 }
             }
             catch (Exception ex)
             {
+                action.Data.ShortMsg = new("宸ユ寮傚父", ShortMessage.Types.Error);
                 ResetNode();
-                action.CatchExceptionWithLog(ex, $"閲囬泦宸ュ簭锛氬伐搴忚妭鐐瑰伐姝ユ彁浜ゆ暟鎹紓甯�");
                 //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}锛氬伐搴忚妭鐐瑰伐姝ユ彁浜ゆ暟鎹紓甯革紝璇锋鏌ュ伐搴忚妭鐐硅缃�");
                 action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.CollectNode.NodeSubmitException", curNode.NODE_NAME));
             }
@@ -447,14 +528,18 @@
         /// </summary>
         /// <param name="action"></param>
         /// <returns></returns>
-        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action)
+        public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action, string locale)
         {
             //淇濆瓨鏁版嵁搴�
             SaveStepsCommitActionToDB();
 
             //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭�
+            CurOperInfo(locale).InputQty += CurWipSNs.Count;
+            action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(locale));
+            action.Data.ShortMsg = new("杩囩珯鎴愬姛", ShortMessage.Types.Success);
             //action.LocaleMsg = new($"宸ュ崟[{CurWipSN.WORK_ORDER}]鐨勬潯鐮乕{CurWipSN.SN}]鍦ㄥ矖浣峓{CurWipSN.POST_CODE}]宸ュ簭[{CurWipSN.NODE_NAME}]杩囩珯鎴愬姛锛岀姸鎬乕{CurWipSN.STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()}]");
             action.LocaleMsg = new("MES.Transaction.CollectNode.ScanSn.PassSuccess", CurWipSNs.First().WORK_ORDER, CurSN, CurWipSNs.First().POST_CODE, CurWipSNs.First().NODE_NAME,CurWipSNs.First().STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>());
+            
             //閲嶇疆宸ュ簭
             ResetNode();
             return action;

--
Gitblit v1.9.3