打印下载直接预览显示

booking_auth_dev
wanghaomei 2 years ago
parent f672323be3
commit 7271d0a9e9

@ -4682,7 +4682,7 @@
<param name="input"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.Add(Myshipping.Application.AddBookingOrderInput)">
<member name="M:Myshipping.Application.BookingOrderService.Add(Myshipping.Application.BookingOrderDto)">
<summary>
增加订舱
</summary>
@ -4696,7 +4696,7 @@
<param name="Id"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.Update(Myshipping.Application.UpdateBookingOrderInput)">
<member name="M:Myshipping.Application.BookingOrderService.Update(Myshipping.Application.BookingOrderDto)">
<summary>
更新订舱
</summary>
@ -4832,6 +4832,21 @@
<param name="fileName">文件名</param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.PrintWithView(System.Int64,System.String)">
<summary>
打印(可浏览器预览)
</summary>
<param name="bookingId">订舱Id</param>
<param name="typeCode">打印类型代码对应字典booking_template_type</param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.ViewPrintPdf(System.String)">
<summary>
下载打印文件(PDF直接预览)
</summary>
<param name="vid">查看ID</param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.SendXHZ(System.Int64)">
<summary>
发送下货纸

@ -85,6 +85,7 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<SysTenant> _repTenant;
private readonly SqlSugarRepository<BookingStatus> _repBookingStatus;
private readonly SqlSugarRepository<BookingEDIExt> _bookingEDIExt;
private readonly IHttpContextAccessor _httpContextAccessor;
const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING";
const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT";
@ -96,7 +97,8 @@ namespace Myshipping.Application
ILogger<BookingOrderService> logger, ISysCacheService cache,
SqlSugarRepository<BookingPrintTemplate> repPrintTemplate, SqlSugarRepository<BookingLetteryard> repLetterYard, SqlSugarRepository<SysUser> repUser,
SqlSugarRepository<BookingOrderUrl> repOrderUrl, SqlSugarRepository<BookingOrderContact> repOrderContact, SqlSugarRepository<BookingSampleBill> repSampleBill,
SqlSugarRepository<DjyUserMailAccount> repUserMail, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<BookingStatus> repBookingStatus, SqlSugarRepository<BookingEDIExt> bookingEDIExt)
SqlSugarRepository<DjyUserMailAccount> repUserMail, SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<BookingStatus> repBookingStatus, SqlSugarRepository<BookingEDIExt> bookingEDIExt,
IHttpContextAccessor httpContextAccessor)
{
this._logger = logger;
this._rep = rep;
@ -122,6 +124,7 @@ namespace Myshipping.Application
this._repTenant = repTenant;
this._repBookingStatus = repBookingStatus;
this._bookingEDIExt = bookingEDIExt;
_httpContextAccessor = httpContextAccessor;
}
#region 主表和箱信息
@ -1180,6 +1183,8 @@ namespace Myshipping.Application
reportUrl += "/";
}
reportUrl = "http://127.0.0.1:8101/"; //test
//订舱数据
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
if (order == null)
@ -1233,6 +1238,7 @@ namespace Myshipping.Application
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
}
}
#endregion
#region 打印
@ -1270,6 +1276,50 @@ namespace Myshipping.Application
var result = new FileStreamResult(new FileStream(Path.Combine(fileFullPath, fileName), FileMode.Open), "application/octet-stream") { FileDownloadName = fileName };
return result;
}
/// <summary>
/// 打印(可浏览器预览)
/// </summary>
/// <param name="bookingId">订舱Id</param>
/// <param name="typeCode">打印类型代码对应字典booking_template_type</param>
/// <returns></returns>
[HttpGet("/BookingOrder/PrintWithView")]
public async Task<string> PrintWithView(long bookingId, string typeCode)
{
var bs = await GetReportFile(bookingId, typeCode);
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}.pdf", Encoding.GetEncoding("UTF-8"));//名称
var opt = App.GetOptions<TempFileOptions>().Path;
var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
if (!Directory.Exists(serverpath))
{
Directory.CreateDirectory(serverpath);
}
var fullPath = Path.Combine(serverpath, fileName);
await File.WriteAllBytesAsync(fullPath, bs);
var vid = Guid.NewGuid().ToString().Replace("-", "");
await _cache.SetTimeoutAsync(vid, fullPath, TimeSpan.FromSeconds(300));
return vid;
}
/// <summary>
/// 下载打印文件(PDF直接预览)
/// </summary>
/// <param name="vid">查看ID</param>
/// <returns></returns>
[HttpGet("/BookingOrder/ViewPrintPdf/{vid}"), AllowAnonymous]
public void ViewPrintPdf(string vid)
{
if (_cache.Exists(vid))
{
var fileFullName = _cache.Get(vid);
var readMem = new ReadOnlyMemory<byte>(File.ReadAllBytes(fileFullName));
_httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(readMem);
}
else
{
throw Oops.Bah("下载链接失效,请重新打印");
}
}
#endregion
#region 下货纸

Loading…
Cancel
Save