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.
132 lines
4.5 KiB
C#
132 lines
4.5 KiB
C#
using System.Text;
|
|
using DS.Module.Core;
|
|
using DS.Module.Core.Data;
|
|
using DS.WMS.Core.Op.Entity;
|
|
using DS.WMS.Core.Op.Entity.TaskInteraction;
|
|
using DS.WMS.Core.Op.Interface.TaskInteraction;
|
|
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="docType">单据类型</param>
|
|
/// <param name="bsId">业务ID</param>
|
|
/// <param name="businessType">业务类型</param>
|
|
/// <returns></returns>
|
|
[HttpGet, Route("RenderTemplate")]
|
|
public async Task<DataResult<string>> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType)
|
|
{
|
|
return await service.RenderTemplateAsync(docType, bsId, businessType);
|
|
}
|
|
|
|
/// <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="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost, Route("GetList")]
|
|
public async Task<DataResult<List<BusinessTaskMail>>> GetListAsync(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(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.Receiver == null)
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailReceiverNotNull));
|
|
|
|
if (taskMail.Sender == null)
|
|
return DataResult.FailedWithDesc(nameof(MultiLanguageConst.TaskMailSenderNotNull));
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|