From 0fdd0687f116ac43f7432227dfaa2ebc2f696575 Mon Sep 17 00:00:00 2001
From: Rodney Chen <rodney.chen@hotmail.com>
Date: 星期日, 04 八月 2024 17:21:11 +0800
Subject: [PATCH] 增加扩展信息绑定工序

---
 Tiger.Business.MES/WorkAction/WipExtInfo.cs |  185 +++++++++++----------------------------------
 1 files changed, 46 insertions(+), 139 deletions(-)

diff --git a/Tiger.Business.MES/WorkAction/WipExtInfo.cs b/Tiger.Business.MES/WorkAction/WipExtInfo.cs
index 9026560..4587973 100644
--- a/Tiger.Business.MES/WorkAction/WipExtInfo.cs
+++ b/Tiger.Business.MES/WorkAction/WipExtInfo.cs
@@ -22,9 +22,8 @@
         public MES_WO_NODE_ACT NodeAct { get; set; }
         public MES_WO_ACTION Setting { get; set; }
         #endregion
-        public List<BAS_PROD_BOM> Boms { get; set; } = new();
-        public Dictionary<string, List<BAS_ITEM>> SubItemDic { get; set; } = new();
-        public AssemblyInfo CurAssembly { get; set; } = new();
+        public BAS_WIP_EXT ExtInfo { get; set; } 
+        public MES_WIP_EXT CurWipExt { get; set; }
         #endregion Propertys & Variables
 
         #region Functions
@@ -41,49 +40,16 @@
             Setting = setting;
             #endregion
 
-            //鑾峰彇浜у搧BOM
-            Boms = Biz.Db.Queryable<BAS_PROD_BOM>().Where(q => q.PROD_CODE == CurPosition.WorkBatch.WO.ITEM_CODE).ToList();
-            //鑾峰彇涓婃枡鐗╂枡
-            var assyList = new List<AssemblySetting>();
-            try
+            //鑾峰彇鎵╁睍瀛楁瀹氫箟
+            var seq = Setting.ITEM_CODE.ToInt32();
+            ExtInfo = Biz.Db.Queryable<BAS_WIP_EXT>().Where(q => q.SEQ == seq).First();
+            //鑾峰彇褰撳墠SN鐨勬墿灞曚俊鎭�
+            CurWipExt = Biz.Db.Queryable<MES_WIP_EXT>().Where(q => q.SN == CurPosition.CurWipSN.SN).First() ?? new ()
             {
-                assyList = setting.ITEM_CODE.JsonToObject<List<AssemblySetting>>();
-            }
-            catch (System.Exception ex)
-            {
-                var codeList = setting.ITEM_CODE.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
-                foreach (var code in codeList)
-                {
-                    assyList.Add(new() { ItemCode = code });
-                }
-            }
-            var codes = assyList.Select(q => q.ItemCode).ToList();
-            var items = Biz.Db.Queryable<BAS_ITEM>().Where(q => codes.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList();
-            //鑾峰彇涓婃枡鐗╂枡鐨勬浛浠f枡
-            foreach (var assy in assyList)
-            {
-                var info = items.FirstOrDefault(q => q.ITEM_CODE == assy.ItemCode);
-                if (!info.IsNullOrEmpty())
-                {
-                    var item = new AssemblyItem
-                    {
-                        ItemInfo = info,
-                        RuleCode = assy.RuleCode,
-                        LoadQty = assy.Qty,
-                    };
-                    var bom = Boms.FirstOrDefault(q => q.ITEM_CODE == assy.ItemCode);
-                    if (!bom.IsNullOrEmpty())
-                    {
-                        var subs = bom.SUB_CODE.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries);
-                        var surItems = Biz.Db.Queryable<BAS_ITEM>().Where(q => subs.Contains(q.ITEM_CODE) && q.AUTH_ORG == CurPosition.WorkBatch.WO.AUTH_ORG).ToList();
-                        if (!SubItemDic.ContainsKey(assy.ItemCode))
-                        {
-                            SubItemDic.Add(assy.ItemCode, surItems);
-                        }
-                    }
-                    CurAssembly.Items.Add(item);
-                }
-            }
+                AUTH_ORG = CurPosition.CurWipSN.AUTH_ORG,
+                AUTH_PROD = CurPosition.CurWipSN.AUTH_PROD,
+                SN = CurPosition.CurWipSN.SN,
+            };
         }
 
         /// <summary>
@@ -92,8 +58,8 @@
         /// <returns></returns>
         public Locale GetBeginMsg()
         {
-            var msg = new Locale("MES.WorkAction.WipExtInfo.BeginMsg", string.Join("锛�", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})")));
-            //var msg = new Locale($"璇锋壂鎻忎互涓嬮渶瑕佷笂鏂欑殑鐗╂枡鏉$爜锛歿string.Join("锛�", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}");
+            var msg = new Locale("MES.WorkAction.WipExtInfo.BeginMsg", ExtInfo.FIELD_NAME);
+            //var msg = new Locale($"璇锋壂鎻忎骇鍝乕{CurPosition.CurWipSN.SN}]闇�瑕佺粦瀹氱殑[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜");
             return msg;
         }
 
@@ -105,14 +71,10 @@
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
 
-            if (input.SN != CurPosition.CurWipSN.SN)
-            {
-                action = SaveAssembly(input, action);
-                return action;
-            }
+            action.LocaleMsg = GetBeginMsg();
 
             //濡傛灉杩斿洖鎴愬姛鍒欒涓哄綋鍓嶈涓哄彲浠ュ紑濮嬫墽琛岋紝鍚﹀垯杩斿洖澶辫触
-            action.IsSuccessed = false;
+            action.IsSuccessed = true;
             return action;
         }
 
@@ -124,7 +86,7 @@
         {
             var action = new ApiAction<SubmitOutput>(new SubmitOutput());
 
-            action = SaveAssembly(input, action);
+            action = SaveExtInfo(input, action);
             //涓婃枡鏁版嵁淇濆瓨澶辫触
             if (!action.IsSuccessed)
             {
@@ -137,91 +99,41 @@
             return action;
         }
 
-        public ApiAction<SubmitOutput> SaveAssembly(SubmitInput input, ApiAction<SubmitOutput> action)
+        public ApiAction<SubmitOutput> SaveExtInfo(SubmitInput input, ApiAction<SubmitOutput> action)
         {
             try
             {
-                foreach (var item in CurAssembly.Items.Where(q => !q.IsFinished))
+                var isOK = true;
+                //楠岃瘉鎵弿鐨勬潯鐮佹槸鍚N鐨勬墿灞曚俊鎭殑鏍囩
+                if (input.SN.IsNullOrEmpty())
                 {
-                    var isOK = true;
-                    //鏍规嵁鏉$爜瑙勫垯楠岃瘉涓婃枡鏄惁姝g‘
-                    if (!item.RuleCode.IsNullOrEmpty())
-                    {
-                        if (!Biz.CodeRule[item.RuleCode].IsNullOrEmpty())
-                        {
-                            var result = Biz.CodeRule[item.RuleCode].Verify(input.SN);
-                            if (!result.IsSuccessed)
-                            {
-                                isOK = false;
-                            }
-                        }
-                        //涓嶅瓨鍦ㄦ潯鐮佽鍒欙紝鍒欏垽鏂槸鍚︽湁鑷畾涔夎鍒欙紝娌℃湁鍒欒繑鍥炲け璐�
-                        else
-                        {
-                            switch (item.RuleCode)
-                            {
-                                case "鑷楠岃瘉":
-                                    break;
-                                default:
-                                    isOK = false;
-                                    break;
-                            }
-                        }
-                    }
-                    //楠岃瘉閫氳繃鍒欎繚瀛樹笂鏂欎俊鎭�
-                    if (isOK)
-                    {
-                        var record = new MES_WIP_ASSY()
-                        {
-                            AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG,
-                            AUTH_PROD = CurPosition.CurLine.LINE_CODE,
-                            SN = input.SN,
-                            PROD_SN = CurPosition.CurWipSN.SN,
-                            ITEM_CODE = item.ItemInfo.ITEM_CODE,
-                            QTY = 1,
-                            UNIT = item.ItemInfo.UNIT,
-                            WORK_ORDER = CurPosition.CurWipSN.WORK_ORDER,
-                            BATCH_NO = CurPosition.CurWipSN.BATCH_NO,
-                            ROT_CODE = CurPosition.CurWipSN.ROT_CODE,
-                            NODE_ID = CurPosition.CurWipSN.NODE_ID,
-                            NODE_NAME = CurPosition.CurWipSN.NODE_NAME,
-                            FTY_CODE = CurPosition.CurWipSN.FTY_CODE,
-                            WS_CODE = CurPosition.CurWipSN.WS_CODE,
-                            LINE_CODE = CurPosition.CurWipSN.LINE_CODE,
-                            POST_CODE = CurPosition.CurWipSN.POST_CODE,
-                            OPER_CODE = CurPosition.CurWipSN.OPER_CODE,
-                            SEGMENT = CurPosition.CurWipSN.SEGMENT,
-                        };
-                        item.Records.Add(record);
-                        if (item.Records.Sum(q => q.QTY) >= item.LoadQty)
-                        {
-                            item.IsFinished = true;
-                        }
-
-                        action.IsSuccessed = true;
-                        action.Data.Data = CurAssembly;
-                        action.LocaleMsg = new Locale($"鎵弿鐗╂枡[{item.ItemInfo.ITEM_NAME}({item.ItemInfo.ITEM_CODE})鐨勬潯鐮乕{input.SN}]鎴愬姛锛岃缁х画涓婃枡");
-                        action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.LoadSuccess", item.ItemInfo.ITEM_NAME, item.ItemInfo.ITEM_CODE);
-
-                        //涓婃枡瀹屾垚
-                        if (CurAssembly.IsFinished)
-                        {
-                            action = End();
-                        }
-                        return action;
-                    }
+                    action.IsSuccessed = isOK = false;
+                    //action.LocaleMsg = new Locale($"閿欒锛歔{ExtInfo.FIELD_NAME}]鏍囩鏉$爜涓嶈兘涓虹┖锛岃閲嶆柊鎵弿");
+                    action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.SnEmptyError", ExtInfo.FIELD_NAME);
                 }
+                if (input.SN == CurPosition.CurWipSN.SN)
+                {
+                    action.IsSuccessed = isOK = false;
+                    //action.LocaleMsg = new Locale($"閿欒锛氭壂鎻忓埌浜у搧鏉$爜[{input.SN}]锛岃閲嶆柊鎵弿[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜");
+                    action.LocaleMsg = new Locale("MES.WorkAction.WipExtInfo.ScanProdSnError", input.SN, ExtInfo.FIELD_NAME);
+                }
+
+                //楠岃瘉閫氳繃鍒欎繚瀛樹笂鏂欎俊鎭�
+                if (isOK)
+                {
+                    CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.SetValue(CurWipExt, input.SN);
+                    action = End();
+                }
+
                 //閮芥病鏈夌墿鏂欓獙璇侀�氳繃锛屽垯杩斿洖閿欒淇℃伅
-                action.IsSuccessed = false;
-                //action.LocaleMsg = new($"鏉$爜[{input.SN}]楠岃瘉澶辫触锛屼笉鏄互涓嬬墿鏂欑殑鏉$爜锛歿string.Join("锛�", CurAssembly.Items.Where(q => !q.IsFinished).Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}");
-                action.LocaleMsg = new("MES.WorkAction.WipExtInfo.LoadFail", input.SN, string.Join("锛�", CurAssembly.Items.Where(q => !q.IsFinished).Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})")));
+                
             }
             catch (System.Exception ex)
             {
-                action.CatchExceptionWithLog(ex, $"涓婃枡琛屼负锛氶獙璇佹潯鐮乕{input.SN}]骞朵繚瀛樻暟鎹け璐�");
+                action.CatchExceptionWithLog(ex, $"鎵╁睍淇℃伅缁戝畾琛屼负锛氫骇鍝乕{CurPosition.CurWipSN.SN}]缁戝畾[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜[{input.SN}]淇濆瓨寮傚父");
                 action.IsSuccessed = false;
-                action.LocaleMsg = new($"楠岃瘉鏉$爜[{input.SN}]骞朵繚瀛樻暟鎹け璐ワ紝宸ュ簭宸查噸缃紝璇烽噸鏂版壂鎻忚繘绔欎骇鍝佹潯鐮�");
-                action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveAssemblyException", input.SN);
+                //action.LocaleMsg = new($"浜у搧[{CurPosition.CurWipSN.SN}]缁戝畾[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜[{input.SN}]淇濆瓨寮傚父锛屽伐搴忓凡閲嶇疆锛岃閲嶆柊鎵弿杩涚珯浜у搧鏉$爜");
+                action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveExtInfoException", CurPosition.CurWipSN.SN, ExtInfo.FIELD_NAME, input.SN);
                 CurPosition.ResetNode();
             }
             return action;
@@ -264,27 +176,22 @@
                 PRD_CODE = CurPosition.CurWipSN.PRD_CODE,
                 ACT_TYPE = NodeAct.ACT_TYPE,
                 ACT_SN = CurPosition.CurWipSN.SN,
-                ACT_VALUE_1 = CurAssembly.ToJson(),
+                ACT_VALUE_1 = CurWipExt.ToJson(),
                 ACT_RESULT = "Y",
-                TRACE_INFO = $"浠ヤ笅鐗╂枡涓婃枡瀹屾垚锛歿string.Join(",", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}",
+                TRACE_INFO = $"浜у搧[{CurPosition.CurWipSN.SN}]缁戝畾[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]淇濆瓨鎴愬姛",
             };
-            var records = new List<MES_WIP_ASSY>();
-            foreach (var item in CurAssembly.Items)
-            {
-                records.AddRange(item.Records);
-            }
 
             //淇濆瓨鏁版嵁
             CurStep.DBSubmitAction = () =>
             {
                 var db = CurPosition.GetCommitDB();
                 db.Storageable(wipAct, CurPosition.UserCode).ExecuteCommand();
-                db.Insertable(records, CurPosition.UserCode).ExecuteCommand();
+                db.Storageable(CurWipExt, CurPosition.UserCode).ExecuteCommand();
             };
 
             IsFinished = true;
-            //action.LocaleMsg = new($"浠ヤ笅鐗╂枡涓婃枡瀹屾垚锛歿string.Join("锛�", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})"))}");
-            action.LocaleMsg = new("MES.WorkAction.WipExtInfo.LoadFinish", string.Join("锛�", CurAssembly.Items.Select(q => $"{q.ItemInfo.ITEM_NAME}({q.ItemInfo.ITEM_CODE})")));
+            //action.LocaleMsg = new($"浜у搧[{CurPosition.CurWipSN.SN}]缁戝畾[{ExtInfo.FIELD_NAME}]鏍囩鏉$爜[{CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString()}]淇濆瓨鎴愬姛");
+            action.LocaleMsg = new("MES.WorkAction.WipExtInfo.SaveSuccess", CurPosition.CurWipSN.SN, ExtInfo.FIELD_NAME, CurWipExt.GetType().GetProperty($"FIELD_{ExtInfo.SEQ.ToString("00")}")?.GetValue(CurWipExt)?.ToString());
             return action;
         }
 

--
Gitblit v1.9.3