From b50a06a3185619c4cbbc521ab026f1bfa4d13aae Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期二, 30 四月 2024 11:13:08 +0800 Subject: [PATCH] 调度 --- Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs | 68 ++++++++++++++++++++++++--------- 1 files changed, 49 insertions(+), 19 deletions(-) diff --git a/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs b/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs index c101ab8..fb0e762 100644 --- a/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs +++ b/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs @@ -17,6 +17,8 @@ return $"{_tableNamePrefix}{runFlag}"; } + #region Table + /// <summary> /// 鑾峰彇鍏ㄩ儴琛ㄥ悕 /// </summary> @@ -50,11 +52,10 @@ using (SqlSugarClient db = Connection) { var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{GetTableName(runFlag)}';"; - var bol = db.Ado.ExecuteCommand(sql) > 0; + var bol = db.Ado.GetInt(sql) > 0; return bol; } } - /// <summary> /// 鏁版嵁搴撳垱寤鸿〃 @@ -65,13 +66,41 @@ { var tableName = GetTableName(runFlag); var sql_exist = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; - if (db.Ado.ExecuteCommand(sql_exist) > 0) + if (db.Ado.GetInt(sql_exist) > 0) return true; var sql_create_table = $"CREATE TABLE {tableName} (\r\n ID BIGINT NOT NULL\r\n PRIMARY KEY,\r\n ScheduleCombineID BIGINT,\r\n RunFlag VARCHAR (255),\r\n Pump1 REAL,\r\n Pump2 REAL,\r\n Pump3 REAL,\r\n Head REAL,\r\n Flow REAL,\r\n Power REAL,\r\n WP REAL,\r\n UWP REAL\r\n);"; var bol = db.Ado.ExecuteCommand(sql_create_table) > 0; return bol; } } + + /// <summary> + // 鍒犻櫎鎵�鏈夎〃 + /// </summary> + public bool DeleteAllTable() + { + var tables = GetAllTableName(); + if (tables == null || !tables.Any()) + return false; + + using (SqlSugarClient db = Connection) + { + db.BeginTran(); + + foreach (var table in tables) + { + var sql = $"drop table {table};"; + db.Ado.ExecuteCommand(sql); + } + db.CommitTran(); + } + return true; + } + + + #endregion + + #region BulkInserts /// <summary> /// 澶ф壒閲忔彃鍏� @@ -131,7 +160,6 @@ } } - /// <summary> /// 澶ф壒閲忔彃鍏� /// </summary> @@ -152,8 +180,6 @@ return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; } } - - /// <summary> /// 澶ф壒閲忔彃鍏� @@ -193,28 +219,32 @@ return true; } + #endregion + + /// <summary> - /// 鑾峰彇鍏ㄩ儴琛ㄥ悕 + /// 澶ф壒閲忔彃鍏� /// </summary> - public bool DeleteAllTable() + public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetFlow, double targetHead, int takeCount) { - var tables = GetAllTableName(); - if (tables == null || !tables.Any()) - return false; - + var tableName = GetTableName(runFlag); using (SqlSugarClient db = Connection) { - db.BeginTran(); - - foreach (var table in tables) + var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; + if (db.Ado.GetInt(sql) < 1) { - var sql = $"drop table {table};"; - db.Ado.ExecuteCommand(sql); + return default; } - db.CommitTran(); + var list = db.Queryable<Entity.ScheduleConclusion>().AS(tableName) + .Where(x => x.Head >= targetHead && x.Head <= targetHead * 1.01 && x.Flow > targetFlow) + .OrderBy(x => x.Power) + .Take(takeCount) + .ToList(); + return list; } - return true; + + } } -- Gitblit v1.9.3