using djy.Paas.Model;
using FreeRedis;
using FreeRedis.Internal;
using FreeSql;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Ys.Core.Common;
namespace djy.Paas.Service
{
///
/// 数据库结构体
///
public static class DbList
{
///
///独立的大简云publice库
///
public const string djypublicedb = "djydb";
///
///大简云平台老库
///
public const string djyolddb = "djyolddb";
///
/// 账单中心库
///
public const string BillCenter = "billcenter";
///
/// 日志库
///
public const string Logsdb = "logsdb";
}
///
/// 数据库操作类
///
public class DbContext
{
///
/// 数据库连接池
///
public static IdleBus DbBus=new IdleBus(TimeSpan.FromSeconds(20));
//public static IFreeSql DbBus.Get(DbList.djypublicedb);
///
/// RedisDB
///
public static RedisClient DbRedis = new RedisClient(string.Format("{0}", sysOptionConfig.YsWebconfig.Redis));
///
/// 数据库连接池初始化
///
///
public static bool DbBusInit() {
foreach (var item in sysOptionConfig.YsWebconfig.DataConnList)
{
if (item.SysKey == DbList.Logsdb)//日志库允许自动更新表结构
{
DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString)
.UseAutoSyncStructure(true)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd =>
{
Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText);
})
.Build());
}
else
{
DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString)
// .UseAutoSyncStructure(sysOptionConfig.YsWebconfig.IsDev)
.UseAutoSyncStructure(false)
.UseNoneCommandParameter(true)
.UseMonitorCommand(cmd =>
{
Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText);
})
.Build());
}
}
return true;
}
///
/// 数据库初始化
///
public static ReturnResult DbInit()
{
var rs = new ReturnResult();
DbBus.Get(DbList.djypublicedb).CodeFirst.SyncStructure();
DbBus.Get(DbList.djypublicedb).CodeFirst.SyncStructure();
rs.OK("生成成功!");
return rs;
}
}
}