From df696a48804df1b3e37e2a222a96344cda6091c3 Mon Sep 17 00:00:00 2001 From: cjy Date: Tue, 29 Oct 2024 16:15:01 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=80=9A=E7=94=A8Excel=E5=AF=BC=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DS.Module.Core/Extensions/Extensions.cs | 10 +- .../MultiLanguageMiddleware.cs | 1 + .../Controllers/ExcelController.cs | 106 +++++++++++------- 3 files changed, 73 insertions(+), 44 deletions(-) diff --git a/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs b/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs index 894c5286..8e6431f9 100644 --- a/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs +++ b/ds-wms-service/DS.Module.Core/Extensions/Extensions.cs @@ -157,7 +157,15 @@ public static partial class Extensions return reval; } - + /// + /// + /// + /// + /// + public static dynamic ObjToDynamic(this object thisValue) + { + return thisValue; + } /// /// /// diff --git a/ds-wms-service/DS.Module.MultiLanguage/MultiLanguageMiddleware.cs b/ds-wms-service/DS.Module.MultiLanguage/MultiLanguageMiddleware.cs index 1a3fcbdb..9ea060a3 100644 --- a/ds-wms-service/DS.Module.MultiLanguage/MultiLanguageMiddleware.cs +++ b/ds-wms-service/DS.Module.MultiLanguage/MultiLanguageMiddleware.cs @@ -52,6 +52,7 @@ public class MultiLanguageMiddleware || context.Request.Path.Value.IndexOf("DownloadBookingOrClosingEDI", StringComparison.InvariantCultureIgnoreCase) > -1 || context.Request.Path.Value.IndexOf("DownloadFile", StringComparison.InvariantCultureIgnoreCase) > -1 || context.Request.Path.Value.IndexOf("ExportExcelStreamByColumn", StringComparison.InvariantCultureIgnoreCase) > -1 + || context.Request.Path.Value.IndexOf("CommonExcelExport", StringComparison.InvariantCultureIgnoreCase) > -1 ) ) { diff --git a/ds-wms-service/DS.WMS.MainApi/Controllers/ExcelController.cs b/ds-wms-service/DS.WMS.MainApi/Controllers/ExcelController.cs index bd857bb8..14640001 100644 --- a/ds-wms-service/DS.WMS.MainApi/Controllers/ExcelController.cs +++ b/ds-wms-service/DS.WMS.MainApi/Controllers/ExcelController.cs @@ -27,6 +27,12 @@ using DS.WMS.Core.Flow.Entity; using DS.WMS.Core; using MathNet.Numerics; 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 { @@ -35,15 +41,29 @@ namespace DS.WMS.MainApi.Controllers /// public class ExcelController : ApiController { + private readonly IServiceProvider _serviceProvider; private readonly IExcelService _invokeService; + private readonly IUser user; + static readonly ApiFox api; + private readonly ISqlSugarClient db; + /// + /// 构造函数 + /// + static ExcelController() + { + api = new ApiFox(); + } /// /// 构造函数 /// /// - public ExcelController(IExcelService invokeService) + public ExcelController(IExcelService invokeService, IServiceProvider serviceProvider) { _invokeService = invokeService; + _serviceProvider = serviceProvider; + user = _serviceProvider.GetRequiredService(); + db = _serviceProvider.GetRequiredService(); } /// @@ -58,48 +78,48 @@ namespace DS.WMS.MainApi.Controllers return _invokeService.ExportExcelByColumn(req); } - //[HttpPost] - //[Route("CommonExcelExportAsync")] - //public async Task 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(instance.CallbackURL, callback); - // if (result.Succeeded) - // { - // //更新回调执行标识 - // await Db.Updateable().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); - // } + /// + /// 通用Excel导出 + /// + /// + /// + [HttpPost] + [Route("CommonExcelExport")] + [ProducesResponseType(typeof(FileResult), StatusCodes.Status200OK)] + public async Task CommonExcelExportAsync([FromBody] ExportExcelReq req) + { + if (api.DefaultHeaders.Contains("Authorization")) + api.DefaultHeaders.Remove("Authorization"); + + api.DefaultHeaders.Add("Authorization", "Bearer " + user.GetToken()); + + var result = await api.PostAsync(req.Url, req.QueryRequest); + if (!result.Succeeded) + { + await new ApplicationException($"调用URL:{req.Url} 时返回了错误:" + result.Message).LogAsync(db); + } + var data = req.Url.Contains("GetSeaExportList") ?JsonConvert.SerializeObject(result.Data.ObjToDynamic()?.Data.list) : JsonConvert.SerializeObject(result.Data.Data); + var res1 = await _invokeService.ExportExcelStreamByColumnAsync(new ExportByColumnReq() + { + JsonDataStr = data, + ColumnSets = req.ColumnSets, + }); + + var dtstr = DateTime.Now.ToString("yyyyMMddHHmmssfff"); + + var filename = $"{dtstr}.xlsx"; + + 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; + } //} /// @@ -114,7 +134,7 @@ namespace DS.WMS.MainApi.Controllers public async Task ExportExcelStreamByColumn([FromBody] ExportByColumnReq req)// { - var result = _invokeService.ExportExcelStreamByColumn(req); + 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"); From 59934d0849926da0e4d9291c71083c76126e9a50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B5=87=E6=96=87=E9=BE=99?= Date: Tue, 29 Oct 2024 16:16:25 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=8F=90=E5=8D=95?= =?UTF-8?q?=E7=A1=AE=E8=AE=A4=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../TaskInteraction/Method/SeaExportTaskService.cs | 2 +- .../DS.WMS.Core/TaskInteraction/Method/TaskService.cs | 2 +- .../DS.WMS.OpApi/Controllers/SeaExportTaskController.cs | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/SeaExportTaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/SeaExportTaskService.cs index f789c61a..a650dc5a 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/SeaExportTaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/SeaExportTaskService.cs @@ -227,7 +227,7 @@ namespace DS.WMS.Core.TaskInteraction.Method var list = await TenantDb.Queryable() .LeftJoin((t, b) => t.BusinessId == b.Id) - .Where((t, b) => t.TaskType == BL_CONFIRM_TASK && t.ParentBusinessId == bsId && t.BusinessType == bsType) + .Where((t, b) => t.ParentBusinessId == bsId && t.BusinessType == bsType) .Select((t, b) => new BLTask { BLNumber = b.HBLNO, diff --git a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs index cb0376b5..e21cf011 100644 --- a/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs +++ b/ds-wms-service/DS.WMS.Core/TaskInteraction/Method/TaskService.cs @@ -375,7 +375,7 @@ namespace DS.WMS.Core.TaskInteraction.Method CreateTime = dtNow }).ToList(); - await TenantDb.Insertable(request.Steps).ExecuteCommandAsync(); + await TenantDb.Insertable(steps).ExecuteCommandAsync(); } result = await OnTaskCreated(task); diff --git a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs index 13c92b0f..b85fce54 100644 --- a/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs +++ b/ds-wms-service/DS.WMS.OpApi/Controllers/SeaExportTaskController.cs @@ -49,13 +49,13 @@ namespace DS.WMS.OpApi.Controllers /// /// 获取提单确认信息 /// - /// 业务ID - /// 业务类型 + /// 业务ID + /// 业务类型(可选参数) /// [HttpGet, Route("GetBLConfirmation")] - public async Task> GetBLConfirmationAsync(long bsId, BusinessType bsType) + public async Task> GetBLConfirmationAsync(long businessId, BusinessType businessType) { - return await taskService.GetBLConfirmationAsync(bsId, bsType); + return await taskService.GetBLConfirmationAsync(businessId, businessType); } ///