You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

177 lines
6.1 KiB
C#

using DS.Module.Core;
using DS.Module.ExcelModule;
using DS.Module.ExcelModule.Model;
using DS.WMS.Core.Code.Interface;
2 months ago
using Masuit.Tools.Files;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
2 months ago
using Newtonsoft.Json;
using NPOI.HPSF;
2 months ago
using NPOI.XSSF.UserModel;
using SharpCompress.Common;
using System.IO;
using System.Text;
2 months ago
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 SixLabors.ImageSharp.Drawing;
using System.IO;
using System.Web;
using DS.WMS.Core.Flow.Dtos;
using DS.WMS.Core.Flow.Entity;
using DS.WMS.Core;
using MathNet.Numerics;
using NPOI.SS.Formula.Functions;
namespace DS.WMS.MainApi.Controllers
{
/// <summary>
/// Excel服务 模块
/// </summary>
public class ExcelController : ApiController
{
private readonly IExcelService _invokeService;
/// <summary>
/// 构造函数
/// </summary>
/// <param name="invokeService"></param>
public ExcelController(IExcelService invokeService)
{
_invokeService = invokeService;
}
/// <summary>
/// 根据用户列导出Excel数据
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
[HttpPost]
[Route("ExportExcelByColumn")]
public DataResult<string> ExportExcelByColumn([FromBody] ExportByColumnReq req)
{
return _invokeService.ExportExcelByColumn(req);
}
8 months ago
//[HttpPost]
//[Route("CommonExcelExportAsync")]
//public async Task<IActionResult> CommonExcelExportAsync([FromBody] ExportExcelReq req)
//{
// if (instance.CallbackURL.IsNullOrEmpty())
// return;
// //请求参数设置
// var callback = new FlowCallback
// {
// InstanceId = instance.Id,
// BusinessId = instance.BusinessId,
// BusinessType = instance.BusinessType,
// AuditType = instance.AuditType,
// FlowStatus = instance.FlowStatus,
// RejectReason = instance.Note
// };
// if (api.DefaultHeaders.Contains("Authorization"))
// api.DefaultHeaders.Remove("Authorization");
// api.DefaultHeaders.Add("Authorization", "Bearer " + User.GetToken());
// try
// {
// var result = await api.PostAsync<DataResult>(instance.CallbackURL, callback);
// if (result.Succeeded)
// {
// //更新回调执行标识
// await Db.Updateable<FlowInstance>().SetColumns(it => it.IsCallbackExecuted == true)
// .Where(it => it.Id == instance.Id).ExecuteCommandAsync();
// }
// else
// {
// await new ApplicationException($"访问回调URL{instance.CallbackURL} 时返回了错误:" + result.Message).LogAsync(Db);
// }
// }
// catch (Exception ex)
// {
// await ex.LogAsync(Db);
// }
//}
8 months ago
/// <summary>
/// 根据用户列导出Excel文件流
/// </summary>
/// <param name="req">请求数据</param>
/// <returns></returns>
[HttpPost]
[Route("ExportExcelStreamByColumn")]
2 months ago
[ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
//[AllowAnonymous]
public async Task<IActionResult> ExportExcelStreamByColumn([FromBody] ExportByColumnReq req)//
8 months ago
{
2 months ago
var result = _invokeService.ExportExcelStreamByColumn(req);
//HttpContext.Response.Headers.Add("Content-Length", result.Length.ToString());
//HttpContext.Response.Headers.Add("Content-Type", "application/octet-stream;charset=UTF-8");
var dtstr = DateTime.Now.ToString("yyyyMMddHHmmssfff");
var filename = $"{req.Title}-{dtstr}.xlsx";
byte[] bytes = new byte[result.Length];
result.ReadExactly(bytes, 0, bytes.Length);
string mimeType = "application/octet-stream";
var _r = new FileContentResult(bytes, mimeType)
{
FileDownloadName = filename
};
return _r;
//var path = Path.Combine("", "wwwroot/export/" + filename);
//using (FileStream fileStream = new FileStream(path, FileMode.Create, FileAccess.Write))
//{
// result.WriteTo(fileStream);
//}
//byte[] byteArr = System.IO.File.ReadAllBytes(path);
//string mimeType = "application/octet-stream";
//return new FileContentResult(byteArr, mimeType)
//{
// FileDownloadName = filename
//};
//return File(result, "application/octet-stream;charset=UTF-8",filename);
////return new FileStreamResult(result, "application/octet-stream;charset=UTF-8")
////{
//// FileDownloadName = filename
////};
//return File(result, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename);
//var bytes = new byte[result.Length];
//result.Read(bytes, 0, bytes.Length);
//result.Close();
//return new FileContentResult(bytes, "application/octet-stream");
//return new FileStreamResult(result, "application/octet-stream") { FileDownloadName = $"{req.Title}-{dtstr}.xlsx" };
//var provider = new Microsoft.AspNetCore.StaticFiles.FileExtensionContentTypeProvider();
//var memi = provider.Mappings[".xlsx"];
//var fileName = Path.GetFileName(filename);
//return File(result, memi, fileName);
//var result = _invokeService.OutputExcel(req);
//return File(result, "application/octet-stream;charset=UTF-8", "UploadTemplate.xlsx");
8 months ago
}
}
}