From d033387c60273da0291b2e5ec91e72df295d31d9 Mon Sep 17 00:00:00 2001 From: wangjiahao <1522128093@qq.com> Date: Tue, 26 Apr 2022 18:03:37 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=9B=B4=E6=8E=A5=E5=A4=8D=E5=88=B6tab?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E5=86=85=E9=83=A8=E8=A7=86=E5=9B=BE=E4=BE=9D?= =?UTF-8?q?=E7=84=B6=E6=98=AF=E8=BD=AF=E8=BF=9E=E6=8E=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/chart/ChartViewController.java | 13 ++++--- .../request/chart/ChartCopyBatchRequest.java | 20 +++++++++++ .../service/chart/ChartViewService.java | 35 +++++++++++++++---- frontend/src/api/chart/chart.js | 8 +++++ frontend/src/components/canvas/store/copy.js | 15 +++++++- 5 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 backend/src/main/java/io/dataease/controller/request/chart/ChartCopyBatchRequest.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 8f4604dd22..dddcbac4ce 100644 --- a/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java +++ b/backend/src/main/java/io/dataease/controller/chart/ChartViewController.java @@ -5,10 +5,7 @@ import io.dataease.auth.annotation.DePermission; import io.dataease.auth.annotation.DePermissionProxy; 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.request.chart.*; import io.dataease.controller.response.ChartDetail; import io.dataease.dto.chart.ChartViewDTO; import io.dataease.plugins.common.base.domain.ChartViewCacheWithBLOBs; @@ -23,6 +20,7 @@ import springfox.documentation.annotations.ApiIgnore; import javax.annotation.Resource; import java.util.List; +import java.util.Map; /** * @Author gin @@ -112,6 +110,13 @@ public class ChartViewController { return chartViewService.chartCopy(id, panelId); } + @DePermission(type = DePermissionType.PANEL, level = ResourceAuthLevel.PANNEL_LEVEL_MANAGE, paramIndex = 1) + @ApiOperation("批量复制") + @PostMapping("chartBatchCopy/{panelId}") + public Map chartBatchCopy(@RequestBody ChartCopyBatchRequest request, @PathVariable String panelId) { + return chartViewService.chartBatchCopy(request,panelId); + } + @ApiIgnore @GetMapping("searchAdviceSceneId/{panelId}") public String searchAdviceSceneId(@PathVariable String panelId) { diff --git a/backend/src/main/java/io/dataease/controller/request/chart/ChartCopyBatchRequest.java b/backend/src/main/java/io/dataease/controller/request/chart/ChartCopyBatchRequest.java new file mode 100644 index 0000000000..9a8248ecc9 --- /dev/null +++ b/backend/src/main/java/io/dataease/controller/request/chart/ChartCopyBatchRequest.java @@ -0,0 +1,20 @@ +package io.dataease.controller.request.chart; + +import lombok.Data; + +import java.util.HashMap; +import java.util.Map; + +/** + * Author: wangjiahao + * Date: 2022/4/26 + * Description: + */ +@Data +public class ChartCopyBatchRequest { + + private String panelId; + + private Map sourceAndTargetIds; + +} 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 c3d1e31871..4ba1f479a6 100644 --- a/backend/src/main/java/io/dataease/service/chart/ChartViewService.java +++ b/backend/src/main/java/io/dataease/service/chart/ChartViewService.java @@ -1,5 +1,6 @@ package io.dataease.service.chart; +import cn.hutool.core.lang.Assert; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import io.dataease.auth.entity.SysUserEntity; @@ -1024,13 +1025,35 @@ public class ChartViewService { return chartViewMapper.selectByPrimaryKey(id); } - public String chartCopy(String id, String panelId) { + public String chartCopy(String sourceViewId,String newViewId, String panelId) { + extChartViewMapper.chartCopy(newViewId, sourceViewId, panelId); + extChartViewMapper.copyCache(sourceViewId, newViewId); + extPanelGroupExtendDataMapper.copyExtendData(sourceViewId, newViewId, panelId); + chartViewCacheService.refreshCache(newViewId); + return newViewId; + } + + public String chartCopy(String sourceViewId, String panelId) { String newChartId = UUID.randomUUID().toString(); - extChartViewMapper.chartCopy(newChartId, id, panelId); - extChartViewMapper.copyCache(id, newChartId); - extPanelGroupExtendDataMapper.copyExtendData(id, newChartId, panelId); - chartViewCacheService.refreshCache(newChartId); - return newChartId; + return chartCopy(sourceViewId,newChartId,panelId); + } + + + /** + * @Description Copy a set of views with a given source ID and target ID + * @param request + * @param panelId + * @return + */ + public Map chartBatchCopy(ChartCopyBatchRequest request,String panelId){ + Assert.notNull(panelId,"panelId should not be null"); + Map sourceAndTargetIds = request.getSourceAndTargetIds(); + if(sourceAndTargetIds != null && !sourceAndTargetIds.isEmpty()){ + for(Map.Entry entry:sourceAndTargetIds.entrySet()){ + chartCopy(entry.getKey(),entry.getValue(),panelId); + } + } + return request.getSourceAndTargetIds(); } public String searchAdviceSceneId(String panelId) { diff --git a/frontend/src/api/chart/chart.js b/frontend/src/api/chart/chart.js index a3de990024..42ed1fdd90 100644 --- a/frontend/src/api/chart/chart.js +++ b/frontend/src/api/chart/chart.js @@ -27,6 +27,14 @@ export function chartCopy(id, panelId) { loading: false }) } +export function chartBatchCopy(params, panelId) { + return request({ + url: '/chart/view/chartBatchCopy/' + panelId, + method: 'post', + data: params, + loading: false + }) +} export function chartGroupTree(data) { return request({ url: '/chart/group/tree', diff --git a/frontend/src/components/canvas/store/copy.js b/frontend/src/components/canvas/store/copy.js index f8bcfa22c7..a8fde22975 100644 --- a/frontend/src/components/canvas/store/copy.js +++ b/frontend/src/components/canvas/store/copy.js @@ -2,7 +2,7 @@ import store from '@/store/index' import toast from '@/components/canvas/utils/toast' import generateID from '@/components/canvas/utils/generateID' import { deepCopy } from '@/components/canvas/utils/utils' -import { chartCopy } from '@/api/chart/chart' +import { chartBatchCopy, chartCopy } from '@/api/chart/chart' import { uuid } from 'vue-uuid' export default { @@ -53,6 +53,19 @@ export default { newView.propValue.viewId = res.data store.commit('addComponent', { component: newView }) }) + } if (data.type === 'de-tabs') { + const sourceAndTargetIds = {} + const newCop = deepCopy(data) + newCop.options.tabList.forEach((item) => { + if (item.content && item.content.type === 'view') { + const newViewId = uuid.v1() + sourceAndTargetIds[item.content.propValue.viewId] = newViewId + item.content.propValue.viewId = newViewId + } + }) + chartBatchCopy({ 'sourceAndTargetIds': sourceAndTargetIds }, state.panel.panelInfo.id).then((rsp) => { + store.commit('addComponent', { component: newCop }) + }) } else { const newCop = deepCopy(data) newCop.id = uuid.v1()