初步完成轨迹推送
This commit is contained in:
parent
f39cd3421c
commit
80e6cc0c53
@ -2,6 +2,11 @@
|
||||
|
||||
public class TrackPushAfterUpdateOrderEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// 操作类型
|
||||
/// </summary>
|
||||
public OptionType OptionType { get; set; } = OptionType.新增;
|
||||
|
||||
/// <summary>
|
||||
/// 订单Id
|
||||
/// </summary>
|
||||
@ -13,12 +18,12 @@ public class TrackPushAfterUpdateOrderEvent
|
||||
public int TrackContentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// 问题类型
|
||||
/// </summary>
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最新描述
|
||||
/// 问题描述
|
||||
/// </summary>
|
||||
public string? Message { get; set; }
|
||||
}
|
||||
@ -68,7 +68,7 @@ public class TrackPushEvent
|
||||
public string? ExpandFieldsValue { get; set; }
|
||||
|
||||
/// <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.Domain.Aggregates.OrderAggregate;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
using SJZY.Track.Domain.Enums;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.EventHandlers;
|
||||
@ -21,16 +22,29 @@ public class TrackPushAfterUpdateOrderEventHandler : ITransientDependency, ICapS
|
||||
var order = await _orderRepository.GetFirstAsync(x => x.Id == @event.OrderId);
|
||||
if (order == default) return;
|
||||
|
||||
// 异常:最近一条推送是失败
|
||||
// 预警:添加一条推送距离现在超过12h
|
||||
// if (!@event.IsSuccess)
|
||||
// {
|
||||
// order.QuestionType = TrackPushProblemType.Error;
|
||||
// }
|
||||
/*
|
||||
* 异常:最近一条推送是失败
|
||||
*/
|
||||
if (!@event.IsSuccess)
|
||||
{
|
||||
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
|
||||
{
|
||||
x.LatestPushTrackContentId, x.QuestionType
|
||||
x.LatestPushTrackContentId, x.QuestionType, x.ProblemDescription, x.LatestPushTime
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -25,24 +25,54 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
[CapSubscribe(GlobalConst.TrackPushSubscribe)]
|
||||
public async Task ConsumerAsync(TrackPushEvent @event)
|
||||
{
|
||||
InterfaceRelayUnifyResultDto res = null!;
|
||||
switch (@event.OptionType)
|
||||
{
|
||||
case OptionType.无:
|
||||
break;
|
||||
return;
|
||||
case OptionType.新增:
|
||||
await PushAddAsync(@event);
|
||||
res = await PushAddAsync(@event);
|
||||
break;
|
||||
case OptionType.删除:
|
||||
break;
|
||||
case OptionType.修改:
|
||||
await PushUpdateAsync(@event);
|
||||
res = await PushUpdateAsync(@event);
|
||||
break;
|
||||
default:
|
||||
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
|
||||
{
|
||||
@ -68,33 +98,10 @@ public class TrackPushEventHandler : ITransientDependency, ICapSubscribe
|
||||
var res = await _httpClientProxy.Service.ForwardWithSubscribeAsync(InterfaceRelayConst.PushTrackInterfaceCode,
|
||||
@event.ServiceProviderCode, data);
|
||||
|
||||
var isSuccess = res.Code == InterfaceRelayConst.SuccessCode;
|
||||
// 写推送日志
|
||||
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
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
private async Task PushUpdateAsync(TrackPushEvent @event)
|
||||
private async Task<InterfaceRelayUnifyResultDto> PushUpdateAsync(TrackPushEvent @event)
|
||||
{
|
||||
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);
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@ -74,7 +74,7 @@ public class TrackPullService : ApplicationService
|
||||
/// <returns></returns>
|
||||
[AllowAnonymous]
|
||||
[HttpPost("Track/RefreshForTask")]
|
||||
public async Task<bool> RefreshTrackAsync()
|
||||
public async Task<bool> RefreshForTaskAsync()
|
||||
{
|
||||
var configs = await _trackPullCacheService.GetAllPullConfigsAsync();
|
||||
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.TrackDetailsAggregate;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
using SJZY.Track.Domain.Enums;
|
||||
using SJZY.UserCenter.HttpApi.Services;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ProvideServices;
|
||||
@ -86,7 +87,7 @@ public class TrackPushService : ApplicationService
|
||||
TrackEnContentValue = config.TrackEnContentValue,
|
||||
TrackStatusValue = config.TrackStatusValue,
|
||||
ExpandFieldsValue = config.ExpandFieldsValue,
|
||||
PushMan = CurrentUserRequest.CurrentUser.Name,
|
||||
OperationMan = CurrentUserRequest.CurrentUser.Name,
|
||||
};
|
||||
|
||||
await _capPublisher.PublishAsync(GlobalConst.TrackPushSubscribe, trackPushEvent);
|
||||
@ -96,4 +97,23 @@ public class TrackPushService : ApplicationService
|
||||
|
||||
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")]
|
||||
public int? LatestPushTrackContentId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最新推送时间(异步维护)
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "LatestPushTime")]
|
||||
public DateTime? LatestPushTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 最新轨迹内容(异步维护)
|
||||
/// </summary>
|
||||
@ -115,10 +121,10 @@ public class OrderEntity : IFullAuditedBasicEntitys, IAggregateRoot
|
||||
public int QuestionType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 问题描述(主数据枚举TrackProblemDescription)
|
||||
/// 问题描述
|
||||
/// </summary>
|
||||
[SugarColumn(ColumnName = "ProblemDescription")]
|
||||
public int ProblemDescription { get; set; }
|
||||
public string? ProblemDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 起运港口
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
using Nest;
|
||||
using SJZY.Expand.ABP.Common.Enums;
|
||||
using SJZY.Expand.ElasticSearch;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
|
||||
@ -18,10 +17,20 @@ public class TrackPushRecordIndex : IdBaseIndex
|
||||
/// </summary>
|
||||
public Guid RequestId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 信息
|
||||
/// </summary>
|
||||
public string Message { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 操作类型
|
||||
/// </summary>
|
||||
public OptionType OptionType { get; set; }
|
||||
public string OptionType { get; set; } = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 是否自动推送
|
||||
/// </summary>
|
||||
public bool IsAuto { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 轨迹发生地
|
||||
|
||||
@ -1,10 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SJZY.Track.Domain.Dtos.Order
|
||||
namespace SJZY.Track.Domain.Dtos.Order
|
||||
{
|
||||
public class GetPageTrackOrderInputVO : PageInfoInput
|
||||
{
|
||||
@ -97,7 +91,7 @@ namespace SJZY.Track.Domain.Dtos.Order
|
||||
/// <summary>
|
||||
/// 客户id
|
||||
/// </summary>
|
||||
public int CustomerId { get; set; }
|
||||
public int CustomerId { get; set; }
|
||||
|
||||
///// <summary>
|
||||
///// 订单明细(json)
|
||||
@ -162,7 +156,7 @@ namespace SJZY.Track.Domain.Dtos.Order
|
||||
/// <summary>
|
||||
/// 问题描述(主数据枚举TrackProblemDescription)
|
||||
/// </summary>
|
||||
public int ProblemDescription { get; set; }
|
||||
public string? ProblemDescription { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 问题描述名称
|
||||
|
||||
@ -73,15 +73,6 @@ public class TrackOrderQueries : ISugarRepository, ITrackOrderQueries,
|
||||
QuestionTypeName = SqlFunc.IF(a.QuestionType == 1).Return("异常").ElseIF(a.QuestionType == 2).Return("预警")
|
||||
.End(""),
|
||||
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,
|
||||
NewestTrackEnContent = a.LatestTrackEnContent,
|
||||
NewestTrackPlace = a.LatestTrackPlace,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user