using Ao.Lang; using CMS.Extensions.Abp.AspNetCore.Mvc.Filters; using CMS.Plugin.PipeLineLems.Application.Contracts.Dtos.CallMaterialOrder; 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 { /// /// 叫料单表服务 /// [ApiController] [TypeFilter(typeof(CMSLanguageFilter))] [TypeFilter(typeof(CMSUowActionFilter))] [TypeFilter(typeof(CMSAuditActionFilter))] [TypeFilter(typeof(CMSExceptionFilter))] [Route("api/v{version:apiVersion}/PipeLineLems/[controller]")] public class CallMaterialOrderController : ControllerBase { private readonly ICallMaterialOrderAppService _callMaterialOrderAppService; /// /// Initializes a new instance of the class. /// /// The callMaterialOrder application service. public CallMaterialOrderController(ICallMaterialOrderAppService callMaterialOrderAppService) { _callMaterialOrderAppService = callMaterialOrderAppService; } /// /// 获取叫料单表 /// /// 标识符. /// [HttpGet] [Route("{id}")] public virtual Task GetAsync(Guid id) { return _callMaterialOrderAppService.GetAsync(id); } /// /// 分页获取叫料单表的列表. /// /// 输入. /// [HttpGet] [Route("Page")] public virtual Task> GetListAsync([FromQuery] GetCallMaterialOrderInput input) { return _callMaterialOrderAppService.GetListAsync(input); } /// /// 创建叫料单表 /// /// 输入. /// //[Authorize] [HttpPost] public virtual Task CreateAsync(CallMaterialOrderCreateDto input) { return _callMaterialOrderAppService.CreateAsync(input); } /// /// 更新叫料单表 /// /// 标识符. /// 输入. /// //[Authorize] [HttpPut] [Route("{id}")] public virtual Task UpdateAsync(Guid id, CallMaterialOrderUpdateDto input) { return _callMaterialOrderAppService.UpdateAsync(id, input); } /// /// 克隆叫料单表 /// /// Id集合. /// //[Authorize] [HttpPost] [Route("Clone")] public virtual Task> CloneAsync([FromBody] IEnumerable ids) { return _callMaterialOrderAppService.CloneAsync(ids); } /// /// 删除叫料单表 /// /// 标识符. /// //[Authorize] [HttpDelete] [Route("{id}")] public virtual Task DeleteAsync(Guid id) { return _callMaterialOrderAppService.DeleteAsync(id); } /// /// 批量删除叫料单表 /// /// The ids. /// //[Authorize] [HttpDelete] public virtual Task DeleteAsync([FromBody] IEnumerable ids) { return _callMaterialOrderAppService.DeleteManyAsync(ids); } /// /// 调整排序叫料单表 /// /// 标识符. /// [HttpPut] [Route("{id}/AdjustSort/{sort}")] public virtual Task AdjustSortAsync(Guid id, int sort) { return _callMaterialOrderAppService.AdjustSortAsync(id, sort); } /// /// 导入叫料单表 /// /// [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 callMaterialOrderRows = sheetNames.Contains("配置") ? MiniExcel.Query(stream, sheetName: "配置").ToList() : new(); if (!callMaterialOrderRows.Any()) { throw new UserFriendlyException("请检查导入的表格"); } await _callMaterialOrderAppService.ImportAsync(new CallMaterialOrdersImportModel { CallMaterialOrders = callMaterialOrderRows, }); return Ok(); } /// /// 导出叫料单表 /// /// [HttpGet] [Route("Export")] public virtual async Task ExportAsync([FromQuery] GetCallMaterialOrderInput input) { input.MaxResultCount = int.MaxValue; var exportData = await _callMaterialOrderAppService.ExportAsync(input); var templatePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, $"Resources/Templates/CallMaterialOrder导出模板.xlsx"); if (!System.IO.File.Exists(templatePath)) { templatePath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, $"Resources/Templates/CallMaterialOrder导出模板.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" }; } } }