|
|
|
@ -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<BookingOrder> _repOrder;
|
|
|
|
|
private readonly SqlSugarRepository<BookingExcelTemplate> _excelrep;
|
|
|
|
|
private readonly SqlSugarRepository<BookingExcelTemplateSub> _excelsubrep;
|
|
|
|
|
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrintTemplate;
|
|
|
|
|
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;
|
|
|
|
|
_excelsubrep = excelsubrep;
|
|
|
|
|
_repOrder = repOrder;
|
|
|
|
|
_rep = rep;
|
|
|
|
|
_logger = logger;
|
|
|
|
|
_repPrintTemplate = repPrintTemplate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -249,18 +252,42 @@ namespace Myshipping.Application
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <param name="excelTemplateId"></param>
|
|
|
|
|
/// <param name="printTemplateId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[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("请传入正确参数");
|
|
|
|
|
}
|
|
|
|
|
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<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 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))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(fileFullPath);
|
|
|
|
|