using System.Text; using BSI.Stack.Rabbit; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.TrackPush; using SJZY.Track.Application.Contract.Events; using SJZY.Track.Application.Contract.Services; namespace SJZY.Track.Application.Services.Broadcasting; /// /// 广播服务 /// public class BroadcastingService : IBroadcastingService { private readonly RabbitClientBus _rabbitClientBus; public BroadcastingService(RabbitClientBus rabbitClientBus) { _rabbitClientBus = rabbitClientBus; } /// /// 轨迹变更广播 /// /// /// 轨迹内容中的是否对外 /// 子系统代码 /// 轨迹状态代码 /// public void TrackChangePublicTopic(TrackUpsertEvent eto, bool contentIsExternal, string subSystemCode, string trackStatusCode) { var data = new TrackChangeEto { EstimatedDeliveryDate = eto.EstimatedDeliveryDate, TrackPlacePostcode = eto.TrackPlacePostcode, TrackPlaceNation = eto.TrackPlaceNation, TrackPlaceNationId = eto.TrackPlaceNationId, TrackPlaceProvince = eto.TrackPlaceProvince, TrackPlaceProvinceId = eto.TrackPlaceProvinceId, TrackPlaceCity = eto.TrackPlaceCity, TrackPlaceCityId = eto.TrackPlaceCityId, Files = eto.Files, Remarks = eto.Remarks, Source = eto.Source, IsVisibility = eto.IsVisibility, IsExternal = eto.IsExternal ?? contentIsExternal, TrackTimeZone = eto.TrackTimeZone, TrackTime = eto.NewTrackTime ?? eto.TrackTime, TrackPlace = eto.TrackPlace, TrackStatusCode = trackStatusCode, OrderNo = eto.OrderIdentifiers.First().OrderNo, EnStatus = eto.EnStatus, Content = eto.Content, TrackCode = eto.TrackCode, OperationMan = eto.OperationMan, OrderIdentifiers = eto.OrderIdentifiers, CustomId = eto.CustomId, SubSystemId = eto.SubSystemId, Extra = eto.Extra }; if (eto.IsAdd) data.Option = 1; else data.Option = 3; _rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{subSystemCode}", Encoding.UTF8.GetBytes(data.ToJson())); } public void TrackChangePublicTopic(TrackChangeEto eto, string subSystemCode) { eto.Option = 2; _rabbitClientBus.Publish(GlobalConst.TrackChangeExchange, $"TrackChange.{subSystemCode}", Encoding.UTF8.GetBytes(eto.ToJson())); } /// /// 轨迹推送完成广播 /// /// /// public void TrackPushCompletedPublicTopic(TrackPushRecordDto log) { var data = new TrackPushCompletedEvent { RequestId = log.RequestId, IsSuccess = log.IsSuccess, Message = log.Message, OperationMan = log.OperationMan, PushTime = log.PushTime, OptionType = log.OptionType, IsManualPush = log.IsManualPush, //操作人不为系统用户,则认为是仍推送 PushContent = log.PushContent, OrderNo = log.OrderNo, TrackStatus = log.TrackStatus, TrackContent = log.TrackContent, TrackTimeZone = log.TrackTimeZone, TrackTime = log.TrackTime, TrackPlace = log.TrackPlace, TrackCode = log.TrackCode, Extra = log.Extra }; _rabbitClientBus.Publish(GlobalConst.TrackPushExchange, $"TrackPush.{log.SubSystemCode}", Encoding.UTF8.GetBytes(data.ToJson())); } public void TrackPushFailedPubilcTopic(TrackPushRecordDto log) { //暂时使用推送完成模型,后续可能会出现有区分度的模型 TrackPushCompletedPublicTopic(log); } }