diff --git a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java index e508e2c3cc..6d5dc52075 100644 --- a/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java +++ b/core/core-backend/src/main/java/io/dataease/visualization/server/DataVisualizationServer.java @@ -172,6 +172,7 @@ public class DataVisualizationServer implements DataVisualizationApi { @Override @Transactional public String saveCanvas(DataVisualizationBaseRequest request) throws Exception{ + Boolean isAppSave = false; Long time = System.currentTimeMillis(); // 如果是应用 则新进行应用校验 数据集名称和 数据源名称校验 VisualizationExport2AppVO appData = request.getAppData(); @@ -179,6 +180,7 @@ public class DataVisualizationServer implements DataVisualizationApi { Map dsTableIdMap = new HashMap<>(); Map dsTableFieldsIdMap = new HashMap<>(); if(appData != null){ + isAppSave = true; try { Map datasourceIdMap = appData.getDatasourceInfo().stream() .collect(Collectors.toMap(AppCoreDatasourceVO::getId, AppCoreDatasourceVO::getSystemDatasourceId)); @@ -265,6 +267,13 @@ public class DataVisualizationServer implements DataVisualizationApi { Long newDvId = coreVisualizationManage.innerSave(visualizationInfo); request.setId(newDvId); // TODO 还原ID信息 + if(isAppSave){ + request.getCanvasViewInfo().forEach((key,viewInfo) ->{ + viewInfo.setTableId(dsGroupIdMap.get(viewInfo.getTableId())); + viewInfo.setDataFrom("dataset"); + }); + + } //保存图表信息 chartDataManage.saveChartViewFromVisualization(request.getComponentData(), newDvId, request.getCanvasViewInfo()); return newDvId.toString(); @@ -395,101 +404,112 @@ public class DataVisualizationServer implements DataVisualizationApi { @Override public DataVisualizationVO decompression(DataVisualizationBaseRequest request) throws Exception { - Long newDvId = IDUtils.snowID(); - String newFrom = request.getNewFrom(); - String templateStyle = null; - String templateData = null; - String dynamicData = null; - String staticResource = null; - String appDataStr = null; - String name = null; - String dvType = null; - Integer version = null; - //内部模板新建 - if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_INNER_TEMPLATE.equals(newFrom)) { - VisualizationTemplate visualizationTemplate = templateMapper.selectById(request.getTemplateId()); - templateStyle = visualizationTemplate.getTemplateStyle(); - templateData = visualizationTemplate.getTemplateData(); - dynamicData = visualizationTemplate.getDynamicData(); - name = visualizationTemplate.getName(); - dvType = visualizationTemplate.getDvType(); - version = visualizationTemplate.getVersion(); - appDataStr = visualizationTemplate.getAppData(); - // 模板市场记录 - coreOptRecentManage.saveOpt(request.getTemplateId(), OptConstants.OPT_RESOURCE_TYPE.TEMPLATE, OptConstants.OPT_TYPE.NEW); - VisualizationTemplate visualizationTemplateUpdate = new VisualizationTemplate(); - visualizationTemplateUpdate.setId(visualizationTemplate.getId()); - visualizationTemplateUpdate.setUseCount(visualizationTemplate.getUseCount() == null ? 0 : visualizationTemplate.getUseCount() + 1); - templateMapper.updateById(visualizationTemplateUpdate); - } else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_OUTER_TEMPLATE.equals(newFrom)) { - templateStyle = request.getCanvasStyleData(); - templateData = request.getComponentData(); - dynamicData = request.getDynamicData(); - staticResource = request.getStaticResource(); - name = request.getName(); - dvType = request.getType(); - } else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_MARKET_TEMPLATE.equals(newFrom)) { - TemplateManageFileDTO templateFileInfo = templateCenterManage.getTemplateFromMarket(request.getTemplateUrl()); - if (templateFileInfo == null) { - DEException.throwException("Can't find the template's info from market,please check"); - } - templateStyle = templateFileInfo.getCanvasStyleData(); - templateData = templateFileInfo.getComponentData(); - dynamicData = templateFileInfo.getDynamicData(); - staticResource = templateFileInfo.getStaticResource(); - name = templateFileInfo.getName(); - dvType = templateFileInfo.getDvType(); - version = templateFileInfo.getVersion(); - appDataStr = templateFileInfo.getAppData(); - // 模板市场记录 - coreOptRecentManage.saveOpt(request.getResourceName(), OptConstants.OPT_RESOURCE_TYPE.TEMPLATE, OptConstants.OPT_TYPE.NEW); - } - // 解析动态数据 - Map dynamicDataMap = JsonUtil.parseObject(dynamicData, Map.class); - List chartViews = new ArrayList<>(); - Map canvasViewInfo = new HashMap<>(); - Map extendDataInfo = new HashMap<>(); - for (Map.Entry entry : dynamicDataMap.entrySet()) { - String originViewId = entry.getKey(); - Object viewInfo = entry.getValue(); - try { - // 旧模板图表过滤器适配 - if (viewInfo instanceof Map && ((Map) viewInfo).get("customFilter") instanceof ArrayList) { - ((Map) viewInfo).put("customFilter", new HashMap<>()); + try{ + Long newDvId = IDUtils.snowID(); + String newFrom = request.getNewFrom(); + String templateStyle = null; + String templateData = null; + String dynamicData = null; + String staticResource = null; + String appDataStr = null; + String name = null; + String dvType = null; + Integer version = null; + //内部模板新建 + if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_INNER_TEMPLATE.equals(newFrom)) { + VisualizationTemplate visualizationTemplate = templateMapper.selectById(request.getTemplateId()); + templateStyle = visualizationTemplate.getTemplateStyle(); + templateData = visualizationTemplate.getTemplateData(); + dynamicData = visualizationTemplate.getDynamicData(); + name = visualizationTemplate.getName(); + dvType = visualizationTemplate.getDvType(); + version = visualizationTemplate.getVersion(); + appDataStr = visualizationTemplate.getAppData(); + // 模板市场记录 + coreOptRecentManage.saveOpt(request.getTemplateId(), OptConstants.OPT_RESOURCE_TYPE.TEMPLATE, OptConstants.OPT_TYPE.NEW); + VisualizationTemplate visualizationTemplateUpdate = new VisualizationTemplate(); + visualizationTemplateUpdate.setId(visualizationTemplate.getId()); + visualizationTemplateUpdate.setUseCount(visualizationTemplate.getUseCount() == null ? 0 : visualizationTemplate.getUseCount() + 1); + templateMapper.updateById(visualizationTemplateUpdate); + } else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_OUTER_TEMPLATE.equals(newFrom)) { + templateStyle = request.getCanvasStyleData(); + templateData = request.getComponentData(); + dynamicData = request.getDynamicData(); + staticResource = request.getStaticResource(); + name = request.getName(); + dvType = request.getType(); + } else if (DataVisualizationConstants.NEW_PANEL_FROM.NEW_MARKET_TEMPLATE.equals(newFrom)) { + TemplateManageFileDTO templateFileInfo = templateCenterManage.getTemplateFromMarket(request.getTemplateUrl()); + if (templateFileInfo == null) { + DEException.throwException("Can't find the template's info from market,please check"); } - } catch (Exception e) { - LogUtil.error("History Adaptor Error", e); + templateStyle = templateFileInfo.getCanvasStyleData(); + templateData = templateFileInfo.getComponentData(); + dynamicData = templateFileInfo.getDynamicData(); + staticResource = templateFileInfo.getStaticResource(); + name = templateFileInfo.getName(); + dvType = templateFileInfo.getDvType(); + version = templateFileInfo.getVersion(); + appDataStr = templateFileInfo.getAppData(); + // 模板市场记录 + coreOptRecentManage.saveOpt(request.getResourceName(), OptConstants.OPT_RESOURCE_TYPE.TEMPLATE, OptConstants.OPT_TYPE.NEW); } - String originViewData = JsonUtil.toJSONString(entry.getValue()).toString(); - ChartViewDTO chartView = JsonUtil.parseObject(originViewData, ChartViewDTO.class); - if (chartView == null) { - continue; - } - Long newViewId = IDUtils.snowID(); - chartView.setId(newViewId); - chartView.setSceneId(newDvId); - chartView.setTableId(null); - chartView.setDataFrom(CommonConstants.VIEW_DATA_FROM.TEMPLATE); - // 数据处理 1.替换viewId 2.加入模板view data数据 - VisualizationTemplateExtendDataDTO extendDataDTO = new VisualizationTemplateExtendDataDTO(newDvId, newViewId, originViewData); - extendDataInfo.put(newViewId, extendDataDTO); - templateData = templateData.replaceAll(originViewId, newViewId.toString()); if(StringUtils.isNotEmpty(appDataStr)){ - VisualizationExport2AppVO appDataFormat = JsonUtil.parse(appDataStr,VisualizationExport2AppVO.class); - Map dvInfo = JsonUtil.parse(appDataFormat.getVisualizationInfo(),Map.class); - String sourceDvId = (String) dvInfo.get("id"); - appDataStr = appDataStr.replaceAll(originViewId, newViewId.toString()).replaceAll(sourceDvId, newDvId.toString()); + VisualizationExport2AppVO appDataFormat = JsonUtil.parseObject(appDataStr,VisualizationExport2AppVO.class); + String dvInfo = appDataFormat.getVisualizationInfo(); + VisualizationBaseInfoVO baseInfoVO = JsonUtil.parseObject(dvInfo,VisualizationBaseInfoVO.class); + Long sourceDvId = baseInfoVO.getId(); + appDataStr = appDataStr.replaceAll(sourceDvId.toString(), newDvId.toString()); } - canvasViewInfo.put(chartView.getId(), chartView); - //插入模板数据 此处预先插入减少数据交互量 - VisualizationTemplateExtendData extendData = new VisualizationTemplateExtendData(); - templateExtendDataMapper.insert(BeanUtils.copyBean(extendData, extendDataDTO)); + // 解析动态数据 + Map dynamicDataMap = JsonUtil.parseObject(dynamicData, Map.class); + List chartViews = new ArrayList<>(); + Map canvasViewInfo = new HashMap<>(); + Map extendDataInfo = new HashMap<>(); + for (Map.Entry entry : dynamicDataMap.entrySet()) { + String originViewId = entry.getKey(); + Object viewInfo = entry.getValue(); + try { + // 旧模板图表过滤器适配 + if (viewInfo instanceof Map && ((Map) viewInfo).get("customFilter") instanceof ArrayList) { + ((Map) viewInfo).put("customFilter", new HashMap<>()); + } + } catch (Exception e) { + LogUtil.error("History Adaptor Error", e); + } + String originViewData = JsonUtil.toJSONString(entry.getValue()).toString(); + ChartViewDTO chartView = JsonUtil.parseObject(originViewData, ChartViewDTO.class); + if (chartView == null) { + continue; + } + Long newViewId = IDUtils.snowID(); + chartView.setId(newViewId); + chartView.setSceneId(newDvId); + chartView.setTableId(null); + chartView.setDataFrom(CommonConstants.VIEW_DATA_FROM.TEMPLATE); + // 数据处理 1.替换viewId 2.加入模板view data数据 + VisualizationTemplateExtendDataDTO extendDataDTO = new VisualizationTemplateExtendDataDTO(newDvId, newViewId, originViewData); + extendDataInfo.put(newViewId, extendDataDTO); + templateData = templateData.replaceAll(originViewId, newViewId.toString()); + if(StringUtils.isNotEmpty(appDataStr)){ + appDataStr = appDataStr.replaceAll(originViewId, newViewId.toString()); + } + canvasViewInfo.put(chartView.getId(), chartView); + //插入模板数据 此处预先插入减少数据交互量 + VisualizationTemplateExtendData extendData = new VisualizationTemplateExtendData(); + templateExtendDataMapper.insert(BeanUtils.copyBean(extendData, extendDataDTO)); + } + request.setComponentData(templateData); + request.setCanvasStyleData(templateStyle); + //Store static resource into the server + staticResourceServer.saveFilesToServe(staticResource); + return new DataVisualizationVO(newDvId, name, dvType, version, templateStyle, templateData,appDataStr, canvasViewInfo, null); + }catch (Exception e){ + e.printStackTrace(); + DEException.throwException("解析错误"); + return null; } - request.setComponentData(templateData); - request.setCanvasStyleData(templateStyle); - //Store static resource into the server - staticResourceServer.saveFilesToServe(staticResource); - return new DataVisualizationVO(newDvId, name, dvType, version, templateStyle, templateData,appDataStr, canvasViewInfo, null); + } @Override diff --git a/core/core-frontend/src/components/data-visualization/DvToolbar.vue b/core/core-frontend/src/components/data-visualization/DvToolbar.vue index b0d73c0694..afd5cde95b 100644 --- a/core/core-frontend/src/components/data-visualization/DvToolbar.vue +++ b/core/core-frontend/src/components/data-visualization/DvToolbar.vue @@ -99,13 +99,6 @@ const resourceOptFinish = param => { saveCanvasWithCheck() } } -const appOptFinish = param => { - if (param && param.opt === 'newLeaf') { - dvInfo.value.dataState = 'ready' - dvInfo.value.pid = param.pid - dvInfo.value.name = param.name - } -} const saveCanvasWithCheck = () => { const appData = dvMainStore.getAppDataInfo() @@ -382,7 +375,7 @@ const fullScreenPreview = () => { :dv-info="dvInfo" :canvas-view-info="canvasViewInfo" cur-canvas-type="dataV" - @saveApp="appOptFinish" + @saveApp="saveCanvasWithCheck" > diff --git a/core/core-frontend/src/components/de-app/AppExportForm.vue b/core/core-frontend/src/components/de-app/AppExportForm.vue index 55c5a425c4..d960b90d1f 100644 --- a/core/core-frontend/src/components/de-app/AppExportForm.vue +++ b/core/core-frontend/src/components/de-app/AppExportForm.vue @@ -169,7 +169,11 @@ const downloadApp = () => { const dsIds = [] gatherAppInfo(viewIds, dsIds) export2AppCheck({ dvId: dvInfo.value.id, viewIds, dsIds }).then(rsp => { - const params = { ...rsp.data, ...state.form } + const params = { + ...rsp.data, + ...state.form, + visualizationInfo: JSON.stringify(dvInfo.value) + } emits('downLoadApp', params) state.applyDownloadDrawer = false }) diff --git a/core/core-frontend/src/utils/canvasUtils.ts b/core/core-frontend/src/utils/canvasUtils.ts index bc11df128a..a9565adeaa 100644 --- a/core/core-frontend/src/utils/canvasUtils.ts +++ b/core/core-frontend/src/utils/canvasUtils.ts @@ -519,10 +519,7 @@ export async function decompressionPre(params, callBack) { .then(response => { const deTemplateDataTemp = response.data const sourceComponentData = JSON.parse(deTemplateDataTemp['componentData']) - let appData - if (deTemplateDataTemp['appData']) { - appData = JSON.parse(deTemplateDataTemp['appData']) - } + const appData = deTemplateDataTemp['appData'] sourceComponentData.forEach(componentItem => { // 2 为基础版本 此处需要增加仪表板矩阵密度 if ( diff --git a/core/core-frontend/src/views/common/DeAppApply.vue b/core/core-frontend/src/views/common/DeAppApply.vue index 331aed7ff2..6612e22d80 100644 --- a/core/core-frontend/src/views/common/DeAppApply.vue +++ b/core/core-frontend/src/views/common/DeAppApply.vue @@ -207,8 +207,6 @@ const state = reactive({ pid: [ { required: true, - min: 2, - max: 25, message: '请选择所属文件夹', trigger: 'blur' } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/DataVisualizationVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/DataVisualizationVO.java index 3cfb865b0e..a3df1ab27f 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/DataVisualizationVO.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/DataVisualizationVO.java @@ -186,7 +186,7 @@ public class DataVisualizationVO implements Serializable { this.canvasViewInfo = canvasViewInfo; this.extendDataInfo = extendDataInfo; if(StringUtils.isNotEmpty(appDataStr)){ - this.appData= JsonUtil.parse(appDataStr,VisualizationExport2AppVO.class); + this.appData= JsonUtil.parseObject(appDataStr,VisualizationExport2AppVO.class); } this.version = version; } diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationBaseInfoVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationBaseInfoVO.java new file mode 100644 index 0000000000..997a24ebb3 --- /dev/null +++ b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationBaseInfoVO.java @@ -0,0 +1,48 @@ +package io.dataease.api.visualization.vo; + +import com.fasterxml.jackson.databind.annotation.JsonSerialize; +import com.fasterxml.jackson.databind.ser.std.ToStringSerializer; +import lombok.Data; + + +@Data +public class VisualizationBaseInfoVO { + + @JsonSerialize(using = ToStringSerializer.class) + private Long id; + + private String name; + + private String label; + + private String nodeType; + + @JsonSerialize(using = ToStringSerializer.class) + private Long pid; + + /** + * 移动端布局 + */ + private String mobileLayout; + + /** + * 创建时间 + */ + private Long createTime; + + /** + * 创建人 + */ + private String createBy; + + /** + * 更新时间 + */ + private Long updateTime; + + /** + * 更新人 + */ + private String updateBy; + +} diff --git a/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationExport2AppVO.java b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationExport2AppVO.java index a365ef8514..9ea473773b 100644 --- a/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationExport2AppVO.java +++ b/sdk/api/api-base/src/main/java/io/dataease/api/visualization/vo/VisualizationExport2AppVO.java @@ -1,6 +1,7 @@ package io.dataease.api.visualization.vo; import com.google.gson.Gson; +import io.dataease.api.visualization.request.DataVisualizationBaseRequest; import lombok.Data; import java.util.ArrayList;