From d63b83c2c745c1f8a140221c28c0e6dbe61d6110 Mon Sep 17 00:00:00 2001 From: ningshuxia <ningshuxia0927@outlook.com> Date: 星期二, 30 四月 2024 17:47:17 +0800 Subject: [PATCH] 调度修改 --- Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs | 148 ++++++++++++++++++++++++++++++++++++------------- 1 files changed, 108 insertions(+), 40 deletions(-) diff --git a/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs b/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs index f41ae35..f1c8372 100644 --- a/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs +++ b/Schedule/IStation.Algorithm/DAL/ScheduleConclusion.cs @@ -1,7 +1,4 @@ -锘縰sing MathNet.Numerics.Distributions; -using System.Collections.Generic; - -namespace IStation.DAL +锘縩amespace IStation.DAL { /// <summary> /// @@ -19,6 +16,8 @@ { return $"{_tableNamePrefix}{runFlag}"; } + + #region Table /// <summary> /// 鑾峰彇鍏ㄩ儴琛ㄥ悕 @@ -53,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> /// 鏁版嵁搴撳垱寤鸿〃 @@ -68,7 +66,7 @@ { 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; @@ -76,7 +74,70 @@ } } + /// <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> + /// 澶ф壒閲忔彃鍏� + /// </summary> + public bool BulkInserts(string runFlag, List<Entity.ScheduleConclusion> list) + { + if (list == null || list.Count < 1) + return default; + var tableName = GetTableName(runFlag); + using (SqlSugarClient db = Connection) + { + return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; + } + } + + /// <summary> + /// 澶ф壒閲忔彃鍏� + /// </summary> + public async Task<bool> BulkInserts_Create_Async(string runFlag, List<Entity.ScheduleConclusion> list) + { + if (list == null || list.Count < 1) + return default; + var tableName = GetTableName(runFlag); + using (SqlSugarClient db = Connection) + { + var exist_sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}' ;"; + if (db.Ado.GetInt(exist_sql) < 1) + { + 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);"; + if (db.Ado.ExecuteCommand(sql_create_table) < 1) + { + return false; + } + } + return await db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopyAsync(list) > 0; + } + } /// <summary> /// 澶ф壒閲忔彃鍏� @@ -102,7 +163,7 @@ /// <summary> /// 澶ф壒閲忔彃鍏� /// </summary> - public bool BulkInserts_SplitTable_Create(string runFlag, List<Entity.ScheduleConclusion> list) + public bool BulkInserts_Create(string runFlag, List<Entity.ScheduleConclusion> list) { if (list == null || list.Count < 1) return default; @@ -113,30 +174,12 @@ if (db.Ado.GetInt(exist_sql) < 1) { 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);"; - if (db.Ado.ExecuteCommand(sql_create_table) < 1) - { - return false; - } + db.Ado.ExecuteCommand(sql_create_table); } //澶ф暟鎹啓鍏� return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; } } - - /// <summary> - /// 澶ф壒閲忔彃鍏� - /// </summary> - public bool BulkInserts(string runFlag, List<Entity.ScheduleConclusion> list) - { - if (list == null || list.Count < 1) - return default; - var tableName = GetTableName(runFlag); - using (SqlSugarClient db = Connection) - { - return db.Fastest<Entity.ScheduleConclusion>().AS(tableName).BulkCopy(list) > 0; - } - } - /// <summary> /// 澶ф壒閲忔彃鍏� @@ -176,28 +219,53 @@ return true; } + #endregion + + /// <summary> - /// 鑾峰彇鍏ㄩ儴琛ㄥ悕 + /// 鏌ヨ /// </summary> - public bool DeleteAllTable() + public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetHead) { - 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) + .OrderBy(x => x.Power) + .ToList(); + return list; } - return true; + + } + + /// <summary> + /// 鏌ヨ + /// </summary> + public List<Entity.ScheduleConclusion> GetList(string runFlag, double targetFlow, double targetHead, int takeCount) + { + var tableName = GetTableName(runFlag); + using (SqlSugarClient db = Connection) + { + var sql = $"select count(*) from sqlite_master where type = 'table' and name = '{tableName}';"; + if (db.Ado.GetInt(sql) < 1) + { + return default; + } + 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; + } + } } -- Gitblit v1.9.3