对接前端轨迹预警

This commit is contained in:
xiaolipro 2024-09-20 15:07:58 +08:00
parent c22421676c
commit 1a16606443
20 changed files with 146 additions and 79 deletions

View File

@ -26,9 +26,9 @@ public class NotifyDto
public int Id { get; set; } public int Id { get; set; }
/// <summary> /// <summary>
/// 通知人id /// 通知人
/// </summary> /// </summary>
public List<int> NotifyUserIds { get; set; } public List<NotifyUser> NotifyUsers { get; set; }
/// <summary> /// <summary>
/// 通知方式(1站内信,2飞书) /// 通知方式(1站内信,2飞书)

View File

@ -22,18 +22,26 @@ public class WarningNotifyDto
/// </summary> /// </summary>
public string EndTrackStatus { get; set; } = null!; public string EndTrackStatus { get; set; } = null!;
/// <summary>
/// 通知人id
/// </summary>
public List<int> NotifyUserIds { get; set; }
/// <summary> /// <summary>
/// 通知人 /// 通知人
/// </summary> /// </summary>
public List<string> NotifyUsers { get; set; } public List<NotifyUser> NotifyUsers { get; set; }
/// <summary> /// <summary>
/// 通知方式(1站内信,2飞书) /// 通知方式(1站内信,2飞书)
/// </summary> /// </summary>
public List<int> NotifyModes { get; set; } public List<int> NotifyModes { get; set; }
} }
public class NotifyUser
{
/// <summary>
/// 用户id
/// </summary>
public int UserId { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
}

View File

@ -28,7 +28,7 @@ public class WarningNotifyCacheEntry
public int OrderId { get; set; } public int OrderId { get; set; }
/// <summary> /// <summary>
/// 预警次数 /// 预警次数(第几次)
/// </summary> /// </summary>
public int Counter { get; set; } public int Counter { get; set; }

View File

@ -107,9 +107,11 @@ public class TrackDeleteEventHandler : ITransientDependency, ICapSubscribe
// 删除轨迹(删的是同子系统下的单,所以code是统一的) // 删除轨迹(删的是同子系统下的单,所以code是统一的)
var tracks = await _trackDetailsEsRepository.GetLatestListAsync(@event.OrderIds, @event.TrackCodes); var tracks = await _trackDetailsEsRepository.GetLatestListAsync(@event.OrderIds, @event.TrackCodes);
await _trackDetailsEsRepository.DeleteTrackAsync(@event.OrderIds, @event.TrackCodes); var orderIds = await _trackDetailsEsRepository.DeleteTrackAsync(@event.OrderIds, @event.TrackCodes);
var orders = await _orderRepository.GetListAsync(x => @event.OrderIds.Contains(x.Id), if (orderIds.Count == 0) return;
var orders = await _orderRepository.GetListAsync(x => orderIds.Contains(x.Id),
x => new OrderEntity x => new OrderEntity
{ {
Id = x.Id, Id = x.Id,

View File

@ -160,8 +160,7 @@ public class ForewarningHelper
StartTrackStatusId = x.StartTrackStatusId, StartTrackStatusId = x.StartTrackStatusId,
EndTrackStatusId = x.EndTrackStatusId, EndTrackStatusId = x.EndTrackStatusId,
NotifyMode = x.NotifyModes.JoinAsString(","), NotifyMode = x.NotifyModes.JoinAsString(","),
NotifyUser = x.NotifyUsers.JoinAsString(","), NotifyUser = x.NotifyUsers.ToJson(),
NotifyUserId = x.NotifyUserIds.JoinAsString(","),
}).ToList(); }).ToList();
} }
@ -180,8 +179,7 @@ public class ForewarningHelper
StartTrackStatus = statusDic.TryGetValue(x.StartTrackStatusId, out var start) ? start : "", StartTrackStatus = statusDic.TryGetValue(x.StartTrackStatusId, out var start) ? start : "",
EndTrackStatusId = x.EndTrackStatusId, EndTrackStatusId = x.EndTrackStatusId,
EndTrackStatus = statusDic.TryGetValue(x.EndTrackStatusId, out var end) ? end : "", EndTrackStatus = statusDic.TryGetValue(x.EndTrackStatusId, out var end) ? end : "",
NotifyUserIds = x.NotifyUserId.Split(',').Select(int.Parse).ToList(), NotifyUsers = JsonConvert.DeserializeObject<List<NotifyUser>>(x.NotifyUser) ?? new List<NotifyUser>(),
NotifyUsers = x.NotifyUser.Split(',').ToList(),
NotifyModes = x.NotifyMode.Split(',').Select(int.Parse).ToList(), NotifyModes = x.NotifyMode.Split(',').Select(int.Parse).ToList(),
}).ToList(), }).ToList(),
WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto WarningFactors = warning.WarningFactors.Select(x => new WarningFactorWithIdDto

View File

@ -16,4 +16,9 @@ public class TrackAppOptions
/// 轨迹兜底扫描间隔(秒) /// 轨迹兜底扫描间隔(秒)
/// </summary> /// </summary>
public int TrackButtomUpScanInterval { get; set; } public int TrackButtomUpScanInterval { get; set; }
/// <summary>
/// 轨迹运输时效预警通知跳转地址
/// </summary>
public string WarningNotifyUrl { get; set; }
} }

View File

@ -1,9 +1,11 @@
using System.Text; using System.Text;
using FreeRedis; using FreeRedis;
using Microsoft.Extensions.Options;
using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core;
using SJZY.Expand.ABP.Core.Logger; using SJZY.Expand.ABP.Core.Logger;
using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Options;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Enums;
@ -22,6 +24,7 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency
{ {
private readonly IForewarningCacheService _forewarningCacheService; private readonly IForewarningCacheService _forewarningCacheService;
private readonly IOptionsSnapshot<TrackAppOptions> _options;
private readonly IHttpClientProxy<IRequestSendMessageService> _requestSendMessageService; private readonly IHttpClientProxy<IRequestSendMessageService> _requestSendMessageService;
private readonly IWarningQueries _warningQueries; private readonly IWarningQueries _warningQueries;
private readonly IWarningRecordEsRepository _warningRecordEsRepository; private readonly IWarningRecordEsRepository _warningRecordEsRepository;
@ -29,12 +32,13 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
public ForewarningNotifyService(IWarningQueries warningQueries, public ForewarningNotifyService(IWarningQueries warningQueries,
IWarningRecordEsRepository warningRecordEsRepository, IWarningRecordEsRepository warningRecordEsRepository,
IHttpClientProxy<IRequestSendMessageService> requestSendMessageService, IHttpClientProxy<IRequestSendMessageService> requestSendMessageService,
IForewarningCacheService forewarningCacheService) IForewarningCacheService forewarningCacheService, IOptionsSnapshot<TrackAppOptions> options)
{ {
_warningQueries = warningQueries; _warningQueries = warningQueries;
_warningRecordEsRepository = warningRecordEsRepository; _warningRecordEsRepository = warningRecordEsRepository;
_requestSendMessageService = requestSendMessageService; _requestSendMessageService = requestSendMessageService;
_forewarningCacheService = forewarningCacheService; _forewarningCacheService = forewarningCacheService;
_options = options;
} }
@ -147,20 +151,27 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
{ {
var rule = notifyRules.FirstOrDefault(x => x.RuleId == entry.RuleId); var rule = notifyRules.FirstOrDefault(x => x.RuleId == entry.RuleId);
if (rule == null) continue; if (rule == null) continue;
foreach (var notifyUser in rule.NotifyUsers)
{
warningRecords.Add(new WarningRecordIndex warningRecords.Add(new WarningRecordIndex
{ {
SubSystemId = rule.SubSystemId, SubSystemId = rule.SubSystemId,
SubSystemName = rule.SubSystemName,
WarningName = rule.WarningName, WarningName = rule.WarningName,
CustomName = rule.CustomName, CustomName = rule.CustomName,
RuleId = entry.RuleId, RuleId = entry.RuleId,
Rule = rule.ToString(), Rule = rule.ToString(),
Counter = entry.Counter, Counter = entry.Counter,
IsLast = rule.WarnCount == entry.Counter,
OrderId = entry.OrderId, OrderId = entry.OrderId,
WarningStatus = WarningStatus.UnProcessed, WarningStatus = WarningStatus.UnProcessed,
NotifyUser = rule.NotifyUser, NotifyUserId = notifyUser.UserId,
NotifyUserName = notifyUser.UserName,
CreateTime = DateTime.Now, CreateTime = DateTime.Now,
}); });
} }
}
await _warningRecordEsRepository.BulkInsertAsync(warningRecords); await _warningRecordEsRepository.BulkInsertAsync(warningRecords);
return warningRecords; return warningRecords;
@ -172,20 +183,20 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
var userRules = new Dictionary<int, List<GetWarningNotifiesVo>>(); var userRules = new Dictionary<int, List<GetWarningNotifiesVo>>();
foreach (var rule in notifyRules) foreach (var rule in notifyRules)
{ {
foreach (var userId in rule.NotifyUserIds) foreach (var notifyUser in rule.NotifyUsers)
{ {
if (!userRules.ContainsKey(userId)) if (!userRules.ContainsKey(notifyUser.UserId))
{ {
userRules[userId] = new List<GetWarningNotifiesVo>(); userRules[notifyUser.UserId] = new List<GetWarningNotifiesVo>();
} }
userRules[userId].Add(rule); userRules[notifyUser.UserId].Add(rule);
} }
} }
// 以人的维度发送通知,异步
foreach (var userRule in userRules) foreach (var userRule in userRules)
{ {
// 以人的维度发送通知,异步
_ = DoNotifyAsync(subSystemId, userRule.Key, userRule.Value, entries, _ = DoNotifyAsync(subSystemId, userRule.Key, userRule.Value, entries,
NotifyMode.SiteInternal); NotifyMode.SiteInternal);
_ = DoNotifyAsync(subSystemId, userRule.Key, userRule.Value, entries, NotifyMode.FeiShu); _ = DoNotifyAsync(subSystemId, userRule.Key, userRule.Value, entries, NotifyMode.FeiShu);
@ -214,7 +225,8 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
*/ */
var notifyContent = new StringBuilder(); var notifyContent = new StringBuilder();
foreach (var warningGroup in rules.Where(x => x.NotifyModes.Contains(mode)) foreach (var warningGroup in rules
.Where(x => x.NotifyMode.Split(',').Select(Enum.Parse<NotifyMode>).Contains(mode))
.GroupBy(x => x.WarningName)) .GroupBy(x => x.WarningName))
{ {
notifyContent.AppendLine($"预警名称:{warningGroup.Key}"); notifyContent.AppendLine($"预警名称:{warningGroup.Key}");
@ -224,7 +236,7 @@ public class ForewarningNotifyService : IForewarningNotifyService, ITransientDep
{ {
var cnt = entries.Count(x => x.RuleId == rule.RuleId); var cnt = entries.Count(x => x.RuleId == rule.RuleId);
notifyContent.AppendLine( notifyContent.AppendLine(
$"{rule.ToString()} 命中订单总数:{cnt},详情点击https://middlebusiness.pet.shijizhongyun.com/trajectoryCenter/trajectoryOrder"); $"{rule.ToString()} 命中订单总数:{cnt},详情点击{_options.Value.WarningNotifyUrl}?userId={userId}");
} }
} }

View File

@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations;
using SJZY.Expand.ABP.Core.PublicMethords;
using SJZY.Track.Application.Contract.Dtos.Forewarning; using SJZY.Track.Application.Contract.Dtos.Forewarning;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Application.Helpers; using SJZY.Track.Application.Helpers;
@ -114,7 +115,7 @@ public class ForewarningService : ApplicationService
{ {
Id = x.Id, Id = x.Id,
NotifyMode = x.NotifyModes.JoinAsString(","), NotifyMode = x.NotifyModes.JoinAsString(","),
NotifyUserId = x.NotifyUserIds.JoinAsString(","), NotifyUser = x.NotifyUsers.ToJson(),
}).ToList(); }).ToList();
await _warningRepository.UpdateForewarningAsync(warning); await _warningRepository.UpdateForewarningAsync(warning);

View File

@ -33,11 +33,13 @@ public class OrderWarningService : ApplicationService
/// 获取订单运输时效预警分页列表 /// 获取订单运输时效预警分页列表
/// </summary> /// </summary>
/// <param name="inputVo"></param> /// <param name="inputVo"></param>
/// <param name="userId"></param>
/// <returns></returns> /// <returns></returns>
[HttpPost("GetOrderWarningPageList")] [HttpPost("GetOrderWarningPageList")]
public async Task<UnifyPageResultDto<GetOrderWarningPageOutput>> GetOrderWarningPageListAsync( public async Task<UnifyPageResultDto<GetOrderWarningPageOutput>> GetOrderWarningPageListAsync(
GetOrderWarningPageListVo inputVo) [FromBody] GetOrderWarningPageListVo inputVo, [FromQuery] int? userId)
{ {
if (userId != null) inputVo.NotifyUserId = userId;
var result = await _warningRecordEsRepository.GetOrderWarningPageListAsync(inputVo); var result = await _warningRecordEsRepository.GetOrderWarningPageListAsync(inputVo);
var orderIds = result.list.Select(x => x.OrderId).ToList(); var orderIds = result.list.Select(x => x.OrderId).ToList();
var orders = await _orderRepository.GetListAsync(x => orderIds.Contains(x.Id), x => new var orders = await _orderRepository.GetListAsync(x => orderIds.Contains(x.Id), x => new
@ -51,17 +53,18 @@ public class OrderWarningService : ApplicationService
var list = new List<GetOrderWarningPageOutput>(); var list = new List<GetOrderWarningPageOutput>();
result.list.ForEach(x => result.list.ForEach(x =>
{ {
var item = new GetOrderWarningPageOutput var item = new GetOrderWarningPageOutput
{ {
SubSystemName = x.SubSystemName,
Rule = x.Rule, Rule = x.Rule,
Counter = x.Counter, Counter = x.Counter,
IsLast = x.IsLast,
WarningName = x.WarningName, WarningName = x.WarningName,
WarningStatus = x.WarningStatus, WarningStatus = x.WarningStatus,
CreateTime = x.CreateTime, CreateTime = x.CreateTime,
NotifyUser = x.NotifyUser, NotifyUser = x.NotifyUserName,
CustomName = x.CustomName, CustomName = x.CustomName,
}; };
var order = orders.FirstOrDefault(o => o.Id == x.OrderId); var order = orders.FirstOrDefault(o => o.Id == x.OrderId);

View File

@ -10,6 +10,6 @@ public class RuleTrackStateDtoValidator : AbstractValidator<WarningNotifyDto>
RuleFor(x => x.StartTrackStatusId).GreaterThan(0).WithMessage("起始轨迹状态id必须大于0"); RuleFor(x => x.StartTrackStatusId).GreaterThan(0).WithMessage("起始轨迹状态id必须大于0");
RuleFor(x => x.EndTrackStatusId).GreaterThan(0).WithMessage("终止轨迹状态id必须大于0"); RuleFor(x => x.EndTrackStatusId).GreaterThan(0).WithMessage("终止轨迹状态id必须大于0");
RuleFor(x => x.NotifyModes).NotEmpty().WithMessage("通知方式不能为空"); RuleFor(x => x.NotifyModes).NotEmpty().WithMessage("通知方式不能为空");
RuleFor(x => x.NotifyUserIds).NotEmpty().WithMessage("通知对象不能为空"); RuleFor(x => x.NotifyUsers).NotEmpty().WithMessage("通知对象不能为空");
} }
} }

View File

@ -34,13 +34,7 @@ public class WarningNotifyEntity : IFullAuditedBasicEntitys, IEntity
public string NotifyMode { get; set; } public string NotifyMode { get; set; }
/// <summary> /// <summary>
/// 通知人id,多个逗号分隔 /// 通知人,json格式 多个
/// </summary>
[SugarColumn(ColumnName = "NotifyUserId")]
public string NotifyUserId { get; set; }
/// <summary>
/// 通知人,多个逗号分隔
/// </summary> /// </summary>
[SugarColumn(ColumnName = "NotifyUser")] [SugarColumn(ColumnName = "NotifyUser")]
public string NotifyUser { get; set; } public string NotifyUser { get; set; }

View File

@ -8,10 +8,15 @@ namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public class WarningRecordIndex : IdBaseIndex public class WarningRecordIndex : IdBaseIndex
{ {
/// <summary> /// <summary>
/// 子系统 /// 子系统id
/// </summary> /// </summary>
public int SubSystemId { get; set; } public int SubSystemId { get; set; }
/// <summary>
/// 子系统name
/// </summary>
public string SubSystemName { get; set; }
/// <summary> /// <summary>
/// 索引名称 /// 索引名称
/// </summary> /// </summary>
@ -22,6 +27,11 @@ public class WarningRecordIndex : IdBaseIndex
/// </summary> /// </summary>
public string WarningName { get; set; } = null!; public string WarningName { get; set; } = null!;
/// <summary>
/// 客户id
/// </summary>
public int CustomId { get; set; }
/// <summary> /// <summary>
/// 客户简称 /// 客户简称
/// </summary> /// </summary>
@ -47,15 +57,25 @@ public class WarningRecordIndex : IdBaseIndex
/// </summary> /// </summary>
public int Counter { get; set; } public int Counter { get; set; }
/// <summary>
/// 是否最后一次
/// </summary>
public bool IsLast { get; set; }
/// <summary> /// <summary>
/// 预警状态 /// 预警状态
/// </summary> /// </summary>
public WarningStatus WarningStatus { get; set; } public WarningStatus WarningStatus { get; set; }
/// <summary> /// <summary>
/// 通知用户 /// 通知用户name
/// </summary> /// </summary>
public string NotifyUser { get; set; } public string NotifyUserName { get; set; }
/// <summary>
/// 通知用户id
/// </summary>
public int NotifyUserId { get; set; }
/// <summary> /// <summary>
/// 创建时间 /// 创建时间

View File

@ -22,7 +22,7 @@ public interface ITrackDetailsEsRepository : IElasticsearchClientService<TrackDe
Task<List<TrackDetailsIndex>> GetListAsync(int orderId); Task<List<TrackDetailsIndex>> GetListAsync(int orderId);
Task DeleteTrackAsync(int[] orderIds, List<string> trackCodes); Task<List<int>> DeleteTrackAsync(int[] orderIds, List<string> trackCodes);
Task DeleteTrackByIdAsync(string id, string indexName); Task DeleteTrackByIdAsync(string id, string indexName);
} }

View File

@ -22,9 +22,9 @@ public class GetOrderWarningPageListVo : PageInfoInput
public WarningStatus? WarningStatus { get; set; } public WarningStatus? WarningStatus { get; set; }
/// <summary> /// <summary>
/// 客户简称 /// 客户id
/// </summary> /// </summary>
public string? CustomName { get; set; } public int? CustomId { get; set; }
/// <summary> /// <summary>
/// 预警名称 /// 预警名称
@ -32,9 +32,9 @@ public class GetOrderWarningPageListVo : PageInfoInput
public string? WarningName { get; set; } public string? WarningName { get; set; }
/// <summary> /// <summary>
/// 通知用户 /// 通知用户id
/// </summary> /// </summary>
public string? NotifyUser { get; set; } public int? NotifyUserId { get; set; }
/// <summary> /// <summary>
/// 创建时间开始 /// 创建时间开始

View File

@ -4,6 +4,11 @@ namespace SJZY.Track.Domain.Dtos.Forewarning;
public class GetOrderWarningPageOutput public class GetOrderWarningPageOutput
{ {
/// <summary>
/// 子系统name
/// </summary>
public string SubSystemName { get; set; }
/// <summary> /// <summary>
/// 预警名称 /// 预警名称
/// </summary> /// </summary>
@ -24,6 +29,11 @@ public class GetOrderWarningPageOutput
/// </summary> /// </summary>
public int Counter { get; set; } public int Counter { get; set; }
/// <summary>
/// 是否最后一次
/// </summary>
public bool IsLast { get; set; }
/// <summary> /// <summary>
/// 预警状态 /// 预警状态
/// </summary> /// </summary>

View File

@ -7,10 +7,15 @@ namespace SJZY.Track.Domain.Dtos.Forewarning;
public class GetWarningNotifiesVo public class GetWarningNotifiesVo
{ {
/// <summary> /// <summary>
/// 子系统 /// 子系统id
/// </summary> /// </summary>
public int SubSystemId { get; set; } public int SubSystemId { get; set; }
/// <summary>
/// 子系统name
/// </summary>
public string SubSystemName { get; set; }
/// <summary> /// <summary>
/// 规则 id /// 规则 id
/// </summary> /// </summary>
@ -37,7 +42,7 @@ public class GetWarningNotifiesVo
public float WarnTimeSpan { get; set; } public float WarnTimeSpan { get; set; }
/// <summary> /// <summary>
/// 提醒次数 /// 提醒次数(总次数)
/// </summary> /// </summary>
public int WarnCount { get; set; } public int WarnCount { get; set; }
@ -82,21 +87,17 @@ public class GetWarningNotifiesVo
public string? ProductCode { get; set; } public string? ProductCode { get; set; }
/// <summary> /// <summary>
/// 通知方式 /// 通知方式(多个逗号拼接)
/// </summary> /// </summary>
public string NotifyMode { get; set; } public string NotifyMode { get; set; }
public List<NotifyMode> NotifyModes { get; set; }
/// <summary> /// <summary>
/// 通知人 /// 通知用户(json多个)
/// </summary> /// </summary>
public string NotifyUserId { get; set; }
public List<int> NotifyUserIds { get; set; }
public string NotifyUser { get; set; } public string NotifyUser { get; set; }
public List<NotifyUserVo> NotifyUsers { get; set; }
/// <summary> /// <summary>
/// 因素类型排序 /// 因素类型排序
/// </summary> /// </summary>
@ -140,3 +141,16 @@ public class GetWarningNotifiesVo
return res.ToString(); return res.ToString();
} }
} }
public class NotifyUserVo
{
/// <summary>
/// 用户id
/// </summary>
public int UserId { get; set; }
/// <summary>
/// 用户名
/// </summary>
public string UserName { get; set; }
}

View File

@ -1,7 +1,7 @@
using Newtonsoft.Json;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate; using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums;
using SJZY.Track.Domain.Queries; using SJZY.Track.Domain.Queries;
using SJZY.Track.Domain.VEntities; using SJZY.Track.Domain.VEntities;
@ -21,11 +21,13 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
wr.WarningId == wn.WarningId && wr.StartTrackStatusId == wn.StartTrackStatusId && wr.WarningId == wn.WarningId && wr.StartTrackStatusId == wn.StartTrackStatusId &&
wr.EndTrackStatusId == wn.EndTrackStatusId) wr.EndTrackStatusId == wn.EndTrackStatusId)
.LeftJoin<VExternalSubjectEntity>((w, wr, a, wn, cus) => w.CustomerId == cus.Id) .LeftJoin<VExternalSubjectEntity>((w, wr, a, wn, cus) => w.CustomerId == cus.Id)
.LeftJoin<VSystemEntity>((w, wr, a, wn, cus, system) => w.SubSystemId == system.Id)
.Filter(null, true) // 支持历史规则 .Filter(null, true) // 支持历史规则
.Where((w, wr) => ruleIds.Contains(wr.Id)) .Where((w, wr) => ruleIds.Contains(wr.Id))
.Select<GetWarningNotifiesVo>((w, wr, a, wn, cus) => new GetWarningNotifiesVo .Select<GetWarningNotifiesVo>((w, wr, a, wn, cus, system) => new GetWarningNotifiesVo
{ {
SubSystemId = w.SubSystemId, SubSystemId = w.SubSystemId,
SubSystemName = system.CnName,
RuleId = wr.Id, RuleId = wr.Id,
WarningName = w.Name, WarningName = w.Name,
CustomName = cus.Name, CustomName = cus.Name,
@ -42,13 +44,12 @@ public class WarningQueries : ISugarRepository, IWarningQueries,
ProductCode = wr.ProductCode, ProductCode = wr.ProductCode,
NotifyMode = wn.NotifyMode, NotifyMode = wn.NotifyMode,
NotifyUser = wn.NotifyUser, NotifyUser = wn.NotifyUser,
NotifyUserId = wn.NotifyUserId,
FactorTypeSort = w.FactorTypeSort FactorTypeSort = w.FactorTypeSort
}) })
.Mapper(x => .Mapper(rule =>
{ {
x.NotifyModes = x.NotifyMode.Split(',').Select(Enum.Parse<NotifyMode>).ToList(); rule.NotifyUsers = JsonConvert.DeserializeObject<List<NotifyUserVo>>(rule.NotifyUser) ??
x.NotifyUserIds = x.NotifyUserId.Split(',').Select(int.Parse).ToList(); new List<NotifyUserVo>();
}) })
.ToListAsync(); .ToListAsync();
} }

View File

@ -296,7 +296,7 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
return r.ToIdList(); return r.ToIdList();
} }
public async Task DeleteTrackAsync(int[] orderIds, List<string> trackCodes) public async Task<List<int>> DeleteTrackAsync(int[] orderIds, List<string> trackCodes)
{ {
// var deleteResponse = await Context.DeleteByQueryAsync<TrackDetailsIndex>(d => d // var deleteResponse = await Context.DeleteByQueryAsync<TrackDetailsIndex>(d => d
// .Index($"{GlobalConst.TrackDetailsIndex}-*") // 使用通配符匹配所有相关索引 // .Index($"{GlobalConst.TrackDetailsIndex}-*") // 使用通配符匹配所有相关索引
@ -345,6 +345,8 @@ public class TrackDetailsEsRepository : ElasticSearchContextAbstract<TrackDetail
{ {
await DeleteTrackByIdAsync(track.Id, track.IndexName); await DeleteTrackByIdAsync(track.Id, track.IndexName);
} }
return tracks.Select(x => x.OrderId).ToList();
} }
public async Task DeleteTrackByIdAsync(string id, string indexName) public async Task DeleteTrackByIdAsync(string id, string indexName)

View File

@ -78,15 +78,11 @@ public class WarningRecordEsRepository : ElasticSearchContextAbstract<WarningRec
.Terms(input.OrderNos)) .Terms(input.OrderNos))
: null) : null)
&& (input.WarningStatus.HasValue ? q.Term(f => f.WarningStatus, input.WarningStatus) : null) && (input.WarningStatus.HasValue ? q.Term(f => f.WarningStatus, input.WarningStatus) : null)
&& (!input.CustomName.IsNullOrWhiteSpace() && (input.CustomId.HasValue ? q.Term(f => f.CustomId, input.CustomId) : null)
? q.Wildcard(w => w.CustomName, $"*{input.CustomName}*")
: null)
&& (!input.WarningName.IsNullOrWhiteSpace() && (!input.WarningName.IsNullOrWhiteSpace()
? q.Wildcard(w => w.WarningName, $"*{input.WarningName}*") ? q.Wildcard(w => w.WarningName, $"*{input.WarningName}*")
: null) : null)
&& (!input.NotifyUser.IsNullOrWhiteSpace() && (input.NotifyUserId.HasValue ? q.Term(f => f.NotifyUserId, input.NotifyUserId) : null)
? q.Wildcard(w => w.NotifyUser, $"*{input.NotifyUser}*")
: null)
&& (input.StartTime.HasValue && (input.StartTime.HasValue
? q.DateRange(r => r.Field(f => f.CreateTime).GreaterThanOrEquals(input.StartTime)) ? q.DateRange(r => r.Field(f => f.CreateTime).GreaterThanOrEquals(input.StartTime))
: null) : null)
@ -97,6 +93,7 @@ public class WarningRecordEsRepository : ElasticSearchContextAbstract<WarningRec
var data = await Context.SearchAsync<WarningRecordIndex>(x => x var data = await Context.SearchAsync<WarningRecordIndex>(x => x
.Index(GlobalConst.TrackWarningRecordIndex) .Index(GlobalConst.TrackWarningRecordIndex)
.Source() .Source()
.Query(query)
.Sort(s => s.Field(f => f.CreateTime, SortOrder.Descending)) .Sort(s => s.Field(f => f.CreateTime, SortOrder.Descending))
.From((input.PageIndex - 1) * input.PageSize) .From((input.PageIndex - 1) * input.PageSize)
.Size(input.PageSize) .Size(input.PageSize)

View File

@ -87,7 +87,7 @@ public class WarningRepository : BasicRepository<WarningEntity>, IWarningReposit
.UpdateColumns(x => new .UpdateColumns(x => new
{ {
x.NotifyMode, x.NotifyMode,
x.NotifyUserId, x.NotifyUser,
x.UpdateTime, x.UpdateTime,
x.UpdateUserId x.UpdateUserId
}) })