using MailKit.Search; using Rhea.Common; using SqlSugar; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Tiger.IBusiness; using Tiger.Model; using Tiger.Model.Entitys.MES.Position; namespace Tiger.Business.MES.WorkAction { public class PrintLabel : IPrintLabel { #region Propertys & Variables public bool IsFinished { get; set; } = false; public string StepID { get; set; } public IPosition CurPosition { get; set; } public MES_WO_NODE_ACT NodeAct { get; set; } public MES_WO_ACTION Setting { get; set; } public BAS_LABEL_TEMP Label { get; set; } public List LabelPV { get; set; } #endregion Propertys & Variables #region Functions /// /// 开始执行工序行为 /// /// public ApiAction Begin(string stepID, IPosition position, MES_WO_NODE_ACT nodeAct, MES_WO_ACTION setting) { StepID = stepID; CurPosition = position; NodeAct = nodeAct; Setting = setting; var action = new ApiAction(); Label = Biz.Db.Queryable().Where(q => q.LABEL_CODE == setting.LABEL_CODE).IncludesAllFirstLayer().First(); LabelPV = Biz.Db.Queryable().ToList(); foreach (var item in Label.Variables) { switch (item.VAR_TYPE.GetEnum()) { 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; action.Data.Data = Label; return action; } /// /// 工序行为提交数据 /// /// public ApiAction Submit(SubmitInput input) { var action = new ApiAction(); if (input.Data.ToBoolean()) { action = End(); } else { //重置当前工序 CurPosition.ResetSteps(); action.IsSuccessed = false; //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); } return action; } /// /// 结束执行工序行为 /// /// public ApiAction End() { var action = new ApiAction(); IsFinished = true; //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()) { 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().Where(q => q.ITEM_CODE == CurPosition.CurWipSN.ITEM_CODE).First(); return itemInfo.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 } }