From 72080a2270d06efe6c9d44fbb82e7edf28d14f05 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期四, 08 八月 2024 11:35:08 +0800 Subject: [PATCH] 包装行为增加已扫条码验证,不允许重复扫描 --- Tiger.Business.MES/WorkAction/PackingAction.cs | 363 +++++++++++++++++++++++++++++++++------------------ 1 files changed, 235 insertions(+), 128 deletions(-) diff --git a/Tiger.Business.MES/WorkAction/PackingAction.cs b/Tiger.Business.MES/WorkAction/PackingAction.cs index 312c526..9ba0268 100644 --- a/Tiger.Business.MES/WorkAction/PackingAction.cs +++ b/Tiger.Business.MES/WorkAction/PackingAction.cs @@ -6,6 +6,7 @@ using System.Text; using System.Threading.Tasks; using Tiger.IBusiness; +using Tiger.IBusiness.MES.WorkAction; using Tiger.Model; using Tiger.Model.Entitys.MES.Position; @@ -24,10 +25,10 @@ public BAS_PKG_RULE PkgRule { get; set; } public WipPkg CurPkg { get; set; } public WipPkgItem CurPkgItem { get; set; } - public PackingActionOutput CurPrint { get; set; } + public PackingActionOutput CurCmd { get; set; } public int PrintTimes = 0; - public Dictionary<int, BAS_LABEL_TEMP> LabelDic { get; set; } - public List<BAS_LABEL_PV> LabelPV { get; set; } + public Dictionary<int, BAS_LABEL_TEMP> LabelDic { get; set; } = new(); + public List<BAS_LABEL_PV> LabelPV { get; set; } = new(); public int FinishLevel = 0; #endregion Propertys & Variables @@ -44,15 +45,24 @@ NodeAct = nodeAct; Setting = setting; #endregion - - PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); - //鏍规嵁琛屼负璁剧疆鑾峰彇澶氬眰鍖呰鐨勬爣绛炬墦鍗版ā鏉垮瓧鍏� - for (int i = 1; i < 10; i++) + //鎵嬪姩缁撴潫鍖呰涓撶敤锛屼复鏃舵墽琛岃涓� + if (setting.IsNullOrEmpty()) { - var code = Setting.GetType().GetProperty($"OPTION_{i}")?.GetValue(Setting).ToString() ?? ""; - var label = code.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == code).IncludesAllFirstLayer().First(); - LabelDic.Add(i, label); + PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); + } + //姝e父鏉$爜杩囩珯鎵ц鍖呰琛屼负 + else + { + PkgRule = Biz.Db.Queryable<BAS_PKG_RULE>().Where(q => q.RULE_CODE == setting.PKG_CODE).IncludesAllFirstLayer().IncludesAllSecondLayer(q => q.Details).First(); } + //鏍规嵁琛屼负璁剧疆鑾峰彇澶氬眰鍖呰鐨勬爣绛炬墦鍗版ā鏉垮瓧鍏� + var codes = (Setting.OPTION_1?? "").JsonToObject<List<WipPkgItem>>(); + foreach (var code in codes) + { + var label = code.LABEL_CODE.IsNullOrEmpty() ? null : Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == code.LABEL_CODE).IncludesAllFirstLayer().First(); + LabelDic.Add(code.PKG_LEVEL, label); + } + LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList(); //濡傛灉宸ュ簭涓婁笅鏂囦腑娌℃湁鍖呰璁板綍鍒欐柊寤轰竴涓紝鏈夊垯鑾峰彇褰撳墠鐨勫寘瑁呰褰� if (CurPosition.Context.ContainsKey("CurPackage") && !CurPosition.Context["CurPackage"].IsNullOrEmpty()) { @@ -72,7 +82,7 @@ IS_MIN_PKG = max.PkgType.IS_MIN_PKG, PKG_LEVEL = max.PKG_LEVEL, PKG_QTY = max.PKG_QTY, - LABEL_CODE = LabelDic[max.PKG_LEVEL].LABEL_CODE, + LABEL_CODE = LabelDic[max.PKG_LEVEL]?.LABEL_CODE, } }; WipPkgItem child = null; @@ -87,7 +97,7 @@ IS_MIN_PKG = dtl.PkgType.IS_MIN_PKG, PKG_LEVEL = dtl.PKG_LEVEL, PKG_QTY = dtl.PKG_QTY, - LABEL_CODE = LabelDic[dtl.PKG_LEVEL].LABEL_CODE, + LABEL_CODE = LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, }; if (!child.IsNullOrEmpty()) { @@ -96,7 +106,11 @@ child = item; } } - CurPkg.Item.Items.Add(child); + if (!child.IsNullOrEmpty()) + { + CurPkg.Item.Items.Add(child); + } + } } @@ -110,14 +124,14 @@ //琛屼负璁惧畾鐨凮PTION_1鏄涓�灞傚寘瑁呯殑鏍囩妯℃澘浠g爜锛屽鏋滀负绌哄垯涓嶉渶瑕佹墦鍗� if (LabelDic[min.PKG_LEVEL].IsNullOrEmpty()) { - var msg = new Locale("MES.WorkAction.PackingAction.BeginMsg", min.PKG_LEVEL, min.PkgType.PKG_NAME, CurPosition.CurWipSN.SN); + var msg = new Locale("MES.WorkAction.PackingAction.BeginMsg", min.PKG_LEVEL, min.PkgType.PKG_NAME, CurPosition.CurSN); //var msg = new Locale($"宸叉壂鎻忕{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮乕{CurPosition.CurWipSN.SN}]"); return msg; } else { - var msg = new Locale("MES.WorkAction.PackingAction.BeginPrint", min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL].LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); - //var msg = new Locale($"寮�濮嬫墦鍗扮{min.PKG_LEVEL}灞傚寘瑁匸{min.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[min.PKG_LEVEL].LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); + var msg = new Locale("MES.WorkAction.PackingAction.BeginPrint", min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL]?.LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); + //var msg = new Locale($"寮�濮嬫墦鍗扮{min.PKG_LEVEL}灞傚寘瑁匸{min.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); return msg; } } @@ -132,7 +146,7 @@ action.LocaleMsg = GetBeginMsg(); var min = PkgRule.Details.OrderBy(q => q.PKG_LEVEL).First(); - //琛屼负璁惧畾鐨凮PTION_1-9鏄寘瑁呬笉鍚屽眰绾х殑鏍囩妯℃澘浠g爜锛屽鏋滀负绌哄垯涓嶉渶瑕佹墦鍗� + //鏍规嵁鍖呰涓嶅悓灞傜骇鐨勬爣绛炬ā鏉夸唬鐮侊紝濡傛灉涓虹┖鍒欎笉闇�瑕佹墦鍗� if (LabelDic[min.PKG_LEVEL].IsNullOrEmpty()) { input.Data = new PackingActionInput() @@ -140,7 +154,7 @@ ExecCode = "Scan", IsFinish = true, PkgLevel = min.PKG_LEVEL, - PkgSN = CurPosition.CurWipSN.SN, + PkgSN = CurPosition.CurSN, }.ToJson(); action = Submit(input); } @@ -153,11 +167,11 @@ data.ExecCode = "Print"; data.PkgLevel = min.PKG_LEVEL; data.PrintLable = LabelDic[min.PKG_LEVEL]; - CurPrint = data; + CurCmd = data; PrintTimes++; action.Data.Data = data; - //action.LocaleMsg = new Locale($"寮�濮嬬{PrintTimes}娆℃墦鍗扮{min.PKG_LEVEL}灞傚寘瑁匸{min.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[min.PKG_LEVEL].LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); - action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL].LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); + //action.LocaleMsg = new Locale($"寮�濮嬬{PrintTimes}娆℃墦鍗扮{min.PKG_LEVEL}灞傚寘瑁匸{min.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); + action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, min.PKG_LEVEL, min.PkgType.PKG_NAME, LabelDic[min.PKG_LEVEL]?.LABEL_CODE, LabelDic[min.PKG_LEVEL].LABEL_NAME); } //濡傛灉杩斿洖鎴愬姛鍒欒涓哄綋鍓嶈涓哄彲浠ュ紑濮嬫墽琛岋紝鍚﹀垯杩斿洖澶辫触 @@ -173,19 +187,15 @@ { var action = new ApiAction<SubmitOutput>(new SubmitOutput()); - var pInput = input.Data?.JsonToObject<PackingActionInput>(); - switch (pInput.ExecCode) + var pInput = input?.Data?.JsonToObject<PackingActionInput>(); + switch (pInput?.ExecCode) { //Scan锛氭壂鐮侊紝鎵弿褰撳墠鍖呰灞傜骇鐨勬潯鐮� case "Scan": + if (CurCmd.IsNullOrEmpty() || CurCmd.ExecCode == "Scan" || (CurCmd.ExecCode == "Print" && CurCmd.PkgLevel == pInput.PkgLevel)) { - //瀹㈡埛绔壂鎻忔垚鍔� - if (pInput.IsFinish) - { - action = SavePkgData(input, action); - } //瀹㈡埛绔壂鎻忓け璐� - else + if (!pInput.IsFinish || pInput.PkgSN.IsNullOrEmpty()) { var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel); action.IsSuccessed = false; @@ -193,20 +203,35 @@ action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanFail", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); return action; } + //楠岃瘉褰撳墠鍖呰鏉$爜鏄惁宸茬粡琚壂鎻忚繃 + if (GetPackageList(CurPkg.Item).Any(q => q.SN == pInput.PkgSN)) + { + var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel); + action.IsSuccessed = false; + //action.LocaleMsg = new($"鏉$爜[{pInput.PkgSN}]鏃犻渶閲嶅鎵弿锛岃鎵弿绗瑊dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮�"); + action.LocaleMsg = new("MES.WorkAction.PackingAction.ScanRepeat", pInput.PkgSN, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); + return action; + } + //瀹㈡埛绔壂鎻忔垚鍔� + CurCmd = null; + PrintTimes = 0; + action = SavePkgData(input, action); } break; //Print锛氭墦鍗帮紝鎵撳嵃褰撳墠鍖呰灞傜骇鐨勬爣绛� case "Print": + if (CurCmd.ExecCode == "Print") { var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == pInput.PkgLevel); //瀹㈡埛绔畬鎴愭墦鍗� if (pInput.IsFinish) { - CurPrint = null; + CurCmd = null; PrintTimes = 0; var data = new PackingActionOutput() { PkgInfo = CurPkg }; data.ExecCode = "Scan"; data.PkgLevel = dtl.PKG_LEVEL; + CurCmd = data; action.Data.Data = data; //action.LocaleMsg = new($"璇锋壂鎻忕{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮�"); action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); @@ -215,29 +240,76 @@ else { //濡傛灉鎵撳嵃澶辫触鍒欏皾璇曚笁娆¢噸鏂版墦鍗帮紝濡傛灉閮藉け璐ュ垯閲嶇疆宸ュ簭 - if (PrintTimes < 3 && !CurPrint.IsNullOrEmpty()) + if (PrintTimes < 3 && !CurCmd.IsNullOrEmpty()) { PrintTimes++; - action.Data.Data = CurPrint; - //action.LocaleMsg = new Locale($"寮�濮媨PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); - action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); + action.Data.Data = CurCmd; + //action.LocaleMsg = new Locale($"寮�濮媨PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); + action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); } else { - CurPrint = null; + CurCmd = null; PrintTimes = 0; action.IsSuccessed = false; - //action.LocaleMsg = new($"灏濊瘯绗瑊PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]澶辫触锛屽伐搴忓凡閲嶇疆锛岃閲嶆柊鎵弿杩涚珯浜у搧鏉$爜"); - action.LocaleMsg = new("MES.WorkAction.PackingAction.PrintFail3Times", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); - CurPosition.ResetSteps(); + //action.LocaleMsg = new($"灏濊瘯绗瑊PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]澶辫触锛屽伐搴忓凡閲嶇疆锛岃閲嶆柊鎵弿杩涚珯浜у搧鏉$爜"); + action.LocaleMsg = new("MES.WorkAction.PackingAction.PrintFail3Times", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); + CurPosition.ResetNode(); } } } break; // Complete锛氬畬鎴愶紝瀹屾垚鍏ㄩ儴鍖呰鍚庣粨鏉熻涓� case "Complete": + if (CurCmd.ExecCode == "Complete") { + CurCmd = null; + PrintTimes = 0; action = End(); + } + break; + // 鎵嬪姩缁撴潫鍖呰锛屼繚瀛樻殏瀛樼殑鍖呰鏁版嵁 + case null: + { + CurCmd = null; + PrintTimes = 0; + FinishLevel = 1; + WipPkgItem curItem = CurPkg.Item; + while (curItem.PKG_LEVEL > 2) + { + var next = curItem.Items.FirstOrDefault(q => !q.IsFinished); + curItem = next; + } + CurPkgItem = curItem; + + //鎵嬪姩缁撴潫鍖呰榛樿浠庣浜屽眰鍖呰寮�濮嬮獙璇� + var dtl = PkgRule.Details.First(q => q.PKG_LEVEL == 2); + //琛屼负璁惧畾鐨凮PTION_1-9鏄寘瑁呬笉鍚屽眰绾х殑鏍囩妯℃澘浠g爜锛屽鏋滀负绌哄垯涓嶉渶瑕佹墦鍗� + if (LabelDic[dtl.PKG_LEVEL].IsNullOrEmpty()) + { + var data = new PackingActionOutput() { PkgInfo = CurPkg }; + data.ExecCode = "Scan"; + data.PkgLevel = dtl.PKG_LEVEL; + CurCmd = data; + action.Data.Data = data; + //action.LocaleMsg = new($"璇锋壂鎻忕{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮�"); + action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); + } + else + { + //璁剧疆鎵撳嵃鍙橀噺鍊� + LabelDic[dtl.PKG_LEVEL] = CurPosition.SetLabelVariables(LabelPV, LabelDic[dtl.PKG_LEVEL]); + + var data = new PackingActionOutput() { PkgInfo = CurPkg }; + data.ExecCode = "Print"; + data.PkgLevel = dtl.PKG_LEVEL; + data.PrintLable = LabelDic[dtl.PKG_LEVEL]; + CurCmd = data; + PrintTimes++; + action.Data.Data = data; + //action.LocaleMsg = new Locale($"寮�濮嬬{PrintTimes}娆℃墦鍗扮{min.PKG_LEVEL}灞傚寘瑁匸{min.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[min.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[min.PKG_LEVEL].LABEL_NAME}]"); + action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); + } } break; default: @@ -247,7 +319,7 @@ //濡傛灉琛屼负璁剧疆涓哄嚭閿欓渶瑕侀噸缃伐搴忔搷浣� if (!action.IsSuccessed && NodeAct.NEED_RESET == "Y") { - CurPosition.ResetSteps(); + CurPosition.ResetNode(); } return action; } @@ -271,7 +343,7 @@ IS_MIN_PKG = dtl.PkgType.IS_MIN_PKG, PKG_LEVEL = dtl.PKG_LEVEL, PKG_QTY = dtl.PKG_QTY, - LABEL_CODE = LabelDic[dtl.PKG_LEVEL].LABEL_CODE, + LABEL_CODE = LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, IsFinished = true, Package = new() { @@ -279,20 +351,20 @@ AUTH_PROD = CurPosition.CurLine.LINE_CODE, SN = pInput.PkgSN, PKG_TYPE = dtl.PkgType.PKG_NAME, - ITEM_CODE = CurPosition.CurWipSN.ITEM_CODE, - QTY = CurPosition.CurWipSN.QTY, + ITEM_CODE = CurPosition.CurWipSNs.First().ITEM_CODE, + QTY = CurPosition.CurWipSNs.First().QTY, UNIT = dtl.PkgType.PKG_NAME, - 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, + WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER, + BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO, + ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE, + NODE_ID = CurPosition.CurWipSNs.First().NODE_ID, + NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME, + FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE, + WS_CODE = CurPosition.CurWipSNs.First().WS_CODE, + LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE, + POST_CODE = CurPosition.CurWipSNs.First().POST_CODE, + OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE, + SEGMENT = CurPosition.CurWipSNs.First().SEGMENT, } }; FinishLevel++; @@ -311,20 +383,20 @@ AUTH_PROD = CurPosition.CurLine.LINE_CODE, SN = pInput.PkgSN, PKG_TYPE = dtl.PkgType.PKG_NAME, - ITEM_CODE = CurPosition.CurWipSN.ITEM_CODE, + ITEM_CODE = CurPosition.CurWipSNs.First().ITEM_CODE, QTY = CurPkgItem.Items.Sum(q => q.Package.QTY), UNIT = dtl.PkgType.PKG_NAME, - 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, + WORK_ORDER = CurPosition.CurWipSNs.First().WORK_ORDER, + BATCH_NO = CurPosition.CurWipSNs.First().BATCH_NO, + ROT_CODE = CurPosition.CurWipSNs.First().ROT_CODE, + NODE_ID = CurPosition.CurWipSNs.First().NODE_ID, + NODE_NAME = CurPosition.CurWipSNs.First().NODE_NAME, + FTY_CODE = CurPosition.CurWipSNs.First().FTY_CODE, + WS_CODE = CurPosition.CurWipSNs.First().WS_CODE, + LINE_CODE = CurPosition.CurWipSNs.First().LINE_CODE, + POST_CODE = CurPosition.CurWipSNs.First().POST_CODE, + OPER_CODE = CurPosition.CurWipSNs.First().OPER_CODE, + SEGMENT = CurPosition.CurWipSNs.First().SEGMENT, }; FinishLevel++; //瀹屾垚鍖呰鐨勫眰绾у皬浜庢渶澶栧眰鍖呰灞傜骇 @@ -336,7 +408,7 @@ //鏈�澶栧眰鍖呰宸茬粡瀹屾垚鍖呰锛屼繚瀛樺寘瑁呮暟鎹埌鏁版嵁搴� else { - action = SaveToDB(); + action = CompletePkg(); } } //褰撳墠澶勭悊鐨勫寘瑁呭眰绾у凡缁忓鐞嗗畬锛岀户缁線涓婁繚瀛� @@ -357,18 +429,21 @@ IS_MIN_PKG = nextDtl.PkgType.IS_MIN_PKG, PKG_LEVEL = nextDtl.PKG_LEVEL, PKG_QTY = nextDtl.PKG_QTY, - LABEL_CODE = LabelDic[nextDtl.PKG_LEVEL].LABEL_CODE, + LABEL_CODE = LabelDic[nextDtl.PKG_LEVEL]?.LABEL_CODE, }; curItem.Items.Add(next); } curItem = next; } //娣诲姞褰撳墠鐨勫寘瑁呮槑缁嗗埌涓婁竴灞傚寘瑁呯殑鏄庣粏鍒楄〃 - curItem.Items.Add(CurPkgItem); + if (!curItem.Items.Contains(CurPkgItem)) + { + curItem.Items.Add(CurPkgItem); + } CurPkgItem = curItem; //娣诲姞鏄庣粏鍚庡垽鏂綋鍓嶅寘瑁呭眰绾х殑鏄庣粏鏁伴噺鏄惁绛変簬鍖呰鏁伴噺锛岃嫢鐩哥瓑鍒欐爣璁板綋鍓嶅寘瑁呭眰绾т负瀹屾垚骞跺皾璇曟墦鍗版爣绛� - if (CurPkgItem.Items.Count == CurPkgItem.PKG_QTY) + if (CurPkgItem.Items.Count(q => q.IsFinished) == CurPkgItem.PKG_QTY || CurStep.IsNullOrEmpty()) { //琛屼负璁惧畾鐨凮PTION_1-9鏄寘瑁呬笉鍚屽眰绾х殑鏍囩妯℃澘浠g爜锛屽鏋滀负绌哄垯涓嶉渶瑕佹墦鍗� if (LabelDic[dtl.PKG_LEVEL].IsNullOrEmpty()) @@ -376,6 +451,7 @@ var data = new PackingActionOutput() { PkgInfo = CurPkg }; data.ExecCode = "Scan"; data.PkgLevel = dtl.PKG_LEVEL; + CurCmd = data; action.Data.Data = data; //action.LocaleMsg = new($"璇锋壂鎻忕{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮�"); action.LocaleMsg = new("MES.WorkAction.PackingAction.PleaseScanLabel", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); @@ -389,11 +465,11 @@ data.ExecCode = "Print"; data.PkgLevel = dtl.PKG_LEVEL; data.PrintLable = LabelDic[dtl.PKG_LEVEL]; - CurPrint = data; + CurCmd = data; PrintTimes++; action.Data.Data = data; - //action.LocaleMsg = new Locale($"寮�濮嬬{PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL].LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); - action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL].LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); + //action.LocaleMsg = new Locale($"寮�濮嬬{PrintTimes}娆℃墦鍗扮{dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛綶{LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE}: {LabelDic[dtl.PKG_LEVEL].LABEL_NAME}]"); + action.LocaleMsg = new Locale("MES.WorkAction.PackingAction.BeginPrint", PrintTimes, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, LabelDic[dtl.PKG_LEVEL]?.LABEL_CODE, LabelDic[dtl.PKG_LEVEL].LABEL_NAME); } } //褰撳墠鍖呰灞傜骇鐨勬槑缁嗘暟閲忔湭杈惧埌鍖呰鏁伴噺锛屽垯瀹屾垚鏈鎵弿锛岀瓑寰呬笅涓骇鍝佽繘绔� @@ -409,7 +485,7 @@ action.IsSuccessed = false; //action.LocaleMsg = new($"瀹㈡埛绔彁浜ょ殑鍖呰灞傜骇[{pdtl.PKG_LEVEL}]({pdtl.PkgType.PKG_NAME})鏁版嵁涓嶆槸姝e湪澶勭悊鐨勫寘瑁呭眰绾{dtl.PKG_LEVEL}]({dtl.PkgType.PKG_NAME})锛屽伐搴忓凡閲嶇疆锛岃閲嶆柊鎵弿杩涚珯浜у搧鏉$爜"); action.LocaleMsg = new("MES.WorkAction.PackingAction.SaveLevelNotMatchException", pdtl.PKG_LEVEL, pdtl.PkgType.PKG_NAME, dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME); - CurPosition.ResetSteps(); + CurPosition.ResetNode(); } } } @@ -420,7 +496,7 @@ action.IsSuccessed = false; //action.LocaleMsg = new($"鎵弿绗瑊dtl.PKG_LEVEL}灞傚寘瑁匸{dtl.PkgType.PKG_NAME}]鐨勬爣绛炬潯鐮乕{input.SN}]鍚庝繚瀛樻暟鎹け璐ワ紝宸ュ簭宸查噸缃紝璇烽噸鏂版壂鎻忚繘绔欎骇鍝佹潯鐮�"); action.LocaleMsg = new("MES.WorkAction.PackingAction.SavePkgDataException", dtl.PKG_LEVEL, dtl.PkgType.PKG_NAME, input.SN); - CurPosition.ResetSteps(); + CurPosition.ResetNode(); } return action; } @@ -436,32 +512,23 @@ return list; } - public ApiAction<SubmitOutput> SaveToDB() + public ApiAction<SubmitOutput> CompletePkg() { var action = new ApiAction<SubmitOutput>(new SubmitOutput()); - - var pkgList = GetPackageList(CurPkg.Item); - - //淇濆瓨鏁版嵁搴� - var db = Biz.Db; - var dbTran = db.UseTran(() => - { - db.Insertable(pkgList, CurPosition.UserCode).ExecuteCommand(); - }); - if (!dbTran.IsSuccess) - { - throw dbTran.ErrorException; - } - - //鍒犻櫎宸ュ簭涓婁笅鏂囦腑鐨勫寘瑁呰褰� - CurPosition.Context.Remove("CurPackage"); var data = new PackingActionOutput() { PkgInfo = CurPkg }; data.ExecCode = "Complete"; data.PkgLevel = CurPkg.Item.PKG_LEVEL; + CurCmd = data; action.Data.Data = data; //action.LocaleMsg = new($"绗瑊CurPkg.Item.PKG_LEVEL}灞傚寘瑁匸{CurPkg.Item.PKG_NAME}]宸茬粡鍏ㄩ儴瀹屾垚锛屼繚瀛樺寘瑁呮暟鎹�"); action.LocaleMsg = new("MES.WorkAction.PackingAction.PackageComplete", CurPkg.Item.PKG_LEVEL, CurPkg.Item.PKG_NAME); + + //鎵嬪姩缁撴潫鍖呰鍒欐爣璁拌涓哄畬鎴� + if (CurStep.IsNullOrEmpty()) + { + IsFinished = true; + } return action; } @@ -475,58 +542,98 @@ var action = new ApiAction<SubmitOutput>(new SubmitOutput()); //璁板綍琛屼负鎿嶄綔璁板綍 - var wipAct = new MES_WIP_ACT() + var wipActs = new List<MES_WIP_ACT>(); + foreach (var wipSn in CurPosition.CurWipSNs) { - AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, - AUTH_PROD = CurPosition.CurLine.LINE_CODE, - HIS_ID = CurPosition.CurWipSNHis.ID, - SN = CurPosition.CurWipSN.SN, - STATUS = CurPosition.CurWipSN.STATUS, - ITEM_CODE = CurPosition.CurWipSN.ITEM_CODE, - 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, - ACT_ID = NodeAct.ID, - ACT_NAME = NodeAct.ACT_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, - TRAY_SN = CurPosition.CurWipSN.TRAY_SN, - OPERATION_TIME = DateTime.Now, - SFTS_CODE = CurPosition.CurWipSN.SFTS_CODE, - SFT_CODE = CurPosition.CurWipSN.SFT_CODE, - PRD_CODE = CurPosition.CurWipSN.PRD_CODE, - ACT_TYPE = NodeAct.ACT_TYPE, - ACT_SN = CurPosition.CurWipSN.SN, - ACT_RESULT = "Y", - TRACE_INFO = $"浜у搧鏉$爜[{CurPosition.CurWipSN.SN}]鍖呰瀹屾垚", - }; + var wipAct = new MES_WIP_ACT() + { + AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, + AUTH_PROD = CurPosition.CurLine.LINE_CODE, + HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID, + SN = wipSn.SN, + STATUS = wipSn.STATUS, + ITEM_CODE = wipSn.ITEM_CODE, + WORK_ORDER = wipSn.WORK_ORDER, + BATCH_NO = wipSn.BATCH_NO, + ROT_CODE = wipSn.ROT_CODE, + NODE_ID = wipSn.NODE_ID, + NODE_NAME = wipSn.NODE_NAME, + ACT_ID = NodeAct.ID, + ACT_NAME = NodeAct.ACT_NAME, + FTY_CODE = wipSn.FTY_CODE, + WS_CODE = wipSn.WS_CODE, + LINE_CODE = wipSn.LINE_CODE, + POST_CODE = wipSn.POST_CODE, + OPER_CODE = wipSn.OPER_CODE, + SEGMENT = wipSn.SEGMENT, + TRAY_SN = wipSn.TRAY_SN, + OPERATION_TIME = DateTime.Now, + SFTS_CODE = wipSn.SFTS_CODE, + SFT_CODE = wipSn.SFT_CODE, + PRD_CODE = wipSn.PRD_CODE, + ACT_TYPE = NodeAct.ACT_TYPE, + ACT_SN = wipSn.SN, + ACT_RESULT = "Y", + TRACE_INFO = $"浜у搧鏉$爜[{string.Join("锛�", CurPosition.CurSN)}]鍖呰瀹屾垚", + }; + wipActs.Add(wipAct); + } + //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊� + var _wipActs = wipActs.Clone(); + var _pkgList = CurPkg.IsFinished ? GetPackageList(CurPkg.Item) : new(); //淇濆瓨鏁版嵁 CurStep.DBSubmitAction = () => { var db = CurPosition.GetCommitDB(); - db.Storageable(wipAct, CurPosition.UserCode).ExecuteCommand(); + db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand(); + if (_pkgList.Any()) + { + db.Insertable(_pkgList, CurPosition.UserCode).ExecuteCommand(); + foreach (var pkg in _pkgList) + { + //鍖呰淇℃伅淇濆瓨鍒板湪鍒跺搧淇℃伅琛� + db.Updateable<MES_WIP_DATA>() + .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN) + .SetColumns(q => q.CONTAINER_SN == q.CARTON_SN) + .SetColumns(q => q.CARTON_SN == CurPkg.Item.Package.SN) + .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN) + .ExecuteCommand(); + //鍖呰淇℃伅淇濆瓨鍒板伐鍗曟潯鐮佹槑缁嗚〃 + db.Updateable<BIZ_MES_WO_SN>() + .SetColumns(q => q.TRAY_SN == CurPkg.Item.Package.SN) + .SetColumns(q => q.OUTER_SN == CurPkg.Item.Package.SN) + .Where(q => q.WORK_ORDER == pkg.WORK_ORDER && q.SN == pkg.SN) + .ExecuteCommand(); + } + } }; - //濡傛灉宸ュ簭涓婁笅鏂囦腑娌℃湁鍖呰璁板綍鍒欐柊寤轰竴涓� - if (CurPosition.Context.ContainsKey("CurPackage")) + if (CurPkg.IsFinished) { - CurPosition.Context["CurPackage"] = CurPkg; + //鏈�澶栧眰鍖呰宸茬粡瀹屾垚鍖呰锛屽垯鎶婂伐搴忎腑鏆傚瓨鏍囪璁句负false锛岀粺涓�鎻愪氦鍖呰鍐呬骇鍝佺殑杩囩珯璁板綍 + CurPosition.NeedTemporaryStoreDBCommitAction = false; + //鍒犻櫎宸ュ簭涓婁笅鏂囦腑鐨勫寘瑁呰褰� + CurPosition.Context.Remove("CurPackage"); } else { - CurPosition.Context.Add("CurPackage", CurPkg); + //鏈�澶栧眰鍖呰鏈畬鎴愬寘瑁咃紝鍒欐妸宸ュ簭涓殏瀛樻爣璁拌涓簍rue锛屽緟鍏ㄩ儴鍖呰瀹屾垚鍐嶇粺涓�鎻愪氦鍖呰鍐呬骇鍝佺殑杩囩珯璁板綍 + CurPosition.NeedTemporaryStoreDBCommitAction = true; + //濡傛灉宸ュ簭涓婁笅鏂囦腑娌℃湁鍖呰璁板綍鍒欐柊寤轰竴涓� + if (CurPosition.Context.ContainsKey("CurPackage")) + { + CurPosition.Context["CurPackage"] = CurPkg; + } + else + { + CurPosition.Context.Add("CurPackage", CurPkg); + } } IsFinished = true; - action.LocaleMsg = new($"浜у搧鏉$爜[{CurPosition.CurWipSN.SN}]鍖呰瀹屾垚"); - action.LocaleMsg = new("MES.WorkAction.PackingAction.PackingSuccess", CurPosition.CurWipSN.SN); + action.LocaleMsg = new($"浜у搧鏉$爜[{CurPosition.CurSN}]鍖呰瀹屾垚"); + action.LocaleMsg = new("MES.WorkAction.PackingAction.PackingSuccess", CurPosition.CurSN); return action; } -- Gitblit v1.9.3