|
|
package com.anjiplus.template.gaea.business.modules.export.service.impl;
|
|
|
|
|
|
import com.anjiplus.template.gaea.business.modules.dashboard.dao.entity.ReportDashboard;
|
|
|
import com.anjiplus.template.gaea.business.modules.dashboard.service.ReportDashboardService;
|
|
|
import com.anjiplus.template.gaea.business.modules.dashboardwidget.dao.entity.ReportDashboardWidget;
|
|
|
import com.anjiplus.template.gaea.business.modules.dashboardwidget.service.ReportDashboardWidgetService;
|
|
|
import com.anjiplus.template.gaea.business.modules.dataset.dao.entity.DataSet;
|
|
|
import com.anjiplus.template.gaea.business.modules.dataset.service.DataSetService;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasetparam.dao.entity.DataSetParam;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasetparam.service.DataSetParamService;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasettransform.dao.entity.DataSetTransform;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasettransform.service.DataSetTransformService;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasource.dao.entity.DataSource;
|
|
|
import com.anjiplus.template.gaea.business.modules.datasource.service.DataSourceService;
|
|
|
import com.anjiplus.template.gaea.business.modules.export.service.ExportService;
|
|
|
import com.anjiplus.template.gaea.business.modules.report.dao.entity.Report;
|
|
|
import com.anjiplus.template.gaea.business.modules.report.service.ReportService;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
/**
|
|
|
* @author lzc
|
|
|
* @version 1.0
|
|
|
* @date 2022-06-21 11:03
|
|
|
*/
|
|
|
@Service
|
|
|
public class ExportServiceImpl implements ExportService {
|
|
|
|
|
|
private final ReportService reportService;
|
|
|
private final ReportDashboardService reportDashboardService;
|
|
|
private final ReportDashboardWidgetService reportDashboardWidgetService;
|
|
|
private final DataSetService dataSetService;
|
|
|
private final DataSetParamService dataSetParamService;
|
|
|
private final DataSetTransformService dataSetTransformService;
|
|
|
private final DataSourceService dataSourceService;
|
|
|
|
|
|
public ExportServiceImpl(ReportService reportService, ReportDashboardService reportDashboardService, ReportDashboardWidgetService reportDashboardWidgetService, DataSetService dataSetService, DataSetParamService dataSetParamService, DataSetTransformService dataSetTransformService, DataSourceService dataSourceService) {
|
|
|
this.reportService = reportService;
|
|
|
this.reportDashboardService = reportDashboardService;
|
|
|
this.reportDashboardWidgetService = reportDashboardWidgetService;
|
|
|
this.dataSetService = dataSetService;
|
|
|
this.dataSetParamService = dataSetParamService;
|
|
|
this.dataSetTransformService = dataSetTransformService;
|
|
|
this.dataSourceService = dataSourceService;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public List<Report> export(List<String> reportCodeList) {
|
|
|
//大屏
|
|
|
List<Report> reportList = reportService.list(new LambdaQueryWrapper<Report>()
|
|
|
.in(Report::getReportCode, reportCodeList));
|
|
|
if (reportList == null || reportList.size() == 0) {
|
|
|
return reportList;
|
|
|
}
|
|
|
//大屏配置
|
|
|
reportCodeList = reportList.stream().map(Report::getReportCode).collect(Collectors.toList());
|
|
|
List<ReportDashboard> reportDashboardList = reportDashboardService.list(new LambdaQueryWrapper<ReportDashboard>()
|
|
|
.in(ReportDashboard::getReportCode, reportCodeList));
|
|
|
//大屏组件
|
|
|
List<ReportDashboardWidget> reportDashboardWidgetList = reportDashboardWidgetService.list(new LambdaQueryWrapper<ReportDashboardWidget>()
|
|
|
.in(ReportDashboardWidget::getReportCode, reportCodeList));
|
|
|
//组件中的接口地址
|
|
|
List<String> setCodeList = new ArrayList<>();
|
|
|
reportDashboardWidgetList.stream().filter(item -> item.getData().contains("setCode")).forEach(item -> {
|
|
|
String data = item.getData();
|
|
|
int startIndex = data.indexOf("setCode");
|
|
|
int endIndex = data.indexOf(",", startIndex);
|
|
|
String setCode = data.substring(startIndex + 10, endIndex - 1);
|
|
|
setCodeList.add(setCode);
|
|
|
item.setSetCode(setCode);
|
|
|
});
|
|
|
if (setCodeList.size() == 0) {
|
|
|
return reportList;
|
|
|
}
|
|
|
//接口地址
|
|
|
List<DataSet> dataSetList = dataSetService.list(new LambdaQueryWrapper<DataSet>()
|
|
|
.in(DataSet::getSetCode, setCodeList));
|
|
|
if (dataSetList == null || dataSetList.size() == 0) {
|
|
|
return reportList;
|
|
|
}
|
|
|
//接口参数
|
|
|
List<String> setCodes = dataSetList.stream().map(DataSet::getSetCode).collect(Collectors.toList());
|
|
|
List<DataSetParam> dataSetParamList = dataSetParamService.list(new LambdaQueryWrapper<DataSetParam>()
|
|
|
.in(DataSetParam::getSetCode, setCodes));
|
|
|
//数据转换
|
|
|
List<DataSetTransform> dataSetTransformList = dataSetTransformService.list(new LambdaQueryWrapper<DataSetTransform>()
|
|
|
.in(DataSetTransform::getSetCode, setCodes));
|
|
|
//数据源
|
|
|
List<String> sourceCodeList = dataSetList.stream().map(DataSet::getSourceCode).distinct().collect(Collectors.toList());
|
|
|
List<DataSource> dataSourceList = dataSourceService.list(new LambdaQueryWrapper<DataSource>()
|
|
|
.in(DataSource::getSourceCode, sourceCodeList));
|
|
|
//组合大屏组件
|
|
|
Map<String, List<ReportDashboard>> reportDashboardMap = reportDashboardList.stream().collect(Collectors.groupingBy(ReportDashboard::getReportCode));
|
|
|
Map<String, List<ReportDashboardWidget>> reportDashboardWidgetMap = reportDashboardWidgetList.stream().collect(Collectors.groupingBy(ReportDashboardWidget::getReportCode));
|
|
|
for (Report report : reportList) {
|
|
|
if (reportDashboardMap.get(report.getReportCode()) != null) {
|
|
|
report.setReportDashboardList(reportDashboardMap.get(report.getReportCode()));
|
|
|
}
|
|
|
if (reportDashboardWidgetMap.get(report.getReportCode()) != null) {
|
|
|
report.setReportDashboardWidgetList(reportDashboardWidgetMap.get(report.getReportCode()));
|
|
|
}
|
|
|
}
|
|
|
//组合组件接口
|
|
|
Map<String, List<DataSet>> dataSetMap = dataSetList.stream().collect(Collectors.groupingBy(DataSet::getSetCode));
|
|
|
reportDashboardWidgetList.stream().filter(item -> item.getData().contains("setCode")).forEach(reportDashboardWidget -> {
|
|
|
if (dataSetMap.get(reportDashboardWidget.getSetCode()) != null) {
|
|
|
reportDashboardWidget.getDataSetList().addAll(dataSetMap.get(reportDashboardWidget.getSetCode()));
|
|
|
}
|
|
|
});
|
|
|
//组合接口参数转换数据源
|
|
|
Map<String, List<DataSetTransform>> dataSetTransformMap = dataSetTransformList.stream().collect(Collectors.groupingBy(DataSetTransform::getSetCode));
|
|
|
Map<String, List<DataSetParam>> dataSetParamMap = dataSetParamList.stream().collect(Collectors.groupingBy(DataSetParam::getSetCode));
|
|
|
Map<String, List<DataSource>> dataSourceMap = dataSourceList.stream().collect(Collectors.groupingBy(DataSource::getSourceCode));
|
|
|
for (DataSet dataSet : dataSetList) {
|
|
|
if (dataSetTransformMap.get(dataSet.getSetCode()) != null) {
|
|
|
dataSet.getDataSetTransformList().addAll(dataSetTransformMap.get(dataSet.getSetCode()));
|
|
|
}
|
|
|
if (dataSetParamMap.get(dataSet.getSetCode()) != null) {
|
|
|
dataSet.getDataSetParamList().addAll(dataSetParamMap.get(dataSet.getSetCode()));
|
|
|
}
|
|
|
if (dataSourceMap.get(dataSet.getSourceCode()) != null) {
|
|
|
dataSet.getDataSourceList().addAll(dataSourceMap.get(dataSet.getSourceCode()));
|
|
|
}
|
|
|
}
|
|
|
return reportList;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void importE(List<Report> reportList) {
|
|
|
|
|
|
//新增大屏
|
|
|
if (reportList == null || reportList.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
List<String> reportCodeList = reportList.stream().map(Report::getReportCode).collect(Collectors.toList());
|
|
|
reportService.delete(new LambdaQueryWrapper<Report>().in(Report::getReportCode, reportCodeList));
|
|
|
reportService.insertBatch(reportList);
|
|
|
|
|
|
//新增大屏配置
|
|
|
List<ReportDashboard> reportDashboardList = new ArrayList<>();
|
|
|
reportList.stream().map(Report::getReportDashboardList).forEach(reportDashboardList::addAll);
|
|
|
if (reportDashboardList.size() != 0) {
|
|
|
reportDashboardService.delete(new LambdaQueryWrapper<ReportDashboard>().in(ReportDashboard::getReportCode, reportCodeList));
|
|
|
reportDashboardService.insertBatch(reportDashboardList);
|
|
|
}
|
|
|
|
|
|
//新增大屏组件
|
|
|
List<ReportDashboardWidget> reportDashboardWidgetList = new ArrayList<>();
|
|
|
reportList.stream().map(Report::getReportDashboardWidgetList).forEach(reportDashboardWidgetList::addAll);
|
|
|
if (reportDashboardWidgetList.size() == 0) {
|
|
|
return;
|
|
|
}
|
|
|
reportDashboardWidgetService.delete(new LambdaQueryWrapper<ReportDashboardWidget>().in(ReportDashboardWidget::getReportCode, reportCodeList));
|
|
|
reportDashboardWidgetService.insertBatch(reportDashboardWidgetList);
|
|
|
|
|
|
//新增数据集
|
|
|
List<String> setCodeList = reportDashboardWidgetList.stream().map(ReportDashboardWidget::getSetCode).distinct().collect(Collectors.toList());
|
|
|
List<DataSet> dataSetList = new ArrayList<>();
|
|
|
reportDashboardWidgetList.stream().map(ReportDashboardWidget::getDataSetList).forEach(dataSetList::addAll);
|
|
|
if (dataSetList.size() != 0) {
|
|
|
dataSetService.delete(new LambdaQueryWrapper<DataSet>().in(DataSet::getSetCode, setCodeList));
|
|
|
for (DataSet dataSet : dataSetList) {
|
|
|
if (StringUtils.isNotBlank(dataSet.getSourceCodeChange())) {
|
|
|
dataSet.setSourceCode(dataSet.getSourceCodeChange());
|
|
|
}
|
|
|
}
|
|
|
dataSetService.insertBatch(dataSetList);
|
|
|
}
|
|
|
|
|
|
//新增数据集参数
|
|
|
List<DataSetParam> dataSetParamList = new ArrayList<>();
|
|
|
dataSetList.stream().map(DataSet::getDataSetParamList).forEach(dataSetParamList::addAll);
|
|
|
if (dataSetParamList.size() != 0) {
|
|
|
dataSetParamService.delete(new LambdaQueryWrapper<DataSetParam>().in(DataSetParam::getSetCode, setCodeList));
|
|
|
dataSetParamService.insertBatch(dataSetParamList);
|
|
|
}
|
|
|
|
|
|
//新增数据源转换
|
|
|
List<DataSetTransform> dataSetTransformList = new ArrayList<>();
|
|
|
dataSetList.stream().map(DataSet::getDataSetTransformList).forEach(dataSetTransformList::addAll);
|
|
|
if (dataSetTransformList.size() != 0) {
|
|
|
dataSetTransformService.delete(new LambdaQueryWrapper<DataSetTransform>().in(DataSetTransform::getSetCode, setCodeList));
|
|
|
dataSetTransformService.insertBatch(dataSetTransformList);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|