forked from github/dataease
Merge pull request #2029 from dataease/pr@dev@fix_sql-error
fix: 仪表板编辑是页面偶尔出现SQL报错
This commit is contained in:
commit
5b3a009aad
@ -45,4 +45,7 @@ public interface ExtChartViewMapper {
|
|||||||
|
|
||||||
void copyCacheToView(@Param("viewIds") List<String> viewIds );
|
void copyCacheToView(@Param("viewIds") List<String> viewIds );
|
||||||
|
|
||||||
|
int updateToCache(@Param("viewId") String viewId );
|
||||||
|
|
||||||
|
void copyCache(@Param("sourceViewId") String sourceViewId,@Param("newViewId") String newViewId);
|
||||||
}
|
}
|
||||||
|
@ -89,6 +89,69 @@
|
|||||||
chart_view.id = #{id}
|
chart_view.id = #{id}
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
|
<insert id="copyCache">
|
||||||
|
INSERT INTO chart_view_cache (
|
||||||
|
id,
|
||||||
|
`name`,
|
||||||
|
title,
|
||||||
|
scene_id,
|
||||||
|
table_id,
|
||||||
|
`type`,
|
||||||
|
render,
|
||||||
|
result_count,
|
||||||
|
result_mode,
|
||||||
|
create_by,
|
||||||
|
create_time,
|
||||||
|
update_time,
|
||||||
|
style_priority,
|
||||||
|
chart_type,
|
||||||
|
is_plugin,
|
||||||
|
x_axis,
|
||||||
|
x_axis_ext,
|
||||||
|
y_axis,
|
||||||
|
y_axis_ext,
|
||||||
|
ext_stack,
|
||||||
|
ext_bubble,
|
||||||
|
custom_attr,
|
||||||
|
custom_style,
|
||||||
|
custom_filter,
|
||||||
|
drill_fields,
|
||||||
|
senior,
|
||||||
|
SNAPSHOT,
|
||||||
|
data_from
|
||||||
|
) SELECT
|
||||||
|
#{newViewId} as id,
|
||||||
|
`name`,
|
||||||
|
title,
|
||||||
|
scene_id,
|
||||||
|
table_id,
|
||||||
|
`type`,
|
||||||
|
render,
|
||||||
|
result_count,
|
||||||
|
result_mode,
|
||||||
|
create_by,
|
||||||
|
create_time,
|
||||||
|
update_time,
|
||||||
|
style_priority,
|
||||||
|
chart_type,
|
||||||
|
is_plugin,
|
||||||
|
x_axis,
|
||||||
|
x_axis_ext,
|
||||||
|
y_axis,
|
||||||
|
y_axis_ext,
|
||||||
|
ext_stack,
|
||||||
|
ext_bubble,
|
||||||
|
custom_attr,
|
||||||
|
custom_style,
|
||||||
|
custom_filter,
|
||||||
|
drill_fields,
|
||||||
|
senior,
|
||||||
|
SNAPSHOT,
|
||||||
|
data_from from chart_view_cache
|
||||||
|
WHERE
|
||||||
|
chart_view_cache.id = #{sourceViewId}
|
||||||
|
</insert>
|
||||||
|
|
||||||
<!-- <select id="searchOne" resultMap="BaseResultMapDTO">-->
|
<!-- <select id="searchOne" resultMap="BaseResultMapDTO">-->
|
||||||
<!-- select-->
|
<!-- select-->
|
||||||
<!-- id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,-->
|
<!-- id, `name`, scene_id, table_id, `type`, title, create_by, create_time, update_time,-->
|
||||||
@ -404,4 +467,37 @@
|
|||||||
#{viewId}
|
#{viewId}
|
||||||
</foreach>
|
</foreach>
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<update id="updateToCache">
|
||||||
|
UPDATE chart_view_cache cv,
|
||||||
|
chart_view cve
|
||||||
|
SET cv.`name` = cve.`name`,
|
||||||
|
cv.title = cve.title,
|
||||||
|
cv.scene_id = cve.scene_id,
|
||||||
|
cv.table_id = cve.table_id,
|
||||||
|
cv.`type` = cve.`type`,
|
||||||
|
cv.render = cve.render,
|
||||||
|
cv.result_count = cve.result_count,
|
||||||
|
cv.result_mode = cve.result_mode,
|
||||||
|
cv.create_by = cve.create_by,
|
||||||
|
cv.create_time = cve.create_time,
|
||||||
|
cv.update_time = cve.update_time,
|
||||||
|
cv.style_priority = cve.style_priority,
|
||||||
|
cv.chart_type = cve.chart_type,
|
||||||
|
cv.is_plugin = cve.is_plugin,
|
||||||
|
cv.x_axis = cve.x_axis,
|
||||||
|
cv.x_axis_ext = cve.x_axis_ext,
|
||||||
|
cv.y_axis = cve.y_axis,
|
||||||
|
cv.y_axis_ext = cve.y_axis_ext,
|
||||||
|
cv.ext_stack = cve.ext_stack,
|
||||||
|
cv.ext_bubble = cve.ext_bubble,
|
||||||
|
cv.custom_attr = cve.custom_attr,
|
||||||
|
cv.custom_style = cve.custom_style,
|
||||||
|
cv.custom_filter = cve.custom_filter,
|
||||||
|
cv.drill_fields = cve.drill_fields,
|
||||||
|
cv.senior = cve.senior,
|
||||||
|
cv.SNAPSHOT = cve.SNAPSHOT,
|
||||||
|
cv.data_from = cve.data_from
|
||||||
|
where cve.id = cv.id and cv.id =#{viewId}
|
||||||
|
</update>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
@ -13,6 +13,7 @@ import io.dataease.controller.request.chart.ChartViewCacheRequest;
|
|||||||
import io.dataease.controller.request.chart.ChartViewRequest;
|
import io.dataease.controller.request.chart.ChartViewRequest;
|
||||||
import io.dataease.controller.response.ChartDetail;
|
import io.dataease.controller.response.ChartDetail;
|
||||||
import io.dataease.dto.chart.ChartViewDTO;
|
import io.dataease.dto.chart.ChartViewDTO;
|
||||||
|
import io.dataease.service.chart.ChartViewCacheService;
|
||||||
import io.dataease.service.chart.ChartViewService;
|
import io.dataease.service.chart.ChartViewService;
|
||||||
import io.dataease.service.panel.PanelViewService;
|
import io.dataease.service.panel.PanelViewService;
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
@ -34,8 +35,9 @@ import java.util.List;
|
|||||||
public class ChartViewController {
|
public class ChartViewController {
|
||||||
@Resource
|
@Resource
|
||||||
private ChartViewService chartViewService;
|
private ChartViewService chartViewService;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PanelViewService panelViewService;
|
private ChartViewCacheService chartViewCacheService;
|
||||||
|
|
||||||
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
|
@DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE)
|
||||||
@ApiOperation("保存")
|
@ApiOperation("保存")
|
||||||
@ -150,7 +152,7 @@ public class ChartViewController {
|
|||||||
@ApiOperation("重置视图缓存")
|
@ApiOperation("重置视图缓存")
|
||||||
@PostMapping("/resetViewCache/{id}/{panelId}")
|
@PostMapping("/resetViewCache/{id}/{panelId}")
|
||||||
public void resetViewCache(@PathVariable String id, @PathVariable String panelId) {
|
public void resetViewCache(@PathVariable String id, @PathVariable String panelId) {
|
||||||
chartViewService.resetViewCache(id);
|
chartViewCacheService.refreshCache(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
package io.dataease.service.chart;
|
||||||
|
|
||||||
|
import io.dataease.base.mapper.ChartViewCacheMapper;
|
||||||
|
import io.dataease.base.mapper.ext.ExtChartViewMapper;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Author: wangjiahao
|
||||||
|
* Date: 2022/4/2
|
||||||
|
* Description:
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class ChartViewCacheService {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private ExtChartViewMapper extChartViewMapper;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public void refreshCache(String viewId){
|
||||||
|
if(extChartViewMapper.updateToCache(viewId)==0){
|
||||||
|
extChartViewMapper.copyToCache(viewId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -97,6 +97,8 @@ public class ChartViewService {
|
|||||||
private PanelGroupExtendDataService extendDataService;
|
private PanelGroupExtendDataService extendDataService;
|
||||||
@Resource
|
@Resource
|
||||||
private ExtPanelGroupExtendDataMapper extPanelGroupExtendDataMapper;
|
private ExtPanelGroupExtendDataMapper extPanelGroupExtendDataMapper;
|
||||||
|
@Resource
|
||||||
|
private ChartViewCacheService chartViewCacheService;
|
||||||
|
|
||||||
|
|
||||||
//默认使用非公平
|
//默认使用非公平
|
||||||
@ -130,7 +132,7 @@ public class ChartViewService {
|
|||||||
chartView.setUpdateTime(timestamp);
|
chartView.setUpdateTime(timestamp);
|
||||||
chartViewMapper.insertSelective(chartView);
|
chartViewMapper.insertSelective(chartView);
|
||||||
// 新建的视图也存入缓存表中
|
// 新建的视图也存入缓存表中
|
||||||
extChartViewMapper.copyToCache(chartView.getId());
|
chartViewCacheService.refreshCache(chartView.getId());
|
||||||
|
|
||||||
PanelView newPanelView = new PanelView();
|
PanelView newPanelView = new PanelView();
|
||||||
newPanelView.setId(UUIDUtil.getUUIDAsString());
|
newPanelView.setId(UUIDUtil.getUUIDAsString());
|
||||||
@ -154,27 +156,6 @@ public class ChartViewService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// // 直接保存统一到缓存表
|
|
||||||
// public ChartViewWithBLOBs save(ChartViewRequest chartView) {
|
|
||||||
// checkName(chartView);
|
|
||||||
// long timestamp = System.currentTimeMillis();
|
|
||||||
// chartView.setUpdateTime(timestamp);
|
|
||||||
// if (ObjectUtils.isEmpty(chartView.getId())) {
|
|
||||||
// chartView.setId(UUID.randomUUID().toString());
|
|
||||||
// chartView.setCreateBy(AuthUtils.getUser().getUsername());
|
|
||||||
// chartView.setCreateTime(timestamp);
|
|
||||||
// chartView.setUpdateTime(timestamp);
|
|
||||||
// chartViewMapper.insertSelective(chartView);
|
|
||||||
// } else {
|
|
||||||
// chartViewMapper.updateByPrimaryKeySelective(chartView);
|
|
||||||
// }
|
|
||||||
// Optional.ofNullable(chartView.getId()).ifPresent(id -> {
|
|
||||||
// CacheUtils.remove(JdbcConstants.VIEW_CACHE_KEY, id);
|
|
||||||
// });
|
|
||||||
// return getOneWithPermission(chartView.getId());
|
|
||||||
// }
|
|
||||||
|
|
||||||
public List<ChartViewDTO> list(ChartViewRequest chartViewRequest) {
|
public List<ChartViewDTO> list(ChartViewRequest chartViewRequest) {
|
||||||
chartViewRequest.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
|
chartViewRequest.setUserId(String.valueOf(AuthUtils.getUser().getUserId()));
|
||||||
return extChartViewMapper.search(chartViewRequest);
|
return extChartViewMapper.search(chartViewRequest);
|
||||||
@ -268,7 +249,7 @@ public class ChartViewService {
|
|||||||
//仪表板编辑页面 从缓存表中取数据 缓存表中没有数据则进行插入
|
//仪表板编辑页面 从缓存表中取数据 缓存表中没有数据则进行插入
|
||||||
result = extChartViewMapper.searchOneFromCache(id);
|
result = extChartViewMapper.searchOneFromCache(id);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
extChartViewMapper.copyToCache(id);
|
chartViewCacheService.refreshCache(id);
|
||||||
result = extChartViewMapper.searchOneFromCache(id);
|
result = extChartViewMapper.searchOneFromCache(id);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1047,8 +1028,9 @@ public class ChartViewService {
|
|||||||
public String chartCopy(String id, String panelId) {
|
public String chartCopy(String id, String panelId) {
|
||||||
String newChartId = UUID.randomUUID().toString();
|
String newChartId = UUID.randomUUID().toString();
|
||||||
extChartViewMapper.chartCopy(newChartId, id, panelId);
|
extChartViewMapper.chartCopy(newChartId, id, panelId);
|
||||||
|
extChartViewMapper.copyCache(id,newChartId);
|
||||||
extPanelGroupExtendDataMapper.copyExtendData(id,newChartId,panelId);
|
extPanelGroupExtendDataMapper.copyExtendData(id,newChartId,panelId);
|
||||||
extChartViewMapper.copyToCache(newChartId);
|
chartViewCacheService.refreshCache(id);
|
||||||
return newChartId;
|
return newChartId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1082,9 +1064,4 @@ public class ChartViewService {
|
|||||||
extChartViewMapper.deleteCacheWithPanel(panelId);
|
extChartViewMapper.deleteCacheWithPanel(panelId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetViewCache(String viewId) {
|
|
||||||
extChartViewMapper.deleteViewCache(viewId);
|
|
||||||
|
|
||||||
extChartViewMapper.copyToCache(viewId);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user