112 lines
4.5 KiB
C#
112 lines
4.5 KiB
C#
using Newtonsoft.Json;
|
|
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
|
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Dtos.Common;
|
|
using SJZY.Track.Domain.Dtos.Forewarning;
|
|
using SJZY.Track.Domain.Queries;
|
|
using SJZY.Track.Domain.VEntities;
|
|
|
|
namespace SJZY.Track.Repository.Queries;
|
|
|
|
public class WarningQueries : ISugarRepository, IWarningQueries,
|
|
ITransientDependency
|
|
{
|
|
public ISqlSugarClient Context { get; set; } = SqlsugarScopeBasic.GetContextSafely("default");
|
|
|
|
public async Task<List<GetWarningNotifiesVo>> GetWarningNotifyRulesAsync(List<int> ruleIds)
|
|
{
|
|
return await Context.Queryable<WarningEntity>()
|
|
.LeftJoin<WarningRuleEntity>((w, wr) => w.Id == wr.WarningId)
|
|
.LeftJoin<RuleAreaEntity>((w, wr, a) => wr.AreaId == a.Id)
|
|
.LeftJoin<WarningNotifyEntity>((w, wr, a, wn) =>
|
|
wr.WarningId == wn.WarningId && wr.StartTrackStatusId == wn.StartTrackStatusId &&
|
|
wr.EndTrackStatusId == wn.EndTrackStatusId)
|
|
.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) // 支持历史规则
|
|
.Where((w, wr) => ruleIds.Contains(wr.Id))
|
|
.Select<GetWarningNotifiesVo>((w, wr, a, wn, cus, system) => new GetWarningNotifiesVo
|
|
{
|
|
SubSystemId = w.SubSystemId,
|
|
SubSystemName = system.CnName,
|
|
RuleId = wr.Id,
|
|
WarningName = w.Name,
|
|
CustomId = w.CustomerId,
|
|
CustomName = cus.Name,
|
|
TotalTimeSpan = wr.TotalTimeSpan,
|
|
WarnTimeSpan = wr.WarnTimeSpan,
|
|
WarnCount = wr.WarnCount,
|
|
StartTrackStatus = wr.StartTrackStatus,
|
|
EndTrackStatus = wr.EndTrackStatus,
|
|
CargoType = wr.CargoType,
|
|
Months = wr.Months,
|
|
AreaName = a.Name,
|
|
IsTransit = wr.IsTransit,
|
|
LeavePort = wr.LeavePort,
|
|
ProductCode = wr.ProductCode,
|
|
NotifyMode = wn.NotifyMode,
|
|
NotifyUser = wn.NotifyUser,
|
|
FactorTypeSort = w.FactorTypeSort
|
|
})
|
|
.Mapper(rule =>
|
|
{
|
|
rule.NotifyUsers = JsonConvert.DeserializeObject<List<NotifyUserVo>>(rule.NotifyUser) ??
|
|
new List<NotifyUserVo>();
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public Task<List<WarningRuleCacheDto>?> GetWarningRule(int systemId, int customerId)
|
|
{
|
|
return Context.Queryable<WarningRuleEntity>()
|
|
.InnerJoin<WarningEntity>((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<List<RuleAreaBaseInfoVo>> GetWarningRuleByAreaId(int areaId)
|
|
{
|
|
return Context.Queryable<WarningRuleEntity>()
|
|
.InnerJoin<WarningEntity>((a, b) => a.WarningId == b.Id)
|
|
.Where((a, b) => b.IsEnable && a.AreaId == areaId)
|
|
.Select((a, b) => new RuleAreaBaseInfoVo
|
|
{
|
|
CustomerId = b.CustomerId,
|
|
SystemId = b.SubSystemId
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task<List<IdWithNameDto>> GetOrderNoByIdsAsync(int[] orderIds)
|
|
{
|
|
return await Context.Queryable<OrderEntity>()
|
|
.Where(x => orderIds.Contains(x.Id))
|
|
.Select(x => new IdWithNameDto
|
|
{
|
|
Id = x.Id,
|
|
Name = x.OrderNo
|
|
})
|
|
.Filter(null, true)
|
|
.ToListAsync();
|
|
}
|
|
}
|