修改单票BC引入

optimize
jianghaiqing 2 years ago
parent 600bb5f3ee
commit 31fdebbdea

@ -2,6 +2,7 @@
using Furion.DependencyInjection; using Furion.DependencyInjection;
using Furion.DistributedIDGenerator; using Furion.DistributedIDGenerator;
using Furion.DynamicApiController; using Furion.DynamicApiController;
using Furion.Extensions;
using Furion.FriendlyException; using Furion.FriendlyException;
using Furion.JsonSerialization; using Furion.JsonSerialization;
using Furion.RemoteRequest.Extensions; using Furion.RemoteRequest.Extensions;
@ -15,10 +16,12 @@ using Myshipping.Core;
using Myshipping.Core.Entity; using Myshipping.Core.Entity;
using Myshipping.Core.Service; using Myshipping.Core.Service;
using Org.BouncyCastle.Crypto; using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Utilities;
using SqlSugar; using SqlSugar;
using StackExchange.Profiling.Internal; using StackExchange.Profiling.Internal;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized;
using System.Diagnostics; using System.Diagnostics;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -31,6 +34,8 @@ using System.Text.Json;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web;
using Ubiety.Dns.Core;
using Yitter.IdGenerator; using Yitter.IdGenerator;
namespace Myshipping.Application namespace Myshipping.Application
@ -48,6 +53,7 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingFile> _bookingfile; private readonly SqlSugarRepository<BookingFile> _bookingfile;
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _djyWebsiteAccountConfigRepository; private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _djyWebsiteAccountConfigRepository;
private readonly SqlSugarRepository<SysUser> _sysUserRepository; private readonly SqlSugarRepository<SysUser> _sysUserRepository;
private readonly SqlSugarRepository<BookingLetteryard> _bookingLetteryardRepository;
const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT"; const string CONST_MAPPING_BC_MODULE_ROUTE = "BC_DOWN_RT";
const string CONST_MAPPING_DRAFT_MODULE_ROUTE = "DRAFT_DOWN_RT"; const string CONST_MAPPING_DRAFT_MODULE_ROUTE = "DRAFT_DOWN_RT";
@ -59,9 +65,13 @@ namespace Myshipping.Application
const string CONST_FORMAT_WEB = "{0}Web"; const string CONST_FORMAT_WEB = "{0}Web";
const string CONST_BC_FILE_PARSE_URL = "bc_file_parse_url";
const string CONST_BC_FILE_READ_URL = "bc_file_pdf_read_url";
public BookingValueAddedService(ISysCacheService cache, ILogger<BookingTruckService> logger, public BookingValueAddedService(ISysCacheService cache, ILogger<BookingTruckService> logger,
SqlSugarRepository<BookingOrder> bookingOrderRepository, SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<BookingOrder> bookingOrderRepository, SqlSugarRepository<BookingFile> bookingfile,
SqlSugarRepository<DjyWebsiteAccountConfig> djyWebsiteAccountConfigRepository, SqlSugarRepository<SysUser> sysUserRepository) SqlSugarRepository<DjyWebsiteAccountConfig> djyWebsiteAccountConfigRepository, SqlSugarRepository<SysUser> sysUserRepository,
SqlSugarRepository<BookingLetteryard> bookingLetteryardRepository)
{ {
_cache = cache; _cache = cache;
_logger = logger; _logger = logger;
@ -71,6 +81,7 @@ namespace Myshipping.Application
_djyWebsiteAccountConfigRepository = djyWebsiteAccountConfigRepository; _djyWebsiteAccountConfigRepository = djyWebsiteAccountConfigRepository;
_sysUserRepository = sysUserRepository; _sysUserRepository = sysUserRepository;
_bookingLetteryardRepository = bookingLetteryardRepository;
} }
@ -1191,10 +1202,153 @@ namespace Myshipping.Application
/// 单票BC文件解析 /// 单票BC文件解析
/// </summary> /// </summary>
/// <param name="file">上传文件</param> /// <param name="file">上传文件</param>
/// <param name="bookingOrderId">订舱主键</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
public async Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file) [HttpPost("/BookingValueAdded/SingleBCFileRead")]
public async Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file, long bookingOrderId)
{ {
return new TaskManageOrderResultDto(); TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
SingleBCDto singleBCDto = null;
try
{
/*
1
2BC
*/
if(bookingOrderId < 0)
throw Oops.Oh($"订舱主键不能为空");
var bookingOrder = _bookingOrderRepository.AsQueryable().First(a => a.Id == bookingOrderId);
if(bookingOrder == null)
throw Oops.Oh($"订舱信息获取失败,订舱信息不存在或已作废");
//获取解析BC文件链接
var bcUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code.Equals(CONST_BC_FILE_PARSE_URL, StringComparison.OrdinalIgnoreCase))?.Value;
_logger.LogInformation("提单号{mbl} 获取解析BC文件URL完成结果={rlt}",
bookingOrder.MBLNO, bcUrl);
if (string.IsNullOrWhiteSpace(bcUrl))
{
_logger.LogInformation("提单号{0} 获取解析BC文件URL失败未取到配置key={key}",
bookingOrder.MBLNO, CONST_BC_FILE_PARSE_URL);
throw Oops.Bah($"未配置请求地址{CONST_BC_FILE_PARSE_URL} 请联系管理员");
}
byte[] bytes = file.ToByteArray();
DateTime bDate = DateTime.Now;
//请求BC解析
var bcParseRlt = await TransmitFile(bcUrl, new
{
file = "file",
fileName = file.FileName,
fileBytes = bytes
});
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation("批次={no} result={result} 获取解析BC文件URL结束 耗时:{timeDiff}ms. ", batchNo,
JSON.Serialize(bcParseRlt), timeDiff);
if (bcParseRlt.status == 1)
{
var currBC = bcParseRlt.data.BCList.FirstOrDefault();
singleBCDto = new SingleBCDto
{
BookingOrderId = bookingOrderId,
BLNo = currBC.BLNo?.Trim().ToUpper(),
Vessel = currBC.Vessel?.Trim().ToUpper(),
Voyage = currBC.Voyage?.Trim().ToUpper(),
ClosingDate = currBC.ClosingDate,
CYCutOffTime = currBC.CYCutOffTime,
ETD = currBC.ETD
};
singleBCDto.BookingOrderBCDto = new BookingOrderBCDto {
MBLNO = bookingOrder.MBLNO,
CUSTNO = bookingOrder.CUSTNO,
CLOSEDOCDATE = bookingOrder.CLOSEDOCDATE,
CLOSEVGMDATE = bookingOrder.CLOSEVGMDATE,
CLOSINGDATE = bookingOrder.CLOSINGDATE,
ETD = bookingOrder.ETD,
VESSEL = bookingOrder.VESSEL,
VOYNO = bookingOrder.VOYNO,
};
result.succ = true;
result.ext = singleBCDto;
}
else
{
result.succ = false;
result.msg = $"解析BC失败原因{bcParseRlt.message}";
}
}
catch(Exception ex)
{
_logger.LogInformation("批次={no} 解析BC异常原因{error} ", batchNo, ex.Message);
result.succ = false;
result.msg = $"解析BC异常原因{ex.Message}";
}
return result;
}
/// <summary>
/// 请求BC解析
/// </summary>
/// <param name="requestUrl">请求地址</param>
/// <param name="fileInfo">文件详情</param>
/// <returns>返回BC解析详情</returns>
private async Task<BCAPIBaseDataParse> TransmitFile(string requestUrl, dynamic fileInfo)
{
BCAPIBaseDataParse model = null;
try
{
var response = await requestUrl.SetContentType("multipart/form-data")
.SetBodyBytes((fileInfo.file.ToString(), fileInfo.fileBytes, fileInfo.fileName.ToString()))
.PostAsync();
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
var result = response.Content.ReadAsStringAsync().Result;
if (string.IsNullOrWhiteSpace(result))
{
throw Oops.Bah($"获取解析BC文件失败未获取到有效信息");
}
System.Text.Json.JsonSerializerOptions jsonOptions = new JsonSerializerOptions();
jsonOptions.Converters.Add(new DateTimeJsonConverter("yyyy-MM-dd HH:mm:ss"));
jsonOptions.Converters.Add(new IntegerJsonConverter());
jsonOptions.Converters.Add(new DecimalJsonConverter());
model = JSON.Deserialize<BCAPIBaseDataParse>(result, jsonOptions);
}
}
catch (Exception ex)
{
_logger.LogInformation("{name} 发送BC文件解析请求 url={url} 异常,原因={error}", nameof(TransmitFile),
requestUrl, ex.Message);
throw Oops.Bah($"{nameof(TransmitFile)} {requestUrl} 发送BC文件解析请求异常{ex.Message}");
}
return model;
} }
/// <summary> /// <summary>
@ -1231,5 +1385,59 @@ namespace Myshipping.Application
writer.WriteStringValue(value.ToUniversalTime().ToString(_dateFormatString)); writer.WriteStringValue(value.ToUniversalTime().ToString(_dateFormatString));
} }
} }
public class IntegerJsonConverter : System.Text.Json.Serialization.JsonConverter<Int32>
{
public IntegerJsonConverter()
{
}
public override Int32 Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var curStr = reader.GetString();
Int32 curVal = 0;
Int32.TryParse(curStr, out curVal);
return curVal;
}
else
{
return reader.GetInt32();
}
}
public override void Write(Utf8JsonWriter writer, Int32 value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value);
}
}
public class DecimalJsonConverter : System.Text.Json.Serialization.JsonConverter<decimal>
{
public DecimalJsonConverter()
{
}
public override decimal Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType == JsonTokenType.String)
{
var curStr = reader.GetString();
decimal curVal = 0;
decimal.TryParse(curStr, out curVal);
return curVal;
}
else
{
return reader.GetDecimal();
}
}
public override void Write(Utf8JsonWriter writer, decimal value, JsonSerializerOptions options)
{
writer.WriteNumberValue(value);
}
}
} }

@ -210,7 +210,7 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// 箱量 /// 箱量
/// </summary> /// </summary>
public Nullable<int> CartonQuantity { get; set; } public Nullable<Int32> CartonQuantity { get; set; }
/// <summary> /// <summary>
/// 箱型 /// 箱型
@ -220,7 +220,7 @@ namespace Myshipping.Application
/// <summary> /// <summary>
/// 件数 /// 件数
/// </summary> /// </summary>
public Nullable<int> Pieces { get; set; } public Nullable<Int32> Pieces { get; set; }
/// <summary> /// <summary>
/// 尺寸 /// 尺寸

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -16,6 +17,11 @@ namespace Myshipping.Application
/// </summary> /// </summary>
public long BookingOrderId { get; set; } public long BookingOrderId { get; set; }
/// <summary>
/// 放舱主键(入货通知保存后的主键)
/// </summary>
public string LetterYardId { get; set; }
/// <summary> /// <summary>
/// 截关时间 /// 截关时间
/// </summary> /// </summary>
@ -45,5 +51,61 @@ namespace Myshipping.Application
/// 开船日期 /// 开船日期
/// </summary> /// </summary>
public Nullable<DateTime> ETD { get; set; } public Nullable<DateTime> ETD { get; set; }
}
/// <summary>
/// 文件暂存路径
/// </summary>
public string FileTempPath { get; set; }
/// <summary>
/// 入货通知详情
/// </summary>
public BookingLetteryardInput LetteryardDto { get; set; }
/// <summary>
/// 是否转为入货通知
/// </summary>
public bool IsLetterYard { get; set; } = false;
/// <summary>
/// 订舱详情
/// </summary>
public BookingOrderBCDto BookingOrderBCDto { get; set; }
}
public class BookingOrderBCDto
{
/// <summary>
/// 船名
/// </summary>
public string VESSEL { get; set; }
/// <summary>
/// 海关航次
/// </summary>
public string VOYNO { get; set; }
/// <summary>
/// 主提单号
/// </summary>
public string MBLNO { get; set; }
/// <summary>
/// 订舱编号
/// </summary>
public string CUSTNO { get; set; }
/// <summary>
/// 开船日期(船司提供的开船日期,操作填写)
/// </summary>
public Nullable<DateTime> ETD { get; set; }
/// <summary>
/// 截港日期
/// </summary>
public Nullable<DateTime> CLOSINGDATE { get; set; }
/// <summary>
/// 截单日期
/// </summary>
public Nullable<DateTime> CLOSEDOCDATE { get; set; }
/// <summary>
/// 截VGM时间
/// </summary>
public Nullable<DateTime> CLOSEVGMDATE { get; set; }
}
} }

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
using Myshipping.Application.Entity;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -38,8 +39,10 @@ namespace Myshipping.Application
/// 单票BC文件解析 /// 单票BC文件解析
/// </summary> /// </summary>
/// <param name="file">上传文件</param> /// <param name="file">上传文件</param>
/// <param name="bookingOrderId">订舱主键</param>
/// <returns>返回回执</returns> /// <returns>返回回执</returns>
Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file); Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file, long bookingOrderId);
/// <summary> /// <summary>
/// 单票BC更新订舱 /// 单票BC更新订舱

Loading…
Cancel
Save