Shuxia Ning
2024-11-06 adf8dc1c7cae1b12f486dcdb3d7daf4a5a59ec52
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
namespace IStation.DAL.SQLite
{
    /// <summary>
    /// 能效(多)实时记录
    /// </summary>
    public class EtaMultiRealRecord :  IEtaMultiRealRecord
    {
        /// <summary>
        /// 
        /// </summary>
        public ConnectionConfig ConnectionConfig
        {
            get
            {
                var dbName = "eta.db";
                var filePath = $"{Settings.ParasHelper.LocalFile.DataFolderDirectory}\\{dbName}";
                var config = new ConnectionConfig
                {
                    DbType = SqlSugar.DbType.Sqlite,//数据库类型
                    ConnectionString = $"DataSource={filePath}",
                    IsAutoCloseConnection = true,//是否自动关闭
                    MoreSettings = new ConnMoreSettings()
                    {
                        //PgSqlIsAutoToLower = false //数据库存在大写字段的 ,需要把这个设为false ,并且实体和字段名称要一样
                    },
                    AopEvents = new AopEvents
                    {
                        OnLogExecuting = (sql, p) =>
                        {
                            var sqlString = UtilMethods.GetNativeSql(sql, p);
                        }
                    },
                    ConfigureExternalServices = new ConfigureExternalServices()
                    {
                        EntityService = (property, column) =>
                        {
                            //除主键外都可空
                            if (!column.IsPrimarykey)
                            {
                                column.IsNullable = true;
                            }
                        }
                    }
                };
                return config;
            }
        }
         
 
 
        /// <summary>
        ///  通过 ObjectType 和 ObjectID 获取流量、扬程、日期区间内运行的汇总内容数据
        /// </summary>
        public List<Entity.EtaMultiRunSummaryContent> GetRunSummaryContentByStationOfQHDayRange(int Station, double Qmin, double Qmax, double Hmin, double Hmax, DateTime StartDay, DateTime EndDay)
        {
            //判断流量
            if (Qmin > Qmax)
            {
                return default;
            }
            //判断扬程
            if (Hmin > Hmax)
            {
                return default;
            }
            //判断日期
            if (StartDay.Date > EndDay.Date)
            {
                return default;
            }
 
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Entity.EtaMultiRealRecord>()
                            .GroupBy(x => new { x.Station, x.RunningCount, x.RunningFlag })
                            .Where(x => x.DataTime >= StartDay.Date && x.DataTime < EndDay.Date.AddDays(1))
                            .Where(x => x.Station == Station)
                            .Where(x => x.RunningCount > 0)
                            .Where(x => SqlFunc.Between(x.Qa, Qmin, Qmax))
                            .Where(x => SqlFunc.Between(x.Ha, Hmin, Hmax))
                            .Select(x => new Entity.EtaMultiRunSummaryContent()
                            {
                                Station = x.Station,
                                RunningCount = x.RunningCount,
                                RunningFlag = x.RunningFlag,
                                Qavg = SqlFunc.AggregateAvg(x.Qa.Value),
                                Havg = SqlFunc.AggregateAvg(x.Ha.Value),
                                Pavg = SqlFunc.AggregateAvg(x.Pa.Value),
                                Eavg = SqlFunc.AggregateAvg(x.Ea.Value),
                                Tsum = SqlFunc.AggregateSum(x.Duration)
                            }).ToList();
            }
 
        }
 
 
 
        /// <summary>
        /// 通过 ObjectType 和 ObjectID 获取时间区间内的运行QHET
        /// </summary>
        public List<Entity.EtaQHET> GetRunQHETByStationOfDayRange(int Station, DateTime StartDay, DateTime EndDay)
        {
            //判断日期
            if (StartDay.Date > EndDay.Date)
            {
                return default;
            }
 
            using (var db = new SqlSugarClient(ConnectionConfig))
            {
                return db.Queryable<Model.EtaMultiRealRecord>()
                            .Where(x => x.DataTime >= StartDay.Date && x.DataTime < EndDay.Date.AddDays(1))
                            .Where(x => x.Station == Station)
                            .Where(x => x.RunningCount > 0)
                            .Select(x => new Entity.EtaQHET() { Q = x.Qa.Value, H = x.Ha.Value, E = x.Ea.Value, T = x.Duration }).ToList();
            }
        }
 
 
 
    }
}