|
|
|
@ -3,6 +3,7 @@ using Autofac.Core;
|
|
|
|
|
using DS.Module.Core;
|
|
|
|
|
using DS.Module.Core.Extensions;
|
|
|
|
|
using DS.Module.Core.Helpers;
|
|
|
|
|
using DS.Module.DjyServiceStatus;
|
|
|
|
|
using DS.WMS.Core.Code.Entity;
|
|
|
|
|
using DS.WMS.Core.Info.Entity;
|
|
|
|
|
using DS.WMS.Core.Invoice.Dtos;
|
|
|
|
@ -14,7 +15,11 @@ using DS.WMS.Core.Sys.Entity;
|
|
|
|
|
using LanguageExt;
|
|
|
|
|
using LanguageExt.Common;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNet.SignalR;
|
|
|
|
|
using Microsoft.AspNetCore.Connections;
|
|
|
|
|
using Microsoft.AspNetCore.Identity;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Microsoft.EntityFrameworkCore.Metadata;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
using NPOI.HSSF.UserModel;
|
|
|
|
@ -23,6 +28,7 @@ using NPOI.SS.UserModel;
|
|
|
|
|
using Org.BouncyCastle.Ocsp;
|
|
|
|
|
using System.Collections.Specialized;
|
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
|
|
|
|
|
|
namespace DS.WMS.Core.Op.Method
|
|
|
|
@ -32,6 +38,7 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class SeaExportService
|
|
|
|
|
{
|
|
|
|
|
const string CONST_AUTO_SYNC_DONGSHENG_BY_MQ = "AutoSyncBookingOrderToDongshengMQ";
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 打印保函
|
|
|
|
@ -2649,5 +2656,318 @@ namespace DS.WMS.Core.Op.Method
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 推送东胜(MQ)
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 推送东胜(MQ)
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="ids">海运订单主键数组</param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<dynamic> SendBookingOrder(long[] ids)
|
|
|
|
|
{
|
|
|
|
|
var logTitle = $"同步订舱数据,ids:{string.Join(',', ids.ToList())},";
|
|
|
|
|
|
|
|
|
|
_logger.Info($"开始{logTitle}");
|
|
|
|
|
|
|
|
|
|
var BookingOrderMQUri = AppSetting.app(new string[] { "SyncDongSheng7", "MQConfig" });
|
|
|
|
|
|
|
|
|
|
var paramConfig = _configService.GetConfig(CONST_AUTO_SYNC_DONGSHENG_BY_MQ, long.Parse(user.TenantId), false).GetAwaiter().GetResult()?.Data?.Value;
|
|
|
|
|
|
|
|
|
|
_logger.Info($"{logTitle}订舱数据回推地址:{BookingOrderMQUri},{CONST_AUTO_SYNC_DONGSHENG_BY_MQ}:{paramConfig}");
|
|
|
|
|
|
|
|
|
|
var tenantDb = saasService.GetBizDbScopeById(user.TenantId);
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(paramConfig) && paramConfig.Equals("ENABLE",StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
if (ids.Count() == 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info($"{logTitle}请求参数错误,未提供上传订单的主键,结束");
|
|
|
|
|
|
|
|
|
|
throw new Exception("请求参数错误,未提供上传订单的主键");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var order = await tenantDb.Queryable<SeaExport>().Filter(null, true).Where(x => ids.Contains(x.Id) && x.Deleted == false).ToListAsync();
|
|
|
|
|
|
|
|
|
|
foreach (var item in order)
|
|
|
|
|
{
|
|
|
|
|
//2023-9-8,增加校验,分单不能单独推送东胜,只能随主单推送
|
|
|
|
|
if (item.ParentId > 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info($"Id:{item.Id},分单不能单独推送东胜,只能随主单推送,continue跳过");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
//2023-9-26,添加校验:推送前通过Cache判断一下待推送的数据是否正在走删除逻辑
|
|
|
|
|
if (await _cache.ExistsAsync($"DeletingBookingOrderId_{item.Id}"))
|
|
|
|
|
{
|
|
|
|
|
_logger.Info($"Id:{item.Id},正在走删除逻辑,continue跳过");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var dto = item.Adapt<SyncBookingOrderDto>();
|
|
|
|
|
|
|
|
|
|
//if (syncTypeEnum != null)
|
|
|
|
|
//{
|
|
|
|
|
// dto.SyncType = syncTypeEnum.ToString();
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(dto.YARDREMARK))
|
|
|
|
|
{
|
|
|
|
|
dto.YARDREMARK += "\\n" + item.BookingSlotTypeName;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.YARDREMARK = item.BookingSlotTypeName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<EmbedServiceProjectStatusDto> statusList = new List<EmbedServiceProjectStatusDto>();
|
|
|
|
|
|
|
|
|
|
QueryServiceProjectWithStatus queryInfo = new QueryServiceProjectWithStatus
|
|
|
|
|
{
|
|
|
|
|
BookingId = item.Id,
|
|
|
|
|
QueryType = TrackingQueryTypeEnum.QUERY_SERVICE_PROJECT,
|
|
|
|
|
TenantId = item.TenantId.Value
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var queryRlt = await _serviceWorkFlowManageService.GetEnableStatusListByBusiness(queryInfo);
|
|
|
|
|
|
|
|
|
|
if (queryRlt.succ)
|
|
|
|
|
{
|
|
|
|
|
statusList = JsonConvert.DeserializeObject<List<EmbedServiceProjectStatusDto>>(JsonConvert.SerializeObject(queryRlt.ext));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (statusList != null && statusList.Any(x => x.StatusSKUCode == "SQXS" && x.IsYield))
|
|
|
|
|
{
|
|
|
|
|
dto.CtnDayNum = statusList.FirstOrDefault(x => x.StatusSKUCode == "SQXS" && x.IsYield)?.ActVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var ctn = await tenantDb.Queryable<SeaExportctn>.AsQueryable().Filter(null, true).Where(x => x.BILLID == item.Id && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
|
|
|
|
|
dto.ctnInputs = ctn.Adapt<List<BookingCtnDto>>();
|
|
|
|
|
foreach (var it in dto.ctnInputs)
|
|
|
|
|
{
|
|
|
|
|
var ctnDetailInputs = await _ctndetailrep.AsQueryable().Filter(null, true).Where(x => x.CTNID == it.Id && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
it.ctnDetailInputs = ctnDetailInputs.Adapt<List<BookingCtnDetailDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//2024-06-20 这里如果遇到拆票情况需要重新组织提单号
|
|
|
|
|
if (item.SplitOrMergeFlag.HasValue && (item.SplitOrMergeFlag.Value == 1 || item.SplitOrMergeFlag.Value == 2))
|
|
|
|
|
{
|
|
|
|
|
dto.MBLNO = $"{item.MBLNO}-{item.HBLNO}";
|
|
|
|
|
|
|
|
|
|
//如果当前是合票时,需要所有子票的箱型箱量合并到主票同步到东胜,子票的箱型箱量不同步东胜
|
|
|
|
|
if (item.SplitOrMergeFlag.Value == 2)
|
|
|
|
|
{
|
|
|
|
|
//如果当前是主票
|
|
|
|
|
if (dto.CUSTNO.Equals(dto.HBLNO, StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
var allOrderList = await _rep.AsQueryable().Filter(null, true).Where(x => dto.HBLNO == x.HBLNO && (x.SPLIT_OR_MERGE_FLAG != null && x.SPLIT_OR_MERGE_FLAG == 2)
|
|
|
|
|
&& x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
|
|
|
|
|
if (allOrderList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var allOrderIds = allOrderList.Select(x => x.Id).ToList();
|
|
|
|
|
var currCtn = await _repCtn.AsQueryable().Filter(null, true).Where(x => x.BILLID != null && allOrderIds.Contains(x.BILLID.Value)
|
|
|
|
|
&& x.IsDeleted == false).ToListAsync();
|
|
|
|
|
|
|
|
|
|
dto.ctnInputs = currCtn.Adapt<List<BookingCtnDto>>();
|
|
|
|
|
foreach (var it in dto.ctnInputs)
|
|
|
|
|
{
|
|
|
|
|
var ctnDetailInputs = await _ctndetailrep.AsQueryable().Filter(null, true).Where(x => x.CTNID == it.Id && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
it.ctnDetailInputs = ctnDetailInputs.Adapt<List<BookingCtnDetailDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dto.CNTRTOTAL = string.Join(",", dto.ctnInputs.GroupBy(x => x.CTNALL).Select(x => $"{x.Key}*{x.Sum(b => b.CTNNUM)}").ToArray());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.ctnInputs = new List<BookingCtnDto>();
|
|
|
|
|
dto.CNTRTOTAL = string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//EDI
|
|
|
|
|
var BookingEDIExt = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == item.Id && x.IsDeleted == false).FirstAsync();
|
|
|
|
|
if (BookingEDIExt != null)
|
|
|
|
|
{
|
|
|
|
|
dto.BookingEDIExt = BookingEDIExt.Adapt<BookingEDIExtDto>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (App.Configuration["ServiceStatusOpenAuto"] == "1")
|
|
|
|
|
{
|
|
|
|
|
if (statusList != null && statusList.Any(x => x.IsYield))
|
|
|
|
|
{
|
|
|
|
|
dto.GoodsStatus = statusList.Where(x => x.IsYield).OrderBy(x => x.SortNo).Select(x => new BookingGoodsStatusDto
|
|
|
|
|
{
|
|
|
|
|
StatusName = x.ShowName,
|
|
|
|
|
FinishTime = x.ActDate,
|
|
|
|
|
Remark = x.ActRemark,
|
|
|
|
|
ExtData = x.ActVal
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
dto.GoodsStatus = new List<BookingGoodsStatusDto>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//货物状态
|
|
|
|
|
dto.GoodsStatus = await _goodsStatus.AsQueryable().Filter(null, true).Where(x => x.bookingId == item.Id).InnerJoin<BookingGoodsStatusConfig>((t, d) => t.ConfigId == d.Id).Select((t, d) => new BookingGoodsStatusDto
|
|
|
|
|
{
|
|
|
|
|
StatusName = d.StatusName,
|
|
|
|
|
FinishTime = t.FinishTime,
|
|
|
|
|
Remark = t.Remark,
|
|
|
|
|
ExtData = t.ExtData
|
|
|
|
|
}).Distinct().ToListAsync();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//等拓展数据
|
|
|
|
|
var extData = await _repextendstate.AsQueryable().Filter(null, true).FirstAsync(x => x.bookingId == item.Id);
|
|
|
|
|
if (extData != null)
|
|
|
|
|
{
|
|
|
|
|
dto.ExtendState = extData.Adapt<BookingExtendStateDto>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//提箱返场
|
|
|
|
|
var statusloglist = _repStatuslog.AsQueryable().Filter(null, true).Where(x => x.BookingId == item.Id && x.IsDeleted == false && x.Category == "yunzong").ToList();
|
|
|
|
|
var statuslogId = statusloglist.Select(x => x.Id).ToList();
|
|
|
|
|
//运踪状态详情
|
|
|
|
|
var statuslogdetaillist = _statuslogdetail.AsQueryable().Where(x => statuslogId.Contains(x.PId)).ToList();
|
|
|
|
|
var staLogListDto = statusloglist.Adapt<List<BookingStatusLogSyncDto>>();
|
|
|
|
|
dto.StatusLogs = staLogListDto;
|
|
|
|
|
foreach (var sl in dto.StatusLogs)
|
|
|
|
|
{
|
|
|
|
|
var detailList = statuslogdetaillist.Where(x => x.PId == sl.Id).ToList();
|
|
|
|
|
sl.Details = detailList.Adapt<List<BookingStatusLogDetailSyncDto>>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var childrens = await _rep.AsQueryable().Filter(null, true).Where(x => x.ParentId == item.Id && x.TenantId == UserManager.TENANT_ID && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
dto.childrens = childrens.Adapt<List<Children>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var files = await _bookingfile.AsQueryable().Filter(null, true).Where(x => x.BookingId == item.Id).ToListAsync();
|
|
|
|
|
dto.Files = files.Select(x => new ReceiveBcInfoDto.DownloadFile()
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
FileName = x.FileName,
|
|
|
|
|
FileType = x.TypeCode,
|
|
|
|
|
FilePath = x.FilePath
|
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
|
|
foreach (var childitem in dto.childrens)
|
|
|
|
|
{
|
|
|
|
|
var ctnInputs = await _repCtn.AsQueryable().Filter(null, true).Where(x => x.BILLID == childitem.Id && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
childitem.ctnInputs = ctnInputs.Adapt<List<BookingCtnDto>>();
|
|
|
|
|
|
|
|
|
|
foreach (var it in childitem.ctnInputs)
|
|
|
|
|
{
|
|
|
|
|
var ctnDetailInputs = await _ctndetailrep.AsQueryable().Filter(null, true).Where(x => x.CTNID == it.Id && x.IsDeleted == false).ToListAsync();
|
|
|
|
|
it.ctnDetailInputs = ctnDetailInputs.Adapt<List<BookingCtnDetailDto>>();
|
|
|
|
|
}
|
|
|
|
|
var childBookingEDIExt = await _bookingEDIExt.AsQueryable().Filter(null, true).Where(x => x.BookingId == childitem.Id && x.IsDeleted == false).FirstAsync();
|
|
|
|
|
if (childBookingEDIExt != null)
|
|
|
|
|
{
|
|
|
|
|
childitem.BookingEDIExt = childBookingEDIExt.Adapt<BookingEDIExtDto>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = dto.ToJsonString();
|
|
|
|
|
json = $"[{json}]";
|
|
|
|
|
_logger.Info($"Id:{item.Id},订舱数据回推,消息内容:{json}");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
string MqActionExchangeName = AppSetting.app(new string[] { "SyncDongSheng7", "MQConfig" }); //djy.output.dingcang.ds6
|
|
|
|
|
string MqActionQueueName = AppSetting.app(new string[] { "SyncDongSheng7", "MQConfig" }); //djy.output.dingcang.ds6
|
|
|
|
|
|
|
|
|
|
//ConnectionFactory factory = new ConnectionFactory();
|
|
|
|
|
//factory.Uri = new Uri(BookingOrderMQUri);
|
|
|
|
|
|
|
|
|
|
//using (IConnection conn = factory.CreateConnection())
|
|
|
|
|
//{
|
|
|
|
|
// IModel mqModel = conn.CreateModel();
|
|
|
|
|
// mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct);
|
|
|
|
|
// var queueName = $"{MqActionQueueName}.{(item.SubTenantId.HasValue && item.SubTenantId > 0 ? item.SubTenantId.Value : item.TenantId)}";
|
|
|
|
|
// mqModel.QueueDeclare(queueName, false, false, false, null);
|
|
|
|
|
// mqModel.QueueBind(queueName, MqActionExchangeName, queueName, null);
|
|
|
|
|
// byte[] messageBodyBytes = Encoding.UTF8.GetBytes(SharpZipLib.Compress(json));
|
|
|
|
|
// IBasicProperties props = mqModel.CreateBasicProperties();
|
|
|
|
|
// props.DeliveryMode = 2;
|
|
|
|
|
// mqModel.BasicPublish(MqActionExchangeName, queueName, props, messageBodyBytes);
|
|
|
|
|
// conn.Close();
|
|
|
|
|
// _logger.LogInformation($"Id:{item.Id},订舱数据回推,已发送数据到消息队列【{BookingOrderMQUri}】,队列名称:【{queueName}】");
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error(ex.Message, $"Id:{item.Id},订舱数据回推推送过程中出现异常");
|
|
|
|
|
_logger.Error($"Id:{item.Id},订舱数据回推推送过程中出现异常,ex.StackTrace:{ex.StackTrace}");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await SendLetterYard(item.Id);
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
if (order.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
_logger.Info($"{logTitle}未查到订舱数据,结束");
|
|
|
|
|
}
|
|
|
|
|
return order;
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region 放舱推送东胜
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 放舱推送东胜
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public async Task<dynamic> SendLetterYard(long bookingId)
|
|
|
|
|
{
|
|
|
|
|
/*
|
|
|
|
|
var entity = _repLetterYard.AsQueryable().Filter(null, true).First(x => x.BookingId == bookingId && x.IsDeleted == false);
|
|
|
|
|
if (entity != null)
|
|
|
|
|
{
|
|
|
|
|
var json = entity.ToJsonString();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
const string MqActionExchangeName = "djy.output.dingcang.ds6";
|
|
|
|
|
const string MqActionQueueName = "djy.output.dingcang.ds6_fangcang";
|
|
|
|
|
ConnectionFactory factory = new ConnectionFactory();
|
|
|
|
|
factory.Uri = new Uri(_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
using (IConnection conn = factory.CreateConnection())
|
|
|
|
|
{
|
|
|
|
|
IModel mqModel = conn.CreateModel();
|
|
|
|
|
mqModel.ExchangeDeclare(MqActionExchangeName, ExchangeType.Direct);
|
|
|
|
|
var queueName = $"{MqActionQueueName}.{UserManager.TENANT_ID}";
|
|
|
|
|
mqModel.QueueDeclare(queueName, false, false, false, null);
|
|
|
|
|
mqModel.QueueBind(queueName, MqActionExchangeName, queueName, null);
|
|
|
|
|
byte[] messageBodyBytes = Encoding.UTF8.GetBytes(json);
|
|
|
|
|
IBasicProperties props = mqModel.CreateBasicProperties();
|
|
|
|
|
props.DeliveryMode = 2;
|
|
|
|
|
mqModel.BasicPublish(MqActionExchangeName,
|
|
|
|
|
queueName, props,
|
|
|
|
|
messageBodyBytes);
|
|
|
|
|
conn.Close();
|
|
|
|
|
_logger.LogInformation($"放舱数据回推,已发送数据到消息队列【{_cache.GetAllDictData().Result.Where(x => x.Code == "BookingOrderMQUri").Select(x => x.Value).FirstOrDefault()}】,数据内容:【{json}】");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError(ex.Message);
|
|
|
|
|
_logger.LogError(ex.StackTrace);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|