Skip to content

Commit 24ea67c

Browse files
committed
add support global default TableFilter -> fix #32
``` yml TableFilter: IgnoreNoPKTable: true IgnoreView: true ```
1 parent 787184f commit 24ea67c

File tree

7 files changed

+56
-17
lines changed

7 files changed

+56
-17
lines changed

build/version.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<PropertyGroup>
33
<VersionMajor>2</VersionMajor>
44
<VersionMinor>2</VersionMinor>
5-
<VersionPatch>50</VersionPatch>
5+
<VersionPatch>52</VersionPatch>
66
<VersionPrefix>$(VersionMajor).$(VersionMinor).$(VersionPatch)</VersionPrefix>
77
</PropertyGroup>
88
</Project>

doc/SmartCode.yml

+7-9
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Output:
1414
Type: File
1515
Path: 'E:\SmartSql-Starter'
1616
Parameters:
17-
SmartSqlVersion: '4.0.56'
17+
SmartSqlVersion: '4.0.58'
1818
SmartSqlSchemaVersion: '4.0.42'
1919
BuildDir: 'E:\SmartSql-Starter\build'
2020
DockerImage: 'smartsql.starter'
@@ -44,6 +44,10 @@ NamingConverter:
4444
Delimiter: '_'
4545
Converter:
4646
Type: Pascal
47+
48+
TableFilter:
49+
IgnoreNoPKTable: true
50+
IgnoreView: true
4751

4852
# 构建任务
4953
Build:
@@ -101,6 +105,8 @@ Build:
101105
Module: Entity
102106
TemplateEngine:
103107
Path: Entity.cshtml
108+
IgnoreNoPKTable: false
109+
IgnoreView: false
104110
Output:
105111
Path: 'src/{{Project.Module}}.{{Build.Module}}'
106112
Name: '{{Items.CurrentTable.ConvertedName}}'
@@ -111,8 +117,6 @@ Build:
111117
Module: Repository
112118
TemplateEngine:
113119
Path: Repository.cshtml
114-
IgnoreNoPKTable: true
115-
IgnoreView: true
116120
Output:
117121
Path: 'src/{{Project.Module}}.{{Build.Module}}'
118122
Name: 'I{{Items.CurrentTable.ConvertedName}}Repository'
@@ -123,8 +127,6 @@ Build:
123127
Module: Service
124128
TemplateEngine:
125129
Path: Service.cshtml
126-
IgnoreNoPKTable: true
127-
IgnoreView: true
128130
Output:
129131
Path: 'src/{{Project.Module}}.{{Build.Module}}'
130132
Name: '{{Items.CurrentTable.ConvertedName}}Service'
@@ -135,8 +137,6 @@ Build:
135137
Module: API
136138
TemplateEngine:
137139
Path: API/APIController.cshtml
138-
IgnoreNoPKTable: true
139-
IgnoreView: true
140140
Output:
141141
Path: 'src/{{Project.Module}}.{{Build.Module}}/Controllers'
142142
Name: '{{Items.CurrentTable.ConvertedName}}Controller'
@@ -150,8 +150,6 @@ Build:
150150
Path: 'src/{{Project.Module}}.Repository/Maps'
151151
Name: '{{Items.CurrentTable.ConvertedName}}'
152152
Extension: .xml
153-
IgnoreNoPKTable: true
154-
IgnoreView: true
155153

156154
# Please install dotnet-format first!
157155
# dotnet tool install -g dotnet-format

src/SmartCode.Generator/BuildTasks/AbstractDbBuildTask.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,32 @@ protected IList<Table> FilterTable(IEnumerable<Table> tables, string buildKey, B
3434
{
3535
_logger.LogInformation($"FilterTable Build:{buildKey} Start!");
3636
IEnumerable<Table> buildTables = CopyTables(tables);
37-
if (build.IgnoreNoPKTable)
37+
if (build.IgnoreNoPKTable.HasValue && build.IgnoreNoPKTable.Value)
3838
{
3939
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreNoPKTable!");
4040
buildTables = buildTables.Where(m => m.PKColumn != null);
4141
}
42-
if (build.IgnoreView)
42+
43+
if (build.IgnoreView.HasValue && build.IgnoreView.Value)
4344
{
4445
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreView!");
4546
buildTables = buildTables.Where(m => m.Type != Table.TableType.View);
4647
}
48+
4749
if (build.IgnoreTables != null)
4850
{
49-
_logger.LogInformation($"FilterTable Build:{buildKey} IgnoreTables: [{String.Join(",", build.IgnoreTables)}]!");
51+
_logger.LogInformation(
52+
$"FilterTable Build:{buildKey} IgnoreTables: [{String.Join(",", build.IgnoreTables)}]!");
5053
buildTables = buildTables.Where(m => !build.IgnoreTables.Contains(m.Name));
5154
}
55+
5256
if (build.IncludeTables != null)
5357
{
54-
_logger.LogInformation($"FilterTable Build:{buildKey} IncludeTables: [{String.Join(",", build.IncludeTables)}]!");
58+
_logger.LogInformation(
59+
$"FilterTable Build:{buildKey} IncludeTables: [{String.Join(",", build.IncludeTables)}]!");
5560
buildTables = buildTables.Where(m => build.IncludeTables.Contains(m.Name));
5661
}
62+
5763
_logger.LogInformation($"FilterTable Build:{buildKey} End!");
5864
return buildTables.ToList();
5965
}
@@ -83,4 +89,4 @@ protected IList<Table> CopyTables(IEnumerable<Table> tables)
8389
}).ToList();
8490
}
8591
}
86-
}
92+
}

src/SmartCode/Configuration/Build.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Text;
45

56
namespace SmartCode.Configuration
@@ -16,8 +17,8 @@ public class Build
1617
public Output Output { get; set; }
1718
public IEnumerable<String> IncludeTables { get; set; }
1819
public IEnumerable<String> IgnoreTables { get; set; }
19-
public bool IgnoreNoPKTable { get; set; }
20-
public bool IgnoreView { get; set; }
20+
public bool? IgnoreNoPKTable { get; set; }
21+
public bool? IgnoreView { get; set; }
2122
public NamingConverter NamingConverter { get; set; }
2223
/// <summary>
2324
/// 自定义构建参数

src/SmartCode/Configuration/ConfigBuilders/ConfigBuilder.cs

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,26 @@ protected void InitDefault()
8888
buildTask.NamingConverter.Column = Project.NamingConverter.Column;
8989
}
9090
}
91+
92+
if (Project.TableFilter != null)
93+
{
94+
if (buildTask.IgnoreTables == null)
95+
{
96+
buildTask.IgnoreTables = Project.TableFilter.IgnoreTables;
97+
}
98+
if (buildTask.IncludeTables == null)
99+
{
100+
buildTask.IncludeTables = Project.TableFilter.IncludeTables;
101+
}
102+
if (!buildTask.IgnoreView.HasValue)
103+
{
104+
buildTask.IgnoreView = Project.TableFilter.IgnoreView;
105+
}
106+
if (!buildTask.IgnoreNoPKTable.HasValue)
107+
{
108+
buildTask.IgnoreNoPKTable = Project.TableFilter.IgnoreNoPKTable;
109+
}
110+
}
91111
}
92112
}
93113
}

src/SmartCode/Configuration/Project.cs

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ public class Project
2020
public IDictionary<string, Build> BuildTasks { get; set; }
2121
public String OutputPath => Output.Path;
2222
public NamingConverter NamingConverter { get; set; }
23+
public TableFilter TableFilter { get; set; }
2324
}
2425
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
using System.Collections.Generic;
3+
4+
namespace SmartCode.Configuration
5+
{
6+
public class TableFilter
7+
{
8+
public IEnumerable<String> IncludeTables { get; set; }
9+
public IEnumerable<String> IgnoreTables { get; set; }
10+
public bool? IgnoreNoPKTable { get; set; }
11+
public bool? IgnoreView { get; set; }
12+
}
13+
}

0 commit comments

Comments
 (0)