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<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)
|
{
|
StepID = stepID;
|
CurPosition = position;
|
NodeAct = nodeAct;
|
Setting = setting;
|
var action = new ApiAction<SubmitOutput>();
|
|
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;
|
action.Data.Data = Label;
|
return action;
|
}
|
/// <summary>
|
/// 工序行为提交数据
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> Submit(SubmitInput input)
|
{
|
var action = new ApiAction<SubmitOutput>();
|
if (input.Data.ToBoolean())
|
{
|
action = End();
|
}
|
else
|
{
|
//重置当前工序
|
CurPosition.ResetSteps();
|
action.IsSuccessed = false;
|
action.LocaleMsg = new($"标签[{Label.LABEL_NAME}]打印失败,请重新扫描产品条码", Label.LABEL_NAME);
|
//action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintFail", Label.LABEL_NAME);
|
}
|
return action;
|
}
|
/// <summary>
|
/// 结束执行工序行为
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> End()
|
{
|
var action = new ApiAction<SubmitOutput>();
|
IsFinished = true;
|
action.LocaleMsg = new($"标签[{Label.LABEL_NAME}]打印成功", Label.LABEL_NAME);
|
//action.LocaleMsg = new("MES.WorkAction.PrintLabel.PrintSuccess", Label.LABEL_NAME);
|
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;
|
default:
|
return "";
|
}
|
}
|
case BAS_LABEL_PV.VAR_TYPEs.WebApiWebApi:
|
break;
|
case BAS_LABEL_PV.VAR_TYPEs.StoredProcedure:
|
break;
|
default:
|
break;
|
}
|
}
|
return "action";
|
}
|
|
#endregion Functions
|
}
|
}
|