using HStation.WinFrmUI.PhartRelation;
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
using System.Linq;
|
using System.Windows.Input;
|
using Yw.WinFrmUI.Q3d;
|
|
namespace HStation.WinFrmUI
|
{
|
public class AssetsMatchingHelper
|
{
|
private readonly Lazy<BLL.PhartDiagramRelation> _bll_ex = new();
|
private const double _caliberTolerance = 10.0;
|
private const double _speedTolerance = 100;
|
private const double _flowTolerance = 10;
|
private const double _headTolerance = 5;
|
private const double _powerTolerance = 0.05;
|
private const double _valveLift = 10;//阀门开度范围
|
private const int _angle = 1;//角度范围
|
|
//资产自动匹配
|
public static bool Matching(HydroMatchingViewModel assetsAutoMatchingView, out string Error)
|
{
|
Error = string.Empty;
|
bool IsMaching = false;
|
var AssetsPumpMain = new BLL.AssetsPumpMain();
|
var AdaptingManage = new BLL.AdaptingManage();
|
var pipeLineManage = new BLL.AssetsPipeMain();
|
var AssetsValveMain = new BLL.AssetsValveMain();
|
var AssetsElbowMain = new BLL.AssetsElbowMain();
|
var AssetsThreelinkMain = new BLL.AssetsThreelinkMain();
|
var AssetsFourlinkMain = new BLL.AssetsFourlinkMain();
|
var AssetsSprinkler = new BLL.AssetsSprinklerMain();
|
var AssetsExchanger = new BLL.AssetsExchangerMain();
|
var AssetsCompressorMain = new BLL.AssetsCompressorMain();
|
var AssetsBluntheadMain = new BLL.AssetsBluntheadMain();
|
var AssetsTankMain = new BLL.AssetsTankMain();
|
var AssetsMeterMain = new BLL.AssetsMeterMain();
|
var AssetsFlowmeterMain = new BLL.AssetsFlowmeterMain();
|
var AssetsHydrantMain = new BLL.AssetsHydrantMain();
|
var AssetsPressmeterMain = new BLL.AssetsPressmeterMain();
|
var AssetsTranslationMain = new BLL.AssetsTranslationMain();
|
var AssetsCoolingMain = new BLL.AssetsCoolingMain();
|
try
|
{
|
var allPump = Task.Run(async () => await AssetsPumpMain.GetAll()).Result;
|
// var allAdapting = Task.Run(async () => await adaptingManage.GetAll()).Result;
|
var allPipeLine = Task.Run(async () => await pipeLineManage.GetAll()).Result;
|
var allValve = Task.Run(async () => await AssetsValveMain.GetAll()).Result;
|
var allElbow = Task.Run(async () => await AssetsElbowMain.GetAll()).Result;
|
var allThreeLink = Task.Run(async () => await AssetsThreelinkMain.GetAll()).Result;
|
var allFourLink = Task.Run(async () => await AssetsFourlinkMain.GetAll()).Result;
|
var allSprinkler = Task.Run(async () => await AssetsSprinkler.GetAll()).Result;
|
var allExchanger = Task.Run(async () => await AssetsExchanger.GetAll()).Result;
|
var allCompressorMain = Task.Run(async () => await AssetsCompressorMain.GetAll()).Result;
|
var allBluntheadMain = Task.Run(async () => await AssetsBluntheadMain.GetAll()).Result;
|
var allTankMain = Task.Run(async () => await AssetsTankMain.GetAll()).Result;
|
var allMeterMain = Task.Run(async () => await AssetsMeterMain.GetAll()).Result;
|
var allFlowmeterMain = Task.Run(async () => await AssetsFlowmeterMain.GetAll()).Result;
|
var allHydrantMain = Task.Run(async () => await AssetsHydrantMain.GetAll()).Result;
|
var allPressmeterMain = Task.Run(async () => await AssetsPressmeterMain.GetAll()).Result;
|
var allTranslationMain = Task.Run(async () => await AssetsTranslationMain.GetAll()).Result;
|
var allCoolingMain = Task.Run(async () => await AssetsCoolingMain.GetAll()).Result;
|
//泵匹配
|
foreach (var item in assetsAutoMatchingView.Pumps)
|
{
|
if (MatchingPumps(item, allPump))
|
{
|
IsMaching = true;
|
}
|
}
|
//三通匹配
|
foreach (var item in assetsAutoMatchingView.Threelinks)
|
{
|
if (Matching(item, allThreeLink))
|
{
|
IsMaching = true;
|
}
|
}
|
//四通匹配
|
foreach (var item in assetsAutoMatchingView.Fourlinks)
|
{
|
if (Matching(item, allFourLink))
|
{
|
IsMaching = true;
|
}
|
}
|
//管道匹配
|
foreach (var item in assetsAutoMatchingView.Pipes)
|
{
|
if (Matching(item, allPipeLine))
|
{
|
IsMaching = true;
|
}
|
}
|
//阀门匹配
|
foreach (var item in assetsAutoMatchingView.Valves)
|
{
|
if (Matching(item, allValve))
|
{
|
IsMaching = true;
|
}
|
}
|
//弯头匹配
|
foreach (var item in assetsAutoMatchingView.Elbows)
|
{
|
if (Matching(item, allElbow))
|
{
|
IsMaching = true;
|
}
|
}
|
//喷头匹配
|
foreach (var item in assetsAutoMatchingView.Nozzles)
|
{
|
if (Matching(item, allSprinkler))
|
{
|
IsMaching = true;
|
}
|
}
|
|
//喷头匹配
|
foreach (var item in assetsAutoMatchingView.Coolings)
|
{
|
if (Matching(item, allCoolingMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//闷头匹配
|
foreach (var item in assetsAutoMatchingView.Bluntheads)
|
{
|
if (Matching(item, allBluntheadMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//换热器匹配
|
foreach (var item in assetsAutoMatchingView.Exchangers)
|
{
|
if (Matching(item, allExchanger))
|
{
|
IsMaching = true;
|
}
|
}
|
//压缩机匹配
|
foreach (var item in assetsAutoMatchingView.Compressors)
|
{
|
if (Matching(item, allCompressorMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//水池匹配
|
foreach (var item in assetsAutoMatchingView.Tanks)
|
{
|
if (Matching(item, allTankMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//水表匹配
|
foreach (var item in assetsAutoMatchingView.Meters)
|
{
|
if (Matching(item, allMeterMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//流量计匹配
|
foreach (var item in assetsAutoMatchingView.Flowmeters)
|
{
|
if (Matching(item, allFlowmeterMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//消火栓匹配
|
foreach (var item in assetsAutoMatchingView.Hydrants)
|
{
|
if (Matching(item, allHydrantMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//压力表匹配
|
foreach (var item in assetsAutoMatchingView.Pressmeters)
|
{
|
if (Matching(item, allPressmeterMain))
|
{
|
IsMaching = true;
|
}
|
}
|
//过渡件匹配
|
foreach (var item in assetsAutoMatchingView.Translations)
|
{
|
if (Matching(item, allTranslationMain))
|
{
|
IsMaching = true;
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
Error = ex.Message;
|
return false;
|
}
|
return IsMaching;
|
}
|
|
//泵匹配
|
public static bool MatchingPumps(HydroPumpMatchingViewModel InputModel, List<Vmo.AssetsPumpMainVmo> AssetsPumpMainVmos)
|
{
|
if (AssetsPumpMainVmos == null)
|
{
|
return true;
|
}
|
Vmo.AssetsPumpMainVmo vmo = null;
|
int startCount = 0;
|
// 尝试绝对匹配
|
var absoluteMatch = AssetsPumpMainVmos.Where(item =>
|
(InputModel.RatedN == null || InputModel.RatedN == item.RatedSpeed) &&
|
(InputModel.RatedQ == null || InputModel.RatedQ == item.RatedFlow) &&
|
(InputModel.RatedH == null || InputModel.RatedH == item.RatedHead) &&
|
(InputModel.RatedP == item.RatedPower)).ToList();
|
if (absoluteMatch != null && absoluteMatch.Count != 0)
|
{
|
foreach (var item in absoluteMatch)
|
{
|
int commonCount = GetIntersect(InputModel.ModelType, item.Name);
|
if (commonCount > startCount)
|
{
|
vmo = item;
|
startCount = commonCount;
|
}
|
}
|
}
|
else
|
{
|
// 尝试区间匹配
|
var rangeMatch = AssetsPumpMainVmos.Where(item =>
|
(InputModel.RatedN.HasValue ? Math.Abs(InputModel.RatedN.Value - item.RatedSpeed) <= _speedTolerance : true) &&
|
(InputModel.RatedQ.HasValue ? Math.Abs(InputModel.RatedQ.Value - item.RatedFlow) <= _flowTolerance : true) &&
|
(InputModel.RatedH.HasValue ? Math.Abs(InputModel.RatedH.Value - item.RatedHead) <= _headTolerance : true) &&
|
(Math.Abs(InputModel.RatedP - item.RatedPower) <= _powerTolerance)).ToList();
|
if (rangeMatch != null && rangeMatch.Count != 0)
|
{
|
foreach (var item in rangeMatch)
|
{
|
int commonCount = GetIntersect(InputModel.ModelType, item.Name);
|
if (commonCount > startCount)
|
{
|
vmo = item;
|
startCount = commonCount;
|
}
|
}
|
}
|
}
|
//
|
if (vmo == null)
|
{
|
foreach (var item in AssetsPumpMainVmos)
|
{
|
int commonCount = GetIntersect(InputModel.ModelType, item.Name);
|
if (commonCount > startCount)
|
{
|
vmo = item;
|
startCount = commonCount;
|
}
|
}
|
}
|
if (vmo != null)
|
{
|
InputModel.MatchingRatedH = vmo.RatedHead;
|
InputModel.MatchingRatedN = vmo.RatedSpeed;
|
InputModel.MatchingRatedQ = vmo.RatedFlow;
|
InputModel.MatchingRatedP = vmo.RatedPower;
|
InputModel.MatchingDbId = vmo.ID.ToString();
|
InputModel.MatchingModelType = vmo.Name;
|
var list = Task.Run(async () => await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.PumpMain, vmo.ID)).Result;
|
if (list != null && list.Count > 0)
|
{
|
var def = list.OrderByDescending(x => x.Importance).First();
|
InputModel.MatchingCurveDbId = def.ID.ToString();
|
var diagram = def.Diagram.GetDefaultVmo();
|
var qh = diagram.QH.GetFeatPointList();
|
var qp = diagram.QP.GetFeatPointList();
|
var qe = diagram.QE.GetFeatPointList();
|
InputModel.MatchingCurveQH = new List<HydroCurvePointViewModel>();
|
InputModel.MatchingCurveQP = new List<HydroCurvePointViewModel>();
|
InputModel.MatchingCurveQE = new List<HydroCurvePointViewModel>();
|
foreach (var item in qh)
|
{
|
InputModel.MatchingCurveQH.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
foreach (var item in qp)
|
{
|
InputModel.MatchingCurveQP.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
foreach (var item in qe)
|
{
|
InputModel.MatchingCurveQE.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
}
|
|
return true;
|
}
|
return false;
|
}
|
|
//阀门匹配
|
public static bool Matching(HydroValveMatchingViewModel input, List<AssetsValveMainVmo> valveMainVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (valveMainVmos == null || valveMainVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsValveMainVmo, double>();
|
foreach (var item in valveMainVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in valveMainVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in valveMainVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Diameter > 0)
|
{
|
foreach (var item in valveMainVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Diameter);
|
dict[item] += diff / input.Diameter * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in valveMainVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in valveMainVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var valve = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = valve.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = valve.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = valve.Material;
|
}
|
if (input.Diameter <= 0 && valve.Caliber.HasValue)
|
{
|
input.Diameter = valve.Caliber.Value;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = valve.MinorLoss;
|
}
|
if (input.ValveSetting == null)
|
{
|
input.MatchingValveSetting = valve.ValveSetting;
|
}
|
if (input.CurveDbId == null)
|
{
|
var list = Task.Run(async () =>
|
await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.ValveMain, valve.ID)).Result;
|
if (list != null && list.Count > 0)
|
{
|
var def = list.OrderByDescending(x => x.Importance).First();
|
input.MatchingCurveDbId = def.ID.ToString();
|
var curve = def.Diagram.GraphList[0].GetFeatPointList();
|
if (valve.ValveType == HStation.Assets.eValveType.GPV)
|
{
|
input.MatchingCurveQL = new List<HydroCurvePointViewModel>();
|
foreach (var item in curve)
|
{
|
input.MatchingCurveQL.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
}
|
else if (valve.ValveType == HStation.Assets.eValveType.TCV)
|
{
|
input.MatchingCurveOL = new List<HydroCurvePointViewModel>();
|
foreach (var item in curve)
|
{
|
input.MatchingCurveOL.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
}
|
}
|
}
|
|
return true;
|
}
|
|
//管道匹配
|
public static bool Matching(HydroPipeMatchingViewModel input, List<AssetsPipeMainVmo> pipeLineMainVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (pipeLineMainVmos == null || pipeLineMainVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsPipeMainVmo, double>();
|
foreach (var item in pipeLineMainVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in pipeLineMainVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in pipeLineMainVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Diameter > 0)
|
{
|
foreach (var item in pipeLineMainVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Diameter);
|
dict[item] += diff / input.Diameter * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in pipeLineMainVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in pipeLineMainVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var pipe = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = pipe.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = pipe.Name;
|
}
|
if (input.Roughness == 0)
|
{
|
input.MatchingRoughness = pipe.Hazen;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = pipe.Material;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = pipe.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//三通匹配
|
public static bool Matching(HydroThreelinkMatchingViewModel input, List<AssetsThreelinkMainVmo> threelinkVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (threelinkVmos == null || threelinkVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsThreelinkMainVmo, double>();
|
foreach (var item in threelinkVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in threelinkVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in threelinkVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in threelinkVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in threelinkVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in threelinkVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var threelink = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = threelink.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = threelink.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = threelink.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = threelink.Caliber;
|
}
|
if (!input.MinorLoss.HasValue)
|
{
|
input.MatchingMinorLoss = threelink.MinorLoss;
|
}
|
if (!input.RunningThroughLoss.HasValue)
|
{
|
input.MatchingRunningThroughLoss = threelink.RunThroughMinorLoss;
|
}
|
if (!input.MatchingBranchThroughLoss.HasValue)
|
{
|
input.MatchingBranchThroughLoss = threelink.BranchThroughMinorLoss;
|
}
|
|
return true;
|
}
|
|
//四通匹配
|
public static bool Matching(HydroFourlinkMatchingViewModel input, List<AssetsFourlinkMainVmo> fourLinkVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (fourLinkVmos == null || fourLinkVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsFourlinkMainVmo, double>();
|
foreach (var item in fourLinkVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in fourLinkVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in fourLinkVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in fourLinkVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in fourLinkVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in fourLinkVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var fourlink = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = fourlink.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = fourlink.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = fourlink.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = fourlink.Caliber;
|
}
|
if (!input.MinorLoss.HasValue)
|
{
|
input.MatchingMinorLoss = fourlink.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//喷头匹配
|
public static bool Matching(HydroNozzleMatchingViewModel input, List<AssetsSprinklerMainVmo> sprinklerVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (sprinklerVmos == null || sprinklerVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsSprinklerMainVmo, double>();
|
foreach (var item in sprinklerVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in sprinklerVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in sprinklerVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in sprinklerVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in sprinklerVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in sprinklerVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var sprinkler = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = sprinkler.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = sprinkler.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = sprinkler.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = sprinkler.Caliber;
|
}
|
if (!input.MinorLoss.HasValue)
|
{
|
input.MatchingMinorLoss = sprinkler.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//换热器匹配
|
public static bool Matching(HydroExchangerMatchingViewModel input, List<Vmo.AssetsExchangerMainVmo> allExchangerList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allExchangerList == null || allExchangerList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsExchangerMainVmo, double>();
|
foreach (var item in allExchangerList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allExchangerList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in allExchangerList)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int diameterWeight = 1;
|
if (input.Diameter > 0)
|
{
|
foreach (var item in allExchangerList)
|
{
|
if (item.Diameter.HasValue)
|
{
|
var diff = Math.Abs(item.Diameter.Value - input.Diameter);
|
dict[item] += diff / input.Diameter * 100 * diameterWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allExchangerList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in allExchangerList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var exchanger = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = exchanger.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = exchanger.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = exchanger.Material;
|
}
|
if (input.Diameter <= 0)
|
{
|
if (exchanger.Diameter.HasValue)
|
{
|
input.MatchingDiameter = exchanger.Diameter.Value;
|
}
|
}
|
if (input.MinorLoss <= 0)
|
{
|
input.MatchingMinorLoss = exchanger.MinorLoss;
|
}
|
var relationList = Task.Run(async () =>
|
await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance
|
.GetExByObjectTypeAndObjectID(HStation.Assets.DataType.ExchangerMain, exchanger.ID)).Result;
|
if (relationList != null && relationList.Count > 0)
|
{
|
var relation = relationList.OrderBy(x => x.Importance).LastOrDefault();
|
input.MatchingCurveDbId = relation.ID.ToString();
|
var diagram = Task.Run(async () =>
|
await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.GetByID(relation.DiagramID)).Result;
|
if (diagram != null)
|
{
|
var graph = diagram.GraphList?.FirstOrDefault();
|
if (graph != null)
|
{
|
var pts = graph.GetFeatPointList();
|
input.MatchingCurveQL = pts?.Select(x => new HydroCurvePointViewModel(x.X, x.Y)).ToList();
|
}
|
}
|
}
|
return true;
|
}
|
|
//空压机匹配
|
public static bool Matching(HydroCompressorMatchingViewModel input, List<Vmo.AssetsCompressorMainVmo> allCompressorList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allCompressorList == null || allCompressorList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsCompressorMainVmo, double>();
|
foreach (var item in allCompressorList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allCompressorList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in allCompressorList)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int diameterWeight = 1;
|
if (input.Diameter > 0)
|
{
|
foreach (var item in allCompressorList)
|
{
|
if (item.Diameter.HasValue)
|
{
|
var diff = Math.Abs(item.Diameter.Value - input.Diameter);
|
dict[item] += diff / input.Diameter * 100 * diameterWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allCompressorList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in allCompressorList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var compressor = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = compressor.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = compressor.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = compressor.Material;
|
}
|
if (input.Diameter <= 0)
|
{
|
if (compressor.Diameter.HasValue)
|
{
|
input.MatchingDiameter = compressor.Diameter.Value;
|
}
|
}
|
if (input.MinorLoss <= 0)
|
{
|
input.MatchingMinorLoss = compressor.MinorLoss;
|
}
|
var relationList = Task.Run(async () =>
|
await BLLFactory<HStation.BLL.PhartDiagramRelation>.Instance
|
.GetExByObjectTypeAndObjectID(HStation.Assets.DataType.ExchangerMain, compressor.ID)).Result;
|
if (relationList != null && relationList.Count > 0)
|
{
|
var relation = relationList.OrderBy(x => x.Importance).LastOrDefault();
|
input.MatchingCurveDbId = relation.ID.ToString();
|
var diagram = Task.Run(async () =>
|
await BLLFactory<Yw.BLL.PhartDiagramExtensions>.Instance.GetByID(relation.DiagramID)).Result;
|
if (diagram != null)
|
{
|
var graph = diagram.GraphList?.FirstOrDefault();
|
if (graph != null)
|
{
|
var pts = graph.GetFeatPointList();
|
input.MatchingCurveQL = pts?.Select(x => new HydroCurvePointViewModel(x.X, x.Y)).ToList();
|
}
|
}
|
}
|
return true;
|
}
|
|
//闷头匹配
|
public static bool Matching(HydroBluntheadMatchingViewModel input, List<AssetsBluntheadMainVmo> bluntheadVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (bluntheadVmos == null || bluntheadVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsBluntheadMainVmo, double>();
|
foreach (var item in bluntheadVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in bluntheadVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in bluntheadVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in bluntheadVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in bluntheadVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in bluntheadVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var blunthead = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = blunthead.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = blunthead.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = blunthead.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = blunthead.Caliber;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = blunthead.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//水池匹配
|
public static bool Matching(HydroTankMatchingViewModel input, List<AssetsTankMainVmo> tankVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (tankVmos == null || tankVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsTankMainVmo, double>();
|
foreach (var item in tankVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in tankVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in tankVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in tankVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var tank = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = tank.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = tank.Name;
|
}
|
|
if (input.DN <= 0)
|
{
|
input.MatchingDN = tank.DN;
|
}
|
if (input.MinLevel <= 0)
|
{
|
input.MatchingMinLevel = tank.MinLevel;
|
}
|
input.MatchingOverFlow = tank.OverFlow;
|
if (input.MinVol <= 0)
|
{
|
input.MatchingMinVol = tank.MinVol;
|
}
|
if (input.MaxLevel <= 0)
|
{
|
input.MatchingMaxLevel = tank.MaxLevel;
|
}
|
if (input.CurveDbId == null)
|
{
|
var list = Task.Run(async () =>
|
await new BLL.PhartDiagramRelation().GetExByObjectTypeAndObjectID(HStation.Assets.DataType.TankMain, tank.ID)).Result;
|
if (list != null && list.Count > 0)
|
{
|
var def = list.OrderByDescending(x => x.Importance).First();
|
input.MatchingCurveDbId = def.ID.ToString();
|
var curve = def.Diagram.GraphList[0].GetFeatPointList();
|
input.MatchingVolCurve = new List<HydroCurvePointViewModel>();
|
foreach (var item in curve)
|
{
|
input.MatchingVolCurve.Add(new HydroCurvePointViewModel(item.X, item.Y));
|
}
|
}
|
}
|
return true;
|
}
|
|
//水表匹配
|
public static bool Matching(HydroMeterMatchingViewModel input, List<AssetsMeterMainVmo> allMeterList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allMeterList == null || allMeterList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsMeterMainVmo, double>();
|
foreach (var item in allMeterList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 100;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allMeterList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allMeterList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 10;
|
foreach (var item in allMeterList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var flowmeter = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = flowmeter.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = flowmeter.Name;
|
}
|
if (input.MinorLoss <= 0)
|
{
|
input.MatchingMinorLoss = flowmeter.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//流量计匹配
|
public static bool Matching(HydroFlowmeterMatchingViewModel input, List<Vmo.AssetsFlowmeterMainVmo> allFlowmeterList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allFlowmeterList == null || allFlowmeterList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsFlowmeterMainVmo, double>();
|
foreach (var item in allFlowmeterList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 100;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allFlowmeterList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allFlowmeterList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 10;
|
foreach (var item in allFlowmeterList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var flowmeter = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = flowmeter.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = flowmeter.Name;
|
}
|
if (input.MinorLoss <= 0)
|
{
|
input.MatchingMinorLoss = flowmeter.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//消火栓匹配
|
public static bool Matching(HydroHydrantMatchingViewModel input, List<AssetsHydrantMainVmo> hydrantVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (hydrantVmos == null || hydrantVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsHydrantMainVmo, double>();
|
foreach (var item in hydrantVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in hydrantVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in hydrantVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in hydrantVmos)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in hydrantVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in hydrantVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var hydrant = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = hydrant.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = hydrant.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = hydrant.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = hydrant.Caliber;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = hydrant.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//弯头匹配
|
public static bool Matching(HydroElbowMatchingViewModel input, List<Vmo.AssetsElbowMainVmo> allElbowList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allElbowList == null || allElbowList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsElbowMainVmo, double>();
|
foreach (var item in allElbowList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 100;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allElbowList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allElbowList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 10;
|
foreach (var item in allElbowList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var elbow = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = elbow.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = elbow.Name;
|
}
|
if (input.MinorLoss <= 0 || input.MinorLoss == null)
|
{
|
input.MatchingMinorLoss = elbow.MinorLoss;
|
}
|
if (input.BendingAngle <= 0 || input.BendingAngle == null)
|
{
|
input.MatchingBendingAngle = elbow.Angle;
|
}
|
input.MatchingElbowType = (Yw.WinFrmUI.eElbowType)(int)elbow.ElbowType;
|
if (input.Material == null || input.Material == string.Empty)
|
{
|
input.MatchingMaterial = elbow.Material;
|
}
|
if (!input.Caliber.HasValue)
|
input.MatchingCaliber = elbow.Caliber;
|
return true;
|
}
|
|
//压力表匹配
|
public static bool Matching(HydroPressmeterMatchingViewModel input, List<AssetsPressmeterMainVmo> pressmeterVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (pressmeterVmos == null || pressmeterVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsPressmeterMainVmo, double>();
|
foreach (var item in pressmeterVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in pressmeterVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in pressmeterVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in pressmeterVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var pressmeter = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = pressmeter.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = pressmeter.Name;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = pressmeter.MinorLoss;
|
}
|
|
return true;
|
}
|
|
//过渡件匹配
|
public static bool Matching(HydroTranslationMatchingViewModel input, List<AssetsTranslationMainVmo> translationVmos)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (translationVmos == null || translationVmos.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsTranslationMainVmo, double>();
|
foreach (var item in translationVmos)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in translationVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in translationVmos)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in translationVmos)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in translationVmos)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var translation = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = translation.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = translation.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = translation.Material;
|
}
|
if (input.MinorLoss < 0)
|
{
|
input.MatchingMinorLoss = translation.MinorLoss;
|
}
|
if (input.Roughness < 0)
|
{
|
input.MatchingRoughness = translation.Roughness;
|
}
|
if (input.EndDiameter < 0)
|
{
|
input.MatchingEndDiameter = translation.EndDiameter;
|
}
|
if (input.StartDiameter < 0)
|
{
|
input.MatchingStartDiameter = translation.StartDiameter;
|
}
|
if (input.Diameter < 0)
|
{
|
input.MatchingDiameter = translation.Diameter;
|
}
|
|
return true;
|
}
|
|
//冷却器匹配
|
public static bool Matching(HydroCoolingMatchingViewModel input, List<AssetsCoolingMainVmo> allCoolingList)
|
{
|
//输入参数验证
|
if (input == null)
|
{
|
return false;
|
}
|
|
//数据源没有数据则没有匹配成功
|
if (allCoolingList == null || allCoolingList.Count < 1)
|
{
|
return false;
|
}
|
|
//权重字典
|
var dict = new Dictionary<AssetsCoolingMainVmo, double>();
|
foreach (var item in allCoolingList)
|
{
|
dict.Add(item, 0);
|
}
|
|
//型号
|
int modelTypeWeight = 10;
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
foreach (var item in allCoolingList)
|
{
|
if (!string.IsNullOrEmpty(item.Name))
|
{
|
var count = item.Name.ToLower().Intersect(input.ModelType.ToLower()).Count();
|
dict[item] += count * modelTypeWeight;
|
}
|
}
|
}
|
|
//材质
|
int materialWeight = 5;
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
foreach (var item in allCoolingList)
|
{
|
if (!string.IsNullOrEmpty(item.Material))
|
{
|
var count = item.Material.ToLower().Intersect(input.Material.ToLower()).Count();
|
dict[item] += count * materialWeight;
|
}
|
}
|
}
|
|
//口径
|
int caliberWeight = 1;
|
if (input.Caliber.HasValue)
|
{
|
foreach (var item in allCoolingList)
|
{
|
if (item.Caliber.HasValue)
|
{
|
var diff = Math.Abs(item.Caliber.Value - input.Caliber.Value);
|
dict[item] += diff / input.Caliber.Value * 100 * caliberWeight;
|
}
|
}
|
}
|
|
// 关键字
|
int keywordWeight = 1;
|
foreach (var item in allCoolingList)
|
{
|
if (item.KeyWords != null && item.KeyWords.Count > 0)
|
{
|
if (!string.IsNullOrEmpty(input.ModelType))
|
{
|
var count = item.KeyWords.Count(x => input.ModelType.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
if (!string.IsNullOrEmpty(input.Material))
|
{
|
var count = item.KeyWords.Count(x => input.Material.ToLower().Contains(x.ToLower()));
|
dict[item] += count * keywordWeight;
|
}
|
}
|
}
|
|
//标签
|
int flagWeight = 1;
|
foreach (var item in allCoolingList)
|
{
|
if (item.Flags != null && item.Flags.Count > 0)
|
{
|
if (item.Flags.Contains(HStation.Assets.Flags.默认))
|
{
|
dict[item] += flagWeight;
|
}
|
}
|
}
|
|
var cooling = dict.OrderBy(x => x.Value).LastOrDefault().Key;
|
input.MatchingDbId = cooling.ID.ToString();
|
if (string.IsNullOrEmpty(input.ModelType))
|
{
|
input.MatchingModelType = cooling.Name;
|
}
|
if (string.IsNullOrEmpty(input.Material))
|
{
|
input.MatchingMaterial = cooling.Material;
|
}
|
if (!input.Caliber.HasValue || input.Caliber.Value <= 0)
|
{
|
input.Caliber = cooling.Caliber;
|
}
|
if (input.Coefficient <= 1)
|
{
|
input.MatchingCoefficient = cooling.Coefficient;
|
}
|
if (input.LowerLimit <= 0)
|
{
|
input.MatchingLowerLimit = cooling.LowerLimit;
|
}
|
|
return true;
|
}
|
|
/// <summary>
|
/// 获取两个字符串的所有交集
|
/// </summary>
|
public static int GetIntersect(string str1, string str2)
|
{
|
if (str1 == null || str2 == null) return 0;
|
return string.Join("", str1.Intersect(str2)).Count();
|
}
|
}
|
}
|