You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

129 lines
4.5 KiB
C#

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
{
/// <summary>
/// 邮件模板API
/// </summary>
public class TaskMailController : ApiController
{
readonly ITaskMailService service;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="service"></param>
public TaskMailController(ITaskMailService service)
{
this.service = service;
}
///// <summary>
///// 预览邮件模板
///// </summary>
///// <param name="host"></param>
///// <param name="customerNO">委托编号</param>
///// <param name="docType">单据类型</param>
///// <param name="templateName">模板自定义名称</param>
///// <returns></returns>
//[HttpGet, Route("Preview")]
//public async Task<IActionResult> 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");
//}
/// <summary>
/// 获取数据提供程序
/// </summary>
/// <param name="queryKey">模糊搜索</param>
/// <returns></returns>
[HttpGet, Route("GetProviders")]
public async Task<DataResult<List<BusinessDataProvider>>> GetProvidersAsync([FromQuery] string? queryKey)
{
return await service.GetProvidersAsync(queryKey);
}
/// <summary>
/// 获取分页列表
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[HttpPost, Route("GetList")]
public async Task<DataResult<List<BusinessTaskMail>>> GetListAsync([FromBody] PageRequest request)
{
return await service.GetListAsync(request);
}
/// <summary>
/// 详情
/// </summary>
/// <param name="id">ID</param>
/// <returns></returns>
[HttpGet, Route("Edit")]
public async Task<DataResult<BusinessTaskMail>> GetAsync([FromQuery] long id)
{
return await service.GetAsync(id);
}
/// <summary>
/// 编辑
/// </summary>
/// <param name="taskMail">邮件配置</param>
/// <returns></returns>
[HttpPost, Route("Edit")]
public async Task<DataResult> 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);
}
/// <summary>
/// 删除
/// </summary>
/// <param name="idModel"></param>
/// <returns></returns>
[HttpPost, Route("Delete")]
public async Task<DataResult> DeleteAsync([FromBody] IdModel idModel)
{
return await service.DeleteAsync(idModel);
}
/// <summary>
/// 删除附件
/// </summary>
/// <param name="attachments"></param>
/// <returns></returns>
[HttpPost, Route("DeleteAttachments")]
public async Task<DataResult> DeleteAttachmentsAsync([FromBody] List<BusinessTaskAttachment> attachments)
{
return await service.DeleteAttachmentsAsync(attachments);
}
}
}