Skip to content

Commit 33cf0df

Browse files
Merge pull request dataease#109 from dataease/pr@dev@cyw
Pr@dev@cyw
2 parents 1c7e097 + 5b8b367 commit 33cf0df

File tree

39 files changed

+2389
-91
lines changed

39 files changed

+2389
-91
lines changed

backend/src/main/java/io/dataease/auth/service/impl/ShiroServiceImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public Map<String, String> loadFilterChainDefinitionMap() {
3838
filterChainDefinitionMap.put("/link/**", ANON);
3939
filterChainDefinitionMap.put("/index.html", ANON);
4040
filterChainDefinitionMap.put("/link.html", ANON);
41+
filterChainDefinitionMap.put("/axios.map", ANON);
4142

4243
//验证链接
4344
filterChainDefinitionMap.put("/api/link/validate**", ANON);

backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,18 @@
22

33
import io.dataease.controller.request.chart.ChartViewRequest;
44
import io.dataease.dto.chart.ChartViewDTO;
5+
import org.apache.ibatis.annotations.Mapper;
6+
import org.apache.ibatis.annotations.Param;
7+
import org.apache.ibatis.annotations.Select;
58

69
import java.util.List;
710

11+
@Mapper
812
public interface ExtChartViewMapper {
913
List<ChartViewDTO> search(ChartViewRequest request);
14+
15+
void chartCopy(@Param("newChartId")String newChartId,@Param("oldChartId")String oldChartId);
16+
17+
@Select("select id from chart_view where table_id = #{tableId}")
18+
List<String> allViewIds(@Param("tableId") String tableId);
1019
}

backend/src/main/java/io/dataease/base/mapper/ext/ExtChartViewMapper.xml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,45 @@
2727

2828

2929
</select>
30+
31+
<insert id="chartCopy">
32+
INSERT INTO chart_view (
33+
`id`,
34+
`name`,
35+
`scene_id`,
36+
`table_id`,
37+
`type`,
38+
`title`,
39+
`x_axis`,
40+
`y_axis`,
41+
`custom_attr`,
42+
`custom_style`,
43+
`custom_filter`,
44+
`create_by`,
45+
`create_time`,
46+
`update_time`,
47+
`snapshot`,
48+
`style_priority`
49+
) SELECT
50+
#{newChartId},
51+
GET_CHART_VIEW_COPY_NAME ( #{oldChartId} ),
52+
`scene_id`,
53+
`table_id`,
54+
`type`,
55+
`title`,
56+
`x_axis`,
57+
`y_axis`,
58+
`custom_attr`,
59+
`custom_style`,
60+
`custom_filter`,
61+
`create_by`,
62+
`create_time`,
63+
`update_time`,
64+
`snapshot`,
65+
`style_priority`
66+
FROM
67+
chart_view
68+
WHERE
69+
id = #{oldChartId}
70+
</insert>
3071
</mapper>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.dataease.commons.constants;
2+
3+
public class JdbcConstants {
4+
5+
public final static String VIEW_CACHE_KEY = "view_cache";
6+
}

backend/src/main/java/io/dataease/controller/chart/ChartViewController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public ChartViewDTO getData(@PathVariable String id, @RequestBody ChartExtReques
5555
public Map<String, Object> chartDetail(@PathVariable String id) {
5656
return chartViewService.getChartDetail(id);
5757
}
58+
59+
@PostMapping("chartCopy/{id}")
60+
public String chartCopy(@PathVariable String id) {
61+
return chartViewService.chartCopy(id);
62+
}
5863
}

backend/src/main/java/io/dataease/datasource/provider/JdbcProvider.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import io.dataease.exception.DataEaseException;
1111
import org.apache.commons.lang3.StringUtils;
1212
import org.springframework.stereotype.Service;
13-
1413
import java.beans.PropertyVetoException;
1514
import java.sql.*;
1615
import java.util.*;
@@ -22,14 +21,29 @@ public class JdbcProvider extends DatasourceProvider {
2221
private static int initPoolSize = 5;
2322
private static int maxConnections = 200;
2423

24+
/**
25+
* 增加缓存机制 key 由 'provider_sql_' dsr.datasource.id dsr.table dsr.query共4部分组成,命中则使用缓存直接返回不再执行sql逻辑
26+
* @param dsr
27+
* @return
28+
* @throws Exception
29+
*/
30+
/**
31+
* 这里使用声明式缓存不是很妥当
32+
* 改为chartViewService中使用编程式缓存
33+
@Cacheable(
34+
value = JdbcConstants.JDBC_PROVIDER_KEY,
35+
key = "'provider_sql_' + #dsr.datasource.id + '_' + #dsr.table + '_' + #dsr.query",
36+
condition = "#dsr.pageSize == null || #dsr.pageSize == 0L"
37+
)
38+
*/
2539
@Override
26-
public List<String[]> getData(DatasourceRequest datasourceRequest) throws Exception {
40+
public List<String[]> getData(DatasourceRequest dsr) throws Exception {
2741
List<String[]> list = new LinkedList<>();
2842
Connection connection = null;
2943
try {
30-
connection = getConnectionFromPool(datasourceRequest);
44+
connection = getConnectionFromPool(dsr);
3145
Statement stat = connection.createStatement();
32-
ResultSet rs = stat.executeQuery(datasourceRequest.getQuery());
46+
ResultSet rs = stat.executeQuery(dsr.getQuery());
3347
list = fetchResult(rs);
3448
} catch (SQLException e) {
3549
DataEaseException.throwException(e);

backend/src/main/java/io/dataease/listener/util/CacheUtils.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,19 @@ public static Object get(String cacheName, Object key) {
2424
return element.getObjectValue();
2525
}
2626

27-
private static void put(String cacheName, Object key, Object value, Integer ttl, Integer tti) {
27+
public static void put(String cacheName, Object key, Object value, Integer ttl, Integer tti) {
2828
Element e = new Element(key, value);
2929
//不设置则使用xml配置
30-
if (ttl != null)
30+
if (ttl != null) {
3131
e.setEternal(false);
3232
e.setTimeToLive(ttl);
33+
}
3334
if (tti != null)
3435
e.setTimeToIdle(tti);
3536
cache(cacheName).put(e);
3637
}
3738

38-
private static boolean remove(String cacheName, Object key) {
39+
public static boolean remove(String cacheName, Object key) {
3940
return cache(cacheName).remove(key);
4041
}
4142

backend/src/main/java/io/dataease/provider/doris/DorisQueryProvider.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public String getSQL(String table, List<ChartViewFieldDTO> xAxis, List<ChartView
189189
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
190190
filter.append("%").append(f.getValue()).append("%");
191191
} else {
192-
filter.append("'" + f.getValue() + "'");
192+
filter.append("'").append(f.getValue()).append("'");
193193
}
194194
return filter.toString();
195195
}).toArray(String[]::new);
@@ -225,7 +225,7 @@ public String getSQL(String table, List<ChartViewFieldDTO> xAxis, List<ChartView
225225
} else if (StringUtils.containsIgnoreCase(f.getTerm(), "like")) {
226226
filter.append("%").append(f.getValue()).append("%");
227227
} else {
228-
filter.append("'" + f.getValue() + "'");
228+
filter.append("'").append(f.getValue()).append("'");
229229
}
230230
return filter.toString();
231231
}).toArray(String[]::new);
@@ -234,9 +234,10 @@ public String getSQL(String table, List<ChartViewFieldDTO> xAxis, List<ChartView
234234
if (resultFilter.length == 0) {
235235
return sql;
236236
} else {
237-
String filterSql = MessageFormat.format("SELECT * FROM {0} WHERE 1=1 {1}",
237+
String filterSql = MessageFormat.format("SELECT * FROM {0} WHERE 1=1 {1} ORDER BY {2}",
238238
"(" + sql + ") AS tmp",
239-
StringUtils.join(resultFilter, " "));
239+
StringUtils.join(resultFilter, " "),
240+
ObjectUtils.isNotEmpty(yOrder) ? StringUtils.join(yOrder, ",") : "null");
240241
return filterSql;
241242
}
242243
}
@@ -314,9 +315,10 @@ public String getSQLSummary(String table, List<ChartViewFieldDTO> yAxis, List<Ch
314315
if (resultFilter.length == 0) {
315316
return sql;
316317
} else {
317-
String filterSql = MessageFormat.format("SELECT * FROM {0} WHERE 1=1 {1}",
318+
String filterSql = MessageFormat.format("SELECT * FROM {0} WHERE 1=1 {1} ORDER BY {2}",
318319
"(" + sql + ") AS tmp",
319-
StringUtils.join(resultFilter, " "));
320+
StringUtils.join(resultFilter, " "),
321+
ObjectUtils.isNotEmpty(order) ? StringUtils.join(order, ",") : "null");
320322
return filterSql;
321323
}
322324
}

0 commit comments

Comments
 (0)