fix(应用): 修复应用新建自定义数据集可能无效的问题

This commit is contained in:
wangjiahao 2022-11-07 11:06:00 +08:00
parent a446ac999b
commit b783cf42c8
3 changed files with 47 additions and 39 deletions

View File

@ -2866,7 +2866,7 @@ public class DataSetTableService {
createDorisView(TableUtils.tableName(tableId), sql);
}
public void updateDatasetInfo(DatasetTable datasetTable){
public void updateDatasetInfo(DatasetTable datasetTable) {
datasetTableMapper.updateByPrimaryKeySelective(datasetTable);
}
}

View File

@ -69,7 +69,7 @@ public class PanelAppTemplateService {
private StaticResourceService staticResourceService;
public List<PanelAppTemplateWithBLOBs> list(PanelAppTemplateRequest request) {
return extPanelAppTemplateMapper.queryBaseInfo(request.getNodeType(),request.getPid());
return extPanelAppTemplateMapper.queryBaseInfo(request.getNodeType(), request.getPid());
}
public void save(PanelAppTemplateRequest request) {
@ -81,7 +81,7 @@ public class PanelAppTemplateService {
if (StringUtils.isEmpty(requestTemplate.getNodeType())) {
requestTemplate.setNodeType("template");
}
if(StringUtils.isNotEmpty(request.getSnapshot())){
if (StringUtils.isNotEmpty(request.getSnapshot())) {
//Store static resource into the server
String snapshotName = "app-template-" + request.getId() + ".jpeg";
staticResourceService.saveSingleFileToServe(snapshotName, request.getSnapshot().replace("data:image/jpeg;base64,", ""));
@ -98,7 +98,7 @@ public class PanelAppTemplateService {
PanelAppTemplateWithBLOBs requestTemplate = new PanelAppTemplateWithBLOBs();
BeanUtils.copyBean(requestTemplate, request);
//Store static resource into the server
if(StringUtils.isNotEmpty(request.getSnapshot())){
if (StringUtils.isNotEmpty(request.getSnapshot())) {
String snapshotName = "app-template-" + request.getId() + ".jpeg";
staticResourceService.saveSingleFileToServe(snapshotName, request.getSnapshot().replace("data:image/jpeg;base64,", ""));
requestTemplate.setSnapshot("/" + UPLOAD_URL_PREFIX + '/' + snapshotName);
@ -159,7 +159,7 @@ public class PanelAppTemplateService {
}
@Transactional(rollbackFor = Exception.class)
public String applyPanel(PanelGroupRequest panelInfo, Map<String, String> chartViewsRealMap,Map<String,String> datasetsRealMap ,Map<String,String> datasetFieldsRealMap, String newPanelId, String panelName, String pid) {
public String applyPanel(PanelGroupRequest panelInfo, Map<String, String> chartViewsRealMap, Map<String, String> datasetsRealMap, Map<String, String> datasetFieldsRealMap, String newPanelId, String panelName, String pid) {
panelInfo.setId(newPanelId);
panelInfo.setPid(pid);
panelInfo.setName(panelName);
@ -200,7 +200,7 @@ public class PanelAppTemplateService {
public Map<String, String> applyDatasetField(List<DatasetTableField> datasetTableFieldsInfo, Map<String, String> datasetsRealMap) {
Map<String, String> datasetFieldsRealMap = new HashMap<>();
for (DatasetTableField datasetTableField : datasetTableFieldsInfo) {
if(datasetTableField.getExtField()!=2){
if (datasetTableField.getExtField() != 2) {
String oldId = datasetTableField.getId();
datasetTableField.setTableId(datasetsRealMap.get(datasetTableField.getTableId()));
datasetTableField.setId(null);
@ -210,7 +210,7 @@ public class PanelAppTemplateService {
}
//数据集计算字段替换
for (DatasetTableField datasetTableField : datasetTableFieldsInfo) {
if(datasetTableField.getExtField()==2){
if (datasetTableField.getExtField() == 2) {
String oldId = datasetTableField.getId();
datasetTableField.setTableId(datasetsRealMap.get(datasetTableField.getTableId()));
datasetTableField.setId(null);
@ -240,7 +240,7 @@ public class PanelAppTemplateService {
} else if (DatasetType.UNION.name().equalsIgnoreCase(datasetTable.getType())) {
dataSetTableService.createAppUnionDorisView(datasetTable.getInfo(), datasetTable.getId());
}
}else{
} else {
dataSetTableService.updateDatasetInfo(datasetTable);
}
}

View File

@ -29,7 +29,6 @@ import io.dataease.listener.util.CacheUtils;
import io.dataease.plugins.common.base.domain.*;
import io.dataease.plugins.common.base.mapper.*;
import io.dataease.plugins.common.constants.DeTypeConstants;
import io.dataease.service.chart.ChartGroupService;
import io.dataease.service.chart.ChartViewService;
import io.dataease.service.dataset.DataSetGroupService;
import io.dataease.service.dataset.DataSetTableService;
@ -38,7 +37,8 @@ import io.dataease.service.sys.SysAuthService;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.*;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.pentaho.di.core.util.UUIDUtil;
@ -233,7 +233,7 @@ public class PanelGroupService {
return panelId;
}
public void move(PanelGroupRequest request){
public void move(PanelGroupRequest request) {
PanelGroupWithBLOBs panelInfo = panelGroupMapper.selectByPrimaryKey(request.getId());
if (panelInfo.getPid().equalsIgnoreCase(request.getPid())) {
DataEaseException.throwException(Translator.get("i18n_select_diff_folder"));
@ -420,14 +420,15 @@ public class PanelGroupService {
panelGroupMapper.insertSelective(newPanel);
return newPanelId;
}
@Transactional(rollbackFor = Exception.class)
public String newPanelFromApp(PanelGroupRequest request,Map<String,String> chartViewsRealMap){
public String newPanelFromApp(PanelGroupRequest request, Map<String, String> chartViewsRealMap) {
String newPanelId = request.getId();
String templateData = request.getPanelData();
String staticResource = request.getStaticResource();
Boolean mobileLayout = panelViewService.haveMobileLayout(templateData);
for(Map.Entry<String,String> entry:chartViewsRealMap.entrySet()){
templateData = templateData.replaceAll(entry.getKey(),entry.getValue());
for (Map.Entry<String, String> entry : chartViewsRealMap.entrySet()) {
templateData = templateData.replaceAll(entry.getKey(), entry.getValue());
}
request.setMobileLayout(mobileLayout);
request.setPanelData(templateData);
@ -825,13 +826,13 @@ public class PanelGroupService {
} else if (datasourceDTOS.size() > 1) {
return new PanelExport2App(Translator.get("I18N_APP_ONE_DATASOURCE_TIPS"));
}
return new PanelExport2App(chartViewsInfo, chartViewFieldsInfo, datasetTablesInfo, datasetTableFieldsInfo, dataSetTasksInfo, datasourceDTOS,panelViews);
return new PanelExport2App(chartViewsInfo, chartViewFieldsInfo, datasetTablesInfo, datasetTableFieldsInfo, dataSetTasksInfo, datasourceDTOS, panelViews);
}
@Transactional(rollbackFor = Exception.class)
public String appApply(PanelAppTemplateApplyRequest request) throws Exception{
public String appApply(PanelAppTemplateApplyRequest request) throws Exception {
//仪表板名称校验数据集分组名称校验数据源名称校验
panelAppTemplateService.nameCheck(request,"add");
panelAppTemplateService.nameCheck(request, "add");
String newPanelId = UUIDUtil.getUUIDAsString();
// 新建数据集分组
@ -845,39 +846,46 @@ public class PanelGroupService {
//查询应用信息
PanelAppTemplateWithBLOBs appInfo = panelAppTemplateMapper.selectByPrimaryKey(request.getAppTemplateId());
//1.获取所有视图信息
List<ChartViewWithBLOBs> chartViewsInfo = gson.fromJson(appInfo.getChartViewsInfo(), new TypeToken<List<ChartViewWithBLOBs>>(){}.getType());
List<ChartViewWithBLOBs> chartViewsInfo = gson.fromJson(appInfo.getChartViewsInfo(), new TypeToken<List<ChartViewWithBLOBs>>() {
}.getType());
//2.获取视图扩展字段信息
List<ChartViewField> chartViewFieldsInfo = gson.fromJson(appInfo.getChartViewFieldsInfo(), new TypeToken<List<ChartViewField>>(){}.getType());
List<ChartViewField> chartViewFieldsInfo = gson.fromJson(appInfo.getChartViewFieldsInfo(), new TypeToken<List<ChartViewField>>() {
}.getType());
//3.获取所有数据集信息
List<DatasetTable> datasetTablesInfo = gson.fromJson(appInfo.getDatasetTablesInfo(), new TypeToken<List<DatasetTable>>(){}.getType());
List<DatasetTable> datasetTablesInfo = gson.fromJson(appInfo.getDatasetTablesInfo(), new TypeToken<List<DatasetTable>>() {
}.getType());
//4.获取所有数据集字段信息
List<DatasetTableField> datasetTableFieldsInfo = gson.fromJson(appInfo.getDatasetTableFieldsInfo(), new TypeToken<List<DatasetTableField>>(){}.getType());
List<DatasetTableField> datasetTableFieldsInfo = gson.fromJson(appInfo.getDatasetTableFieldsInfo(), new TypeToken<List<DatasetTableField>>() {
}.getType());
//5.获取所有任务信息
List<DataSetTaskDTO> dataSetTasksInfo = gson.fromJson(appInfo.getDatasetTasksInfo(), new TypeToken<List<DataSetTaskDTO>>(){}.getType());
List<DataSetTaskDTO> dataSetTasksInfo = gson.fromJson(appInfo.getDatasetTasksInfo(), new TypeToken<List<DataSetTaskDTO>>() {
}.getType());
//6.获取所有数据源信息
List<Datasource> oldDatasourceInfo = gson.fromJson(appInfo.getDatasourceInfo(), new TypeToken<List<Datasource>>(){}.getType());
List<Datasource> oldDatasourceInfo = gson.fromJson(appInfo.getDatasourceInfo(), new TypeToken<List<Datasource>>() {
}.getType());
//获取仪表板信息
PanelGroupRequest panelInfo = gson.fromJson(appInfo.getPanelInfo(),PanelGroupRequest.class);
PanelGroupRequest panelInfo = gson.fromJson(appInfo.getPanelInfo(), PanelGroupRequest.class);
//获取仪表板视图信息
List<PanelView> panelViewsInfo = gson.fromJson(appInfo.getPanelViewsInfo(), new TypeToken<List<PanelView>>(){}.getType());
List<PanelView> panelViewsInfo = gson.fromJson(appInfo.getPanelViewsInfo(), new TypeToken<List<PanelView>>() {
}.getType());
Map<String,String> datasourceRealMap = panelAppTemplateService.applyDatasource(oldDatasourceInfo,request.getDatasourceList());
Map<String, String> datasourceRealMap = panelAppTemplateService.applyDatasource(oldDatasourceInfo, request.getDatasourceList());
Map<String,String> datasetsRealMap = panelAppTemplateService.applyDataset(datasetTablesInfo,datasourceRealMap,asideDatasetGroupId);
Map<String, String> datasetsRealMap = panelAppTemplateService.applyDataset(datasetTablesInfo, datasourceRealMap, asideDatasetGroupId);
Map<String,String> datasetFieldsRealMap = panelAppTemplateService.applyDatasetField(datasetTableFieldsInfo,datasetsRealMap);
Map<String, String> datasetFieldsRealMap = panelAppTemplateService.applyDatasetField(datasetTableFieldsInfo, datasetsRealMap);
panelAppTemplateService.resetCustomAndUnionDataset(datasetTablesInfo,datasetsRealMap,datasetFieldsRealMap);
panelAppTemplateService.resetCustomAndUnionDataset(datasetTablesInfo, datasetsRealMap, datasetFieldsRealMap);
Map<String,String> chartViewsRealMap = panelAppTemplateService.applyViews(chartViewsInfo,datasetsRealMap,datasetFieldsRealMap,newPanelId);
Map<String, String> chartViewsRealMap = panelAppTemplateService.applyViews(chartViewsInfo, datasetsRealMap, datasetFieldsRealMap, newPanelId);
panelAppTemplateService.applyViewsField(chartViewFieldsInfo,chartViewsRealMap,datasetsRealMap,datasetFieldsRealMap);
panelAppTemplateService.applyViewsField(chartViewFieldsInfo, chartViewsRealMap, datasetsRealMap, datasetFieldsRealMap);
panelAppTemplateService.applyPanel(panelInfo,chartViewsRealMap,datasetsRealMap,datasetFieldsRealMap,newPanelId, request.getPanelName(), request.getPanelGroupPid());
panelAppTemplateService.applyPanel(panelInfo, chartViewsRealMap, datasetsRealMap, datasetFieldsRealMap, newPanelId, request.getPanelName(), request.getPanelGroupPid());
panelAppTemplateService.applyPanelView(panelViewsInfo,chartViewsRealMap,newPanelId);
panelAppTemplateService.applyPanelView(panelViewsInfo, chartViewsRealMap, newPanelId);
String newDatasourceId =datasourceRealMap.entrySet().stream().findFirst().get().getValue();
String newDatasourceId = datasourceRealMap.entrySet().stream().findFirst().get().getValue();
String newDatasourceName = request.getDatasourceList().get(0).getName();
@ -895,18 +903,18 @@ public class PanelGroupService {
}
@Transactional(rollbackFor = Exception.class)
public void appEdit(PanelAppTemplateApplyRequest request) throws Exception{
public void appEdit(PanelAppTemplateApplyRequest request) throws Exception {
long currentTime = System.currentTimeMillis();
String userName = AuthUtils.getUser().getUsername();
//名称校验数据集分组名称校验数据源名称校验
panelAppTemplateService.nameCheck(request,"update");
panelAppTemplateService.nameCheck(request, "update");
//仪表板移动更新名称
PanelGroup panelHistoryInfo = panelGroupMapper.selectByPrimaryKey(request.getPanelId());
String panelHistoryPid = panelHistoryInfo.getPid();
if(panelHistoryPid.equals(request.getPanelGroupPid())){
if (panelHistoryPid.equals(request.getPanelGroupPid())) {
// 未移动
checkPanelName(request.getPanelName(), request.getPanelGroupPid(), PanelConstants.OPT_TYPE_UPDATE, request.getPanelId(), "panel");
}else{
} else {
checkPanelName(request.getPanelName(), request.getPanelGroupPid(), PanelConstants.OPT_TYPE_INSERT, null, "panel");
}
panelHistoryInfo.setName(request.getPanelName());
@ -920,7 +928,7 @@ public class PanelGroupService {
DatasetGroup datasetGroup = new DatasetGroup();
datasetGroup.setName(request.getDatasetGroupName());
datasetGroup.setId(request.getDatasetGroupId());
if(datasetGroupHistoryInfo.getPid().equals(request.getDatasetGroupPid())){
if (datasetGroupHistoryInfo.getPid().equals(request.getDatasetGroupPid())) {
datasetGroup.setPid(request.getDatasetGroupPid());
}
dataSetGroupService.checkName(datasetGroup);