修改ONE 下载EDI自动生成订舱附件功能

optimize
jianghaiqing 2 years ago
parent 6ef8bc3b7c
commit 1945aff9b9

@ -1,4 +1,5 @@
using Furion; using Furion;
using Furion.FriendlyException;
using Furion.Logging; using Furion.Logging;
using Furion.RemoteRequest.Extensions; using Furion.RemoteRequest.Extensions;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -192,5 +193,94 @@ namespace Myshipping.Application
return fileFullName; return fileFullName;
} }
#endregion #endregion
#region 保存文件并返回文件完整路径
/// <summary>
/// 保存文件并返回文件完整路径
/// </summary>
/// <param name="fileDictKey">文件目录KEY</param>
/// <param name="fileBytes">文件二进制流</param>
/// <param name="batchNo">批次号</param>
/// <param name="fileNameNoSuffix">文件名称不带后缀名</param>
/// <param name="printFileType">文件类型</param>
/// <param name="attachFileType">附件类型 bcfiles-BC文件 sofile-订舱附件</param>
/// <param name="isUseTimeDocName">是否生成日期文件名</param>
/// <returns>返回文件完整路径</returns>
public static async Task<string> SaveFile(string fileDictKey, byte[] fileBytes, string batchNo, string fileNameNoSuffix,
PrintFileTypeEnum printFileType, string attachFileType = "sofiles", bool isUseTimeDocName = false)
{
var logger = Log.CreateLogger(nameof(FileAttachHelper));
var fileCfg = App.GetOptions<BookingAttachOptions>();
string fileRoot = string.Empty;
if (fileCfg != null)
{
if (!string.IsNullOrWhiteSpace(fileCfg.basePath))
{
fileRoot = fileCfg.basePath;
}
}
if (string.IsNullOrWhiteSpace(fileRoot))
fileRoot = App.WebHostEnvironment.WebRootPath;
string relativePath = fileCfg.relativePath;
if (!string.IsNullOrWhiteSpace(attachFileType))
relativePath += $"\\{attachFileType}";
if (!string.IsNullOrWhiteSpace(fileDictKey))
relativePath += $"\\{fileDictKey}";
relativePath += $"\\{DateTime.Now.ToString("yyyyMMddHHmmssfff")}";
string filePath = $"{fileRoot}\\{relativePath}";
var fileType = string.Empty;
if (printFileType == PrintFileTypeEnum.PDF)
{
fileType = ".pdf";
}
else if (printFileType == PrintFileTypeEnum.XLSX)
{
fileType = ".xlsx";
}
else if (printFileType == PrintFileTypeEnum.DOCX)
{
fileType = ".docx";
}
string curFileName = fileNameNoSuffix;
if (isUseTimeDocName)
{
curFileName = DateTime.Now.ToString("yyyyMMddHHmmssfff");
}
string fileFullName = $"{filePath}\\{curFileName}{fileType}";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
relativePath = relativePath.Replace("\\", "/");
filePath = filePath.Replace("\\", "/");
fileFullName = fileFullName.Replace("\\", "/");
}
logger.LogInformation("批次={no} 生成文件保存路径完成 路由={filePath} 服务器系统={system}", batchNo, filePath,
RuntimeInformation.OSDescription);
//预先创建目录
if (!Directory.Exists(filePath))
{
Directory.CreateDirectory(filePath);
}
await File.WriteAllBytesAsync(fileFullName, fileBytes);
return fileFullName;
}
#endregion
} }
} }

@ -129,6 +129,8 @@ namespace Myshipping.Application
const string CONST_TSL_EDI_URL = "tsl_edi_declare_url"; const string CONST_TSL_EDI_URL = "tsl_edi_declare_url";
const string CONST_TSL_TYPE_CODE = "TslWeb"; const string CONST_TSL_TYPE_CODE = "TslWeb";
const string CONST_ONE_SOFILE_CATE_CODE = "one_so_file_template";
const string PRINT_DATASOURCE_KEY = "booking_order";
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep, public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark, SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
@ -6250,11 +6252,80 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// 打印船公司ONE的订舱附件生成后自动写入订舱附件 /// 打印船公司ONE的订舱附件生成后自动写入订舱附件
/// </summary> /// </summary>
/// <param name="bookingId">订舱ID</param> /// <param name="model">订舱详情</param>
/// <returns></returns> /// <returns></returns>
private async Task PrintCarrierOneSOFileAsync(long bookingId) private async Task PrintCarrierOneSOFileAsync(BookingOrder model)
{ {
string batchNo = IDGen.NextID().ToString();
/*
1ONE
2
3
*/
try
{
var printTemplate = 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.Equals(CONST_ONE_SOFILE_CATE_CODE)
&& d.Type == BookingPrintTemplateType.FastReport.ToString())
.FirstAsync();
//取到打印模板文件
if(printTemplate == null)
{
_logger.LogInformation("打印船公司ONE的订舱附件 batchNo={batchno} 获取模板文件失败", batchNo);
throw Oops.Bah("获取模板文件失败");
}
_logger.LogInformation("打印船公司ONE的订舱附件 batchNo={batchno} 获取模板文件成功", batchNo);
//打印报表服务地址
var reportUrl = _cache.GetAllDictData().Result.FirstOrDefault(x => x.TypeCode == "url_set" &&
x.Code == "url_report_generate").Value;
if(string.IsNullOrWhiteSpace(reportUrl))
{
_logger.LogInformation("打印船公司ONE的订舱附件 batchNo={batchno} 获取打印报表服务地址失败", batchNo);
throw Oops.Bah("获取打印报表服务地址失败");
}
if (!reportUrl.EndsWith("/"))
{
reportUrl += "/";
}
//调取生成打印二进制流
var bs = await PrintHelper.GeneratePrintFile(JSON.Serialize(model), reportUrl,
PRINT_DATASOURCE_KEY, PrintFileTypeEnum.PDF, printTemplate);
//保存文件
var bookFilePath = await FileAttachHelper.SaveFile(model.Id.ToString(), bs, batchNo, "",
PrintFileTypeEnum.PDF, "sofile", true);
_logger.LogInformation("打印船公司ONE的订舱附件 批次={no} id={id} 完成文件保存 {filepath}", batchNo
, model.Id, bookFilePath);
//写入订舱随附单据
string fileTypeCode = "sofile";
string fileTypeName = "订舱附件";
//将BC引入的文件写入订舱的附件
await SaveEDIFile(model.Id, bookFilePath, new System.IO.FileInfo(bookFilePath).Name,
fileTypeCode, fileTypeName);
_logger.LogInformation("打印船公司ONE的订舱附件 批次={no} id={id} 完成写入附件表 {filepath}", batchNo
, model.Id, bookFilePath);
}
catch (Exception ex)
{
_logger.LogInformation("打印船公司ONE的订舱附件失败 batchNo={batchno} 原因={reason}", batchNo,ex.GetMessage());
}
} }
#endregion #endregion
} }

@ -52,7 +52,7 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingTruckCtn> _bookingTruckContaRepository; private readonly SqlSugarRepository<BookingTruckCtn> _bookingTruckContaRepository;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository; private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
private readonly SqlSugarRepository<BookingCtn> _bookingCtnRepository; private readonly SqlSugarRepository<BookingCtn> _bookingCtnRepository;
private readonly SqlSugarRepository<BookingPrintTemplate> _bookingPrintTemplateTemplate; private readonly SqlSugarRepository<BookingPrintTemplate> _bookingPrintTemplateRepository;
private readonly SqlSugarRepository<DjyUserConfig> _djyUserConfigConfig; private readonly SqlSugarRepository<DjyUserConfig> _djyUserConfigConfig;
private readonly SqlSugarRepository<BookingExcelTemplate> _bookingExcelTemplateRepository; private readonly SqlSugarRepository<BookingExcelTemplate> _bookingExcelTemplateRepository;
private readonly SqlSugarRepository<SysUser> _sysUserRepository; private readonly SqlSugarRepository<SysUser> _sysUserRepository;
@ -87,7 +87,7 @@ namespace Myshipping.Application
_bookingCtnRepository = bookingCtnRepository; _bookingCtnRepository = bookingCtnRepository;
_taskManageExternalService = taskManageExternalService; _taskManageExternalService = taskManageExternalService;
_bookingPrintTemplateTemplate = bookingPrintTemplateTemplate; _bookingPrintTemplateRepository = bookingPrintTemplateTemplate;
_djyUserConfigConfig = djyUserConfigConfig; _djyUserConfigConfig = djyUserConfigConfig;
_bookingExcelTemplateRepository = bookingExcelTemplateRepository; _bookingExcelTemplateRepository = bookingExcelTemplateRepository;
_sysUserRepository = sysUserRepository; _sysUserRepository = sysUserRepository;
@ -1241,7 +1241,7 @@ namespace Myshipping.Application
{ {
var typeCode = printType.ToString(); var typeCode = printType.ToString();
//当前公司所有已配置的模板 //当前公司所有已配置的模板
var allList = await _bookingPrintTemplateTemplate.AsQueryable() var allList = await _bookingPrintTemplateRepository.AsQueryable()
.Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId) .Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId)
.Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode.Contains(cateCode) && d.Type == typeCode) .Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode.Contains(cateCode) && d.Type == typeCode)
.Select(d => new .Select(d => new
@ -1297,7 +1297,7 @@ namespace Myshipping.Application
public async Task<string> Print([FromQuery] long id, [FromQuery] long templateId, [FromQuery] string cateCode, [FromQuery] PrintFileTypeEnum printFileType = PrintFileTypeEnum.PDF, public async Task<string> Print([FromQuery] long id, [FromQuery] long templateId, [FromQuery] string cateCode, [FromQuery] PrintFileTypeEnum printFileType = PrintFileTypeEnum.PDF,
[FromQuery] BookingPrintTemplateType printType = BookingPrintTemplateType.FastReport) [FromQuery] BookingPrintTemplateType printType = BookingPrintTemplateType.FastReport)
{ {
var printTemplate = await _bookingPrintTemplateTemplate.AsQueryable().Filter(null, true) var printTemplate = await _bookingPrintTemplateRepository.AsQueryable().Filter(null, true)
.FirstAsync(x => x.Id == templateId); .FirstAsync(x => x.Id == templateId);
if (printTemplate == null) if (printTemplate == null)

@ -38,7 +38,7 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<TaskTruckInfo> _taskTruckRepository; private readonly SqlSugarRepository<TaskTruckInfo> _taskTruckRepository;
private readonly SqlSugarRepository<TaskTruckCtn> _taskTruckContaRepository; private readonly SqlSugarRepository<TaskTruckCtn> _taskTruckContaRepository;
private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository; private readonly SqlSugarRepository<TaskBaseInfo> _taskBaseRepository;
private readonly SqlSugarRepository<BookingPrintTemplate> _bookingPrintTemplateTemplate; private readonly SqlSugarRepository<BookingPrintTemplate> _bookingPrintTemplateRepository;
private readonly SqlSugarRepository<DjyUserConfig> _djyUserConfigConfig; private readonly SqlSugarRepository<DjyUserConfig> _djyUserConfigConfig;
private readonly SqlSugarRepository<BookingExcelTemplate> _bookingExcelTemplateRepository; private readonly SqlSugarRepository<BookingExcelTemplate> _bookingExcelTemplateRepository;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository; private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
@ -65,7 +65,7 @@ namespace Myshipping.Application
_taskTruckContaRepository = taskTruckContaRepository; _taskTruckContaRepository = taskTruckContaRepository;
_taskBaseRepository = taskBaseRepository; _taskBaseRepository = taskBaseRepository;
_bookingPrintTemplateTemplate = bookingPrintTemplateTemplate; _bookingPrintTemplateRepository = bookingPrintTemplateTemplate;
_djyUserConfigConfig = djyUserConfigConfig; _djyUserConfigConfig = djyUserConfigConfig;
_bookingExcelTemplateRepository = bookingExcelTemplateRepository; _bookingExcelTemplateRepository = bookingExcelTemplateRepository;
_bookingOrderRepository = bookingOrderRepository; _bookingOrderRepository = bookingOrderRepository;
@ -324,7 +324,7 @@ namespace Myshipping.Application
public async Task<string> Print([FromQuery] string taskPKId, [FromQuery] long templateId, [FromQuery] string cateCode, [FromQuery] PrintFileTypeEnum printFileType = PrintFileTypeEnum.PDF, public async Task<string> Print([FromQuery] string taskPKId, [FromQuery] long templateId, [FromQuery] string cateCode, [FromQuery] PrintFileTypeEnum printFileType = PrintFileTypeEnum.PDF,
[FromQuery] BookingPrintTemplateType printType = BookingPrintTemplateType.FastReport) [FromQuery] BookingPrintTemplateType printType = BookingPrintTemplateType.FastReport)
{ {
var printTemplate = await _bookingPrintTemplateTemplate.AsQueryable().Filter(null, true) var printTemplate = await _bookingPrintTemplateRepository.AsQueryable().Filter(null, true)
.FirstAsync(x => x.Id == templateId); .FirstAsync(x => x.Id == templateId);
if (printTemplate == null) if (printTemplate == null)
@ -1269,7 +1269,7 @@ namespace Myshipping.Application
{ {
var typeCode = printType.ToString(); var typeCode = printType.ToString();
//当前公司所有已配置的模板 //当前公司所有已配置的模板
var allList = await _bookingPrintTemplateTemplate.AsQueryable() var allList = await _bookingPrintTemplateRepository.AsQueryable()
.Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId) .Filter(null, true).InnerJoin<BookingPrinttemplateRight>((d, t) => d.Id == t.PrintTemplateId && t.SysUserId == UserManager.UserId)
.Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode.Contains(cateCode) && d.Type == typeCode) .Where(d => d.TenantId == UserManager.TENANT_ID && d.CateCode.Contains(cateCode) && d.Type == typeCode)
.Select(d => new .Select(d => new

Loading…
Cancel
Save