Skip to content

Commit 1f95d9b

Browse files
committed
fix fromItem.getAlias().getName() null point bug
1 parent 0d07930 commit 1f95d9b

8 files changed

Lines changed: 52 additions & 11 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<groupId>com.codingapi.springboot</groupId>
1717
<artifactId>springboot-parent</artifactId>
18-
<version>2.10.34</version>
18+
<version>2.10.35</version>
1919

2020
<url>https://github.com/codingapi/springboot-framewrok</url>
2121
<name>springboot-parent</name>

springboot-starter-data-authorization/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.10.34</version>
9+
<version>2.10.35</version>
1010
</parent>
1111

1212
<name>springboot-starter-data-authorization</name>

springboot-starter-data-authorization/src/main/java/com/codingapi/springboot/authorization/enhancer/TableColumnAliasHolder.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private void searchSubSelect(String parent, PlainSelect plainSelect) {
6464
if (fromItem instanceof Select) {
6565
PlainSelect subPlainSelect = ((Select) fromItem).getPlainSelect();
6666
this.appendColumnAlias(parent, null, plainSelect.getSelectItems());
67-
parent = fromItem.getAlias().getName();
67+
parent = fromItem.getAlias()!=null?fromItem.getAlias().getName():null;
6868
this.searchSubSelect(parent, subPlainSelect);
6969
}
7070

@@ -75,7 +75,7 @@ private void searchSubSelect(String parent, PlainSelect plainSelect) {
7575
FromItem currentItem = join.getRightItem();
7676
PlainSelect subPlainSelect = ((Select) currentItem).getPlainSelect();
7777
this.appendColumnAlias(parent, null, plainSelect.getSelectItems());
78-
parent = currentItem.getAlias().getName();
78+
parent = currentItem.getAlias()!=null?currentItem.getAlias().getName():null;
7979
this.searchSubSelect(parent, subPlainSelect);
8080
}
8181
if (join.getRightItem() instanceof Table) {
@@ -125,4 +125,4 @@ private void appendColumnAlias(String parent, String tableName, List<SelectItem<
125125
}
126126
}
127127

128-
}
128+
}

springboot-starter-data-authorization/src/test/java/com/codingapi/springboot/authorization/analyzer/SelectSQLAnalyzerTest.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,6 @@ void test7() throws Exception{
196196
System.out.println(builder.getTableAlias());;
197197
}
198198

199-
200199
@Test
201200
@Order(8)
202201
void test8() throws Exception{
@@ -222,4 +221,46 @@ void test8() throws Exception{
222221
assertEquals("SELECT ade1_0.id, ade1_0.ba_dept_name, ade1_0.ba_org_shortname, ade1_0.ba_dept_code, ade1_0.ba_code, ade1_0.ba_dept_property_code, ade1_0.ba_parent_type, ade1_0.ba_real_super_org_id, ade1_0.ba_org_is_avoidance_dept, ade1_0.ba_real_super_org_id, ade1_0.ba_super_org_name FROM ba04_administrative_department ade1_0 WHERE ade1_0.id < 100 AND ade1_0.ba_parent_type = 0 " +
223222
"UNION ALL SELECT ade2_0.id, ade2_0.ba_dept_name, ade2_0.ba_org_shortname, ade2_0.ba_dept_code, ade2_0.ba_code, ade2_0.ba_dept_property_code, ade2_0.ba_parent_type, ade2_0.ba_real_super_org_id, ade2_0.ba_org_is_avoidance_dept, ade3_0.ba_real_super_org_id, ade3_0.ba_super_org_name FROM ba04_administrative_department ade2_0 LEFT JOIN ba04_administrative_department ade3_0 ON ade2_0.ba_real_super_org_id = ade3_0.id WHERE ade3_0.id < 100 AND ade2_0.id < 100 AND ade2_0.ba_real_super_org_id = 1", newSQL);
224223
}
225-
}
224+
225+
226+
@Test
227+
@Order(9)
228+
void test9() throws Exception{
229+
String sql = "select cd.id,cd.name,cd.parent_id from depart cd join depart pd on cd.id = pd.parent_id where cd.id = ?";
230+
231+
RowHandler rowHandler = (subSql, tableName, tableAlias) -> {
232+
if (tableName.equalsIgnoreCase("depart") && tableAlias.equalsIgnoreCase("cd")) {
233+
String conditionTemplate = "%s.id = 100 ";
234+
return Condition.formatCondition(conditionTemplate, tableAlias);
235+
}
236+
return null;
237+
};
238+
DataPermissionSQLEnhancer builder = new DataPermissionSQLEnhancer(sql, rowHandler);
239+
String newSQL = builder.getNewSQL();
240+
System.out.println(newSQL);
241+
System.out.println(builder.getTableAlias().getTableAlias());
242+
assertEquals("SELECT cd.id, cd.name, cd.parent_id FROM depart cd JOIN depart pd ON cd.id = pd.parent_id WHERE cd.id = 100 AND cd.id = ?",newSQL);
243+
}
244+
245+
246+
247+
@Test
248+
@Order(10)
249+
void test10() throws Exception{
250+
String sql = "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( SELECT t.id,t.parent_id,t.type,t.target_id,t.system_code,t.full_name,t.short_name,t.system_short_name,t.full_name_tair,t.short_name_tair,t.system_short_name_tair,t.tree_sort,t.sys_creator_id,t.sys_updater_id,t.sys_create_time,t.sys_update_time,t.sys_deleted,t.sys_enabled,parent.short_name AS parentName,parent.type AS parentType,if(parent.type=0,'单位','部门') AS parentTypeText FROM sys_u_organization t LEFT JOIN sys_u_organization parent ON (parent.id = t.parent_id AND parent.sys_deleted=0) LEFT JOIN sys_u_company t2 ON (t2.organization_id = t.id AND t2.sys_deleted=0) WHERE t.sys_deleted=0 AND (t.id <> ? AND t.type = ? AND t.system_code LIKE ?) ORDER BY t.tree_sort ASC,t.tree_sort ASC ) TMP WHERE ROWNUM <=?) WHERE ROW_ID > ?";
251+
252+
RowHandler rowHandler = (subSql, tableName, tableAlias) -> {
253+
if (tableName.equalsIgnoreCase("sys_u_organization")) {
254+
String conditionTemplate = "%s.id < 100 ";
255+
return Condition.formatCondition(conditionTemplate, tableAlias);
256+
}
257+
return null;
258+
};
259+
DataPermissionSQLEnhancer builder = new DataPermissionSQLEnhancer(sql, rowHandler);
260+
String newSQL = builder.getNewSQL();
261+
System.out.println(newSQL);
262+
System.out.println(builder.getTableAlias().getTableAlias());
263+
assertEquals("SELECT * FROM (SELECT TMP.*, ROWNUM ROW_ID FROM (SELECT t.id, t.parent_id, t.type, t.target_id, t.system_code, t.full_name, t.short_name, t.system_short_name, t.full_name_tair, t.short_name_tair, t.system_short_name_tair, t.tree_sort, t.sys_creator_id, t.sys_updater_id, t.sys_create_time, t.sys_update_time, t.sys_deleted, t.sys_enabled, parent.short_name AS parentName, parent.type AS parentType, if(parent.type = 0, '单位', '部门') AS parentTypeText FROM sys_u_organization t LEFT JOIN sys_u_organization parent ON (parent.id = t.parent_id AND parent.sys_deleted = 0) LEFT JOIN sys_u_company t2 ON (t2.organization_id = t.id AND t2.sys_deleted = 0) WHERE parent.id < 100 AND t.id < 100 AND t.sys_deleted = 0 AND (t.id <> ? AND t.type = ? AND t.system_code LIKE ?) ORDER BY t.tree_sort ASC, t.tree_sort ASC) TMP WHERE ROWNUM <= ?) WHERE ROW_ID > ?", newSQL);
264+
}
265+
266+
}

springboot-starter-data-fast/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>springboot-parent</artifactId>
77
<groupId>com.codingapi.springboot</groupId>
8-
<version>2.10.34</version>
8+
<version>2.10.35</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

springboot-starter-flow/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.10.34</version>
9+
<version>2.10.35</version>
1010
</parent>
1111

1212
<name>springboot-starter-flow</name>

springboot-starter-security/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<artifactId>springboot-parent</artifactId>
88
<groupId>com.codingapi.springboot</groupId>
9-
<version>2.10.34</version>
9+
<version>2.10.35</version>
1010
</parent>
1111

1212
<artifactId>springboot-starter-security</artifactId>

springboot-starter/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.codingapi.springboot</groupId>
77
<artifactId>springboot-parent</artifactId>
8-
<version>2.10.34</version>
8+
<version>2.10.35</version>
99
</parent>
1010
<artifactId>springboot-starter</artifactId>
1111

0 commit comments

Comments
 (0)