ningshuxia
2025-03-13 982cde7e9372dc218f23b204265d8e54f7e9ce4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
namespace Yw.WinFrmUI
{
    /// <summary>
    /// 
    /// </summary>
    public class HydroLossStatisticsCategoryHelper
    {
        /// <summary>
        /// 创建
        /// </summary>
        public static HydroLossStatisticsCategoryViewModel Create
            (
                Yw.Model.HydroModelInfo hydroInfo,
                HydroCalcuResult calcuResult,
                List<HydroLossStatisticsItemViewModel> allItemList
            )
        {
            if (hydroInfo == null)
            {
                return default;
            }
            if (calcuResult == null || !calcuResult.Succeed)
            {
                return default;
            }
            if (allItemList == null || allItemList.Count < 1)
            {
                return default;
            }
 
            var vm = new HydroLossStatisticsCategoryViewModel();
            vm.Items = new List<HydroLossStatisticsCategoryItemViewModel>();
 
            var groupList = allItemList.GroupBy(x => x.EnergyType).OrderBy(x => x.Key).ToList();
            foreach (var group in groupList)
            {
                var item = new HydroLossStatisticsCategoryItemViewModel();
                item.EnergyType = group.Key;
                item.EnergyName = group.Key.GetDisplayText();
                item.EnergyValue = group.Sum(x => x.EnergyValue);
                vm.Items.Add(item);
            }
 
            double pumpLoss = 0;
            if (hydroInfo.Pumps != null && hydroInfo.Pumps.Count > 0)
            {
                var allCalcuVisualDict = calcuResult.GetVisualDict();
                foreach (var pump in hydroInfo.Pumps)
                {
                    var calcuPumpResult = allCalcuVisualDict?.GetValue(pump.Code) as HydroCalcuPumpResult;
                    if (calcuPumpResult != null)
                    {
                        if (calcuPumpResult.CalcuP.HasValue && calcuPumpResult.CalcuE.HasValue)
                        {
                            pumpLoss += calcuPumpResult.CalcuP.Value * 1000 * (1 - calcuPumpResult.CalcuE.Value / 100);
                        }
                    }
                }
            }
 
            var promoteItem = vm.Items.Find(x => x.EnergyType == eEnergyType.Promote);
            if (promoteItem != null)
            {
                promoteItem.EnergyValue += pumpLoss;
            }
 
            var minorLossItem = vm.Items.Find(x => x.EnergyType == Yw.WinFrmUI.eEnergyType.MinorLoss);
            if (minorLossItem != null)
            {
                minorLossItem.EnergyValue += pumpLoss;
            }
 
            //w=>kW
            vm.Items.ForEach(x => x.EnergyValue = Math.Round(x.EnergyValue / 1000d, 1));
 
            return vm;
 
        }
 
    }
}