|
|
|
@ -31,6 +31,9 @@ using Furion.RemoteRequest.Extensions;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using Myshipping.Core.Service;
|
|
|
|
|
using Myshipping.Application.EDI;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Web;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
|
|
|
|
namespace Myshipping.Application
|
|
|
|
|
{
|
|
|
|
@ -49,14 +52,15 @@ namespace Myshipping.Application
|
|
|
|
|
private readonly SqlSugarRepository<BookingFile> _bookingfile;
|
|
|
|
|
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _webconfig;
|
|
|
|
|
private readonly SqlSugarRepository<SysDictData> _dicdata;
|
|
|
|
|
private readonly SqlSugarRepository<BookingPrintTemplate> _repPrint;
|
|
|
|
|
private readonly ILogger<BookingOrderService> _logger;
|
|
|
|
|
private readonly ISysCacheService _cache;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
|
|
|
|
|
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
|
|
|
|
|
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyWebsiteAccountConfig> webconfig, SqlSugarRepository<SysDictData> dicdata,
|
|
|
|
|
ILogger<BookingOrderService> logger, ISysCacheService cache)
|
|
|
|
|
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyWebsiteAccountConfig> webconfig, SqlSugarRepository<BookingPrintTemplate> repPrint,
|
|
|
|
|
SqlSugarRepository<SysDictData> dicdata, ILogger<BookingOrderService> logger, ISysCacheService cache)
|
|
|
|
|
{
|
|
|
|
|
this._logger = logger;
|
|
|
|
|
this._rep = rep;
|
|
|
|
@ -67,6 +71,7 @@ namespace Myshipping.Application
|
|
|
|
|
this._bookingremark = bookingremark;
|
|
|
|
|
this._bookingfile = bookingfile;
|
|
|
|
|
this._webconfig = webconfig;
|
|
|
|
|
this._repPrint = repPrint;
|
|
|
|
|
this._dicdata = dicdata;
|
|
|
|
|
this._cache = cache;
|
|
|
|
|
}
|
|
|
|
@ -537,19 +542,113 @@ namespace Myshipping.Application
|
|
|
|
|
billdto.Children = billTraceList;
|
|
|
|
|
billdto.Key = key.Account;
|
|
|
|
|
billdto.PWD = key.Password;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var json = billdto.ToJsonString();
|
|
|
|
|
var html = await url.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "seae_billtraceurl").Value.SetHttpMethod(HttpMethod.Post).SetQueries(new { msg = json }).SetRetryPolicy(3, 5000).SendAsAsync<RespCommon>();
|
|
|
|
|
_logger.LogInformation("提单号:" + MBLNO + " 调用运踪接口返回" + html.ToJsonString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取用户报表的json
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
[HttpGet("/BookingOrder/reportJson")]
|
|
|
|
|
public async Task<IActionResult> GenReportJson(long id)
|
|
|
|
|
{
|
|
|
|
|
var jsonUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == "url_report_generate").Value;
|
|
|
|
|
if (!jsonUrl.EndsWith("/"))
|
|
|
|
|
{
|
|
|
|
|
jsonUrl += "/";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
jsonUrl += "Report/BookingReportJson?bookingId=" + id;
|
|
|
|
|
|
|
|
|
|
var rtn = await jsonUrl.SetHttpMethod(HttpMethod.Get).GetAsStringAsync();
|
|
|
|
|
var fileName = HttpUtility.UrlEncode($"{id}.json", Encoding.GetEncoding("UTF-8"));
|
|
|
|
|
var result = new FileContentResult(Encoding.UTF8.GetBytes(rtn), "application/octet-stream") { FileDownloadName = fileName };
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/BookingPrintTemplate/test")]
|
|
|
|
|
public async Task<string> Test(long id)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 生成报表文件
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="type">类型,对应字典中的【订舱打印模板类型】</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpGet("/BookingOrder/reportFile")]
|
|
|
|
|
public async Task<IActionResult> GenReportJson(long id, string type)
|
|
|
|
|
{
|
|
|
|
|
var rtn = XiahuozhiHelpler.Send(id, "9", out string msg);
|
|
|
|
|
return $"{rtn} {msg}";
|
|
|
|
|
//打印报表服务地址
|
|
|
|
|
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 == id);
|
|
|
|
|
if (order == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh(ErrorCode.BOOK001);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//打印模板
|
|
|
|
|
var printTemplate = _repPrint.FirstOrDefault(x => x.TenantId == order.TenantId && x.TypeCode == type);
|
|
|
|
|
if (printTemplate == null)
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh(ErrorCode.BOOK112);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取配置路劲
|
|
|
|
|
var opt = App.GetOptions<PrintTemplateOptions>();
|
|
|
|
|
var dirAbs = opt.basePath;
|
|
|
|
|
if (string.IsNullOrEmpty(dirAbs))
|
|
|
|
|
{
|
|
|
|
|
dirAbs = App.WebHostEnvironment.WebRootPath;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//读取模板并调用接口
|
|
|
|
|
var fileAbsPath = Path.Combine(dirAbs, printTemplate.FilePath).ToLower();
|
|
|
|
|
if (!File.Exists(fileAbsPath))
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Oh(ErrorCode.BOOK112);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"准备调用报表生成:id:{id},文件:{printTemplate.FileName}");
|
|
|
|
|
var genUrl = reportUrl + "Report/BookingReport?bookingId=" + id;
|
|
|
|
|
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:{id},文件名:{fn}");
|
|
|
|
|
var readFileUrl = reportUrl + "Report/GetFile?fileName=" + fn;
|
|
|
|
|
var bs = await readFileUrl.GetAsByteArrayAsync();
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"调用读取文件返回:{bs.Length}");
|
|
|
|
|
|
|
|
|
|
var fileName = HttpUtility.UrlEncode($"{id}_{type}_{DateTime.Now.Ticks}.pdf", Encoding.GetEncoding("UTF-8"));
|
|
|
|
|
var result = new FileContentResult(bs, "application/octet-stream") { FileDownloadName = fileName };
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw Oops.Bah($"生成报表文件失败:{jobjRtn.GetStringValue("Message")}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[HttpGet("/BookingPrintTemplate/test")]
|
|
|
|
|
//public async Task<string> Test(long id)
|
|
|
|
|
//{
|
|
|
|
|
// var rtn = XiahuozhiHelpler.Send(id, "9", out string msg);
|
|
|
|
|
// return $"{rtn} {msg}";
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|