提交 cfe1ed3f authored 作者: wangjiahao's avatar wangjiahao

refactor: 仪表板视图操作优化

上级 59aa355e
...@@ -126,11 +126,11 @@ ...@@ -126,11 +126,11 @@
`chart_type`, `chart_type`,
`senior`) `senior`)
SELECT #{newChartId}, SELECT #{newChartId},
GET_CHART_VIEW_COPY_NAME(#{oldChartId}), `name`,
#{panelId}, #{panelId},
`table_id`, `table_id`,
`type`, `type`,
GET_CHART_VIEW_COPY_NAME(#{oldChartId}), `title`,
`x_axis`, `x_axis`,
`x_axis_ext`, `x_axis_ext`,
`y_axis`, `y_axis`,
...@@ -151,7 +151,7 @@ ...@@ -151,7 +151,7 @@
`result_mode`, `result_mode`,
'private', 'private',
`senior` `senior`
FROM chart_view FROM chart_view_cache
WHERE id = #{oldChartId} WHERE id = #{oldChartId}
</insert> </insert>
...@@ -293,8 +293,7 @@ ...@@ -293,8 +293,7 @@
</select> </select>
<delete id="deleteCacheWithPanel"> <delete id="deleteCacheWithPanel">
DELETE cvc, DELETE cvc
pv
FROM FROM
chart_view_cache cvc chart_view_cache cvc
INNER JOIN panel_view pv ON cvc.id = pv.chart_view_id INNER JOIN panel_view pv ON cvc.id = pv.chart_view_id
......
...@@ -15,12 +15,16 @@ public interface ExtPanelGroupMapper { ...@@ -15,12 +15,16 @@ public interface ExtPanelGroupMapper {
//会级联删除pid 下的所有数据 //会级联删除pid 下的所有数据
int deleteCircle(@Param("pid") String pid); int deleteCircle(@Param("pid") String pid);
int deleteCircleView(@Param("pid") String pid);
int deleteCircleViewCache(@Param("pid") String pid);
PanelGroupDTO findOneWithPrivileges(@Param("panelId") String panelId,@Param("userId") String userId); PanelGroupDTO findOneWithPrivileges(@Param("panelId") String panelId,@Param("userId") String userId);
void copyPanelView(@Param("pid") String panelId); void copyPanelView(@Param("pid") String panelId);
//移除未使用的视图 //移除未使用的视图
void removeUselessViews(@Param("panelId") String panelId); void removeUselessViews(@Param("panelId") String panelId,@Param("viewIds") List<String> viewIds);
List<PanelGroupDTO> panelGroupInit(); List<PanelGroupDTO> panelGroupInit();
......
...@@ -171,6 +171,14 @@ ...@@ -171,6 +171,14 @@
delete from panel_group where FIND_IN_SET(panel_group.id,GET_PANEL_GROUP_WITH_CHILDREN(#{pid})) or FIND_IN_SET(panel_group.source,GET_PANEL_GROUP_WITH_CHILDREN(#{pid})) delete from panel_group where FIND_IN_SET(panel_group.id,GET_PANEL_GROUP_WITH_CHILDREN(#{pid})) or FIND_IN_SET(panel_group.source,GET_PANEL_GROUP_WITH_CHILDREN(#{pid}))
</delete> </delete>
<delete id="deleteCircleView">
delete from chart_view where FIND_IN_SET(chart_view.scene_id,GET_PANEL_GROUP_WITH_CHILDREN(#{pid}))
</delete>
<delete id="deleteCircleViewCache">
delete from chart_view_cache where FIND_IN_SET(chart_view_cache.scene_id,GET_PANEL_GROUP_WITH_CHILDREN(#{pid}))
</delete>
<insert id="copyPanelView"> <insert id="copyPanelView">
INSERT INTO panel_view ( id, panel_id, chart_view_id ) SELECT INSERT INTO panel_view ( id, panel_id, chart_view_id ) SELECT
uuid(), uuid(),
...@@ -189,14 +197,13 @@ ...@@ -189,14 +197,13 @@
WHERE WHERE
chart_view.chart_type = 'private' chart_view.chart_type = 'private'
AND chart_view.scene_id = #{panelId} AND chart_view.scene_id = #{panelId}
AND id NOT IN ( <if test="viewIds != null and viewIds.size>0">
SELECT AND id NOT IN
panel_view.chart_view_id <foreach collection="viewIds" item="viewId" open="(" separator="," close=")" >
FROM #{viewId}
panel_view </foreach>
WHERE </if>
panel_view.panel_id = #{panelId}
)
</delete> </delete>
</mapper> </mapper>
...@@ -39,6 +39,7 @@ import org.apache.commons.collections4.CollectionUtils; ...@@ -39,6 +39,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils; import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal; import java.math.BigDecimal;
...@@ -98,7 +99,6 @@ public class ChartViewService { ...@@ -98,7 +99,6 @@ public class ChartViewService {
chartView.setCreateTime(timestamp); chartView.setCreateTime(timestamp);
chartView.setUpdateTime(timestamp); chartView.setUpdateTime(timestamp);
chartViewMapper.insertSelective(chartView); chartViewMapper.insertSelective(chartView);
// 新建的视图也存入缓存表中 // 新建的视图也存入缓存表中
extChartViewMapper.copyToCache(chartView.getId()); extChartViewMapper.copyToCache(chartView.getId());
...@@ -221,6 +221,7 @@ public class ChartViewService { ...@@ -221,6 +221,7 @@ public class ChartViewService {
return extChartViewMapper.searchOneWithPrivileges(userId, id); return extChartViewMapper.searchOneWithPrivileges(userId, id);
} }
@Transactional
public ChartViewDTO getOne(String id,String queryFrom){ public ChartViewDTO getOne(String id,String queryFrom){
ChartViewDTO result; ChartViewDTO result;
//仪表板编辑页面 从缓存表中取数据 缓存表中没有数据则进行插入 //仪表板编辑页面 从缓存表中取数据 缓存表中没有数据则进行插入
...@@ -1742,6 +1743,7 @@ public class ChartViewService { ...@@ -1742,6 +1743,7 @@ 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.copyToCache(newChartId);
return newChartId; return newChartId;
} }
......
...@@ -105,9 +105,9 @@ public class PanelGroupService { ...@@ -105,9 +105,9 @@ public class PanelGroupService {
// @Transactional // @Transactional
public PanelGroup saveOrUpdate(PanelGroupRequest request) { public PanelGroup saveOrUpdate(PanelGroupRequest request) {
String panelId = request.getId(); String panelId = request.getId();
List<String> viewIds = null;
if(StringUtils.isNotEmpty(panelId)){ if(StringUtils.isNotEmpty(panelId)){
Boolean mobileLayout = panelViewService.syncPanelViews(request); viewIds = panelViewService.syncPanelViews(request);
request.setMobileLayout(mobileLayout);
} }
if (StringUtils.isEmpty(panelId)) { if (StringUtils.isEmpty(panelId)) {
// 新建 // 新建
...@@ -166,7 +166,7 @@ public class PanelGroupService { ...@@ -166,7 +166,7 @@ public class PanelGroupService {
} }
//移除没有用到的仪表板私有视图 //移除没有用到的仪表板私有视图
// extPanelGroupMapper.removeUselessViews(panelId); extPanelGroupMapper.removeUselessViews(panelId,viewIds);
return panelGroupDTOList.get(0); return panelGroupDTOList.get(0);
} }
...@@ -189,12 +189,18 @@ public class PanelGroupService { ...@@ -189,12 +189,18 @@ public class PanelGroupService {
public void deleteCircle(String id) { public void deleteCircle(String id) {
Assert.notNull(id, "id cannot be null"); Assert.notNull(id, "id cannot be null");
sysAuthService.checkTreeNoManageCount("panel", id); sysAuthService.checkTreeNoManageCount("panel", id);
//清理view 和 view cache
extPanelGroupMapper.deleteCircleView(id);
extPanelGroupMapper.deleteCircleViewCache(id);
// 同时会删除对应默认仪表盘 // 同时会删除对应默认仪表盘
extPanelGroupMapper.deleteCircle(id); extPanelGroupMapper.deleteCircle(id);
storeService.removeByPanelId(id); storeService.removeByPanelId(id);
shareService.delete(id, null); shareService.delete(id, null);
panelLinkService.deleteByResourceId(id); panelLinkService.deleteByResourceId(id);
//清理跳转信息 //清理跳转信息
extPanelLinkJumpMapper.deleteJumpTargetViewInfoWithPanel(id); extPanelLinkJumpMapper.deleteJumpTargetViewInfoWithPanel(id);
extPanelLinkJumpMapper.deleteJumpInfoWithPanel(id); extPanelLinkJumpMapper.deleteJumpInfoWithPanel(id);
......
...@@ -84,7 +84,8 @@ public class PanelViewService { ...@@ -84,7 +84,8 @@ public class PanelViewService {
} }
@Transactional(propagation = Propagation.REQUIRES_NEW) @Transactional(propagation = Propagation.REQUIRES_NEW)
public Boolean syncPanelViews(PanelGroupWithBLOBs panelGroup) { public List<String> syncPanelViews(PanelGroupWithBLOBs panelGroup) {
List<String> viewIds = new ArrayList<>();
Boolean mobileLayout = null; Boolean mobileLayout = null;
String panelId = panelGroup.getId(); String panelId = panelGroup.getId();
Assert.notNull(panelId, "panelId cannot be null"); Assert.notNull(panelId, "panelId cannot be null");
...@@ -120,12 +121,13 @@ public class PanelViewService { ...@@ -120,12 +121,13 @@ public class PanelViewService {
if (CollectionUtils.isNotEmpty(panelViewInsertDTOList)) { if (CollectionUtils.isNotEmpty(panelViewInsertDTOList)) {
extPanelViewMapper.savePanelView(panelViewInsertDTOList); extPanelViewMapper.savePanelView(panelViewInsertDTOList);
//将视图从cache表中更新到正式表中 //将视图从cache表中更新到正式表中
List<String> viewIds = panelViewInsertDTOList.stream().map(panelView ->panelView.getChartViewId()).collect(Collectors.toList()); viewIds = panelViewInsertDTOList.stream().map(panelView ->panelView.getChartViewId()).collect(Collectors.toList());
extChartViewMapper.copyCacheToView(viewIds); extChartViewMapper.copyCacheToView(viewIds);
extChartViewMapper.deleteCacheWithPanel(panelId); extChartViewMapper.deleteCacheWithPanel(panelId);
} }
} }
return mobileLayout; panelGroup.setMobileLayout(mobileLayout);
return viewIds;
} }
public List<PanelViewTableDTO> detailList(String panelId) { public List<PanelViewTableDTO> detailList(String panelId) {
......
...@@ -1281,7 +1281,8 @@ export default { ...@@ -1281,7 +1281,8 @@ export default {
drill: false, drill: false,
hasEdit: false, hasEdit: false,
quotaItemCompare: {}, quotaItemCompare: {},
showEditQuotaCompare: false showEditQuotaCompare: false,
preChartId: ''
} }
}, },
...@@ -1297,14 +1298,13 @@ export default { ...@@ -1297,14 +1298,13 @@ export default {
]) ])
}, },
watch: { watch: {
'param': function() { 'param': function(val) {
if (this.param.optType === 'new') { if (this.param.optType === 'new') {
// //
} else { } else if (this.param.id !== this.preChartId) {
this.resetDrill() this.preChartId = this.param.id
this.initFromPanel() this.chartInit()
// this.getData(this.param.id) // console.log('fromwatch:' + JSON.stringify(val))
this.getChart(this.param.id)
} }
}, },
searchField(val) { searchField(val) {
...@@ -1323,12 +1323,11 @@ export default { ...@@ -1323,12 +1323,11 @@ export default {
// this.initAreas() // this.initAreas()
}, },
mounted() { mounted() {
debugger
this.bindPluginEvent() this.bindPluginEvent()
// this.get(this.$store.state.chart.viewId);
// this.getData(this.param.id)
// this.getChart(this.param.id)
// this.myEcharts();
this.initFromPanel() this.initFromPanel()
this.chartInit()
// console.log('mounted')
}, },
activated() { activated() {
}, },
...@@ -1337,6 +1336,11 @@ export default { ...@@ -1337,6 +1336,11 @@ export default {
initFromPanel() { initFromPanel() {
this.hasEdit = (this.panelViewEditInfo[this.param.id] || false) this.hasEdit = (this.panelViewEditInfo[this.param.id] || false)
}, },
chartInit() {
this.resetDrill()
this.initFromPanel()
this.getChart(this.param.id)
},
bindPluginEvent() { bindPluginEvent() {
bus.$on('show-dimension-edit-filter', this.showDimensionEditFilter) bus.$on('show-dimension-edit-filter', this.showDimensionEditFilter)
bus.$on('show-rename', this.showRename) bus.$on('show-rename', this.showRename)
......
...@@ -225,9 +225,9 @@ ...@@ -225,9 +225,9 @@
</el-row> </el-row>
</de-main-container> </de-main-container>
<div v-if="!this.mobileLayoutStatus&&this.rightDrawOpen" class="tools-window-main"> <div v-if="!mobileLayoutStatus&&rightDrawOpen" class="tools-window-main">
<div v-if="showViewToolsAside"> <div v-if="showViewToolsAside">
<chart-edit v-if="this.curComponent" ref="chartEditRef" :edit-from="'panel'" :param="chartEditParam" /> <chart-edit v-if="curComponent" ref="chartEditRef" :edit-from="'panel'" :param="chartEditParam" />
</div> </div>
<div v-if="!showViewToolsAside"> <div v-if="!showViewToolsAside">
<el-row style="height: 40px"> <el-row style="height: 40px">
...@@ -562,6 +562,7 @@ export default { ...@@ -562,6 +562,7 @@ export default {
this.$store.commit('resetViewEditInfo') this.$store.commit('resetViewEditInfo')
}, },
mounted() { mounted() {
debugger
// this.insertToBody() // this.insertToBody()
bus.$on('component-on-drag', () => { bus.$on('component-on-drag', () => {
this.show = false this.show = false
...@@ -618,6 +619,10 @@ export default { ...@@ -618,6 +619,10 @@ export default {
initPanelData(panelId, function() { initPanelData(panelId, function() {
// 初始化视图缓存 // 初始化视图缓存
initViewCache(panelId) initViewCache(panelId)
// 初始化保存状态
setTimeout(() => {
_this.$store.commit('refreshSaveStatus')
}, 500)
// initPanelComponentsData(panelId, function(rsp) { // initPanelComponentsData(panelId, function(rsp) {
// _this.$store.commit('initPanelComponents', rsp)// 初始化仪表板组件视图数据 // _this.$store.commit('initPanelComponents', rsp)// 初始化仪表板组件视图数据
// _this.$store.commit('recordSnapshot', 'init')// 记录快照 // _this.$store.commit('recordSnapshot', 'init')// 记录快照
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论