|
|
@ -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);
|
|
|
|