123 lines
4.4 KiB
C#
123 lines
4.4 KiB
C#
using SJZY.Track.Domain;
|
|
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
|
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackStatusAggregate;
|
|
using SJZY.Track.Domain.Dtos.Forewarning;
|
|
using SJZY.Track.Domain.VEntities;
|
|
|
|
namespace SJZY.Track.Repository.Repositories;
|
|
|
|
public class WarningRepository : BasicRepository<WarningEntity>, IWarningRepository, ITransientDependency
|
|
{
|
|
public async Task<int> CreateForewarningAsync(WarningEntity warning)
|
|
{
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
var ruleId = await InsertReturnIdentityAsync(warning);
|
|
warning.WarningFactors.ForEach(x => x.WarningId = ruleId);
|
|
await Context.Insertable(warning.WarningFactors).ExecuteCommandAsync();
|
|
|
|
warning.WarningRules.ForEach(x => x.WarningId = ruleId);
|
|
await Context.Insertable(warning.WarningRules).ExecuteCommandAsync();
|
|
|
|
tran.Complete();
|
|
return ruleId;
|
|
}
|
|
|
|
public Task CopyForewarning(int warningId)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public Task<UnifyPageResultDto<WarningPageOutput>> GetWarningPageListAsync(GetWarningPageInputVo input)
|
|
{
|
|
var query = Context.Queryable<WarningEntity>()
|
|
.LeftJoin<VSystemEntity>((a, b) => a.SubSystemId == b.Id)
|
|
.LeftJoin<VExternalSubjectEntity>((a, b, c) => a.CustomerId == c.Id)
|
|
.WhereIF(input.SystemId.HasValue, (a, b) => a.SubSystemId == input.SystemId)
|
|
.WhereIF(!string.IsNullOrEmpty(input.KeyWord),
|
|
(a, b, c) => a.Name.Contains(input.KeyWord!) || c.Name.Contains(input.KeyWord!))
|
|
.OrderBy(a => a.UpdateTime, OrderByType.Desc);
|
|
|
|
return query
|
|
.Select((a, b, c) => new WarningPageOutput
|
|
{
|
|
Id = a.Id,
|
|
SubSystem = b.CnName,
|
|
Custom = c.Name,
|
|
Name = a.Name,
|
|
UpdateTime = a.UpdateTime
|
|
})
|
|
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
|
}
|
|
|
|
public async Task<List<WarningRuleVo>> GetWarningRuleListAsync(int warningId)
|
|
{
|
|
return await Context.Queryable<WarningRuleEntity>()
|
|
.LeftJoin<TrackStatusEntity>((a, b) => a.StartTrackStatusId == b.Id)
|
|
.LeftJoin<TrackStatusEntity>((a, b, c) => a.EndTrackStatusId == c.Id)
|
|
.LeftJoin<RuleAreaEntity>((a, b, c, d) => a.AreaId == d.Id)
|
|
.Where(a => a.WarningId == warningId)
|
|
.Select((a, b, c, d) => new WarningRuleVo
|
|
{
|
|
StartTrackStatus = b.Status,
|
|
EndTrackStatus = c.Status,
|
|
Area = d.Name
|
|
}, true)
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task UpdateForewarningAsync(WarningEntity warning)
|
|
{
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
await Context.Updateable(warning).ExecuteCommandAsync();
|
|
|
|
await Context.Updateable(warning.WarningRules).WhereColumns(x => new
|
|
{
|
|
x.WarningId,
|
|
x.StartTrackStatusId,
|
|
x.EndTrackStatusId
|
|
}).UpdateColumns(x => new
|
|
{
|
|
x.NotifyMode,
|
|
x.NotifyUserId,
|
|
x.UpdateTime,
|
|
x.UpdateUserId,
|
|
}, true)
|
|
.ExecuteCommandAsync();
|
|
|
|
tran.Complete();
|
|
}
|
|
|
|
public async Task<int> ModifyTimeSpansAsync(List<WarningRuleEntity> rules)
|
|
{
|
|
return await Context.Updateable(rules)
|
|
.UpdateColumns(x => new { x.TotalTimeSpan, x.WarnTimeSpan, x.WarnCount, x.UpdateTime, x.UpdateUserId })
|
|
.ExecuteCommandAsync();
|
|
}
|
|
|
|
public async Task<bool> TurnWarningAsync(WarningEntity warning)
|
|
{
|
|
return await Context.Updateable(warning)
|
|
.UpdateColumns(x => new { x.IsEnable, x.UpdateTime, x.UpdateUserId })
|
|
.ExecuteCommandAsync() > 0;
|
|
}
|
|
|
|
public async Task<WarningEntity?> GetWithRulesAsync(int warningId)
|
|
{
|
|
var warning = await GetFirstAsync(x => x.Id == warningId);
|
|
|
|
if (warning == null) return null;
|
|
|
|
warning.WarningFactors = await Context.Queryable<WarningFactorEntity>()
|
|
.Where(x => x.WarningId == warningId)
|
|
.ToListAsync();
|
|
|
|
warning.WarningRules = await Context.Queryable<WarningRuleEntity>()
|
|
.Where(x => x.WarningId == warningId)
|
|
.ToListAsync();
|
|
|
|
return warning;
|
|
}
|
|
} |