From 976d3ae1547b896cc5c7875408c09616d5c2ee55 Mon Sep 17 00:00:00 2001 From: Ben Lin <maobin001@msn.com> Date: 星期二, 26 十一月 2024 20:51:17 +0800 Subject: [PATCH] 箱数更新 --- Tiger.Business.MES/Transaction/Position.cs | 266 ++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 202 insertions(+), 64 deletions(-) diff --git a/Tiger.Business.MES/Transaction/Position.cs b/Tiger.Business.MES/Transaction/Position.cs index 460e71e..6bc6cc8 100644 --- a/Tiger.Business.MES/Transaction/Position.cs +++ b/Tiger.Business.MES/Transaction/Position.cs @@ -14,6 +14,8 @@ using System.Globalization; using Tiger.Business.MES.WorkAction; using System.Collections; +using Tiger.IBusiness.MES.WorkAction; +using Dm.parser; namespace Tiger.Business.MES.Transaction { @@ -62,6 +64,7 @@ public WorkBatch CurBatch { get; set; } public IWorkBatch WorkBatch => CurBatch; public List<MES_WIP_DATA> CurWipSNs { get; set; } = new(); + public List<MES_WIP_DATA> LastWipSNs { get; set; } = new(); public string CurSN => (CurWipSNs.Any() ? (CurWipSNs.First().TRAY_SN.IsNullOrEmpty() ? CurWipSNs.First().SN : CurWipSNs.First().TRAY_SN) : ""); public List<MES_WIP_HIS> CurWipSNHiss { get; set; } = new(); public List<MES_WIP_DFT> CurDefects { get; set; } = new(); @@ -117,7 +120,7 @@ { action.IsSuccessed = false; //action.LocaleMsg = new($"宸ュ崟[{0}]鐘舵�乕{1}]涓嶈兘鐢熶骇"); - action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, wo.STATUS.GetEnum<BIZ_MES_WO.STATUSs>().GetName()); + 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) @@ -135,11 +138,12 @@ { action.IsSuccessed = false; //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()); + action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.BatchStatusException", input.OrderNo, batch.BATCH_NO, batch.STATUS.GetEnumDesc<BIZ_MES_WO_BATCH.STATUSs>()); return action; } var wb = new WorkBatch(input.OrderNo).Init(CurLine.LINE_CODE); WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb); + batchNo = wb.Batch.BATCH_NO; } CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE, batchNo); if (!OperInfoDic.ContainsKey(CurBatch.Batch.BATCH_NO)) @@ -410,24 +414,24 @@ //淇濆瓨宸ユ鐨勬暟鎹簱鎻愪氦鎿嶄綔鍒版彁浜ゆ搷浣滃垪琛� if (!Steps.IsNullOrEmpty()) { - var commitList = new List<Action>(); - foreach (var step in Steps.OrderBy(q => q.Sequence)) - { - commitList.Add(step.DBSubmitAction); - } - //璁板綍宸ュ簭鑰楁椂 - commitList.Add(() => - { - EndAt = DateTime.Now; - var ids = CurWipSNHiss.Select(q => q.ID).ToList(); - GetCommitDB().Updateable<MES_WIP_HIS>().SetColumns(q => q.ELAPSED_TIME == ElapsedTime.TotalMilliseconds.ToInt64()).Where(q => ids.Contains(q.ID)).ExecuteCommand(); - }); + var commitList = new List<Action>(); + foreach (var step in Steps.OrderBy(q => q.Sequence)) + { + commitList.Add(step.DBSubmitAction); + } + //璁板綍宸ュ簭鑰楁椂 + var ids = CurWipSNHiss.Select(q => q.ID).ToList().Clone(); + commitList.Add(() => + { + EndAt = DateTime.Now; + GetCommitDB().Updateable<MES_WIP_HIS>().SetColumns(q => q.ELAPSED_TIME == ElapsedTime.TotalMilliseconds.ToInt64()).Where(q => ids.Contains(q.ID)).ExecuteCommand(); + }); //澧炲姞闄勫姞鐨勪繚瀛樺唴瀹� if (!appendToSave.IsNullOrEmpty()) { commitList.Add(appendToSave); } - DBCommitList.Add(CurSN, commitList); + DBCommitList.Add(CurSN, commitList); } else { @@ -479,6 +483,9 @@ throw dbTran.ErrorException; } } + //璁板綍鏈�鍚庢垚鍔熻繃绔欑殑鏉$爜 + LastWipSNs.Clear(); + LastWipSNs.AddRange(CurWipSNs); } protected void DoSaveToDB() @@ -507,6 +514,11 @@ /// <returns></returns> public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action) { + return SetLabelVariables(labelPVs, label, action, null); + } + + public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action, WipPkg? CurPkg) + { foreach (var item in label.Variables.OrderBy(q => q.VAR_TYPE == BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate.GetValue() ? 0 : 1)) { switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>()) @@ -515,7 +527,7 @@ item.Value = item.VAR_VALUE; break; case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable: - item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action); + item.Value = GetPrintProcessValue(labelPVs, item, label.Variables, action, CurPkg); break; case BAS_LABEL_VAR.VAR_TYPEs.DateVariable: item.Value = DateTime.Now.ToString(item.VAR_VALUE); @@ -538,7 +550,7 @@ /// <param name="labelPVs">杩囩▼鍙橀噺鍒楄〃</param> /// <param name="lv">鏍囩妯℃澘鍙橀噺</param> /// <returns></returns> - public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction action) + public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, List<BAS_LABEL_VAR> lvars, IWorkAction curAction, WipPkg? CurPkg) { var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE); if (!pv.IsNullOrEmpty()) @@ -551,58 +563,130 @@ { case "GetSN": return CurSN; + case "GetItemCode": + return GetLabelVarWo(lv, WorkBatch.Product.ITEM_CODE); case "GetBAS_ITEM": - return WorkBatch.Product.CUST_PROD_CODE; + return GetLabelVarWo(lv, WorkBatch.Product.CUST_PROD_CODE); + case "GetItemName": + return GetLabelVarWo(lv, WorkBatch.Product.ITEM_NAME); case "GetCustomer": - return WorkBatch.Batch.Customer.ToJson(); + return GetLabelVarWo(lv, WorkBatch.Batch.Customer.ToJson()); + case "GetSalesOrder": + return GetLabelVarWo(lv, WorkBatch.WO.SALES_ORDER); + case "GetPackNumber": + return GetLabelVarWo(lv, WorkBatch.WO.ORDER_NO); case "GetBoxQR": - return action is PackingAction ? GetBoxCode(lvars, action as PackingAction) : ""; + return GetCardOrBoxQR(GetBoxCode(), curAction, CurPkg); case "GetCardQR": - return action is PackingAction ? GetCardCode(lvars, action as PackingAction) : ""; + return GetCardOrBoxQR("", curAction, CurPkg); case "GetCardSN": List<string> minPkgList = new List<string>(); - var _pkaction = action is PackingAction ? action as PackingAction : null; - if (_pkaction != null) + if (!CurPkg.IsNullOrEmpty()) { - minPkgList = GetMinPkgList(_pkaction); + minPkgList = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } + else + { + var _pkaction = curAction is PackingAction ? curAction as PackingAction : null; + if (!_pkaction.IsNullOrEmpty()) + { + minPkgList = GetMinPkgList(_pkaction); + } } return string.Join("\r\n", minPkgList); case "GetDescription": - return WorkBatch.Product.ITEM_DESC; + return GetLabelVarWo(lv, WorkBatch.Product.ITEM_DESC); case "GetFengZ": - return WorkBatch.Product.ExtInfo.Packaging; + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo.Packaging); case "GetPAndO": - return WorkBatch.WO.SALES_CONTRACT; + return GetLabelVarWo(lv, WorkBatch.WO.SALES_CONTRACT); case "GetLTD": - return WorkBatch.Batch.Customer.SHORT_NAME; + return GetLabelVarWo(lv, WorkBatch.WO.Customer?.CUST_NAME_CN); case "GetHWDate": List<string> list = new List<string>(); - var _action = action is PackingAction ? action as PackingAction : null; - if (_action!=null) + if (!CurPkg.IsNullOrEmpty()) { - list = GetMinPkgList(_action); + list = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } + else + { + var _action = curAction is PackingAction ? curAction as PackingAction : null; + if (_action != null) + { + list = _action.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } } 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) + if (!CurPkg.IsNullOrEmpty()) { - qtylist = GetMinPkgList(_qtyAction); + qtylist = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); } - return $"{qtylist.Count}PCS"; + else + { + if (curAction is PackingAction) + { + qtylist = (curAction as PackingAction).CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } + if (curAction is PrintInStoreLabel) + { + qtylist = (curAction as PrintInStoreLabel).CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } + } + return $"{qtylist.Count}"; case "GetModel": return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Model); - case "GetInput": + case "GetInput": return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Input); - case "GetOutput": + case "GetOutput": return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.OutPut); - case "GetPower": + case "GetPower": return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Power); - case "GetAccuracy": + case "GetAccuracy": return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Accuracy); case "GetVarByWo": return GetLabelVarWo(lv, ""); + case "GetLOTNO": + string _lotnos = ""; + var _orderAction = curAction is PackingAction ? curAction as PackingAction : null; + if (!CurPkg.IsNullOrEmpty()) + { + qtylist = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + } + else + { + if (_orderAction != null) + { + var snList = _orderAction.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + if (!snList.Any()) + { + snList.Add(_orderAction.CurPkg.CustSN?.FLOW_SN); + } + _lotnos = string.Join(",", Biz.Db.Queryable<MES_CUST_SN>() + .Where((q) => snList.Contains(q.FLOW_SN)) + .Select((q) => q.WORK_ORDER).Distinct().ToList()); + return _lotnos; + } + } + return ""; + case "GetNOTES": + return GetLabelVarWo(lv, WorkBatch.Product.ExtInfo?.Remark); + case "GetXH": + return ""; + case "GetCardNo": + return $"{Context["CurWaitShipmentCarton"].ToInt32() + 1}"; + case "GetCardTotal": + var total = ""; + var _curaction = curAction is PackingAction ? curAction as PackingAction : null; + if (!_curaction.IsNullOrEmpty()) { + total = $"{Math.Ceiling(Context["CurShipQty"].ToDecimal()/_curaction.PkgRule.GetTotalQty().ToDecimal())}"; + } + return total; + case "GetModelSpec": //Model+绌烘牸+SPEC, + return GetLabelVarWo(lv, $"{WorkBatch.Product.ExtInfo?.Model} {WorkBatch.Product.SPEC}"); + case "GetDATE": + return GetLabelVarWo(lv, $"{DateTime.Now.ToString("yyyy/MM/dd")}"); default: return ""; } @@ -665,7 +749,7 @@ } else { - result = value.IsNullOrEmpty() ? (labelVarwos.Count > 0 ? labelVarwos.First().DEFAULT_VALUE : "") : value; + result = value.IsNullOrEmpty() ? (labelVarwos.Count > 0 ? labelVarwos.First(q => q.WORK_ORDER.IsNullOrEmpty()).DEFAULT_VALUE : "") : value; } return result; } @@ -675,15 +759,16 @@ /// </summary> /// <param name="action"></param> /// <returns></returns> - private List<string> GetMinPkgList(PackingAction action) { + private List<string> GetMinPkgList(PackingAction action) + { List<string> list = new List<string>(); - if (action.CurPkg.Item.PKG_LEVEL == 1) + if (action.CurPkg.IsNullOrEmpty()) { list.Add(CurSN); } else { - list = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN).ToList(); + list = action.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList(); } return list; } @@ -691,24 +776,19 @@ /// <summary> /// 鑾峰彇鐧界洅鏉$爜 /// </summary> - /// <param name="action"></param> /// <returns></returns> - private string GetBoxCode(List<BAS_LABEL_VAR> lvars, PackingAction action) + private string GetBoxCode() { - var boxCode = Biz.CodeRule["WhiteBoxNo"]?.Generate("W", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; - return GetCardOrBoxQR(boxCode, lvars, action); + return Biz.CodeRule["WhiteBoxNo"]?.Generate("W", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; } /// <summary> /// 鑾峰彇绠辨潯鐮� /// </summary> - /// <param name="lvars"></param> - /// <param name="action"></param> /// <returns></returns> - private string GetCardCode(List<BAS_LABEL_VAR> lvars, PackingAction action) + private string GetCardCode() { - var cardCode = Biz.CodeRule["CartonNo"]?.Generate("B", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? "" ; - return GetCardOrBoxQR(cardCode, lvars, action); + return Biz.CodeRule["CartonNo"]?.Generate("B", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; } /// <summary> @@ -718,22 +798,50 @@ /// <param name="lvars"></param> /// <param name="action"></param> /// <returns></returns> - private string GetCardOrBoxQR(string code, List<BAS_LABEL_VAR> lvars, PackingAction action) + private string GetCardOrBoxQR(string code, IWorkAction action, WipPkg? CurPkg) { - var minPkgList = action.GetMinPackageList(action.CurPkg.Item).Select(q => q.SN); + List<string> minPkgList = new List<string>(); + var itemCode = ""; + double weight = 0; + var unit = ""; + if (!CurPkg.IsNullOrEmpty()) + { + minPkgList = CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + itemCode = CurPkg.CustSN?.ITEM_CODE; + weight = CurPkg.WeightInfo.Weight; + unit = CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg"; + } + else + { + if (action is PackingAction) + { + var pkg = action as PackingAction; + //minPkgList = pkg.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList(); + minPkgList = pkg.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + itemCode = pkg.CurPkg.CustSN?.ITEM_CODE; + weight = pkg.CurPkg.WeightInfo.Weight; + unit = pkg.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg"; + } + if (action is PrintInStoreLabel) + { + var print = action as PrintInStoreLabel; + //minPkgList = print.CurPkg.Item.GetMinPackageList().Select(q => q.SN).ToList(); + minPkgList = print.CurPkg.Item.GetWipSnList().Select(q => q.Value).ToList(); + itemCode = print.CurPkg.CustSN?.ITEM_CODE; + weight = print.CurPkg.WeightInfo.Weight; + unit = print.CurPkg.WeightInfo.Unit?.ToUpper() ?? "kg"; + } + } var wo = WorkBatch.Batch.ORDER_NO; 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; - var Input = WorkBatch.Product.ExtInfo.Input; - var OutPut = WorkBatch.Product.ExtInfo.OutPut; - var Power = WorkBatch.Product.ExtInfo.Power; - var Accuracy = WorkBatch.Product.ExtInfo.Accuracy; - var Display = WorkBatch.Product.ExtInfo.Display; - var Remark = WorkBatch.Product.ExtInfo.Remark; + var model = WorkBatch.Product.ExtInfo?.Model; + var Input = WorkBatch.Product.ExtInfo?.Input; + var OutPut = WorkBatch.Product.ExtInfo?.OutPut; + var Power = WorkBatch.Product.ExtInfo?.Power; + var Accuracy = WorkBatch.Product.ExtInfo?.Accuracy; + var Display = WorkBatch.Product.ExtInfo?.Display; + var Remark = WorkBatch.Product.ExtInfo?.Remark; return $"{code}|{itemCode}|{wo}|\r\n{snList}|{weight}{unit}|鍨嬪彿:{model},杈撳叆:{Input},鏄剧ず:{Display},杈撳嚭:{OutPut},鐢垫簮:{Power},绮惧害:{Accuracy},澶囨敞:{Remark}"; } @@ -781,7 +889,37 @@ } } #endregion + #region 鏉$爜瑙勫垯鏂规硶 + /// <summary> + /// 鑾峰彇鏍规嵁鏉$爜瑙勫垯鐢熸垚鏉$爜 + /// </summary> + /// <param name="ruleCode"></param> + /// <param name="curAction"></param> + /// <returns></returns> + public string GenerateSN(string ruleCode, IWorkAction curAction) + { + var rule = Biz.CodeRule[ruleCode ?? ""]; + if (!rule.IsNullOrEmpty()) + { + switch (rule.RULE_CODE) + { + case "WhiteBoxNo": + return rule.Generate("W", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; + case "CartonNo": + return rule.Generate("B", $"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; + default: + return rule.Generate().Data.ToString() ?? ""; + } + } + return ""; + } + #endregion #region 鍖呰涓撶敤鏂规硶 + /// <summary> + /// 鏍规嵁浼犲叆鐨勫寘瑁呭璞¤繑鍥炴墍鏈夌殑鍖呰瀹炰綋鍒楄〃 + /// </summary> + /// <param name="parent"></param> + /// <returns></returns> public List<MES_WIP_PKG> GetPackageList(WipPkgItem parent) { List<MES_WIP_PKG> list = new(); -- Gitblit v1.9.3