From a96b665105c57a4ae67d286b2bb6897988ca590e Mon Sep 17 00:00:00 2001
From: Ben Lin <maobin001@msn.com>
Date: 星期三, 20 十一月 2024 20:52:58 +0800
Subject: [PATCH] 雅达装箱工序:打印测试标签

---
 Tiger.Business.MES/Transaction/YadaPacking.cs                  |   28 +++++++
 Tiger.Business.MES/Transaction/Position.cs                     |  118 ++++++++++++++++++++---------
 Tiger.IBusiness.MES/Transaction/IYadaPacking.cs                |    6 +
 Tiger.Controllers.MES/Controllers/MESController.YadaPacking.cs |   44 +++++++++++
 Tiger.IBusiness.MES/Transaction/IPosition.cs                   |    2 
 5 files changed, 159 insertions(+), 39 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index 88b16c2..c52ef1d 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/Tiger.Business.MES/Transaction/Position.cs
@@ -514,6 +514,11 @@
         /// <returns></returns>
         public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action)
         {
+            return SetLabelVariables(labelPVs, label, action, null);
+        }
+
+        public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action, WipPkg? CurPkg)
+        {
             foreach (var item in label.Variables.OrderBy(q => q.VAR_TYPE == BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate.GetValue() ? 0 : 1))
             {
                 switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>())
@@ -522,7 +527,7 @@
                         item.Value = item.VAR_VALUE;
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable:
-                        item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action);
+                        item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action, CurPkg);
                         break;
                     case BAS_LABEL_VAR.VAR_TYPEs.DateVariable:
                         item.Value = DateTime.Now.ToString(item.VAR_VALUE);
@@ -545,7 +550,7 @@
         /// <param name="labelPVs">杩囩▼鍙橀噺鍒楄〃</param>
         /// <param name="lv">鏍囩妯℃澘鍙橀噺</param>
         /// <returns></returns>
-        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction curAction)
+        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction curAction, WipPkg? CurPkg)
         {
             var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE);
             if (!pv.IsNullOrEmpty())
@@ -571,15 +576,22 @@
                                 case "GetPackNumber":
                                     return GetLabelVarWo(lv, WorkBatch.WO.ORDER_NO);
                                 case "GetBoxQR":
-                                    return GetCardOrBoxQR(GetBoxCode(), curAction);
+                                    return GetCardOrBoxQR(GetBoxCode(), curAction, CurPkg);
                                 case "GetCardQR":
-                                    return GetCardOrBoxQR("", curAction);
+                                    return GetCardOrBoxQR("", curAction, CurPkg);
                                 case "GetCardSN":
                                     List<string> minPkgList = new List<string>();
-                                    var _pkaction = curAction is PackingAction ? curAction as PackingAction : null;
-                                    if (_pkaction != null)
+                                    if (!CurPkg.IsNullOrEmpty())
                                     {
-                                        minPkgList = GetMinPkgList(_pkaction);
+                                        minPkgList = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                    }
+                                    else
+                                    {
+                                        var _pkaction = curAction is PackingAction ? curAction as PackingAction : null;
+                                        if (!_pkaction.IsNullOrEmpty())
+                                        {
+                                            minPkgList = GetMinPkgList(_pkaction);
+                                        }
                                     }
                                     return string.Join("\r\n", minPkgList);
                                 case "GetDescription":
@@ -592,21 +604,35 @@
                                     return GetLabelVarWo(lv, WorkBatch.WO.Customer?.CUST_NAME_CN);
                                 case "GetHWDate":
                                     List<string> list = new List<string>();
-                                    var _action = curAction is PackingAction ? curAction as PackingAction : null;
-                                    if (_action != null)
+                                    if (!CurPkg.IsNullOrEmpty())
                                     {
-                                        list = GetMinPkgList(_action);
+                                        list = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                    }
+                                    else
+                                    {
+                                        var _action = curAction is PackingAction ? curAction as PackingAction : null;
+                                        if (_action != null)
+                                        {
+                                            list = GetMinPkgList(_action);
+                                        }
                                     }
                                     return GetHuaWeiWeek(WorkBatch.Batch.ORDER_NO, list);
                                 case "GetQty":
                                     List<string> qtylist = new List<string>();
-                                    if (curAction is PackingAction)
+                                    if (!CurPkg.IsNullOrEmpty())
                                     {
-                                        qtylist = GetMinPkgList(curAction as PackingAction);
+                                        qtylist = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
                                     }
-                                    if (curAction is PrintInStoreLabel)
+                                    else
                                     {
-                                        qtylist = (curAction as PrintInStoreLabel).CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                        if (curAction is PackingAction)
+                                        {
+                                            qtylist = GetMinPkgList(curAction as PackingAction);
+                                        }
+                                        if (curAction is PrintInStoreLabel)
+                                        {
+                                            qtylist = (curAction as PrintInStoreLabel).CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                        }
                                     }
                                     return $"{qtylist.Count}";
                                 case "GetModel":
@@ -624,18 +650,24 @@
                                 case "GetLOTNO":
                                     string _lotnos = "";
                                     var _orderAction = curAction is PackingAction ? curAction as PackingAction : null;
-                                    if (_orderAction != null)
+                                    if (!CurPkg.IsNullOrEmpty())
                                     {
-                                        //var snList = _orderAction.CurPkg.Item.GetMinPackageList().Select(q => q.FLOW_SN).ToList();
-                                        var snList = _orderAction.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
-                                        if (!snList.Any())
+                                        qtylist = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                    }
+                                    else
+                                    {
+                                        if (_orderAction != null)
                                         {
-                                            snList.Add(_orderAction.CurPkg.CustSN?.FLOW_SN);
+                                            var snList = _orderAction.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                                            if (!snList.Any())
+                                            {
+                                                snList.Add(_orderAction.CurPkg.CustSN?.FLOW_SN);
+                                            }
+                                            _lotnos = string.Join(",", Biz.Db.Queryable<MES_CUST_SN>()
+                                                .Where((q) => snList.Contains(q.FLOW_SN))
+                                                .Select((q) => q.WORK_ORDER).Distinct().ToList());
+                                            return _lotnos;
                                         }
-                                        _lotnos = string.Join(",", Biz.Db.Queryable<MES_CUST_SN>()
-                                            .Where((q) => snList.Contains(q.FLOW_SN))
-                                            .Select((q) => q.WORK_ORDER).Distinct().ToList());
-                                        return _lotnos;
                                     }
                                     return "";
                                 case "GetNOTES":
@@ -761,29 +793,39 @@
         /// <param name="lvars"></param>
         /// <param name="action"></param>
         /// <returns></returns>
-        private string GetCardOrBoxQR(string code, IWorkAction action)
+        private string GetCardOrBoxQR(string code, IWorkAction action, WipPkg? CurPkg)
         {
             List<string> minPkgList = new List<string>();
             var itemCode = "";
             double weight = 0;
             var unit = "";
-            if (action is PackingAction)
+            if (!CurPkg.IsNullOrEmpty())
             {
-                var pkg = action as PackingAction;
-                //minPkgList = pkg.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList();
-                minPkgList = pkg.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
-                itemCode = pkg.CurPkg.CustSN?.ITEM_CODE;
-                weight = pkg.CurPkg.WeightInfo.Weight;
-                unit = pkg.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg";
+                minPkgList = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                itemCode = CurPkg.CustSN?.ITEM_CODE;
+                weight = CurPkg.WeightInfo.Weight;
+                unit = CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg";
             }
-            if (action is PrintInStoreLabel)
+            else
             {
-                var print = action as PrintInStoreLabel;
-                //minPkgList = print.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList();
-                minPkgList = print.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
-                itemCode = print.CurPkg.CustSN?.ITEM_CODE;
-                weight = print.CurPkg.WeightInfo.Weight;
-                unit = print.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg";
+                if (action is PackingAction)
+                {
+                    var pkg = action as PackingAction;
+                    //minPkgList = pkg.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList();
+                    minPkgList = pkg.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                    itemCode = pkg.CurPkg.CustSN?.ITEM_CODE;
+                    weight = pkg.CurPkg.WeightInfo.Weight;
+                    unit = pkg.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg";
+                }
+                if (action is PrintInStoreLabel)
+                {
+                    var print = action as PrintInStoreLabel;
+                    //minPkgList = print.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList();
+                    minPkgList = print.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList();
+                    itemCode = print.CurPkg.CustSN?.ITEM_CODE;
+                    weight = print.CurPkg.WeightInfo.Weight;
+                    unit = print.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg";
+                }
             }
             var wo = WorkBatch.Batch.ORDER_NO;
             var snList = string.Join("\r\n", minPkgList);
diff --git a/Tiger.Business.MES/Transaction/YadaPacking.cs b/Tiger.Business.MES/Transaction/YadaPacking.cs
index 562f8fa..e05068c 100644
--- a/Tiger.Business.MES/Transaction/YadaPacking.cs
+++ b/Tiger.Business.MES/Transaction/YadaPacking.cs
@@ -878,6 +878,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>
diff --git a/Tiger.Controllers.MES/Controllers/MESController.YadaPacking.cs b/Tiger.Controllers.MES/Controllers/MESController.YadaPacking.cs
index 42477bd..3440350 100644
--- a/Tiger.Controllers.MES/Controllers/MESController.YadaPacking.cs
+++ b/Tiger.Controllers.MES/Controllers/MESController.YadaPacking.cs
@@ -277,5 +277,49 @@
             return Ok(response);
         }
 
+        /// <summary>
+        /// 闆呰揪瑁呯宸ュ簭锛氭墦鍗版祴璇曟爣绛�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        [HttpPost]
+        [Route("api/[controller]/YadaPacking/TestPrint")]
+        public async Task<IActionResult> YadaPacking_TestPrintAsync([FromBody] ApiAction action)
+        {
+            ApiAction response;
+            IYadaPacking trans = null;
+            try
+            {
+                if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
+                {
+                    trans = iBiz.MES.Context.GetTransDic()[action.ID] as IYadaPacking;
+                    if (!trans.IsFinished)
+                    {
+                        if (action.IsAsync)
+                        {
+                            response = action.GetResponse(await trans.TestPrint());
+                        }
+                        else
+                        {
+                            lock (trans.TransLock) { response = action.GetResponse(trans.TestPrint().Result); }
+                        }
+                    }
+                    else
+                    {
+                        response = action.GetResponse($"Transaction Error: 宀椾綅[{trans.PostCode}]鐨勯泤杈捐绠卞伐搴忎簨鍔ID:{action.ID}]宸茬粡鍏抽棴", false);
+                    }
+                }
+                else
+                {
+                    response = action.GetResponse($"Transaction Error: 宀椾綅鐨勯泤杈捐绠卞伐搴忎簨鍔ID:{action.ID}]宸茬粡琚叧闂�", false);
+                }
+            }
+            catch (System.Exception ex)
+            {
+                response = action.GetResponse().CatchExceptionWithLog(ex);
+            }
+            trans?.AddHistory(Request, action);
+            return Ok(response);
+        }
     }
 }
diff --git a/Tiger.IBusiness.MES/Transaction/IPosition.cs b/Tiger.IBusiness.MES/Transaction/IPosition.cs
index e3116a0..c90e1d9 100644
--- a/Tiger.IBusiness.MES/Transaction/IPosition.cs
+++ b/Tiger.IBusiness.MES/Transaction/IPosition.cs
@@ -72,7 +72,7 @@
         /// <param name="labelPVs">杩囩▼鍙橀噺鍒楄〃</param>
         /// <param name="lv">鏍囩妯℃澘鍙橀噺</param>
         /// <returns></returns>
-        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction action);
+        public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction curAction, WipPkg? CurPkg);
         /// <summary>
         /// 鏍规嵁浼犲叆鐨勫寘瑁呭璞¤繑鍥炴墍鏈夌殑鍖呰瀹炰綋鍒楄〃
         /// </summary>
diff --git a/Tiger.IBusiness.MES/Transaction/IYadaPacking.cs b/Tiger.IBusiness.MES/Transaction/IYadaPacking.cs
index 274b6e4..644dc4b 100644
--- a/Tiger.IBusiness.MES/Transaction/IYadaPacking.cs
+++ b/Tiger.IBusiness.MES/Transaction/IYadaPacking.cs
@@ -39,5 +39,11 @@
         /// </summary>
         /// <returns></returns>
         public Task<ApiAction<SubmitOutput>> CompletePkg(ApiAction input);
+        /// <summary>
+        /// 鍖呰宸ュ簭锛氭墦鍗版祴璇曟爣绛�
+        /// </summary>
+        /// <param name="input"></param>
+        /// <returns></returns>
+        public Task<ApiAction<PackingActionOutput>> TestPrint();
     }
 }

--
Gitblit v1.9.3