1122222eee

This commit is contained in:
xiaolipro 2025-08-04 17:46:29 +08:00
parent cd475c0b19
commit be1a18dfcb
21 changed files with 222 additions and 654 deletions

View File

@ -0,0 +1,43 @@
using TrackCenter.Domain.VEntities;
namespace TrackCenter.Application.Caching;
/// <summary>
/// 系统id中文名称字典缓存
/// </summary>
public class AppNameDictCache : BasicCacheForPeriodicRefresh<string, string>, ISingletonDependency
{
private readonly IBasicRepository<VAppEntity> _appRepository;
public AppNameDictCache(IBasicRepository<VAppEntity> appRepository) : base(RedisHelper.Client)
{
_appRepository = appRepository;
}
protected override string BuildRedisKey(string key) => $"{GlobalConst.TrackDataDictKeyPrefix}:AppName:{key}";
protected override TimeSpan RedisExpire => TimeSpan.FromSeconds(-1); // 设置缓存不过期,指定id系统被删除时仍能兜底提供系统中文名
protected override TimeSpan LocalExpire => TimeSpan.FromMinutes(10); // 本地缓存10分钟过期后在次请求会刷新数据
protected override TimeSpan MissingKeySetNullRedisExpire => TimeSpan.FromMinutes(1); // 缓存不存在时设置redisNull
protected override async ValueTask<string?> LoadAsync(string key)
{
if (key.IsNullOrEmpty()) return null;
return await _appRepository.GetFirstAsync(x => x.AppKey == key, x => x.Name);
}
protected override async ValueTask<Dictionary<string, string>> LoadAsync(HashSet<string> keys)
{
if (keys.Count == 0) return Empty<string, string>.Dict;
var result = await _appRepository.GetListAsync(x => keys.Contains(x.AppKey), x => new
{
x.AppKey,
x.Name
});
return result.Count == 0
? Empty<string, string>.Dict
: result.ToDictionary(x => x.AppKey, y => y.Name);
}
}

View File

@ -6,14 +6,4 @@ public class GetDetailTimelineInput
/// 订单编号 /// 订单编号
/// </summary> /// </summary>
public string OrderNumber { get; set; } public string OrderNumber { get; set; }
/// <summary>
/// 订单所属应用
/// </summary>
public string AppKey { get; set; }
/// <summary>
/// 当前用户登陆应用
/// </summary>
public int CurrenUserAppKey { get; set; }
} }

View File

@ -76,12 +76,6 @@ public class UpdateOrderInput : OrderNoInfo
/// 订单航班信息 /// 订单航班信息
/// </summary> /// </summary>
public List<OrderFlightInfo> FlightInfos { get; set; } = new(); public List<OrderFlightInfo> FlightInfos { get; set; } = new();
/// <summary>
/// 模板code
/// </summary>
public List<string>? TemplateCodes { get; set; }
} }
public class PullConfigInfo public class PullConfigInfo

View File

@ -12,7 +12,7 @@ public class EditTrackPullConfigInput
/// <summary> /// <summary>
/// 应用 /// 应用
/// </summary> /// </summary>
public int? AppKey { get; set; } public string? AppKey { get; set; }
/// <summary> /// <summary>
/// 服务商id /// 服务商id

View File

@ -8,7 +8,7 @@ public class GetWarningRuleInput
/// <summary> /// <summary>
/// 应用 /// 应用
/// </summary> /// </summary>
public int? AppKey { get; set; } public string? AppKey { get; set; }
/// <summary> /// <summary>
/// kpi名称 模糊查询 /// kpi名称 模糊查询

View File

@ -1,98 +0,0 @@
using Fake.DependencyInjection;
using Fake.DomainDrivenDesign.Repositories.SqlSugarCore;
using SqlSugar;
using TrackCenter.Domain.VEntities;
namespace TrackCenter.Repository.Queries;
/// <summary>
/// 时区查询
/// </summary>
public class TimezoneQueries : SqlSugarRootlessRepository<TrackCenterDbContext>, ITransientDependency
{
public ISqlSugarClient Context => GetDbContextAsync().Result;
/// <summary>
/// 获取城市时区
/// </summary>
/// <param name="cityEnName">城市英文名称</param>
/// <returns>时区</returns>
public async Task<string> GetCityTimezone(string cityEnName)
{
var key = GetCityKey(cityEnName);
var timezone = RedisHelper.Client.Get<string>(key);
if (!string.IsNullOrEmpty(timezone))
{
return timezone;
}
var cityTimezone = await GetTimezoneByCityName(cityEnName);
if (cityTimezone == null!)
{
await RedisHelper.Client.SetAsync(key, string.Empty, TimeSpan.FromSeconds(20));
return string.Empty;
}
await RedisHelper.Client.SetAsync(key, cityTimezone.Timezone, TimeSpan.FromHours(24));
return cityTimezone.Timezone;
}
/// <summary>
/// 获取港口时区
/// </summary>
/// <param name="airCode">港口三字码</param>
/// <returns>时区</returns>
public async Task<string> GetPortTimezone(string airCode)
{
var key = GetPortKey(airCode);
var timezone = RedisHelper.Client.Get<string>(key);
if (!string.IsNullOrEmpty(timezone))
{
return timezone;
}
var portTimezone = await GetTimezoneByPortCode(airCode);
if (portTimezone == null!)
{
await RedisHelper.Client.SetAsync(key, string.Empty, TimeSpan.FromSeconds(20));
return string.Empty;
}
await RedisHelper.Client.SetAsync(key, portTimezone.Timezone, TimeSpan.FromHours(24));
return portTimezone.Timezone;
}
private string GetCityKey(string cityEnName)
{
return $"{GlobalConst.CityTimezoneKeyPrefix}:{cityEnName}";
}
private string GetPortKey(string airCode)
{
return $"{GlobalConst.PortTimezoneKeyPrefix}:{airCode}";
}
private Task<CityTimezoneDto> GetTimezoneByCityName(string cityEnName)
{
return Context.Queryable<VCityEntity>().Where(val => !val.IsDeleted && val.EnName == cityEnName)
.Select(val => new CityTimezoneDto()
{
CityEnName = val.EnName,
Timezone = val.TimeZone
})
.FirstAsync();
}
private Task<PortTimezoneDto> GetTimezoneByPortCode(string airCode)
{
return Context.Queryable<VCityEntity>()
.InnerJoin<VAirportEntity>((city, airport) => city.Id == airport.CityId)
.Where((city, airport) => !airport.IsDeleted && !city.IsDeleted && airport.Code == airCode)
.Select((city, airport) => new PortTimezoneDto()
{
PortCode = airport.Code,
Timezone = city.TimeZone
})
.FirstAsync();
}
}

View File

@ -79,7 +79,6 @@ public partial class OrderService : ApplicationServiceBase
order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(input); order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(input);
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos); order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos);
order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos);
order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes);
order.SetThirdPartyOrderNumber(order.OrderPullStatus); order.SetThirdPartyOrderNumber(order.OrderPullStatus);
var orderId = await _orderRepository.CreateOrderAsync(order); var orderId = await _orderRepository.CreateOrderAsync(order);
@ -135,7 +134,6 @@ public partial class OrderService : ApplicationServiceBase
var order2 = ObjectMapper.Map(input2, order); var order2 = ObjectMapper.Map(input2, order);
order2.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input2.FlightInfos); order2.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input2.FlightInfos);
order2.OrderPullStatus = BuiltOrderPullStatus(input2.PullConfigInfos); order2.OrderPullStatus = BuiltOrderPullStatus(input2.PullConfigInfos);
order2.TemplateCodes = input2.TemplateCodes == null ? null : string.Join(',', input2.TemplateCodes);
order2.SetThirdPartyOrderNumber(order.OrderPullStatus); order2.SetThirdPartyOrderNumber(order.OrderPullStatus);
updateOrders.Add(order2); updateOrders.Add(order2);
updateRecords.Add(new OrderOperationRecordIndex updateRecords.Add(new OrderOperationRecordIndex
@ -170,7 +168,6 @@ public partial class OrderService : ApplicationServiceBase
var order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(insertInput); var order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(insertInput);
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(insertInput.FlightInfos); order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(insertInput.FlightInfos);
order.OrderPullStatus = BuiltOrderPullStatus(insertInput.PullConfigInfos); order.OrderPullStatus = BuiltOrderPullStatus(insertInput.PullConfigInfos);
order.TemplateCodes = insertInput.TemplateCodes == null ? null : string.Join(',', insertInput.TemplateCodes);
order.SetThirdPartyOrderNumber(order.OrderPullStatus); order.SetThirdPartyOrderNumber(order.OrderPullStatus);
insertOrders.Add(order); insertOrders.Add(order);
createRecords.Add(new OrderOperationRecordIndex createRecords.Add(new OrderOperationRecordIndex
@ -228,7 +225,6 @@ public partial class OrderService : ApplicationServiceBase
order = ObjectMapper.Map(input, order); order = ObjectMapper.Map(input, order);
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos); order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos);
order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos); order.OrderPullStatus = BuiltOrderPullStatus(input.PullConfigInfos);
order.TemplateCodes = input.TemplateCodes == null ? null : string.Join(',', input.TemplateCodes);
order.SetThirdPartyOrderNumber(order.OrderPullStatus); order.SetThirdPartyOrderNumber(order.OrderPullStatus);
await _orderRepository.UpdateOrderAsync(order); await _orderRepository.UpdateOrderAsync(order);
} }

View File

@ -7,7 +7,6 @@ using TrackCenter.Application.Helpers;
using TrackCenter.Application.Options; using TrackCenter.Application.Options;
using TrackCenter.Domain.Aggregates.OrderAggregate; using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Enums; using TrackCenter.Domain.Enums;
using TrackCenter.Repository.Queries;
namespace TrackCenter.Application.Services.TimerTaskss; namespace TrackCenter.Application.Services.TimerTaskss;
@ -19,14 +18,11 @@ public class TrackButtomUpScanTask : ApplicationServiceBase
{ {
private readonly IOptionsSnapshot<TrackAppOptions> _options; private readonly IOptionsSnapshot<TrackAppOptions> _options;
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly TimezoneQueries _timezoneQueries;
public TrackButtomUpScanTask(IOptionsSnapshot<TrackAppOptions> options, IOrderRepository orderRepository, public TrackButtomUpScanTask(IOptionsSnapshot<TrackAppOptions> options, IOrderRepository orderRepository)
TimezoneQueries timezoneQueries)
{ {
_options = options; _options = options;
_orderRepository = orderRepository; _orderRepository = orderRepository;
_timezoneQueries = timezoneQueries;
} }
/// <summary> /// <summary>
@ -59,52 +55,6 @@ public class TrackButtomUpScanTask : ApplicationServiceBase
return "ok"; return "ok";
} }
/// <summary>
/// 获取轨迹时区
/// </summary>
/// <param name="matchedContentConfig">配置信息</param>
/// <param name="context">订单id</param>
/// <returns>时区,是否执行了兜底轨迹时区</returns>
private async Task<(float? trackTimeZone, bool hasTimezoneBottomLine)> GetTimezone(
TrackPullContentConfigDto? matchedContentConfig,
TrackRefreshContext context)
{
float? trackTimeZone = null;
var hasTimezoneBottomLine = false; // 执行了兜底但是没有兜底住,需要记录
if (matchedContentConfig?.TrackZonePlaceValue is not null)
{
//兜底没配置的就不需要兜底,拉取的发生地没就没
var timezone = await GetTimezone(matchedContentConfig, context.OrderId);
trackTimeZone = timezone;
hasTimezoneBottomLine = !timezone.HasValue;
}
return (trackTimeZone, hasTimezoneBottomLine);
}
/// <summary>
/// 获得轨迹地址
/// </summary>
/// <param name="matchedContentConfig">配置信息</param>
/// <param name="context">订单id</param>
/// <returns>时区,是否执行了兜底轨迹时区</returns>
private async Task<(string? trackPlace, bool hasPlaceBottomLine)> GetTrackPlace(
TrackPullContentConfigDto? matchedContentConfig, TrackRefreshContext context)
{
string? trackPlace = null;
var hasPlaceBottomLine = false; //执行了兜底但是没有兜底住,需要记录
if (matchedContentConfig?.TrackPlaceValue is not null)
{
//兜底没配置的就不需要兜底,拉取的发生地没就没
trackPlace = await GetPlaceByOrder(matchedContentConfig!.TrackPlaceValue.Value, context.OrderId);
hasPlaceBottomLine = string.IsNullOrWhiteSpace(trackPlace);
}
return (trackPlace, hasPlaceBottomLine);
}
/// <summary> /// <summary>
/// 根据订单id获取兜底位置 /// 根据订单id获取兜底位置
/// </summary> /// </summary>
@ -127,33 +77,6 @@ public class TrackButtomUpScanTask : ApplicationServiceBase
return _orderRepository.GetFirstAsync(x => x.Id == orderId, resultExpression); return _orderRepository.GetFirstAsync(x => x.Id == orderId, resultExpression);
} }
/// <summary>
/// 获取时区
/// </summary>
/// <param name="matchedContentConfig"></param>
/// <param name="orderId"></param>
/// <returns></returns>
private async Task<float?> GetTimezone(TrackPullContentConfigDto matchedContentConfig, int orderId)
{
var placeOrCode = await GetPlaceByOrder(matchedContentConfig!.TrackZonePlaceValue.Value, orderId);
string timezone = null;
if (!string.IsNullOrEmpty(placeOrCode))
{
if (matchedContentConfig!.TrackZonePlaceValue.Value == (int) TrackLocationValue.ArrivalPort
|| matchedContentConfig!.TrackZonePlaceValue.Value == (int) TrackLocationValue.LeavePort)
{
timezone = await _timezoneQueries.GetPortTimezone(placeOrCode);
return DateTimeHelper.ConvertTimeZoneToFloat(timezone);
}
timezone = await _timezoneQueries.GetCityTimezone(placeOrCode);
return DateTimeHelper.ConvertTimeZoneToFloat(timezone);
}
return null;
}
/// <summary> /// <summary>
/// 触发了兜底,但是没有兜底住,对订单进行标记 /// 触发了兜底,但是没有兜底住,对订单进行标记
/// 1表示时区,2表示发生地,3表示两种 /// 1表示时区,2表示发生地,3表示两种

View File

@ -1,25 +1,17 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using Fake.Application.Dtos; using Fake.Application.Dtos;
using Microsoft.Extensions.Localization;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Expand.AliyunOSS;
using TrackCenter.Application.Dtos.ProvideServices; using TrackCenter.Application.Dtos.ProvideServices;
using TrackCenter.Application.Dtos.TrackContents; using TrackCenter.Application.Dtos.TrackContents;
using TrackCenter.Application.Helpers; using TrackCenter.Application.Helpers;
using TrackCenter.Application.Helpers.OSS; using TrackCenter.Application.Helpers.OSS;
using TrackCenter.Application.Services;
using TrackCenter.Application.Localization;
using TrackCenter.Application.Services.TrackPush; using TrackCenter.Application.Services.TrackPush;
using TrackCenter.Domain.Aggregates.OrderAggregate; using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Aggregates.TrackContentAggregate; using TrackCenter.Domain.Aggregates.TrackContentAggregate;
using TrackCenter.Domain.Aggregates.TrackDetailsAggregate; using TrackCenter.Domain.Aggregates.TrackDetailsAggregate;
using TrackCenter.Domain.Aggregates.TrackFlagAggregate; using TrackCenter.Domain.Aggregates.TrackFlagAggregate;
using TrackCenter.Domain.Aggregates.TrackStatusAggregate; using TrackCenter.Domain.Aggregates.TrackStatusAggregate;
using TrackCenter.Domain.Aggregates.TrackTemplateAggregate;
using TrackCenter.Domain.Dtos.TrackContents; using TrackCenter.Domain.Dtos.TrackContents;
using TrackCenter.Domain.Enums; using TrackCenter.Domain.Enums;
using TrackCenter.Domain.Queries;
using TrackCenter.Repository; using TrackCenter.Repository;
namespace TrackCenter.Application.Services.TrackContents; namespace TrackCenter.Application.Services.TrackContents;
@ -32,7 +24,6 @@ namespace TrackCenter.Application.Services.TrackContents;
public class TrackContentService : ApplicationServiceBase public class TrackContentService : ApplicationServiceBase
{ {
private readonly ITrackContentRepository _trackContentRepository; private readonly ITrackContentRepository _trackContentRepository;
private readonly ITrackTemplateRepository _trackTemplateRepository;
private readonly IBasicRepository<TrackFlagEntity> _trackFlagBasicQuery; private readonly IBasicRepository<TrackFlagEntity> _trackFlagBasicQuery;
private readonly IBasicRepository<TrackStatusEntity> _trackStatusBasicQuery; private readonly IBasicRepository<TrackStatusEntity> _trackStatusBasicQuery;
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
@ -45,14 +36,13 @@ public class TrackContentService : ApplicationServiceBase
IBasicRepository<TrackFlagEntity> trackFlagBasicQuery, IBasicRepository<TrackFlagEntity> trackFlagBasicQuery,
IOrderRepository orderRepository, IOrderRepository orderRepository,
ITrackDetailsEsRepository trackDetailsEsRepository, ITrackDetailsEsRepository trackDetailsEsRepository,
ITrackTemplateRepository trackTemplateRepository, TrackPushCacheService trackPushCacheService) TrackPushCacheService trackPushCacheService)
{ {
_trackContentRepository = trackContentRepository; _trackContentRepository = trackContentRepository;
_trackStatusBasicQuery = trackStatusBasicQuery; _trackStatusBasicQuery = trackStatusBasicQuery;
_trackFlagBasicQuery = trackFlagBasicQuery; _trackFlagBasicQuery = trackFlagBasicQuery;
_orderRepository = orderRepository; _orderRepository = orderRepository;
_trackDetailsEsRepository = trackDetailsEsRepository; _trackDetailsEsRepository = trackDetailsEsRepository;
_trackTemplateRepository = trackTemplateRepository;
_trackPushCacheService = trackPushCacheService; _trackPushCacheService = trackPushCacheService;
} }
@ -82,13 +72,22 @@ public class TrackContentService : ApplicationServiceBase
} }
} }
return input.Options switch switch (input.Options)
{ {
OptionType.新增 => await AddAsync(input), case OptionType.无:
OptionType.修改 => await UpdateAsync(input), break;
OptionType.删除 => await DeleteAsync(input), case OptionType.新增:
_ => throw new BusinessException(message: "当前操作动作不合法") await AddAsync(input);
}; break;
case OptionType.删除:
await DeleteAsync(input);
break;
case OptionType.修改:
await UpdateAsync(input);
break;
default:
throw new ArgumentOutOfRangeException();
}
} }
/// <summary> /// <summary>
@ -156,14 +155,14 @@ public class TrackContentService : ApplicationServiceBase
if (input.Options != OptionTypeNoNull.删除) if (input.Options != OptionTypeNoNull.删除)
{ {
if (input.AppKey == input.MapAppKey) if (input.AppKey == input.MapAppKey)
throw new BusinessException(message: _stringLocalizer["NotAllowedToMapApp"]); throw new BusinessException("禁止自己映射自己");
Expression<Func<TrackContentMapEntity, bool>> isMapAnyExp = x => Expression<Func<TrackContentMapEntity, bool>> isMapAnyExp = x =>
x.TrackContentId == input.TrackContentId && x.MapTrackContentId == input.MapTrackContentId; x.TrackContentId == input.TrackContentId && x.MapTrackContentId == input.MapTrackContentId;
if (input.Options == OptionTypeNoNull.修改) isMapAnyExp.And(x => x.Id != input.Id); if (input.Options == OptionTypeNoNull.修改) isMapAnyExp.And(x => x.Id != input.Id);
if (await _trackContentRepository.IsMapAnyAsync(isMapAnyExp)) if (await _trackContentRepository.IsMapAnyAsync(isMapAnyExp))
throw new BusinessException(message: _stringLocalizer["IsTrackContentMapAny"]); throw new BusinessException("映射已经存在");
} }
switch (input.Options) switch (input.Options)
@ -176,7 +175,7 @@ public class TrackContentService : ApplicationServiceBase
case OptionTypeNoNull.修改: case OptionTypeNoNull.修改:
var oldTrackContentMapEntity = await _trackContentRepository.GetMapByIdAsync(input.Id!.Value) ?? var oldTrackContentMapEntity = await _trackContentRepository.GetMapByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException("找不到数据");
ObjectMapper.Map(input, oldTrackContentMapEntity); ObjectMapper.Map(input, oldTrackContentMapEntity);
@ -188,8 +187,7 @@ public class TrackContentService : ApplicationServiceBase
break; break;
default: default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, throw new ArgumentOutOfRangeException();
nameof(EditTrackContentMapInput.Options)]);
} }
return true; return true;
@ -203,27 +201,16 @@ public class TrackContentService : ApplicationServiceBase
[HttpPost("GetTrackContentByCode")] [HttpPost("GetTrackContentByCode")]
public async Task<GetTrackContentByCodeOutput> GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input) public async Task<GetTrackContentByCodeOutput> GetTrackContentByCodeAsync([FromBody] GetTrackContentByCodeInput input)
{ {
if (input.AppKey <= 0)
return new UnifyResultDto<GetTrackContentByCodeOutput>(false, "应用必须大于等于0");
if (string.IsNullOrEmpty(input.Code))
return new UnifyResultDto<GetTrackContentByCodeOutput>(false, "轨迹内容code不能为空");
var content = await _trackContentRepository.GetByCodeAsync(input.AppKey, input.Code); var content = await _trackContentRepository.GetByCodeAsync(input.AppKey, input.Code);
if (content == null) if (content == null)
return new UnifyResultDto<GetTrackContentByCodeOutput>(false, "在当前应用中未找到指定code的轨迹内容"); throw new BusinessException("在当前应用中未找到指定code的轨迹内容");
var res = new UnifyResultDto<GetTrackContentByCodeOutput>(true) return new GetTrackContentByCodeOutput
{ {
Data = new GetTrackContentByCodeOutput Content = content.Content,
{ EnContent = content.EnContent,
Content = content.Content, IsExternal = content.IsExternal
EnContent = content.EnContent,
IsExternal = content.IsExternal
}
}; };
return res;
} }
/// <summary> /// <summary>
@ -296,6 +283,7 @@ public class TrackContentService : ApplicationServiceBase
{ {
trackDetails = trackDetails.Where(m => m.Source != (int) TrackSourceEnum.ExternalServiceProvide).ToList(); trackDetails = trackDetails.Where(m => m.Source != (int) TrackSourceEnum.ExternalServiceProvide).ToList();
} }
var res = new List<GetAvailableContentOutput>();
//进行推送时,匹配订单类型一致的轨迹 //进行推送时,匹配订单类型一致的轨迹
if (input.TrackOptionType == TrackOptionType.推送) if (input.TrackOptionType == TrackOptionType.推送)
@ -312,7 +300,6 @@ public class TrackContentService : ApplicationServiceBase
trackDetails = trackDetails.Where(m => trackCodes.Contains(m.TrackCode)).ToList(); trackDetails = trackDetails.Where(m => trackCodes.Contains(m.TrackCode)).ToList();
} }
var res = new List<GetAvailableContentOutput>();
//进行删除和推送行为无任何轨迹内容,直接返回为空即可 //进行删除和推送行为无任何轨迹内容,直接返回为空即可
if (input.TrackOptionType is TrackOptionType.删除 or TrackOptionType.推送 && trackDetails.Count == 0) if (input.TrackOptionType is TrackOptionType.删除 or TrackOptionType.推送 && trackDetails.Count == 0)
{ {
@ -324,14 +311,6 @@ public class TrackContentService : ApplicationServiceBase
if (contentList == null) if (contentList == null)
throw new BusinessException(message: "当前应用下未找到任何可用的轨迹内容!"); throw new BusinessException(message: "当前应用下未找到任何可用的轨迹内容!");
//如果订单给了获取模板code,则进一步根据模板code进行过滤
if (!string.IsNullOrEmpty(order.TemplateCodes))
{
var currentCodes = order.TemplateCodes.Split(",");
var template = await _trackTemplateRepository.GetContentByTemplateCodes(currentCodes, input.AppKey);
contentList = contentList.Where(m => template.Contains(m.Code)).ToList();
}
foreach (var item in contentList) foreach (var item in contentList)
{ {
//新增时,不允许重复的轨迹,跳过已存在轨迹内容 //新增时,不允许重复的轨迹,跳过已存在轨迹内容

View File

@ -1,11 +1,9 @@
using Microsoft.Extensions.Localization; using Fake.Application.Dtos;
using TrackCenter.Application.Dtos.TrackFlags; using TrackCenter.Application.Dtos.TrackFlags;
using TrackCenter.Domain.Aggregates.TrackContentAggregate; using TrackCenter.Domain.Aggregates.TrackContentAggregate;
using TrackCenter.Domain.Aggregates.TrackFlagAggregate; using TrackCenter.Domain.Aggregates.TrackFlagAggregate;
using TrackCenter.Domain.Dtos.TrackFlags; using TrackCenter.Domain.Dtos.TrackFlags;
using SqlSugar; using SqlSugar;
using TrackCenter.Application.Localization;
using Volo.Abp.DependencyInjection;
namespace TrackCenter.Application.Services.TrackFlags; namespace TrackCenter.Application.Services.TrackFlags;
@ -16,17 +14,14 @@ namespace TrackCenter.Application.Services.TrackFlags;
[Route("/Track/Flag")] [Route("/Track/Flag")]
public class TrackFlagService : ApplicationServiceBase, ITransientDependency public class TrackFlagService : ApplicationServiceBase, ITransientDependency
{ {
private readonly IStringLocalizer<TrackLocalizationResource> _stringLocalizer;
private readonly ITrackContentRepository _trackContentRepository; private readonly ITrackContentRepository _trackContentRepository;
private readonly ITrackFlagRepository _trackFlagRepository; private readonly ITrackFlagRepository _trackFlagRepository;
public TrackFlagService( public TrackFlagService(
IStringLocalizer<TrackLocalizationResource> stringLocalizer,
ITrackFlagRepository trackFlagRepository, ITrackFlagRepository trackFlagRepository,
ITrackContentRepository trackContentRepository ITrackContentRepository trackContentRepository
) )
{ {
this._stringLocalizer = stringLocalizer;
this._trackFlagRepository = trackFlagRepository; this._trackFlagRepository = trackFlagRepository;
this._trackContentRepository = trackContentRepository; this._trackContentRepository = trackContentRepository;
} }
@ -36,15 +31,24 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("Edit")] [HttpPost("Edit")]
public async Task<UnifyResultDto> EditAsync(EditTrackFlagInput input) public async Task EditAsync(EditTrackFlagInput input)
{ {
return input.Options switch switch (input.Options)
{ {
OptionType.新增 => await AddAsync(input), case OptionType.无:
OptionType.修改 => await UpdateAsync(input), break;
OptionType.删除 => await DeleteAsync(input), case OptionType.新增:
_ => throw new BusinessException(message: "当前操作动作不合法") await AddAsync(input);
}; break;
case OptionType.删除:
await DeleteAsync(input);
break;
case OptionType.修改:
await UpdateAsync(input);
break;
default:
throw new ArgumentOutOfRangeException();
}
} }
/// <summary> /// <summary>
@ -53,16 +57,11 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
[HttpGet("GetDetail")] [HttpGet("GetDetail")]
public async Task<UnifyResultDto<GetTrackFlagDetailDto>> GetDetailAsync(int id) public async Task<GetTrackFlagDetailDto> GetDetailAsync(int id)
{ {
var detailInfo = await _trackFlagRepository.GetDetailAsync(id); var detailInfo = await _trackFlagRepository.GetDetailAsync(id);
if (detailInfo == null) var dto = ObjectMapper.Map<GetTrackFlagDetailVO, GetTrackFlagDetailDto>(detailInfo!);
{ return dto;
return new UnifyResultDto<GetTrackFlagDetailDto>(false, null, "未查询到轨迹状态");
}
var dto = ObjectMapper.Map<GetTrackFlagDetailVO, GetTrackFlagDetailDto>(detailInfo);
return new UnifyResultDto<GetTrackFlagDetailDto>(GlobalConst.SuccessCode, "", dto);
} }
/// <summary> /// <summary>
@ -84,7 +83,7 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
#region 私有方法 #region 私有方法
private async Task<UnifyResultDto> AddAsync(EditTrackFlagInput input) private async Task AddAsync(EditTrackFlagInput input)
{ {
#region 业务校验 #region 业务校验
@ -109,11 +108,9 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
var entity = ObjectMapper.Map<EditTrackFlagInput, TrackFlagEntity>(input); var entity = ObjectMapper.Map<EditTrackFlagInput, TrackFlagEntity>(input);
var isTrue = await _trackFlagRepository.InsertAsync(entity); var isTrue = await _trackFlagRepository.InsertAsync(entity);
return new UnifyResultDto(GlobalConst.SuccessCode, "新增成功", isTrue);
} }
private async Task<UnifyResultDto> UpdateAsync(EditTrackFlagInput input) private async Task UpdateAsync(EditTrackFlagInput input)
{ {
#region 业务校验 #region 业务校验
@ -146,11 +143,9 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
ObjectMapper.Map(input, trackFlag); ObjectMapper.Map(input, trackFlag);
var isTrue = await _trackFlagRepository.UpdateAsync(trackFlag); var isTrue = await _trackFlagRepository.UpdateAsync(trackFlag);
return new UnifyResultDto(GlobalConst.SuccessCode, "修改成功", isTrue);
} }
private async Task<UnifyResultDto> DeleteAsync(EditTrackFlagInput input) private async Task DeleteAsync(EditTrackFlagInput input)
{ {
#region 业务校验 #region 业务校验
@ -164,8 +159,6 @@ public class TrackFlagService : ApplicationServiceBase, ITransientDependency
#endregion #endregion
var isTrue = await _trackFlagRepository.SoftDeleteAsync(x => x.Id == input.Id); var isTrue = await _trackFlagRepository.SoftDeleteAsync(x => x.Id == input.Id);
return new UnifyResultDto(GlobalConst.SuccessCode, "删除成功", isTrue);
} }
#endregion #endregion

View File

@ -1,173 +0,0 @@
using Fake.Application.Dtos;
using TrackCenter.Application.Dtos.TrackNode;
using TrackCenter.Application.Dtos.TrackStatus;
using TrackCenter.Application.Helpers;
using TrackCenter.Domain.Aggregates.TrackNodeAggregate;
using TrackCenter.Domain.Aggregates.TrackStatusAggregate;
using TrackCenter.Domain.Dtos.TrackNode;
namespace TrackCenter.Application.Services.TrackNode;
/// <summary>
/// 轨迹节点服务
/// </summary>
[ApiExplorerSettings(GroupName = "轨迹节点")]
[Route("/Track/Node")]
public class TrackNodeService : ApplicationServiceBase
{
private readonly ITrackNodeRepository _trackNodeRepository;
private readonly ITrackStatusRepository _trackStatusRepository;
public TrackNodeService(
ITrackNodeRepository trackNodeRepository, ITrackStatusRepository trackStatusRepository)
{
this._trackNodeRepository = trackNodeRepository;
_trackStatusRepository = trackStatusRepository;
}
/// <summary>
/// 轨迹节点编辑
/// </summary>
/// <returns></returns>
[HttpPost("Edit")]
public async Task EditAsync(EditTrackNodeInput input)
{
switch (input.Options)
{
case OptionType.无:
break;
case OptionType.新增:
await AddAsync(input);
break;
case OptionType.删除:
await DeleteAsync(input);
break;
case OptionType.修改:
await UpdateAsync(input);
break;
default:
throw new BusinessException(message: "当前操作动作不合法");
}
}
/// <summary>
/// 获取分页轨迹节点
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetList")]
public async Task<PagedResult<TrackNodeDto>> GetPageTrackNode(QueryTrackNodeRequest input)
{
var queryParam = ObjectMapper.Map<QueryTrackNodeRequest, TrackNodePageDto>(input);
var resultDto = await _trackNodeRepository.GetPageList(queryParam);
return resultDto;
}
/// <summary>
/// 获取详情
/// </summary>
/// <param name="nodeid">节点id</param>
/// <returns></returns>
[HttpPost("GetDetail")]
public async Task<TrackNodeDto> GetDetail(int nodeid)
{
var resultDto = await _trackNodeRepository.GetDetail(nodeid);
return resultDto;
}
/// <summary>
/// 获取分页轨迹字典,下拉框用的
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("GetTrackNodeOption")]
public async Task<PagedResult<TrackNodeDicDto>> GetTrackNodeOption(QueryTrackNodeRequest input)
{
var queryParam = ObjectMapper.Map<QueryTrackNodeRequest, TrackNodePageDto>(input);
var resultDto = await _trackNodeRepository.GetPageDicList(queryParam);
return resultDto;
}
#region 私有方法
private async Task AddAsync(EditTrackNodeInput input)
{
#region 业务校验
if (string.IsNullOrEmpty(input.NodeName) || string.IsNullOrEmpty(input.NodeEnName) ||
!input.AppKey.HasValue)
{
throw new BusinessException("NodeName,NodeEnName,AppKey 必填");
}
var trackNodesEntitys = await _trackNodeRepository.GetListAsync(a =>
a.AppKey == input.AppKey &&
(a.NodeName == input.NodeName || a.NodeEnName == input.NodeEnName));
if (trackNodesEntitys.Any())
{
var trackNodeName = trackNodesEntitys.FirstOrDefault(a => a.NodeName == input.NodeName);
if (trackNodeName != null)
{
throw new BusinessException(message: "该应用下节点名称已存在");
}
var trackNodeEnName = trackNodesEntitys.FirstOrDefault(a => a.NodeEnName == input.NodeEnName);
if (trackNodeEnName != null)
{
throw new BusinessException(message: "该应用下节点英文名称已存在");
}
}
#endregion
if (!StringHelper.IsValidEnglishString(input.NodeEnName))
{
throw new BusinessException("节点英文名称必须是英文和常用英文符号");
}
var entity = ObjectMapper.Map<EditTrackNodeInput, TrackNodeEntity>(input);
await _trackNodeRepository.InsertAsync(entity);
}
private async Task UpdateAsync(EditTrackNodeInput input)
{
#region 业务校验
if (string.IsNullOrEmpty(input.NodeName) || string.IsNullOrEmpty(input.NodeEnName))
{
throw new BusinessException("NodeName,NodeEnName 必填");
}
var trackNodesEntitys = await _trackNodeRepository.GetFirstAsync(a => a.Id == input.Id);
if (trackNodesEntitys == null)
{
throw new BusinessException("没有找到数据,更新失败");
}
#endregion
trackNodesEntitys.NodeEnName = input.NodeEnName;
trackNodesEntitys.NodeName = input.NodeName;
await _trackNodeRepository.UpdateAsync(trackNodesEntitys);
}
private async Task DeleteAsync(EditTrackNodeInput input)
{
if (input.Id <= 0 || !input.AppKey.HasValue)
{
throw new BusinessException("AppKey 必填");
}
var trackStatus =
await _trackStatusRepository.GetFirstAsync(val =>
val.Node == input.Id && val.AppKey == input.AppKey);
if (trackStatus != null)
{
throw new BusinessException("删除失败,该节点已被使用");
}
await _trackNodeRepository.DeleteById(input.Id);
}
#endregion
}

View File

@ -1,9 +1,9 @@
using System.Linq.Expressions; using System.Linq.Expressions;
using SJZY.Expand.ABP.Core.Logger; using Fake.Application.Dtos;
using SJZY.Expand.AliyunOSS;
using TrackCenter.Application.Dtos.ProvideServices; using TrackCenter.Application.Dtos.ProvideServices;
using TrackCenter.Application.Dtos.TrackOrder; using TrackCenter.Application.Dtos.TrackOrder;
using TrackCenter.Application.Helpers; using TrackCenter.Application.Helpers;
using TrackCenter.Application.Helpers.OSS;
using TrackCenter.Application.Services.Warning.Handlers; using TrackCenter.Application.Services.Warning.Handlers;
using TrackCenter.Domain.Aggregates.OrderAggregate; using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Aggregates.TrackContentAggregate; using TrackCenter.Domain.Aggregates.TrackContentAggregate;
@ -11,6 +11,7 @@ using TrackCenter.Domain.Aggregates.TrackDetailsAggregate;
using TrackCenter.Domain.Aggregates.TrackPushAggregate; using TrackCenter.Domain.Aggregates.TrackPushAggregate;
using TrackCenter.Domain.Aggregates.TrackStatusAggregate; using TrackCenter.Domain.Aggregates.TrackStatusAggregate;
using TrackCenter.Domain.Dtos.Order; using TrackCenter.Domain.Dtos.Order;
using TrackCenter.Repository.Aggregates.OrderAggregate;
namespace TrackCenter.Application.Services.TrackOrders; namespace TrackCenter.Application.Services.TrackOrders;
@ -23,8 +24,6 @@ public class TrackOrderService : ApplicationServiceBase
{ {
private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository; private readonly IOrderOperationRecordEsRepository _orderOperationRecordEsRepository;
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly ITrackContentRepository _trackContentRepository;
private readonly ITrackStatusRepository _trackStatusRepository;
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository; private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository; private readonly ITrackPushRecordEsRepository _trackPushRecordEsRepository;
private readonly IServiceProvider _serviceProvider; private readonly IServiceProvider _serviceProvider;
@ -32,17 +31,14 @@ public class TrackOrderService : ApplicationServiceBase
public TrackOrderService( public TrackOrderService(
IOrderRepository orderRepository, IOrderRepository orderRepository,
ITrackDetailsEsRepository trackDetailsEsRepository, ITrackDetailsEsRepository trackDetailsEsRepository,
ITrackContentRepository trackContentRepository,
ITrackPushRecordEsRepository trackPushRecordEsRepository, ITrackPushRecordEsRepository trackPushRecordEsRepository,
IOrderOperationRecordEsRepository orderOperationRecordEsRepository, IOrderOperationRecordEsRepository orderOperationRecordEsRepository,
ITrackStatusRepository trackStatusRepository, IServiceProvider serviceProvider) IServiceProvider serviceProvider)
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
_trackDetailsEsRepository = trackDetailsEsRepository; _trackDetailsEsRepository = trackDetailsEsRepository;
_trackContentRepository = trackContentRepository;
_trackPushRecordEsRepository = trackPushRecordEsRepository; _trackPushRecordEsRepository = trackPushRecordEsRepository;
_orderOperationRecordEsRepository = orderOperationRecordEsRepository; _orderOperationRecordEsRepository = orderOperationRecordEsRepository;
_trackStatusRepository = trackStatusRepository;
_serviceProvider = serviceProvider; _serviceProvider = serviceProvider;
} }
@ -147,7 +143,7 @@ public class TrackOrderService : ApplicationServiceBase
whereExpression = m => m.Id == orderId; whereExpression = m => m.Id == orderId;
//根据订单号+系统id查询 //根据订单号+系统id查询
if (!string.IsNullOrEmpty(orderNo) && appKey != null && appKey > 0) if (!string.IsNullOrEmpty(orderNo) && !string.IsNullOrEmpty(appKey))
whereExpression = m => m.OrderNo == orderNo && m.AppKey == appKey; whereExpression = m => m.OrderNo == orderNo && m.AppKey == appKey;
if (whereExpression == default) if (whereExpression == default)
@ -199,9 +195,6 @@ public class TrackOrderService : ApplicationServiceBase
case SortMethod.ByTrackTimeDesc: case SortMethod.ByTrackTimeDesc:
list.Sort((a, b) => DateTimeHelper.ConvertUtc0Compare(b.TrackTime, b.TrackTimeZoneValue, a.TrackTime, a.TrackTimeZoneValue)); list.Sort((a, b) => DateTimeHelper.ConvertUtc0Compare(b.TrackTime, b.TrackTimeZoneValue, a.TrackTime, a.TrackTimeZoneValue));
break; break;
case SortMethod.ByTemplateAndTrackTime:
case SortMethod.ByTemplateAndTrackTimeDesc:
throw new BusinessException(message: "该接口暂不支持该模板排序方式,如需支持请联系轨迹中台负责人");
case SortMethod.ByCreateTime: case SortMethod.ByCreateTime:
list.Sort((a, b) => a.CreateTime.CompareTo(b.CreateTime)); list.Sort((a, b) => a.CreateTime.CompareTo(b.CreateTime));
break; break;
@ -222,41 +215,25 @@ public class TrackOrderService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetDetailTimeline")] [HttpPost("GetDetailTimeline")]
public async Task<UnifyResultDto<List<GetDetailTimelineOutput>>> GetDetailTimeline(GetDetailTimelineInput input) public async Task<List<GetDetailTimelineOutput>> GetDetailTimeline(GetDetailTimelineInput input)
{ {
var res = new UnifyResultDto<List<GetDetailTimelineOutput>>(true); var res = new List<GetDetailTimelineOutput>();
var order = await _orderRepository.GetFirstAsync(m => m.OrderNo == input.OrderNumber); var order = await _orderRepository.GetFirstAsync(m => m.OrderNo == input.OrderNumber);
if (order == null) if (order == null)
return new UnifyResultDto<List<GetDetailTimelineOutput>>(false, "订单不存在"); throw new BusinessException("订单不存在");
if (input.AppKey <= 0)
return new UnifyResultDto<List<GetDetailTimelineOutput>>(false, "应用不合法");
if (input.CurrenUserAppKey <= 0)
return new UnifyResultDto<List<GetDetailTimelineOutput>>(false, "当前登陆用户应用不合法");
var system = await _orderRepository.GetSystemInfoById(input.CurrenUserAppKey);
if (system == null)
return new UnifyResultDto<List<GetDetailTimelineOutput>>(false, "未找到指定id的应用");
var trackDetails = await _trackDetailsEsRepository.GetListAsync(order.Id); var trackDetails = await _trackDetailsEsRepository.GetListAsync(order.Id);
//时间轴不显示轨迹内容为空的轨迹,进行过滤 //时间轴不显示轨迹内容为空的轨迹,进行过滤
trackDetails = trackDetails.Where(x => !x.TrackContent.IsNullOrWhiteSpace() && x.TrackContent != GlobalConst.EmptyString).ToList(); trackDetails = trackDetails.Where(x => !x.TrackContent.IsNullOrWhiteSpace() && x.TrackContent != GlobalConst.EmptyString).ToList();
res.Data = new List<GetDetailTimelineOutput>();
foreach (var item in trackDetails) foreach (var item in trackDetails)
{ {
//如果是外部系统,且轨迹内容不对外则跳过这条轨迹内容
if (system.SystemProperty == 2 && !item.IsExternal)
continue;
//时间和时区任意一个为空则使用创建时间做为排序参照值 //时间和时区任意一个为空则使用创建时间做为排序参照值
var timeTick = ToUnixTimestamp((item.TrackTime == null var timeTick = ToUnixTimestamp(Math.Abs(item.TrackTimeZone - GlobalConst.NoneTrackTimeZone) < 1
|| Math.Abs(item.TrackTimeZone - GlobalConst.NoneTrackTimeZone) < 1)
? item.CreateTime ? item.CreateTime
: item.TrackTime); : item.TrackTime);
res.Data.Add(new GetDetailTimelineOutput() res.Add(new GetDetailTimelineOutput()
{ {
IsHighlight = true, IsHighlight = true,
IsShowHover = true, IsShowHover = true,
@ -282,17 +259,17 @@ public class TrackOrderService : ApplicationServiceBase
} }
// 按轨迹发生时间正序排序 // 按轨迹发生时间正序排序
res.Data = res.Data.OrderBy(m => m.TrackTime).ToList(); res = res.OrderBy(m => m.TrackTime).ToList();
if (!order.IsCompleted) //如果没完结则显示签收节点 if (!order.IsCompleted) //如果没完结则显示签收节点
{ {
var eddUnixTimestamp = order.EstimatedDeliveryDate.HasValue ? ToUnixTimestamp(DateTime.Parse(order.EstimatedDeliveryDate.ToString()!)) : 0; var eddUnixTimestamp = order.EstimatedDeliveryDate.HasValue ? ToUnixTimestamp(DateTime.Parse(order.EstimatedDeliveryDate.ToString()!)) : 0;
var isShowTime = eddUnixTimestamp > 0 && res.Data.All(m => m.TrackTime < eddUnixTimestamp); var isShowTime = eddUnixTimestamp > 0 && res.All(m => m.TrackTime < eddUnixTimestamp);
//当存在需要显示的轨迹才需要补充签收节点 //当存在需要显示的轨迹才需要补充签收节点
if (res.Data.Count != 0) if (res.Count != 0)
{ {
res.Data.Add(new GetDetailTimelineOutput() res.Add(new GetDetailTimelineOutput()
{ {
Content = "签收", Content = "签收",
IsHighlight = false, IsHighlight = false,

View File

@ -1,14 +1,11 @@
using SJZY.Expand.ABP.Core; using Fake.ObjectMapping;
using TrackCenter.Application.Dtos.TrackPull; using TrackCenter.Application.Dtos.TrackPull;
using TrackCenter.Application.Services;
using TrackCenter.Domain.Aggregates.TrackPullAggregate; using TrackCenter.Domain.Aggregates.TrackPullAggregate;
using TrackCenter.Domain.Dtos.TrackPull; using TrackCenter.Domain.Dtos.TrackPull;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ObjectMapping;
namespace TrackCenter.Application.Services.TrackPull; namespace TrackCenter.Application.Services.TrackPull;
public class TrackPullCacheService : ITransientDependency, ITrackPullCacheService public class TrackPullCacheService : ITransientDependency
{ {
private readonly IObjectMapper _objectMapper; private readonly IObjectMapper _objectMapper;
private readonly ITrackPullConfigRepository _trackPullConfigRepository; private readonly ITrackPullConfigRepository _trackPullConfigRepository;

View File

@ -1,18 +1,14 @@
using System.ComponentModel; using System.ComponentModel;
using System.Linq.Expressions; using System.Linq.Expressions;
using Fake.Application.Dtos; using Fake.Application.Dtos;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options; using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core.Localization;
using SJZY.Expand.ABP.Core.PublicMethords;
using TrackCenter.Application.Dtos.TrackPull; using TrackCenter.Application.Dtos.TrackPull;
using TrackCenter.Application.Services;
using TrackCenter.Domain.Aggregates.TrackPullAggregate; using TrackCenter.Domain.Aggregates.TrackPullAggregate;
using TrackCenter.Domain.Dtos.TrackPull; using TrackCenter.Domain.Dtos.TrackPull;
using SqlSugar; using SqlSugar;
using TrackCenter.Application.Helpers; using TrackCenter.Application.Helpers;
using TrackCenter.Application.Localization;
using TrackCenter.Application.Options; using TrackCenter.Application.Options;
using TrackCenter.Repository;
namespace TrackCenter.Application.Services.TrackPull; namespace TrackCenter.Application.Services.TrackPull;
@ -212,7 +208,7 @@ public class TrackPullService : ApplicationServiceBase
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x => if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(x =>
x.TrackContentId == input.TrackContentId))) x.TrackContentId == input.TrackContentId)))
throw new BusinessException("找不到配置"); throw new BusinessException("配置已存在");
if (!input.TrackStatusValues.IsNullOrEmpty()) if (!input.TrackStatusValues.IsNullOrEmpty())
{ {
@ -223,7 +219,7 @@ public class TrackPullService : ApplicationServiceBase
}); });
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackStatusValuesExp))) if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackStatusValuesExp)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentStatusValueAny"]); throw new BusinessException(message: "配置已存在");
} }
if (!input.TrackKeywords.IsNullOrEmpty()) if (!input.TrackKeywords.IsNullOrEmpty())
@ -235,7 +231,7 @@ public class TrackPullService : ApplicationServiceBase
}); });
if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackKeywordExp))) if (await _trackPullConfigRepository.IsContentAnyAsync(isContentAnyExp.And(trackKeywordExp)))
throw new BusinessException(message: _stringLocalizer["IsTrackPullContentKeywordsAny"]); throw new BusinessException(message: "配置已存在");
} }
} }
@ -255,7 +251,7 @@ public class TrackPullService : ApplicationServiceBase
{ {
var oldTrackPullContentEntity = var oldTrackPullContentEntity =
await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
ObjectMapper.Map(input, oldTrackPullContentEntity); ObjectMapper.Map(input, oldTrackPullContentEntity);
@ -269,7 +265,7 @@ public class TrackPullService : ApplicationServiceBase
{ {
var oldTrackPullContentEntity = var oldTrackPullContentEntity =
await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? await _trackPullConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); await _trackPullConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);
await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId); await _trackPullCacheService.SetPullConfigAsync(oldTrackPullContentEntity.TrackPullConfigId);
@ -278,8 +274,7 @@ public class TrackPullService : ApplicationServiceBase
} }
default: default:
throw new BusinessException(message: _stringLocalizer[SjzyBasicLocalization.Validation_IsInEnum, throw new ArgumentOutOfRangeException();
nameof(EditTrackPullContentInput.Options)]);
} }
return true; return true;

View File

@ -147,7 +147,7 @@ public class TrackPushService : ApplicationServiceBase, ISingletonDependency
case OptionTypeNoNull.修改: case OptionTypeNoNull.修改:
var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? var oldTrackPushEntity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
ObjectMapper.Map(input, oldTrackPushEntity); ObjectMapper.Map(input, oldTrackPushEntity);
await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity); await _trackPushConfigRepository.UpdateAsync(oldTrackPushEntity);
@ -157,7 +157,7 @@ public class TrackPushService : ApplicationServiceBase, ISingletonDependency
case OptionTypeNoNull.删除: case OptionTypeNoNull.删除:
var entity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ?? var entity = await _trackPushConfigRepository.GetFirstAsync(x => x.Id == input.Id) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id); await _trackPushConfigRepository.SoftDeleteAsync(x => x.Id == input.Id);
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.TrackPushConfigId == input.Id);
@ -245,7 +245,7 @@ public class TrackPushService : ApplicationServiceBase, ISingletonDependency
case OptionTypeNoNull.修改: case OptionTypeNoNull.修改:
{ {
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
oldContentConfig = entity.DeepCopy(); oldContentConfig = entity.DeepCopy();
ObjectMapper.Map(input, entity); ObjectMapper.Map(input, entity);
await _trackPushConfigRepository.UpdateContentAsync(entity); await _trackPushConfigRepository.UpdateContentAsync(entity);
@ -256,7 +256,7 @@ public class TrackPushService : ApplicationServiceBase, ISingletonDependency
case OptionTypeNoNull.删除: case OptionTypeNoNull.删除:
{ {
var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ?? var entity = await _trackPushConfigRepository.GetContentByIdAsync(input.Id!.Value) ??
throw new BusinessException(message: _stringLocalizer["NotFindData"]); throw new BusinessException(message: "找不到数据");
oldContentConfig = entity; oldContentConfig = entity;
trackPushConfigId = entity.TrackPushConfigId; trackPushConfigId = entity.TrackPushConfigId;
await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id); await _trackPushConfigRepository.SoftDeleteContentAsync(x => x.Id == input.Id);

View File

@ -1,5 +1,6 @@
using DotNetCore.CAP; using DotNetCore.CAP;
using SJZY.Expand.ABP.Core.PublicMethords; using Fake.Application.Dtos;
using InterfaceForward.Domain.Shared.Helpers;
using TrackCenter.Application.Dtos.Warning; using TrackCenter.Application.Dtos.Warning;
using TrackCenter.Application.Dtos.Warning.Return; using TrackCenter.Application.Dtos.Warning.Return;
using TrackCenter.Application.Events; using TrackCenter.Application.Events;
@ -7,13 +8,10 @@ using TrackCenter.Domain.Aggregates.OrderAggregate;
using TrackCenter.Domain.Aggregates.WarningAggregate; using TrackCenter.Domain.Aggregates.WarningAggregate;
using TrackCenter.Domain.Dtos.Warning; using TrackCenter.Domain.Dtos.Warning;
using TrackCenter.Domain.Enums; using TrackCenter.Domain.Enums;
using TrackCenter.Domain.Queries;
using SJZY.UserCenter.HttpApi.Services.User;
using TrackCenter.Application.Caching; using TrackCenter.Application.Caching;
using TrackCenter.Application.Helpers; using TrackCenter.Application.Helpers;
using TrackCenter.Application.Services.Warning.Handlers; using TrackCenter.Application.Services.Warning.Handlers;
using TrackCenter.Application.Services.Warning.Model; using TrackCenter.Application.Services.Warning.Model;
using Volo.Abp.Http.Client.DynamicProxying;
namespace TrackCenter.Application.Services.Warning; namespace TrackCenter.Application.Services.Warning;
@ -25,39 +23,30 @@ namespace TrackCenter.Application.Services.Warning;
public class ReturnWarningService : ApplicationServiceBase public class ReturnWarningService : ApplicationServiceBase
{ {
private readonly IOrderRepository _orderRepository; private readonly IOrderRepository _orderRepository;
private readonly IVSystemQueries _vSystemQueries;
private readonly IReturnWarningHandler _returnWarningHandler; private readonly IReturnWarningHandler _returnWarningHandler;
private readonly IWarningRuleRepository _warningRuleRepository; private readonly IWarningRuleRepository _warningRuleRepository;
private readonly IWarningDetailsEsRepository _warningDetailsEsRepository; private readonly IWarningDetailsEsRepository _warningDetailsEsRepository;
private readonly ICapPublisher _capPublisher; private readonly ICapPublisher _capPublisher;
private readonly IHttpClientProxy<IUserBaseInfoService> _requestCurrentUserService;
private readonly TrackStatusNameDictCache _trackStatusNameDictCache; private readonly TrackStatusNameDictCache _trackStatusNameDictCache;
private readonly CustomAbbreviationDictCache _customAbbreviationDictCache; private readonly AppNameDictCache _appNameDictCache;
private readonly SystemCnNameDictCache _systemCnNameDictCache;
public ReturnWarningService( public ReturnWarningService(
IOrderRepository orderRepository, IOrderRepository orderRepository,
IVSystemQueries vSystemQueries,
IReturnWarningHandler returnWarningHandler, IReturnWarningHandler returnWarningHandler,
IWarningRuleRepository warningRuleRepository, IWarningRuleRepository warningRuleRepository,
IWarningDetailsEsRepository warningDetailsEsRepository, IWarningDetailsEsRepository warningDetailsEsRepository,
ICapPublisher capPublisher, ICapPublisher capPublisher,
IHttpClientProxy<IUserBaseInfoService> requestCurrentUserService,
TrackStatusNameDictCache trackStatusNameDictCache, TrackStatusNameDictCache trackStatusNameDictCache,
CustomAbbreviationDictCache customAbbreviationDictCache, AppNameDictCache appNameDictCache
SystemCnNameDictCache systemCnNameDictCache
) )
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
_vSystemQueries = vSystemQueries;
_returnWarningHandler = returnWarningHandler; _returnWarningHandler = returnWarningHandler;
_warningRuleRepository = warningRuleRepository; _warningRuleRepository = warningRuleRepository;
_warningDetailsEsRepository = warningDetailsEsRepository; _warningDetailsEsRepository = warningDetailsEsRepository;
_capPublisher = capPublisher; _capPublisher = capPublisher;
_requestCurrentUserService = requestCurrentUserService;
_trackStatusNameDictCache = trackStatusNameDictCache; _trackStatusNameDictCache = trackStatusNameDictCache;
_customAbbreviationDictCache = customAbbreviationDictCache; _appNameDictCache = appNameDictCache;
_systemCnNameDictCache = systemCnNameDictCache;
} }
/// <summary> /// <summary>
@ -66,12 +55,12 @@ public class ReturnWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetReturnWarningRuleItem")] [HttpPost("GetReturnWarningRuleItem")]
public async Task<UnifyResultDto<List<ReturnWarningRuleItemDto>>> GetReturnWarningRuleItem(GetReturnWarningRuleItemInput input) public async Task<List<ReturnWarningRuleItemDto>> GetReturnWarningRuleItem(GetReturnWarningRuleItemInput input)
{ {
var result = await _warningRuleRepository.GetReturnRuleItemsAsync(input.WarningId); var result = await _warningRuleRepository.GetReturnRuleItemsAsync(input.WarningId);
if (result.Count == 0) if (result.Count == 0)
return new UnifyResultDto<List<ReturnWarningRuleItemDto>>(true, new List<ReturnWarningRuleItemDto>()); return new List<ReturnWarningRuleItemDto>();
var trackStatusIds = result var trackStatusIds = result
.SelectMany(x => x.TrackStatusIds.Split(',').Select(int.Parse)) .SelectMany(x => x.TrackStatusIds.Split(',').Select(int.Parse))
@ -83,10 +72,10 @@ public class ReturnWarningService : ApplicationServiceBase
Id = x.Id, Id = x.Id,
TrackStatus = BuildTrackStatus(x.TrackStatusIds), TrackStatus = BuildTrackStatus(x.TrackStatusIds),
ReturnTimeSpan = x.ReturnTimeSpan, ReturnTimeSpan = x.ReturnTimeSpan,
NotifyUsers = x.NotifyUsers.ToObject<List<NotifyUserDto>>() NotifyUsers = x.NotifyUsers.ToObject<List<NotifyUserDto>>()!
}); });
return new UnifyResultDto<List<ReturnWarningRuleItemDto>>(true, map.ToList()); return map.ToList();
List<TrackStatusDto> BuildTrackStatus(string statusIds) List<TrackStatusDto> BuildTrackStatus(string statusIds)
{ {
@ -112,28 +101,25 @@ public class ReturnWarningService : ApplicationServiceBase
{ {
var vo = ObjectMapper.Map<GetPageReturnWarningDetailsInput, GetPageReturnWarningDetailsInputVO>(input); var vo = ObjectMapper.Map<GetPageReturnWarningDetailsInput, GetPageReturnWarningDetailsInputVO>(input);
var result = await _warningDetailsEsRepository.GetPageReturnWarningDetailsAsync(vo); var result = await _warningDetailsEsRepository.GetPageReturnWarningDetailsAsync(vo);
if (result.List.Count == 0) if (result.Items.Count == 0)
{ {
return new PagedResult<ReturnWarningDetailsDto>(new List<ReturnWarningDetailsDto>(), return new PagedResult<ReturnWarningDetailsDto>(result.TotalCount, new List<ReturnWarningDetailsDto>());
result.Pagination.PageIndex,
result.Pagination.PageSize,
result.Pagination.Total);
} }
// 订单类型名称字典 // 订单类型名称字典
var orderTypeDict = await _orderRepository.GetTrackOrderTypeDictAsync(); var orderTypeDict = await _orderRepository.GetTrackOrderTypeDictAsync();
// 客户id简称字典 // 客户id简称字典
var customIds = result.List.Select(x => x.CustomId).ToHashSet(); var customIds = result.Items.Select(x => x.CustomId).ToHashSet();
var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds); var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds);
// 应用中文名字典 // 应用中文名字典
var AppKeys = result.List.Select(x => x.AppKey).ToHashSet(); var appKeys = result.Items.Select(x => x.AppKey).ToHashSet();
var AppDict = await _systemCnNameDictCache.SafeGetBatchAsync(AppKeys); var appDict = await _appNameDictCache.SafeGetBatchAsync(appKeys);
var map = result.List.Select(x => new ReturnWarningDetailsDto var map = result.Items.Select(x => new ReturnWarningDetailsDto
{ {
EsId = x.Id, EsId = x.Id,
AppKey = x.AppKey, AppKey = x.AppKey,
AppName = AppDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString), AppName = appDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString),
OrderType = x.OrderType, OrderType = x.OrderType,
OrderTypeName = orderTypeDict.GetValueOrDefault(x.OrderType.ToString(), GlobalConst.EmptyString), OrderTypeName = orderTypeDict.GetValueOrDefault(x.OrderType.ToString(), GlobalConst.EmptyString),
OrderId = x.OrderId, OrderId = x.OrderId,
@ -173,18 +159,14 @@ public class ReturnWarningService : ApplicationServiceBase
.OrderBy(x => x.Status == (int) ReturnWarningStatus.人工介入 ? 1 : 2) .OrderBy(x => x.Status == (int) ReturnWarningStatus.人工介入 ? 1 : 2)
.ThenByDescending(x => x.CreateTime); //同状态组按时间降序; .ThenByDescending(x => x.CreateTime); //同状态组按时间降序;
return new PagedResult<ReturnWarningDetailsDto>( return new PagedResult<ReturnWarningDetailsDto>(result.TotalCount, sorted.ToList());
sorted.ToList(),
result.Pagination.PageIndex,
result.Pagination.PageSize,
result.Pagination.Total);
// 通知用户提取用户名称 // 通知用户提取用户名称
string ToUserNames(string? notifyUsers) string ToUserNames(string? notifyUsers)
{ {
if (string.IsNullOrWhiteSpace(notifyUsers)) if (string.IsNullOrWhiteSpace(notifyUsers))
return string.Empty; return string.Empty;
return string.Join(',', notifyUsers.ToObject<List<NotifyUserDto>>().Select(x => x.UserName)); return string.Join(',', notifyUsers.ToObject<List<NotifyUserDto>>()!.Select(x => x.UserName));
} }
// 时间 // 时间
@ -200,7 +182,7 @@ public class ReturnWarningService : ApplicationServiceBase
/// 获取回传报文日志 /// 获取回传报文日志
/// </summary> /// </summary>
[HttpPost("GetReturnMessageRecord")] [HttpPost("GetReturnMessageRecord")]
public async Task<UnifyResultDto<List<ReturnMessageRecordDto>>> GetReturnMessageRecord(GetReturnMessageRecordInput input) public async Task<List<ReturnMessageRecordDto>> GetReturnMessageRecord(GetReturnMessageRecordInput input)
{ {
var result = await _warningDetailsEsRepository.GetReturnMessageRecordListByIdAsync(input.WarningDetailsId); var result = await _warningDetailsEsRepository.GetReturnMessageRecordListByIdAsync(input.WarningDetailsId);
@ -213,7 +195,7 @@ public class ReturnWarningService : ApplicationServiceBase
CreateTime = x.CreateTime CreateTime = x.CreateTime
}); });
return new UnifyResultDto<List<ReturnMessageRecordDto>>(true, map.ToList()); return map.ToList();
} }
/// <summary> /// <summary>
@ -222,7 +204,7 @@ public class ReturnWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("EditReturnWarningRuleItem")] [HttpPost("EditReturnWarningRuleItem")]
public async Task<UnifyResultDto> EditReturnWarningRuleItem(EditReturnWarningRuleItemInput input) public async Task EditReturnWarningRuleItem(EditReturnWarningRuleItemInput input)
{ {
var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.回传时效预警); var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.回传时效预警);
if (rule == null) if (rule == null)
@ -238,8 +220,6 @@ public class ReturnWarningService : ApplicationServiceBase
} }
await _returnWarningHandler.HandleEditAsync(rule, bos); await _returnWarningHandler.HandleEditAsync(rule, bos);
return new UnifyResultDto(true);
} }
/// <summary> /// <summary>
@ -247,7 +227,7 @@ public class ReturnWarningService : ApplicationServiceBase
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("ReturnPush")] [HttpPost("ReturnPush")]
public async Task<UnifyResultDto> ReturnPush(ReturnPushInput input) public async Task<string> ReturnPush(ReturnPushInput input)
{ {
if (input.WarningDetailIds.Count == 0) if (input.WarningDetailIds.Count == 0)
{ {
@ -275,22 +255,6 @@ public class ReturnWarningService : ApplicationServiceBase
throw new BusinessException(message: "一个能推送的也没有"); throw new BusinessException(message: "一个能推送的也没有");
} }
// 获取当前用户信息
var userInfo = await _requestCurrentUserService.Service.GetCurrentUserBasicInfoAsync();
if (userInfo.Code != GlobalConst.SuccessCode || userInfo.Data is null)
{
throw new BusinessException(message: $"调用用户中心,获取用户信息失败:{userInfo.Msg}");
}
// 应用换code
var AppKeys = filtered.Select(x => x.AppKey).ToHashSet();
var AppCodeDict = (await _vSystemQueries
.GetListAsync(x => AppKeys.Contains(x.Id), x => new
{
x.Id,
x.Key
})).ToDictionary(x => x.Id, x => x.Key);
// 3.进行推送 // 3.进行推送
foreach (var detail in filtered) foreach (var detail in filtered)
{ {
@ -298,14 +262,13 @@ public class ReturnWarningService : ApplicationServiceBase
{ {
OptionType = OptionType.新增, OptionType = OptionType.新增,
AppKey = detail.AppKey, AppKey = detail.AppKey,
AppCode = AppCodeDict.GetValueOrDefault(detail.AppKey, $"系统代码{detail.AppKey}不存在"),
CustomId = detail.CustomId, CustomId = detail.CustomId,
OrderIdTrackMetadataDict = new Dictionary<int, KeyValuePair<string, long>> OrderIdTrackMetadataDict = new Dictionary<int, TrackMetadata>
{ {
[detail.OrderId] = KeyValuePair.Create(detail.TrackEsId, detail.TrackVersion) [detail.OrderId] = TrackMetadata.Build(detail.Id, detail.TrackVersion, detail.CreateTime)
}, },
TrackCode = detail.TrackCode, TrackCode = detail.TrackCode,
OperationMan = userInfo.Data.UserName, OperationMan = CurrentUser.UserName,
SystemPushInfo = new SystemPushStruct SystemPushInfo = new SystemPushStruct
{ {
TrackStatusId = detail.TrackStatusId, TrackStatusId = detail.TrackStatusId,
@ -323,7 +286,7 @@ public class ReturnWarningService : ApplicationServiceBase
await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent); await _capPublisher.PublishAsync(GlobalConst.TrackManualPushSubscribe, trackPushEvent);
} }
return new UnifyResultDto(true, $"即将进行{filtered.Count}个回传推送!"); return $"即将进行{filtered.Count}个回传推送!";
} }
// 检查集合中是否存在交集 // 检查集合中是否存在交集

View File

@ -1,4 +1,5 @@
using SJZY.Expand.ABP.Core.PublicMethords; using Fake.Application.Dtos;
using InterfaceForward.Domain.Shared.Helpers;
using TrackCenter.Application.Dtos.Warning; using TrackCenter.Application.Dtos.Warning;
using TrackCenter.Application.Dtos.Warning.Transport; using TrackCenter.Application.Dtos.Warning.Transport;
using TrackCenter.Application.Caching; using TrackCenter.Application.Caching;
@ -29,8 +30,7 @@ public class TransportWarningService : ApplicationServiceBase
private readonly ITrackDetailsEsRepository _trackDetailsEsRepository; private readonly ITrackDetailsEsRepository _trackDetailsEsRepository;
private readonly ITransportWarningHandler _transportWarningHandler; private readonly ITransportWarningHandler _transportWarningHandler;
private readonly TrackStatusNameDictCache _trackStatusNameDictCache; private readonly TrackStatusNameDictCache _trackStatusNameDictCache;
private readonly CustomAbbreviationDictCache _customAbbreviationDictCache; private readonly AppNameDictCache _appNameDictCache;
private readonly SystemCnNameDictCache _systemCnNameDictCache;
public TransportWarningService( public TransportWarningService(
IOrderRepository orderRepository, IOrderRepository orderRepository,
@ -40,8 +40,7 @@ public class TransportWarningService : ApplicationServiceBase
ITrackDetailsEsRepository trackDetailsEsRepository, ITrackDetailsEsRepository trackDetailsEsRepository,
ITransportWarningHandler transportWarningHandler, ITransportWarningHandler transportWarningHandler,
TrackStatusNameDictCache trackStatusNameDictCache, TrackStatusNameDictCache trackStatusNameDictCache,
CustomAbbreviationDictCache customAbbreviationDictCache, AppNameDictCache appNameDictCache
SystemCnNameDictCache systemCnNameDictCache
) )
{ {
_orderRepository = orderRepository; _orderRepository = orderRepository;
@ -51,8 +50,7 @@ public class TransportWarningService : ApplicationServiceBase
_trackDetailsEsRepository = trackDetailsEsRepository; _trackDetailsEsRepository = trackDetailsEsRepository;
_transportWarningHandler = transportWarningHandler; _transportWarningHandler = transportWarningHandler;
_trackStatusNameDictCache = trackStatusNameDictCache; _trackStatusNameDictCache = trackStatusNameDictCache;
_customAbbreviationDictCache = customAbbreviationDictCache; _appNameDictCache = appNameDictCache;
_systemCnNameDictCache = systemCnNameDictCache;
} }
/// <summary> /// <summary>
@ -61,10 +59,10 @@ public class TransportWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetTransportWarningScene")] [HttpPost("GetTransportWarningScene")]
public async Task<UnifyResultDto<List<TransportWarningSceneDto>>> GetTransportWarningScene(GetTransportWarningSceneInput input) public async Task<List<TransportWarningSceneDto>> GetTransportWarningScene(GetTransportWarningSceneInput input)
{ {
var entities = await _warningRuleRepository.GetTransportSceneAsync(input.WarningId); var entities = await _warningRuleRepository.GetTransportSceneAsync(input.WarningId);
if (entities.Count == 0) return new UnifyResultDto<List<TransportWarningSceneDto>>(true, Empty<TransportWarningSceneDto>.List); if (entities.Count == 0) return Empty<TransportWarningSceneDto>.List;
var areaIds = entities var areaIds = entities
.Select(x => x.AreaId) .Select(x => x.AreaId)
@ -97,7 +95,7 @@ public class TransportWarningService : ApplicationServiceBase
AreaName = x.AreaId.HasValue ? areaNameDict?.GetValueOrDefault(x.AreaId.Value) : null AreaName = x.AreaId.HasValue ? areaNameDict?.GetValueOrDefault(x.AreaId.Value) : null
}); });
return new UnifyResultDto<List<TransportWarningSceneDto>>(true, map.ToList()); return map.ToList();
// 构建场景摘要 // 构建场景摘要
string BuildSummary(TransportWarningSceneEntity entity) string BuildSummary(TransportWarningSceneEntity entity)
@ -139,7 +137,7 @@ public class TransportWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetTransportWarningSceneRuleItem")] [HttpPost("GetTransportWarningSceneRuleItem")]
public async Task<UnifyResultDto<List<TransportWarningSceneRuleItemDto>>> GetTransportWarningSceneRuleItem(GetTransportWarningSceneRuleItemInput input) public async Task<List<TransportWarningSceneRuleItemDto>> GetTransportWarningSceneRuleItem(GetTransportWarningSceneRuleItemInput input)
{ {
var entities = await _warningRuleRepository.GetTransportSceneRuleItemsAsync(input.WarningId, input.SceneId); var entities = await _warningRuleRepository.GetTransportSceneRuleItemsAsync(input.WarningId, input.SceneId);
@ -162,7 +160,7 @@ public class TransportWarningService : ApplicationServiceBase
NotifyUsers = x.NotifyUsers.ToObject<List<NotifyUserDto>>() NotifyUsers = x.NotifyUsers.ToObject<List<NotifyUserDto>>()
}); });
return new UnifyResultDto<List<TransportWarningSceneRuleItemDto>>(true, map.ToList()); return map.ToList();
} }
/// <summary> /// <summary>
@ -178,16 +176,13 @@ public class TransportWarningService : ApplicationServiceBase
if (input.Status == (int) TransportWarningStatus.已超时) if (input.Status == (int) TransportWarningStatus.已超时)
vo.Status = (int) TransportWarningStatus.即将超时; vo.Status = (int) TransportWarningStatus.即将超时;
var result = await _warningDetailsEsRepository.GetPageTransportWarningDetailsAsync(vo); var result = await _warningDetailsEsRepository.GetPageTransportWarningDetailsAsync(vo);
if (result.List.Count == 0) if (result.Items.Count == 0)
{ {
return new PagedResult<TransportWarningDetailsDto>(new List<TransportWarningDetailsDto>(), return new PagedResult<TransportWarningDetailsDto>(0, new List<TransportWarningDetailsDto>());
result.Pagination.PageIndex,
result.Pagination.PageSize,
result.Pagination.Total);
} }
// 查最新轨迹(创建时间) // 查最新轨迹(创建时间)
var orderIds = result.List.Select(x => x.OrderId).ToHashSet(); var orderIds = result.Items.Select(x => x.OrderId).ToHashSet();
var orderIdTrackDict = await _trackDetailsEsRepository.GetLatestDictAsync(orderIds); var orderIdTrackDict = await _trackDetailsEsRepository.GetLatestDictAsync(orderIds);
// 查轨迹状态最早轨迹 // 查轨迹状态最早轨迹
var orderIdTrackStatusEarliestTrackDict = await _trackDetailsEsRepository.GetTrackStatusEarliestDictAsync(orderIds); var orderIdTrackStatusEarliestTrackDict = await _trackDetailsEsRepository.GetTrackStatusEarliestDictAsync(orderIds);
@ -195,13 +190,13 @@ public class TransportWarningService : ApplicationServiceBase
// 订单类型名称字典 // 订单类型名称字典
var orderTypeDict = await _orderRepository.GetTrackOrderTypeDictAsync(); var orderTypeDict = await _orderRepository.GetTrackOrderTypeDictAsync();
// 客户id简称字典 // 客户id简称字典
var customIds = result.List.Select(x => x.CustomId).ToHashSet(); var customIds = result.Items.Select(x => x.CustomId).ToHashSet();
var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds); var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds);
// 应用中文名字典 // 应用中文名字典
var AppKeys = result.List.Select(x => x.AppKey).ToHashSet(); var appKeys = result.Items.Select(x => x.AppKey).ToHashSet();
var AppDict = await _systemCnNameDictCache.SafeGetBatchAsync(AppKeys); var appDict = await _appNameDictCache.SafeGetBatchAsync(appKeys);
var map = result.List.Select(x => var map = result.Items.Select(x =>
{ {
var orderIdTrack = orderIdTrackDict.GetValueOrDefault(x.OrderId); var orderIdTrack = orderIdTrackDict.GetValueOrDefault(x.OrderId);
var orderIdTrackStatusEarliestTracks = orderIdTrackStatusEarliestTrackDict.GetValueOrDefault(x.OrderId); var orderIdTrackStatusEarliestTracks = orderIdTrackStatusEarliestTrackDict.GetValueOrDefault(x.OrderId);
@ -211,7 +206,7 @@ public class TransportWarningService : ApplicationServiceBase
{ {
EsId = x.Id, EsId = x.Id,
AppKey = x.AppKey, AppKey = x.AppKey,
AppName = AppDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString), AppName = appDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString),
CustomId = x.CustomId, CustomId = x.CustomId,
CustomName = customDict.GetValueOrDefault(x.CustomId, GlobalConst.EmptyString), CustomName = customDict.GetValueOrDefault(x.CustomId, GlobalConst.EmptyString),
OrderId = x.OrderId, OrderId = x.OrderId,
@ -259,18 +254,14 @@ public class TransportWarningService : ApplicationServiceBase
.ThenByDescending(x => x.CreateTime) //同状态组按时间降序 .ThenByDescending(x => x.CreateTime) //同状态组按时间降序
.ToList(); .ToList();
return new PagedResult<TransportWarningDetailsDto>( return new PagedResult<TransportWarningDetailsDto>(0, sorted);
sorted,
result.Pagination.PageIndex,
result.Pagination.PageSize,
result.Pagination.Total);
// 通知用户提取用户名称 // 通知用户提取用户名称
string ToUserNames(string notifyUsers) string ToUserNames(string notifyUsers)
{ {
if (string.IsNullOrWhiteSpace(notifyUsers)) if (string.IsNullOrWhiteSpace(notifyUsers))
return string.Empty; return string.Empty;
return string.Join(',', notifyUsers.ToObject<List<NotifyUserDto>>().Select(x => x.UserName)); return string.Join(',', notifyUsers.ToObject<List<NotifyUserDto>>()!.Select(x => x.UserName));
} }
// 格式化累计运输时间为文本形式 // 格式化累计运输时间为文本形式
@ -288,7 +279,7 @@ public class TransportWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("UpsertTransportWarningScene")] [HttpPost("UpsertTransportWarningScene")]
public async Task<UnifyResultDto<IdBaseDto>> UpsertTransportWarningScene(UpsertTransportWarningSceneInput input) public async Task<IdBaseDto> UpsertTransportWarningScene(UpsertTransportWarningSceneInput input)
{ {
var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.运输时效预警); var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.运输时效预警);
if (rule == null) if (rule == null)
@ -315,10 +306,10 @@ public class TransportWarningService : ApplicationServiceBase
if (oldBo != null) if (oldBo != null)
await _transportWarningHandler.HandleSceneChangedAsync(rule, oldBo, postBo); await _transportWarningHandler.HandleSceneChangedAsync(rule, oldBo, postBo);
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto return new IdBaseDto
{ {
Id = id Id = id
}); };
} }
/// <summary> /// <summary>
@ -327,7 +318,7 @@ public class TransportWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("DeleteTransportWarningScene")] [HttpPost("DeleteTransportWarningScene")]
public async Task<UnifyResultDto> DeleteTransportWarningScene(DeleteTransportWarningSceneInput input) public async Task DeleteTransportWarningScene(DeleteTransportWarningSceneInput input)
{ {
var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.运输时效预警); var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, WarningRuleType.运输时效预警);
if (rule == null) if (rule == null)
@ -346,8 +337,6 @@ public class TransportWarningService : ApplicationServiceBase
// 处理删除后 // 处理删除后
await _transportWarningHandler.HandleSceneDeletedAsync(rule, TransportWarningSceneBO.From(scene)); await _transportWarningHandler.HandleSceneDeletedAsync(rule, TransportWarningSceneBO.From(scene));
return new UnifyResultDto(true);
} }
/// <summary> /// <summary>
@ -356,7 +345,7 @@ public class TransportWarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("EditTransportWarningSceneRuleItem")] [HttpPost("EditTransportWarningSceneRuleItem")]
public async Task<UnifyResultDto> EditTransportWarningSceneRuleItem(EditTransportWarningSceneRuleItemInput input) public async Task EditTransportWarningSceneRuleItem(EditTransportWarningSceneRuleItemInput input)
{ {
// 起始轨迹生成预警时间不能大于时效 // 起始轨迹生成预警时间不能大于时效
if (input.Items.Count > 0 && input.Items.Any(x => x.StartTrackWarningTimeSpan >= x.TransportTimeSpan)) if (input.Items.Count > 0 && input.Items.Any(x => x.StartTrackWarningTimeSpan >= x.TransportTimeSpan))
@ -393,7 +382,5 @@ public class TransportWarningService : ApplicationServiceBase
var sceneBo = TransportWarningSceneBO.From(ruleScene); var sceneBo = TransportWarningSceneBO.From(ruleScene);
await _transportWarningHandler.HandleEditAsync(rule, sceneBo, postRuleItems); await _transportWarningHandler.HandleEditAsync(rule, sceneBo, postRuleItems);
return new UnifyResultDto(true);
} }
} }

View File

@ -18,7 +18,7 @@ public class WarningService : ApplicationServiceBase
private readonly ITransportWarningHandler _transportWarningHandler; private readonly ITransportWarningHandler _transportWarningHandler;
private readonly IReturnWarningHandler _returnWarningHandler; private readonly IReturnWarningHandler _returnWarningHandler;
private readonly CustomAbbreviationDictCache _customAbbreviationDictCache; private readonly CustomAbbreviationDictCache _customAbbreviationDictCache;
private readonly SystemCnNameDictCache _systemCnNameDictCache; private readonly AppNameDictCache _appNameDictCache;
public WarningService( public WarningService(
IWarningRuleRepository warningRuleRepository, IWarningRuleRepository warningRuleRepository,
@ -26,7 +26,7 @@ public class WarningService : ApplicationServiceBase
ITransportWarningHandler transportWarningHandler, ITransportWarningHandler transportWarningHandler,
IReturnWarningHandler returnWarningHandler, IReturnWarningHandler returnWarningHandler,
CustomAbbreviationDictCache customAbbreviationDictCache, CustomAbbreviationDictCache customAbbreviationDictCache,
SystemCnNameDictCache systemCnNameDictCache AppNameDictCache appNameDictCache
) )
{ {
_warningRuleRepository = warningRuleRepository; _warningRuleRepository = warningRuleRepository;
@ -34,7 +34,7 @@ public class WarningService : ApplicationServiceBase
_transportWarningHandler = transportWarningHandler; _transportWarningHandler = transportWarningHandler;
_returnWarningHandler = returnWarningHandler; _returnWarningHandler = returnWarningHandler;
_customAbbreviationDictCache = customAbbreviationDictCache; _customAbbreviationDictCache = customAbbreviationDictCache;
_systemCnNameDictCache = systemCnNameDictCache; _appNameDictCache = appNameDictCache;
} }
/// <summary> /// <summary>
@ -43,24 +43,24 @@ public class WarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetWarningRule")] [HttpPost("GetWarningRule")]
public async Task<UnifyResultDto<List<WarningRuleDto>>> GetWarningRule(GetWarningRuleInput input) public async Task<List<WarningRuleDto>> GetWarningRule(GetWarningRuleInput input)
{ {
var result = await _warningRuleRepository.GetWarningRuleListAsync(input.AppKey, input.CustomId, input.KpiName, input.IsEnabled, input.WarningType); var result = await _warningRuleRepository.GetWarningRuleListAsync(input.AppKey, input.CustomId, input.KpiName, input.IsEnabled, input.WarningType);
if (result.Count == 0) if (result.Count == 0)
return new UnifyResultDto<List<WarningRuleDto>>(true, new List<WarningRuleDto>()); return new List<WarningRuleDto>();
// 客户id简称字典 // 客户id简称字典
var customIds = result.Select(x => x.CustomId).ToHashSet(); var customIds = result.Select(x => x.CustomId).ToHashSet();
var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds); var customDict = await _customAbbreviationDictCache.SafeGetBatchAsync(customIds);
// 应用中文名字典 // 应用中文名字典
var AppKeys = result.Select(x => x.AppKey).ToHashSet(); var appKeys = result.Select(x => x.AppKey).ToHashSet();
var AppDict = await _systemCnNameDictCache.SafeGetBatchAsync(AppKeys); var appDict = await _appNameDictCache.SafeGetBatchAsync(appKeys);
return new UnifyResultDto<List<WarningRuleDto>>(true, result.Select(x => new WarningRuleDto return result.Select(x => new WarningRuleDto
{ {
Id = x.Id, Id = x.Id,
AppKey = x.AppKey, AppKey = x.AppKey,
AppName = AppDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString), AppName = appDict.GetValueOrDefault(x.AppKey, GlobalConst.EmptyString),
CustomId = x.CustomId, CustomId = x.CustomId,
CustomName = customDict.GetValueOrDefault(x.CustomId, GlobalConst.EmptyString), CustomName = customDict.GetValueOrDefault(x.CustomId, GlobalConst.EmptyString),
Name = x.Name, Name = x.Name,
@ -69,7 +69,7 @@ public class WarningService : ApplicationServiceBase
Version = x.Version, Version = x.Version,
CreateTime = x.CreateTime, CreateTime = x.CreateTime,
UpdateTime = x.UpdateTime, UpdateTime = x.UpdateTime,
}).ToList()); }).ToList();
} }
/// <summary> /// <summary>
@ -79,7 +79,7 @@ public class WarningService : ApplicationServiceBase
/// <returns></returns> /// <returns></returns>
/// <exception cref="BusinessException"></exception> /// <exception cref="BusinessException"></exception>
[HttpPost("UpdateEnabledStatus")] [HttpPost("UpdateEnabledStatus")]
public async Task<UnifyResultDto<IdBaseDto>> UpdateEnabledStatus(UpdateEnabledStatusInput input) public async Task<IdBaseDto> UpdateEnabledStatus(UpdateEnabledStatusInput input)
{ {
var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, (WarningRuleType) input.WarningType); var rule = await _warningRuleRepository.GetWarningRuleByIdAsync(input.WarningId, (WarningRuleType) input.WarningType);
if (rule == null) if (rule == null)
@ -105,10 +105,10 @@ public class WarningService : ApplicationServiceBase
// 预警规则主体状态变化处理 // 预警规则主体状态变化处理
await HandleRuleEnabledChangedAsync(rule); await HandleRuleEnabledChangedAsync(rule);
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto return new IdBaseDto
{ {
Id = rule.Id Id = rule.Id
}); };
} }
/// <summary> /// <summary>
@ -117,7 +117,7 @@ public class WarningService : ApplicationServiceBase
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("UpsertWarningRule")] [HttpPost("UpsertWarningRule")]
public async Task<UnifyResultDto<IdBaseDto>> UpsertWarningRule(UpsertWarningRuleInput input) public async Task<IdBaseDto> UpsertWarningRule(UpsertWarningRuleInput input)
{ {
WarningRuleEntity? ruleEntity = null; WarningRuleEntity? ruleEntity = null;
// 当为修改操作时,则要求被修改的主体必须存在 // 当为修改操作时,则要求被修改的主体必须存在
@ -169,10 +169,10 @@ public class WarningService : ApplicationServiceBase
if (enabledChanged) if (enabledChanged)
await HandleRuleEnabledChangedAsync(ruleEntity); await HandleRuleEnabledChangedAsync(ruleEntity);
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto return new IdBaseDto
{ {
Id = id Id = id
}); };
} }
private async Task HandleRuleEnabledChangedAsync(WarningRuleEntity rule) private async Task HandleRuleEnabledChangedAsync(WarningRuleEntity rule)

View File

@ -189,12 +189,6 @@ public class OrderEntity : FullAuditedAggregateRoot<int>
[SugarColumn(ColumnName = "DestinationTimeZone")] [SugarColumn(ColumnName = "DestinationTimeZone")]
public float? DestinationTimeZone { get; set; } public float? DestinationTimeZone { get; set; }
/// <summary>
/// 模板code
/// </summary>
[SugarColumn(ColumnName = "TemplateCodes")]
public string? TemplateCodes { get; set; }
/// <summary> /// <summary>
/// 冗余订单第三方订单号(创建订单,更新订单时维护) /// 冗余订单第三方订单号(创建订单,更新订单时维护)
/// </summary> /// </summary>

View File

@ -0,0 +1,33 @@
namespace TrackCenter.Domain;
public static class ExpressionExtensions
{
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
Expression right = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body);
return Expression.Lambda<Func<T, bool>>((Expression) Expression.AndAlso(expr1.Body, right), (IEnumerable<ParameterExpression>) expr1.Parameters);
}
public static Expression<Func<T, bool>> Or<T>(this Expression<Func<T, bool>> expr1,
Expression<Func<T, bool>> expr2)
{
var expr2Body = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body);
return Expression.Lambda<Func<T, bool>>(Expression.OrElse(expr1.Body, expr2Body), expr1.Parameters);
}
private class RebindParameterVisitor : ExpressionVisitor
{
private readonly ParameterExpression _oldParameter;
private readonly ParameterExpression _newParameter;
public RebindParameterVisitor(ParameterExpression oldParameter, ParameterExpression newParameter)
{
_oldParameter = oldParameter;
_newParameter = newParameter;
}
protected override Expression VisitParameter(ParameterExpression node)
{
return node == _oldParameter ? _newParameter : base.VisitParameter(node);
}
}
}

View File

@ -116,29 +116,4 @@ public static class CollectionExtensions
_ => false _ => false
}; };
} }
public static Expression<Func<T, bool>> And<T>(this Expression<Func<T, bool>> expr1, Expression<Func<T, bool>> expr2)
{
Expression right = new RebindParameterVisitor(expr2.Parameters[0], expr1.Parameters[0]).Visit(expr2.Body);
return Expression.Lambda<Func<T, bool>>((Expression) Expression.AndAlso(expr1.Body, right), (IEnumerable<ParameterExpression>) expr1.Parameters);
}
private class RebindParameterVisitor : ExpressionVisitor
{
private readonly ParameterExpression _oldParameter;
private readonly ParameterExpression _newParameter;
public RebindParameterVisitor(ParameterExpression oldParameter, ParameterExpression newParameter)
{
_oldParameter = oldParameter;
_newParameter = newParameter;
}
protected override Expression VisitParameter(ParameterExpression node)
{
return node == _oldParameter ? _newParameter : base.VisitParameter(node);
}
}
} }