Merge pull request #11369 from dataease/pr@dev-v2@feat_source-details-export

feat(仪表板): 支持原始明细导出
This commit is contained in:
王嘉豪 2024-08-06 10:26:34 +08:00 committed by GitHub
commit 306d419835
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 3 deletions

View File

@ -5,8 +5,10 @@ import io.dataease.api.visualization.vo.DataVisualizationVO;
import io.dataease.chart.manage.ChartDataManage;
import io.dataease.chart.manage.ChartViewManege;
import io.dataease.constant.CommonConstants;
import io.dataease.dataset.server.DatasetFieldServer;
import io.dataease.engine.constant.DeTypeConstants;
import io.dataease.exception.DEException;
import io.dataease.extensions.datasource.dto.DatasetTableFieldDTO;
import io.dataease.extensions.view.dto.ChartExtFilterDTO;
import io.dataease.extensions.view.dto.ChartExtRequest;
import io.dataease.extensions.view.dto.ChartViewDTO;
@ -45,6 +47,9 @@ public class CoreVisualizationExportManage {
@Resource
private VisualizationTemplateExtendDataManage extendDataManage;
@Resource
private DatasetFieldServer datasetFieldServer;
public File exportExcel(Long dvId, String busiFlag, List<Long> viewIdList, boolean onlyDisplay) throws Exception {
DataVisualizationVO visualization = extDataVisualizationMapper.findDvInfo(dvId, busiFlag);
if (ObjectUtils.isEmpty(visualization)) DEException.throwException("资源不存在或已经被删除...");
@ -81,7 +86,27 @@ public class CoreVisualizationExportManage {
chartViewDTO = extendDataManage.getChartDataInfo(request.getId(), request);
} else {
try {
List<String> dsHeader = null;
Integer[] dsTypes = null;
//downloadType = dataset 为下载原始名字 这里做数据转换模拟 table-info类型图表导出
if ("dataset".equals(request.getDownloadType())) {
request.setType("table-info");
request.setIsPlugin(false);
List<DatasetTableFieldDTO> sourceFields = datasetFieldServer.listByDatasetGroup(request.getTableId());
dsHeader = sourceFields.stream()
.map(DatasetTableFieldDTO::getName)
.toList();
dsTypes = sourceFields.stream()
.map(DatasetTableFieldDTO::getDeType)
.toArray(Integer[]::new);
TypeReference<List<ChartViewFieldDTO>> listTypeReference = new TypeReference<List<ChartViewFieldDTO>>(){
};
request.setXAxis(JsonUtil.parseList(JsonUtil.toJSONString(sourceFields).toString(),listTypeReference));
}
chartViewDTO = chartDataManage.calcData(request);
if ("dataset".equals(request.getDownloadType())) {
result.getData().addFirst(dsHeader);
}
} catch (Exception e) {
throw new RuntimeException(e);
}

View File

@ -41,10 +41,21 @@
icon="Download"
size="middle"
:loading="exportLoading"
@click="downloadViewDetails"
@click="downloadViewDetails('view')"
>
导出Excel
</el-button>
<el-button
class="m-button"
v-if="optType === 'details' && authShow"
link
icon="Download"
size="middle"
:loading="exportLoading"
@click="downloadViewDetails('dataset')"
>
导出原始明细
</el-button>
<el-button
class="m-button"
v-if="optType === 'details' && authShow && viewInfo.type === 'table-pivot'"
@ -275,14 +286,15 @@ const downloadViewImage = () => {
htmlToImage()
}
const downloadViewDetails = () => {
const downloadViewDetails = (downloadType = 'view') => {
const viewDataInfo = dvMainStore.getViewDataDetails(viewInfo.value.id)
const chartExtRequest = dvMainStore.getLastViewRequestInfo(viewInfo.value.id)
const chart = {
...viewInfo.value,
chartExtRequest,
data: viewDataInfo,
type: sourceViewType.value
type: sourceViewType.value,
downloadType: downloadType
}
exportLoading.value = true
exportExcelDownload(chart, () => {

View File

@ -35,4 +35,7 @@ public class ChartViewDTO extends ChartViewBaseDTO {
*/
@JsonSerialize(using = ToStringSerializer.class)
private Long sourceTableId;
// 数据下载模式 dataset 指的是现在原始数据
private String downloadType;
}