diff --git a/Myshipping.Application/Entity/BookingExcelTemplate.cs b/Myshipping.Application/Entity/BookingExcelTemplate.cs
index 153e1d7a..e934ee4e 100644
--- a/Myshipping.Application/Entity/BookingExcelTemplate.cs
+++ b/Myshipping.Application/Entity/BookingExcelTemplate.cs
@@ -21,6 +21,11 @@ namespace Myshipping.Application.Entity
/// 分类
///
public string Type { get; set; }
-
+
+ ///
+ /// 模板id
+ ///
+ public string TemplateId { get; set; }
+
}
}
\ No newline at end of file
diff --git a/Myshipping.Application/Myshipping.Application.xml b/Myshipping.Application/Myshipping.Application.xml
index b8f98792..a1501c96 100644
--- a/Myshipping.Application/Myshipping.Application.xml
+++ b/Myshipping.Application/Myshipping.Application.xml
@@ -9750,12 +9750,13 @@
模板名称
-
+
导出excel
+
diff --git a/Myshipping.Application/Service/BookingTemplate/BookingTemplateService.cs b/Myshipping.Application/Service/BookingTemplate/BookingTemplateService.cs
index 4d9e54d0..a01517f3 100644
--- a/Myshipping.Application/Service/BookingTemplate/BookingTemplateService.cs
+++ b/Myshipping.Application/Service/BookingTemplate/BookingTemplateService.cs
@@ -22,6 +22,7 @@ using Furion;
using System;
using System.Web;
using System.Text;
+using Myshipping.Application.ConfigOption;
namespace Myshipping.Application
{
@@ -35,15 +36,17 @@ namespace Myshipping.Application
private readonly SqlSugarRepository _repOrder;
private readonly SqlSugarRepository _excelrep;
private readonly SqlSugarRepository _excelsubrep;
+ private readonly SqlSugarRepository _repPrintTemplate;
private readonly ILogger _logger;
- public BookingTemplateService(SqlSugarRepository rep, SqlSugarRepository repOrder, SqlSugarRepository excelrep, SqlSugarRepository excelsubrep, ILogger logger)
+ public BookingTemplateService(SqlSugarRepository rep, SqlSugarRepository repOrder, SqlSugarRepository excelrep, SqlSugarRepository excelsubrep, SqlSugarRepository repPrintTemplate, ILogger logger)
{
_excelrep = excelrep;
_excelsubrep = excelsubrep;
_repOrder = repOrder;
_rep = rep;
_logger = logger;
+ _repPrintTemplate = repPrintTemplate;
}
///
@@ -249,18 +252,42 @@ namespace Myshipping.Application
///
///
///
+ ///
///
[HttpGet("/BookingTemplate/ExportExcel")]
- public async Task ExportExcel([FromQuery] long bookingId, long excelTemplateId)
+ public async Task ExportExcel([FromQuery] long bookingId, long excelTemplateId,long printTemplateId)
{
- if (bookingId == 0 || excelTemplateId == 0)
+ if (bookingId == 0 || excelTemplateId == 0|| printTemplateId==0)
{
throw Oops.Bah("请传入正确参数");
}
- var excelwork = new HSSFWorkbook();
- var sheet = excelwork.CreateSheet("订舱台账");
- sheet.ForceFormulaRecalculation = true;
+ var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id== printTemplateId);
+ if (printTemplate == null)
+ {
+ throw Oops.Bah(BookingErrorCode.BOOK115);
+ }
+ var opt = App.GetOptions();
+ var dirAbs = opt.basePath;
+ if (string.IsNullOrEmpty(dirAbs))
+ {
+ dirAbs = App.WebHostEnvironment.WebRootPath;
+ }
+
+ var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath);
+ _logger.LogInformation($"查找EXCEL模板文件:{fileAbsPath}");
+ if (!File.Exists(fileAbsPath))
+ {
+ throw Oops.Bah(BookingErrorCode.BOOK115);
+ }
+
+ _logger.LogInformation($"准备调用EXCEL生成:id:{bookingId},文件:{printTemplate.FileName}");
+
+ var result = new FileStream(fileAbsPath, FileMode.Open) ;
+
+ var excelwork = new HSSFWorkbook(result);
+ var sheet = excelwork.GetSheetAt(0);
+
var order = await _repOrder.AsQueryable().Where(x => x.Id == bookingId).FirstAsync();
var entity = await _excelsubrep.AsQueryable().Where(x => x.Pid == excelTemplateId).OrderBy(x => x.Row).ToListAsync();
//单元格样式
@@ -291,8 +318,8 @@ namespace Myshipping.Application
}
}
}
- var opt = App.GetOptions().Path;
- var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
+
+ var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, App.GetOptions().Path);//服务器路径
if (!Directory.Exists(fileFullPath))
{
Directory.CreateDirectory(fileFullPath);
diff --git a/Myshipping.Core/Myshipping.Core.xml b/Myshipping.Core/Myshipping.Core.xml
index a55833fe..cf417a5f 100644
--- a/Myshipping.Core/Myshipping.Core.xml
+++ b/Myshipping.Core/Myshipping.Core.xml
@@ -16981,9 +16981,14 @@
预抵日期
-
+
- 默认码头
+ 场站
+
+
+
+
+ 场站Code
@@ -17061,9 +17066,14 @@
预抵日期
-
+
+
+ 场站
+
+
+
- 默认码头
+ 场站Code