From 0c0f6d2f8b21fd2c306b7a5e8fc78e16dcf9d568 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Thu, 10 Mar 2022 11:53:18 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96=E6=96=B0?= =?UTF-8?q?=E5=BB=BA=E8=A7=86=E5=9B=BE=E6=93=8D=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/chart/ChartViewController.java | 12 ++++++-- .../request/chart/ChartViewCacheRequest.java | 15 ++++++++++ .../service/chart/ChartViewService.java | 19 ++++++++++++- .../service/panel/PanelGroupService.java | 6 ++-- frontend/src/views/chart/group/Group.vue | 2 +- frontend/src/views/chart/view/ChartEdit.vue | 2 +- frontend/src/views/panel/edit/index.vue | 28 +++++++++++-------- 7 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 backend/src/main/java/io/dataease/controller/request/chart/ChartViewCacheRequest.java diff --git a/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java b/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java index 551ee2becf..f6c2edeeb2 100644 --- a/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java +++ b/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java @@ -9,6 +9,7 @@ import io.dataease.commons.constants.DePermissionType; import io.dataease.commons.constants.ResourceAuthLevel; import io.dataease.controller.request.chart.ChartCalRequest; import io.dataease.controller.request.chart.ChartExtRequest; +import io.dataease.controller.request.chart.ChartViewCacheRequest; import io.dataease.controller.request.chart.ChartViewRequest; import io.dataease.controller.response.ChartDetail; import io.dataease.dto.chart.ChartViewDTO; @@ -36,8 +37,15 @@ public class ChartViewController { @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE) @ApiOperation("保存") @PostMapping("/save/{panelId}") - public ChartViewDTO save(@PathVariable String panelId, @RequestBody ChartViewCacheWithBLOBs chartViewWithBLOBs) { - return chartViewService.save(chartViewWithBLOBs); + public ChartViewDTO save(@PathVariable String panelId, @RequestBody ChartViewCacheRequest request) { + return chartViewService.save(request); + } + + @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE) + @ApiOperation("新建视图") + @PostMapping("/newOne/{panelId}") + public ChartViewWithBLOBs save(@PathVariable String panelId, @RequestBody ChartViewWithBLOBs chartViewWithBLOBs) { + return chartViewService.newOne(chartViewWithBLOBs); } @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE) diff --git a/backend/src/main/java/io/dataease/controller/request/chart/ChartViewCacheRequest.java b/backend/src/main/java/io/dataease/controller/request/chart/ChartViewCacheRequest.java new file mode 100644 index 0000000000..0efccb0615 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/request/chart/ChartViewCacheRequest.java @@ -0,0 +1,15 @@ +package io.dataease.controller.request.chart; + +import io.dataease.base.domain.ChartViewCacheWithBLOBs; +import lombok.Data; + +/** + * Author: wangjiahao + * Date: 2022/3/10 + * Description: + */ +@Data +public class ChartViewCacheRequest extends ChartViewCacheWithBLOBs { + + private String savePosition = "cache"; +} diff --git a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java index 1d3266e31f..f81c1b5396 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -79,7 +79,7 @@ public class ChartViewService { private ReentrantLock lock = new ReentrantLock(); // 直接保存统一到缓存表 - public ChartViewDTO save(ChartViewCacheWithBLOBs chartView) { + public ChartViewDTO save(ChartViewCacheRequest chartView) { long timestamp = System.currentTimeMillis(); chartView.setUpdateTime(timestamp); chartViewCacheMapper.updateByPrimaryKeySelective(chartView); @@ -90,6 +90,22 @@ public class ChartViewService { } + public ChartViewWithBLOBs newOne(ChartViewWithBLOBs chartView) { + long timestamp = System.currentTimeMillis(); + chartView.setUpdateTime(timestamp); + chartView.setId(UUID.randomUUID().toString()); + chartView.setCreateBy(AuthUtils.getUser().getUsername()); + chartView.setCreateTime(timestamp); + chartView.setUpdateTime(timestamp); + chartViewMapper.insertSelective(chartView); + + // 新建的视图也存入缓存表中 + extChartViewMapper.copyToCache(chartView.getId()); + + return chartView; + } + + // 直接保存统一到缓存表 public void save2Cache(ChartViewCacheWithBLOBs chartView) { long timestamp = System.currentTimeMillis(); @@ -1761,6 +1777,7 @@ public class ChartViewService { public void resetViewCache (String viewId){ extChartViewMapper.deleteViewCache(viewId); + extChartViewMapper.copyToCache(viewId); } } diff --git a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java index 18739312fd..936c035825 100644 --- a/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java +++ b/backend/src/main/java/io/dataease/service/panel/PanelGroupService.java @@ -104,9 +104,11 @@ public class PanelGroupService { @DeCleaner(DePermissionType.PANEL) // @Transactional public PanelGroup saveOrUpdate(PanelGroupRequest request) { - Boolean mobileLayout = panelViewService.syncPanelViews(request); - request.setMobileLayout(mobileLayout); String panelId = request.getId(); + if(StringUtils.isNotEmpty(panelId)){ + Boolean mobileLayout = panelViewService.syncPanelViews(request); + request.setMobileLayout(mobileLayout); + } if (StringUtils.isEmpty(panelId)) { // 新建 checkPanelName(request.getName(), request.getPid(), PanelConstants.OPT_TYPE_INSERT, null, request.getNodeType()); diff --git a/frontend/src/views/chart/group/Group.vue b/frontend/src/views/chart/group/Group.vue index ecf1bca916..688f711a6a 100644 --- a/frontend/src/views/chart/group/Group.vue +++ b/frontend/src/views/chart/group/Group.vue @@ -784,7 +784,7 @@ export default { view.extBubble = JSON.stringify([]) this.setChartDefaultOptions(view) const _this = this - post('/chart/view/save/' + this.panelInfo.id, view).then(response => { + post('/chart/view/newOne/' + this.panelInfo.id, view).then(response => { this.closeCreateChart() this.$store.dispatch('chart/setTableId', null) this.$store.dispatch('chart/setTableId', this.table.id) diff --git a/frontend/src/views/chart/view/ChartEdit.vue b/frontend/src/views/chart/view/ChartEdit.vue index b1aab2e1fe..1f9ec47efd 100644 --- a/frontend/src/views/chart/view/ChartEdit.vue +++ b/frontend/src/views/chart/view/ChartEdit.vue @@ -1,5 +1,5 @@