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>
|
/// GetTransaction(ApiAction(Data:NewPositionInput))
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/GetTransaction")]
|
public IActionResult CollectNode_GetTransaction([FromBody] ApiAction<NewPositionInput> action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
}
|
else
|
{
|
trans = AutoFacContainer.Instance.Resolve<ICollectNode>().Init(action.ID, Request.Host.Value, action.Data?.USER_CODE, action.Data?.POST_CODE);
|
iBiz.MES.Context.NewTransaction(HttpContext, trans);
|
}
|
|
response = action.GetResponse();
|
}
|
catch (System.IO.InvalidDataException ex)
|
{
|
response = action.GetResponse();
|
response.IsSuccessed = false;
|
response.LocaleMsg = new(ex.Message, ex.InnerException.Message.Split('|', System.StringSplitOptions.RemoveEmptyEntries));
|
}
|
catch (System.Exception ex)
|
{
|
response = action.GetResponse().CatchExceptionWithLog(ex);
|
}
|
trans?.AddHistory(Request, action);
|
return Ok(response);
|
}
|
|
/// <summary>
|
/// CloseTransaction(ApiAction)
|
/// 关闭事务
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/CloseTransaction")]
|
public IActionResult CollectNode_CloseTransaction([FromBody] ApiAction action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
if (!trans.IsFinished)
|
{
|
if (action.IsAsync)
|
{
|
response = action.GetResponse(trans.Close());
|
}
|
else
|
{
|
lock (trans.TransLock) { response = action.GetResponse(trans.Close()); }
|
}
|
response.Message = $"岗位[{trans.PostCode}]的采集工序事务[ID:{action.ID}]关闭{(response.IsSuccessed ? "成功" : "失败")}";
|
}
|
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);
|
}
|
|
/// <summary>
|
/// Reset(ApiAction)
|
/// 重置工序操作
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/Reset")]
|
public async Task<IActionResult> CollectNode_ResetAsync([FromBody] ApiAction action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
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);
|
}
|
|
/// <summary>
|
/// SelectWO(ApiAction(Data:{WoInput}))
|
/// 采集工序:选择工单
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/SelectWO")]
|
public async Task<IActionResult> CollectNode_SelectWOAsync([FromBody] ApiAction<WoInput> action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
if (!trans.IsFinished)
|
{
|
if (action.IsAsync)
|
{
|
response = action.GetResponse(await trans.SelectOrder(action.Data));
|
}
|
else
|
{
|
lock (trans.TransLock) { response = action.GetResponse(trans.SelectOrder(action.Data).Result); }
|
}
|
}
|
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);
|
}
|
|
/// <summary>
|
/// Submit(ApiAction(Data:{SubmitInput}))
|
/// 采集工序:提交操作数据
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/Submit")]
|
public async Task<IActionResult> CollectNode_SubmitAsync([FromBody] ApiAction<SubmitInput> action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
if (!trans.IsFinished)
|
{
|
if (action.IsAsync)
|
{
|
response = action.GetResponse(await trans.Submit(action.Data));
|
}
|
else
|
{
|
lock (trans.TransLock) { response = action.GetResponse(trans.Submit(action.Data).Result); }
|
}
|
}
|
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);
|
}
|
|
/// <summary>
|
/// 提交前检查是否岗位、工单和不良代码
|
/// </summary>
|
/// <param name="action"></param>
|
/// <returns></returns>
|
[HttpPost]
|
[Route("api/[controller]/CollectNode/CheckCode")]
|
public async Task<IActionResult> CollectNode_CheckCodeAsync([FromBody] ApiAction action)
|
{
|
ApiAction response;
|
ICollectNode trans = null;
|
try
|
{
|
if (iBiz.MES.Context.GetTransDic().ContainsKey(action.ID))
|
{
|
trans = iBiz.MES.Context.GetTransDic()[action.ID] as ICollectNode;
|
if (!trans.IsFinished)
|
{
|
if (action.IsAsync)
|
{
|
response = action.GetResponse(await trans.CheckCode(action.Data?.ToString()));
|
}
|
else
|
{
|
lock (trans.TransLock) { response = action.GetResponse(trans.CheckCode(action.Data?.ToString()).Result); }
|
}
|
}
|
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);
|
}
|
}
|
}
|