review
This commit is contained in:
parent
895e12762d
commit
c772c68e47
@ -5,20 +5,21 @@ namespace SJZY.Track.Application.Helpers;
|
||||
|
||||
public class ForewarningFactorHelper
|
||||
{
|
||||
public static RuleCollectEntity[] GetFactorItem([NotNull]RuleFactorEntity ruleFactors)
|
||||
public static RuleItemEntity[] GetFactorItem([NotNull] RuleFactorEntity ruleFactors)
|
||||
{
|
||||
var total = Factorial(ruleFactors);
|
||||
var ruleCollect = AllocateFactor(total,ruleFactors.RuleId);
|
||||
Assignment(ruleCollect,total,ruleFactors.CargoTypes,(item,value)=>item.CargoType=value);
|
||||
Assignment(ruleCollect,total,ruleFactors.Months,(item,value)=>item.Month=value);
|
||||
Assignment(ruleCollect,total,ruleFactors.Areas,(item,value)=>item.Area=value);
|
||||
Assignment(ruleCollect,total,ruleFactors.IsTransit,(item,value)=>item.IsTransit=value);
|
||||
Assignment(ruleCollect,total,ruleFactors.DeparturePorts,(item,value)=>item.DeparturePort=value);
|
||||
Assignment(ruleCollect,total,ruleFactors.ProductCodes,(item,value)=>item.ProductCode=value);
|
||||
var ruleCollect = AllocateFactor(total, ruleFactors.RuleId);
|
||||
Assignment(ruleCollect, total, ruleFactors.CargoTypes, (item, value) => item.CargoType = value);
|
||||
Assignment(ruleCollect, total, ruleFactors.Months, (item, value) => item.Month = value);
|
||||
Assignment(ruleCollect, total, ruleFactors.Areas, (item, value) => item.Area = value);
|
||||
Assignment(ruleCollect, total, ruleFactors.IsTransit, (item, value) => item.IsTransit = value);
|
||||
Assignment(ruleCollect, total, ruleFactors.DeparturePorts, (item, value) => item.DeparturePort = value);
|
||||
Assignment(ruleCollect, total, ruleFactors.ProductCodes, (item, value) => item.ProductCode = value);
|
||||
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)
|
||||
{
|
||||
@ -26,33 +27,34 @@ public class ForewarningFactorHelper
|
||||
}
|
||||
|
||||
var segment = total / values.Count;
|
||||
for(int index=0;index<values.Count;index++)
|
||||
for (int index = 0; index < values.Count; index++)
|
||||
{
|
||||
var start = index * segment;
|
||||
var assignmentSlice = ruleCollect.Slice(start, segment);
|
||||
foreach (var item in assignmentSlice)
|
||||
{
|
||||
action(item,values[index]);
|
||||
action(item, values[index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Span<RuleCollectEntity> AllocateFactor(int total,int ruleId)
|
||||
private static Span<RuleItemEntity> AllocateFactor(int total, int ruleId)
|
||||
{
|
||||
|
||||
Span<RuleCollectEntity> factors = new RuleCollectEntity[total];
|
||||
Span<RuleItemEntity> factors = new RuleItemEntity[total];
|
||||
for (int index = 0; index < total; index++)
|
||||
{
|
||||
factors[index] = new RuleCollectEntity()
|
||||
factors[index] = new RuleItemEntity()
|
||||
{
|
||||
RuleId = ruleId
|
||||
};
|
||||
}
|
||||
|
||||
return factors;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -1,24 +1,22 @@
|
||||
using FreeRedis;
|
||||
using NetTaste;
|
||||
using SJZY.Expand.ABP.Core;
|
||||
using SJZY.Track.Application.Contract.Services;
|
||||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
using SJZY.Track.Domain.Consts;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
using SJZY.Track.Domain.Enums;
|
||||
using SqlSugar;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
|
||||
/// <summary>
|
||||
/// 单例服务,用于处理预警通知
|
||||
/// 用于处理预警通知
|
||||
/// </summary>
|
||||
public class ForewarningNotifyService:IForewarningNotifyService,ITransientDependency
|
||||
public class ForewarningNotifyService : IForewarningNotifyService, ITransientDependency
|
||||
{
|
||||
private IRuleFactorCacheService _ruleFactorCache;
|
||||
IReadOnlyDictionary<string,List<ForewarningRule>> _ruleGroupDict;
|
||||
IReadOnlyDictionary<string,List<RuleFactor>> _factorDict;
|
||||
IReadOnlyDictionary<string, List<ForewarningRule>> _ruleGroupDict;
|
||||
IReadOnlyDictionary<string, List<RuleFactor>> _factorDict;
|
||||
private IReadOnlyDictionary<int, ForewarningRule> _rules;
|
||||
readonly INotifyService _notifyService;
|
||||
|
||||
@ -39,7 +37,7 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
if (rules == null || rules.Count == 0)
|
||||
return 0;
|
||||
|
||||
return await ExecuteRule(rules,order.Id);
|
||||
return await ExecuteRule(rules, order.Id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -56,7 +54,7 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
var willDeleteMembers = new List<string>();
|
||||
foreach (var rule in rules)
|
||||
{
|
||||
var allRuleNotities= DeleteNotifyValue(rule, order.Id);
|
||||
var allRuleNotities = DeleteNotifyValue(rule, order.Id);
|
||||
willDeleteMembers.AddRange(allRuleNotities);
|
||||
}
|
||||
|
||||
@ -67,14 +65,15 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
public void SendNotification(int intervalMinute)
|
||||
{
|
||||
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)
|
||||
return;
|
||||
|
||||
var notifyValues = notifyMembers.Select(val => new RuleNotifyValue(val));
|
||||
foreach (var notifyValue in notifyValues)
|
||||
{
|
||||
if(!_rules.TryGetValue(notifyValue.RuleId, out var rule))
|
||||
if (!_rules.TryGetValue(notifyValue.RuleId, out var rule))
|
||||
continue;
|
||||
|
||||
//todo 发送通知
|
||||
@ -89,10 +88,10 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
_rules = null;
|
||||
}
|
||||
|
||||
private List<string> DeleteNotifyValue(ForewarningRule rule,int orderId)
|
||||
private List<string> DeleteNotifyValue(ForewarningRule rule, int orderId)
|
||||
{
|
||||
var members = new List<string>();
|
||||
for(var index=0;index<rule.Count;index++)
|
||||
for (var index = 0; index < rule.Count; index++)
|
||||
{
|
||||
var notifyValue = NotifyValue(rule, orderId, index);
|
||||
members.Add(notifyValue);
|
||||
@ -114,26 +113,26 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
}
|
||||
|
||||
var keys = GetForewarningKeys(factors, order);
|
||||
var result = new List< ForewarningRule>();
|
||||
var result = new List<ForewarningRule>();
|
||||
|
||||
foreach (var item in keys)
|
||||
{
|
||||
if (!_ruleGroupDict.TryGetValue(item, out var rules))
|
||||
continue;
|
||||
|
||||
var allRules = rules.Where(val=>val.TrackStart <= order.Track && val.TrackEnd >= order.Track);
|
||||
var allRules = rules.Where(val => val.TrackStart <= order.Track && val.TrackEnd >= order.Track);
|
||||
result.AddRange(allRules);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private async ValueTask<int> ExecuteRule(List<ForewarningRule> rules,int orderId)
|
||||
private async ValueTask<int> ExecuteRule(List<ForewarningRule> rules, int orderId)
|
||||
{
|
||||
var members = new List<ZMember>();
|
||||
foreach (var rule in rules)
|
||||
{
|
||||
var notifys = ExecuteRule(rule,orderId);
|
||||
var notifys = ExecuteRule(rule, orderId);
|
||||
members.AddRange(notifys);
|
||||
}
|
||||
|
||||
@ -141,16 +140,16 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
return members.Count;
|
||||
}
|
||||
|
||||
private List<ZMember> ExecuteRule(ForewarningRule rule,int orderId)
|
||||
private List<ZMember> ExecuteRule(ForewarningRule rule, int orderId)
|
||||
{
|
||||
var members = new List<ZMember>();
|
||||
var intervalMinute = 60 * ((rule.Timeliness - rule.Remind) / rule.Count);// 间隔多少分钟
|
||||
var intervalMinute = 60 * ((rule.Timeliness - rule.Remind) / rule.Count); // 间隔多少分钟
|
||||
|
||||
for(var index=0;index<rule.Count;index++)
|
||||
for (var index = 0; index < rule.Count; index++)
|
||||
{
|
||||
var notifyTime = (rule.Remind*60) + intervalMinute * index;
|
||||
var notifyTime = (rule.Remind * 60) + intervalMinute * index;
|
||||
var notifyTimestamp = GetTimestamp(DateTime.Now.AddMinutes(notifyTime));
|
||||
var notifyValue = new ZMember(NotifyValue(rule, orderId, index),notifyTimestamp);
|
||||
var notifyValue = new ZMember(NotifyValue(rule, orderId, index), notifyTimestamp);
|
||||
members.Add(notifyValue);
|
||||
}
|
||||
|
||||
@ -162,9 +161,9 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
return new DateTimeOffset(dateTime).ToUnixTimeSeconds();
|
||||
}
|
||||
|
||||
private string NotifyValue(ForewarningRule rule, int orderId,int sort)
|
||||
private string NotifyValue(ForewarningRule rule, int orderId, int sort)
|
||||
{
|
||||
var result =new RuleNotifyValue(rule.Id, orderId, sort, rule.TrackEnd);
|
||||
var result = new RuleNotifyValue(rule.Id, orderId, sort, rule.TrackEnd);
|
||||
return result.ToString();
|
||||
}
|
||||
|
||||
@ -182,31 +181,32 @@ public class ForewarningNotifyService:IForewarningNotifyService,ITransientDepend
|
||||
|
||||
private async Task Init()
|
||||
{
|
||||
// todo:缓存设计有问题 重构 120s 10w 30w 3000k/s
|
||||
var allFactorCollect = await _ruleFactorCache.GetAllFactorCollect();
|
||||
var factors = await _ruleFactorCache.GetAllRuleFactor();
|
||||
var factorsMap = factors.GroupBy(val=>val.RuleId)
|
||||
.ToDictionary(val=>val.Key,val=>val.First());
|
||||
var factorsMap = factors.GroupBy(val => val.RuleId)
|
||||
.ToDictionary(val => val.Key, val => val.First());
|
||||
|
||||
_rules = allFactorCollect.ToDictionary(val => val.Id);
|
||||
|
||||
_factorDict = factors.GroupBy(val => GetFactorKey(val.CustomerId,val.SystemId))
|
||||
.ToDictionary(val=>val.Key,val=>val.ToList());
|
||||
_factorDict = factors.GroupBy(val => GetFactorKey(val.CustomerId, val.SystemId))
|
||||
.ToDictionary(val => val.Key, val => val.ToList());
|
||||
|
||||
_ruleGroupDict = allFactorCollect.GroupBy(x => GetRuleKey(x, factorsMap[x.RuleId]))
|
||||
.ToDictionary(val => val.Key, val => val.ToList());
|
||||
}
|
||||
|
||||
private string GetFactorKey(int customerId,int systemId)
|
||||
private string GetFactorKey(int customerId, int systemId)
|
||||
{
|
||||
return $"{customerId}:{systemId}";
|
||||
}
|
||||
|
||||
private string GetRuleKey(IForewarningFactorValue rule,RuleFactor factors)
|
||||
private string GetRuleKey(IForewarningFactorValue rule, RuleFactor factors)
|
||||
{
|
||||
var key = "";
|
||||
foreach (var factorItem in factors.FactorItems)
|
||||
{
|
||||
key+=GetFactorValue(factorItem,rule);
|
||||
key += GetFactorValue(factorItem, rule);
|
||||
}
|
||||
|
||||
return key;
|
||||
|
||||
@ -1,27 +1,24 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using AutoMapper;
|
||||
using SJZY.Track.Application.Helpers;
|
||||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
using SqlSugar;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
|
||||
[ApiExplorerSettings(GroupName = "预警服务")]
|
||||
[Route("/ForewarningService")]
|
||||
public class ForewarningService: ApplicationService
|
||||
public class ForewarningService : ApplicationService
|
||||
{
|
||||
readonly IRuleRepository _ruleRepository;
|
||||
IRuleFactorRepository _ruleFactorRepository;
|
||||
private IRuleCollectRepository _ruleCollectRepository;
|
||||
private IRuleItemRepository _ruleItemRepository;
|
||||
|
||||
public ForewarningService(IRuleRepository ruleRepository
|
||||
,IRuleFactorRepository ruleFactorRepository
|
||||
, IRuleCollectRepository ruleCollectRepository)
|
||||
, IRuleFactorRepository ruleFactorRepository
|
||||
, IRuleItemRepository ruleItemRepository)
|
||||
{
|
||||
_ruleRepository = ruleRepository;
|
||||
_ruleFactorRepository = ruleFactorRepository;
|
||||
_ruleCollectRepository = ruleCollectRepository;
|
||||
_ruleItemRepository = ruleItemRepository;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -32,8 +29,8 @@ public class ForewarningService: ApplicationService
|
||||
[HttpPost("ModifyForewarning")]
|
||||
public async ValueTask<UnifyResultDto> ModifyForewarning(CreateRuleFactorRequest input)
|
||||
{
|
||||
var factors = ObjectMapper.Map<CreateRuleFactorRequest,RuleFactorEntity>(input);
|
||||
var ruleCollects = ForewarningFactorHelper.GetFactorItem(factors);
|
||||
var factors = ObjectMapper.Map<CreateRuleFactorRequest, RuleFactorEntity>(input);
|
||||
var ruleItems = ForewarningFactorHelper.GetFactorItem(factors);
|
||||
|
||||
//todo 原子性没有保证,后续可能需要调整
|
||||
if (input.RuleId > 0)
|
||||
@ -43,22 +40,23 @@ public class ForewarningService: ApplicationService
|
||||
|
||||
if (input.RuleId > 0)
|
||||
{
|
||||
var ruleTemplate = await _ruleRepository.GetFirstAsync(val=>val.Id == input.RuleId);
|
||||
var ruleTemplate = await _ruleRepository.GetFirstAsync(val => val.Id == input.RuleId);
|
||||
if (ruleTemplate == null)
|
||||
return new UnifyResultDto(false,"规则不存在");
|
||||
return new UnifyResultDto(false, "规则不存在");
|
||||
|
||||
ruleTemplate.Name = input.Name;
|
||||
ruleTemplate.CustomId = input.CustomId;
|
||||
|
||||
await _ruleFactorRepository.IndexDocumentAsync(factors);
|
||||
await _ruleRepository.UpdateForewarning(ruleTemplate, ruleCollects);
|
||||
return new UnifyResultDto(true,"保存成功");
|
||||
await _ruleRepository.UpdateForewarning(ruleTemplate, ruleItems);
|
||||
return new UnifyResultDto(true, "保存成功");
|
||||
}
|
||||
|
||||
var newRuleTemplate = ObjectMapper.Map<CreateRuleFactorRequest, RuleEntity>(input);
|
||||
var ruleTemplateId = await _ruleRepository.CreateForewarning(newRuleTemplate, ruleCollects);
|
||||
factors.Id = ruleTemplateId.ToString();
|
||||
return new UnifyResultDto(true,"保存成功");
|
||||
var ruleId = await _ruleRepository.CreateForewarning(newRuleTemplate, ruleItems);
|
||||
factors.Id = ruleId.ToString();
|
||||
await _ruleFactorRepository.IndexDocumentAsync(factors);
|
||||
return new UnifyResultDto(true, "保存成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -67,10 +65,11 @@ public class ForewarningService: ApplicationService
|
||||
[HttpPost("ModifyTimeliness")]
|
||||
public async ValueTask<UnifyResultDto> ModifyTimeliness(ModifyTimelinessRequest input)
|
||||
{
|
||||
var ruleIds = input.Items.Select(val=>val.Id).ToList();
|
||||
var ruleCollect = await _ruleCollectRepository.GetListAsync(val => ruleIds.Contains(val.Id) && val.RuleId == input.RuleId);
|
||||
if (ruleCollect == null|| ruleCollect.Count == 0)
|
||||
throw new BusinessException(message:"规则不存在");
|
||||
var ruleIds = input.Items.Select(val => val.Id).ToList();
|
||||
var ruleCollect =
|
||||
await _ruleItemRepository.GetListAsync(val => ruleIds.Contains(val.Id) && val.RuleId == input.RuleId);
|
||||
if (ruleCollect == null || ruleCollect.Count == 0)
|
||||
throw new BusinessException(message: "规则不存在");
|
||||
|
||||
var ruleMaps = ruleCollect.ToDictionary(val => val.Id);
|
||||
var notModifyList = new List<int>();
|
||||
@ -82,12 +81,12 @@ public class ForewarningService: ApplicationService
|
||||
continue;
|
||||
}
|
||||
|
||||
rule.Remind= item.Remind;
|
||||
rule.Remind = item.Remind;
|
||||
rule.Timeliness = item.Timeliness;
|
||||
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)
|
||||
return new UnifyResultDto(true, $"更新成功,规则{string.Join(",", notModifyList)}不存在");
|
||||
@ -96,24 +95,23 @@ public class ForewarningService: ApplicationService
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询预警模板列表
|
||||
/// 查询预警规则列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("QueryForewarning")]
|
||||
public async Task<UnifyResultDto> QueryForewarning(QueryForewarningRequest input)
|
||||
{
|
||||
var result = await _ruleRepository.QueryForewarning(input);
|
||||
var result = await _ruleRepository.QueryForewarningRuleAsync(input);
|
||||
return new UnifyResultDto(true, result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询预警规则列表
|
||||
/// 查询预警规则明细列表
|
||||
/// </summary>
|
||||
[HttpPost("QueryForewarningRules")]
|
||||
public async Task<UnifyResultDto> QueryForewarningRules(QueryForewarningRuleRequest input)
|
||||
public async Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRuleItems(QueryForewarningRuleRequest input)
|
||||
{
|
||||
var result = await _ruleCollectRepository.QueryForewarningRule(input);
|
||||
return new UnifyResultDto(true, result);
|
||||
return await _ruleItemRepository.QueryForewarningRuleItemsAsync(input);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -122,7 +120,5 @@ public class ForewarningService: ApplicationService
|
||||
[HttpPost("SendForewarningNotification")]
|
||||
public void SendForewarningNotification()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,7 +1,5 @@
|
||||
using AutoMapper;
|
||||
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
using SqlSugar;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
|
||||
@ -9,9 +7,9 @@ namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
[Route("/ForewarningService")]
|
||||
public class KpiAreaService : ApplicationService
|
||||
{
|
||||
readonly IKpiAreaRepository _ruleAreaRepository;
|
||||
private readonly IKpiAreaRepository _ruleAreaRepository;
|
||||
|
||||
public KpiAreaService(IKpiAreaRepository ruleAreaRepository )
|
||||
public KpiAreaService(IKpiAreaRepository ruleAreaRepository)
|
||||
{
|
||||
_ruleAreaRepository = ruleAreaRepository;
|
||||
}
|
||||
@ -26,7 +24,7 @@ public class KpiAreaService : ApplicationService
|
||||
{
|
||||
var ruleAreaEntity = ObjectMapper.Map<CreateRuleAreaRequest, RuleAreaEntity>(input);
|
||||
var areaId = await _ruleAreaRepository.CreateAreaAsync(ruleAreaEntity);
|
||||
return new UnifyResultDto(true,areaId, "创建成功");
|
||||
return new UnifyResultDto(true, areaId, "创建成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -39,7 +37,7 @@ public class KpiAreaService : ApplicationService
|
||||
{
|
||||
var ruleAreaEntity = ObjectMapper.Map<AddRuleAreaInfoRequest, RuleAreaInfoEntity>(input);
|
||||
var ruleInfoId = await _ruleAreaRepository.AddAreaInfoAsync(ruleAreaEntity);
|
||||
return new UnifyResultDto(true,ruleInfoId, "添加成功");
|
||||
return new UnifyResultDto(true, ruleInfoId, "添加成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -74,16 +72,16 @@ public class KpiAreaService : ApplicationService
|
||||
[HttpPost("KpiArea/ModifyKpiArea")]
|
||||
public async Task<UnifyResultDto> ModifyKpiArea(UpdateRuleAreaRequest input)
|
||||
{
|
||||
if(input.Id<=0)
|
||||
return new UnifyResultDto(false,"id不能为空");
|
||||
if (input.Id <= 0)
|
||||
return new UnifyResultDto(false, "id不能为空");
|
||||
|
||||
var ruleArea =await _ruleAreaRepository.GetFirstAsync(val=>val.Id==input.Id);
|
||||
if(ruleArea==null)
|
||||
return new UnifyResultDto(false,"未找到该区域");
|
||||
var ruleArea = await _ruleAreaRepository.GetFirstAsync(val => val.Id == input.Id);
|
||||
if (ruleArea == null)
|
||||
return new UnifyResultDto(false, "未找到该区域");
|
||||
|
||||
ruleArea.Name = input.Name;
|
||||
await _ruleAreaRepository.UpdateAsync(ruleArea);
|
||||
return new UnifyResultDto(true,"更新成功");
|
||||
return new UnifyResultDto(true, "更新成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -94,17 +92,17 @@ public class KpiAreaService : ApplicationService
|
||||
[HttpPost("KpiArea/ModifyKpiAreaInfo")]
|
||||
public async Task<UnifyResultDto> ModifyKpiAreaInfo(UpdateRuleAreaInfoRequest input)
|
||||
{
|
||||
if(input.Id<=0)
|
||||
return new UnifyResultDto(false,"id不能为空");
|
||||
if (input.Id <= 0)
|
||||
return new UnifyResultDto(false, "id不能为空");
|
||||
|
||||
//todo 测试不存在id的情况
|
||||
RuleAreaInfoEntity areaInfo = await _ruleAreaRepository.GetAreaInfoById(input.Id);
|
||||
if(areaInfo==null)
|
||||
return new UnifyResultDto(false,"未找到该区域信息");
|
||||
var areaInfo = await _ruleAreaRepository.GetAreaInfoById(input.Id);
|
||||
if (areaInfo == null)
|
||||
return new UnifyResultDto(false, "未找到该区域信息");
|
||||
|
||||
var ruleAreaEntity = ObjectMapper.Map(input,areaInfo);
|
||||
var ruleAreaEntity = ObjectMapper.Map(input, areaInfo);
|
||||
await _ruleAreaRepository.UpdateAreaInfoAsync(ruleAreaEntity);
|
||||
return new UnifyResultDto(true,"更新成功");
|
||||
return new UnifyResultDto(true, "更新成功");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -7,189 +7,188 @@ using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace SJZY.Track.Application.Services.ForewarningServices;
|
||||
|
||||
public class RuleFactorCacheService:IRuleFactorCacheService,ITransientDependency
|
||||
public class RuleFactorCacheService : IRuleFactorCacheService, ITransientDependency
|
||||
{
|
||||
private const string GlobalFactorLockKey = "RuleFactorCacheService_GlobalLock";
|
||||
private const string GlobalRuleLockKey = "RuleFactorCacheService_GlobalLock";
|
||||
readonly IRuleFactorRepository _ruleFactorRepository;
|
||||
readonly IRuleCollectRepository _ruleCollectRepository;
|
||||
readonly IRuleRepository _ruleRepository;
|
||||
private const string GlobalFactorLockKey = "RuleFactorCacheService_GlobalLock";
|
||||
private const string GlobalRuleLockKey = "RuleFactorCacheService_GlobalLock";
|
||||
readonly IRuleFactorRepository _ruleFactorRepository;
|
||||
readonly IRuleItemRepository _ruleItemRepository;
|
||||
readonly IRuleRepository _ruleRepository;
|
||||
|
||||
public RuleFactorCacheService(IRuleFactorRepository ruleFactorRepository,
|
||||
IRuleCollectRepository ruleCollectRepository, IRuleRepository ruleRepository)
|
||||
{
|
||||
_ruleFactorRepository = ruleFactorRepository;
|
||||
_ruleCollectRepository = ruleCollectRepository;
|
||||
_ruleRepository = ruleRepository;
|
||||
}
|
||||
public RuleFactorCacheService(IRuleFactorRepository ruleFactorRepository,
|
||||
IRuleItemRepository ruleItemRepository, IRuleRepository ruleRepository)
|
||||
{
|
||||
_ruleFactorRepository = ruleFactorRepository;
|
||||
_ruleItemRepository = ruleItemRepository;
|
||||
_ruleRepository = ruleRepository;
|
||||
}
|
||||
|
||||
private string GetKey()
|
||||
{
|
||||
return $"{GlobalConst.RuleFactorKeyPrefix}:allFactor";
|
||||
}
|
||||
private string GetKey()
|
||||
{
|
||||
return $"{GlobalConst.RuleFactorKeyPrefix}:allFactor";
|
||||
}
|
||||
|
||||
private string GetRuleKey()
|
||||
{
|
||||
return $"{GlobalConst.RuleFactorKeyPrefix}:allRule";
|
||||
}
|
||||
private string GetRuleKey()
|
||||
{
|
||||
return $"{GlobalConst.RuleFactorKeyPrefix}:allRule";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有规则数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<ForewarningRule[]> GetAllFactorCollect()
|
||||
{
|
||||
|
||||
var key = GetRuleKey();
|
||||
var result =await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
|
||||
if (result == null)
|
||||
{
|
||||
using (var globalLock = RedisHelper.Client.Lock(GlobalRuleLockKey, 10))
|
||||
{
|
||||
result =await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
|
||||
if (result != null) return result;
|
||||
|
||||
var ruleCollect = await _ruleCollectRepository.GetListAsync(val => true);
|
||||
if (ruleCollect == null || ruleCollect.Count == 0)
|
||||
/// <summary>
|
||||
/// 获取所有规则数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[NonAction]
|
||||
public async Task<ForewarningRule[]> GetAllFactorCollect()
|
||||
{
|
||||
var key = GetRuleKey();
|
||||
var result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
|
||||
if (result == null)
|
||||
{
|
||||
using (var globalLock = RedisHelper.Client.Lock(GlobalRuleLockKey, 10))
|
||||
{
|
||||
ForewarningRule[] rules = new ForewarningRule[0];
|
||||
await RedisHelper.Client.SetAsync(key,rules , TimeSpan.FromSeconds(20));
|
||||
return result;
|
||||
result = await RedisHelper.Client.GetAsync<ForewarningRule[]>(key);
|
||||
if (result != null) return result;
|
||||
|
||||
var ruleCollect = await _ruleItemRepository.GetListAsync(val => true);
|
||||
if (ruleCollect == null || ruleCollect.Count == 0)
|
||||
{
|
||||
ForewarningRule[] rules = new ForewarningRule[0];
|
||||
await RedisHelper.Client.SetAsync(key, rules, TimeSpan.FromSeconds(20));
|
||||
return result;
|
||||
}
|
||||
|
||||
var ruleList = ruleCollect.SelectMany(RuleEntityToRule);
|
||||
await RedisHelper.Client.SetAsync(key, ruleList);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
var ruleList = ruleCollect.SelectMany(RuleEntityToRule);
|
||||
await RedisHelper.Client.SetAsync(key, ruleList);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有因素数据
|
||||
/// </summary>
|
||||
/// <returns>获取所有因素,返回值可能为空</returns>
|
||||
[NonAction]
|
||||
public async Task<List<RuleFactor>> GetAllRuleFactor()
|
||||
{
|
||||
var key = GetKey();
|
||||
var result =await RedisHelper.Client.GetAsync<List<RuleFactor>>(key);
|
||||
if (result == null)
|
||||
{
|
||||
using (var globalLock = RedisHelper.Client.Lock(GlobalFactorLockKey, 10))
|
||||
{
|
||||
result =await RedisHelper.Client.GetAsync<List<RuleFactor>>(key);
|
||||
if (result != null) return result;
|
||||
|
||||
result = await GenerateAllRuleFactor();
|
||||
if (result == null || result.Count == 0)
|
||||
/// <summary>
|
||||
/// 获取所有因素数据
|
||||
/// </summary>
|
||||
/// <returns>获取所有因素,返回值可能为空</returns>
|
||||
[NonAction]
|
||||
public async Task<List<RuleFactor>> GetAllRuleFactor()
|
||||
{
|
||||
var key = GetKey();
|
||||
var result = await RedisHelper.Client.GetAsync<List<RuleFactor>>(key);
|
||||
if (result == null)
|
||||
{
|
||||
using (var globalLock = RedisHelper.Client.Lock(GlobalFactorLockKey, 10))
|
||||
{
|
||||
await RedisHelper.Client.SetAsync(key,new List<RuleFactor>() , TimeSpan.FromSeconds(20));
|
||||
return result;
|
||||
result = await RedisHelper.Client.GetAsync<List<RuleFactor>>(key);
|
||||
if (result != null) return result;
|
||||
|
||||
result = await GenerateAllRuleFactor();
|
||||
if (result == null || result.Count == 0)
|
||||
{
|
||||
await RedisHelper.Client.SetAsync(key, new List<RuleFactor>(), TimeSpan.FromSeconds(20));
|
||||
return result;
|
||||
}
|
||||
|
||||
await RedisHelper.Client.SetAsync(key, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
await RedisHelper.Client.SetAsync(key, result);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
[NonAction]
|
||||
public void ClearFactorCache()
|
||||
{
|
||||
RedisHelper.Client.DelAsync(GetKey());
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void ClearFactorCache()
|
||||
{
|
||||
RedisHelper.Client.DelAsync(GetKey());
|
||||
}
|
||||
[NonAction]
|
||||
public void ClearRuleCache()
|
||||
{
|
||||
RedisHelper.Client.DelAsync(GetRuleKey());
|
||||
}
|
||||
|
||||
[NonAction]
|
||||
public void ClearRuleCache()
|
||||
{
|
||||
RedisHelper.Client.DelAsync(GetRuleKey());
|
||||
}
|
||||
private async Task<List<RuleFactor>> GenerateAllRuleFactor()
|
||||
{
|
||||
var factors = await _ruleFactorRepository.GetAllList();
|
||||
var ruleTemplate = await _ruleRepository.GetListAsync(val => true);
|
||||
var ruleMap = ruleTemplate.ToDictionary(val => val.Id);
|
||||
var result = new List<RuleFactor>();
|
||||
foreach (var item in factors)
|
||||
{
|
||||
if (!ruleMap.TryGetValue(item.RuleId, out var rule))
|
||||
continue;
|
||||
var ruleFactors = EntityToRuleFactor(item, rule);
|
||||
result.AddRange(ruleFactors);
|
||||
}
|
||||
|
||||
private async Task<List<RuleFactor>> GenerateAllRuleFactor()
|
||||
{
|
||||
var factors =await _ruleFactorRepository.GetAllList();
|
||||
var ruleTemplate =await _ruleRepository.GetListAsync(val => true);
|
||||
var ruleMap = ruleTemplate.ToDictionary(val => val.Id);
|
||||
var result = new List<RuleFactor>();
|
||||
foreach (var item in factors)
|
||||
{
|
||||
if(!ruleMap.TryGetValue(item.RuleId,out var rule))
|
||||
continue;
|
||||
var ruleFactors = EntityToRuleFactor(item, rule);
|
||||
result.AddRange(ruleFactors);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
private ForewarningRule[] RuleEntityToRule(RuleItemEntity entity)
|
||||
{
|
||||
var result = RuleCollectToRule(entity);
|
||||
if (string.IsNullOrEmpty(entity.Month))
|
||||
{
|
||||
return new ForewarningRule[] { result };
|
||||
}
|
||||
|
||||
private ForewarningRule[] RuleEntityToRule(RuleCollectEntity entity)
|
||||
{
|
||||
var result = RuleCollectToRule(entity);
|
||||
if (string.IsNullOrEmpty(entity.Month))
|
||||
{
|
||||
return new ForewarningRule[] { result };
|
||||
}
|
||||
var months = entity.Month.Split('/');
|
||||
var rules = new List<ForewarningRule>(months.Length);
|
||||
|
||||
var months = entity.Month.Split('/');
|
||||
var rules = new List<ForewarningRule>(months.Length);
|
||||
foreach (var month in months)
|
||||
{
|
||||
if (int.TryParse(month, out int monthInt))
|
||||
{
|
||||
var rule = result;
|
||||
rule.Month = monthInt;
|
||||
rules.Add(rule);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var month in months)
|
||||
{
|
||||
if (int.TryParse(month, out int monthInt))
|
||||
{
|
||||
var rule = result;
|
||||
rule.Month = monthInt;
|
||||
rules.Add(rule);
|
||||
}
|
||||
}
|
||||
return rules.ToArray();
|
||||
}
|
||||
|
||||
return rules.ToArray();
|
||||
}
|
||||
private ForewarningRule RuleCollectToRule(RuleItemEntity entity)
|
||||
{
|
||||
return new ForewarningRule
|
||||
{
|
||||
Id = entity.Id,
|
||||
RuleId = entity.RuleId,
|
||||
Remind = entity.Remind,
|
||||
Timeliness = entity.Timeliness,
|
||||
Count = entity.Count,
|
||||
TrackStart = entity.TrackStart,
|
||||
TrackEnd = entity.TrackEnd,
|
||||
CargoType = entity.CargoType,
|
||||
Month = null,
|
||||
Area = entity.Area,
|
||||
IsTransit = entity.IsTransit,
|
||||
DeparturePort = entity.DeparturePort,
|
||||
ProductCode = entity.ProductCode
|
||||
};
|
||||
}
|
||||
|
||||
private ForewarningRule RuleCollectToRule(RuleCollectEntity entity)
|
||||
{
|
||||
return new ForewarningRule
|
||||
{
|
||||
Id = entity.Id,
|
||||
RuleId = entity.RuleId,
|
||||
Remind = entity.Remind,
|
||||
Timeliness = entity.Timeliness,
|
||||
Count = entity.Count,
|
||||
TrackStart = entity.TrackStart,
|
||||
TrackEnd = entity.TrackEnd,
|
||||
CargoType = entity.CargoType,
|
||||
Month = null,
|
||||
Area = entity.Area,
|
||||
IsTransit = entity.IsTransit,
|
||||
DeparturePort = entity.DeparturePort,
|
||||
ProductCode = entity.ProductCode
|
||||
};
|
||||
}
|
||||
private List<RuleFactor> EntityToRuleFactor(RuleFactorEntity entity, RuleEntity ruleTemplate)
|
||||
{
|
||||
List<RuleFactor> result = new List<RuleFactor>();
|
||||
foreach (var track in entity.Tracks)
|
||||
{
|
||||
var item = new RuleFactor()
|
||||
{
|
||||
CustomerId = ruleTemplate.CustomId,
|
||||
RuleId = ruleTemplate.Id,
|
||||
NotifyUser = track.NotifyUser,
|
||||
NotifyTemplate = track.NotifyTemplate,
|
||||
FactorItems = entity.FactorItems,
|
||||
End = track.End,
|
||||
Start = track.Start,
|
||||
SystemId = ruleTemplate.SubSystemId
|
||||
};
|
||||
result.Add(item);
|
||||
}
|
||||
|
||||
private List<RuleFactor> EntityToRuleFactor(RuleFactorEntity entity,RuleEntity ruleTemplate)
|
||||
{
|
||||
List<RuleFactor> result = new List<RuleFactor>();
|
||||
foreach (var track in entity.Tracks)
|
||||
{
|
||||
var item = new RuleFactor()
|
||||
{
|
||||
CustomerId = ruleTemplate.CustomId,
|
||||
RuleId = ruleTemplate.Id,
|
||||
NotifyUser = track.NotifyUser,
|
||||
NotifyTemplate = track.NotifyTemplate,
|
||||
FactorItems = entity.FactorItems,
|
||||
End = track.End,
|
||||
Start = track.Start,
|
||||
SystemId = ruleTemplate.SubSystemId
|
||||
};
|
||||
result.Add(item);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@ -2,12 +2,12 @@ using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
|
||||
public interface IRuleCollectRepository:IBasicRepository<RuleCollectEntity>
|
||||
public interface IRuleItemRepository : IBasicRepository<RuleItemEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询分页
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRule(QueryForewarningRuleRequest input);
|
||||
Task<UnifyPageResultDto<RuleCollectDto>> QueryForewarningRuleItemsAsync(QueryForewarningRuleRequest input);
|
||||
}
|
||||
@ -2,11 +2,11 @@ using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
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);
|
||||
}
|
||||
@ -5,7 +5,7 @@ using SJZY.Track.Domain.Consts;
|
||||
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
|
||||
[ElasticsearchType(RelationName = GlobalConst.RuleFactorIndex)]
|
||||
public class RuleFactorEntity:IdBaseIndex
|
||||
public class RuleFactorEntity : IdBaseIndex
|
||||
{
|
||||
/// <summary>
|
||||
/// RuleId 表的id
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
namespace SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
|
||||
[SugarTable("t_rule_collect")]
|
||||
public class RuleCollectEntity : IAggregateRoot,ICloneable
|
||||
[SugarTable("t_rule_item")]
|
||||
public class RuleItemEntity : IAggregateRoot, ICloneable
|
||||
{
|
||||
/// <summary>
|
||||
/// 自增主键
|
||||
@ -9,8 +9,7 @@ public class RuleCollectEntity : IAggregateRoot,ICloneable
|
||||
[SugarColumn(ColumnName = "Id", IsPrimaryKey = true, IsIdentity = true)]
|
||||
public int Id { get; set; }
|
||||
|
||||
[SugarColumn(ColumnName = "RuleId")]
|
||||
public int RuleId { get; set; }
|
||||
[SugarColumn(ColumnName = "RuleId")] public int RuleId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 提醒的时间(小时)
|
||||
@ -2,7 +2,7 @@ using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
namespace SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
||||
|
||||
public interface IKpiAreaRepository:IBasicRepository<RuleAreaEntity>
|
||||
public interface IKpiAreaRepository : IBasicRepository<RuleAreaEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建分区
|
||||
@ -58,7 +58,7 @@ public interface IKpiAreaRepository:IBasicRepository<RuleAreaEntity>
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
Task<RuleAreaInfoEntity> GetAreaInfoById(int id);
|
||||
Task<RuleAreaInfoEntity?> GetAreaInfoById(int id);
|
||||
|
||||
/// <summary>
|
||||
/// 获取所有区域信息
|
||||
|
||||
@ -1,15 +1,14 @@
|
||||
using SJZY.Track.Domain;
|
||||
using SJZY.Track.Domain.Aggregates.ForewarningAggregate;
|
||||
using SJZY.Track.Domain.Aggregates.KPIAreaAggregate;
|
||||
using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
namespace SJZY.Track.Repository.Repositories;
|
||||
|
||||
public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaRepository,ITransientDependency
|
||||
public class KpiAreaRepository : BasicRepository<RuleAreaEntity>, IKpiAreaRepository, ITransientDependency
|
||||
{
|
||||
public async ValueTask<int> CreateAreaAsync(RuleAreaEntity entity)
|
||||
{
|
||||
return await InsertReturnIdentityAsync(entity);
|
||||
return await InsertReturnIdentityAsync(entity);
|
||||
}
|
||||
|
||||
public async ValueTask<int> AddAreaInfoAsync(RuleAreaInfoEntity entity)
|
||||
@ -27,7 +26,7 @@ public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaReposito
|
||||
|
||||
public Task<int> DeleteAreaInfo(int areaInfoId)
|
||||
{
|
||||
return Context.Deleteable<RuleAreaInfoEntity>().Where(val=>val.Id==areaInfoId).ExecuteCommandAsync();
|
||||
return Context.Deleteable<RuleAreaInfoEntity>().Where(val => val.Id == areaInfoId).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
public Task<int> UpdateAreaInfoAsync(RuleAreaInfoEntity entity)
|
||||
@ -54,7 +53,7 @@ public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaReposito
|
||||
}
|
||||
|
||||
return await queryable.OrderBy(x => x.Id, OrderByType.Desc)
|
||||
.Select<AreaDto>(val=>new AreaDto()
|
||||
.Select<AreaDto>(val => new AreaDto()
|
||||
{
|
||||
Id = val.Id,
|
||||
Name = val.Name,
|
||||
@ -74,7 +73,7 @@ public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaReposito
|
||||
var queryable = Context.Queryable<RuleAreaInfoEntity>();
|
||||
queryable = queryable.Where(x => x.AreaId == query.AreaId);
|
||||
return await queryable.OrderBy(x => x.Id, OrderByType.Desc)
|
||||
.Select<RuleAreaInfoDto>(val=>new RuleAreaInfoDto()
|
||||
.Select<RuleAreaInfoDto>(val => new RuleAreaInfoDto()
|
||||
{
|
||||
Id = val.Id,
|
||||
AreaId = val.AreaId,
|
||||
@ -87,9 +86,9 @@ public class KpiAreaRepository:BasicRepository<RuleAreaEntity> ,IKpiAreaReposito
|
||||
.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>
|
||||
|
||||
@ -3,16 +3,16 @@ using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
namespace SJZY.Track.Repository.Repositories;
|
||||
|
||||
public class RuleCollectRepository: BasicRepository<RuleCollectEntity>, IRuleCollectRepository,ITransientDependency
|
||||
public class RuleItemRepository : BasicRepository<RuleItemEntity>, IRuleItemRepository, ITransientDependency
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询预警规则分页信息
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <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);
|
||||
|
||||
if (!string.IsNullOrEmpty(input.SortField))
|
||||
@ -20,11 +20,11 @@ public class RuleCollectRepository: BasicRepository<RuleCollectEntity>, IRuleCol
|
||||
query = query.OrderByPropertyName(input.SortField, input.IsAsc ? OrderByType.Asc : OrderByType.Desc);
|
||||
}
|
||||
|
||||
return query.Select(val=>MapToDto(val))
|
||||
return query.Select(val => MapToDto(val))
|
||||
.ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
}
|
||||
|
||||
private RuleCollectDto MapToDto(RuleCollectEntity entity)
|
||||
private RuleCollectDto MapToDto(RuleItemEntity entity)
|
||||
{
|
||||
return new RuleCollectDto()
|
||||
{
|
||||
@ -4,27 +4,28 @@ using SJZY.Track.Domain.Dtos.Forewarning;
|
||||
|
||||
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();
|
||||
|
||||
var ruleId = await InsertReturnIdentityAsync(rule);
|
||||
foreach (var item in factorList)
|
||||
foreach (var item in ruleItems)
|
||||
{
|
||||
item.RuleId = ruleId;
|
||||
}
|
||||
await Context.Insertable(factorList).ExecuteCommandAsync();
|
||||
|
||||
await Context.Insertable(ruleItems).ExecuteCommandAsync();
|
||||
tran.Complete();
|
||||
return ruleId;
|
||||
}
|
||||
|
||||
public async Task UpdateForewarning(RuleEntity rule,RuleCollectEntity[] factorList)
|
||||
public async Task UpdateForewarning(RuleEntity rule, RuleItemEntity[] factorList)
|
||||
{
|
||||
using var tran = TransactionHelper.GetReadCommitted();
|
||||
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();
|
||||
tran.Complete();
|
||||
}
|
||||
@ -34,11 +35,12 @@ public class RuleRepository:BasicRepository<RuleEntity> ,IRuleRepository,ITransi
|
||||
/// </summary>
|
||||
/// <param name="input"></param>
|
||||
/// <returns></returns>
|
||||
public Task<UnifyPageResultDto<RuleEntity>> QueryForewarning(QueryForewarningRequest input)
|
||||
public Task<UnifyPageResultDto<RuleEntity>> QueryForewarningRuleAsync(QueryForewarningRequest input)
|
||||
{
|
||||
var query = Context.Queryable<RuleEntity>()
|
||||
.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(input.SystemId.HasValue, val => val.SubSystemId == input.SystemId)
|
||||
.WhereIF(!string.IsNullOrEmpty(input.KeyWord),
|
||||
val => val.CustomName.Contains(input.KeyWord!) || val.Name.Contains(input.KeyWord!));
|
||||
|
||||
if (!string.IsNullOrEmpty(input.SortField))
|
||||
{
|
||||
@ -47,7 +49,4 @@ public class RuleRepository:BasicRepository<RuleEntity> ,IRuleRepository,ITransi
|
||||
|
||||
return query.ToPagedListAsync(input.PageIndex, input.PageSize);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user