¶Ô±ÈÐÂÎļþ |
| | |
| | | using Autofac; |
| | | using Microsoft.AspNetCore.Mvc; |
| | | using Rhea.Common; |
| | | using SqlSugar; |
| | | using System.Collections.Generic; |
| | | using System.Threading.Tasks; |
| | | using System.Xml.Linq; |
| | | using Tiger.Api.iBiz; |
| | | using Tiger.IBusiness; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.Api.Controllers.MES |
| | | { |
| | | public partial class MESController : ControllerBase |
| | | { |
| | | /// <summary> |
| | | /// GetSteps(ApiAction) |
| | | /// è·åå½åå·¥åºçå·¥æ¥å表 |
| | | /// </summary> |
| | | /// <param name="action"></param> |
| | | /// <returns></returns> |
| | | [HttpPost] |
| | | [Route("api/[controller]/Node/GetSteps")] |
| | | public async Task<IActionResult> Node_GetStepsAsync([FromBody] ApiAction action) |
| | | { |
| | | ApiAction response; |
| | | ITestNode trans = null; |
| | | try |
| | | { |
| | | if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID)) |
| | | { |
| | | trans = iBiz.MES.Context.GetTransDic()[action.ID] as ITestNode; |
| | | if (!trans.IsFinished) |
| | | { |
| | | lock (trans.TransLock) { response = action.GetResponse(trans.Reset()); } |
| | | } |
| | | else |
| | | { |
| | | response = action.GetResponse($"Transaction Error: å²ä½[{trans.PostCode}]çæµè¯å·¥åºäºå¡[ID:{action.ID}]å·²ç»å
³é", false); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | response = action.GetResponse($"Transaction Error: å²ä½çæµè¯å·¥åºäºå¡[ID:{action.ID}]å·²ç»è¢«å
³é", false); |
| | | } |
| | | } |
| | | catch (System.Exception ex) |
| | | { |
| | | response = action.GetResponse().CatchExceptionWithLog(ex); |
| | | } |
| | | trans?.AddHistory(Request, action); |
| | | return Ok(response); |
| | | } |
| | | |
| | | }//endClass |
| | | } |
| | |
| | | |
| | | //åå§åå·¥æ¥å表 |
| | | Steps.Clear(); |
| | | var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this) |
| | | var curStep = new Biz.WorkStep(IWorkStep.NodeTypes.Node, this) |
| | | { |
| | | Sequence = Steps.Count + 1, |
| | | Node = curNode, |
| | | OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID), |
| | | DBSubmitAction = () => |
| | | { |
| | | //使ç¨ç»ä¸çäºå¡DB对象 |
| | |
| | | } |
| | | else if (!IsFinishNodeSteps) |
| | | { |
| | | var curStep = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | |
| | | //宿å½åå·¥åºèç¹å·¥æ¥ |
| | | curStep.IsFinished = true; |
| | |
| | | //æªå®æææå·¥åºèç¹å·¥æ¥ |
| | | if (!IsFinishNodeSteps) |
| | | { |
| | | var next = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | //设置åç»å¯æ§è¡çå·¥æ¥å表 |
| | | NextSteps.Clear(); |
| | | NextSteps.Add(next); |
| | |
| | | |
| | | //åå§åå·¥æ¥å表 |
| | | Steps.Clear(); |
| | | var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this) |
| | | var curStep = new Biz.WorkStep(IWorkStep.NodeTypes.Node, this) |
| | | { |
| | | Sequence = Steps.Count + 1, |
| | | Node = curNode, |
| | | OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID), |
| | | DBSubmitAction = () => |
| | | { |
| | | //使ç¨ç»ä¸çäºå¡DB对象 |
| | |
| | | } |
| | | else if (!IsFinishNodeSteps) |
| | | { |
| | | var curStep = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | |
| | | //宿å½åå·¥åºèç¹å·¥æ¥ |
| | | curStep.IsFinished = true; |
| | |
| | | //æªå®æææå·¥åºèç¹å·¥æ¥ |
| | | if (!IsFinishNodeSteps) |
| | | { |
| | | var next = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | //设置åç»å¯æ§è¡çå·¥æ¥å表 |
| | | NextSteps.Clear(); |
| | | NextSteps.Add(next); |
| | |
| | | public List<WorkStep> Steps { get; set; } = new(); |
| | | public WorkStep CurStep { get; set; } |
| | | public List<WorkStep> NextSteps { get; set; } = new(); |
| | | public bool IsFinishNodeSteps => !Steps.Any(q => q.Type == IWorkStep.Types.Node && !q.IsFinished); |
| | | public bool IsFinishNodeSteps => !Steps.Any(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished); |
| | | 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; |
| | |
| | | protected Dictionary<string, 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; } |
| | | //protected OperInfo CurOperInfo { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | |
| | | { |
| | | info.CurNode = CurWipSNs.First().NODE_NAME; |
| | | info.NextNode = string.Join(",", CurBatch.GetNextNodes(CurWipSNs.First()).Select(q => q.NODE_NAME)); |
| | | info.StepsInfo = Steps.Select(q => q.GetInfo()).ToList(); |
| | | } |
| | | else |
| | | { |
| | | info.CurNode = " â "; |
| | | info.NextNode = " â "; |
| | | info.StepsInfo = new(); |
| | | } |
| | | return info; |
| | | } |
| | |
| | | } |
| | | else |
| | | { |
| | | var next = new WorkStep(IWorkStep.Types.Action, this) |
| | | var next = new WorkStep(IWorkStep.NodeTypes.Action, this) |
| | | { |
| | | Sequence = parent.Sequence + 1, |
| | | Node = parent.Node, |
| | | OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == parent.Node.ID), |
| | | NodeAct = act, |
| | | Setting = CurBatch.ActionSets.FirstOrDefault(q => q.ACT_ID == act.ID), |
| | | ActSetting = CurBatch.ActionSets.FirstOrDefault(q => q.ACT_ID == act.ID), |
| | | }; |
| | | next.Init(); |
| | | next.PrepNodeIDs.Add(parent.NodeID); |
| | |
| | | |
| | | //åå§åå·¥æ¥å表 |
| | | Steps.Clear(); |
| | | var curStep = new Biz.WorkStep(IWorkStep.Types.Node, this) |
| | | var curStep = new Biz.WorkStep(IWorkStep.NodeTypes.Node, this) |
| | | { |
| | | Sequence = Steps.Count + 1, |
| | | Node = curNode, |
| | | OperSetting = CurBatch.NodeSets.FirstOrDefault(q => q.NODE_ID == curNode.ID), |
| | | DBSubmitAction = () => |
| | | { |
| | | //使ç¨ç»ä¸çäºå¡DB对象 |
| | |
| | | } |
| | | else if (!IsFinishNodeSteps) |
| | | { |
| | | var curStep = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var curStep = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | |
| | | //宿å½åå·¥åºèç¹å·¥æ¥ |
| | | curStep.IsFinished = true; |
| | |
| | | //æªå®æææå·¥åºèç¹å·¥æ¥ |
| | | if (!IsFinishNodeSteps) |
| | | { |
| | | var next = Steps.Where(q => q.Type == IWorkStep.Types.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | var next = Steps.Where(q => q.NodeType == IWorkStep.NodeTypes.Node && !q.IsFinished).OrderBy(q => q.Sequence).First(); |
| | | //设置åç»å¯æ§è¡çå·¥æ¥å表 |
| | | NextSteps.Clear(); |
| | | NextSteps.Add(next); |
| | |
| | | /// </summary> |
| | | public partial class WorkStep : IWorkStep |
| | | { |
| | | public WorkStep(IWorkStep.Types type, IPosition position) |
| | | public WorkStep(IWorkStep.NodeTypes type, IPosition position) |
| | | { |
| | | Type = type; |
| | | NodeType = type; |
| | | CurPosition = position; |
| | | } |
| | | |
| | | #region Propertys & Variables |
| | | public string ID { get; set; } = Guid.NewGuid().ToString("N"); |
| | | |
| | | public IWorkStep.Types Type { get; set; } |
| | | 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 Setting { get; set; } |
| | | public MES_WO_ACTION ActSetting { get; set; } |
| | | public IPosition CurPosition { get; set; } |
| | | public IWorkAction CurAction { get; set; } |
| | | public int Sequence { get; set; } |
| | | public List<string> PrepNodeIDs { get; set; } = new(); |
| | | public string NodeID => Type == IWorkStep.Types.Action ? NodeAct.ID : Node.ID; |
| | | public string NodeID => NodeType == IWorkStep.NodeTypes.Action ? NodeAct.ID : Node.ID; |
| | | private bool _IsFinished = false; |
| | | public bool IsFinished |
| | | { |
| | | get => Type == IWorkStep.Types.Action ? CurAction.IsFinished : _IsFinished; |
| | | get => NodeType == IWorkStep.NodeTypes.Action ? CurAction.IsFinished : _IsFinished; |
| | | set { _IsFinished = value; } |
| | | } |
| | | public Action DBSubmitAction { get; set; } = () => { }; |
| | |
| | | { |
| | | CurAction = DI.Resolve(NodeAct.Definition.SERVICE_TYPE) as IWorkAction; |
| | | //CurAction = DI.Resolve("Tiger.IBusiness.IPrintLabel,Tiger.IBusiness") as IWorkAction; |
| | | CurAction.Init(this, CurPosition, NodeAct, Setting); |
| | | CurAction.Init(this, CurPosition, NodeAct, ActSetting); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | return CurAction.Submit(input); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// ç»æå·¥æ¥æ§è¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> End() |
| | | { |
| | | return CurAction.End(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// è·åå½åå·¥æ¥çä¿¡æ¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public WorkStepInfo GetInfo() |
| | | { |
| | | return new WorkStepInfo() { |
| | | ID = ID, |
| | | Sequence = Sequence, |
| | | NodeID = NodeID, |
| | | NodeType = NodeType.ToString(), |
| | | Node = Node, |
| | | OperSetting = OperSetting, |
| | | NodeAct = NodeAct, |
| | | ActSetting = ActSetting, |
| | | IsFinished = IsFinished, |
| | | }; |
| | | } |
| | | #endregion |
| | | |
| | | } |
¶Ô±ÈÐÂÎļþ |
| | |
| | | using Newtonsoft.Json; |
| | | using Rhea.Common; |
| | | using System; |
| | | using Tiger.Model; |
| | | using Tiger.Model.Entitys.MES.Position; |
| | | |
| | | namespace Tiger.IBusiness |
| | | { |
| | | /// <summary> |
| | | /// æ¥éª¤åºç±» |
| | | /// </summary> |
| | | public interface IStep<InputT, OutputT> |
| | | { |
| | | #region Propertys & Variables |
| | | /// <summary> |
| | | /// æ¥éª¤ID |
| | | /// </summary> |
| | | public string ID { get; set; } |
| | | /// <summary> |
| | | /// æ¥éª¤åºå· |
| | | /// </summary> |
| | | public int Sequence { get; set; } |
| | | /// <summary> |
| | | /// æ¥éª¤æ¯å¦å®æ |
| | | /// </summary> |
| | | public abstract bool IsFinished { get; set; } |
| | | #endregion Propertys & Variables |
| | | |
| | | #region Functions |
| | | /// <summary> |
| | | /// å°è¯å¼å§æ§è¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public abstract ApiAction<OutputT> TryBegin(InputT input); |
| | | /// <summary> |
| | | /// æäº¤æ°æ® |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public abstract ApiAction<OutputT> Submit(InputT input); |
| | | /// <summary> |
| | | /// ç»ææ§è¡ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public abstract ApiAction<OutputT> End(); |
| | | #endregion Functions |
| | | } |
| | | |
| | | } |
| | |
| | | /// <summary> |
| | | /// å·¥æ¥è¡ä¸ºåºç±» |
| | | /// </summary> |
| | | public interface IWorkStep |
| | | public interface IWorkStep : IStep<SubmitInput, SubmitOutput> |
| | | { |
| | | #region Propertys & Variables |
| | | public string ID { get; set; } |
| | | public Types Type { get; set; } |
| | | public int Sequence { get; set; } |
| | | public string NodeID { get; } |
| | | public 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 Setting { get; set; } |
| | | public MES_WO_ACTION ActSetting { get; set; } |
| | | public IPosition CurPosition { get; set; } |
| | | public IWorkAction CurAction { get; set; } |
| | | public List<string> PrepNodeIDs { get; set; } |
| | | public string NodeID { get; } |
| | | public bool IsFinished { get; set; } |
| | | public Action DBSubmitAction { get; set; } |
| | | #endregion Propertys & Variables |
| | | public enum Types { Node, Action } |
| | | public enum NodeTypes { Node, Action } |
| | | |
| | | #region Functions |
| | | /// <summary> |
| | | /// å°è¯å¼å§æ§è¡å·¥æ¥ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> TryBegin(SubmitInput input); |
| | | /// <summary> |
| | | /// è·åè¡ä¸ºå¼å§çæç¤ºä¿¡æ¯ |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Locale GetBeginMsg(); |
| | | /// <summary> |
| | | /// å·¥æ¥æäº¤æ°æ® |
| | | /// </summary> |
| | | /// <param name="input"></param> |
| | | /// <returns></returns> |
| | | public ApiAction<SubmitOutput> Submit(SubmitInput input); |
| | | #endregion Functions |
| | | } |
| | | |
| | | } |
| | |
| | | public string NextNode { get; set; } = " â "; |
| | | public string CurNode { get; set; } = " â "; |
| | | public int InputQty { get; set; } = 0; |
| | | public List<WorkStepInfo> StepsInfo { get; set; } = new List<WorkStepInfo>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// å·¥æ¥ä¿¡æ¯ |
| | | /// </summary> |
| | | public class WorkStepInfo |
| | | { |
| | | public string ID { get; set; } |
| | | public int Sequence { get; set; } |
| | | public string NodeID { get; set; } |
| | | public string 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 bool IsFinished { get; set; } |
| | | } |
| | | |
| | | } |