Skip to content

Commit 909f11c

Browse files
committed
feat: 2.07 ★ load ext doc (See Show Comment Plugin Demo) | 加载外部注释 (参考 Show Comment 插件示例)
1 parent f0e7101 commit 909f11c

21 files changed

+635
-233
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## [1.0.0]
66

7+
- 2.07 ★ load ext doc (See Show Comment Plugin Demo)
78
- 2.06 Bean to table
89
- 2.05 ignore id in ignore.sql-list.txt
910
- 2.04 MyBatis *.xml SQL inspection
@@ -14,6 +15,7 @@
1415

1516
# 中文更新日志
1617

18+
- 2.07 ★ 加载外部注释 (参考 Show Comment 插件示例)
1719
- 2.06 Bean 对应表
1820
- 2.05 忽略 ignore.sql-list.txt 中的 id
1921
- 2.04 MyBatis *.xml SQL 实时检查

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pluginGroup = com.github.linwancen.plugin.sql
44
pluginName = sql-list
55
pluginRepositoryUrl = https://github.com/LinWanCen/sql-list
66
# SemVer format -> https://semver.org
7-
pluginVersion = 2.06
7+
pluginVersion = 2.07
88

99
# Supported build number ranges and IntelliJ Platform versions -> https://plugins.jetbrains.com/docs/intellij/build-number-ranges.html
1010
pluginSinceBuild = 201

src/main/java/io/github/linwancen/sql/Main.java

+13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.linwancen.sql.bean.SqlInfo;
66
import io.github.linwancen.sql.excel.SqlInfoWriter;
77
import io.github.linwancen.sql.parser.AllParser;
8+
import io.github.linwancen.sql.parser.jsqlparser.JSqlParser;
89
import io.github.linwancen.util.excel.ExcelUtils;
910
import io.github.linwancen.util.git.GitUtils;
1011
import io.github.linwancen.util.java.EnvUtils;
@@ -14,6 +15,8 @@
1415
import org.slf4j.LoggerFactory;
1516

1617
import java.io.File;
18+
import java.io.IOException;
19+
import java.nio.file.Files;
1720
import java.util.Arrays;
1821
import java.util.Collections;
1922
import java.util.List;
@@ -56,6 +59,16 @@ private static void forArgs(String[] args, Consumer<List<SqlInfo>> fun, boolean
5659
DiffGit.gitBetween(args, fun);
5760
} else if ("diff".equals(first)) {
5861
DiffSql.diff(args, fun, git);
62+
} else if ("load".equals(first)) {
63+
List<String> list;
64+
try {
65+
list = Files.readAllLines(new File(args[1]).toPath());
66+
} catch (IOException e) {
67+
throw new RuntimeException(e);
68+
}
69+
List<SqlInfo> sqlInfoList = list.parallelStream().map(SqlInfo::of).collect(Collectors.toList());
70+
sqlInfoList.forEach(JSqlParser::parseSQL);
71+
fun.accept(sqlInfoList);
5972
} else {
6073
List<File> files = Arrays.stream(args).parallel()
6174
.map(File::new)

src/main/java/io/github/linwancen/sql/bean/Dto.java

+19-6
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,20 @@
1010
@HeadStyle(wrapped = BooleanEnum.FALSE, horizontalAlignment = HorizontalAlignmentEnum.LEFT)
1111
@HeadFontStyle(fontHeightInPoints = 11, bold = BooleanEnum.FALSE, fontName = "宋体")
1212
public class Dto {
13-
public Dto(String className, String tableName) {
14-
this.className = className;
15-
this.tableName = tableName;
16-
}
17-
1813
@ColumnWidth(50)
1914
private String className;
20-
@ColumnWidth(50)
15+
@ColumnWidth(25)
2116
private String tableName;
17+
@ColumnWidth(25)
18+
private String tableComment;
19+
20+
public static Dto of(String className, String tableName, String tableComment) {
21+
Dto dto = new Dto();
22+
dto.className = className;
23+
dto.tableName = tableName;
24+
dto.tableComment = tableComment;
25+
return dto;
26+
}
2227

2328
public String getClassName() {
2429
return className;
@@ -35,4 +40,12 @@ public String getTableName() {
3540
public void setTableName(String tableName) {
3641
this.tableName = tableName;
3742
}
43+
44+
public String getTableComment() {
45+
return tableComment;
46+
}
47+
48+
public void setTableComment(String tableComment) {
49+
this.tableComment = tableComment;
50+
}
3851
}

src/main/java/io/github/linwancen/sql/bean/Rel.java

+139-5
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,146 @@
66
import com.alibaba.excel.enums.BooleanEnum;
77
import com.alibaba.excel.enums.poi.HorizontalAlignmentEnum;
88

9+
import java.util.Objects;
10+
911
@SuppressWarnings("unused")
1012
@HeadStyle(wrapped = BooleanEnum.FALSE, horizontalAlignment = HorizontalAlignmentEnum.LEFT)
1113
@HeadFontStyle(fontHeightInPoints = 11, bold = BooleanEnum.FALSE, fontName = "宋体")
12-
public class Rel {
13-
@ColumnWidth(50)
14-
private String a;
15-
@ColumnWidth(50)
16-
private String b;
14+
public class Rel implements Comparable<Rel> {
15+
@ColumnWidth(25)
16+
private String tableL;
17+
@ColumnWidth(25)
18+
private String columnL;
19+
@ColumnWidth(25)
20+
private String tableR;
21+
@ColumnWidth(25)
22+
private String columnR;
23+
@ColumnWidth(25)
24+
private String tableCommentL;
25+
@ColumnWidth(25)
26+
private String columnCommentL;
27+
@ColumnWidth(25)
28+
private String tableCommentR;
29+
@ColumnWidth(25)
30+
private String columnCommentR;
31+
32+
public static Rel sortRelOrNull(String tableL, String columnL, String tableR, String columnR) {
33+
if (tableL == null || columnL == null || tableR == null || columnR == null) {
34+
return null;
35+
}
36+
tableL = tableL.toLowerCase();
37+
tableR = tableR.toLowerCase();
38+
columnL = columnL.toLowerCase();
39+
columnR = columnR.toLowerCase();
40+
int compare = tableL.compareTo(tableR);
41+
if (compare == 0) {
42+
compare = columnL.compareTo(columnR);
43+
}
44+
if (compare == 0) {
45+
return null;
46+
}
47+
Rel rel = new Rel();
48+
if (compare < 0) {
49+
rel.tableL = tableL;
50+
rel.columnL = columnL;
51+
rel.tableR = tableR;
52+
rel.columnR = columnR;
53+
} else {
54+
rel.tableL = tableR;
55+
rel.columnL = columnR;
56+
rel.tableR = tableL;
57+
rel.columnR = columnL;
58+
}
59+
return rel;
60+
}
61+
62+
@Override
63+
public String toString() {
64+
return tableL + "." + columnL + " --> " + tableR + "." + tableCommentR;
65+
}
66+
67+
@Override
68+
public int compareTo(Rel o) {
69+
return toString().compareTo((o.toString()));
70+
}
71+
72+
@Override
73+
public boolean equals(Object o) {
74+
if (this == o) return true;
75+
if (o == null || getClass() != o.getClass()) return false;
76+
Rel rel = (Rel) o;
77+
return Objects.equals(tableL, rel.tableL)
78+
&& Objects.equals(columnL, rel.columnL)
79+
&& Objects.equals(tableR, rel.tableR)
80+
&& Objects.equals(columnR, rel.columnR);
81+
}
82+
83+
@Override
84+
public int hashCode() {
85+
return Objects.hash(tableL, columnL, tableR, columnR);
86+
}
87+
88+
public String getTableL() {
89+
return tableL;
90+
}
91+
92+
public void setTableL(String tableL) {
93+
this.tableL = tableL;
94+
}
95+
96+
public String getColumnL() {
97+
return columnL;
98+
}
99+
100+
public void setColumnL(String columnL) {
101+
this.columnL = columnL;
102+
}
103+
104+
public String getTableR() {
105+
return tableR;
106+
}
107+
108+
public void setTableR(String tableR) {
109+
this.tableR = tableR;
110+
}
111+
112+
public String getColumnR() {
113+
return columnR;
114+
}
115+
116+
public void setColumnR(String columnR) {
117+
this.columnR = columnR;
118+
}
119+
120+
public String getTableCommentL() {
121+
return tableCommentL;
122+
}
123+
124+
public void setTableCommentL(String tableCommentL) {
125+
this.tableCommentL = tableCommentL;
126+
}
127+
128+
public String getColumnCommentL() {
129+
return columnCommentL;
130+
}
131+
132+
public void setColumnCommentL(String columnCommentL) {
133+
this.columnCommentL = columnCommentL;
134+
}
135+
136+
public String getTableCommentR() {
137+
return tableCommentR;
138+
}
139+
140+
public void setTableCommentR(String tableCommentR) {
141+
this.tableCommentR = tableCommentR;
142+
}
143+
144+
public String getColumnCommentR() {
145+
return columnCommentR;
146+
}
147+
148+
public void setColumnCommentR(String columnCommentR) {
149+
this.columnCommentR = columnCommentR;
150+
}
17151
}

src/main/java/io/github/linwancen/sql/bean/SqlInfo.java

+18-2
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,16 @@ public class SqlInfo {
3939
@SuppressWarnings("FieldCanBeLocal")
4040
@ColumnWidth(25)
4141
private String table;
42+
@ColumnWidth(25)
43+
private String tableComment;
4244
/** ColumnName, ColumnExcelLine */
4345
@ExcelIgnore
4446
private final List<TreeMap<String, TableColumn>> columnList = new ArrayList<>();
4547
@SuppressWarnings("FieldCanBeLocal")
4648
private String column;
4749
/** tableName.Column --- */
4850
@ExcelIgnore
49-
private final Set<List<String>> columnRel = new HashSet<>();
51+
private final Set<Rel> columnRel = new HashSet<>();
5052
/** gitRootInfo.startDate != null && gitRootInfo.endDate != null */
5153
private Date inDate;
5254
@ExcelIgnore
@@ -67,6 +69,12 @@ public class SqlInfo {
6769
@ExcelIgnore
6870
private final Map<String, String> aliasMap = new HashMap<>();
6971

72+
public static SqlInfo of(String sql) {
73+
SqlInfo sqlInfo = new SqlInfo();
74+
sqlInfo.sql = sql;
75+
return sqlInfo;
76+
}
77+
7078
public String getFullId() {
7179
return namespace + "." + id;
7280
}
@@ -156,6 +164,14 @@ public String getTable() {
156164
return String.join(", ", tableMap.keySet());
157165
}
158166

167+
public String getTableComment() {
168+
return tableComment;
169+
}
170+
171+
public void setTableComment(String tableComment) {
172+
this.tableComment = tableComment;
173+
}
174+
159175
public List<TreeMap<String, TableColumn>> getColumnList() {
160176
return columnList;
161177
}
@@ -167,7 +183,7 @@ public String getColumn() {
167183
.collect(Collectors.joining("\n"));
168184
}
169185

170-
public Set<List<String>> getColumnRel() {
186+
public Set<Rel> getColumnRel() {
171187
return columnRel;
172188
}
173189

src/main/java/io/github/linwancen/sql/bean/TableColumn.java

+20
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class TableColumn {
2020
private String type;
2121
@ColumnWidth(25)
2222
private String table;
23+
@ColumnWidth(25)
24+
private String tableComment;
2325
@ExcelIgnore
2426
private final LinkedHashSet<String> columnUseTypeSet = new LinkedHashSet<>();
2527
@ColumnWidth(15)
@@ -29,6 +31,8 @@ public class TableColumn {
2931
private final LinkedHashSet<String> columnSet = new LinkedHashSet<>();
3032
@ColumnWidth(25)
3133
private String column;
34+
@ColumnWidth(25)
35+
private String columnComment;
3236

3337
public String getFullId() {
3438
return namespace + "." + id;
@@ -70,6 +74,14 @@ public void setTable(String table) {
7074
this.table = table;
7175
}
7276

77+
public String getTableComment() {
78+
return tableComment;
79+
}
80+
81+
public void setTableComment(String tableComment) {
82+
this.tableComment = tableComment;
83+
}
84+
7385
public LinkedHashSet<String> getColumnUseTypeSet() {
7486
return columnUseTypeSet;
7587
}
@@ -109,4 +121,12 @@ public String getColumn() {
109121
public void setColumn(String column) {
110122
this.column = column;
111123
}
124+
125+
public String getColumnComment() {
126+
return columnComment;
127+
}
128+
129+
public void setColumnComment(String columnComment) {
130+
this.columnComment = columnComment;
131+
}
112132
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package io.github.linwancen.sql.excel;
2+
3+
import io.github.linwancen.sql.bean.SqlInfo;
4+
5+
public class SqlInfoErrMd {
6+
7+
public static boolean appendErr(StringBuilder errMd, SqlInfo info) {
8+
String errStr = null;
9+
if (info.getSqlErr() != null) {
10+
errStr = info.getSqlErr();
11+
} else if (info.getXmlErr() != null) {
12+
errStr = info.getXmlErr();
13+
}
14+
if (errStr == null) {
15+
return false;
16+
}
17+
errMd.append("### ").append(info.getLastAuthor())
18+
.append(".(").append(info.getLink()).append(") ")
19+
.append(info.getId()).append("\n");
20+
errMd.append(errStr).append("\n");
21+
if (info.getSql() != null) {
22+
errMd.append("```sql\n").append(info.getSql()).append("\n```\n");
23+
}
24+
errMd.append("\n");
25+
return true;
26+
}
27+
}

0 commit comments

Comments
 (0)