using DS.Module.Core; using DS.Module.Core.Data; using DS.WMS.Core.Code.Dtos; using DS.WMS.Core.Op.Dtos; using DS.WMS.Core.Op.Entity; using DS.WMS.Core.Op.Interface; using DS.WMS.Core.Sys.Dtos; using DS.WMS.Core.Sys.Interface; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using NPOI.HPSF; using SharpCompress.Common; using SixLabors.ImageSharp.Drawing; using System.IO; using System.Text; using System.Web; namespace DS.WMS.MainApi.Controllers; /// /// 业务附件模块 /// public class OpFileController : ApiController { private readonly IOpFileService _invokeService; /// /// 构造函数 /// /// public OpFileController(IOpFileService invokeService) { _invokeService = invokeService; } /// /// 添加附件 /// /// 文件信息 /// 业务附件请求实体 /// [HttpPost] [Route("AddFile")] public async Task> AddFile(IFormFile file, [FromForm] OpFileReq req) { var res = _invokeService.AddFile( file, req); return await res; } /// /// 多附件上传 /// /// 文件信息 /// 业务附件请求实体 /// [HttpPost] [Route("AddMultiFiles")] public async Task> AddMultiFiles(IFormCollection formCollection, [FromForm] OpFileReq req) { var res = _invokeService.AddMultiFiles(formCollection, req); return await res; } /// /// 获取业务附件 /// /// 业务id /// [HttpGet] [Route("GetOpFileList")] public DataResult> GetOpFileList([FromQuery] string id) { var res = _invokeService.GetOpFileList(id); return res; } /// /// 批量删除附件 /// /// /// [HttpPost] [Route("BatchDelFiles")] public async Task> BatchDelFiles([FromBody]IdModel req) { var res = _invokeService.BatchDelFiles(req); return await res; } ///// ///// 下载业务附件 ///// ///// 附件id ///// //[HttpGet] //[Route("DownloadOpFile")] //public async Task DownloadOpFile([FromQuery] string id) //{ // var res = await _invokeService.DownloadFile(id); // return res; //} /// /// 下载业务附件 /// /// 附件id /// [HttpGet] [Route("DownloadOpFileInfo")] [ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)] //[AllowAnonymous] public async Task DownloadOpFileInfo([FromQuery] string id) { var res = _invokeService.GetOpFileDownLoad(id); //var fileName = HttpUtility.UrlEncode(res.Data.FileName, Encoding.GetEncoding("UTF-8")); var path = res.Data.FilePath; var fileName = res.Data.FileName; byte[] byteArr = System.IO.File.ReadAllBytes(res.Data.FilePath); string mimeType = "application/octet-stream"; return new FileContentResult(byteArr, mimeType) { FileDownloadName = fileName }; } }