using JetBrains.Annotations; using SJZY.Track.Domain.Aggregates.ForewarningAggregate; namespace SJZY.Track.Application.Helpers; public class ForewarningFactorHelper { public static RuleCollectEntity[] 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); return ruleCollect.ToArray(); } private static void Assignment(Span ruleCollect,int total,IReadOnlyList values,Action action) { if (values.Count == 0) { return; } var segment = total / values.Count; for(int index=0;index AllocateFactor(int total,int ruleId) { Span factors = new RuleCollectEntity[total]; for (int index = 0; index < total; index++) { factors[index] = new RuleCollectEntity() { 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; } }