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 { /// /// 邮件模板API /// public class TaskMailController : ApiController { readonly ITaskMailService service; /// /// 构造函数 /// /// public TaskMailController(ITaskMailService service) { this.service = service; } /// /// 渲染模板 /// /// 单据类型 /// 业务ID /// 业务类型 /// [HttpGet, Route("RenderTemplate")] public async Task> RenderTemplateAsync(DocumentType docType, long bsId, BusinessType businessType) { return await service.RenderTemplateAsync(docType, bsId, businessType); } /// /// 预览邮件模板 /// /// /// 委托编号 /// 单据类型 /// 模板自定义名称 /// [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"); } /// /// 获取分页列表 /// /// /// [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); } /// /// 删除 /// /// /// [HttpPost, Route("Delete")] public async Task DeleteAsync(IdModel idModel) { return await service.DeleteAsync(idModel); } } }