using MapsterMapper; using MediatR; using Sharing.Notifications.XieTong; using Sharing.Province.Dtos.XieTong.Send; using Sharing.Province.XieTong.Send; namespace Sharing.Province.Handlers.XieTong { /// /// 服务工单上报 /// public class SendCaseInfoHandler : INotificationHandler { private readonly IChannelConfigurationManager _channelConfigurationManager; private readonly PusherProvider _pusherProvider; private readonly IMapper _mapper; private readonly ISendCaseInfoRepository _sendCaseInfoRepository; /// /// /// /// /// /// /// public SendCaseInfoHandler(IChannelConfigurationManager channelConfigurationManager, PusherProvider pusherProvider, IMapper mapper , ISendCaseInfoRepository sendCaseInfoRepository) { _channelConfigurationManager = channelConfigurationManager; _pusherProvider = pusherProvider; _mapper = mapper; _sendCaseInfoRepository = sendCaseInfoRepository; } /// /// 服务工单上报 /// /// /// /// public async Task Handle(SendCaseInfoNotification notification, CancellationToken cancellationToken = default) { var pusher = _pusherProvider.CreatePusher(_channelConfigurationManager); var dataReceive = _mapper.Map(notification.Data); var request = new SendCaseInfoRequest(); request.SetData(dataReceive); var response = await pusher.PushSendCaseInfoAsync(request, cancellationToken); //如果推送成功修改数据状态 if (response != null) { if (response.Code == "1") notification.Data.SyncState = "1"; else notification.Data.SyncState = "2"; notification.Data.ReturnResult = Newtonsoft.Json.JsonConvert.SerializeObject(response); await _sendCaseInfoRepository.UpdateAsync(notification.Data); } } } }