| | |
| | | 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; } |
| | | public string CurSN => CurWipSNs.First().TRAY_SN.IsNullOrEmpty() ? CurWipSNs.First().SN : CurWipSNs.First().TRAY_SN; |
| | | public List<MES_WIP_HIS> CurWipSNHiss { get; set; } |
| | | public Dictionary<string, object> Context { get; set; } = new(); |
| | | public List<WorkStep> Steps { get; set; } = new(); |
| | | public WorkStep CurStep { get; set; } |
| | |
| | | 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 List<Action> DBCommitList { get; set; } = new(); |
| | | |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | |
| | | public virtual void ResetNode() |
| | | { |
| | | Steps.Clear(); |
| | | CurWipSN = null; |
| | | CurWipSNHis = null; |
| | | CurWipSNs = null; |
| | | CurWipSNHiss = null; |
| | | CurStep = null; |
| | | } |
| | | |
| | |
| | | NodeAct = act, |
| | | Setting = CurBatch.ActionSets.FirstOrDefault(q => q.ACT_ID == act.ID), |
| | | }; |
| | | next.Init(); |
| | | next.PrepNodeIDs.Add(parent.NodeID); |
| | | next.PrepNodeIDs.AddRange(parent.PrepNodeIDs); |
| | | next.PrepNodeIDs = next.PrepNodeIDs.Distinct().ToList(); |
| | |
| | | /// <param name="input"></param> |
| | | public ApiAction<SubmitOutput> BeginNextActionStep(SubmitInput input) |
| | | { |
| | | var result = new ApiAction<SubmitOutput>(); |
| | | var result = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | //设置后续可执行的工步列表 |
| | | NextSteps = GetNextSteps(CurStep); |
| | | //尝试有没有可以直接开始的后续工步 |
| | |
| | | //返回结果到客户端 |
| | | result = canBegin; |
| | | result.Data.SetValue(CurBatch, CurStep, CurStep?.ID, IsFinishAllSteps); |
| | | |
| | | |
| | | return result; |
| | | } |
| | | } |
| | |
| | | string.Join("\r\n", NextSteps.Select(q => " >> " + T(q.GetBeginMsg(), input.Locale)))); |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 保存工步的数据库提交操作到数据库 |
| | | /// </summary> |
| | | protected void SaveStepsCommitActionToDB() |
| | | { |
| | | //保存工步的数据库提交操作到提交操作列表 |
| | | foreach (var step in Steps.OrderBy(q => q.Sequence)) |
| | | { |
| | | DBCommitList.Add(step.DBSubmitAction); |
| | | } |
| | | //如果不需要临时存储数据库提交操作,则把提交操作列表提交到数据库 |
| | | if (!NeedTemporaryStoreDBCommitAction) |
| | | { |
| | | //恢复临时存储标记为false |
| | | NeedTemporaryStoreDBCommitAction = false; |
| | | |
| | | var dbTran = GetCommitDB().UseTran(() => |
| | | { |
| | | //在同一个事务中保存所有工步的数据 |
| | | foreach (var action in DBCommitList) |
| | | { |
| | | action.Invoke(); |
| | | } |
| | | }); |
| | | if (dbTran.IsSuccess) |
| | | { |
| | | //保存成功则清空提交操作列表 |
| | | DBCommitList.Clear(); |
| | | } |
| | | else |
| | | { |
| | | //抛出异常 |
| | | throw dbTran.ErrorException; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | switch (pv.VAR_METHOD) |
| | | { |
| | | case "GetSN": |
| | | return CurWipSN.SN; |
| | | return string.Join(",", CurWipSNs.Select(q => q.SN)); |
| | | case "GetTraySN": |
| | | return CurSN; |
| | | case "GetBAS_ITEM": |
| | | return WorkBatch.Product.ToJson(); |
| | | case "GetCustomer": |
| | | return WorkBatch.Batch.ToJson(); |
| | | case "GetVarByWo": |
| | | return GetLabelVarWo(lv); |
| | | default: |
| | | return ""; |
| | | } |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | /// <summary> |
| | | /// 获取工单维护的模板变量 |
| | | /// </summary> |
| | | /// <param name="labelId"></param> |
| | | /// <returns></returns> |
| | | private string GetLabelVarWo(BAS_LABEL_VAR lv) |
| | | { |
| | | string result = ""; |
| | | var labelVarwos = Biz.Db.Queryable<BAS_LABEL_VAR_WO>().Where(x => x.LABEL_ID == lv.LABEL_ID && x.VAR_NAME == lv.VAR_NAME).ToList(); |
| | | if (labelVarwos.Any(q => q.WORK_ORDER == WorkBatch.Batch.ORDER_NO)) |
| | | { |
| | | result = labelVarwos.First(q => q.WORK_ORDER == WorkBatch.Batch.ORDER_NO).VAR_VALUE; |
| | | } |
| | | else |
| | | { |
| | | result = labelVarwos.Count > 0 ? labelVarwos[0].DEFAULT_VALUE : ""; |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | #endregion Functions |
| | | |