using System.Text; using DS.Module.Core; using DS.Module.Core.Data; using DS.WMS.Core.Code.Dtos; using DS.WMS.Core.Code.Interface; using DS.WMS.Core.Info.Dtos; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; namespace DS.WMS.MainApi.Controllers; /// /// 用户邮箱设置 模块 /// public class UserEmailController : ApiController { private readonly IUserEmailService _invokeService; /// /// 构造函数 /// /// public UserEmailController(IUserEmailService invokeService) { _invokeService = invokeService; } /// /// 导入 /// /// /// [HttpPost, Route("Import")] public async Task ImportAsync(IFormFile file) { if (file == null) return DataResult.Failed("请求未包含文件流"); var stream = file.OpenReadStream(); var rows = (await MiniExcel.QueryAsync(stream, excelType: ExcelType.XLSX, startCell: "A2")).ToList(); List list = []; try { foreach (IDictionary item in rows) { var model = new CodeUserEmailReq { ShowName = item["B"]?.ToString(), MailAccount = item["D"]?.ToString(), ReceiveServer = "imap.exmail.qq.com", ReceivePort = 993, ReceiveSSL = true, SmtpServer = "smtp.exmail.qq.com", SmtpPort = 465, SmtpSSL = true, IsCompany = false }; list.Add(model); } } catch (Exception ex) { return DataResult.Failed("读取文件失败:" + ex.Message); } return await _invokeService.ImportAsync(list); } /// /// 列表 /// /// /// [HttpPost] [Route("GetUserEmailList")] public DataResult> GetUserEmailList([FromBody] PageRequest request) { var res = _invokeService.GetListByPage(request); return res; } /// /// 编辑 /// /// /// [HttpPost] [Route("EditUserEmail")] public DataResult EditUserEmail([FromBody] CodeUserEmailReq req) { var res = _invokeService.EditUserEmail(req); return res; } /// /// 详情 /// /// Id /// [HttpGet] [Route("GetUserEmailInfo")] public DataResult GetUserEmailInfo([FromQuery] string id) { var res = _invokeService.GetUserEmailInfo(id); return res; } /// /// 批量删除 /// /// req /// [HttpPost] [Route("BatchDelUserEmail")] public DataResult BatchDelUserEmail([FromBody] IdModel req) { var res = _invokeService.BatchDelUserEmail(req); return res; } /// /// 获取用户邮箱配置 /// /// [HttpGet] [Route("GetUserEmailSetInfo")] public async Task> GetUserEmailSetInfo() { var res = await _invokeService.GetCurrentUserEmailAsync(); return res; } }