| | |
| | | public MES_SHIFT_SYS CurShiftSys { get; set; } |
| | | public WorkBatch CurBatch { get; set; } |
| | | public IWorkBatch WorkBatch => CurBatch; |
| | | public MES_WIP_DATA CurWipSN { get; set; } |
| | | public MES_WIP_HIS CurWipSNHis { get; set; } |
| | | public List<MES_WIP_DATA> CurWipSNs { 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(); |
| | | public Dictionary<string, object> Context { get; set; } = new(); |
| | | public List<WorkStep> Steps { get; set; } = new(); |
| | | public WorkStep CurStep { get; set; } |
| | | public List<WorkStep> NextSteps { get; set; } = new(); |
| | | public bool IsFinishNodeSteps => !Steps.Any(q => q.Type == IWorkStep.Types.Node && !q.IsFinished); |
| | | 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 CommitDB; |
| | | /// <summary> |
| | | /// 是否需要临时存储数据库提交操作,待需要的时候再提交 |
| | | /// </summary> |
| | | public bool NeedTemporaryStoreDBCommitAction { get; set; } = false; |
| | | protected Dictionary<string, List<Action>> DBCommitList { get; set; } = new(); |
| | | protected List<Position> NodeCommitList { get; set; } = new(); |
| | | protected Dictionary<string, OperInfo> OperInfoDic { get; set; } = new(); |
| | | //protected OperInfo CurOperInfo { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | |
| | | action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.LineException", input.OrderNo, CurLine.LINE_CODE); |
| | | return action; |
| | | } |
| | | if (batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Release.GetValue() && batch.STATUS != BIZ_MES_WO_BATCH.STATUSs.Working.GetValue()) |
| | | { |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"工单[{input.OrderNo}]状态[{wo.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName()}]不能生产"); |
| | | action.LocaleMsg = new("MES.Transaction.Position.SelectOrder.StatusException", input.OrderNo, batch.STATUS.GetEnum<BIZ_MES_WO_BATCH.STATUSs>().GetName()); |
| | | return action; |
| | | } |
| | | var wb = new WorkBatch(input.OrderNo).Init(CurLine.LINE_CODE); |
| | | WoContext.WoBatchDic.Add(wb.Batch.BATCH_NO, wb); |
| | | } |
| | | CurBatch = WoContext.GetBatch(input.OrderNo, CurLine.LINE_CODE); |
| | | if (!OperInfoDic.ContainsKey(CurBatch.Batch.BATCH_NO)) |
| | | { |
| | | OperInfoDic.Add(CurBatch.Batch.BATCH_NO, new()); |
| | | } |
| | | |
| | | action.Data = new { WorkOrder = CurBatch.WO, Bacth = CurBatch.Batch }; |
| | | } |
| | | catch (Exception ex) |
| | |
| | | public virtual void ResetNode() |
| | | { |
| | | Steps.Clear(); |
| | | CurWipSN = null; |
| | | CurWipSNHis = null; |
| | | CurWipSNs.Clear(); |
| | | CurWipSNHiss.Clear(); |
| | | CurStep = null; |
| | | CurDefects.Clear(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置当前条码的工序信息 |
| | | /// </summary> |
| | | public OperInfo SetOperNodeInfo(OperInfo info, string locale) |
| | | { |
| | | if (CurWipSNs.Any()) |
| | | { |
| | | info.CurNode = CurWipSNs.First().NODE_NAME; |
| | | info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME)); |
| | | info.StepsInfo = Steps.Select(q => q.GetInfo(locale)).ToList(); |
| | | } |
| | | else |
| | | { |
| | | info.CurNode = " — "; |
| | | info.NextNode = " — "; |
| | | info.StepsInfo = new(); |
| | | } |
| | | return info; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | else |
| | | { |
| | | var next = new WorkStep(IWorkStep.Types.Action, this) |
| | | var next = new WorkStep(IWorkStep.NodeTypes.Action, this) |
| | | { |
| | | Name = act.ACT_NAME, |
| | | Sequence = parent.Sequence + 1, |
| | | Node = parent.Node, |
| | | OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == parent.Node.ID), |
| | | NodeAct = act, |
| | | Setting = CurBatch.ActionSets.FirstOrDefault(q => q.ACT_ID == act.ID), |
| | | ActSetting = CurBatch.ActionSets.FirstOrDefault(q => q.ACT_ID == act.ID), |
| | | }; |
| | | next.Init(); |
| | | next.PrepNodeIDs.Add(parent.NodeID); |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存工步的数据库提交操作到数据库 |
| | | /// </summary> |
| | | protected void SaveStepsCommitActionToDB() |
| | | { |
| | | //保存工步的数据库提交操作到提交操作列表 |
| | | var commitList = new List<Action>(); |
| | | foreach (var step in Steps.OrderBy(q => q.Sequence)) |
| | | { |
| | | commitList.Add(step.DBSubmitAction); |
| | | } |
| | | DBCommitList.Add(CurSN, commitList); |
| | | //如果不需要临时存储数据库提交操作,则把提交操作列表提交到数据库 |
| | | if (!NeedTemporaryStoreDBCommitAction) |
| | | { |
| | | //恢复临时存储标记为false |
| | | NeedTemporaryStoreDBCommitAction = false; |
| | | |
| | | var dbTran = GetCommitDB().UseTran(() => |
| | | { |
| | | //在同一个事务中保存所有工步的数据 |
| | | foreach (var wipSn in DBCommitList.Keys) |
| | | { |
| | | foreach (var action in DBCommitList[wipSn]) |
| | | { |
| | | action.Invoke(); |
| | | } |
| | | } |
| | | }); |
| | | if (dbTran.IsSuccess) |
| | | { |
| | | //保存成功则清空提交操作列表 |
| | | DBCommitList.Clear(); |
| | | } |
| | | else |
| | | { |
| | | //抛出异常 |
| | | throw dbTran.ErrorException; |
| | | } |
| | | } |
| | | } |
| | | |
| | | protected void DoSaveToDB() |
| | | { |
| | | var dbTran = GetCommitDB().UseTran(() => |
| | | { |
| | | //在同一个事务中保存所有工步的数据 |
| | | foreach (var step in Steps.OrderBy(q => q.Sequence)) |
| | | { |
| | | step.DBSubmitAction.Invoke(); |
| | | } |
| | | }); |
| | | if (!dbTran.IsSuccess) |
| | | { |
| | | //抛出异常 |
| | | throw dbTran.ErrorException; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取打印标签模板过程变量值 |
| | | /// </summary> |
| | | /// <param name="labelPVs">过程变量列表</param> |
| | | /// <param name="label">标签模板</param> |
| | | /// <returns></returns> |
| | | public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label) |
| | | public BAS_LABEL_TEMP SetLabelVariables(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_TEMP label, IWorkAction action) |
| | | { |
| | | foreach (var item in label.Variables) |
| | | { |
| | |
| | | item.Value = item.VAR_VALUE; |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable: |
| | | item.Value = GetPrintProcessValue(labelPVs, item); |
| | | item.Value = GetPrintProcessValue(labelPVs, item, action); |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.DateVariable: |
| | | item.Value = DateTime.Now.ToString(item.VAR_VALUE); |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.BarcodeGenerate: |
| | | item.Value = GetGeneratePValue(labelPVs, item); |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.CustomVariable: |
| | | default: |
| | |
| | | /// <param name="labelPVs">过程变量列表</param> |
| | | /// <param name="lv">标签模板变量</param> |
| | | /// <returns></returns> |
| | | public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv) |
| | | public string GetPrintProcessValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv, IWorkAction action) |
| | | { |
| | | var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE); |
| | | if (!pv.IsNullOrEmpty()) |
| | |
| | | switch (pv.VAR_METHOD) |
| | | { |
| | | case "GetSN": |
| | | return CurWipSN.SN; |
| | | return CurSN; |
| | | case "GetBAS_ITEM": |
| | | return WorkBatch.Product.ToJson(); |
| | | case "GetCustomer": |
| | |
| | | return ""; |
| | | } |
| | | } |
| | | case BAS_LABEL_PV.VAR_TYPEs.WebApiWebApi: |
| | | case BAS_LABEL_PV.VAR_TYPEs.WebApi: |
| | | break; |
| | | case BAS_LABEL_PV.VAR_TYPEs.StoredProcedure: |
| | | break; |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取根据条码规则生成标签模板的过程变量值 |
| | | /// </summary> |
| | | /// <param name="labelPVs"></param> |
| | | /// <param name="lv"></param> |
| | | /// <returns></returns> |
| | | public string GetGeneratePValue(List<BAS_LABEL_PV> labelPVs, BAS_LABEL_VAR lv) |
| | | { |
| | | var pv = labelPVs.FirstOrDefault(q => q.VAR_CODE == lv.VAR_VALUE); |
| | | if (!pv.IsNullOrEmpty()) |
| | | { |
| | | switch (pv.VAR_TYPE.GetEnum<BAS_LABEL_PV.VAR_TYPEs>()) |
| | | { |
| | | case BAS_LABEL_PV.VAR_TYPEs.BarcodeGenerate: |
| | | { |
| | | switch (pv.VAR_METHOD) |
| | | { |
| | | case "GetCartonGenerate": |
| | | return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate($"{WorkBatch.Batch.BATCH_NO}-{WorkBatch.Batch.PLAN_QTY}-").Data.ToString() ?? ""; |
| | | case "GetHW21SNGenerate": |
| | | return Biz.CodeRule[lv.BARCODE_RULE ?? ""]?.Generate("SN:","05").Data.ToString() ?? ""; |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取工单维护的模板变量 |
| | | /// </summary> |
| | | /// <param name="labelId"></param> |