refactor(数据大屏): 优化应用导入

This commit is contained in:
wangjiahao 2024-07-18 11:24:02 +08:00
parent d3dc8090c7
commit f87eec1e71
8 changed files with 167 additions and 106 deletions

View File

@ -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<Long,Long> dsTableIdMap = new HashMap<>();
Map<Long,Long> dsTableFieldsIdMap = new HashMap<>();
if(appData != null){
isAppSave = true;
try {
Map<Long,Long> 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<String, String> dynamicDataMap = JsonUtil.parseObject(dynamicData, Map.class);
List<ChartViewDTO> chartViews = new ArrayList<>();
Map<Long, ChartViewDTO> canvasViewInfo = new HashMap<>();
Map<Long, VisualizationTemplateExtendDataDTO> extendDataInfo = new HashMap<>();
for (Map.Entry<String, String> 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<String, String> dynamicDataMap = JsonUtil.parseObject(dynamicData, Map.class);
List<ChartViewDTO> chartViews = new ArrayList<>();
Map<Long, ChartViewDTO> canvasViewInfo = new HashMap<>();
Map<Long, VisualizationTemplateExtendDataDTO> extendDataInfo = new HashMap<>();
for (Map.Entry<String, String> 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

View File

@ -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"
></de-app-apply>
</div>
<de-fullscreen ref="fullScreeRef" show-position="dvEdit"></de-fullscreen>

View File

@ -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
})

View File

@ -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 (

View File

@ -207,8 +207,6 @@ const state = reactive({
pid: [
{
required: true,
min: 2,
max: 25,
message: '请选择所属文件夹',
trigger: 'blur'
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;