This commit is contained in:
李鹏军 2024-07-24 11:14:58 +08:00
parent 895e12762d
commit c772c68e47
13 changed files with 361 additions and 369 deletions

View File

@ -5,7 +5,7 @@ namespace SJZY.Track.Application.Helpers;
public class ForewarningFactorHelper public class ForewarningFactorHelper
{ {
public static RuleCollectEntity[] GetFactorItem([NotNull]RuleFactorEntity ruleFactors) public static RuleItemEntity[] GetFactorItem([NotNull] RuleFactorEntity ruleFactors)
{ {
var total = Factorial(ruleFactors); var total = Factorial(ruleFactors);
var ruleCollect = AllocateFactor(total, ruleFactors.RuleId); var ruleCollect = AllocateFactor(total, ruleFactors.RuleId);
@ -18,7 +18,8 @@ public class ForewarningFactorHelper
return ruleCollect.ToArray(); return ruleCollect.ToArray();
} }
private static void Assignment<T>(Span<RuleCollectEntity> ruleCollect,int total,IReadOnlyList<T> values,Action<RuleCollectEntity,T> action) private static void Assignment<T>(Span<RuleItemEntity> ruleCollect, int total, IReadOnlyList<T> values,
Action<RuleItemEntity, T> action)
{ {
if (values.Count == 0) if (values.Count == 0)
{ {
@ -37,22 +38,23 @@ public class ForewarningFactorHelper
} }
} }
private static Span<RuleCollectEntity> AllocateFactor(int total,int ruleId) private static Span<RuleItemEntity> AllocateFactor(int total, int ruleId)
{ {
Span<RuleItemEntity> factors = new RuleItemEntity[total];
Span<RuleCollectEntity> factors = new RuleCollectEntity[total];
for (int index = 0; index < total; index++) for (int index = 0; index < total; index++)
{ {
factors[index] = new RuleCollectEntity() factors[index] = new RuleItemEntity()
{ {
RuleId = ruleId RuleId = ruleId
}; };
} }
return factors; return factors;
} }
internal static int Factorial(RuleFactorEntity ruleFactors) internal static int Factorial(RuleFactorEntity ruleFactors)
{ {
return ruleFactors.CargoTypes.Count*ruleFactors.Months.Count*ruleFactors.Areas.Count*ruleFactors.IsTransit.Count*ruleFactors.DeparturePorts.Count*ruleFactors.ProductCodes.Count; return ruleFactors.CargoTypes.Count * ruleFactors.Months.Count * ruleFactors.Areas.Count *
ruleFactors.IsTransit.Count * ruleFactors.DeparturePorts.Count * ruleFactors.ProductCodes.Count;
} }
} }

View File

@ -1,18 +1,16 @@
using FreeRedis; using FreeRedis;
using NetTaste;
using SJZY.Expand.ABP.Core; using SJZY.Expand.ABP.Core;
using SJZY.Track.Application.Contract.Services; using SJZY.Track.Application.Contract.Services;
using SJZY.Track.Domain.Aggregates.ForewarningAggregate; using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
using SJZY.Track.Domain.Consts; using SJZY.Track.Domain.Consts;
using SJZY.Track.Domain.Dtos.Forewarning; using SJZY.Track.Domain.Dtos.Forewarning;
using SJZY.Track.Domain.Enums; using SJZY.Track.Domain.Enums;
using SqlSugar;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
namespace SJZY.Track.Application.Services.ForewarningServices; namespace SJZY.Track.Application.Services.ForewarningServices;
/// <summary> /// <summary>
/// 单例服务,用于处理预警通知 /// 用于处理预警通知
/// </summary> /// </summary>
public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency
{ {
@ -67,7 +65,8 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
public void SendNotification(int intervalMinute) public void SendNotification(int intervalMinute)
{ {
var currentTimestamp = GetTimestamp(DateTime.Now); var currentTimestamp = GetTimestamp(DateTime.Now);
var notifyMembers = RedisHelper.Client.ZRangeByScore(GlobalConst.ForewarningNotifyKeyPrefix, 0, currentTimestamp); var notifyMembers =
RedisHelper.Client.ZRangeByScore(GlobalConst.ForewarningNotifyKeyPrefix, 0, currentTimestamp);
if (notifyMembers == null || notifyMembers.Length == 0) if (notifyMembers == null || notifyMembers.Length == 0)
return; return;
@ -182,6 +181,7 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
private async Task Init() private async Task Init()
{ {
// todo:缓存设计有问题 重构 120s 10w 30w 3000k/s
var allFactorCollect = await _ruleFactorCache.GetAllFactorCollect(); var allFactorCollect = await _ruleFactorCache.GetAllFactorCollect();
var factors = await _ruleFactorCache.GetAllRuleFactor(); var factors = await _ruleFactorCache.GetAllRuleFactor();
var factorsMap = factors.GroupBy(val => val.RuleId) var factorsMap = factors.GroupBy(val => val.RuleId)

View File

@ -1,9 +1,6 @@
using System.Diagnostics.CodeAnalysis;
using AutoMapper;
using SJZY.Track.Application.Helpers; using SJZY.Track.Application.Helpers;
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 SqlSugar;
namespace SJZY.Track.Application.Services.ForewarningServices; namespace SJZY.Track.Application.Services.ForewarningServices;
@ -13,15 +10,15 @@ public class ForewarningService: ApplicationService
{ {
readonly IRuleRepository _ruleRepository; readonly IRuleRepository _ruleRepository;
IRuleFactorRepository _ruleFactorRepository; IRuleFactorRepository _ruleFactorRepository;
private IRuleCollectRepository _ruleCollectRepository; private IRuleItemRepository _ruleItemRepository;
public ForewarningService(IRuleRepository ruleRepository public ForewarningService(IRuleRepository ruleRepository
, IRuleFactorRepository ruleFactorRepository , IRuleFactorRepository ruleFactorRepository
, IRuleCollectRepository ruleCollectRepository) , IRuleItemRepository ruleItemRepository)
{ {
_ruleRepository = ruleRepository; _ruleRepository = ruleRepository;
_ruleFactorRepository = ruleFactorRepository; _ruleFactorRepository = ruleFactorRepository;
_ruleCollectRepository = ruleCollectRepository; _ruleItemRepository = ruleItemRepository;
} }
/// <summary> /// <summary>
@ -33,7 +30,7 @@ public class ForewarningService: ApplicationService
public async ValueTask<UnifyResultDto> ModifyForewarning(CreateRuleFactorRequest input) public async ValueTask<UnifyResultDto> ModifyForewarning(CreateRuleFactorRequest input)
{ {
var factors = ObjectMapper.Map<CreateRuleFactorRequest, RuleFactorEntity>(input); var factors = ObjectMapper.Map<CreateRuleFactorRequest, RuleFactorEntity>(input);
var ruleCollects = ForewarningFactorHelper.GetFactorItem(factors); var ruleItems = ForewarningFactorHelper.GetFactorItem(factors);
//todo 原子性没有保证,后续可能需要调整 //todo 原子性没有保证,后续可能需要调整
if (input.RuleId > 0) if (input.RuleId > 0)
@ -51,13 +48,14 @@ public class ForewarningService: ApplicationService
ruleTemplate.CustomId = input.CustomId; ruleTemplate.CustomId = input.CustomId;
await _ruleFactorRepository.IndexDocumentAsync(factors); await _ruleFactorRepository.IndexDocumentAsync(factors);
await _ruleRepository.UpdateForewarning(ruleTemplate, ruleCollects); await _ruleRepository.UpdateForewarning(ruleTemplate, ruleItems);
return new UnifyResultDto(true, "保存成功"); return new UnifyResultDto(true, "保存成功");
} }
var newRuleTemplate = ObjectMapper.Map<CreateRuleFactorRequest, RuleEntity>(input); var newRuleTemplate = ObjectMapper.Map<CreateRuleFactorRequest, RuleEntity>(input);
var ruleTemplateId = await _ruleRepository.CreateForewarning(newRuleTemplate, ruleCollects); var ruleId = await _ruleRepository.CreateForewarning(newRuleTemplate, ruleItems);
factors.Id = ruleTemplateId.ToString(); factors.Id = ruleId.ToString();
await _ruleFactorRepository.IndexDocumentAsync(factors);
return new UnifyResultDto(true, "保存成功"); return new UnifyResultDto(true, "保存成功");
} }
@ -68,7 +66,8 @@ public class ForewarningService: ApplicationService
public async ValueTask<UnifyResultDto> ModifyTimeliness(ModifyTimelinessRequest input) public async ValueTask<UnifyResultDto> ModifyTimeliness(ModifyTimelinessRequest input)
{ {
var ruleIds = input.Items.Select(val => val.Id).ToList(); var ruleIds = input.Items.Select(val => val.Id).ToList();
var ruleCollect = await _ruleCollectRepository.GetListAsync(val => ruleIds.Contains(val.Id) && val.RuleId == input.RuleId); var ruleCollect =
await _ruleItemRepository.GetListAsync(val => ruleIds.Contains(val.Id) && val.RuleId == input.RuleId);
if (ruleCollect == null || ruleCollect.Count == 0) if (ruleCollect == null || ruleCollect.Count == 0)
throw new BusinessException(message: "规则不存在"); throw new BusinessException(message: "规则不存在");
@ -87,7 +86,7 @@ public class ForewarningService: ApplicationService
rule.Count = item.Count; rule.Count = item.Count;
} }
await _ruleCollectRepository.UpdateRangeAsync(ruleCollect,val=>val.RuleId==input.RuleId); await _ruleItemRepository.UpdateRangeAsync(ruleCollect, val => val.RuleId == input.RuleId);
if (notModifyList.Count > 0) if (notModifyList.Count > 0)
return new UnifyResultDto(true, $"更新成功,规则{string.Join(",", notModifyList)}不存在"); return new UnifyResultDto(true, $"更新成功,规则{string.Join(",", notModifyList)}不存在");
@ -96,24 +95,23 @@ public class ForewarningService: ApplicationService
} }
/// <summary> /// <summary>
/// 查询预警模板列表 /// 查询预警规则列表
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
[HttpPost("QueryForewarning")] [HttpPost("QueryForewarning")]
public async Task<UnifyResultDto> QueryForewarning(QueryForewarningRequest input) public async Task<UnifyResultDto> QueryForewarning(QueryForewarningRequest input)
{ {
var result = await _ruleRepository.QueryForewarning(input); var result = await _ruleRepository.QueryForewarningRuleAsync(input);
return new UnifyResultDto(true, result); return new UnifyResultDto(true, result);
} }
/// <summary> /// <summary>
/// 查询预警规则列表 /// 查询预警规则明细列表
/// </summary> /// </summary>
[HttpPost("QueryForewarningRules")] [HttpPost("QueryForewarningRules")]
public async Task<UnifyResultDto> QueryForewarningRules(QueryForewarningRuleRequest input) public async Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRuleItems(QueryForewarningRuleRequest input)
{ {
var result = await _ruleCollectRepository.QueryForewarningRule(input); return await _ruleItemRepository.QueryForewarningRuleItemsAsync(input);
return new UnifyResultDto(true, result);
} }
/// <summary> /// <summary>
@ -122,7 +120,5 @@ public class ForewarningService: ApplicationService
[HttpPost("SendForewarningNotification")] [HttpPost("SendForewarningNotification")]
public void SendForewarningNotification() public void SendForewarningNotification()
{ {
} }
} }

View File

@ -1,7 +1,5 @@
using AutoMapper;
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 SqlSugar;
namespace SJZY.Track.Application.Services.ForewarningServices; namespace SJZY.Track.Application.Services.ForewarningServices;
@ -9,7 +7,7 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
[Route("/ForewarningService")] [Route("/ForewarningService")]
public class KpiAreaService : ApplicationService public class KpiAreaService : ApplicationService
{ {
readonly IKpiAreaRepository _ruleAreaRepository; private readonly IKpiAreaRepository _ruleAreaRepository;
public KpiAreaService(IKpiAreaRepository ruleAreaRepository) public KpiAreaService(IKpiAreaRepository ruleAreaRepository)
{ {
@ -98,7 +96,7 @@ public class KpiAreaService : ApplicationService
return new UnifyResultDto(false, "id不能为空"); return new UnifyResultDto(false, "id不能为空");
//todo 测试不存在id的情况 //todo 测试不存在id的情况
RuleAreaInfoEntity areaInfo = await _ruleAreaRepository.GetAreaInfoById(input.Id); var areaInfo = await _ruleAreaRepository.GetAreaInfoById(input.Id);
if (areaInfo == null) if (areaInfo == null)
return new UnifyResultDto(false, "未找到该区域信息"); return new UnifyResultDto(false, "未找到该区域信息");

View File

@ -12,14 +12,14 @@ public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
private const string GlobalFactorLockKey = "RuleFactorCacheService_GlobalLock"; private const string GlobalFactorLockKey = "RuleFactorCacheService_GlobalLock";
private const string GlobalRuleLockKey = "RuleFactorCacheService_GlobalLock"; private const string GlobalRuleLockKey = "RuleFactorCacheService_GlobalLock";
readonly IRuleFactorRepository _ruleFactorRepository; readonly IRuleFactorRepository _ruleFactorRepository;
readonly IRuleCollectRepository _ruleCollectRepository; readonly IRuleItemRepository _ruleItemRepository;
readonly IRuleRepository _ruleRepository; readonly IRuleRepository _ruleRepository;
public RuleFactorCacheService(IRuleFactorRepository ruleFactorRepository, public RuleFactorCacheService(IRuleFactorRepository ruleFactorRepository,
IRuleCollectRepository ruleCollectRepository, IRuleRepository ruleRepository) IRuleItemRepository ruleItemRepository, IRuleRepository ruleRepository)
{ {
_ruleFactorRepository = ruleFactorRepository; _ruleFactorRepository = ruleFactorRepository;
_ruleCollectRepository = ruleCollectRepository; _ruleItemRepository = ruleItemRepository;
_ruleRepository = ruleRepository; _ruleRepository = ruleRepository;
} }
@ -40,7 +40,6 @@ public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
[NonAction] [NonAction]
public async Task<ForewarningRule[]> GetAllFactorCollect() public async Task<ForewarningRule[]> GetAllFactorCollect()
{ {
var key = GetRuleKey(); var key = GetRuleKey();
var result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key); var result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
if (result == null) if (result == null)
@ -50,7 +49,7 @@ public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key); result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
if (result != null) return result; if (result != null) return result;
var ruleCollect = await _ruleCollectRepository.GetListAsync(val => true); var ruleCollect = await _ruleItemRepository.GetListAsync(val => true);
if (ruleCollect == null || ruleCollect.Count == 0) if (ruleCollect == null || ruleCollect.Count == 0)
{ {
ForewarningRule[] rules = new ForewarningRule[0]; ForewarningRule[] rules = new ForewarningRule[0];
@ -127,7 +126,7 @@ public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
return result; return result;
} }
private ForewarningRule[] RuleEntityToRule(RuleCollectEntity entity) private ForewarningRule[] RuleEntityToRule(RuleItemEntity entity)
{ {
var result = RuleCollectToRule(entity); var result = RuleCollectToRule(entity);
if (string.IsNullOrEmpty(entity.Month)) if (string.IsNullOrEmpty(entity.Month))
@ -151,7 +150,7 @@ public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
return rules.ToArray(); return rules.ToArray();
} }
private ForewarningRule RuleCollectToRule(RuleCollectEntity entity) private ForewarningRule RuleCollectToRule(RuleItemEntity entity)
{ {
return new ForewarningRule return new ForewarningRule
{ {

View File

@ -2,12 +2,12 @@ using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public interface IRuleCollectRepository:IBasicRepository<RuleCollectEntity> public interface IRuleItemRepository : IBasicRepository<RuleItemEntity>
{ {
/// <summary> /// <summary>
/// 查询分页 /// 查询分页
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRule(QueryForewarningRuleRequest input); Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRuleItemsAsync(QueryForewarningRuleRequest input);
} }

View File

@ -4,9 +4,9 @@ namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
public interface IRuleRepository : IBasicRepository<RuleEntity> public interface IRuleRepository : IBasicRepository<RuleEntity>
{ {
Task<int> CreateForewarning(RuleEntity rule, RuleCollectEntity[] factorList); Task<int> CreateForewarning(RuleEntity rule, RuleItemEntity[] ruleItems);
Task UpdateForewarning(RuleEntity rule, RuleCollectEntity[] factorList); Task UpdateForewarning(RuleEntity rule, RuleItemEntity[] factorList);
Task<UnifyPageResultDto<RuleEntity>> QueryForewarning(QueryForewarningRequest input); Task<UnifyPageResultDto<RuleEntity>> QueryForewarningRuleAsync(QueryForewarningRequest input);
} }

View File

@ -1,7 +1,7 @@
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate; namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
[SugarTable("t_rule_collect")] [SugarTable("t_rule_item")]
public class RuleCollectEntity : IAggregateRoot,ICloneable public class RuleItemEntity : IAggregateRoot, ICloneable
{ {
/// <summary> /// <summary>
/// 自增主键 /// 自增主键
@ -9,8 +9,7 @@ public class RuleCollectEntity : IAggregateRoot,ICloneable
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)] [SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
public int Id { get; set; } public int Id { get; set; }
[SugarColumn(ColumnName = "RuleId")] [SugarColumn(ColumnName = "RuleId")] public int RuleId { get; set; }
public int RuleId { get; set; }
/// <summary> /// <summary>
/// 提醒的时间(小时) /// 提醒的时间(小时)

View File

@ -58,7 +58,7 @@ public interface IKpiAreaRepository:IBasicRepository<RuleAreaEntity>
/// </summary> /// </summary>
/// <param name="id"></param> /// <param name="id"></param>
/// <returns></returns> /// <returns></returns>
Task<RuleAreaInfoEntity> GetAreaInfoById(int id); Task<RuleAreaInfoEntity?> GetAreaInfoById(int id);
/// <summary> /// <summary>
/// 获取所有区域信息 /// 获取所有区域信息

View File

@ -1,5 +1,4 @@
using SJZY.Track.Domain; using SJZY.Track.Domain;
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;
@ -87,9 +86,9 @@ public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaReposito
.ToPagedListAsync(query.PageIndex, query.PageSize); .ToPagedListAsync(query.PageIndex, query.PageSize);
} }
public Task<RuleAreaInfoEntity> GetAreaInfoById(int id) public Task<RuleAreaInfoEntity?> GetAreaInfoById(int id)
{ {
return Context.Queryable<RuleAreaInfoEntity>().FirstAsync(val => val.Id == id); return Context.Queryable<RuleAreaInfoEntity>().FirstAsync(val => val.Id == id)!;
} }
/// <summary> /// <summary>

View File

@ -3,16 +3,16 @@ using SJZY.Track.Domain.Dtos.Forewarning;
namespace SJZY.Track.Repository.Repositories; namespace SJZY.Track.Repository.Repositories;
public class RuleCollectRepository: BasicRepository<RuleCollectEntity>, IRuleCollectRepository,ITransientDependency public class RuleItemRepository : BasicRepository<RuleItemEntity>, IRuleItemRepository, ITransientDependency
{ {
/// <summary> /// <summary>
/// 查询预警规则分页信息 /// 查询预警规则分页信息
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
public Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRule(QueryForewarningRuleRequest input) public Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRuleItemsAsync(QueryForewarningRuleRequest input)
{ {
var query = Context.Queryable<RuleCollectEntity>() var query = Context.Queryable<RuleItemEntity>()
.Where(val => val.RuleId == input.RuleId); .Where(val => val.RuleId == input.RuleId);
if (!string.IsNullOrEmpty(input.SortField)) if (!string.IsNullOrEmpty(input.SortField))
@ -24,7 +24,7 @@ public class RuleCollectRepository: BasicRepository<RuleCollectEntity>, IRuleCol
.ToPagedListAsync(input.PageIndex, input.PageSize); .ToPagedListAsync(input.PageIndex, input.PageSize);
} }
private RuleCollectDto MapToDto(RuleCollectEntity entity) private RuleCollectDto MapToDto(RuleItemEntity entity)
{ {
return new RuleCollectDto() return new RuleCollectDto()
{ {

View File

@ -6,25 +6,26 @@ namespace SJZY.Track.Repository.Repositories;
public class RuleRepository : BasicRepository<RuleEntity>, IRuleRepository, ITransientDependency public class RuleRepository : BasicRepository<RuleEntity>, IRuleRepository, ITransientDependency
{ {
public async Task<int> CreateForewarning(RuleEntity rule, RuleCollectEntity[] factorList) public async Task<int> CreateForewarning(RuleEntity rule, RuleItemEntity[] ruleItems)
{ {
using var tran = TransactionHelper.GetReadCommitted(); using var tran = TransactionHelper.GetReadCommitted();
var ruleId = await InsertReturnIdentityAsync(rule); var ruleId = await InsertReturnIdentityAsync(rule);
foreach (var item in factorList) foreach (var item in ruleItems)
{ {
item.RuleId = ruleId; item.RuleId = ruleId;
} }
await Context.Insertable(factorList).ExecuteCommandAsync();
await Context.Insertable(ruleItems).ExecuteCommandAsync();
tran.Complete(); tran.Complete();
return ruleId; return ruleId;
} }
public async Task UpdateForewarning(RuleEntity rule,RuleCollectEntity[] factorList) public async Task UpdateForewarning(RuleEntity rule, RuleItemEntity[] factorList)
{ {
using var tran = TransactionHelper.GetReadCommitted(); using var tran = TransactionHelper.GetReadCommitted();
await UpdateAsync(rule); await UpdateAsync(rule);
await Context.Deleteable<RuleCollectEntity>().Where(x=>x.RuleId==rule.Id).ExecuteCommandAsync(); await Context.Deleteable<RuleItemEntity>().Where(x => x.RuleId == rule.Id).ExecuteCommandAsync();
await Context.Insertable(factorList).ExecuteCommandAsync(); await Context.Insertable(factorList).ExecuteCommandAsync();
tran.Complete(); tran.Complete();
} }
@ -34,11 +35,12 @@ public class RuleRepository:BasicRepository<RuleEntity> ,IRuleRepository,ITransi
/// </summary> /// </summary>
/// <param name="input"></param> /// <param name="input"></param>
/// <returns></returns> /// <returns></returns>
public Task<UnifyPageResultDto<RuleEntity>> QueryForewarning(QueryForewarningRequest input) public Task<UnifyPageResultDto<RuleEntity>> QueryForewarningRuleAsync(QueryForewarningRequest input)
{ {
var query = Context.Queryable<RuleEntity>() var query = Context.Queryable<RuleEntity>()
.WhereIF(input.SystemId.HasValue, val => val.SubSystemId == input.SystemId) .WhereIF(input.SystemId.HasValue, val => val.SubSystemId == input.SystemId)
.WhereIF(string.IsNullOrEmpty(input.KeyWord), val=> val.CustomName.Contains(input.KeyWord)||val.Name.Contains(input.KeyWord)); .WhereIF(!string.IsNullOrEmpty(input.KeyWord),
val => val.CustomName.Contains(input.KeyWord!) || val.Name.Contains(input.KeyWord!));
if (!string.IsNullOrEmpty(input.SortField)) if (!string.IsNullOrEmpty(input.SortField))
{ {
@ -47,7 +49,4 @@ public class RuleRepository:BasicRepository<RuleEntity> ,IRuleRepository,ITransi
return query.ToPagedListAsync(input.PageIndex, input.PageSize); return query.ToPagedListAsync(input.PageIndex, input.PageSize);
} }
} }