wanghaomei 2 years ago
commit e744f912ad

@ -1807,7 +1807,7 @@ namespace Myshipping.Application.EDI.PIL
}
tempstr += GetSpaceStr("", 4);//5//Department Code//M//X(4)//19//22//webCSM Department Code (eg SG00) (out from webCSM only)//部门代码//webcsm部门代码如sg00从webcsm只
tempstr += GetSpaceStr("", 3);//6//Booking Agent Code//M//X(3)//23//25//webCSM Booking Agent Code (eg SIN)//订舱代理代码//webcsm订舱代理代码如犯罪
if (bill.ISSUETYPE.ToString().Trim().ToUpper() == "WAYBILL" || bill.ISSUETYPE.ToString().Trim().ToUpper() == "SEAWAY BILL")
if (bill.ISSUETYPE?.Trim().ToUpper() == "WAYBILL" || bill.ISSUETYPE?.Trim().ToUpper() == "SEAWAY BILL")
{
tempstr += GetSpaceStr("W", 1);//7//BOL Type//M//X(1)//26//26//N-Nominal, G-Negotiable, S-Switch, W-Waybill, M-Memo//公司类型//n-nominalg-negotiableS-开关w-waybillm-memo
}

@ -76,6 +76,7 @@ using Myshipping.Application.Service.DataSync.Dto;
using RabbitMQ.Client;
using System.Configuration;
using System.Collections;
using System.Security.Principal;
namespace Myshipping.Application
{
@ -118,12 +119,16 @@ namespace Myshipping.Application
private readonly SqlSugarRepository<BookingTemplate> _bookingTemplate;
private readonly SqlSugarRepository<ParaGoodsInfo> _paraGoodsInfoRepository;
private readonly SqlSugarRepository<ParaContractNoInfo> _paraContractNoInfoRepository;
private readonly SqlSugarRepository<DjyWebsiteAccountConfig> _djyWebsiteAccountConfigRepository;
private readonly IHttpContextAccessor _httpContextAccessor;
private readonly IBookingGoodsStatusConfigService _GoodsConfig;
const string CONST_MAPPING_MODULE = "BOOK_OR_CLOSING";
const string CONST_MAPPING_MODULE_ROUTE = "BOOK_OR_CLOSING_RT";
private const string PrintRecentListTypeKey = "booking_print_recent_list";
const string CONST_TSL_EDI_URL = "tsl_edi_declare_url";
const string CONST_TSL_TYPE_CODE = "TslWeb";
public BookingOrderService(SqlSugarRepository<BookingOrder> rep, SqlSugarRepository<BookingCtn> repCtn, SqlSugarRepository<BookingCtnDetail> ctndetailrep,
SqlSugarRepository<BookingLog> bookinglog, SqlSugarRepository<BookingLogDetail> bookinglogdetail, SqlSugarRepository<BookingRemark> bookingremark,
SqlSugarRepository<BookingFile> bookingfile, SqlSugarRepository<DjyUserConfig> repUserConfig, SqlSugarRepository<BookingPrintTemplate> repPrint,
@ -133,7 +138,7 @@ namespace Myshipping.Application
SqlSugarRepository<BookingOrderUrl> repOrderUrl, SqlSugarRepository<BookingOrderContact> repOrderContact, SqlSugarRepository<BookingSampleBill> repSampleBill, SqlSugarRepository<DjyCustomer> djycustomer,
SqlSugarRepository<BookingExcelTemplate> excelrep, SqlSugarRepository<DjyUserMailAccount> repUserMail, SqlSugarRepository<BookingGoodsStatus> goodsStatus, SqlSugarRepository<BookingGoodsStatusConfig> goodsStatusConfig,
SqlSugarRepository<SysTenant> repTenant, SqlSugarRepository<BookingStatus> repBookingStatus, SqlSugarRepository<BookingEDIExt> bookingEDIExt, SqlSugarRepository<BookingServiceItem> serviceItem,
SqlSugarRepository<ParaContractNoInfo> paraContractNoInfoRepository, IHttpContextAccessor httpContextAccessor, IBookingGoodsStatusConfigService GoodsConfig)
SqlSugarRepository<ParaContractNoInfo> paraContractNoInfoRepository, IHttpContextAccessor httpContextAccessor, IBookingGoodsStatusConfigService GoodsConfig, SqlSugarRepository<DjyWebsiteAccountConfig> djyWebsiteAccountConfigRepository)
{
this._logger = logger;
this._rep = rep;
@ -170,6 +175,8 @@ namespace Myshipping.Application
this._paraContractNoInfoRepository = paraContractNoInfoRepository;
_httpContextAccessor = httpContextAccessor;
_GoodsConfig = GoodsConfig;
_djyWebsiteAccountConfigRepository = djyWebsiteAccountConfigRepository;
}
#region 主表和箱信息
@ -3946,6 +3953,31 @@ namespace Myshipping.Application
if (ediSOSICfg == null || string.IsNullOrWhiteSpace(ediSOSICfg.MapCode))
throw Oops.Bah($"CARRIERID={order.CARRIERID} 发送SO(SI)的船公司EDI代码未找到");
string postSpiderUrl = string.Empty;
DjyWebsiteAccountConfig userWebAccountConfig = null;
if (ediRouteEnum == EDIRouteEnum.TSL && model.send)
{
if(model.sendType.Equals("E",StringComparison.OrdinalIgnoreCase))
throw Oops.Oh($"暂未提供TSL的截单发送");
postSpiderUrl = _cache.GetAllDictData().GetAwaiter().GetResult()
.FirstOrDefault(x => x.TypeCode == "url_set" && x.Code == CONST_TSL_EDI_URL)?.Value;
if (string.IsNullOrWhiteSpace(postSpiderUrl))
throw Oops.Bah($"字典未配置 url_set->{CONST_TSL_EDI_URL} 请联系管理员");
//获取个人对应的账户,这里GetAccountConfig逻辑优先取个人个人没有配置取公司对应配置
userWebAccountConfig = GetAccountConfig(CONST_TSL_TYPE_CODE, UserManager.UserId, UserManager.TENANT_ID).GetAwaiter()
.GetResult();
_logger.LogInformation("批次={no} 获取获取网站的账户完成result={Num}", batchNo, JSON.Serialize(userWebAccountConfig));
if (userWebAccountConfig == null)
throw Oops.Oh($" 未配置个人或公司网站账户,网站{CONST_TSL_TYPE_CODE}");
}
var ediModel = new EDIBaseModel();
//2023-03-06 修改读取EDI配置方法所有提取配置必须是已启用的EnableFlag=true并且要根据SendType匹配发送类型SendType=""表示使用订舱和截单SO-订舱 SI-截单
@ -4280,23 +4312,23 @@ namespace Myshipping.Application
}
}
//运输条款EDI
var baseServiceList = _cache.GetAllCodeService().GetAwaiter().GetResult();
if (!string.IsNullOrWhiteSpace(order.SERVICE))
{
//运输条款EDI
var baseServiceList = _cache.GetAllCodeService().GetAwaiter().GetResult();
var baseServiceInfo = baseServiceList.FirstOrDefault(t =>
t.Name.Equals(order.SERVICE, StringComparison.OrdinalIgnoreCase));
var baseServiceInfo = baseServiceList.FirstOrDefault(t =>
t.Name.Equals(order.SERVICE, StringComparison.OrdinalIgnoreCase));
if (baseServiceInfo == null)
throw Oops.Bah($"运输条款{order.SERVICE}的基础代码未找到");
if (baseServiceInfo == null)
throw Oops.Bah($"运输条款{order.SERVICE}的基础代码未找到");
//运输条款映射
var ediServiceList = _cache.GetAllMappingService().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
).ToList();
//运输条款映射
var ediServiceList = _cache.GetAllMappingService().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(t.CarrierCode) && t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
).ToList();
if (!string.IsNullOrWhiteSpace(order.SERVICE))
{
var currServiceInfo = ediServiceList.FirstOrDefault(t => t.Code.Equals(baseServiceInfo.Code, StringComparison.OrdinalIgnoreCase));
if (currServiceInfo == null)
@ -4305,22 +4337,23 @@ namespace Myshipping.Application
primaryModel.SERVICEEDICODE = currServiceInfo.MapCode?.Trim();
}
//签单方式EDI
var baseIssueTypeList = _cache.GetAllCodeIssueType().GetAwaiter().GetResult();
var baseIssueTypeInfo = baseIssueTypeList.FirstOrDefault(t =>
t.EnName.Equals(order.ISSUETYPE, StringComparison.OrdinalIgnoreCase));
if (!string.IsNullOrWhiteSpace(order.ISSUETYPE))
{
//签单方式EDI
var baseIssueTypeList = _cache.GetAllCodeIssueType().GetAwaiter().GetResult();
if (baseIssueTypeInfo == null)
throw Oops.Bah($"签单方式{order.ISSUETYPE}的基础代码未找到");
var baseIssueTypeInfo = baseIssueTypeList.FirstOrDefault(t =>
t.EnName.Equals(order.ISSUETYPE, StringComparison.OrdinalIgnoreCase));
//签单方式映射
var ediIssueTypeList = _cache.GetAllMappingIssueType().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
).ToList();
if (baseIssueTypeInfo == null)
throw Oops.Bah($"签单方式{order.ISSUETYPE}的基础代码未找到");
//签单方式映射
var ediIssueTypeList = _cache.GetAllMappingIssueType().GetAwaiter().GetResult()
.Where(t => t.Module.Equals(CONST_MAPPING_MODULE, StringComparison.OrdinalIgnoreCase)
).ToList();
if (!string.IsNullOrWhiteSpace(order.ISSUETYPE))
{
var currIssueTypeInfo = ediIssueTypeList.FirstOrDefault(t => !string.IsNullOrWhiteSpace(t.CarrierCode)
&& t.CarrierCode.Equals(order.CARRIERID, StringComparison.OrdinalIgnoreCase)
&& t.Code.Equals(baseIssueTypeInfo.Code, StringComparison.OrdinalIgnoreCase));
@ -4536,6 +4569,10 @@ namespace Myshipping.Application
if (model.send)
{
/*
2023-05-24 TSLTSL广
*/
string currFilePath = string.Empty;
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
@ -4563,40 +4600,48 @@ namespace Myshipping.Application
DateTime bDate = DateTime.Now;
//上传FTP
CommonWebApiResult sendStatus = null;
//是否发送邮件EDI这里主要分2种通道发送 默认是FTP如果配置里指定了接收接收邮箱就需要推送邮件
bool isSendEmail = false;
//是订舱并且FTP配置了订舱接收邮箱则触发邮箱发送
if (ftpSet.SendType.Equals("SO", StringComparison.OrdinalIgnoreCase)
&& model.sendType.Equals("B", StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
else if (ftpSet.SendType.Equals("SI", StringComparison.OrdinalIgnoreCase)
&& model.sendType.Equals("E", StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
else if (string.IsNullOrWhiteSpace(ftpSet.SendType)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
//上传FTP
CommonWebApiResult sendStatus = null;
if (isSendEmail)
//TSL单独走接口
if (ediRouteEnum == EDIRouteEnum.TSL)
{
//推送订舱邮件
sendStatus = await InnerSendBookingOrClosingEDIToEmail(order, result.extra.ToString(),
model.sendType, result.extra2.ToString(), ftpSet);
sendStatus = await InnerSendBookingOrClosingEDIToPOST(result.extra.ToString(), postSpiderUrl, userWebAccountConfig);
}
else
{
sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
//是订舱并且FTP配置了订舱接收邮箱则触发邮箱发送
if (ftpSet.SendType.Equals("SO", StringComparison.OrdinalIgnoreCase)
&& model.sendType.Equals("B", StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
else if (ftpSet.SendType.Equals("SI", StringComparison.OrdinalIgnoreCase)
&& model.sendType.Equals("E", StringComparison.OrdinalIgnoreCase)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
else if (string.IsNullOrWhiteSpace(ftpSet.SendType)
&& !string.IsNullOrWhiteSpace(ftpSet.RECEIVEEMAIL))
{
isSendEmail = true;
}
if (isSendEmail)
{
//推送订舱邮件
sendStatus = await InnerSendBookingOrClosingEDIToEmail(order, result.extra.ToString(),
model.sendType, result.extra2.ToString(), ftpSet);
}
else
{
sendStatus = await InnerSendBookingOrClosingEDIToFTP(result.extra.ToString(), ftpSet);
}
}
DateTime eDate = DateTime.Now;
@ -4615,12 +4660,23 @@ namespace Myshipping.Application
CreatedUserName = UserManager.Name
});
string sendTypeName = "FTP";
if (isSendEmail)
{
sendTypeName = "邮件";
}
else if(ediRouteEnum == EDIRouteEnum.TSL)
{
sendTypeName = "POST";
}
await _bookinglogdetail.InsertReturnSnowflakeIdAsync(new BookingLogDetail
{
PId = logId,
Field = String.Empty,
OldValue = String.Empty,
NewValue = $"发送 {order.CARRIERID} EDI 类型={model.sendType} 通过{(isSendEmail ? "" : "FTP")} {(sendStatus.succ ? "" : "")}",
NewValue = $"发送 {order.CARRIERID} EDI 类型={model.sendType} 通过{sendTypeName} {(sendStatus.succ ? "" : "")}",
});
if (!sendStatus.succ)
@ -4654,6 +4710,28 @@ namespace Myshipping.Application
}
#endregion
/// <summary>
/// 获取个人或公司网站账户配置
/// </summary>
/// <param name="typeCode">账户类型代码</param>
/// <param name="userId">用户ID</param>
/// <param name="tendId">租户ID</param>
/// <returns>返回账户配置</returns>
private async Task<DjyWebsiteAccountConfig> GetAccountConfig(string typeCode, long userId, long tendId)
{
DjyWebsiteAccountConfig accountConfig = new DjyWebsiteAccountConfig();
accountConfig = await _djyWebsiteAccountConfigRepository.EntityContext.CopyNew().Queryable<DjyWebsiteAccountConfig>()
.FirstAsync(x => x.TypeCode == typeCode && x.CreatedUserId == userId);
if (accountConfig == null)
{
accountConfig = await _djyWebsiteAccountConfigRepository.EntityContext.CopyNew().Queryable<DjyWebsiteAccountConfig>()
.FirstAsync(x => x.TypeCode == typeCode && x.TenantId == tendId && x.IsTenant == true);
}
return accountConfig;
}
#region 下载订舱、截单EDI
/// <summary>
/// 下载订舱、截单EDI
@ -4780,6 +4858,74 @@ namespace Myshipping.Application
}
#endregion
/// <summary>
/// EDI发送POST请求
/// </summary>
/// <param name="filePath">文件路径</param>
/// <param name="url">请求URL</param>
/// <param name="accountConfig">配置账户</param>
/// <returns>返回回执</returns>
private async Task<CommonWebApiResult> InnerSendBookingOrClosingEDIToPOST(string filePath, string url, DjyWebsiteAccountConfig accountConfig)
{
CommonWebApiResult result = new CommonWebApiResult { succ = true };
CancellationTokenSource cts = new CancellationTokenSource();
NameValueCollection par = new NameValueCollection();
par.Add("user_key", App.Configuration["BCOrDraftUserKey"]);
par.Add("user_secret", App.Configuration["BCOrDraftUserSecret"]);
par.Add("web_user", accountConfig.Account?.Trim());
par.Add("web_psw", accountConfig.Password?.Trim());
_logger.LogInformation($"准备请求发送POST{url} ,参数:{JSON.Serialize(par)},文件:{filePath}");
System.IO.FileStream file = new System.IO.FileStream(filePath, FileMode.Open, FileAccess.Read);
int SplitSize = 5242880;//5M分片长度
int index = 1; //序号 第几片
long StartPosition = 5242880 * (index - 1);
long lastLens = file.Length - StartPosition;//真不知道怎么起命了,就这样吧
if (lastLens < 5242880)
{
SplitSize = (int)lastLens;
}
byte[] heByte = new byte[SplitSize];
file.Seek(StartPosition, SeekOrigin.Begin);
//第一个参数是 起始位置
file.Read(heByte, 0, SplitSize);
//第三个参数是 读取长度(剩余长度)
file.Close();
string strJoin = System.IO.File.ReadAllText(filePath);
DateTime bDate = DateTime.Now;
_logger.LogInformation("POST 开始上传");
var res = FTPHelper.TransmitFtpFile(url, par, new
{
file = "file",
fileName = Path.GetFileName(filePath),
fileBytes = heByte
});
DateTime eDate = DateTime.Now;
TimeSpan ts = eDate.Subtract(bDate);
var timeDiff = ts.TotalMilliseconds;
_logger.LogInformation($"请求POST 上传完成 上传文件大小:{heByte.Length} 用时:{timeDiff}ms.,{strJoin}");
_logger.LogInformation($"发送POST返回{res}");
var jobjRetn = JObject.Parse(res);
if (jobjRetn.GetStringValue("code") != "200")
{
result.succ = false;
result.msg = jobjRetn.GetStringValue("msg");
}
return result;
}
#region 上传邮件
/// <summary>
/// 上传邮件

@ -6,6 +6,7 @@ using Furion.Extensions;
using Furion.FriendlyException;
using Furion.JsonSerialization;
using Furion.RemoteRequest.Extensions;
using Mapster;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
@ -47,7 +48,7 @@ namespace Myshipping.Application
public class BookingValueAddedService : IBookingValueAddedService, IDynamicApiController, ITransient
{
private readonly ISysCacheService _cache;
//private readonly IDjyWebsiteAccountConfigService _webAccountConfig;
private readonly IBookingOrderService _bookingOrderService;
private readonly ILogger<BookingTruckService> _logger;
private readonly SqlSugarRepository<BookingOrder> _bookingOrderRepository;
private readonly SqlSugarRepository<BookingFile> _bookingfile;
@ -71,7 +72,7 @@ namespace Myshipping.Application
public BookingValueAddedService(ISysCacheService cache, ILogger<BookingTruckService> logger,
SqlSugarRepository<BookingOrder> bookingOrderRepository, SqlSugarRepository<BookingFile> bookingfile,
SqlSugarRepository<DjyWebsiteAccountConfig> djyWebsiteAccountConfigRepository, SqlSugarRepository<SysUser> sysUserRepository,
SqlSugarRepository<BookingLetteryard> bookingLetteryardRepository)
SqlSugarRepository<BookingLetteryard> bookingLetteryardRepository, IBookingOrderService bookingOrderService)
{
_cache = cache;
_logger = logger;
@ -82,6 +83,7 @@ namespace Myshipping.Application
_djyWebsiteAccountConfigRepository = djyWebsiteAccountConfigRepository;
_sysUserRepository = sysUserRepository;
_bookingLetteryardRepository = bookingLetteryardRepository;
_bookingOrderService = bookingOrderService;
}
@ -1205,7 +1207,7 @@ namespace Myshipping.Application
/// <param name="bookingOrderId">订舱主键</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingValueAdded/SingleBCFileRead")]
public async Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file, long bookingOrderId)
public async Task<TaskManageOrderResultDto> SingleBCFileRead(IFormFile file, [FromForm] long bookingOrderId)
{
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
@ -1336,8 +1338,6 @@ namespace Myshipping.Application
jsonOptions.Converters.Add(new IntegerJsonConverter());
jsonOptions.Converters.Add(new DecimalJsonConverter());
model = JSON.Deserialize<BCAPIBaseDataParse>(result, jsonOptions);
}
}
@ -1356,9 +1356,45 @@ namespace Myshipping.Application
/// </summary>
/// <param name="model">单票BC详情</param>
/// <returns>返回回执</returns>
[HttpPost("/BookingValueAdded/SingleBCUpdateBookingOrder")]
public async Task<TaskManageOrderResultDto> SingleBCUpdateBookingOrder(SingleBCDto model)
{
return new TaskManageOrderResultDto();
TaskManageOrderResultDto result = new TaskManageOrderResultDto();
string batchNo = IDGen.NextID().ToString();
try
{
/*
1BC
2
3
*/
if (model.IsLetterYard)
{
_logger.LogInformation("批次={no} 单票BC更新订舱后用户选择了转为入货通知开始发送入货通知", batchNo);
var letterYardDto = new UpdateBookingLetteryardInput();
letterYardDto = model.LetteryardDto.Adapt<UpdateBookingLetteryardInput>();
if(model.LetterYardId.HasValue)
{
letterYardDto.Id = model.LetterYardId.Value;
}
//放舱保存
var letterYardId = await _bookingOrderService.LetteryardSave(letterYardDto);
//
}
}
catch (Exception ex)
{
}
return result;
}
}

@ -20,7 +20,7 @@ namespace Myshipping.Application
/// <summary>
/// 放舱主键(入货通知保存后的主键)
/// </summary>
public string LetterYardId { get; set; }
public Nullable<long> LetterYardId { get; set; }
/// <summary>
/// 截关时间

@ -47,5 +47,12 @@ namespace Myshipping.Application
Task<string> InnerBookingOrClosingEDI(BookingOrClosingEDIOrderDto model);
Task<dynamic> SendBookingOrder(long[] ids);
/// <summary>
/// 保存(新增或修改)放舱
/// </summary>
/// <param name="input">放舱详情</param>
/// <returns>返回放舱主键</returns>
Task<long> LetteryardSave(UpdateBookingLetteryardInput input);
}
}

@ -943,6 +943,11 @@ namespace Myshipping.Application
var service = _namedServiceProvider.GetService(nameof(BookingTruckService));
var rlt = await service.TruckDispatchCompleteCallBack(model);
if(!rlt.succ)
{
throw Oops.Oh(rlt.msg);
}
result.succ = true;
result.msg = "派车成功";
result.ext = rlt;

Loading…
Cancel
Save