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/PackingNode.cs |  105 ++++++++++++++++++++++++++++++++++------------------
 1 files changed, 69 insertions(+), 36 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/PackingNode.cs b/Tiger.Business.MES/Transaction/PackingNode.cs
index 8801299..dbca424 100644
--- a/Tiger.Business.MES/Transaction/PackingNode.cs
+++ b/Tiger.Business.MES/Transaction/PackingNode.cs
@@ -55,7 +55,7 @@
                     //濡傛灉琛屼负琚爣璁版垚宸插畬鎴愶紝鍒欓噸缃伐搴�
                     if (TempPkgAction.IsFinished)
                     {
-                        action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
+                        action.Data.OperInfo = CurOperInfo(input.Locale);
                         ResetNode();
                     }
                 }
@@ -69,25 +69,29 @@
                         //鍏堝垽鏂綋鍓嶅伐鍗曚笉涓虹┖涓斿綋鍓嶅矖浣嶅湪褰撳墠宸ュ崟鏄笉鏄绔欙紝濡傛灉鏄垯涓嶅厑璁稿彉鏇村綋鍓嶅伐鍗曪紝灏濊瘯鎶婃潯鐮佺粦瀹氬埌褰撳墠宸ュ崟
                         if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode))
                         {
+                            //鏇存柊CurBatch
+                            CurBatch?.Update();
+                            //鎻愪氦鏁版嵁
                             action = NodeSubmit(action, input);
                             //鏇存柊宸ュ簭淇℃伅
                             if (!action.IsSuccessed)
                             {
                                 var info = WoContext.GetSnOperInfo(input.SN).Data;
-                                info.InputQty = OperInfoDic[CurBatch.Batch.BATCH_NO].InputQty;
+                                info.InputQty = CurOperInfo(input.Locale).InputQty;
                                 action.Data.OperInfo = info;
                             }
                             else if (!IsFinishAllSteps)
                             {
-                                action.Data.OperInfo = SetOperNodeInfo(OperInfoDic[CurBatch.Batch.BATCH_NO], input.Locale);
+                                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())
                             {
@@ -100,9 +104,18 @@
                                     action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
                                     return action;
                                 }
+                                if (Context.ContainsKey("CurPackage") && !Context["CurPackage"].IsNullOrEmpty() && (Context["CurPackage"] as WipPkg).WorkBatch != wosns.First().Batch.BATCH_NO)
+                                {
+                                    action.Data.ShortMsg = new("宸ュ崟鎵规閿欒", ShortMessage.Types.Error);
+                                    action.Data.OperInfo = new();
+                                    action.IsSuccessed = false;
+                                    //action.LocaleMsg = new($"姝e湪鍖呰宸ュ崟鎵规[{0}]鐨勪骇鍝侊紝璇峰厛瀹屾垚褰撳墠鍖呰鍚庡啀鎵弿鍏朵粬鎵规[{1}]鐨勪骇鍝乕{2}]");
+                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.BatchError", (Context["CurPackage"] as WipPkg).WorkBatch, wosns.First().Batch.BATCH_NO, CurSN);
+                                    return action;
+                                }
                                 if (wosns.First().Batch.ACT_LINE != CurLine.LINE_CODE)
                                 {
-                                    action.Data.ShortMsg = new("浜х嚎閿欒", ShortMessage.Types.Error);
+                                    action.Data.ShortMsg = new("浜х嚎鎶曚骇閿欒", ShortMessage.Types.Error);
                                     action.Data.OperInfo = new();
                                     action.IsSuccessed = false;
                                     //action.LocaleMsg = new($"鏉$爜[{0}]宸插湪浜х嚎[{1}]鎶曞叆鐢熶骇锛岃鍦ㄦ纭矖浣嶆壂鎻�");
@@ -123,17 +136,19 @@
 	                                        return action;
 	                                    }
 	                                }
-	                                //鏉$爜杩囩珯
-	                                action = NodeSubmit(action, input);
+                                    //鏇存柊CurBatch
+                                    CurBatch?.Update();
+                                    //鏉$爜杩囩珯
+                                    action = NodeSubmit(action, input);
                                     if (!action.IsSuccessed && !CurWipSNs.Any())
                                     {
                                         var info = WoContext.GetSnOperInfo(input.SN).Data;
-                                        info.InputQty = OperInfoDic[CurBatch.Batch.BATCH_NO].InputQty;
+                                        info.InputQty = CurOperInfo(input.Locale).InputQty;
                                         action.Data.OperInfo = info;
                                     }
                                     else if (!IsFinishAllSteps)
                                     {
-                                        action.Data.OperInfo = SetOperNodeInfo(OperInfoDic[CurBatch.Batch.BATCH_NO], input.Locale);
+                                        action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                                     }
                                 }
                             }
@@ -164,19 +179,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);
-                            action.Data.OperInfo = OperInfoDic[CurBatch.Batch.BATCH_NO];
                         }
                         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
@@ -184,30 +202,29 @@
                                 //琛屼负鎵ц鍑洪敊锛屽伐姝ヨ閲嶇疆
                                 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)
-                            {
-                                result = DoIfFinishAllSteps(result, input.Locale);
-                            }
-                            else
-                            {
-                                result.Data.OperInfo = OperInfoDic[CurBatch.Batch.BATCH_NO];
-                            }
-                            return result;
+                        }
+                        //濡傛灉鎵�鏈夊伐姝ラ兘瀹屾垚
+                        if (IsFinishAllSteps)
+                        {
+                            action = DoIfFinishAllSteps(action, input.Locale);
+                        }
+                        else
+                        {
+                            action.Data.OperInfo = CurOperInfo(input.Locale);
                         }
                     }
                     //娌℃湁鍙墽琛岀殑宸ユ
                     else
                     {
                         action.Data.ShortMsg = new("閲嶇疆鎵弿", ShortMessage.Types.Error);
-                        action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
+                        action.Data.OperInfo = CurOperInfo(input.Locale);
                         ResetNode();
 	                    action.IsSuccessed = false;
 	                    //action.LocaleMsg = new($"宀椾綅[{CurPosition.POST_CODE}]宸ユ鎵ц寮傚父锛岃閲嶆柊鎵弿浜у搧鏉$爜", CurPosition.POST_CODE);
@@ -218,7 +235,7 @@
             catch (Exception ex)
             {
                 action.Data.ShortMsg = new("宸ュ簭寮傚父", ShortMessage.Types.Error);
-                action.Data.OperInfo = OperInfoDic.ContainsKey(CurBatch?.Batch?.BATCH_NO ?? "") ? OperInfoDic[CurBatch.Batch.BATCH_NO] : new();
+                action.Data.OperInfo = CurOperInfo(input.Locale);
                 //action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氭彁浜ゆ搷浣滄暟鎹紓甯�");
                 action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException"));
             }
@@ -243,8 +260,8 @@
                     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()
@@ -277,7 +294,7 @@
                         action.Data.ShortMsg = new("宸ュ崟閿欒", ShortMessage.Types.Error);
                         action.IsSuccessed = false;
                         //action.LocaleMsg = new($"浜у搧[{CurSN}]涓嶅睘浜庡綋鍓嶅伐鍗曪紝璇峰垏鎹㈠埌宸ュ崟[{wipSNs.First().WORK_ORDER}]鍚庡啀鎵弿");
-                        action.LocaleMsg = new("MES.Transaction.PackingNode.NodeSubmit.WoError", CurSN, wipSNs.First().WORK_ORDER);
+                        action.LocaleMsg = new("MES.Transaction.PackingNode.NodeSubmit.WoError", input.SN, wipSNs.First().WORK_ORDER);
                         return action;
                     }
                     else
@@ -285,7 +302,7 @@
                         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.PackingNode.NodeSubmit.LineError", CurSN, wipSNs.First().LINE_CODE);
+                        action.LocaleMsg = new("MES.Transaction.PackingNode.NodeSubmit.LineError", input.SN, wipSNs.First().LINE_CODE);
                         return action;
                     }
                 }
@@ -486,6 +503,7 @@
                     }
 
                     //瀹屾垚绗竴涓伐搴忚妭鐐瑰伐姝�
+                    curStep.IsFinished = true;
                     curStep.Status = StepStatus.Finished;
                     CurStep = curStep;
                 } 
@@ -494,6 +512,7 @@
                     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;
                 }
@@ -556,8 +575,8 @@
             SaveStepsCommitActionToDB();
 
             //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭�
-            OperInfoDic[CurBatch.Batch.BATCH_NO].InputQty += CurWipSNs.Count;
-            action.Data.OperInfo = SetOperNodeInfo(OperInfoDic[CurBatch.Batch.BATCH_NO], locale);
+            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>());
@@ -572,7 +591,7 @@
         /// 鍖呰宸ュ簭锛氭墜鍔ㄧ粨鏉熷寘瑁�
         /// </summary>
         /// <returns></returns>
-        public async Task<ApiAction<SubmitOutput>> CompletePkg()
+        public async Task<ApiAction<SubmitOutput>> CompletePkg(ApiAction input)
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
             try
@@ -582,10 +601,24 @@
                 {
                     if (Context.ContainsKey("CurPackage"))
                     {
+                        var CurPkg = Context["CurPackage"] as WipPkg;
+                        int shipQty = input.Data.ToInt32();
+    
                         NodeCmd = "PkgSubmit";
 
                         TempPkgAction = new PackingAction();
-                        TempPkgAction.Init(null, this, null, null);
+                        TempPkgAction.Init(this);
+
+                        int curQty = CurPkg.Item.TotalQty;
+                        int ruleQty = TempPkgAction.PkgRule.GetTotalQty();
+                        //鏈夊~鍑鸿揣鏁伴噺鍒欓獙璇佸綋鍓嶅寘瑁呮暟閲忓繀椤荤瓑浜庯紙鍑鸿揣鏁伴噺/鍖呰瑙勫垯鏁伴噺锛夌殑浣欐暟
+                        if (shipQty > 0 &&  curQty != shipQty % ruleQty)
+                        {
+                            action.IsSuccessed = false;
+                            //action.LocaleMsg = new($"鍑鸿揣鏁伴噺璁惧畾涓篬{0}]锛岀洰鍓嶅寘瑁呬簡[{1}]锛屽寘瑁呭熬鏁扮殑鏁伴噺蹇呴渶鏄痆{2}]锛岃瑁呭鏁伴噺鍚庡啀缁撴潫鍖呰");
+                            action.LocaleMsg = new("MES.Transaction.PackingNode.NotMatchShipQty", shipQty, curQty, shipQty % ruleQty); 
+                            return action;
+                        }
                         action = TempPkgAction.Submit(null);
                     }
                     else

--
Gitblit v1.9.3