|
|
|
@ -368,7 +368,7 @@ namespace Myshipping.Application
|
|
|
|
|
var groupList = input.ctnInputs.Where(x => x.CTNNUM > 0).GroupBy(c => c.CTNALL).Select(g => $"{g.Key}*{g.Sum(gg => gg.CTNNUM)}");
|
|
|
|
|
input.CNTRTOTAL = string.Join(" / ", groupList);
|
|
|
|
|
}
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID&&x.ParentId==0).FirstAsync();
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.ParentId == 0).FirstAsync();
|
|
|
|
|
if (et != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -483,7 +483,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
var main = await _rep.AsQueryable().Where(x => x.Id == input.Id).FirstAsync();
|
|
|
|
|
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.Id != input.Id&& x.ParentId == 0).FirstAsync();
|
|
|
|
|
var et = await _rep.Where(x => x.MBLNO == input.MBLNO && x.TenantId == UserManager.TENANT_ID && x.Id != input.Id && x.ParentId == 0).FirstAsync();
|
|
|
|
|
if (et != null)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -933,7 +933,8 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation("调用运踪接口提单号:" + item.MBLNO + " 调用运踪接口");
|
|
|
|
|
if (item.isBook&&(string.IsNullOrWhiteSpace(item.CARRIERID)|| string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO))) {
|
|
|
|
|
if (item.isBook && (string.IsNullOrWhiteSpace(item.CARRIERID) || string.IsNullOrWhiteSpace(item.CARRIER) || string.IsNullOrWhiteSpace(item.MBLNO)))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("订阅目的港船公司或提单号不能为空!");
|
|
|
|
|
}
|
|
|
|
|
billTraceList.Add(new BillTraceList
|
|
|
|
@ -1372,7 +1373,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取放舱pdf
|
|
|
|
|
/// 获取放舱pdf(准备作废,后期使用打印相关接口)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
|
@ -1412,7 +1413,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取放舱excel
|
|
|
|
|
/// 获取放舱excel(准备作废,后期使用打印相关接口)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
@ -1431,7 +1432,7 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成报表文件
|
|
|
|
|
/// 生成报表文件(准备作废)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId"></param>
|
|
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
|
@ -1501,11 +1502,75 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成打印报表文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId">订舱ID</param>
|
|
|
|
|
/// <param name="printTemplate">打印模板</param>
|
|
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[NonAction]
|
|
|
|
|
private async Task<byte[]> GenPrintFile(long bookingId, BookingPrintTemplate printTemplate, int type = 1)
|
|
|
|
|
{
|
|
|
|
|
//打印报表服务地址
|
|
|
|
|
var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
|
|
if (!reportUrl.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
reportUrl += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//订舱数据
|
|
|
|
|
var order = _rep.FirstOrDefault(x => x.Id == bookingId);
|
|
|
|
|
if (order == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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($"查找模板文件:{fileAbsPath}");
|
|
|
|
|
if (!File.Exists(fileAbsPath))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"准备调用报表生成:id:{bookingId},文件:{printTemplate.FileName}");
|
|
|
|
|
var genUrl = $"{reportUrl}Report/BookingReport?bookingId={bookingId}&type={type}";
|
|
|
|
|
var rtn = await genUrl
|
|
|
|
|
.SetContentType("multipart/form-data")
|
|
|
|
|
.SetBodyBytes(("file", File.ReadAllBytes(fileAbsPath), HttpUtility.UrlEncode(printTemplate.FileName, Encoding.GetEncoding("UTF-8"))))
|
|
|
|
|
.PostAsStringAsync();
|
|
|
|
|
var jobjRtn = JObject.Parse(rtn);
|
|
|
|
|
_logger.LogInformation($"调用报表生成返回:{rtn}");
|
|
|
|
|
if (jobjRtn.GetBooleanValue("Success"))
|
|
|
|
|
{
|
|
|
|
|
//调用读取文件
|
|
|
|
|
var fn = jobjRtn.GetStringValue("Data");
|
|
|
|
|
_logger.LogInformation($"准备调用读取报表文件:id:{bookingId},文件名:{fn}");
|
|
|
|
|
var readFileUrl = $"{reportUrl}Report/GetFile?fileName={fn}";
|
|
|
|
|
var bs = await readFileUrl.GetAsByteArrayAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"调用读取报表文件返回:{bs.Length}");
|
|
|
|
|
|
|
|
|
|
return bs;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 打印
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印
|
|
|
|
|
/// 打印(准备作废,使用PrintOrder代替)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId">订舱Id</param>
|
|
|
|
|
/// <param name="typeCode">打印类型代码,对应字典booking_template_type</param>
|
|
|
|
@ -1589,16 +1654,40 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印(可浏览器预览)
|
|
|
|
|
/// 打印(返回文件名)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="bookingId">订舱Id</param>
|
|
|
|
|
/// <param name="typeCode">打印类型代码,对应字典booking_template_type</param>
|
|
|
|
|
/// <param name="templateId">打印模板ID</param>
|
|
|
|
|
/// <param name="type">类型,1:pdf、2:xlsx、3:docx</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingOrder/PrintWithView")]
|
|
|
|
|
public async Task<string> PrintWithView(long bookingId, string typeCode)
|
|
|
|
|
[HttpGet("/BookingOrder/PrintOrder")]
|
|
|
|
|
public async Task<string> PrintOrder(long bookingId, long templateId, int type = 1)
|
|
|
|
|
{
|
|
|
|
|
var bs = await GetReportFile(bookingId, typeCode);
|
|
|
|
|
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}.pdf", Encoding.GetEncoding("UTF-8"));//名称
|
|
|
|
|
var printTemplate = await _repPrintTemplate.AsQueryable().Filter(null, true).FirstAsync(x => x.Id == templateId);
|
|
|
|
|
if (printTemplate == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah(BookingErrorCode.BOOK115);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var bs = await GenPrintFile(bookingId, printTemplate, type);
|
|
|
|
|
var fileType = "";
|
|
|
|
|
if (type == 1)
|
|
|
|
|
{
|
|
|
|
|
fileType = ".pdf";
|
|
|
|
|
}
|
|
|
|
|
else if (type == 2)
|
|
|
|
|
{
|
|
|
|
|
fileType = ".xlsx";
|
|
|
|
|
}
|
|
|
|
|
else if (type == 3)
|
|
|
|
|
{
|
|
|
|
|
fileType = ".docx";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("类型参数不正确");
|
|
|
|
|
}
|
|
|
|
|
var fileName = HttpUtility.UrlEncode($"{bookingId}_{DateTime.Now.Ticks}{fileType}", Encoding.GetEncoding("UTF-8"));//名称
|
|
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
|
|
var serverpath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);//服务器路径
|
|
|
|
|
if (!Directory.Exists(serverpath))
|
|
|
|
@ -1607,33 +1696,73 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
//记录打印次数和时间,用于前端动态展示常用的打印类型
|
|
|
|
|
var printRecentListKey = $"{PrintRecentListTypeKey}_{printTemplate.CateCode}";
|
|
|
|
|
var usrCfg = _repUserConfig.AsQueryable().First(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey);
|
|
|
|
|
if (usrCfg == null)
|
|
|
|
|
{
|
|
|
|
|
usrCfg = new DjyUserConfig();
|
|
|
|
|
usrCfg.Type = printRecentListKey;
|
|
|
|
|
usrCfg.ConfigJson = (new long[] { templateId }).ToJson();
|
|
|
|
|
await _repUserConfig.InsertAsync(usrCfg);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).Where(x => x != templateId).ToList();
|
|
|
|
|
arr.Insert(0, templateId);
|
|
|
|
|
usrCfg.ConfigJson = arr.ToArray().ToJson();
|
|
|
|
|
await _repUserConfig.UpdateAsync(usrCfg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fileName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
///// <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("下载链接失效,请重新打印");
|
|
|
|
|
// }
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下载打印文件(PDF直接预览)
|
|
|
|
|
/// 预览模板生成的pdf文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="vid">查看ID</param>
|
|
|
|
|
/// <param name="fn">文件名称</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingOrder/ViewPrintPdf/{vid}"), AllowAnonymous]
|
|
|
|
|
public void ViewPrintPdf(string vid)
|
|
|
|
|
[HttpGet("/BookingOrder/ViewPrintPdf/{fn}"), AllowAnonymous]
|
|
|
|
|
public void ViewPrintPdf(string fn)
|
|
|
|
|
{
|
|
|
|
|
if (_cache.Exists(vid))
|
|
|
|
|
var opt = App.GetOptions<TempFileOptions>().Path;
|
|
|
|
|
var fileFullPath = Path.Combine(App.WebHostEnvironment.WebRootPath, opt);
|
|
|
|
|
var fileFullName = Path.Combine(fileFullPath, fn);
|
|
|
|
|
if (File.Exists(fileFullName))
|
|
|
|
|
{
|
|
|
|
|
var fileFullName = _cache.Get(vid);
|
|
|
|
|
var readMem = new ReadOnlyMemory<byte>(File.ReadAllBytes(fileFullName));
|
|
|
|
|
_httpContextAccessor.HttpContext.Response.BodyWriter.WriteAsync(readMem);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah("下载链接失效,请重新打印");
|
|
|
|
|
_httpContextAccessor.HttpContext.Response.StatusCode = 404;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取订舱打印模板列表(带有当前用户打印历史排序)
|
|
|
|
|
/// 获取订舱打印模板列表(带有当前用户打印历史排序)(准备作废,使用PrintTemplateWithHistoryList代替)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingOrder/PrintTemplateList")]
|
|
|
|
@ -1682,6 +1811,59 @@ namespace Myshipping.Application
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取订舱打印模板列表(带有当前用户打印历史排序)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="cateCode">分类代码(使用字典【booking_template_category】中的代码)</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingOrder/PrintTemplateWithHistoryList")]
|
|
|
|
|
public async Task<dynamic> PrintTemplateWithHistoryList(string cateCode)
|
|
|
|
|
{
|
|
|
|
|
//当前公司所有已配置的模板
|
|
|
|
|
var allList = await _repPrintTemplate.AsQueryable()
|
|
|
|
|
.Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId)
|
|
|
|
|
.Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode == cateCode)
|
|
|
|
|
.Select(d => new
|
|
|
|
|
{
|
|
|
|
|
d.Id,
|
|
|
|
|
d.CateCode,
|
|
|
|
|
d.CateName,
|
|
|
|
|
d.DisplayName
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
var listReult = new List<dynamic>();
|
|
|
|
|
//当前用户打印历史数据
|
|
|
|
|
var printRecentListKey = $"{PrintRecentListTypeKey}_{cateCode}";
|
|
|
|
|
var usrCfg = await _repUserConfig.AsQueryable().FirstAsync(x => x.CreatedUserId == UserManager.UserId && x.Type == printRecentListKey);
|
|
|
|
|
if (usrCfg != null)
|
|
|
|
|
{
|
|
|
|
|
var arr = JArray.Parse(usrCfg.ConfigJson).Select(x => Convert.ToInt64(x)).ToList();
|
|
|
|
|
|
|
|
|
|
//按顺序加入到结果
|
|
|
|
|
arr.ForEach(x =>
|
|
|
|
|
{
|
|
|
|
|
var find = allList.FirstOrDefault(y => y.Id == x);
|
|
|
|
|
if (find != null)
|
|
|
|
|
{
|
|
|
|
|
listReult.Add(find);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var listOut = allList.Where(x => !arr.Contains(x.Id)).ToList();
|
|
|
|
|
listReult.AddRange(listOut);
|
|
|
|
|
|
|
|
|
|
return listReult;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return allList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 下货纸
|
|
|
|
|