From 76e99e160320c9d612feb0861fc9e2b0075172e9 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期五, 25 十月 2024 19:32:29 +0800
Subject: [PATCH] 删除PackingNode多余逻辑

---
 Tiger.Business.MES/Transaction/PackingNode.cs |   81 ++++++++++++++++++++--------------------
 1 files changed, 40 insertions(+), 41 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/PackingNode.cs b/Tiger.Business.MES/Transaction/PackingNode.cs
index ebf4b87..2884e5f 100644
--- a/Tiger.Business.MES/Transaction/PackingNode.cs
+++ b/Tiger.Business.MES/Transaction/PackingNode.cs
@@ -48,16 +48,6 @@
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
             try
             {
-                if (input.Qty.ToInt32() <= 0)
-                {
-                    action.Data.ShortMsg = new("璇疯緭鍏ュ寘瑁呮暟閲�", ShortMessage.Types.Error);
-                    action.Data.OperInfo = new();
-                    action.Data.Data = "QtyError";
-                    action.IsSuccessed = false;
-                    action.LocaleMsg = new($"鍖呰鏁伴噺[{input.Qty}]涓嶆纭紝璇烽噸鏂拌緭鍏ユ暟閲忓悗缁х画鍖呰鎿嶄綔");
-                    //action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.QtyError", input.Qty);
-                    return action;
-                }
                 //PkgSubmit锛氭墜鍔ㄧ粨鏉熷寘瑁咃紝鎵嬪姩淇濆瓨鏆傚瓨鐨勫寘瑁呮暟鎹�
                 if (NodeCmd == "PkgSubmit")
                 {
@@ -89,7 +79,7 @@
                                 info.InputQty = CurOperInfo(input.Locale).InputQty;
                                 action.Data.OperInfo = info;
                             }
-                            else if (!IsFinishAllSteps)
+                            else if (Steps.Any() && !IsFinishAllSteps)
                             {
                                 action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale));
                             }
@@ -114,13 +104,14 @@
                                     action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN);
                                     return action;
                                 }
-                                if (Context.ContainsKey("CurPackage") && !Context["CurPackage"].IsNullOrEmpty() && (Context["CurPackage"] as WipPkg).WorkBatch != curSNs.First().Batch.BATCH_NO)
+                                var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
+                                if (!curPkg.IsNullOrEmpty() && !curPkg.IsFinished && curPkg.WorkBatch != curSNs.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, curSNs.First().Batch.BATCH_NO, input.SN);
+                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.BatchError", curPkg.WorkBatch, curSNs.First().Batch.BATCH_NO, input.SN);
                                     return action;
                                 }
                                 if (curSNs.First().Batch.ACT_LINE != CurLine.LINE_CODE)
@@ -165,29 +156,30 @@
                             //鏌ユ壘涓嶅埌鏉$爜宸茬粦瀹氱殑宸ュ崟
                             else
                             {
-                                //娌℃湁褰撳墠宸ュ崟锛屽垯鍏堥�夋嫨宸ュ崟鍚庡啀鎵弿鏉$爜
-                                if (CurBatch.IsNullOrEmpty())
+                                var lastSn = wosns.OrderByDescending(q => q.SN.UPDATE_TIME).FirstOrDefault();
+                                if (!lastSn.IsNullOrEmpty())
                                 {
-                                    action.Data.ShortMsg = new("鏈�夋嫨宸ュ崟", ShortMessage.Types.Error);
+                                    action.Data.ShortMsg = new($"浜у搧{lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()}", ShortMessage.Types.Error);
                                     action.Data.OperInfo = new();
                                     action.IsSuccessed = false;
-                                    //action.LocaleMsg = new($"鏈�夋嫨宸ュ崟锛岃鍏堥�夋嫨瑕佺敓浜х殑宸ュ崟");
-                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotSelectOrderException");
+                                    //action.LocaleMsg = new($"杩涚珯鎵弿閿欒锛屾潯鐮乕{0}]{1}", input.SN);
+                                    action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.SnStatusError", input.SN, lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>());
                                 }
-                                //鏈夊綋鍓嶅伐鍗曚笖涓嶆槸鎶曞叆锛屽垯鎻愮ず鏉$爜鏈姇鍏ョ敓浜э紝璇峰厛鍘婚绔欐壂鎻�
                                 else
                                 {
-                                    var lastSn = wosns.OrderByDescending(q => q.SN.UPDATE_TIME).FirstOrDefault();
-                                    if (!lastSn.IsNullOrEmpty())
+                                    //娌℃湁褰撳墠宸ュ崟锛屽垯鍏堥�夋嫨宸ュ崟鍚庡啀鎵弿鏉$爜
+                                    if (CurBatch.IsNullOrEmpty())
                                     {
-                                        action.Data.ShortMsg = new($"浜у搧{lastSn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()}", ShortMessage.Types.Error);
+                                        action.Data.ShortMsg = new("鏈�夋嫨宸ュ崟", ShortMessage.Types.Error);
                                         action.Data.OperInfo = new();
                                         action.IsSuccessed = false;
-                                        //action.LocaleMsg = new($"杩涚珯鎵弿閿欒锛屾潯鐮乕{0}]{1}", input.SN);
-                                        action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotInputException", input.SN);
+                                        //action.LocaleMsg = new($"鏈�夋嫨宸ュ崟锛岃鍏堥�夋嫨瑕佺敓浜х殑宸ュ崟");
+                                        action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.NotSelectOrderException");
                                     }
+                                    //鏈夊綋鍓嶅伐鍗曚笖涓嶆槸鎶曞叆锛屽垯鎻愮ず鏉$爜鏈姇鍏ョ敓浜э紝璇峰厛鍘婚绔欐壂鎻�
                                     else
                                     {
+
                                         action.Data.ShortMsg = new("鏈姇鍏ョ敓浜�", ShortMessage.Types.Error);
                                         action.Data.OperInfo = new();
                                         action.IsSuccessed = false;
@@ -475,7 +467,7 @@
                     CurWipSNHiss.Clear();
                     foreach (var wipSN in wipSNs)
                     {
-                        var his = 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}]鎴愬姛锛圱ransId锛歿TransID}锛�");
                         wipSN.History.Add(his);
                         CurWipSNHiss.Add(his);
                     }
@@ -621,12 +613,18 @@
         /// <returns></returns>
         public ApiAction<SubmitOutput> DoIfFinishAllSteps(ApiAction<SubmitOutput> action, string locale)
         {
+            var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
             var operInfo = SetOperNodeInfo(CurOperInfo(locale));
             Action endAction = null;
 
             //濡傛灉褰撳墠鏉$爜宸茬粡璧板埌娴佺▼缁堢偣鍒欒褰曟潯鐮佸畬宸�
             if (operInfo.IsReachedEndNode)
             {
+                //鏍囪褰撳墠鍖呰淇℃伅涓虹粓鐐圭珯
+                if (!curPkg.IsNullOrEmpty())
+                {
+                    curPkg.IsReachedEndNode = true;
+                }
                 //鏇存柊宸ュ崟鏉$爜鏄庣粏淇℃伅
                 var woSNs = CurBatch.WoSNs.Where(q => CurWipSNs.Any(w => q.WIP_ID == w.ID)).ToList();
                 foreach (var woSN in woSNs)
@@ -642,6 +640,7 @@
                     wipSN.NODE_NAME = curNode.NODE_NAME;
                     wipSN.OPER_CODE = curNode.OPER_CODE;
                     wipSN.SEGMENT = curNode.SEGMENT;
+                    wipSN.OPERATION_TIME = DateTime.Now;
                 }
 
                 var wipHiss = new List<MES_WIP_HIS>();
@@ -656,15 +655,28 @@
                 var _woSns = woSNs.Clone();
                 var _wipSns = CurWipSNs.Clone();
                 var _wipHiss = wipHiss.Clone();
+                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item) : new();
                 //淇濆瓨鏁版嵁
                 endAction = () =>
                 {
                     //浣跨敤缁熶竴鐨勪簨鍔B瀵硅薄
                     var db = GetCommitDB();
                     //鏁版嵁淇濆瓨閫昏緫
-                    db.Storageable(_woSns, UserCode).ExecuteCommand();
-                    db.Storageable(_wipSns, UserCode).ExecuteCommand();
+                    db.Updateable(_woSns, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS }).ExecuteCommand();
+                    db.Updateable(_wipSns, UserCode).UpdateColumns(q => new { q.UPDATE_TIME, q.UPDATE_USER, q.STATUS, q.NODE_ID, q.NODE_NAME, q.OPER_CODE, q.SEGMENT, q.OPERATION_TIME }).ExecuteCommand();
                     db.Storageable(_wipHiss, UserCode).ExecuteCommand();
+                    if (_pkgList.Any())
+                    {
+                        var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList();
+                        var wo = _pkgList.First().WORK_ORDER;
+                        //鍖呰淇℃伅淇濆瓨鍒扮敓浜ц繃绋嬭褰�
+                        db.Updateable<MES_WIP_HIS>()
+                            .SetColumns(q => q.TRAY_SN == curPkg.Item.Package.SN)
+                            .SetColumns(q => q.INNER_SN == q.CARTON_SN)
+                            .SetColumns(q => q.CARTON_SN == curPkg.Item.Package.SN)
+                            .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && wipIDs.Contains(q.WIP_ID))
+                            .ExecuteCommand();
+                    }
                 };
             }
 
@@ -673,7 +685,7 @@
 
             //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭�
             CurOperInfo(locale).InputQty += CurWipSNs.Count;
-            action.Data.Data = new PackingActionOutput() { PkgInfo = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null };
+            action.Data.Data = new PackingActionOutput() { PkgInfo = curPkg };
             action.Data.OperInfo = operInfo;
             action.Data.ShortMsg = new(CurWipSNs.Any(q => q.DFT_FLAG == "Y") ? "涓嶈壇杩囩珯" : "鑹搧杩囩珯", ShortMessage.Types.Success);
             //action.LocaleMsg = new($"宸ュ崟[{CurWipSN.WORK_ORDER}]鐨勬潯鐮乕{CurWipSN.SN}]鍦ㄥ矖浣峓{CurWipSN.POST_CODE}]宸ュ簭[{CurWipSN.NODE_NAME}]杩囩珯鎴愬姛锛岀姸鎬乕{CurWipSN.STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()}]");
@@ -707,19 +719,6 @@
                     {
                         TempPkgAction = new PackingAction();
                         TempPkgAction.Init(this);
-
-                        var CurPkg = Context["CurPackage"] as WipPkg;
-                        int shipQty = input.Data.ToInt32();
-                        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;
-                        }
 
                         NodeCmd = "PkgSubmit";
                         action = TempPkgAction.Submit(null);

--
Gitblit v1.9.3