| | |
| | | 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 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(); |
| | | 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 |
| | |
| | | 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) |
| | | { |
| | | if (CurWipSNs.Any()) |
| | | { |
| | | info.CurNode = CurWipSNs.First().NODE_NAME; |
| | | info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME)); |
| | | } |
| | | else |
| | | { |
| | | info.CurNode = " — "; |
| | | info.NextNode = " — "; |
| | | } |
| | | return info; |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <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; |
| | | } |
| | | } |
| | | } |
| | | |
| | | 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> |
| | |
| | | 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: |
| | |
| | | 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; |
| | |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /// <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() ?? ""; |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return ""; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取工单维护的模板变量 |
| | | /// </summary> |