| | |
| | | using Ao.Lang; |
| | | using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; |
| | | using CMS.Plugin.WareCmsUtilityApi.Application.Contracts.Dtos.Samples; |
| | | using CMS.Plugin.WareCmsUtilityApi.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; |
| | | //using Ao.Lang; |
| | | //using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; |
| | | //using CMS.Plugin.WareCmsUtilityApi.Application.Contracts.Dtos.Samples; |
| | | //using CMS.Plugin.WareCmsUtilityApi.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.WareCmsUtilityApi.Controller |
| | | { |
| | | /// <summary> |
| | | /// Sampleæå¡ |
| | | /// </summary> |
| | | [ApiController] |
| | | [TypeFilter(typeof(CMSLanguageFilter))] |
| | | [TypeFilter(typeof(CMSUowActionFilter))] |
| | | [TypeFilter(typeof(CMSAuditActionFilter))] |
| | | [TypeFilter(typeof(CMSExceptionFilter))] |
| | | [Route("api/v{version:apiVersion}/WareCmsUtilityApi/[controller]")] |
| | | public class SampleController : ControllerBase |
| | | { |
| | | private readonly ISampleAppService _sampleAppService; |
| | | //namespace CMS.Plugin.WareCmsUtilityApi.Controller |
| | | //{ |
| | | // /// <summary> |
| | | // /// Sampleæå¡ |
| | | // /// </summary> |
| | | // [ApiController] |
| | | // [TypeFilter(typeof(CMSLanguageFilter))] |
| | | // [TypeFilter(typeof(CMSUowActionFilter))] |
| | | // [TypeFilter(typeof(CMSAuditActionFilter))] |
| | | // [TypeFilter(typeof(CMSExceptionFilter))] |
| | | // [Route("api/v{version:apiVersion}/WareCmsUtilityApi/[controller]")] |
| | | // public class SampleController : ControllerBase |
| | | // { |
| | | // private readonly ISampleAppService _sampleAppService; |
| | | |
| | | /// <summary> |
| | | /// Initializes a new instance of the <see cref="SampleController"/> class. |
| | | /// </summary> |
| | | /// <param name="sampleAppService">The sample application service.</param> |
| | | public SampleController(ISampleAppService sampleAppService) |
| | | { |
| | | _sampleAppService = sampleAppService; |
| | | } |
| | | // /// <summary> |
| | | // /// Initializes a new instance of the <see cref="SampleController"/> class. |
| | | // /// </summary> |
| | | // /// <param name="sampleAppService">The sample application service.</param> |
| | | // public SampleController(ISampleAppService sampleAppService) |
| | | // { |
| | | // _sampleAppService = sampleAppService; |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// è·åsample. |
| | | /// </summary> |
| | | /// <param name="id">æ è¯ç¬¦.</param> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | [Route("{id}")] |
| | | public virtual Task<SampleDto> GetAsync(Guid id) |
| | | { |
| | | return _sampleAppService.GetAsync(id); |
| | | } |
| | | // /// <summary> |
| | | // /// è·åsample. |
| | | // /// </summary> |
| | | // /// <param name="id">æ è¯ç¬¦.</param> |
| | | // /// <returns></returns> |
| | | // [HttpGet] |
| | | // [Route("{id}")] |
| | | // public virtual Task<SampleDto> GetAsync(Guid id) |
| | | // { |
| | | // return _sampleAppService.GetAsync(id); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// è·åsampleçå表. |
| | | /// </summary> |
| | | /// <param name="input">è¾å
¥.</param> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | public virtual Task<PagedResultDto<SampleDto>> GetListAsync([FromQuery] GetSamplesInput input) |
| | | { |
| | | return _sampleAppService.GetListAsync(input); |
| | | } |
| | | // /// <summary> |
| | | // /// è·åsampleçå表. |
| | | // /// </summary> |
| | | // /// <param name="input">è¾å
¥.</param> |
| | | // /// <returns></returns> |
| | | // [HttpGet] |
| | | // public virtual Task<PagedResultDto<SampleDto>> GetListAsync([FromQuery] GetSamplesInput input) |
| | | // { |
| | | // return _sampleAppService.GetListAsync(input); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// å建sample. |
| | | /// </summary> |
| | | /// <param name="input">è¾å
¥.</param> |
| | | /// <returns></returns> |
| | | //[Authorize] |
| | | [HttpPost] |
| | | public virtual Task<SampleDto> CreateAsync(SampleCreateDto input) |
| | | { |
| | | return _sampleAppService.CreateAsync(input); |
| | | } |
| | | // /// <summary> |
| | | // /// å建sample. |
| | | // /// </summary> |
| | | // /// <param name="input">è¾å
¥.</param> |
| | | // /// <returns></returns> |
| | | // //[Authorize] |
| | | // [HttpPost] |
| | | // public virtual Task<SampleDto> CreateAsync(SampleCreateDto input) |
| | | // { |
| | | // return _sampleAppService.CreateAsync(input); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// æ´æ°sample. |
| | | /// </summary> |
| | | /// <param name="id">æ è¯ç¬¦.</param> |
| | | /// <param name="input">è¾å
¥.</param> |
| | | /// <returns></returns> |
| | | //[Authorize] |
| | | [HttpPut] |
| | | [Route("{id}")] |
| | | public virtual Task<SampleDto> UpdateAsync(Guid id, SampleUpdateDto input) |
| | | { |
| | | return _sampleAppService.UpdateAsync(id, input); |
| | | } |
| | | // /// <summary> |
| | | // /// æ´æ°sample. |
| | | // /// </summary> |
| | | // /// <param name="id">æ è¯ç¬¦.</param> |
| | | // /// <param name="input">è¾å
¥.</param> |
| | | // /// <returns></returns> |
| | | // //[Authorize] |
| | | // [HttpPut] |
| | | // [Route("{id}")] |
| | | // public virtual Task<SampleDto> UpdateAsync(Guid id, SampleUpdateDto input) |
| | | // { |
| | | // return _sampleAppService.UpdateAsync(id, input); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// å
éSample. |
| | | /// </summary> |
| | | /// <param name="ids">Idéå.</param> |
| | | /// <returns></returns> |
| | | //[Authorize] |
| | | [HttpPost] |
| | | [Route("Clone")] |
| | | public virtual Task<List<SampleDto>> CloneAsync([FromBody] IEnumerable<Guid> ids) |
| | | { |
| | | return _sampleAppService.CloneAsync(ids); |
| | | } |
| | | // /// <summary> |
| | | // /// å
éSample. |
| | | // /// </summary> |
| | | // /// <param name="ids">Idéå.</param> |
| | | // /// <returns></returns> |
| | | // //[Authorize] |
| | | // [HttpPost] |
| | | // [Route("Clone")] |
| | | // public virtual Task<List<SampleDto>> CloneAsync([FromBody] IEnumerable<Guid> ids) |
| | | // { |
| | | // return _sampleAppService.CloneAsync(ids); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// å é¤sample. |
| | | /// </summary> |
| | | /// <param name="id">æ è¯ç¬¦.</param> |
| | | /// <returns></returns> |
| | | //[Authorize] |
| | | [HttpDelete] |
| | | [Route("{id}")] |
| | | public virtual Task DeleteAsync(Guid id) |
| | | { |
| | | return _sampleAppService.DeleteAsync(id); |
| | | } |
| | | // /// <summary> |
| | | // /// å é¤sample. |
| | | // /// </summary> |
| | | // /// <param name="id">æ è¯ç¬¦.</param> |
| | | // /// <returns></returns> |
| | | // //[Authorize] |
| | | // [HttpDelete] |
| | | // [Route("{id}")] |
| | | // public virtual Task DeleteAsync(Guid id) |
| | | // { |
| | | // return _sampleAppService.DeleteAsync(id); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// æ¹éå é¤sample. |
| | | /// </summary> |
| | | /// <param name="ids">The ids.</param> |
| | | /// <returns></returns> |
| | | //[Authorize] |
| | | [HttpDelete] |
| | | public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids) |
| | | { |
| | | return _sampleAppService.DeleteManyAsync(ids); |
| | | } |
| | | // /// <summary> |
| | | // /// æ¹éå é¤sample. |
| | | // /// </summary> |
| | | // /// <param name="ids">The ids.</param> |
| | | // /// <returns></returns> |
| | | // //[Authorize] |
| | | // [HttpDelete] |
| | | // public virtual Task DeleteAsync([FromBody] IEnumerable<Guid> ids) |
| | | // { |
| | | // return _sampleAppService.DeleteManyAsync(ids); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// è°æ´æåº. |
| | | /// </summary> |
| | | /// <param name="id">æ è¯ç¬¦.</param> |
| | | /// <returns></returns> |
| | | [HttpPut] |
| | | [Route("{id}/AdjustSort/{sort}")] |
| | | public virtual Task AdjustSortAsync(Guid id, int sort) |
| | | { |
| | | return _sampleAppService.AdjustSortAsync(id, sort); |
| | | } |
| | | // /// <summary> |
| | | // /// è°æ´æåº. |
| | | // /// </summary> |
| | | // /// <param name="id">æ è¯ç¬¦.</param> |
| | | // /// <returns></returns> |
| | | // [HttpPut] |
| | | // [Route("{id}/AdjustSort/{sort}")] |
| | | // public virtual Task AdjustSortAsync(Guid id, int sort) |
| | | // { |
| | | // return _sampleAppService.AdjustSortAsync(id, sort); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// 导å
¥sample. |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [Authorize] |
| | | [HttpPost] |
| | | [Route("Import")] |
| | | public virtual async Task<IActionResult> ImportAsync(IFormFile file) |
| | | { |
| | | using var stream = new MemoryStream(); |
| | | await file.CopyToAsync(stream); |
| | | stream.Seek(0L, SeekOrigin.Begin); |
| | | // /// <summary> |
| | | // /// 导å
¥sample. |
| | | // /// </summary> |
| | | // /// <returns></returns> |
| | | // [Authorize] |
| | | // [HttpPost] |
| | | // [Route("Import")] |
| | | // public virtual async Task<IActionResult> ImportAsync(IFormFile file) |
| | | // { |
| | | // using var stream = new MemoryStream(); |
| | | // await file.CopyToAsync(stream); |
| | | // stream.Seek(0L, SeekOrigin.Begin); |
| | | |
| | | var sheetNames = stream.GetSheetNames(); |
| | | var sampleRows = sheetNames.Contains("é
ç½®") ? MiniExcel.Query<SamplesImportModel.SampleImportModel>(stream, sheetName: "é
ç½®").ToList() : new(); |
| | | // var sheetNames = stream.GetSheetNames(); |
| | | // var sampleRows = sheetNames.Contains("é
ç½®") ? MiniExcel.Query<SamplesImportModel.SampleImportModel>(stream, sheetName: "é
ç½®").ToList() : new(); |
| | | |
| | | if (!sampleRows.Any()) |
| | | { |
| | | throw new UserFriendlyException("è¯·æ£æ¥å¯¼å
¥çè¡¨æ ¼"); |
| | | } |
| | | // if (!sampleRows.Any()) |
| | | // { |
| | | // throw new UserFriendlyException("è¯·æ£æ¥å¯¼å
¥çè¡¨æ ¼"); |
| | | // } |
| | | |
| | | await _sampleAppService.ImportAsync(new SamplesImportModel |
| | | { |
| | | Samples = sampleRows, |
| | | }); |
| | | // await _sampleAppService.ImportAsync(new SamplesImportModel |
| | | // { |
| | | // Samples = sampleRows, |
| | | // }); |
| | | |
| | | return Ok(); |
| | | } |
| | | // return Ok(); |
| | | // } |
| | | |
| | | /// <summary> |
| | | /// 导åºsample. |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | [HttpGet] |
| | | [Route("Export")] |
| | | public virtual async Task<IActionResult> ExportAsync([FromQuery] GetSamplesInput input) |
| | | { |
| | | input.MaxResultCount = int.MaxValue; |
| | | var exportData = await _sampleAppService.ExportAsync(input); |
| | | var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/Sampleå¯¼åºæ¨¡æ¿.xlsx"); |
| | | if (!System.IO.File.Exists(templatePath)) |
| | | { |
| | | templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/Sampleå¯¼åºæ¨¡æ¿.xlsx"); |
| | | } |
| | | // /// <summary> |
| | | // /// 导åºsample. |
| | | // /// </summary> |
| | | // /// <returns></returns> |
| | | // [HttpGet] |
| | | // [Route("Export")] |
| | | // public virtual async Task<IActionResult> ExportAsync([FromQuery] GetSamplesInput input) |
| | | // { |
| | | // input.MaxResultCount = int.MaxValue; |
| | | // var exportData = await _sampleAppService.ExportAsync(input); |
| | | // var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/Sampleå¯¼åºæ¨¡æ¿.xlsx"); |
| | | // if (!System.IO.File.Exists(templatePath)) |
| | | // { |
| | | // templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/Sampleå¯¼åºæ¨¡æ¿.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" }; |
| | | } |
| | | } |
| | | } |
| | | // 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" }; |
| | | // } |
| | | // } |
| | | //} |