You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
2.2 KiB

7 months ago
using log4net;
using SqlSugar;
namespace ConsoleStarter;
public class ExportDb
{
private static readonly ILog Log = LogManager.GetLogger(typeof(ExportDb));
6 months ago
private static readonly string[] UsedTable =
7 months ago
{
6 months ago
"equip_alarm_define",
"equip_alarm_record",
"equip_alarm_process_record"
7 months ago
};
6 months ago
private readonly SqlSugarClient Db = new(new ConnectionConfig
{
ConnectionString =
6 months ago
"server=180.76.133.253;Port=16306;Database=huanneng_dev;Uid=root;Pwd=Rszn123;Charset=utf8;",
6 months ago
DbType = DbType.MySql,
IsAutoCloseConnection = true,
InitKeyType = InitKeyType.Attribute
});
7 months ago
public void Export()
{
List<DbTableInfo> tableInfoList = Db.DbMaintenance.GetTableInfoList(false);
6 months ago
foreach (var tableInfo in tableInfoList)
7 months ago
if (UsedTable.Contains(tableInfo.Name))
{
Log.Info($"{tableInfo.Name}:{tableInfo.Description}");
List<DbColumnInfo> columnInfos = Db.DbMaintenance.GetColumnInfosByTableName(tableInfo.Name, false);
6 months ago
foreach (var columnInfo in columnInfos)
7 months ago
Log.Info($" {columnInfo.DbColumnName}:{columnInfo.ColumnDescription}");
}
6 months ago
Db.DbFirst
.Where(it => UsedTable.Contains(it))
.IsCreateAttribute() //创建sqlsugar自带特性
.FormatFileName(ToPascalCase) //格式化文件名(文件名和表名不一样情况)
.FormatClassName(ToPascalCase) //格式化类名 (类名和表名不一样的情况)
.FormatPropertyName(ToPascalCase) //格式化属性名 (属性名和字段名不一样情况)
.CreateClassFile("D:\\RiderProjects\\hn_back_main\\Entity\\DbModel\\Station",
"Entity.DbModel.Station");
}
static string ToPascalCase(string input)
{
if (string.IsNullOrEmpty(input))
return input;
string[] strings = input.Split("_");
string res = "";
foreach (var s in strings)
{
string first = s.First().ToString().ToUpper();
string te = first + s.Substring(1);
res += te;
}
return res;
7 months ago
}
6 months ago
}