using System;
using System.Threading.Tasks;
using Rhea.Common;
using Tiger.Model;
using Tiger.IBusiness;
using Microsoft.AspNetCore.Mvc;
using Tiger.Model.Minsun;
using Autofac;
namespace Tiger.Api.Controllers.WMS
{
public partial class WMSController : ControllerBase
{
///
/// GetTransaction(ApiAction(Data:UserId))
/// 根据ApiAction的id返回一个送货单(U9)清点事务
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/GetTransaction")]
public IActionResult Count_BIZ_U9_ASN_GetTransaction([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
}
else
{
trans = AutoFacContainer.Instance.Resolve().Init(action.ID, action.Data?.USER_CODE, Request.Host.Value, action.Data?.ORG_CODE);
iBiz.WMS.Context.NewTransaction(HttpContext, trans);
}
response = action.GetResponse();
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// CloseTransaction(ApiAction)
/// 关闭事务
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/CloseTransaction")]
public IActionResult Count_BIZ_U9_ASN_CloseTransaction([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(trans.Close());
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.Close()); }
}
response.Message = $"送货单(U9)清点事务[ID:{action.ID}]关闭{(response.IsSuccessed ? "成功" : "失败")}";
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// Scan(ApiAction(BaseInput))
/// 扫描入口
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/Scan")]
public async Task Count_BIZ_U9_ASN_ScanAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(await trans.Scan(action.Data));
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.Scan(action.Data).Result); }
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// DeleteScannedList(ApiAction)
/// 删除当前所有已清点记录
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/DeleteScannedList")]
public async Task Count_BIZ_U9_ASN_DeleteScannedListAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(await trans.DeleteScannedList());
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.DeleteScannedList().Result); }
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// DeleteScannedSn(ApiAction(BaseInput(SN:SN)))
/// 根据传入要删除的SN,删除当前用户的已扫单个条码记录
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/DeleteScannedSn")]
public async Task Count_BIZ_U9_ASN_DeleteScannedSnAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(await trans.DeleteScannedSn(action.Data));
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.DeleteScannedSn(action.Data).Result); }
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// GetScannedList(ApiAction)
/// 获取本次已清点的物料列表(带分页)
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/GetScannedList")]
public async Task Count_BIZ_U9_ASN_GetScannedListAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
response = action.GetResponse(await trans.GetScannedList());
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// GetOrderList(ApiAction)
/// 获取当前所有单据信息
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/GetOrderList")]
public async Task Count_BIZ_U9_ASN_GetOrderListAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
response = action.GetResponse(await trans.GetOrderList());
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// SetGiftQty(ApiAction(BaseInput(Data:BIZ_U9_ASN_DTL)))
/// 设置收货单明细赠品数量,根据传入明细实体,更新其中QTY_GIFT字段
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/SetGiftQty")]
public async Task Count_BIZ_U9_ASN_SetGiftQtyAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(await trans.SetGiftQty(action.Data));
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.SetGiftQty(action.Data).Result); }
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
///
/// GenerateReceipt(ApiAction(BaseInput(Data:OrderNo)))
/// 根据传入的单号生成收货单,并调用U9新增收货单接口
///
///
///
[HttpPost]
[Route("api/[controller]/Count_U9ASN/GenerateReceipt")]
public async Task Count_BIZ_U9_ASN_GenerateReceiptAsync([FromBody] ApiAction action)
{
ApiAction response;
ICount_BIZ_U9_ASN trans = null;
try
{
if (iBiz.WMS.Context.GetTransDic().ContainsKey(action.ID))
{
trans = iBiz.WMS.Context.GetTransDic()[action.ID] as ICount_BIZ_U9_ASN;
if (!trans.IsFinished)
{
if (action.IsAsync)
{
response = action.GetResponse(await trans.GenerateReceipt(action.Data));
}
else
{
lock (trans.TransLock) { response = action.GetResponse(trans.GenerateReceipt(action.Data).Result); }
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]已经关闭,请重新打开送货单(U9)清点功能", false);
}
}
else
{
response = action.GetResponse($"Transaction Error: 送货单(U9)清点事务[ID:{action.ID}]数据丢失,请重新打开送货单(U9)清点功能", false);
}
}
catch (System.Exception ex)
{
response = action.GetResponse().CatchExceptionWithLog(ex);
}
trans?.AddHistory(Request, action);
return Ok(response);
}
}
}