订舱打印模板

打印模板测试
booking_auth_dev
wanghaomei 2 years ago
parent 346e49b301
commit b8e62b295a

@ -3180,6 +3180,19 @@
<param name="MBLNO"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Application.BookingOrderService.GenReportJson(System.Int64)">
<summary>
获取用户报表的json
</summary>
<param name="id"></param>
</member>
<member name="M:Myshipping.Application.BookingOrderService.GenReportJson(System.Int64,System.String)">
<summary>
生成报表文件
</summary>
<param name="id"></param>
<returns></returns>
</member>
<member name="P:Myshipping.Application.Service.BookingOrder.Dto.BookingLogDto.Type">
<summary>
操作类型(新增,编辑)

@ -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}";
//}
}
}

@ -141,6 +141,7 @@ namespace Myshipping.Application
throw Oops.Oh(ErrorCode.BOOK112);
}
entity = input.Adapt(entity);
var dirAbs = string.Empty;
if (string.IsNullOrEmpty(opt.basePath))

@ -41,7 +41,7 @@ namespace Myshipping.Application
/// <summary>
/// 订舱打印模板修改输入参数
/// </summary>
public class UpdateBookingPrintTemplateInput
public class UpdateBookingPrintTemplateInput: BookingPrintTemplateInput
{
/// <summary>
/// 主键Id

@ -406,6 +406,14 @@ public enum ErrorCode
#region 订舱
/// <summary>
/// 订舱数据不存在
/// </summary>
[ErrorCodeItemMetadata("订舱数据不存在")]
BOOK001,
/// <summary>
/// 已存在同类型且名称相同的收发通模板
/// </summary>

@ -130,5 +130,24 @@ namespace Myshipping.Core
return null;
}
/// <summary>
/// 获取int值
/// </summary>
/// <param name="jobj"></param>
/// <param name="prop"></param>
/// <returns></returns>
public static bool GetBooleanValue(this JObject jobj, string prop)
{
var jt = jobj[prop];
if (jt == null)
{
return false;
}
var strVal = jt.ToString();
bool.TryParse(strVal, out bool rtnVal);
return rtnVal;
}
}
}

@ -3785,6 +3785,11 @@
表单不存在
</summary>
</member>
<member name="F:Myshipping.Core.ErrorCode.BOOK001">
<summary>
订舱数据不存在
</summary>
</member>
<member name="F:Myshipping.Core.ErrorCode.BOOK101">
<summary>
已存在同类型且名称相同的收发通模板
@ -4550,6 +4555,14 @@
<param name="prop"></param>
<returns></returns>
</member>
<member name="M:Myshipping.Core.JsonExtension.GetBooleanValue(Newtonsoft.Json.Linq.JObject,System.String)">
<summary>
获取int值
</summary>
<param name="jobj"></param>
<param name="prop"></param>
<returns></returns>
</member>
<member name="T:Myshipping.Core.PagedQueryableExtensions">
<summary>
分页拓展类

Loading…
Cancel
Save