From 3f364634b79a0f97a550c54f67313dfc0cfd4cb5 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期三, 27 十一月 2024 22:16:01 +0800
Subject: [PATCH] 一大波签入来了

---
 Tiger.Business.MES/Transaction/Position.cs |   72 +++++++++++++++++++++++++++++++-----
 1 files changed, 62 insertions(+), 10 deletions(-)

diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs
index 707f714..5696ae8 100644
--- a/Tiger.Business.MES/Transaction/Position.cs
+++ b/Tiger.Business.MES/Transaction/Position.cs
@@ -30,22 +30,23 @@
             UserCode = userCode;
             ApiHost = apiHost;
             PostCode = postCode;
+            _MainDB = Biz.Db;
 
-            CurPosition = Biz.Db.Queryable<MES_POSITION>().Where(q => q.POST_CODE == postCode).First();
+            CurPosition = MainDB.Queryable<MES_POSITION>().Where(q => q.POST_CODE == postCode).First();
             //if (CurPosition.IsNullOrEmpty()) throw new InvalidDataException($"MES.Transaction.Position.PositionNotExistsException", new Exception($"{postCode}|"));
             if (CurPosition.IsNullOrEmpty()) throw new InvalidDataException($"宀椾綅[{postCode}]涓嶅瓨鍦紝璇锋彁浜ゆ纭殑宀椾綅浠g爜", new Exception($"{postCode}|"));
-            CurLine = Biz.Db.Queryable<MES_LINE>().Where(q => q.LINE_CODE == CurPosition.LINE_CODE).First();
+            CurLine = MainDB.Queryable<MES_LINE>().Where(q => q.LINE_CODE == CurPosition.LINE_CODE).First();
             //if (CurLine.IsNullOrEmpty()) throw new InvalidDataException($"MES.Transaction.Position.LineNotExistsException", new Exception($"{postCode}|{CurPosition.LINE_CODE}"));
             if (CurLine.IsNullOrEmpty()) throw new InvalidDataException($"宀椾綅[{postCode}]鎵�灞炵殑浜х嚎[{CurPosition.LINE_CODE}]涓嶅瓨鍦紝璇峰厛璁剧疆鎵�灞炰骇绾�", new Exception($"{postCode}|{CurPosition.LINE_CODE}"));
-            CurWorkshop = Biz.Db.Queryable<MES_WORKSHOP>().Where(q => q.WS_CODE == CurLine.WS_CODE).First();
+            CurWorkshop = MainDB.Queryable<MES_WORKSHOP>().Where(q => q.WS_CODE == CurLine.WS_CODE).First();
             //if (CurWorkshop.IsNullOrEmpty()) throw new InvalidDataException($"MES.Transaction.Position.WorkshopNotExistsException", new Exception($"{postCode}|{CurLine.WS_CODE}"));
             if (CurWorkshop.IsNullOrEmpty()) throw new InvalidDataException($"宀椾綅[{postCode}]鎵�灞炵殑杞﹂棿[{CurLine.WS_CODE}]涓嶅瓨鍦紝璇峰厛璁剧疆鎵�灞炶溅闂�", new Exception($"{postCode}|{CurLine.WS_CODE}"));
-            CurFactory = Biz.Db.Queryable<MES_FACTORY>().Where(q => q.FTY_CODE == CurWorkshop.FTY_CODE).First();
+            CurFactory = MainDB.Queryable<MES_FACTORY>().Where(q => q.FTY_CODE == CurWorkshop.FTY_CODE).First();
             //if (CurFactory.IsNullOrEmpty()) throw new InvalidDataException($"MES.Transaction.Position.FactoryNotExistsException", new Exception($"{postCode}|{CurWorkshop.FTY_CODE}"));
             if (CurFactory.IsNullOrEmpty()) throw new InvalidDataException($"宀椾綅[{postCode}]鎵�灞炵殑宸ュ巶[{CurWorkshop.FTY_CODE}]涓嶅瓨鍦紝璇峰厛璁剧疆鎵�灞炲伐鍘�", new Exception($"{postCode}|{CurWorkshop.FTY_CODE}"));
 
             //鍔犺浇褰撳墠浜х嚎鐨勭彮鍒�
-            CurShiftSys = Biz.Db.Queryable<MES_SHIFT_SYS>().Where(q => q.SFTS_CODE == CurLine.SFTS_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Shifts).First();
+            CurShiftSys = MainDB.Queryable<MES_SHIFT_SYS>().Where(q => q.SFTS_CODE == CurLine.SFTS_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Shifts).First();
 
             return this;
         }
@@ -75,6 +76,8 @@
         public bool IsFinishNodeSteps => !Steps.Any(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished);
         public bool IsFinishAllSteps => Steps.Any() && !Steps.Any(q => !q.IsFinished);
         //public int CurStep => Steps.Where(q => !q.IsFinished).OrderBy(q => q.Sequence).FirstOrDefault()?.Sequence ?? 0;
+        private DbClient _MainDB;
+        public DbClient MainDB => _MainDB;
         private DbClient CommitDB;
         /// <summary>
         /// 鏄惁闇�瑕佷复鏃跺瓨鍌ㄦ暟鎹簱鎻愪氦鎿嶄綔锛屽緟闇�瑕佺殑鏃跺�欏啀鎻愪氦
@@ -107,7 +110,7 @@
             {
                 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();
+                    var wo = await MainDB.Queryable<BIZ_MES_WO>().ByAuth(input.AuthOption).Where(q => q.ORDER_NO == input.OrderNo).FirstAsync();
                     //楠岃瘉鏄庣粏鏄惁姝g‘
                     if (wo.IsNullOrEmpty())
                     {
@@ -123,7 +126,7 @@
                         action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, wo.STATUS.GetEnumDesc<BIZ_MES_WO.STATUSs>());
                         return action;
                     }
-                    var batch = await Biz.Db.Queryable<BIZ_MES_WO_BATCH>().ByAuth(input.AuthOption)
+                    var batch = await MainDB.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();
@@ -242,6 +245,55 @@
                 info.NextNode = "   鈥�   ";
             }
             return info;
+        }
+
+        /// <summary>
+        /// 璁剧疆褰撳墠鏉$爜鐨勫伐搴忎俊鎭�
+        /// </summary>
+        public ApiAction<SubmitOutput> SetOutPutMqttMsg(ApiAction<SubmitOutput> action, string locale = null)
+        {
+            MQTT.Message msg = new()
+            {
+                IsSuccessed = action.IsSuccessed,
+                Content = Biz.T(action.LocaleMsg, locale),
+            };
+            switch (action.Status)
+            {
+                case ApiAction.StatusCodes.Success:
+                    if (action.Data.IsFinished)
+                    {
+                        msg.Voice = MQTT.Voice.Pass;
+                        msg.Color = "#FF228B22";
+                    }
+                    else
+                    {
+                        msg.Voice = MQTT.Voice.Success;
+                        msg.Color = "#FF1E90FF";
+                    }
+                    break;
+                case ApiAction.StatusCodes.Warning:
+                    msg.Voice = MQTT.Voice.Warning;
+                    msg.Color = "#FFB8860B";
+                    break;
+                case ApiAction.StatusCodes.Error:
+                case ApiAction.StatusCodes.Failed:
+                    msg.Voice = MQTT.Voice.Fail;
+                    msg.Color = "#FFFF0000";
+                    break;
+                case ApiAction.StatusCodes.Exception:
+                    msg.Voice = MQTT.Voice.Fail;
+                    msg.Color = "#FF8B0000";
+                    break;
+                case ApiAction.StatusCodes.Normal:
+                case ApiAction.StatusCodes.NeedConfrim:
+                case ApiAction.StatusCodes.Confrimed:
+                default:
+                    msg.Voice = MQTT.Voice.Silent;
+                    msg.Color = "#FF000000";
+                    break;
+            }
+            action.Data.MqttMsg = msg;
+            return action;
         }
 
         /// <summary>
@@ -663,7 +715,7 @@
                                             {
                                                 snList.Add(_orderAction.CurPkg.CustSN?.FLOW_SN);
                                             }
-                                            _lotnos = string.Join(",", Biz.Db.Queryable<MES_CUST_SN>()
+                                            _lotnos = string.Join(",", MainDB.Queryable<MES_CUST_SN>()
                                                 .Where((q) => snList.Contains(q.FLOW_SN))
                                                 .Select((q) => q.WORK_ORDER).Distinct().ToList());
                                             return _lotnos;
@@ -742,7 +794,7 @@
         private string GetLabelVarWo(BAS_LABEL_VAR lv, string value)
         {
             string result = "";
-            var labelVarwos = Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == lv.LABEL_ID && x.VAR_NAME == lv.VAR_NAME).ToList();
+            var labelVarwos = MainDB.Queryable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == lv.LABEL_ID && x.VAR_NAME == lv.VAR_NAME).ToList();
             if (labelVarwos.Any(q => q.WORK_ORDER == WorkBatch.Batch.ORDER_NO))
             {
                 result = labelVarwos.First(q => q.WORK_ORDER == WorkBatch.Batch.ORDER_NO).VAR_VALUE;
@@ -854,7 +906,7 @@
         private string GetHuaWeiWeek(string pkgOrder, List<string> snList)
         {
             Dictionary<string, string> dic = new();
-            var snOrder = Biz.Db.Queryable<MES_CUST_SN, BIZ_MES_WO>((q, w) => new JoinQueryInfos(JoinType.Left, q.WORK_ORDER == w.ORDER_NO))
+            var snOrder = MainDB.Queryable<MES_CUST_SN, BIZ_MES_WO>((q, w) => new JoinQueryInfos(JoinType.Left, q.WORK_ORDER == w.ORDER_NO))
                                             .Where((q, w) => q.PKG_ORDER == pkgOrder && (snList.Contains(q.FLOW_SN) || snList.Contains(q.CUST_SN)))
                                            .Select((q, w) => new { q.PKG_ORDER, q.WORK_ORDER, w.ACT_START_TIME, w.PLAN_START_TIME, q.FLOW_SN, q.CUST_SN }).ToList();
             foreach (var sn in snList)

--
Gitblit v1.9.3