using Ao.Lang; using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; using CMS.Plugin.$NameSpacePath$.Application.Contracts.Dtos.$EntityName$; using CMS.Plugin.$NameSpacePath$.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.$NameSpacePath$.Controller { /// /// $ChinaComment$·þÎñ /// [ApiController] [TypeFilter(typeof(CMSLanguageFilter))] [TypeFilter(typeof(CMSUowActionFilter))] [TypeFilter(typeof(CMSAuditActionFilter))] [TypeFilter(typeof(CMSExceptionFilter))] [Route("api/v{version:apiVersion}/$NameSpacePath$/[controller]")] public class $EntityName$Controller : ControllerBase { private readonly I$EntityName$AppService _$EntityInstanceName$AppService; /// /// Initializes a new instance of the class. /// /// The $EntityInstanceName$ application service. public $EntityName$Controller(I$EntityName$AppService $EntityInstanceName$AppService) { _$EntityInstanceName$AppService = $EntityInstanceName$AppService; } /// /// »ñÈ¡$ChinaComment$ /// /// ±êʶ·û. /// [HttpGet] [Route("{id}")] public virtual Task<$EntityName$Dto> GetAsync(Guid id) { return _$EntityInstanceName$AppService.GetAsync(id); } /// /// ·ÖÒ³»ñÈ¡$ChinaComment$µÄÁбí. /// /// ÊäÈë. /// [HttpGet] [Route("Page")] public virtual Task> GetListAsync([FromQuery] Get$EntityName$Input input) { return _$EntityInstanceName$AppService.GetListAsync(input); } /// /// ´´½¨$ChinaComment$ /// /// ÊäÈë. /// //[Authorize] [HttpPost] public virtual Task<$EntityName$Dto> CreateAsync($EntityName$CreateDto input) { return _$EntityInstanceName$AppService.CreateAsync(input); } /// /// ¸üÐÂ$ChinaComment$ /// /// ±êʶ·û. /// ÊäÈë. /// //[Authorize] [HttpPut] [Route("{id}")] public virtual Task<$EntityName$Dto> UpdateAsync(Guid id, $EntityName$UpdateDto input) { return _$EntityInstanceName$AppService.UpdateAsync(id, input); } /// /// ¿Ë¡$ChinaComment$ /// /// Id¼¯ºÏ. /// //[Authorize] [HttpPost] [Route("Clone")] public virtual Task> CloneAsync([FromBody] IEnumerable ids) { return _$EntityInstanceName$AppService.CloneAsync(ids); } /// /// ɾ³ý$ChinaComment$ /// /// ±êʶ·û. /// //[Authorize] [HttpDelete] [Route("{id}")] public virtual Task DeleteAsync(Guid id) { return _$EntityInstanceName$AppService.DeleteAsync(id); } /// /// ÅúÁ¿É¾³ý$ChinaComment$ /// /// The ids. /// //[Authorize] [HttpDelete] public virtual Task DeleteAsync([FromBody] IEnumerable ids) { return _$EntityInstanceName$AppService.DeleteManyAsync(ids); } /// /// µ÷ÕûÅÅÐò$ChinaComment$ /// /// ±êʶ·û. /// [HttpPut] [Route("{id}/AdjustSort/{sort}")] public virtual Task AdjustSortAsync(Guid id, int sort) { return _$EntityInstanceName$AppService.AdjustSortAsync(id, sort); } /// /// µ¼Èë$ChinaComment$ /// /// [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 $EntityInstanceName$Rows = sheetNames.Contains("ÅäÖÃ") ? MiniExcel.Query<$EntityName$sImportModel.$EntityName$ImportModel>(stream, sheetName: "ÅäÖÃ").ToList() : new(); if (!$EntityInstanceName$Rows.Any()) { throw new UserFriendlyException("Çë¼ì²éµ¼ÈëµÄ±í¸ñ"); } await _$EntityInstanceName$AppService.ImportAsync(new $EntityName$sImportModel { $EntityName$s = $EntityInstanceName$Rows, }); return Ok(); } /// /// µ¼³ö$ChinaComment$ /// /// [HttpGet] [Route("Export")] public virtual async Task ExportAsync([FromQuery] Get$EntityName$Input input) { input.MaxResultCount = int.MaxValue; var exportData = await _$EntityInstanceName$AppService.ExportAsync(input); var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/$EntityName$µ¼³öÄ£°å.xlsx"); if (!System.IO.File.Exists(templatePath)) { templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/$EntityName$µ¼³öÄ£°å.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" }; } } }