From d0eb14b78b4d84c3e77a917da25e82750b4de335 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期二, 15 十月 2024 16:27:49 +0800
Subject: [PATCH] 优化注释

---
 Tiger.Business.MES/Transaction/Position.cs |  121 ++++++++++++++++++++++++++++++---------
 1 files changed, 92 insertions(+), 29 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index 0ab06c3..d0b6c7f 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/Tiger.Business.MES/Transaction/Position.cs
@@ -13,6 +13,7 @@
 using Tiger.Model.Entitys.MES.Position;
 using System.Globalization;
 using Tiger.Business.MES.WorkAction;
+using System.Collections;
 
 namespace Tiger.Business.MES.Transaction
 {
@@ -96,12 +97,12 @@
         /// </summary>
         /// <param name="input"></param>
         /// <returns></returns>
-        public async Task<ApiAction> SelectOrder(WoInput input)
+        public async Task<ApiAction> SelectOrder(WoInput input, string batchNo = "")
         {
             var action = new ApiAction();
             try
             {
-                if (!WoContext.ExistsBatch(input.OrderNo, CurLine.LINE_CODE))
+                if (!WoContext.ExistsBatch(input.OrderNo, CurLine.LINE_CODE, batchNo, true))
                 {
                     var wo = await Biz.Db.Queryable<BIZ_MES_WO>().ByAuth(input.AuthOption).Where(q => q.ORDER_NO == input.OrderNo).FirstAsync();
                     //楠岃瘉鏄庣粏鏄惁姝g‘
@@ -115,11 +116,14 @@
                     if (wo.STATUS != BIZ_MES_WO.STATUSs.Release.GetValue() && wo.STATUS != BIZ_MES_WO.STATUSs.Working.GetValue())
                     {
                         action.IsSuccessed = false;
-                        //action.LocaleMsg = new($"宸ュ崟[{input.OrderNo}]鐘舵�乕{wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>().GetName()}]涓嶈兘鐢熶骇");
+                        //action.LocaleMsg = new($"宸ュ崟[{0}]鐘舵�乕{1}]涓嶈兘鐢熶骇");
                         action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>().GetName());
                         return action;
                     }
-                    var batch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().ByAuth(input.AuthOption).Where(q => q.ORDER_NO == input.OrderNo && q.ACT_LINE == CurLine.LINE_CODE).FirstAsync();
+                    var batch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().ByAuth(input.AuthOption)
+                        .Where(q => q.ORDER_NO == input.OrderNo && q.ACT_LINE == CurLine.LINE_CODE)
+                        .WhereIF(!batchNo.IsNullOrEmpty(), q => q.BATCH_NO == batchNo)
+                        .OrderBy(q => q.STATUS).FirstAsync();
                     if (batch.IsNullOrEmpty())
                     {
                         action.IsSuccessed = false;
@@ -130,14 +134,14 @@
                     if (batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() && batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Working.GetValue())
                     {
                         action.IsSuccessed = false;
-                        //action.LocaleMsg = new($"宸ュ崟[{input.OrderNo}]鐘舵�乕{wo.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName()}]涓嶈兘鐢熶骇");
-                        action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName());
+                        //action.LocaleMsg = new($"宸ュ崟[{0}]鎵规[1]鐘舵�乕{2}]涓嶈兘鐢熶骇");
+                        action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.BatchStatusException", input.OrderNo, batch.BATCH_NO, batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName());
                         return action;
                     }
                     var wb = new WorkBatch(input.OrderNo).Init(CurLine.LINE_CODE);
                     WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb);
                 }
-                CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE);
+                CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE, batchNo);
                 if (!OperInfoDic.ContainsKey(CurBatch.Batch.BATCH_NO))
                 {
                     OperInfoDic.Add(CurBatch.Batch.BATCH_NO, new());
@@ -221,7 +225,12 @@
             if (CurWipSNs.Any())
             {
                 info.CurNode = CurWipSNs.First().NODE_NAME;
-                info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME));
+                var nextNodes = CurBatch.GetNextNodes(CurWipSNs.First());
+                info.NextNode = string.Join(",", nextNodes.Select(q => q.NODE_NAME));
+                if (nextNodes.Count == 1 && nextNodes.Single().OPER_CODE == "EndNode")
+                {
+                    info.IsReachedEndNode = true;
+                }
             }
             else
             {
@@ -550,8 +559,18 @@
                                     return action is PackingAction ? GetBoxCode(lvars, action as PackingAction) : "";
                                 case "GetCardQR":
                                     return action is PackingAction ? GetCardCode(lvars, action as PackingAction) : "";
+                                case "GetCardSN":
+                                    List<string> minPkgList = new List<string>();
+                                    var _pkaction = action is PackingAction ? action as PackingAction : null;
+                                    if (_pkaction != null)
+                                    {
+                                        minPkgList = GetMinPkgList(_pkaction);
+                                    }
+                                    return string.Join("\r\n", minPkgList);
                                 case "GetDescription":
-                                    return WorkBatch.Product.ExtInfo.Packaging; //WorkBatch.Product.ITEM_DESC;
+                                    return WorkBatch.Product.ITEM_DESC;
+                                case "GetFengZ":
+                                    return WorkBatch.Product.ExtInfo.Packaging; 
                                 case "GetPAndO":
                                     return WorkBatch.WO.SALES_CONTRACT;
                                 case "GetLTD":
@@ -559,25 +578,29 @@
                                 case "GetHWDate":
                                     List<string> list = new List<string>();
                                     var _action = action is PackingAction ? action as PackingAction : null;
-                                    if (_action.CurPkg.Item.PKG_LEVEL == 1)
+                                    if (_action!=null)
                                     {
-                                        list.Add(CurSN);
-                                    }
-                                    else
-                                    {
-                                        list = _action != null ? _action.GetMinPackageList(_action.CurPkg.Item).Select(q => q.SN).ToList() : new List<string>();
+                                        list = GetMinPkgList(_action);
                                     }
                                     return GetHuaWeiWeek(WorkBatch.Batch.ORDER_NO, list);
+                                case "GetQty":
+                                    List<string> qtylist = new List<string>();
+                                    var _qtyAction = action is PackingAction ? action as PackingAction : null;
+                                    if (_qtyAction != null)
+                                    {
+                                        qtylist = GetMinPkgList(_qtyAction);
+                                    }
+                                    return $"{qtylist.Count}PCS";
                                 case "GetModel":
-                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Model);
-                                case "GetInput":
-                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Input);
-                                case "GetOutput":
-                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.OutPut);
-                                case "GetPower":
-                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Power);
-                                case "GetAccuracy":
-                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Accuracy);
+                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Model);
+                                case "GetInput":                                      
+                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Input);
+                                case "GetOutput":                                     
+                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.OutPut);
+                                case "GetPower":                                      
+                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Power);
+                                case "GetAccuracy":                                   
+                                    return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Accuracy);
                                 case "GetVarByWo":
                                     return GetLabelVarWo(lv, "");
                                 default:
@@ -648,6 +671,24 @@
         }
 
         /// <summary>
+        /// 鑾峰彇鏈�灏忓寘瑁呮潯鐮佸垪琛�
+        /// </summary>
+        /// <param name="action"></param>
+        /// <returns></returns>
+        private List<string> GetMinPkgList(PackingAction action) {
+            List<string> list = new List<string>();
+            if (action.CurPkg.Item.PKG_LEVEL == 1)
+            {
+                list.Add(CurSN);
+            }
+            else
+            {
+                list = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN).ToList();
+            }
+            return list;
+        }
+
+        /// <summary>
         /// 鑾峰彇鐧界洅鏉$爜
         /// </summary>
         /// <param name="action"></param>
@@ -679,10 +720,11 @@
         /// <returns></returns>
         private string GetCardOrBoxQR(string code, List<BAS_LABEL_VAR> lvars, PackingAction action)
         {
-            var itemCode = WorkBatch.Product.ITEM_CODE;
+            var minPkgList = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN);
             var wo = WorkBatch.Batch.ORDER_NO;
-            var snList = string.Join("\r\n", action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN));
+            var snList = string.Join("\r\n", minPkgList);
             if (snList.IsNullOrEmpty()) { snList = $"{CurSN}"; }
+            var itemCode = Biz.Db.Queryable<MES_CUST_SN>().Where(q => q.FLOW_SN == CurWipSNs.First().FLOW_SN).First()?.ITEM_CODE;
             var weight = action.CurPkg.WeightInfo.Weight;
             var unit = action.CurPkg.WeightInfo.Unit.ToUpper();
             var model = WorkBatch.Product.ExtInfo.Model;
@@ -717,7 +759,7 @@
                     int daysOffset = firstDay.DayOfWeek.GetValue() > 3 ? (firstDay.DayOfWeek.GetValue() - 7) : 0;
                     int year = date.Year + ((date - firstDay).TotalDays + daysOffset < 0 ? -1 : 0);
                     int week = CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Sunday);
-                    dic.Add(sn, $"{year.ToString().Substring(2, 2)}{week:00}");
+                    dic.Add(sn, $"{year.ToString("0000").Substring(2, 2)}{week:00}");
                 }
                 else
                 {
@@ -733,12 +775,33 @@
                 case 1:
                     return weeks.First();
                 case 2:
-                    return string.Join("/", weeks.Select(q => q + $"({dic.Count(d => d.Value == q)})"));
+                    return string.Join("銆�", weeks.Select(q => q + $"({dic.Count(d => d.Value == q)}PCS)"));
                 default:
-                    return string.Join("/", weeks.Take(2)) + " (+)";
+                    return string.Join("銆�", weeks.Take(2)) + " (+)";
             }
         }
         #endregion
+        #region 鍖呰涓撶敤鏂规硶
+        /// <summary>
+        /// 鏍规嵁浼犲叆鐨勫寘瑁呭璞¤繑鍥炴墍鏈夌殑鍖呰瀹炰綋鍒楄〃
+        /// </summary>
+        /// <param name="parent"></param>
+        /// <returns></returns>
+        public List<MES_WIP_PKG> GetPackageList(WipPkgItem parent)
+        {
+            List<MES_WIP_PKG> list = new();
+            if (!parent.Package.IsNullOrEmpty())
+            {
+                list.Add(parent.Package);
+            }
+            foreach (var item in parent.Items)
+            {
+                item.Package.PARENT_SN = parent.Package?.SN;
+                list.AddRange(GetPackageList(item));
+            }
+            return list;
+        }
+        #endregion
         #endregion Functions
 
         public override bool Close(bool needSaveHistoryLog = false)

--
Gitblit v1.9.3