|
|
@ -27,6 +27,12 @@ using DS.WMS.Core.Flow.Entity;
|
|
|
|
using DS.WMS.Core;
|
|
|
|
using DS.WMS.Core;
|
|
|
|
using MathNet.Numerics;
|
|
|
|
using MathNet.Numerics;
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
using NPOI.SS.Formula.Functions;
|
|
|
|
|
|
|
|
using DS.Module.UserModule;
|
|
|
|
|
|
|
|
using SqlSugar;
|
|
|
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
|
|
|
using LanguageExt.Common;
|
|
|
|
|
|
|
|
using DS.WMS.Core.TaskPlat.Dtos;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.MainApi.Controllers
|
|
|
|
namespace DS.WMS.MainApi.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -35,15 +41,29 @@ namespace DS.WMS.MainApi.Controllers
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
public class ExcelController : ApiController
|
|
|
|
public class ExcelController : ApiController
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
private readonly IExcelService _invokeService;
|
|
|
|
private readonly IExcelService _invokeService;
|
|
|
|
|
|
|
|
private readonly IUser user;
|
|
|
|
|
|
|
|
static readonly ApiFox api;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private readonly ISqlSugarClient db;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
|
|
/// 构造函数
|
|
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
|
|
static ExcelController()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
api = new ApiFox();
|
|
|
|
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|
/// 构造函数
|
|
|
|
/// 构造函数
|
|
|
|
/// </summary>
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="invokeService"></param>
|
|
|
|
/// <param name="invokeService"></param>
|
|
|
|
public ExcelController(IExcelService invokeService)
|
|
|
|
public ExcelController(IExcelService invokeService, IServiceProvider serviceProvider)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_invokeService = invokeService;
|
|
|
|
_invokeService = invokeService;
|
|
|
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
|
|
|
user = _serviceProvider.GetRequiredService<IUser>();
|
|
|
|
|
|
|
|
db = _serviceProvider.GetRequiredService<ISqlSugarClient>();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
@ -58,48 +78,48 @@ namespace DS.WMS.MainApi.Controllers
|
|
|
|
return _invokeService.ExportExcelByColumn(req);
|
|
|
|
return _invokeService.ExportExcelByColumn(req);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//[HttpPost]
|
|
|
|
/// <summary>
|
|
|
|
//[Route("CommonExcelExportAsync")]
|
|
|
|
/// 通用Excel导出
|
|
|
|
//public async Task<IActionResult> CommonExcelExportAsync([FromBody] ExportExcelReq req)
|
|
|
|
/// </summary>
|
|
|
|
//{
|
|
|
|
/// <param name="req"></param>
|
|
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
|
|
[Route("CommonExcelExport")]
|
|
|
|
|
|
|
|
[ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)]
|
|
|
|
|
|
|
|
public async Task<IActionResult> CommonExcelExportAsync([FromBody] ExportExcelReq req)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (api.DefaultHeaders.Contains("Authorization"))
|
|
|
|
|
|
|
|
api.DefaultHeaders.Remove("Authorization");
|
|
|
|
|
|
|
|
|
|
|
|
// if (instance.CallbackURL.IsNullOrEmpty())
|
|
|
|
api.DefaultHeaders.Add("Authorization", "Bearer " + user.GetToken());
|
|
|
|
// return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// //请求参数设置
|
|
|
|
var result = await api.PostAsync<DataResult>(req.Url, req.QueryRequest);
|
|
|
|
// var callback = new FlowCallback
|
|
|
|
if (!result.Succeeded)
|
|
|
|
// {
|
|
|
|
{
|
|
|
|
// InstanceId = instance.Id,
|
|
|
|
await new ApplicationException($"调用URL:{req.Url} 时返回了错误:" + result.Message).LogAsync(db);
|
|
|
|
// BusinessId = instance.BusinessId,
|
|
|
|
}
|
|
|
|
// BusinessType = instance.BusinessType,
|
|
|
|
var data = req.Url.Contains("GetSeaExportList") ?JsonConvert.SerializeObject(result.Data.ObjToDynamic()?.Data.list) : JsonConvert.SerializeObject(result.Data.Data);
|
|
|
|
// AuditType = instance.AuditType,
|
|
|
|
|
|
|
|
// FlowStatus = instance.FlowStatus,
|
|
|
|
|
|
|
|
// RejectReason = instance.Note
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if (api.DefaultHeaders.Contains("Authorization"))
|
|
|
|
var res1 = await _invokeService.ExportExcelStreamByColumnAsync(new ExportByColumnReq()
|
|
|
|
// api.DefaultHeaders.Remove("Authorization");
|
|
|
|
{
|
|
|
|
|
|
|
|
JsonDataStr = data,
|
|
|
|
|
|
|
|
ColumnSets = req.ColumnSets,
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// api.DefaultHeaders.Add("Authorization", "Bearer " + User.GetToken());
|
|
|
|
var dtstr = DateTime.Now.ToString("yyyyMMddHHmmssfff");
|
|
|
|
// try
|
|
|
|
|
|
|
|
// {
|
|
|
|
var filename = $"{dtstr}.xlsx";
|
|
|
|
// 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);
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
byte[] bytes = new byte[res1.Length];
|
|
|
|
|
|
|
|
res1.ReadExactly(bytes, 0, bytes.Length);
|
|
|
|
|
|
|
|
string mimeType = "application/octet-stream";
|
|
|
|
|
|
|
|
var _r = new FileContentResult(bytes, mimeType)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FileDownloadName = filename
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//}
|
|
|
|
//}
|
|
|
|
/// <summary>
|
|
|
|
/// <summary>
|
|
|
|