using Tiger.Model;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq.Expressions;
|
using System.Text;
|
using System.Threading.Tasks;
|
using Rhea.Common;
|
using System.Net;
|
using System.Linq;
|
using Newtonsoft.Json;
|
using Tiger.IBusiness;
|
using Tiger.Model.Entitys.MES.Position;
|
using Tiger.Business.MES.Transaction;
|
|
namespace Tiger.Business
|
{
|
/// <summary>
|
/// 工步
|
/// </summary>
|
public partial class WorkStep : IWorkStep
|
{
|
public WorkStep(IWorkStep.NodeTypes type, IPosition position)
|
{
|
NodeType = type;
|
CurPosition = position;
|
}
|
|
#region Propertys & Variables
|
public string ID { get; set; } = Guid.NewGuid().ToString("N");
|
public string Name { get; set; }
|
private DateTime BeginAt;
|
private DateTime EndAt;
|
public TimeSpan ElapsedTime => EndAt - BeginAt;
|
public IWorkStep.NodeTypes NodeType { get; set; }
|
public MES_WO_NODE Node { get; set; }
|
public MES_WO_OPER OperSetting { get; set; }
|
public MES_WO_NODE_ACT NodeAct { get; set; }
|
public MES_WO_ACTION ActSetting { get; set; }
|
public IPosition CurPosition { get; set; }
|
public IWorkAction CurAction { get; set; }
|
public Dictionary<string, string> ActionDic { get; set; } = new();
|
public int Sequence { get; set; }
|
public List<string> PrepNodeIDs { get; set; } = new();
|
public string NodeID => NodeType == IWorkStep.NodeTypes.Action ? NodeAct.ID : Node.ID;
|
private bool _IsActive = true;
|
public bool IsActive
|
{
|
get => NodeType == IWorkStep.NodeTypes.Action ? ActSetting.IS_ACTIVE == "Y" : _IsActive;
|
set { _IsActive = value; }
|
}
|
private bool _IsFinished = false;
|
public bool IsFinished
|
{
|
get => NodeType == IWorkStep.NodeTypes.Action ? CurAction.IsFinished : _IsFinished;
|
set { _IsFinished = value; }
|
}
|
public StepStatus Status { get; set; } = StepStatus.Normal;
|
//public bool IsFinished => Status == StepStatus.Finished;
|
private Locale _Message;
|
public Locale Message
|
{
|
get => _Message;
|
set { _MsgHistory.Add(_Message = value); }
|
}
|
private List<Locale> _MsgHistory = new();
|
public List<Locale> MsgHistory => _MsgHistory;
|
public Action DBSubmitAction { get; set; } = () => { };
|
#endregion
|
|
#region Functions
|
/// <summary>
|
/// 初始化工步
|
/// </summary>
|
/// <returns></returns>
|
public void Init()
|
{
|
CurAction = DI.Resolve(NodeAct.Definition.SERVICE_TYPE) as IWorkAction;
|
//CurAction = DI.Resolve("Tiger.IBusiness.IPrintLabel,Tiger.IBusiness") as IWorkAction;
|
|
//设置行为字典
|
ActionDic = NodeAct.Variables.ToDictionary(k => k.VAR_CODE, v => v.DEFAULT);
|
|
CurAction.Init(this, CurPosition, NodeAct, ActSetting);
|
}
|
|
/// <summary>
|
/// 尝试开始执行工步
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> TryBegin(SubmitInput input)
|
{
|
BeginAt = DateTime.Now;
|
//工步行为启用则正常执行
|
if (IsActive)
|
{
|
UpdateActionDic(input.ActionDic);
|
return ResetActionDic(CurAction.TryBegin(input));
|
}
|
//工步行为不启用,否则工步默认完成
|
else
|
{
|
CurAction.IsFinished = true;
|
var action = new ApiAction<SubmitOutput>(new SubmitOutput());
|
this.Message = Biz.L($"行为未启用");
|
this.Status = StepStatus.InActive;
|
action.Data.ShortMsg = new($"行为未启用", ShortMessage.Types.Success);
|
//action.LocaleMsg = new($"{0}行为未启用");
|
action.LocaleMsg = new("MES.WorkAction.NotActive", NodeAct.ACT_NAME);
|
return action;
|
}
|
}
|
|
/// <summary>
|
/// 获取行为开始的提示信息
|
/// </summary>
|
/// <returns></returns>
|
public Locale GetBeginMsg()
|
{
|
return CurAction.GetBeginMsg();
|
}
|
|
/// <summary>
|
/// 工步提交数据
|
/// </summary>
|
/// <param name="input"></param>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> Submit(SubmitInput input)
|
{
|
UpdateActionDic(input.ActionDic);
|
return ResetActionDic(CurAction.Submit(input));
|
}
|
|
/// <summary>
|
/// 结束工步执行
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> End(SubmitInput input)
|
{
|
UpdateActionDic(input.ActionDic);
|
var result = CurAction.End(input);
|
EndAt = DateTime.Now;
|
return ResetActionDic(result);
|
}
|
|
/// <summary>
|
/// 获取工步当前耗时
|
/// </summary>
|
/// <returns></returns>
|
public void UpdateActionDic(Dictionary<string, string> newDic)
|
{
|
foreach (var item in newDic ?? new())
|
{
|
if (ActionDic.ContainsKey(item.Key))
|
{
|
ActionDic[item.Key] = item.Value;
|
}
|
else
|
{
|
ActionDic.Add(item.Key, item.Value);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 获取工步当前耗时
|
/// </summary>
|
/// <returns></returns>
|
public ApiAction<SubmitOutput> ResetActionDic(ApiAction<SubmitOutput> output)
|
{
|
output.Data.ActionDic = ActionDic;
|
return output;
|
}
|
|
/// <summary>
|
/// 获取工步当前耗时
|
/// </summary>
|
/// <returns></returns>
|
public TimeSpan GetElapsedTime()
|
{
|
return DateTime.Now - BeginAt;
|
}
|
|
/// <summary>
|
/// 设置工步状态和消息
|
/// </summary>
|
/// <returns></returns>
|
public void SetStatusMessage(StepStatus status, Locale msg)
|
{
|
Message = msg;
|
Status = status;
|
}
|
|
/// <summary>
|
/// 获取当前工步的信息
|
/// </summary>
|
/// <returns></returns>
|
public WorkStepInfo GetInfo(string locale)
|
{
|
return new WorkStepInfo()
|
{
|
ID = ID,
|
Name = Name,
|
Sequence = Sequence,
|
NodeID = NodeID,
|
NodeType = NodeType.ToString(),
|
Node = Node,
|
OperSetting = OperSetting,
|
NodeAct = NodeAct,
|
ActSetting = ActSetting,
|
Status = Status.ToString(),
|
Message = Message.IsNullOrEmpty() ? "" : Biz.T(Message, locale),
|
};
|
}
|
#endregion
|
|
}
|
}
|