optimize
wet 2 years ago
parent edfbce4e7b
commit 1086342c91

@ -22,5 +22,10 @@ namespace Myshipping.Application.Entity
/// </summary> /// </summary>
public string Type { get; set; } public string Type { get; set; }
/// <summary>
/// 模板id
/// </summary>
public string TemplateId { get; set; }
} }
} }

@ -9750,12 +9750,13 @@
<param name="Id">模板名称</param> <param name="Id">模板名称</param>
<returns></returns> <returns></returns>
</member> </member>
<member name="M:Myshipping.Application.BookingTemplateService.ExportExcel(System.Int64,System.Int64)"> <member name="M:Myshipping.Application.BookingTemplateService.ExportExcel(System.Int64,System.Int64,System.Int64)">
<summary> <summary>
导出excel 导出excel
</summary> </summary>
<param name="bookingId"></param> <param name="bookingId"></param>
<param name="excelTemplateId"></param> <param name="excelTemplateId"></param>
<param name="printTemplateId"></param>
<returns></returns> <returns></returns>
</member> </member>
<member name="T:Myshipping.Application.BookingTemplateInput"> <member name="T:Myshipping.Application.BookingTemplateInput">

@ -22,6 +22,7 @@ using Furion;
using System; using System;
using System.Web; using System.Web;
using System.Text; using System.Text;
using Myshipping.Application.ConfigOption;
namespace Myshipping.Application namespace Myshipping.Application
{ {
@ -35,15 +36,17 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingOrder> _repOrder; private readonly SqlSugarRepository<BookingOrder> _repOrder;
private readonly SqlSugarRepository<BookingExcelTemplate> _excelrep; private readonly SqlSugarRepository<BookingExcelTemplate> _excelrep;
private readonly SqlSugarRepository<BookingExcelTemplateSub> _excelsubrep; private readonly SqlSugarRepository<BookingExcelTemplateSub> _excelsubrep;
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrintTemplate;
private readonly ILogger<BookingTemplate> _logger; private readonly ILogger<BookingTemplate> _logger;
public BookingTemplateService(SqlSugarRepository<BookingTemplate> rep, SqlSugarRepository<BookingOrder> repOrder, SqlSugarRepository<BookingExcelTemplate> excelrep, SqlSugarRepository<BookingExcelTemplateSub> excelsubrep, ILogger<BookingTemplate> logger) public BookingTemplateService(SqlSugarRepository<BookingTemplate> rep, SqlSugarRepository<BookingOrder> repOrder, SqlSugarRepository<BookingExcelTemplate> excelrep, SqlSugarRepository<BookingExcelTemplateSub> excelsubrep, SqlSugarRepository<BookingPrintTemplate> repPrintTemplate, ILogger<BookingTemplate> logger)
{ {
_excelrep = excelrep; _excelrep = excelrep;
_excelsubrep = excelsubrep; _excelsubrep = excelsubrep;
_repOrder = repOrder; _repOrder = repOrder;
_rep = rep; _rep = rep;
_logger = logger; _logger = logger;
_repPrintTemplate = repPrintTemplate;
} }
/// <summary> /// <summary>
@ -249,18 +252,42 @@ namespace Myshipping.Application
/// </summary> /// </summary>
/// <param name="bookingId"></param> /// <param name="bookingId"></param>
/// <param name="excelTemplateId"></param> /// <param name="excelTemplateId"></param>
/// <param name="printTemplateId"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("/BookingTemplate/ExportExcel")] [HttpGet("/BookingTemplate/ExportExcel")]
public async Task<dynamic> ExportExcel([FromQuery] long bookingId, long excelTemplateId) public async Task<dynamic> ExportExcel([FromQuery] long bookingId, long excelTemplateId,long printTemplateId)
{ {
if (bookingId == 0 || excelTemplateId == 0) if (bookingId == 0 || excelTemplateId == 0|| printTemplateId==0)
{ {
throw Oops.Bah("请传入正确参数"); throw Oops.Bah("请传入正确参数");
} }
var excelwork = new HSSFWorkbook(); var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id== printTemplateId);
var sheet = excelwork.CreateSheet("订舱台账"); if (printTemplate == null)
sheet.ForceFormulaRecalculation = true; {
throw Oops.Bah(BookingErrorCode.BOOK115);
}
var opt = App.GetOptions<PrintTemplateOptions>();
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 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(); 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<TempFileOptions>().Path;
var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径 var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, App.GetOptions<TempFileOptions>().Path);//服务器路径
if (!Directory.Exists(fileFullPath)) if (!Directory.Exists(fileFullPath))
{ {
Directory.CreateDirectory(fileFullPath); Directory.CreateDirectory(fileFullPath);

@ -16981,9 +16981,14 @@
预抵日期 预抵日期
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfo.Wharf"> <member name="P:Myshipping.Application.Entity.DjyVesselInfo.Yard">
<summary> <summary>
默认码头 场站
</summary>
</member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfo.YardCode">
<summary>
场站Code
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfo.ATD"> <member name="P:Myshipping.Application.Entity.DjyVesselInfo.ATD">
@ -17061,9 +17066,14 @@
预抵日期 预抵日期
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfoDto.Wharf"> <member name="P:Myshipping.Application.Entity.DjyVesselInfoDto.Yard">
<summary>
场站
</summary>
</member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfoDto.YardCode">
<summary> <summary>
默认码头 场站Code
</summary> </summary>
</member> </member>
<member name="P:Myshipping.Application.Entity.DjyVesselInfoDto.ATD"> <member name="P:Myshipping.Application.Entity.DjyVesselInfoDto.ATD">

Loading…
Cancel
Save