using System.Net;
using DS.Module.Core;
using DS.WMS.Core.Op.Entity.TaskInteraction;
using DS.WMS.Core.Op.Interface.TaskInteraction;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.OpApi.Controllers
{
///
/// 任务邮件API
///
public class TaskMailController : ApiController
{
readonly ITaskMailService service;
///
/// 构造函数
///
///
public TaskMailController(ITaskMailService service)
{
this.service = service;
}
///
/// 运行测试
///
///
/// 任务类型
/// 业务ID
///
[HttpGet, Route("RunTest")]
public async Task RunTestAsync([FromServices] IActionManagerService actionManager,
[FromQuery] TaskBaseTypeEnum taskype, [FromQuery] long? id)
{
HttpStatusCode statusCode;
try
{
var result = await actionManager.TriggerTestAsync(taskype, id);
if (result.Succeeded)
{
statusCode = HttpStatusCode.NoContent;
return new StatusCodeResult((int)statusCode);
}
return new ContentResult
{
Content = result.Message,
StatusCode = result.Data == null ? null : (int)result.Data
};
}
catch
{
statusCode = HttpStatusCode.InternalServerError;
return new StatusCodeResult((int)statusCode);
}
}
///
/// 获取分页列表
///
///
///
[HttpPost, Route("GetList")]
public async Task>> GetListAsync(PageRequest request)
{
return await service.GetListAsync(request);
}
///
/// 详情
///
/// ID
///
[HttpGet, Route("Edit")]
public async Task> GetAsync(long id)
{
return await service.GetAsync(id);
}
///
/// 编辑
///
/// 邮件配置
///
[HttpPost, Route("Edit")]
public async Task EditAsync(BusinessTaskMail taskMail)
{
if (taskMail.Receiver == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailReceiverNotNull));
if (taskMail.Sender == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailSenderNotNull));
return await service.EditAsync(taskMail);
}
}
}