| | |
| | | using MailKit.Search; |
| | | using Rhea.Common; |
| | | using Rhea.Common; |
| | | using SqlSugar; |
| | | using System; |
| | | using System.Collections.Generic; |
| | |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Tiger.IBusiness; |
| | | using Tiger.IBusiness.MES.WorkAction; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | |
| | | public class PrintLabel : IPrintLabel |
| | | { |
| | | #region Propertys & Variables |
| | | #region 固定写法,工序中的必要信息 |
| | | public bool IsFinished { get; set; } = false; |
| | | public string StepID { get; set; } |
| | | public IWorkStep CurStep { get; set; } |
| | | public IPosition CurPosition { get; set; } |
| | | public MES_WO_NODE_ACT NodeAct { get; set; } |
| | | public MES_WO_ACTION Setting { get; set; } |
| | | #endregion |
| | | public BAS_LABEL_TEMP Label { get; set; } |
| | | public List<BAS_LABEL_PV> LabelPV { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | | /// <summary> |
| | | /// 开始执行工序行为 |
| | | /// 初始化工序行为 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> Begin(string stepID, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting) |
| | | public void Init(IWorkStep curStep, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting) |
| | | { |
| | | StepID = stepID; |
| | | #region 固定写法,给默认变量赋值 |
| | | CurStep = curStep; |
| | | CurPosition = position; |
| | | NodeAct = nodeAct; |
| | | Setting = setting; |
| | | var action = new ApiAction<SubmitOutput>(); |
| | | #endregion |
| | | |
| | | Label = Biz.Db.Queryable<BAS_LABEL_TEMP>().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First(); |
| | | LabelPV = Biz.Db.Queryable<BAS_LABEL_PV>().ToList(); |
| | | foreach (var item in Label.Variables) |
| | | { |
| | | switch (item.VAR_TYPE.GetEnum<BAS_LABEL_VAR.VAR_TYPEs>()) |
| | | { |
| | | case BAS_LABEL_VAR.VAR_TYPEs.Constant: |
| | | item.Value = item.VAR_VALUE; |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.ProcessVariable: |
| | | item.Value = GetProcessValue(item); |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.DateVariable: |
| | | item.Value = DateTime.Now.ToString(item.VAR_VALUE); |
| | | break; |
| | | case BAS_LABEL_VAR.VAR_TYPEs.CustomVariable: |
| | | default: |
| | | item.Value = ""; |
| | | break; |
| | | } |
| | | } |
| | | action.Data.StepActCode = nodeAct.Definition.ACT_CODE; |
| | | |
| | | CurStep.Message = Biz.L("等待标签打印"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取行为开始的提示信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Locale GetBeginMsg() |
| | | { |
| | | var msg = new Locale("MES.WorkAction.PrintLabel.BeginMsg", CurPosition.CurSN, Label.LABEL_CODE, Label.LABEL_NAME); |
| | | //var msg = new Locale($"开始打印条码[{CurPosition.CurWipSN.SN}]的标签[{Label.LABEL_CODE}: {Label.LABEL_NAME}]"); |
| | | return msg; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 尝试开始执行工序行为 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> TryBegin(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | //设置打印变量值 |
| | | Label = CurPosition.SetLabelVariables(LabelPV, Label, this); |
| | | action.Data.Data = Label; |
| | | |
| | | //如果返回成功则认为当前行为可以开始执行,否则返回失败 |
| | | CurStep.Message = Biz.L("打印开始"); |
| | | CurStep.Status = StepStatus.Normal; |
| | | action.IsSuccessed = true; |
| | | action.Data.ShortMsg = new("打印开始", ShortMessage.Types.Success); |
| | | return action; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 工序行为提交数据 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> Submit(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(); |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | //提交数据执行成功 |
| | | if (input.Data.ToBoolean()) |
| | | { |
| | | action = End(); |
| | | action = End(input); |
| | | } |
| | | //提交数据执行失败 |
| | | else |
| | | { |
| | | //重置当前工序 |
| | | CurPosition.ResetSteps(); |
| | | CurStep.Message = Biz.L("打印失败"); |
| | | CurStep.Status = StepStatus.Error; |
| | | action.Data.ShortMsg = new("打印失败", ShortMessage.Types.Failed); |
| | | action.IsSuccessed = false; |
| | | //action.LocaleMsg = new($"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印失败,请重新扫描产品条码", Label.LABEL_NAME); |
| | | //action.LocaleMsg = new($"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印失败", Label.LABEL_NAME); |
| | | action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintFail", Label.LABEL_NAME, Label.LABEL_CODE); |
| | | //如果行为设置为出错需要重置工序操作 |
| | | if (NodeAct.NEED_RESET == "Y") |
| | | { |
| | | CurPosition.ResetNode(); |
| | | } |
| | | } |
| | | return action; |
| | | } |
| | |
| | | /// 结束执行工序行为 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> End() |
| | | public ApiAction<SubmitOutput> End(SubmitInput input) |
| | | { |
| | | var action = new ApiAction<SubmitOutput>(); |
| | | var action = new ApiAction<SubmitOutput>(new SubmitOutput()); |
| | | |
| | | //记录行为操作记录 |
| | | var wipActs = new List<MES_WIP_ACT>(); |
| | | foreach (var wipSn in CurPosition.CurWipSNs) |
| | | { |
| | | var wipAct = new MES_WIP_ACT() |
| | | { |
| | | AUTH_ORG = CurPosition.WorkBatch.WO.AUTH_ORG, |
| | | AUTH_PROD = CurPosition.CurLine.LINE_CODE, |
| | | HIS_ID = CurPosition.CurWipSNHiss.First(q => q.SN == wipSn.SN).ID, |
| | | WIP_ID = wipSn.ID, |
| | | SN = wipSn.SN, |
| | | STATUS = wipSn.STATUS, |
| | | ITEM_CODE = wipSn.ITEM_CODE, |
| | | WORK_ORDER = wipSn.WORK_ORDER, |
| | | BATCH_NO = wipSn.BATCH_NO, |
| | | ROT_CODE = wipSn.ROT_CODE, |
| | | NODE_ID = wipSn.NODE_ID, |
| | | NODE_NAME = wipSn.NODE_NAME, |
| | | ACT_ID = NodeAct.ID, |
| | | ACT_NAME = NodeAct.ACT_NAME, |
| | | FTY_CODE = wipSn.FTY_CODE, |
| | | WS_CODE = wipSn.WS_CODE, |
| | | LINE_CODE = wipSn.LINE_CODE, |
| | | POST_CODE = wipSn.POST_CODE, |
| | | OPER_CODE = wipSn.OPER_CODE, |
| | | SEGMENT = wipSn.SEGMENT, |
| | | FLOW_SN = wipSn.FLOW_SN, |
| | | TRAY_SN = wipSn.TRAY_SN, |
| | | INNER_SN = wipSn.INNER_SN, |
| | | CARTON_SN = wipSn.CARTON_SN, |
| | | PALLET_SN = wipSn.PALLET_SN, |
| | | OPERATION_TIME = DateTime.Now, |
| | | SFTS_CODE = wipSn.SFTS_CODE, |
| | | SFT_CODE = wipSn.SFT_CODE, |
| | | PRD_CODE = wipSn.PRD_CODE, |
| | | ACT_TYPE = NodeAct.ACT_TYPE, |
| | | ACT_SN = wipSn.SN, |
| | | ACT_VALUE_1 = Label.LABEL_CODE, |
| | | ACT_VALUE_2 = Label.Variables.ToJson(), |
| | | ACT_RESULT = "Y", |
| | | ELAPSED_TIME = CurStep.GetElapsedTime().TotalMilliseconds.ToInt64(), |
| | | TRACE_INFO = $"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印成功", |
| | | }; |
| | | wipActs.Add(wipAct); |
| | | } |
| | | |
| | | //创建变量克隆对象用于传入DBSubmitAction中保存当前需要暂存的数据值 |
| | | var _wipActs = wipActs.Clone(); |
| | | //保存数据 |
| | | CurStep.DBSubmitAction = () => |
| | | { |
| | | var db = CurPosition.GetCommitDB(); |
| | | db.Storageable(_wipActs, CurPosition.UserCode).ExecuteCommand(); |
| | | }; |
| | | |
| | | IsFinished = true; |
| | | CurStep.Message = Biz.L("打印完成"); |
| | | CurStep.Status = StepStatus.Finished; |
| | | action.Data.ShortMsg = new("打印完成", ShortMessage.Types.Success); |
| | | //action.LocaleMsg = new($"标签{Label.LABEL_NAME}[{Label.LABEL_CODE}]打印成功", Label.LABEL_NAME); |
| | | action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintSuccess", Label.LABEL_NAME, Label.LABEL_CODE); |
| | | return action; |
| | | } |
| | | |
| | | public string GetProcessValue(BAS_LABEL_VAR lv) |
| | | { |
| | | var pv = LabelPV.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.ServerMethod: |
| | | { |
| | | switch (pv.VAR_METHOD) |
| | | { |
| | | case "GetSN": |
| | | return CurPosition.CurWipSN.SN; |
| | | case "GetBAS_ITEM": |
| | | var itemInfo = Biz.Db.Queryable<BAS_ITEM>().Where(q => q.ITEM_CODE == CurPosition.CurWipSN.ITEM_CODE).First(); |
| | | return itemInfo.ToJson(); |
| | | case "GetCustomer": |
| | | return CurPosition.WorkBatch.Batch.ToJson(); |
| | | default: |
| | | return ""; |
| | | } |
| | | } |
| | | case BAS_LABEL_PV.VAR_TYPEs.WebApiWebApi: |
| | | break; |
| | | case BAS_LABEL_PV.VAR_TYPEs.StoredProcedure: |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | } |
| | | return "action"; |
| | | } |
| | | |
| | | #endregion Functions |