初步完成轨迹推送
This commit is contained in:
parent
f39cd3421c
commit
80e6cc0c53
@ -2,6 +2,11 @@
|
|||||||
|
|
||||||
public class TrackPushAfterUpdateOrderEvent
|
public class TrackPushAfterUpdateOrderEvent
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 操作类型
|
||||||
|
/// </summary>
|
||||||
|
public OptionType OptionType { get; set; } = OptionType.新增;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 订单Id
|
/// 订单Id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -13,12 +18,12 @@ public class TrackPushAfterUpdateOrderEvent
|
|||||||
public int TrackContentId { get; set; }
|
public int TrackContentId { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否成功
|
/// 问题类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsSuccess { get; set; }
|
public bool IsSuccess { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最新描述
|
/// 问题描述
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? Message { get; set; }
|
public string? Message { get; set; }
|
||||||
}
|
}
|
||||||
@ -68,7 +68,7 @@ public class TrackPushEvent
|
|||||||
public string? ExpandFieldsValue { get; set; }
|
public string? ExpandFieldsValue { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 推送人
|
/// 操作人
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? PushMan { get; set; }
|
public string? OperationMan { get; set; }
|
||||||
}
|
}
|
||||||
@ -2,6 +2,7 @@
|
|||||||
using SJZY.Track.Application.Contract.Events;
|
using SJZY.Track.Application.Contract.Events;
|
||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
using SJZY.Track.Domain.Consts;
|
using SJZY.Track.Domain.Consts;
|
||||||
|
using SJZY.Track.Domain.Enums;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
|
|
||||||
namespace SJZY.Track.Application.EventHandlers;
|
namespace SJZY.Track.Application.EventHandlers;
|
||||||
@ -21,16 +22,29 @@ public class TrackPushAfterUpdateOrderEventHandler : ITransientDependency, ICapS
|
|||||||
var order = await _orderRepository.GetFirstAsync(x => x.Id == @event.OrderId);
|
var order = await _orderRepository.GetFirstAsync(x => x.Id == @event.OrderId);
|
||||||
if (order == default) return;
|
if (order == default) return;
|
||||||
|
|
||||||
// 异常:最近一条推送是失败
|
/*
|
||||||
// 预警:添加一条推送距离现在超过12h
|
* 异常:最近一条推送是失败
|
||||||
// if (!@event.IsSuccess)
|
*/
|
||||||
// {
|
if (!@event.IsSuccess)
|
||||||
// order.QuestionType = TrackPushProblemType.Error;
|
{
|
||||||
// }
|
order.QuestionType = (int)TrackPushProblemType.Error;
|
||||||
|
order.ProblemDescription = @event.Message;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
order.QuestionType = (int)TrackPushProblemType.None;
|
||||||
|
if (@event.OptionType == OptionType.新增)
|
||||||
|
{
|
||||||
|
// tips:只有新增会影响推送进度?
|
||||||
|
order.LatestPushTrackContentId = @event.TrackContentId;
|
||||||
|
order.LatestPushTime = DateTime.Now;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
await _orderRepository.UpdateColumnAsync(order, x => new
|
await _orderRepository.UpdateColumnAsync(order, x => new
|
||||||
{
|
{
|
||||||
x.LatestPushTrackContentId, x.QuestionType
|
x.LatestPushTrackContentId, x.QuestionType, x.ProblemDescription, x.LatestPushTime
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -25,24 +25,54 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
[CapSubscribe(GlobalConst.TrackPushSubscribe)]
|
[CapSubscribe(GlobalConst.TrackPushSubscribe)]
|
||||||
public async Task ConsumerAsync(TrackPushEvent @event)
|
public async Task ConsumerAsync(TrackPushEvent @event)
|
||||||
{
|
{
|
||||||
|
InterfaceRelayUnifyResultDto res = null!;
|
||||||
switch (@event.OptionType)
|
switch (@event.OptionType)
|
||||||
{
|
{
|
||||||
case OptionType.无:
|
case OptionType.无:
|
||||||
break;
|
return;
|
||||||
case OptionType.新增:
|
case OptionType.新增:
|
||||||
await PushAddAsync(@event);
|
res = await PushAddAsync(@event);
|
||||||
break;
|
break;
|
||||||
case OptionType.删除:
|
case OptionType.删除:
|
||||||
break;
|
break;
|
||||||
case OptionType.修改:
|
case OptionType.修改:
|
||||||
await PushUpdateAsync(@event);
|
res = await PushUpdateAsync(@event);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentOutOfRangeException();
|
throw new ArgumentOutOfRangeException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var isSuccess = res.Code == InterfaceRelayConst.SuccessCode;
|
||||||
|
|
||||||
|
// 写推送日志
|
||||||
|
await _trackPushRecordsRepository.AddAsync(new TrackPushRecordIndex
|
||||||
|
{
|
||||||
|
IndexName = $"{GlobalConst.TrackPushRecordsIndex}-{DateTime.Now:yyyy.MM.dd}",
|
||||||
|
RequestId = res.RequestId,
|
||||||
|
Message = res.Msg,
|
||||||
|
OptionType = @event.OptionType.ToString(),
|
||||||
|
TrackPlace = @event.TrackPlace,
|
||||||
|
TrackTime = @event.TrackTime,
|
||||||
|
TrackTimeZone = @event.TrackTimeZone,
|
||||||
|
IsSuccess = isSuccess,
|
||||||
|
IsAuto = @event.OperationMan == null,
|
||||||
|
CreateUser = @event.OperationMan ?? "系统",
|
||||||
|
CreateTime = DateTime.Now
|
||||||
|
});
|
||||||
|
|
||||||
|
// 更新订单主表(异步)
|
||||||
|
await _capPublisher.PublishAsync(GlobalConst.TrackPushAfterUpdateOrderSubscribe,
|
||||||
|
new TrackPushAfterUpdateOrderEvent
|
||||||
|
{
|
||||||
|
OptionType = @event.OptionType,
|
||||||
|
OrderId = @event.OrderId,
|
||||||
|
TrackContentId = @event.TrackContentId,
|
||||||
|
IsSuccess = isSuccess,
|
||||||
|
Message = res.Msg
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PushAddAsync(TrackPushEvent @event)
|
private async Task<InterfaceRelayUnifyResultDto> PushAddAsync(TrackPushEvent @event)
|
||||||
{
|
{
|
||||||
var data = new
|
var data = new
|
||||||
{
|
{
|
||||||
@ -68,33 +98,10 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode,
|
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode,
|
||||||
@event.ServiceProviderCode, data);
|
@event.ServiceProviderCode, data);
|
||||||
|
|
||||||
var isSuccess = res.Code == InterfaceRelayConst.SuccessCode;
|
return res;
|
||||||
// 写推送日志
|
|
||||||
await _trackPushRecordsRepository.AddAsync(new TrackPushRecordIndex
|
|
||||||
{
|
|
||||||
IndexName = $"{GlobalConst.TrackPushRecordsIndex}-{DateTime.Now:yyyy.MM.dd}",
|
|
||||||
RequestId = res.RequestId,
|
|
||||||
OptionType = OptionType.新增,
|
|
||||||
TrackPlace = @event.TrackPlace,
|
|
||||||
TrackTime = @event.TrackTime,
|
|
||||||
TrackTimeZone = @event.TrackTimeZone,
|
|
||||||
IsSuccess = isSuccess,
|
|
||||||
CreateUser = @event.PushMan ?? "系统",
|
|
||||||
CreateTime = DateTime.Now
|
|
||||||
});
|
|
||||||
|
|
||||||
// 更新订单主表
|
|
||||||
await _capPublisher.PublishAsync(GlobalConst.TrackPushAfterUpdateOrderSubscribe,
|
|
||||||
new TrackPushAfterUpdateOrderEvent
|
|
||||||
{
|
|
||||||
OrderId = @event.OrderId,
|
|
||||||
TrackContentId = @event.TrackContentId,
|
|
||||||
IsSuccess = isSuccess,
|
|
||||||
Message = res.Msg
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task PushUpdateAsync(TrackPushEvent @event)
|
private async Task<InterfaceRelayUnifyResultDto> PushUpdateAsync(TrackPushEvent @event)
|
||||||
{
|
{
|
||||||
var data = new
|
var data = new
|
||||||
{
|
{
|
||||||
@ -117,7 +124,9 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.TrackUpdateInterfaceCode,
|
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.TrackUpdateInterfaceCode,
|
||||||
@event.ServiceProviderCode, data);
|
@event.ServiceProviderCode, data);
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ public class TrackPullService : ApplicationService
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[AllowAnonymous]
|
[AllowAnonymous]
|
||||||
[HttpPost("Track/RefreshForTask")]
|
[HttpPost("Track/RefreshForTask")]
|
||||||
public async Task<bool> RefreshTrackAsync()
|
public async Task<bool> RefreshForTaskAsync()
|
||||||
{
|
{
|
||||||
var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
|
var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
|
||||||
foreach (var config in configs)
|
foreach (var config in configs)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ using SJZY.Track.Application.Contract.Services;
|
|||||||
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
||||||
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
using SJZY.Track.Domain.Aggregates.TrackDetailsAggregate;
|
||||||
using SJZY.Track.Domain.Consts;
|
using SJZY.Track.Domain.Consts;
|
||||||
|
using SJZY.Track.Domain.Enums;
|
||||||
using SJZY.UserCenter.HttpApi.Services;
|
using SJZY.UserCenter.HttpApi.Services;
|
||||||
|
|
||||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||||
@ -86,7 +87,7 @@ public class TrackPushService : ApplicationService
|
|||||||
TrackEnContentValue = config.TrackEnContentValue,
|
TrackEnContentValue = config.TrackEnContentValue,
|
||||||
TrackStatusValue = config.TrackStatusValue,
|
TrackStatusValue = config.TrackStatusValue,
|
||||||
ExpandFieldsValue = config.ExpandFieldsValue,
|
ExpandFieldsValue = config.ExpandFieldsValue,
|
||||||
PushMan = CurrentUserRequest.CurrentUser.Name,
|
OperationMan = CurrentUserRequest.CurrentUser.Name,
|
||||||
};
|
};
|
||||||
|
|
||||||
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);
|
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);
|
||||||
@ -96,4 +97,23 @@ public class TrackPushService : ApplicationService
|
|||||||
|
|
||||||
return $"即将推送轨迹代码{input.TrackCode}给{res}个订单";
|
return $"即将推送轨迹代码{input.TrackCode}给{res}个订单";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 定时任务推送预警(》12小时没有推送的)
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
[HttpPost("Track/PushWarnForTask")]
|
||||||
|
public async Task<string> PushWarnForTaskAsync()
|
||||||
|
{
|
||||||
|
var time = DateTime.Now.Subtract(TimeSpan.FromHours(12));
|
||||||
|
var orders = await _orderRepository.GetListAsync(x =>
|
||||||
|
!x.IsCompleted && x.QuestionType == 0 && x.LatestPushTime < time);
|
||||||
|
|
||||||
|
orders.ForEach(x => { x.QuestionType = (int)TrackPushProblemType.Warn; });
|
||||||
|
|
||||||
|
await _orderRepository.UpdateRangeAsync(orders, x => new { x.QuestionType });
|
||||||
|
|
||||||
|
return $"成功将{orders.Select(x => x.OrderNo).JoinAsString(",")}置为预警单";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -48,6 +48,12 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
|
|||||||
[SugarColumn(ColumnName = "LatestPushTrackContentId")]
|
[SugarColumn(ColumnName = "LatestPushTrackContentId")]
|
||||||
public int? LatestPushTrackContentId { get; set; }
|
public int? LatestPushTrackContentId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 最新推送时间(异步维护)
|
||||||
|
/// </summary>
|
||||||
|
[SugarColumn(ColumnName = "LatestPushTime")]
|
||||||
|
public DateTime? LatestPushTime { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最新轨迹内容(异步维护)
|
/// 最新轨迹内容(异步维护)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -115,10 +121,10 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
|
|||||||
public int QuestionType { get; set; }
|
public int QuestionType { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 问题描述(主数据枚举TrackProblemDescription)
|
/// 问题描述
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[SugarColumn(ColumnName = "ProblemDescription")]
|
[SugarColumn(ColumnName = "ProblemDescription")]
|
||||||
public int ProblemDescription { get; set; }
|
public string? ProblemDescription { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 起运港口
|
/// 起运港口
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using Nest;
|
using Nest;
|
||||||
using SJZY.Expand.ABP.Common.Enums;
|
|
||||||
using SJZY.Expand.ElasticSearch;
|
using SJZY.Expand.ElasticSearch;
|
||||||
using SJZY.Track.Domain.Consts;
|
using SJZY.Track.Domain.Consts;
|
||||||
|
|
||||||
@ -18,10 +17,20 @@ public class TrackPushRecordIndex : IdBaseIndex
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public Guid RequestId { get; set; }
|
public Guid RequestId { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 信息
|
||||||
|
/// </summary>
|
||||||
|
public string Message { get; set; } = null!;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 操作类型
|
/// 操作类型
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public OptionType OptionType { get; set; }
|
public string OptionType { get; set; } = null!;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 是否自动推送
|
||||||
|
/// </summary>
|
||||||
|
public bool IsAuto { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 轨迹发生地
|
/// 轨迹发生地
|
||||||
|
|||||||
@ -1,10 +1,4 @@
|
|||||||
using System;
|
namespace SJZY.Track.Domain.Dtos.Order
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace SJZY.Track.Domain.Dtos.Order
|
|
||||||
{
|
{
|
||||||
public class GetPageTrackOrderInputVO : PageInfoInput
|
public class GetPageTrackOrderInputVO : PageInfoInput
|
||||||
{
|
{
|
||||||
@ -97,7 +91,7 @@ namespace SJZY.Track.Domain.Dtos.Order
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 客户id
|
/// 客户id
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int CustomerId { get; set; }
|
public int CustomerId { get; set; }
|
||||||
|
|
||||||
///// <summary>
|
///// <summary>
|
||||||
///// 订单明细(json)
|
///// 订单明细(json)
|
||||||
@ -162,11 +156,11 @@ namespace SJZY.Track.Domain.Dtos.Order
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 问题描述(主数据枚举TrackProblemDescription)
|
/// 问题描述(主数据枚举TrackProblemDescription)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int ProblemDescription { get; set; }
|
public string? ProblemDescription { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 问题描述名称
|
/// 问题描述名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? ProblemDescriptionName { get; set; }
|
public string? ProblemDescriptionName { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -73,15 +73,6 @@ public class TrackOrderQueries : ISugarRepository, ITrackOrderQueries,
|
|||||||
QuestionTypeName = SqlFunc.IF(a.QuestionType == 1).Return("异常").ElseIF(a.QuestionType == 2).Return("预警")
|
QuestionTypeName = SqlFunc.IF(a.QuestionType == 1).Return("异常").ElseIF(a.QuestionType == 2).Return("预警")
|
||||||
.End(""),
|
.End(""),
|
||||||
ProblemDescription = a.ProblemDescription,
|
ProblemDescription = a.ProblemDescription,
|
||||||
ProblemDescriptionName = SqlFunc.IF(a.ProblemDescription == 1).Return("推送异常")
|
|
||||||
.ElseIF(a.ProblemDescription == 2).Return("推送预警").End(""),
|
|
||||||
//TrackTemplateNames = SqlFunc.Subqueryable<OrderTemplateEntity>()
|
|
||||||
// .LeftJoin<TrackTemplateEntity>((aa, bb) => aa.TrackTemplateId == bb.Id)
|
|
||||||
// .Where((aa, bb) => a.Id == aa.OrderId).SelectStringJoin((aa, bb) => bb.Name, ","),
|
|
||||||
|
|
||||||
//TrackTemplateIds = SqlFunc.Subqueryable<OrderTemplateEntity>()
|
|
||||||
// .LeftJoin<TrackTemplateEntity>((aa, bb) => aa.TrackTemplateId == bb.Id)
|
|
||||||
// .Where((aa, bb) => a.Id == aa.OrderId).SelectStringJoin((aa, bb) => bb.Id, ","),
|
|
||||||
NewestTrackContent = a.LatestTrackContent,
|
NewestTrackContent = a.LatestTrackContent,
|
||||||
NewestTrackEnContent = a.LatestTrackEnContent,
|
NewestTrackEnContent = a.LatestTrackEnContent,
|
||||||
NewestTrackPlace = a.LatestTrackPlace,
|
NewestTrackPlace = a.LatestTrackPlace,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user