From a55e502c37bdc2831fc904c08961e9bca7778ae7 Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期四, 21 十一月 2024 12:05:29 +0800
Subject: [PATCH] 工序的一些优化

---
 Tiger.Business.MES/Transaction/YadaPacking.cs |   70 ++++++++++++++++++++++++++--------
 1 files changed, 53 insertions(+), 17 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/YadaPacking.cs b/Tiger.Business.MES/Transaction/YadaPacking.cs
index dc47684..79d769a 100644
--- a/Tiger.Business.MES/Transaction/YadaPacking.cs
+++ b/Tiger.Business.MES/Transaction/YadaPacking.cs
@@ -36,6 +36,7 @@
         public string NodeCmd { get; set; }
         public PackingAction TempPkgAction { get; set; }
         public bool IsPrintCustomerLabel { get; set; }
+        public string ShippingOrder { get; set; }
         #endregion Propertys & Variables
 
         #region Functions
@@ -49,19 +50,23 @@
             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;
-                }
+                //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;
+                //}
                 if (input.Options.ContainsKey("IsPrintCustomerLabel"))
                 {
                     IsPrintCustomerLabel = input.Options["IsPrintCustomerLabel"].ToBoolean();
+                }
+                if (input.Options.ContainsKey("ShippingOrder"))
+                {
+                    ShippingOrder = IsPrintCustomerLabel ? input.Options["ShippingOrder"].ToString() : "";
                 }
                 //PkgSubmit锛氭墜鍔ㄧ粨鏉熷寘瑁咃紝鎵嬪姩淇濆瓨鏆傚瓨鐨勫寘瑁呮暟鎹�
                 if (NodeCmd == "PkgSubmit")
@@ -318,7 +323,7 @@
                         return woStatus;
                     }
 
-                    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).Where(q => q.STATUS < MES_WIP_DATA.STATUSs.Finished.GetValue()).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).Where(q => q.FINISHED_FLAG != "Y").ToList();
                     if (wipSNs.IsNullOrEmpty())
                     {
                         var wipSN = new MES_WIP_DATA()
@@ -418,6 +423,8 @@
                         wipSN.OPER_CODE = curNode.OPER_CODE;
                         wipSN.SEGMENT = curNode.SEGMENT;
                         wipSN.OPERATION_TIME = DateTime.Now;
+                        wipSN.SHIPPING_ORDER = ShippingOrder;
+                        wipSN.UNBIND_FLAG = "N";
                         var curShiftPeriod = GetShiftPeriodForNow();
                         if (!curShiftPeriod.IsNullOrEmpty())
                         {
@@ -438,7 +445,7 @@
                         {
                             var woSN = woSNs.First(q => q.WIP_ID == wipSN.ID);
                             woSN.STATUS = BIZ_MES_WO_SN.STATUSs.Finished.GetValue();
-                            wipSN.STATUS = MES_WIP_DATA.STATUSs.Finished.GetValue();
+                            wipSN.STATUS = MES_WIP_DATA.STATUSs.Output.GetValue();
                             wipSN.OUTLINE_DATE = DateTime.Now;
                         }
                         //濡傛灉鏈夋彁浜や笉鑹�
@@ -672,7 +679,7 @@
                 //鏉$爜瀹屽伐
                 foreach (var wipSN in CurWipSNs)
                 {
-                    wipSN.STATUS = MES_WIP_DATA.STATUSs.Finished.GetValue();
+                    wipSN.FINISHED_FLAG = "Y";
                     wipSN.NODE_ID = curNode.ID;
                     wipSN.NODE_NAME = curNode.NODE_NAME;
                     wipSN.OPER_CODE = curNode.OPER_CODE;
@@ -692,7 +699,8 @@
                 var _woSns = woSNs.Clone();
                 var _wipSns = CurWipSNs.Clone();
                 var _wipHiss = wipHiss.Clone();
-                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item) : new();
+                var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item).Clone() : new();
+                var _wipIDs = curPkg?.IsFinished == true ? curPkg.Item.GetWipSnList().Select(q => q.Key).ToList().Clone() : new();
                 //淇濆瓨鏁版嵁
                 endAction = () =>
                 {
@@ -704,14 +712,14 @@
                     db.Storageable(_wipHiss, UserCode).ExecuteCommand();
                     if (_pkgList.Any())
                     {
-                        var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList();
+                        //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>(UserCode)
                             .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))
+                            .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && _wipIDs.Contains(q.WIP_ID))
                             .ExecuteCommand();
                     }
                 };
@@ -828,7 +836,7 @@
                         TempPkgAction.Init(this);
 
                         int shipQty = input.Data.ToInt32();
-                        int curQty = CurPkg.Item.TotalQty;
+                        double curQty = CurPkg.Item.TotalQty;
                         int ruleQty = TempPkgAction.PkgRule.GetTotalQty();
                         //鏈夊~鍑鸿揣鏁伴噺鍒欓獙璇佸綋鍓嶅寘瑁呮暟閲忓繀椤荤瓑浜庯紙鍑鸿揣鏁伴噺/鍖呰瑙勫垯鏁伴噺锛夌殑浣欐暟
                         if (shipQty > 0 && curQty != shipQty % ruleQty)
@@ -872,6 +880,34 @@
             return action;
         }
 
+        /// <summary>
+        /// 鎵撳嵃娴嬭瘯鏍囩
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public async Task<ApiAction<PackingActionOutput>> TestPrint()
+        {
+            var action = new ApiAction<PackingActionOutput>();
+            try
+            {
+                var CurPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null;
+                var LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList();
+                var label = CurPkg.Item.LABEL_CODE.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == CurPkg.Item.LABEL_CODE).IncludesAllFirstLayer().First();
+                var printLb =  SetLabelVariables(LabelPV, label, new PackingAction(), CurPkg);
+                action.Data = new PackingActionOutput()
+                {
+                    ExecCode = "PrintTest",
+                    PkgInfo = CurPkg,
+                    PrintLable = printLb,
+                };
+            }
+            catch (Exception ex)
+            {
+                action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氭墦鍗版祴璇曟爣绛惧紓甯�");
+            }
+            return action;
+        }
+
         #endregion Functions
 
         /// <summary>

--
Gitblit v1.9.3