using System.Threading.Tasks;
|
using System.Xml.Linq;
|
|
namespace IStation.DAL
|
{
|
/// <summary>
|
///
|
/// </summary>
|
public class ScheduleCombine
|
{
|
public SqlSugarClient Connection
|
{
|
get { return ConfigHelper.GetSqlSugarClient(); }
|
}
|
|
/// <summary>
|
/// 获取全部表名
|
/// </summary>
|
public List<string> GetAllTableName()
|
{
|
var tables = new List<string>();
|
using (var connection = new SQLiteConnection(ConfigHelper.ConnectionString))
|
{
|
connection.Open();
|
string query = "SELECT name FROM sqlite_master WHERE type='table';";
|
using (var command = new SQLiteCommand(query, connection))
|
{
|
using (var reader = command.ExecuteReader())
|
{
|
while (reader.Read())
|
{
|
var tableName = reader["name"].ToString();
|
if (!tableName.Contains("_Cb_"))
|
continue;
|
tables.Add(tableName);
|
}
|
}
|
}
|
}
|
|
return tables;
|
}
|
|
/// <summary>
|
/// 通过表名获取所有未分析组合
|
/// </summary>
|
public List<Entity.ScheduleCombine> GetAllUnanalyzedAnaByTableName(string tableName)
|
{
|
using (SqlSugarClient db = Connection)
|
{
|
var sql = $"select * from {tableName} where AnaStatus=False";
|
var list = db.Ado.SqlQuery<Entity.ScheduleCombine>(sql);
|
return list;
|
}
|
}
|
|
|
/// <summary>
|
/// 大批量插入
|
/// </summary>
|
public bool BulkInserts_SplitTable(List<Entity.ScheduleCombine> list)
|
{
|
if (list == null || list.Count < 1)
|
return default;
|
using (SqlSugarClient db = Connection)
|
{
|
///自己来制定定义的规则
|
db.CurrentConnectionConfig.ConfigureExternalServices.SplitTableService = new Entity.ScheduleCombineSubTableService();
|
db.CodeFirst
|
.SplitTables()//标识分表
|
.InitTables<Entity.ScheduleCombine>(); //程序启动时加这一行,如果一张表没有会初始化一张
|
|
|
//大数据写入+表不存在会建表
|
//自动找表大数据写入
|
return db.Fastest<Entity.ScheduleCombine>().SplitTable().BulkCopy(list) > 0;
|
}
|
}
|
|
/// <summary>
|
/// 设置已分析状态
|
/// </summary>
|
public bool SetAnaStatus(string tableName, long id)
|
{
|
using (SqlSugarClient db = Connection)
|
{
|
var sql = $"update {tableName} set AnaStatus=True where ID={id}";
|
var bol = db.Ado.ExecuteCommand(sql) > 0;
|
return bol;
|
}
|
}
|
|
|
/// <summary>
|
/// 设置已分析状态
|
/// </summary>
|
public bool SetAnaStatus(string tableName, List<long> ids)
|
{
|
using (SqlSugarClient db = Connection)
|
{
|
db.BeginTran();
|
var sql = $"update {tableName} set AnaStatus=True where ID in(@ids)";
|
var obj = new { ids = ids.ToArray() };
|
var bol = db.Ado.ExecuteCommand(sql, obj) > 0;
|
return bol;
|
}
|
}
|
|
|
/// <summary>
|
/// 判断数据库是否存在表
|
/// </summary>
|
public bool ExistTable(string runFlag)
|
{
|
using (SqlSugarClient db = Connection)
|
{
|
var sql = $"select count(*) from sqlite_master where type = 'table' and name = 'ScheduleCombine_Cb_{runFlag}';";
|
var bol = db.Ado.ExecuteCommand(sql) > 0;
|
return bol;
|
}
|
}
|
|
|
}
|
}
|