From 28137093fdd7ab9ddd4edfe1774a6f7024166730 Mon Sep 17 00:00:00 2001 From: Rodney Chen <rodney.chen@hotmail.com> Date: 星期二, 03 十二月 2024 21:27:57 +0800 Subject: [PATCH] Merge branch 'master' of http://47.115.28.255:8110/r/TigerClouds-Tech/Server/TigerApi6_2024 --- Tiger.Business.MES/Transaction/YadaPacking.cs | 300 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 258 insertions(+), 42 deletions(-) diff --git a/Tiger.Business.MES/Transaction/YadaPacking.cs b/Tiger.Business.MES/Transaction/YadaPacking.cs index e6d4df5..501eaaa 100644 --- a/Tiger.Business.MES/Transaction/YadaPacking.cs +++ b/Tiger.Business.MES/Transaction/YadaPacking.cs @@ -11,6 +11,9 @@ using Tiger.Model; using Tiger.Model.Entitys.MES.Position; using Tiger.Business.MES.WorkAction; +using Tiger.Model.MES.Yada; +using System.Data; +using System.Diagnostics; namespace Tiger.Business.MES.Transaction { @@ -22,6 +25,7 @@ public new IYadaPacking Init(string id, string apiHost, string userCode, string postCode) { base.Init(id, apiHost, userCode, postCode); + U9CDB = Biz.DataSource["YadaU9C"].Client; Logger.Console.Info($"User[{userCode}] start a {this.GetType().Name}[{postCode}] Transaction[ID: {TransID}]"); return this; } @@ -36,6 +40,11 @@ public string NodeCmd { get; set; } public PackingAction TempPkgAction { get; set; } public bool IsPrintCustomerLabel { get; set; } + public string ShippingOrder { get; set; } + public DbClient U9CDB { get; set; } + public Model.TraceDebug debug { get; set; } + public DateTime curtime = DateTime.Now; + public DateTime prevtime = DateTime.Now; #endregion Propertys & Variables #region Functions @@ -46,23 +55,30 @@ /// <returns></returns> public async Task<ApiAction<SubmitOutput>> Submit(SubmitInput input) { + debug = new(new StackFrame(true)); + debug.Log(new StackFrame(true), "***** 1", info => { ConsoleExt.WriteLine(info.ToString()); }); var action = new ApiAction<SubmitOutput>(new SubmitOutput()); try { - if (input.Qty.ToInt32() <= 0) - { - action.Data.ShortMsg = new("璇疯緭鍏ュ寘瑁呮暟閲�", ShortMessage.Types.Error); - action.Data.OperInfo = new(); - action.Data.Data = "QtyError"; - action.IsSuccessed = false; - action.LocaleMsg = new($"鍖呰鏁伴噺[{input.Qty}]涓嶆纭紝璇烽噸鏂拌緭鍏ユ暟閲忓悗缁х画鍖呰鎿嶄綔"); - //action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.QtyError", input.Qty); - return action; - } - if (input.Options.ContainsKey("IsPrintCustomerLabel")) - { - IsPrintCustomerLabel = input.Options["IsPrintCustomerLabel"].ToBoolean(); - } + //if (input.Qty.ToInt32() <= 0) + //{ + // action.Data.ShortMsg = new("璇疯緭鍏ュ寘瑁呮暟閲�", ShortMessage.Types.Error); + // action.Data.OperInfo = new(); + // action.Data.Data = "QtyError"; + // action.IsSuccessed = false; + // action.LocaleMsg = new($"鍖呰鏁伴噺[{input.Qty}]涓嶆纭紝璇烽噸鏂拌緭鍏ユ暟閲忓悗缁х画鍖呰鎿嶄綔"); + // //action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.QtyError", input.Qty); + // return SetOutPutMqttMsg(action, input.Locale); + //} + //if (input.Options.ContainsKey("IsPrintCustomerLabel")) + //{ + // IsPrintCustomerLabel = input.Options["IsPrintCustomerLabel"].ToBoolean(); + //} + + //if (input.Options.ContainsKey("ShippingOrder")) + //{ + // ShippingOrder = IsPrintCustomerLabel ? input.Options["ShippingOrder"].ToString() : ""; + //} //PkgSubmit锛氭墜鍔ㄧ粨鏉熷寘瑁咃紝鎵嬪姩淇濆瓨鏆傚瓨鐨勫寘瑁呮暟鎹� if (NodeCmd == "PkgSubmit") { @@ -80,32 +96,46 @@ //宸ユ鍒楄〃涓虹┖鎴栬�呭伐搴忚妭鐐瑰伐姝ユ湁鏈畬鎴愭椂锛屼紭鍏堝畬鎴愬伐搴忚妭鐐瑰伐姝� if (Steps.IsNullOrEmpty() || !IsFinishNodeSteps) { + var wosns = MainDB.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER && q.BATCH_NO == s.BATCH_NO)) + .ByAuth(input.AuthOption)//.Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) + .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList(); + debug.Log(new StackFrame(true), "***** 2", info => { ConsoleExt.WriteLine(info.ToString()); }); //鍏堝垽鏂綋鍓嶅伐鍗曚笉涓虹┖涓斿綋鍓嶅矖浣嶅湪褰撳墠宸ュ崟鏄笉鏄绔欙紝濡傛灉鏄垯涓嶅厑璁稿彉鏇村綋鍓嶅伐鍗曪紝灏濊瘯鎶婃潯鐮佺粦瀹氬埌褰撳墠宸ュ崟 if (!CurBatch.IsNullOrEmpty() && CurBatch.IsFirstNode(PostCode)) { //鏇存柊CurBatch CurBatch?.Update(); - //鎻愪氦鏁版嵁 - action = NodeSubmit(action, input); - //鏇存柊宸ュ簭淇℃伅 - if (!action.IsSuccessed) + debug.Log(new StackFrame(true), "***** 3", info => { ConsoleExt.WriteLine(info.ToString()); }); + var wosn = wosns.FirstOrDefault(q => q.Batch.ORDER_NO == CurBatch.WO.ORDER_NO && (q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Finished.GetValue() || q.SN.STATUS == BIZ_MES_WO_SN.STATUSs.Scrap.GetValue())); + if (!wosn.IsNullOrEmpty()) { - var info = WoContext.GetSnOperInfo(input.SN).Data; - info.InputQty = CurOperInfo(input.Locale).InputQty; - action.Data.OperInfo = info; + action.Data.ShortMsg = new($"浜у搧{wosn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()}", ShortMessage.Types.Error); + action.Data.OperInfo = new(); + action.IsSuccessed = false; + //action.LocaleMsg = new($"杩涚珯鎵弿閿欒锛屾潯鐮乕{0}]{1}", input.SN); + action.LocaleMsg = new("MES.Transaction.CollectNode.Submit.SnStatusError", input.SN, wosn.SN.STATUS.GetEnumDesc<BIZ_MES_WO_SN.STATUSs>()); } - else if (Steps.Any() && !IsFinishAllSteps) + else { - action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale)); + //鎻愪氦鏁版嵁 + action = NodeSubmit(action, input); + debug.Log(new StackFrame(true), "***** 4", info => { ConsoleExt.WriteLine(info.ToString()); }); + //鏇存柊宸ュ簭淇℃伅 + if (!action.IsSuccessed) + { + var info = WoContext.GetSnOperInfo(input.SN).Data; + info.InputQty = CurOperInfo(input.Locale).InputQty; + action.Data.OperInfo = info; + } + else if (Steps.Any() && !IsFinishAllSteps) + { + action.Data.OperInfo = SetOperNodeInfo(CurOperInfo(input.Locale)); + } } } //褰撳墠宀椾綅鍦ㄥ綋鍓嶅伐鍗曚笉鏄绔欙紝鍒欐煡鎵炬潯鐮佸凡缁戝畾鐨勫伐鍗曞綋浣滃綋鍓嶅伐鍗� else { - var wosns = Biz.Db.Queryable<BIZ_MES_WO_BATCH, BIZ_MES_WO_SN>((q, s) => new JoinQueryInfos(JoinType.Inner, q.ORDER_NO == s.WORK_ORDER && q.BATCH_NO == s.BATCH_NO)) - .ByAuth(input.AuthOption)//.Where((q, s) => s.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue()) - .Where((q, s) => s.SN == input.SN || s.FLOW_SN == input.SN || s.TRAY_SN == input.SN).Select((q, s) => new { Batch = q, SN = s }).ToList(); - //鏌ユ壘鍒版潯鐮佸凡缁戝畾鐨勫伐鍗� if (wosns.Any(q => q.SN.STATUS < BIZ_MES_WO_SN.STATUSs.Finished.GetValue())) { @@ -117,7 +147,7 @@ action.IsSuccessed = false; //action.LocaleMsg = new($"鏉$爜[{0}]鏄浇鍏锋潯鐮侊紝璇锋壂鎻忚浇鍏蜂腑鐨勪骇鍝佹潯鐮佺户缁寘瑁呮搷浣�"); action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.OnlyMinPackage", input.SN); - return action; + return SetOutPutMqttMsg(action, input.Locale); } var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null; if (!curPkg.IsNullOrEmpty() && !curPkg.IsFinished && curPkg.WorkBatch != curSNs.First().Batch.BATCH_NO) @@ -127,7 +157,7 @@ action.IsSuccessed = false; //action.LocaleMsg = new($"姝e湪鍖呰宸ュ崟鎵规[{0}]鐨勪骇鍝侊紝璇峰厛瀹屾垚褰撳墠鍖呰鍚庡啀鎵弿鍏朵粬鎵规[{1}]鐨勪骇鍝乕{2}]"); action.LocaleMsg = new("MES.Transaction.PackingNode.Submit.BatchError", curPkg.WorkBatch, curSNs.First().Batch.BATCH_NO, input.SN); - return action; + return SetOutPutMqttMsg(action, input.Locale); } if (curSNs.First().Batch.ACT_LINE != CurLine.LINE_CODE) { @@ -149,7 +179,7 @@ action.Data.OperInfo = new(); action.IsSuccessed = result.IsSuccessed; action.LocaleMsg = result.LocaleMsg; - return action; + return SetOutPutMqttMsg(action, input.Locale); } } //鏇存柊CurBatch @@ -210,20 +240,23 @@ { //鏇存柊CurBatch CurBatch?.Update(); - + debug.Log(new StackFrame(true), "***** 5", info => { ConsoleExt.WriteLine(info.ToString()); }); var submitStep = Steps.Where(q => q.ID == input.CurStepID && !q.IsFinished).FirstOrDefault(); //濡傛灉瀹㈡埛绔繑鍥炵殑褰撳墠宸ユID鎵句笉鍒版湭瀹屾垚鐨勮涓哄伐姝ワ紝鍒欑洿鎺ュ紑濮嬩笅涓�涓涓哄伐姝� if (submitStep.IsNullOrEmpty()) { action = BeginNextActionStep(input); + debug.Log(new StackFrame(true), "***** 6", info => { ConsoleExt.WriteLine(info.ToString()); }); } else { action = submitStep.Submit(input); + debug.Log(new StackFrame(true), "***** 7", info => { ConsoleExt.WriteLine(info.ToString()); }); //濡傛灉褰撳墠宸ユ宸插畬鎴愶紝寮�濮嬫墽琛屼笅涓�宸ユ if (action.IsSuccessed && submitStep.IsFinished) { action = BeginNextActionStep(input); + debug.Log(new StackFrame(true), "***** 8", info => { ConsoleExt.WriteLine(info.ToString()); }); } //濡傛灉褰撳墠宸ユ鏈畬鎴� else @@ -268,7 +301,8 @@ //action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氭彁浜ゆ搷浣滄暟鎹紓甯�"); action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.SubmitException")); } - return action; + debug.Log(new StackFrame(true), "***** 9", info => { ConsoleExt.WriteLine(info.ToString()); }); + return SetOutPutMqttMsg(action, input.Locale); } /// <summary> @@ -279,6 +313,7 @@ /// <returns></returns> public ApiAction<SubmitOutput> NodeSubmit(ApiAction<SubmitOutput> action, SubmitInput input) { + debug.Log(new StackFrame(true), "***** 10", info => { ConsoleExt.WriteLine(info.ToString()); }); var curNode = CurBatch.GetNode(PostCode); try { @@ -305,7 +340,7 @@ return woStatus; } - var wipSNs = Biz.Db.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN || q.TRAY_SN == input.SN).ToList(); + var wipSNs = MainDB.Queryable<MES_WIP_DATA>().IncludesAllFirstLayer().Where(q => q.SN == input.SN || q.FLOW_SN == input.SN || q.TRAY_SN == input.SN).Where(q => q.FINISHED_FLAG != "Y").ToList(); if (wipSNs.IsNullOrEmpty()) { var wipSN = new MES_WIP_DATA() @@ -314,6 +349,7 @@ FLOW_SN = input.SN, STATUS = MES_WIP_DATA.STATUSs.Init.GetValue(), ITEM_CODE = CurBatch.WO.ITEM_CODE, + QTY = 1, WORK_ORDER = CurBatch.Batch.ORDER_NO, BATCH_NO = CurBatch.Batch.BATCH_NO, FTY_CODE = CurFactory.FTY_CODE, @@ -323,6 +359,7 @@ HOLD_FLAG = "N", REWORK_FLAG = CurBatch.WO.ORDER_TYPE == BIZ_MES_WO.ORDER_TYPEs.Rework.GetValue() ? "Y" : "N", FINISHED_FLAG = "N", + UNBIND_FLAG = "N", INV_FLAG = "N", DFT_FLAG = "N", DFT_COUNT = 0, @@ -361,7 +398,52 @@ //璁剧疆褰撳墠鎸囦护涓烘甯镐骇鍝佽繃绔� NodeCmd = "NodeSubmit"; + debug.Log(new StackFrame(true), "***** 11", info => { ConsoleExt.WriteLine(info.ToString()); }); + //鑾峰彇鍑鸿揣鐘舵�� + var ship = U9CDB.Queryable<mes_ShipList>().Where(q => q.MoDoc == CurBatch.WO.ORDER_NO && q.Status == 2 && SqlFunc.DateIsSame(q.BusinessDate, DateTime.Now)).First(); + int CurShipQty = 0; + int WaitShipmentCarton = 0; + int WaitShipment = 0; + if (ship.IsNullOrEmpty()) { IsPrintCustomerLabel = false; } + else + { + CurShipQty = ship.ShipQty; + IsPrintCustomerLabel = true; + SugarParameter[] pars = MainDB.Ado.GetParameters(new { BATCH = CurBatch.Batch.BATCH_NO, NodeIdOrName = curNode.NODE_NAME }); + var list = MainDB.Ado.UseStoredProcedure().GetDataTable("SP_MES_GET_NODE_BATCH_COUNT", pars).AsEnumerable().ToList(); + if (!list.IsNullOrEmpty()) + { + var batchCount = list.Where(q => q["ProdDate"].ToString() == "Whole").FirstOrDefault(); + WaitShipmentCarton = batchCount["WaitShipmentCarton"].ToInt32(); + WaitShipment = batchCount["WaitShipment"].ToInt32(); + IsPrintCustomerLabel = batchCount.IsNullOrEmpty() ? IsPrintCustomerLabel : batchCount["WaitShipment"].ToInt32() >= ship.ShipQty ? false : true; + } + } + ShippingOrder = IsPrintCustomerLabel ? ship?.ShipDoc ?? "" : ""; + //缂撳瓨鍑鸿揣鏁伴噺 + Context.SetOrAdd("CurShipQty", CurShipQty); + //if (Context.ContainsKey("CurShipQty")) + //{ + // Context["CurShipQty"] = CurShipQty; + //} + //else + //{ + // Context.Add("CurShipQty", CurShipQty); + //} + //缂撳瓨鍑鸿揣绠辨暟 + Context.SetOrAdd("CurWaitShipmentCarton", WaitShipmentCarton); + Context.SetOrAdd("CurWaitShipment", WaitShipment); + //if (Context.ContainsKey("CurWaitShipmentCarton")) + //{ + // Context["CurWaitShipmentCarton"] = WaitShipmentCarton; + //} + //else + //{ + // Context.Add("CurWaitShipmentCarton", WaitShipmentCarton); + //} + + debug.Log(new StackFrame(true), "***** 12", info => { ConsoleExt.WriteLine(info.ToString()); }); //缁戝畾鏉$爜鍒板伐鍗� foreach (var wipSN in wipSNs) { @@ -375,6 +457,7 @@ FLOW_SN = wipSN.SN, TRAY_SN = wipSN.TRAY_SN, STATUS = BIZ_MES_WO_SN.STATUSs.NotInput.GetValue(), + QTY = 1, }); } } @@ -404,6 +487,8 @@ wipSN.OPER_CODE = curNode.OPER_CODE; wipSN.SEGMENT = curNode.SEGMENT; wipSN.OPERATION_TIME = DateTime.Now; + wipSN.SHIPPING_ORDER = ShippingOrder; + wipSN.UNBIND_FLAG = "N"; var curShiftPeriod = GetShiftPeriodForNow(); if (!curShiftPeriod.IsNullOrEmpty()) { @@ -424,7 +509,7 @@ { var woSN = woSNs.First(q => q.WIP_ID == wipSN.ID); woSN.STATUS = BIZ_MES_WO_SN.STATUSs.Finished.GetValue(); - wipSN.STATUS = MES_WIP_DATA.STATUSs.Finished.GetValue(); + wipSN.STATUS = MES_WIP_DATA.STATUSs.Output.GetValue(); wipSN.OUTLINE_DATE = DateTime.Now; } //濡傛灉鏈夋彁浜や笉鑹� @@ -470,8 +555,16 @@ OBA_BATCH = wipSN.OBA_BATCH, LOCK_BATCH = wipSN.LOCK_BATCH, }; + wipSN.Defects.Add(defect); CurDefects.Add(defect); } + } + + //浜у搧琚垽鏂笉鑹悗涓嬬嚎锛屽苟浠庡伐鍗曚腑绉婚櫎姝e湪鐢熶骇鐨勬潯鐮� + if (CurDefects.Any() && curNodeSetting.IF_DFT_OFFLINE == "Y") + { + woStatus.Data.ShortMsg = new("浜у搧涓嬬嚎", ShortMessage.Types.Error); + return OfflineIfDefect(action, wipSNs, input.Locale); } //宸ュ崟寮�宸� @@ -495,6 +588,7 @@ var _curNodeSetting = curNodeSetting.Clone(); var _Batch = CurBatch.Batch.Clone(); + debug.Log(new StackFrame(true), "***** 13", info => { ConsoleExt.WriteLine(info.ToString()); }); //鍒濆鍖栧伐姝ュ垪琛� Steps.Clear(); var curStep = new WorkStep(IWorkStep.NodeTypes.Node, this) @@ -618,6 +712,7 @@ //action.CatchExceptionWithLog(ex, $"{curNode.NODE_NAME}锛氬伐搴忚妭鐐瑰伐姝ユ彁浜ゆ暟鎹紓甯革紝璇锋鏌ュ伐搴忚妭鐐硅缃�"); action.CatchExceptionWithLog(ex, Biz.L("MES.Transaction.PackingNode.NodeSubmitException", curNode.NODE_NAME)); } + debug.Log(new StackFrame(true), "***** 13.1", info => { ConsoleExt.WriteLine(info.ToString()); }); return action; } @@ -631,6 +726,7 @@ var curPkg = Context.ContainsKey("CurPackage") ? Context["CurPackage"] as WipPkg : null; var operInfo = SetOperNodeInfo(CurOperInfo(locale)); Action endAction = null; + debug.Log(new StackFrame(true), "***** 14", info => { ConsoleExt.WriteLine(info.ToString()); }); //濡傛灉褰撳墠鏉$爜宸茬粡璧板埌娴佺▼缁堢偣鍒欒褰曟潯鐮佸畬宸� if (operInfo.IsReachedEndNode) @@ -650,7 +746,7 @@ //鏉$爜瀹屽伐 foreach (var wipSN in CurWipSNs) { - wipSN.STATUS = MES_WIP_DATA.STATUSs.Finished.GetValue(); + wipSN.FINISHED_FLAG = "Y"; wipSN.NODE_ID = curNode.ID; wipSN.NODE_NAME = curNode.NODE_NAME; wipSN.OPER_CODE = curNode.OPER_CODE; @@ -670,7 +766,8 @@ var _woSns = woSNs.Clone(); var _wipSns = CurWipSNs.Clone(); var _wipHiss = wipHiss.Clone(); - var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item) : new(); + var _pkgList = curPkg?.IsFinished == true ? GetPackageList(curPkg.Item).Clone() : new(); + var _wipIDs = curPkg?.IsFinished == true ? curPkg.Item.GetWipSnList().Select(q => q.Key).ToList().Clone() : new(); //淇濆瓨鏁版嵁 endAction = () => { @@ -682,14 +779,14 @@ db.Storageable(_wipHiss, UserCode).ExecuteCommand(); if (_pkgList.Any()) { - var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList(); + //var wipIDs = _pkgList.Where(q => !q.WIP_ID.IsNullOrEmpty()).Select(q => q.WIP_ID).ToList(); var wo = _pkgList.First().WORK_ORDER; //鍖呰淇℃伅淇濆瓨鍒扮敓浜ц繃绋嬭褰� - db.Updateable<MES_WIP_HIS>() + db.Updateable<MES_WIP_HIS>(UserCode) .SetColumns(q => q.TRAY_SN == curPkg.Item.Package.SN) .SetColumns(q => q.INNER_SN == q.CARTON_SN) .SetColumns(q => q.CARTON_SN == curPkg.Item.Package.SN) - .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && wipIDs.Contains(q.WIP_ID)) + .Where(q => q.WORK_ORDER == wo && q.OPER_CODE == "EndNode" && _wipIDs.Contains(q.WIP_ID)) .ExecuteCommand(); } }; @@ -699,7 +796,7 @@ SaveStepsCommitActionToDB(endAction); //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭� - CurOperInfo(locale).InputQty += CurWipSNs.Count; + operInfo.InputQty += CurWipSNs.Count; action.Data.Data = new PackingActionOutput() { PkgInfo = curPkg }; action.Data.OperInfo = operInfo; action.Data.ShortMsg = new(CurWipSNs.Any(q => q.DFT_FLAG == "Y") ? "涓嶈壇杩囩珯" : "鑹搧杩囩珯", ShortMessage.Types.Success); @@ -714,7 +811,76 @@ //閲嶇疆宸ュ簭 ResetNode(); + debug.Log(new StackFrame(true), "***** 15", info => { ConsoleExt.WriteLine(info.ToString()); }); + return action; + } + /// <summary> + /// 浜у搧琚垽鏂笉鑹悗涓嬬嚎 + /// </summary> + /// <param name="action"></param> + /// <returns></returns> + public ApiAction<SubmitOutput> OfflineIfDefect(ApiAction<SubmitOutput> action, List<MES_WIP_DATA> wipSNs, string locale) + { + var operInfo = SetOperNodeInfo(CurOperInfo(locale)); + operInfo.CurNode = wipSNs.FirstOrDefault()?.NODE_NAME; + operInfo.NextNode = "涓嬬嚎閫�搴�"; + + //鏇存柊宸ュ崟鏉$爜鏄庣粏淇℃伅 + var woSNs = CurBatch.WoSNs.Where(q => wipSNs.Any(w => q.WIP_ID == w.ID)).ToList(); + foreach (var woSN in woSNs) + { + woSN.STATUS = BIZ_MES_WO_SN.STATUSs.Offline.GetValue(); + } + + //鏉$爜涓嬬嚎 + foreach (var wipSN in wipSNs) + { + wipSN.STATUS = MES_WIP_DATA.STATUSs.Offline.GetValue(); + wipSN.UNBIND_FLAG = "Y"; + } + + var wipHiss = new List<MES_WIP_HIS>(); + foreach (var wipSN in wipSNs) + { + var his = new MES_WIP_HIS(wipSN, $"宸ュ崟[{wipSN.WORK_ORDER}]鏉$爜[{wipSN.SN}]鍦ㄥ矖浣峓{wipSN.POST_CODE}]宸ュ簭[{wipSN.NODE_NAME}]鍥犱笉鑹痆{wipSN.Defects.FirstOrDefault()?.DFT_NAME}]涓嬬嚎锛圱ransId锛� {TransID} 锛�"); + wipSN.History.Add(his); + wipHiss.Add(his); + } + + //鍒涘缓鍙橀噺鍏嬮殕瀵硅薄鐢ㄤ簬浼犲叆DBSubmitAction涓繚瀛樺綋鍓嶉渶瑕佹殏瀛樼殑鏁版嵁鍊� + var _woSns = woSNs.Clone(); + var _wipSns = wipSNs.Clone(); + var _wipHiss = wipHiss.Clone(); + var _defect = CurDefects.Clone(); + //浣跨敤缁熶竴鐨勪簨鍔B瀵硅薄 + var db = GetCommitDB(); + //淇濆瓨鏁版嵁搴� + var dbTran = db.UseTran(() => + { + //鏁版嵁淇濆瓨閫昏緫 + db.Storageable(_woSns, UserCode).ExecuteCommand(); + db.Storageable(_wipSns, UserCode).ExecuteCommand(); + db.Storageable(_wipHiss, UserCode).ExecuteCommand(); + db.Storageable(_defect, UserCode).ExecuteCommand(); + }); + if (!dbTran.IsSuccess) + { + //鎶涘嚭寮傚父 + throw dbTran.ErrorException; + } + + //浠庡伐鍗曚腑绉婚櫎姝e湪鐢熶骇鐨勬潯鐮� + CurBatch.RemoveWipSn(wipSNs, UserCode); + + //淇濆瓨鎴愬姛锛岃繑鍥炶繃绔欐秷鎭� + action.Data.OperInfo = operInfo; + action.Data.ShortMsg = new("涓嬬嚎閫�搴�", ShortMessage.Types.Warning); + //action.LocaleMsg = new($"宸ュ崟[0]鐨勬潯鐮乕1]鍦ㄥ矖浣峓2]宸ュ簭[3]鍥犱笉鑹痆4]涓嬬嚎锛岀姸鎬乕5]"); + action.LocaleMsg = new("MES.Transaction.TestNode.OfflineIfDefect", wipSNs.First().WORK_ORDER, CurSN, wipSNs.First().POST_CODE, wipSNs.First().NODE_NAME, wipSNs.First().Defects.FirstOrDefault()?.DFT_NAME, wipSNs.First().STATUS.GetEnumDesc<MES_WIP_DATA.STATUSs>()); + + //閲嶇疆宸ュ簭 + ResetNode(); return action; } @@ -737,7 +903,7 @@ TempPkgAction.Init(this); int shipQty = input.Data.ToInt32(); - int curQty = CurPkg.Item.TotalQty; + double curQty = CurPkg.Item.TotalQty; int ruleQty = TempPkgAction.PkgRule.GetTotalQty(); //鏈夊~鍑鸿揣鏁伴噺鍒欓獙璇佸綋鍓嶅寘瑁呮暟閲忓繀椤荤瓑浜庯紙鍑鸿揣鏁伴噺/鍖呰瑙勫垯鏁伴噺锛夌殑浣欐暟 if (shipQty > 0 && curQty != shipQty % ruleQty) @@ -745,7 +911,7 @@ action.IsSuccessed = false; //action.LocaleMsg = new($"鍑鸿揣鏁伴噺璁惧畾涓篬{0}]锛岀洰鍓嶅寘瑁呬簡[{1}]锛屽寘瑁呭熬鏁扮殑鏁伴噺蹇呴渶鏄痆{2}]锛岃瑁呭鏁伴噺鍚庡啀缁撴潫鍖呰"); action.LocaleMsg = new("MES.Transaction.PackingNode.NotMatchShipQty", shipQty, curQty, shipQty % ruleQty); - return action; + return SetOutPutMqttMsg(action); } NodeCmd = "PkgSubmit"; @@ -778,6 +944,56 @@ action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氭墜鍔ㄧ粨鏉熷寘瑁呭紓甯�"); NodeCmd = null; } + return SetOutPutMqttMsg(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 = MainDB.Queryable<BAS_LABEL_PV>().ToList(); + var label = CurPkg.Item.LABEL_CODE.IsNullOrEmpty() ? null : MainDB.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; + } + + /// <summary> + /// 鑾峰彇鏄惁鎵撳嵃瀹㈡埛鏍囩杩樻槸鍏ュ簱鏍囩 + /// </summary> + /// <returns></returns> + public async Task<ApiAction<ShipingInfo>> GetIsCustomerLabelAndShipQty() + { + var action = new ApiAction<ShipingInfo>(); + try + { + action.Data = new ShipingInfo() + { + IsPrintCustomerLabel = IsPrintCustomerLabel, + ShipQty = Context.GetOrDefault("CurWaitShipment").ToInt32() >= Context.GetOrDefault("CurShipQty").ToInt32() ? CurBatch.Batch.PLAN_QTY - Context.GetOrDefault("CurShipQty").ToInt32() : Context.GetOrDefault("CurShipQty").ToInt32() + }; + } + catch (Exception ex) + { + action.CatchExceptionWithLog(ex, $"鍖呰宸ュ簭锛氳幏鍙栨槸鍚︽墦鍗板鎴锋爣绛捐繕鏄叆搴撴爣绛惧紓甯�"); + } return action; } -- Gitblit v1.9.3