From ca68cde257cbdcdbcd7d865016af8057c72a91ea Mon Sep 17 00:00:00 2001 From: xiaolipro <2357729423@qq.com> Date: Wed, 31 Jul 2024 18:21:23 +0800 Subject: [PATCH] temp --- .../Forewarning/WarningNotifyCacheEntry.cs | 18 ++--- .../Dtos/Forewarning/WarningOrderDto.cs | 5 ++ .../Services/IForewarningNotifyService.cs | 3 +- ...TrackChangeAfterUpdateOrderEventHandler.cs | 1 + .../Helpers/ForewarningHelper.cs | 2 + .../ForewarningCacheService.cs | 15 ++-- .../ForewarningNotifyService.cs | 68 +++++++++--------- .../ForewarningServices/ForewarningService.cs | 25 +++++-- .../IWarningRepository.cs | 14 ---- .../ForewarningAggregate/WarningRuleEntity.cs | 16 ++++- .../Consts/GlobalConst.Redis.cs | 5 ++ .../Dtos/Forewarning/GetWarningNotifiesVo.cs | 69 +++++++++++++++++++ .../Queries/IWarningQueries.cs | 27 ++++++++ .../Queries/WarningQueries.cs | 66 ++++++++++++++++++ .../Repositories/WarningRepository.cs | 36 ---------- .../SJZY.Track.Repository.csproj | 12 ++++ .../Entitys/TrackPushRecordEntity.cs | 59 ---------------- .../Services/ITrackPushRecordRepository.cs | 8 --- .../Services/TrackPushRecordRepository.cs | 10 --- .../Entitys/TrackPushRecordDetailsEntity.cs | 47 ------------- .../ITrackPushRecordDetailsRepository.cs | 8 --- .../TrackPushRecordDetailsRepository.cs | 10 --- 22 files changed, 271 insertions(+), 253 deletions(-) create mode 100644 src/SJZY.Track.Domain/Dtos/Forewarning/GetWarningNotifiesVo.cs create mode 100644 src/SJZY.Track.Domain/Queries/IWarningQueries.cs create mode 100644 src/SJZY.Track.Repository/Queries/WarningQueries.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecord/Entitys/TrackPushRecordEntity.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecord/Services/ITrackPushRecordRepository.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecord/Services/TrackPushRecordRepository.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecordDetails/Entitys/TrackPushRecordDetailsEntity.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecordDetails/Services/ITrackPushRecordDetailsRepository.cs delete mode 100644 src/SJZY.Track.Repository/TrackPushRecordDetails/Services/TrackPushRecordDetailsRepository.cs diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningNotifyCacheEntry.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningNotifyCacheEntry.cs index 71112bb8..61913c6d 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningNotifyCacheEntry.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningNotifyCacheEntry.cs @@ -2,17 +2,17 @@ namespace SJZY.Track.Application.Contract.Dtos.Forewarning; public class WarningNotifyCacheEntry { - /// - /// 订单id - /// - public int OrderId { get; set; } - /// /// 规则id /// public int RuleId { get; set; } + + /// + /// 订单id + /// + public int OrderId { get; set; } - public WarningNotifyCacheEntry(int orderId, int ruleId) + public WarningNotifyCacheEntry(int ruleId, int orderId) { RuleId = ruleId; OrderId = orderId; @@ -21,12 +21,12 @@ public class WarningNotifyCacheEntry public WarningNotifyCacheEntry(string notifyValue) { var values = notifyValue.Split(':'); - OrderId = int.Parse(values[0]); - RuleId = int.Parse(values[1]); + RuleId = int.Parse(values[0]); + OrderId = int.Parse(values[1]); } public override string ToString() { - return $"{OrderId}:{RuleId}"; + return $"{RuleId}:{OrderId}"; } } \ No newline at end of file diff --git a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs index c9a395b9..035175cc 100644 --- a/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs +++ b/src/SJZY.Track.Application.Contract/Dtos/Forewarning/WarningOrderDto.cs @@ -7,6 +7,11 @@ public class WarningOrderDto /// public int Id { get; set; } + /// + /// 轨迹发生时间 + /// + public DateTime TrackTime { get; set; } + public string? CargoType { get; set; } public int Month { get; set; } diff --git a/src/SJZY.Track.Application.Contract/Services/IForewarningNotifyService.cs b/src/SJZY.Track.Application.Contract/Services/IForewarningNotifyService.cs index 2709a84c..914535ae 100644 --- a/src/SJZY.Track.Application.Contract/Services/IForewarningNotifyService.cs +++ b/src/SJZY.Track.Application.Contract/Services/IForewarningNotifyService.cs @@ -19,6 +19,5 @@ public interface IForewarningNotifyService /// /// 发送通知。 /// - /// 通知间隔时间,以分钟为单位。 - void SendNotification(int intervalMinute); + Task SendNotificationAsync(); } \ No newline at end of file diff --git a/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs b/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs index 2d9540aa..9c642169 100644 --- a/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs +++ b/src/SJZY.Track.Application/CAP/EventHandlers/TrackChangeAfterUpdateOrderEventHandler.cs @@ -125,6 +125,7 @@ public class TrackChangeAfterUpdateOrderEventHandler : ITransientDependency, ICa Orders = orders.Select(order => new WarningOrderDto { Id = order.Id, + TrackTime = @event.TrackTime, CargoType = order.CargoType, Month = order.CreateTime.Month, diff --git a/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs b/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs index eb79d6f0..50ea1424 100644 --- a/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs +++ b/src/SJZY.Track.Application/Helpers/ForewarningHelper.cs @@ -60,7 +60,9 @@ public class ForewarningHelper for (var i = 0; i < repeat; i++, row++) { rules[row].StartTrackStatusId = span.StartTrackStatusId; + rules[row].StartTrackStatus = span.StartTrackStatus; rules[row].EndTrackStatusId = span.EndTrackStatusId; + rules[row].EndTrackStatus = span.EndTrackStatus; } } } diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningCacheService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningCacheService.cs index effa72e3..7c3b3b00 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningCacheService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningCacheService.cs @@ -1,13 +1,12 @@ using System.Collections.Concurrent; -using FreeRedis; using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core.PublicMethords; using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Application.Contract.Services; -using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.KPIAreaAggregate; using SJZY.Track.Domain.Consts; using SJZY.Track.Domain.Dtos.Forewarning; +using SJZY.Track.Domain.Queries; using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.ForewarningServices; @@ -15,17 +14,17 @@ namespace SJZY.Track.Application.Services.ForewarningServices; public class ForewarningCacheService : IForewarningCacheService, ISingletonDependency { readonly IKpiAreaRepository _kpiAreaRepository; - readonly IWarningRepository _warningRepository; - + private readonly IWarningQueries _warningQueries; + private const string GlobalWaningLockKey = "GlobalWaningLockKey_GlobalLock"; private readonly ConcurrentDictionary> _rules = new(); private readonly ConcurrentDictionary> _areas = new(); object _lock = new object(); - public ForewarningCacheService(IKpiAreaRepository kpiAreaRepository, IWarningRepository warningRepository) + public ForewarningCacheService(IKpiAreaRepository kpiAreaRepository, IWarningQueries warningQueries) { _kpiAreaRepository = kpiAreaRepository; - _warningRepository = warningRepository; + _warningQueries = warningQueries; } string WarningKey(int subSystemId, int customerId) => @@ -105,7 +104,7 @@ public class ForewarningCacheService : IForewarningCacheService, ISingletonDepen { if (_rules.TryGetValue(key, out var ruleResult)) return ruleResult; - var warnings = await _warningRepository.GetWarningRule(systemId, customerId); + var warnings = await _warningQueries.GetWarningRule(systemId, customerId); if (warnings == null || warnings.Count == 0) { RedisHelper.Client.Set(key, new List(), TimeSpan.FromSeconds(20)); @@ -202,7 +201,7 @@ public class ForewarningCacheService : IForewarningCacheService, ISingletonDepen public async Task ClearRedisByAreaId(int areaId) { - var baseInfos = await _warningRepository.GetWarningRuleByAreaId(areaId); + var baseInfos = await _warningQueries.GetWarningRuleByAreaId(areaId); if(baseInfos==null||baseInfos.Count==0) return; baseInfos = baseInfos.DistinctBy(val => WarningKey(val.SystemId, val.CustomerId)).ToList(); diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs index 003d6cf6..ea453aca 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningNotifyService.cs @@ -2,7 +2,9 @@ using FreeRedis; using SJZY.Expand.ABP.Core; using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Application.Contract.Services; +using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Consts; +using SJZY.Track.Domain.Queries; using Volo.Abp.DependencyInjection; namespace SJZY.Track.Application.Services.ForewarningServices; @@ -12,11 +14,13 @@ namespace SJZY.Track.Application.Services.ForewarningServices; /// public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency { - private readonly ForewarningCacheService _cacheService; + private readonly IForewarningCacheService _cacheService; + private readonly IWarningQueries _warningQueries; - public ForewarningNotifyService(ForewarningCacheService cacheService) + public ForewarningNotifyService(IForewarningCacheService cacheService, IWarningQueries warningQueries) { _cacheService = cacheService; + _warningQueries = warningQueries; } /// @@ -31,8 +35,8 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep var rules = await _cacheService.GetRulesAsync(dto.SubSystemId, dto.CustomerId); if (rules == null || rules.Count == 0) return; - var zMembers = new List(); - var members = new List(); + var adds = new List<(int ruleId, int orderId, int cnt, long ts)>(); + var dels = new List<(int ruleId, int orderId)>(); foreach (var order in dto.Orders) { MatchRule( @@ -40,33 +44,28 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep order ).ForEach(rule => { - var notifyTimestamp = GetTimestamp(DateTime.Now.AddMinutes(rule.WarnTimeSpan)); - var entry = new WarningNotifyCacheEntry(rule.Id, order.Id); - var notifyValue = new ZMember(entry.ToString(), notifyTimestamp); - zMembers.Add(notifyValue); + var timestamp = GetTimestamp(order.TrackTime.AddMinutes(rule.WarnTimeSpan)); + adds.Add((rule.Id, order.Id, rule.WarnCount, timestamp)); }); - var endingRules = MatchRule( + MatchRule( rules.Where(rule => rule.EndTrackStatusId == dto.TrackStatusId).ToList(), order - ); - - foreach (var member in endingRules.Select(rule => - new WarningNotifyCacheEntry(rule.Id, order.Id).ToString()) - ) - { - // todo: pipeline optimize? - var score = await RedisHelper.Client.ZScoreAsync(GlobalConst.ForewarningNotifyKey, member); - // tips: score is null 说明发生ending时,没有匹配到规则,所以没有add到set,不需要删除 - if (score != null && (long)score > GetTimestamp(DateTime.Now)) - { - members.Add(member); - } - } + ).ForEach(rule => { dels.Add((rule.Id, order.Id)); }); } - await RedisHelper.Client.ZAddAsync(GlobalConst.ForewarningNotifyKey, zMembers.ToArray()); - await RedisHelper.Client.ZRemAsync(GlobalConst.ForewarningNotifyKey, members.ToArray()); + + await RedisHelper.Client.HSetAsync(GlobalConst.ForewarningNotifyCntKey, + adds.ToDictionary(x => $"{x.ruleId}_{x.orderId}", x => x.cnt)); + await RedisHelper.Client.ZAddAsync(GlobalConst.ForewarningNotifyKey, adds.Select(x => + { + var entry = new WarningNotifyCacheEntry(x.ruleId, x.orderId); + return new ZMember(entry.ToString(), x.ts); + }).ToArray()); + await RedisHelper.Client.HDelAsync(GlobalConst.ForewarningNotifyCntKey, + dels.Select(x => $"{x.ruleId}_{x.orderId}").ToArray()); + // await RedisHelper.Client.ZRemAsync(GlobalConst.ForewarningNotifyKey, + // dels.Select(x => $"{x.ruleId}:{x.orderId}").ToArray()); } private static List MatchRule(List rules, @@ -118,17 +117,20 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep return res; } - public void SendNotification(int intervalMinute) + public async Task SendNotificationAsync() { - var currentTimestamp = GetTimestamp(DateTime.Now); - var notifyMembers = - RedisHelper.Client.ZRangeByScore(GlobalConst.ForewarningNotifyKey, 0, currentTimestamp); - if (notifyMembers == null || notifyMembers.Length == 0) - return; + var max = GetTimestamp(DateTime.Now); + var set = await RedisHelper.Client.ZRangeByScoreAsync(GlobalConst.ForewarningNotifyKey, 0, max); + + if (set.IsNullOrEmpty()) return; - var notifyValues = notifyMembers.Select(val => new WarningNotifyCacheEntry(val)); - foreach (var notifyValue in notifyValues) + var entries = set.Select(x => new WarningNotifyCacheEntry(x)).ToList(); + var ruleIds = entries.Select(x => x.RuleId).ToList(); + var notifyRules = await _warningQueries.GetWarningNotifyRulesAsync(ruleIds); + + foreach (var group in notifyRules) { + } } diff --git a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs index a155a5f6..454692dc 100644 --- a/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs +++ b/src/SJZY.Track.Application/Services/ForewarningServices/ForewarningService.cs @@ -1,6 +1,7 @@ using System.ComponentModel.DataAnnotations; using SJZY.Track.Application.Contract.Dtos.Common; using SJZY.Track.Application.Contract.Dtos.Forewarning; +using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Helpers; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.TrackStatusAggregate; @@ -15,10 +16,12 @@ namespace SJZY.Track.Application.Services.ForewarningServices; public class ForewarningService : ApplicationService { private readonly IWarningRepository _warningRepository; + private readonly IForewarningCacheService _forewarningCacheService; - public ForewarningService(IWarningRepository warningRepository) + public ForewarningService(IWarningRepository warningRepository, IForewarningCacheService forewarningCacheService) { _warningRepository = warningRepository; + _forewarningCacheService = forewarningCacheService; } /// @@ -115,7 +118,7 @@ public class ForewarningService : ApplicationService }).ToList(); await _warningRepository.UpdateForewarningAsync(warning); - + return true; } @@ -145,7 +148,12 @@ public class ForewarningService : ApplicationService warning.SetEnable(isEnable); - return await _warningRepository.TurnWarningAsync(warning); + await _warningRepository.TurnWarningAsync(warning); + + // 清除缓存 + await _forewarningCacheService.DeleteRulesAsync(warning.SubSystemId, warning.CustomerId); + + return true; } /// @@ -174,17 +182,20 @@ public class ForewarningService : ApplicationService [HttpPost("ModifyTimeSpans")] public async Task ModifyTimeSpans(ModifyTimeSpanInput input) { - if (!await _warningRepository.IsAnyAsync(x => x.Id == input.WarningId)) + if (input.Items.IsNullOrEmpty()) return false; + + var warning = await _warningRepository.GetFirstAsync(x => x.Id == input.WarningId); + if (warning == null) { throw new BusinessException(message: "预警不存在"); } - if (input.Items.IsNullOrEmpty()) return false; - var warningRules = ObjectMapper.Map, List>(input.Items); await _warningRepository.ModifyTimeSpansAsync(warningRules); - + + // 清除缓存 + await _forewarningCacheService.DeleteRulesAsync(warning.SubSystemId, warning.CustomerId); return true; } } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs index e06ea6ae..efa73bbd 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/IWarningRepository.cs @@ -59,18 +59,4 @@ public interface IWarningRepository : IBasicRepository /// /// Task GetByIdAsync(int warningId); - - /// - /// 获取预警规则列表 - /// - /// - Task?> GetWarningRule(int systemId, int customerId); - - /// - /// 获取预警规则基础信息 - /// - /// - /// - Task?> GetWarningRuleByAreaId(int areaId); - } \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs index 4baac33e..56a95930 100644 --- a/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs +++ b/src/SJZY.Track.Domain/Aggregates/ForewarningAggregate/WarningRuleEntity.cs @@ -36,14 +36,26 @@ public class WarningRuleEntity : IFullAuditedBasicEntitys, IEntity /// /// 起始轨迹状态id /// - [SugarColumn(ColumnName = "StartTrackStatusId", IsNullable = false)] + [SugarColumn(ColumnName = "StartTrackStatusId")] public int StartTrackStatusId { get; set; } + + /// + /// 起始轨迹状态(冗余) + /// + [SugarColumn(ColumnName = "StartTrackStatusId")] + public string StartTrackStatus { get; set; } = null!; /// /// 终止轨迹状态id /// - [SugarColumn(ColumnName = "EndTrackStatusId", IsNullable = false)] + [SugarColumn(ColumnName = "EndTrackStatusId")] public int EndTrackStatusId { get; set; } + + /// + /// 终止轨迹状态(冗余) + /// + [SugarColumn(ColumnName = "EndTrackStatus")] + public string EndTrackStatus { get; set; } = null!; /// /// 货物类型 diff --git a/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs b/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs index 1d7be074..06972eff 100644 --- a/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs +++ b/src/SJZY.Track.Domain/Consts/GlobalConst.Redis.cs @@ -27,6 +27,11 @@ public partial class GlobalConst /// public const string ForewarningNotifyKey = "ForewarningNotify"; + /// + /// 预警通知剩余次数redis key + /// + public const string ForewarningNotifyCntKey = "ForewarningNotifyCnt"; + /// /// kpi区域redis key前缀 /// diff --git a/src/SJZY.Track.Domain/Dtos/Forewarning/GetWarningNotifiesVo.cs b/src/SJZY.Track.Domain/Dtos/Forewarning/GetWarningNotifiesVo.cs new file mode 100644 index 00000000..d39fc838 --- /dev/null +++ b/src/SJZY.Track.Domain/Dtos/Forewarning/GetWarningNotifiesVo.cs @@ -0,0 +1,69 @@ +namespace SJZY.Track.Domain.Dtos.Forewarning; + +public class GetWarningNotifiesVo +{ + /// + /// rule id + /// + public int Id { get; set; } + + /// + /// 预警名称 + /// + public string WarningName { get; set; } = null!; + + /// + /// 时效(小时) + /// + public float TotalTimeSpan { get; set; } + + /// + /// 提醒的时间(小时) + /// + public float WarnTimeSpan { get; set; } + + /// + /// 提醒次数 + /// + public int WarnCount { get; set; } + + /// + /// 起始轨迹状态(冗余) + /// + public string StartTrackStatus { get; set; } = null!; + + /// + /// 终止轨迹状态(冗余) + /// + public string EndTrackStatus { get; set; } = null!; + + /// + /// 货物类型 + /// + public string? CargoType { get; set; } + + /// + /// 月份 + /// + public string? Months { get; set; } + + /// + /// 区域 + /// + public string? AreaName { get; set; } + + /// + /// 是否中转 + /// + public bool? IsTransit { get; set; } + + /// + /// 起运港口 + /// + public string? LeavePort { get; set; } + + /// + /// 产品编码 + /// + public string? ProductCode { get; set; } +} \ No newline at end of file diff --git a/src/SJZY.Track.Domain/Queries/IWarningQueries.cs b/src/SJZY.Track.Domain/Queries/IWarningQueries.cs new file mode 100644 index 00000000..b3652bf6 --- /dev/null +++ b/src/SJZY.Track.Domain/Queries/IWarningQueries.cs @@ -0,0 +1,27 @@ +using SJZY.Track.Domain.Dtos.Forewarning; + +namespace SJZY.Track.Domain.Queries; + +public interface IWarningQueries +{ + /// + /// 获取预警通知数据 + /// + /// + /// + Task> GetWarningNotifyRulesAsync(List ruleIds); + + + /// + /// 获取预警规则列表 + /// + /// + Task?> GetWarningRule(int systemId, int customerId); + + /// + /// 获取预警规则基础信息 + /// + /// + /// + Task?> GetWarningRuleByAreaId(int areaId); +} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Queries/WarningQueries.cs b/src/SJZY.Track.Repository/Queries/WarningQueries.cs new file mode 100644 index 00000000..e9b3ec5c --- /dev/null +++ b/src/SJZY.Track.Repository/Queries/WarningQueries.cs @@ -0,0 +1,66 @@ +using SJZY.Track.Domain.Aggregates.ForewarningAggregate; +using SJZY.Track.Domain.Dtos.Forewarning; +using SJZY.Track.Domain.Queries; + +namespace SJZY.Track.Repository.Queries; + +public class WarningQueries : ISugarRepository, IWarningQueries, + ITransientDependency +{ + public ISqlSugarClient Context { get; set; } + + public WarningQueries() + { + Context = SqlsugarScopeBasic.GetContextSafely("default"); + } + + public async Task> GetWarningNotifyRulesAsync(List ruleIds) + { + return await Context.Queryable() + .LeftJoin((a, b) => a.Id == b.WarningId) + .LeftJoin((a, b, c) => + b.WarningId == c.WarningId && b.StartTrackStatusId == c.StartTrackStatusId && + b.EndTrackStatusId == c.EndTrackStatusId) + .Where((a, b) => ruleIds.Contains(b.Id)) + .Select((a, b, c) => new GetWarningNotifiesVo + { + WarningName = a.Name + }, true) + .ToListAsync(); + } + + public Task?> GetWarningRule(int systemId, int customerId) + { + return Context.Queryable() + .InnerJoin((a, b) => a.WarningId == b.Id) + .Where((a, b) => b.IsEnable && b.SubSystemId == systemId && b.CustomerId == customerId) + .Select((a, b) => new WarningRuleCacheDto + { + Id = a.Id, + WarningId = a.WarningId, + TotalTimeSpan = a.TotalTimeSpan, + WarnTimeSpan = a.WarnTimeSpan, + WarnCount = a.WarnCount, + StartTrackStatusId = a.StartTrackStatusId, + EndTrackStatusId = a.EndTrackStatusId, + CargoType = a.CargoType, + Months = a.Months, + AreaId = a.AreaId, + IsTransit = a.IsTransit, + LeavePort = a.LeavePort, + ProductCode = a.ProductCode, + CustomerId = b.CustomerId, + SystemId = b.SubSystemId + }) + .ToListAsync(); + } + + public Task?> GetWarningRuleByAreaId(int areaId) + { + return Context.Queryable() + .InnerJoin((a, b) => a.WarningId == b.Id) + .Where((a, b) => b.IsEnable && a.AreaId == areaId) + .Select((a, b) => new RuleAreaBaseInfo(b.CustomerId, b.SubSystemId)) + .ToListAsync(); + } +} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/Repositories/WarningRepository.cs b/src/SJZY.Track.Repository/Repositories/WarningRepository.cs index 61463fe0..fe25f1d7 100644 --- a/src/SJZY.Track.Repository/Repositories/WarningRepository.cs +++ b/src/SJZY.Track.Repository/Repositories/WarningRepository.cs @@ -109,40 +109,4 @@ public class WarningRepository : BasicRepository, IWarningReposit return warning; } - - public Task?> GetWarningRule(int systemId, int customerId) - { - return Context.Queryable() - .InnerJoin((a, b) => a.WarningId == b.Id) - .Where((a,b)=>b.IsEnable && b.SubSystemId == systemId && b.CustomerId == customerId) - .Select((a,b)=>new WarningRuleCacheDto - { - Id = a.Id, - WarningId = a.WarningId, - TotalTimeSpan = a.TotalTimeSpan, - WarnTimeSpan = a.WarnTimeSpan, - WarnCount = a.WarnCount, - StartTrackStatusId = a.StartTrackStatusId, - EndTrackStatusId = a.EndTrackStatusId, - CargoType = a.CargoType, - Months = a.Months, - AreaId = a.AreaId, - IsTransit = a.IsTransit, - LeavePort = a.LeavePort, - ProductCode = a.ProductCode, - CustomerId = b.CustomerId, - SystemId = b.SubSystemId - }) - .ToListAsync(); - } - - public Task?> GetWarningRuleByAreaId(int areaId) - { - return Context.Queryable() - .InnerJoin((a, b) => a.WarningId == b.Id) - .Where((a,b)=>b.IsEnable && a.AreaId==areaId) - .Select((a,b)=>new RuleAreaBaseInfo(b.CustomerId,b.SubSystemId)) - .ToListAsync(); - } - } \ No newline at end of file diff --git a/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj b/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj index 35617f6a..1c38bf3e 100644 --- a/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj +++ b/src/SJZY.Track.Repository/SJZY.Track.Repository.csproj @@ -17,4 +17,16 @@ + + + + + + + + + + + + diff --git a/src/SJZY.Track.Repository/TrackPushRecord/Entitys/TrackPushRecordEntity.cs b/src/SJZY.Track.Repository/TrackPushRecord/Entitys/TrackPushRecordEntity.cs deleted file mode 100644 index b3c2ff5b..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecord/Entitys/TrackPushRecordEntity.cs +++ /dev/null @@ -1,59 +0,0 @@ -using SJZY.Track.Domain.SeedWork; - -namespace SJZY.Track.Repository.TrackPushRecord.Entitys -{ - /// - /// 轨迹推送记录 - /// - [SugarTable("t_track_push_record")] - public class TrackPushRecordEntity : IAggregateRoot - { - /// - /// 自增主键 - /// - [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] - public int Id { get; set; } - - /// - /// 创建时间(推送时间) - /// - [SugarColumn(ColumnName = "CreateTime")] - public DateTime CreateTime { get; set; } - - /// - /// 创建人(推送人) - /// - [SugarColumn(ColumnName = "CreateUserId")] - public int CreateUserId { get; set; } - - /// - /// 是否自动推送 - /// - [SugarColumn(ColumnName = "IsAutoPush")] - public bool IsAutoPush { get; set; } - - /// - /// 推送内容 - /// - [SugarColumn(ColumnName = "PushContent")] - public string PushContent { get; set; } = null!; - - /// - /// 接口通请求id - /// - [SugarColumn(ColumnName = "RequestId")] - public string RequestId { get; set; } = null!; - - /// - /// 服务商id - /// - [SugarColumn(ColumnName = "ServiceProviderId")] - public int ServiceProviderId { get; set; } - - /// - /// 推送轨迹总数 - /// - [SugarColumn(ColumnName = "TrackTotal")] - public int TrackTotal { get; set; } - } -} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/TrackPushRecord/Services/ITrackPushRecordRepository.cs b/src/SJZY.Track.Repository/TrackPushRecord/Services/ITrackPushRecordRepository.cs deleted file mode 100644 index 686a3402..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecord/Services/ITrackPushRecordRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using SJZY.Track.Repository.TrackPushRecord.Entitys; - -namespace SJZY.Track.Repository.TrackPushRecord.Services -{ - public interface ITrackPushRecordRepository : ISimpleClient - { - } -} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/TrackPushRecord/Services/TrackPushRecordRepository.cs b/src/SJZY.Track.Repository/TrackPushRecord/Services/TrackPushRecordRepository.cs deleted file mode 100644 index e8e16ab9..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecord/Services/TrackPushRecordRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using SJZY.Track.Repository.Repositories; -using SJZY.Track.Repository.TrackPushRecord.Entitys; - -namespace SJZY.Track.Repository.TrackPushRecord.Services -{ - public class TrackPushRecordRepository : BasicRepository, ITrackPushRecordRepository, IScopedDependency - { - - } -} diff --git a/src/SJZY.Track.Repository/TrackPushRecordDetails/Entitys/TrackPushRecordDetailsEntity.cs b/src/SJZY.Track.Repository/TrackPushRecordDetails/Entitys/TrackPushRecordDetailsEntity.cs deleted file mode 100644 index 64208102..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecordDetails/Entitys/TrackPushRecordDetailsEntity.cs +++ /dev/null @@ -1,47 +0,0 @@ -using SJZY.Track.Domain.SeedWork; - -namespace SJZY.Track.Repository.TrackPushRecordDetails.Entitys -{ - /// - /// 轨迹推送明细表 - /// - [SugarTable("t_track_push_record_details")] - public class TrackPushRecordDetailsEntity : IAggregateRoot - { - /// - /// 自增主键 - /// - [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] - public int Id { get; set; } - - /// - /// 创建时间(消费完成时间) - /// - [SugarColumn(ColumnName = "CreateTime")] - public DateTime CreateTime { get; set; } - - /// - /// 异常信息 - /// - [SugarColumn(ColumnName = "ErrorMessage")] - public string ErrorMessage { get; set; } - - /// - /// 是否成功 - /// - [SugarColumn(ColumnName = "IsSuccess")] - public bool IsSuccess { get; set; } - - /// - /// 订单id - /// - [SugarColumn(ColumnName = "OrderId")] - public int OrderId { get; set; } - - /// - /// 推送记录id - /// - [SugarColumn(ColumnName = "PushRecordId")] - public int PushRecordId { get; set; } - } -} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/ITrackPushRecordDetailsRepository.cs b/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/ITrackPushRecordDetailsRepository.cs deleted file mode 100644 index f84fafa7..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/ITrackPushRecordDetailsRepository.cs +++ /dev/null @@ -1,8 +0,0 @@ -using SJZY.Track.Repository.TrackPushRecordDetails.Entitys; - -namespace SJZY.Track.Repository.TrackPushRecordDetails.Services -{ - public interface ITrackPushRecordDetailsRepository : ISimpleClient - { - } -} \ No newline at end of file diff --git a/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/TrackPushRecordDetailsRepository.cs b/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/TrackPushRecordDetailsRepository.cs deleted file mode 100644 index 3a8c025b..00000000 --- a/src/SJZY.Track.Repository/TrackPushRecordDetails/Services/TrackPushRecordDetailsRepository.cs +++ /dev/null @@ -1,10 +0,0 @@ -using SJZY.Track.Repository.Repositories; -using SJZY.Track.Repository.TrackPushRecordDetails.Entitys; - -namespace SJZY.Track.Repository.TrackPushRecordDetails.Services -{ - public class TrackPushRecordDetailsRepository : BasicRepository, ITrackPushRecordDetailsRepository, IScopedDependency - { - - } -}