1 Star 0 Fork 16

青侠oO/SmartCode

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
AbstractDbBuildTask.cs 3.22 KB
一键复制 编辑 原始数据 按行查看 历史
using Microsoft.Extensions.Logging;
using SmartCode.Configuration;
using SmartCode.Generator.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmartCode.Generator.BuildTasks
{
public abstract class AbstractDbBuildTask : IBuildTask
{
private readonly ILogger _logger;
public AbstractDbBuildTask(string name, ILogger logger)
{
Name = name;
_logger = logger;
}
public bool Initialized { get; protected set; }
public string Name { get; protected set; }
public abstract Task Build(BuildContext context);
public virtual void Initialize(IDictionary<string, object> parameters)
{
this.Initialized = true;
}
protected IList<Table> FilterTable(IEnumerable<Table> tables, string buildKey, Build build)
{
_logger.LogInformation($"FilterTable Build:{buildKey} Start!");
IEnumerable<Table> buildTables = CopyTables(tables);
if (build.IgnoreNoPKTable.HasValue && build.IgnoreNoPKTable.Value)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreNoPKTable!");
buildTables = buildTables.Where(m => m.PKColumn != null);
}
if (build.IgnoreView.HasValue && build.IgnoreView.Value)
{
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreView!");
buildTables = buildTables.Where(m => m.Type != Table.TableType.View);
}
if (build.IgnoreTables != null)
{
_logger.LogInformation(
$"FilterTable Build:{buildKey} IgnoreTables: [{String.Join(",", build.IgnoreTables)}]!");
buildTables = buildTables.Where(m => !build.IgnoreTables.Contains(m.Name));
}
if (build.IncludeTables != null)
{
_logger.LogInformation(
$"FilterTable Build:{buildKey} IncludeTables: [{String.Join(",", build.IncludeTables)}]!");
buildTables = buildTables.Where(m => build.IncludeTables.Contains(m.Name));
}
_logger.LogInformation($"FilterTable Build:{buildKey} End!");
return buildTables.ToList();
}
protected IList<Table> CopyTables(IEnumerable<Table> tables)
{
return tables.Select(m => new Table
{
Id = m.Id,
Name = m.Name,
TypeName = m.TypeName,
ConvertedName = m.ConvertedName,
Description = m.Description,
Columns = m.Columns.Select(c => new Column
{
Id = c.Id,
Name = c.Name,
DbType = c.DbType,
Description = c.Description,
AutoIncrement = c.AutoIncrement,
ConvertedName = c.ConvertedName,
IsNullable = c.IsNullable,
IsPrimaryKey = c.IsPrimaryKey,
LanguageType = c.LanguageType,
DataLength = c.DataLength
}).ToList()
}).ToList();
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/MuNet/SmartCode.git
git@gitee.com:MuNet/SmartCode.git
MuNet
SmartCode
SmartCode
master

搜索帮助