using DS.Module.Core;
using DS.Module.Core.Data;
using DS.WMS.Core.TaskInteraction.Entity;
using DS.WMS.Core.TaskInteraction.Interface;
using Microsoft.AspNetCore.Mvc;
namespace DS.WMS.OpApi.Controllers
{
///
/// 邮件模板API
///
public class TaskMailController : ApiController
{
readonly ITaskMailService service;
///
/// 构造函数
///
///
public TaskMailController(ITaskMailService service)
{
this.service = service;
}
/////
///// 预览邮件模板
/////
/////
///// 委托编号
///// 单据类型
///// 模板自定义名称
/////
//[HttpGet, Route("Preview")]
//public async Task PreviewAsync([FromServices] IHostEnvironment host, string customerNO, DocumentType docType, string? templateName = null)
//{
// var result = await service.GetMailContentAsync(customerNO, docType, templateName);
// if (!result.Succeeded)
// return Content(result.Message);
// //string dir = Path.Combine(host.ContentRootPath, "wwwroot", "content-preview");
// //if (!Directory.Exists(dir))
// // Directory.CreateDirectory(dir);
// //string path = Path.Combine(dir, customerNO + ".htm");
// //FileStream fs = new FileStream(path, FileMode.Create);
// //StreamWriter writer = new StreamWriter(fs, Encoding.UTF8);
// //await writer.WriteAsync(result.Data.Item2);
// //await fs.FlushAsync();
// //return PhysicalFile(path, "application/octet-stream");
// return File(Encoding.UTF8.GetBytes(result.Data.Item2), "application/octet-stream", customerNO + ".htm");
//}
///
/// 获取数据提供程序
///
/// 模糊搜索
///
[HttpGet, Route("GetProviders")]
public async Task>> GetProvidersAsync([FromQuery] string? queryKey)
{
return await service.GetProvidersAsync(queryKey);
}
///
/// 获取分页列表
///
///
///
[HttpPost, Route("GetList")]
public async Task>> GetListAsync([FromBody] PageRequest request)
{
return await service.GetListAsync(request);
}
///
/// 详情
///
/// ID
///
[HttpGet, Route("Edit")]
public async Task> GetAsync([FromQuery] long id)
{
return await service.GetAsync(id);
}
///
/// 编辑
///
/// 邮件配置
///
[HttpPost, Route("Edit")]
public async Task EditAsync([FromBody] BusinessTaskMail taskMail)
{
if (taskMail.Receivers == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailReceiverNotNull));
if (taskMail.Sender == null)
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailSenderNotNull));
taskMail.IsBusiness = true;
return await service.EditAsync(taskMail);
}
///
/// 删除
///
///
///
[HttpPost, Route("Delete")]
public async Task DeleteAsync([FromBody] IdModel idModel)
{
return await service.DeleteAsync(idModel);
}
///
/// 删除附件
///
///
///
[HttpPost, Route("DeleteAttachments")]
public async Task DeleteAttachmentsAsync([FromBody] List attachments)
{
return await service.DeleteAttachmentsAsync(attachments);
}
}
}