using Ao.Lang; using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.MyTestEntityNames; using CMS.Plugin.PipeLineLems.Application.Contracts.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using MiniExcelLibs; using System.Reflection; using Volo.Abp; using Volo.Abp.Application.Dtos; namespace CMS.Plugin.PipeLineLems.Controller { /// /// MyTestEntityName服务 /// [ApiController] [TypeFilter(typeof(CMSLanguageFilter))] [TypeFilter(typeof(CMSUowActionFilter))] [TypeFilter(typeof(CMSAuditActionFilter))] [TypeFilter(typeof(CMSExceptionFilter))] [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")] public class MyTestEntityNameController : ControllerBase { private readonly IMyTestEntityNameAppService _mytestentitynameAppService; /// /// Initializes a new instance of the class. /// /// The mytestentityname application service. public MyTestEntityNameController(IMyTestEntityNameAppService mytestentitynameAppService) { _mytestentitynameAppService = mytestentitynameAppService; } /// /// 获取mytestentityname. /// /// 标识符. /// [HttpGet] [Route("{id}")] public virtual Task GetAsync(Guid id) { return _mytestentitynameAppService.GetAsync(id); } /// /// 获取mytestentityname的列表. /// /// 输入. /// [HttpGet] public virtual Task> GetListAsync([FromQuery] GetMyTestEntityNamesInput input) { return _mytestentitynameAppService.GetListAsync(input); } /// /// 创建mytestentityname. /// /// 输入. /// //[Authorize] [HttpPost] public virtual Task CreateAsync(MyTestEntityNameCreateDto input) { return _mytestentitynameAppService.CreateAsync(input); } /// /// 更新mytestentityname. /// /// 标识符. /// 输入. /// //[Authorize] [HttpPut] [Route("{id}")] public virtual Task UpdateAsync(Guid id, MyTestEntityNameUpdateDto input) { return _mytestentitynameAppService.UpdateAsync(id, input); } /// /// 克隆MyTestEntityName. /// /// Id集合. /// //[Authorize] [HttpPost] [Route("Clone")] public virtual Task> CloneAsync([FromBody] IEnumerable ids) { return _mytestentitynameAppService.CloneAsync(ids); } /// /// 删除mytestentityname. /// /// 标识符. /// //[Authorize] [HttpDelete] [Route("{id}")] public virtual Task DeleteAsync(Guid id) { return _mytestentitynameAppService.DeleteAsync(id); } /// /// 批量删除mytestentityname. /// /// The ids. /// //[Authorize] [HttpDelete] public virtual Task DeleteAsync([FromBody] IEnumerable ids) { return _mytestentitynameAppService.DeleteManyAsync(ids); } /// /// 调整排序. /// /// 标识符. /// [HttpPut] [Route("{id}/AdjustSort/{sort}")] public virtual Task AdjustSortAsync(Guid id, int sort) { return _mytestentitynameAppService.AdjustSortAsync(id, sort); } /// /// 导入mytestentityname. /// /// [Authorize] [HttpPost] [Route("Import")] public virtual async Task ImportAsync(IFormFile file) { using var stream = new MemoryStream(); await file.CopyToAsync(stream); stream.Seek(0L, SeekOrigin.Begin); var sheetNames = stream.GetSheetNames(); var mytestentitynameRows = sheetNames.Contains("配置") ? MiniExcel.Query(stream, sheetName: "配置").ToList() : new(); if (!mytestentitynameRows.Any()) { throw new UserFriendlyException("请检查导入的表格"); } await _mytestentitynameAppService.ImportAsync(new MyTestEntityNamesImportModel { MyTestEntityNames = mytestentitynameRows, }); return Ok(); } /// /// 导出mytestentityname. /// /// [HttpGet] [Route("Export")] public virtual async Task ExportAsync([FromQuery] GetMyTestEntityNamesInput input) { input.MaxResultCount = int.MaxValue; var exportData = await _mytestentitynameAppService.ExportAsync(input); var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/MyTestEntityName导出模板.xlsx"); if (!System.IO.File.Exists(templatePath)) { templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/MyTestEntityName导出模板.xlsx"); } var memoryStream = new MemoryStream(); await memoryStream.SaveAsByTemplateAsync(templatePath, exportData.Sheets); memoryStream.Seek(0L, SeekOrigin.Begin); return new FileStreamResult(memoryStream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet") { FileDownloadName = $"{exportData.FileName}_{DateTime.Now:yyyyMMddhhmmss}.xlsx" }; } } }