Merge pull request #12267 from ulleo/dev-v2

feat(X-Pack): [数据填报]支持表单数据下载
This commit is contained in:
ulleo 2024-09-18 17:52:07 +08:00 committed by GitHub
commit 5dcb310861
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 118 additions and 10 deletions

View File

@ -10,11 +10,10 @@ import io.dataease.api.chart.request.ChartExcelRequestInner;
import io.dataease.api.dataset.dto.DataSetExportRequest;
import io.dataease.api.dataset.union.DatasetGroupInfoDTO;
import io.dataease.api.dataset.union.UnionDTO;
import io.dataease.extensions.datasource.api.PluginManageApi;
import io.dataease.extensions.view.dto.DatasetRowPermissionsTreeObj;
import io.dataease.license.manage.F2CLicLimitedManage;
import io.dataease.model.ExportTaskDTO;
import io.dataease.api.export.BaseExportApi;
import io.dataease.api.permissions.dataset.dto.DataSetRowPermissionsTreeDTO;
import io.dataease.api.xpack.dataFilling.DataFillingApi;
import io.dataease.api.xpack.dataFilling.dto.DataFillFormTableDataRequest;
import io.dataease.auth.bo.TokenUserBO;
import io.dataease.chart.dao.auto.mapper.CoreChartViewMapper;
import io.dataease.chart.server.ChartDataServer;
@ -22,7 +21,6 @@ import io.dataease.dataset.dao.auto.entity.CoreDatasetGroup;
import io.dataease.dataset.dao.auto.mapper.CoreDatasetGroupMapper;
import io.dataease.dataset.manage.*;
import io.dataease.datasource.utils.DatasourceUtils;
import io.dataease.engine.constant.DeTypeConstants;
import io.dataease.engine.sql.SQLProvider;
import io.dataease.engine.trans.Field2SQLObj;
import io.dataease.engine.trans.Order2SQLObj;
@ -32,6 +30,7 @@ import io.dataease.engine.utils.Utils;
import io.dataease.exception.DEException;
import io.dataease.exportCenter.dao.auto.entity.CoreExportTask;
import io.dataease.exportCenter.dao.auto.mapper.CoreExportTaskMapper;
import io.dataease.extensions.datasource.api.PluginManageApi;
import io.dataease.extensions.datasource.dto.DatasetTableFieldDTO;
import io.dataease.extensions.datasource.dto.DatasourceRequest;
import io.dataease.extensions.datasource.dto.DatasourceSchemaDTO;
@ -39,8 +38,11 @@ import io.dataease.extensions.datasource.factory.ProviderFactory;
import io.dataease.extensions.datasource.model.SQLMeta;
import io.dataease.extensions.datasource.provider.Provider;
import io.dataease.extensions.view.dto.ColumnPermissionItem;
import io.dataease.extensions.view.dto.DatasetRowPermissionsTreeObj;
import io.dataease.i18n.Translator;
import io.dataease.license.config.XpackInteract;
import io.dataease.license.manage.F2CLicLimitedManage;
import io.dataease.model.ExportTaskDTO;
import io.dataease.system.manage.CoreUserManage;
import io.dataease.system.manage.SysParameterManage;
import io.dataease.utils.*;
@ -72,7 +74,7 @@ import java.util.stream.Collectors;
@Component
@Transactional(rollbackFor = Exception.class)
public class ExportCenterManage {
public class ExportCenterManage implements BaseExportApi {
@Resource
private CoreExportTaskMapper exportTaskMapper;
@Resource
@ -117,6 +119,13 @@ public class ExportCenterManage {
@Resource
private DatasetDataManage datasetDataManage;
@Autowired(required = false)
private DataFillingApi dataFillingApi = null;
private DataFillingApi getDataFillingApi() {
return dataFillingApi;
}
@Resource(name = "f2CLicLimitedManage")
private F2CLicLimitedManage f2CLicLimitedManage;
@ -153,7 +162,7 @@ public class ExportCenterManage {
}
private Long getExportLimit() {
return Math.min(f2CLicLimitedManage.checkDatasetLimit(),limit);
return Math.min(f2CLicLimitedManage.checkDatasetLimit(), limit);
}
public void download(String id, HttpServletResponse response) throws Exception {
@ -234,6 +243,10 @@ public class ExportCenterManage {
DataSetExportRequest request = JsonUtil.parseObject(exportTask.getParams(), DataSetExportRequest.class);
startDatasetTask(exportTask, request);
}
if (exportTask.getExportFromType().equalsIgnoreCase("data_filling")) {
HashMap request = JsonUtil.parseObject(exportTask.getParams(), HashMap.class);
startDataFillingTask(exportTask, request);
}
}
public List<ExportTaskDTO> exportTasks(String status) {
@ -279,6 +292,13 @@ public class ExportCenterManage {
List<String> finalFullName = fullName;
exportTaskDTO.setExportFromName(String.join("/", finalFullName));
}
if (exportTaskDTO.getExportFromType().equalsIgnoreCase("data_filling")) {
List<String> fullName = new ArrayList<>();
getDataFillingApi().geFullName(Long.valueOf(exportTaskDTO.getExportFrom()), fullName);
Collections.reverse(fullName);
List<String> finalFullName = fullName;
exportTaskDTO.setExportFromName(String.join("/", finalFullName));
}
}
private void setExportFromName(ExportTaskDTO exportTaskDTO) {
@ -288,6 +308,9 @@ public class ExportCenterManage {
if (exportTaskDTO.getExportFromType().equalsIgnoreCase("dataset")) {
exportTaskDTO.setExportFromName(coreDatasetGroupMapper.selectById(exportTaskDTO.getExportFrom()).getName());
}
if (exportTaskDTO.getExportFromType().equalsIgnoreCase("data_filling")) {
exportTaskDTO.setExportFromName(getDataFillingApi().get(Long.parseLong(exportTaskDTO.getExportFrom())).getName());
}
}
private String hostName() {
@ -333,6 +356,65 @@ public class ExportCenterManage {
startDatasetTask(exportTask, request);
}
@Override
public void addTask(String exportFromId, String exportFromType, HashMap<String, Object> request, Long userId, Long org) {
CoreExportTask exportTask = new CoreExportTask();
request.put("org", org);
exportTask.setId(UUID.randomUUID().toString());
exportTask.setUserId(userId);
exportTask.setExportFrom(exportFromId);
exportTask.setExportFromType(exportFromType);
exportTask.setExportStatus("PENDING");
exportTask.setFileName(request.get("name") + ".xlsx");
exportTask.setExportProgress("0");
exportTask.setExportTime(System.currentTimeMillis());
exportTask.setParams(JsonUtil.toJSONString(request).toString());
exportTask.setExportMachineName(hostName());
exportTaskMapper.insert(exportTask);
if (StringUtils.equals(exportFromType, "data_filling")) {
startDataFillingTask(exportTask, request);
}
}
private void startDataFillingTask(CoreExportTask exportTask, HashMap<String, Object> request) {
if (ObjectUtils.isEmpty(getDataFillingApi())) {
return;
}
String dataPath = exportData_path + exportTask.getId();
File directory = new File(dataPath);
boolean isCreated = directory.mkdir();
TokenUserBO tokenUserBO = AuthUtils.getUser();
Future future = scheduledThreadPoolExecutor.submit(() -> {
AuthUtils.setUser(tokenUserBO);
try {
exportTask.setExportStatus("IN_PROGRESS");
exportTaskMapper.updateById(exportTask);
getDataFillingApi().writeExcel(dataPath + "/" + exportTask.getFileName(),
new DataFillFormTableDataRequest()
.setId(Long.parseLong(exportTask.getExportFrom()))
.setWithoutLogs(true)
, exportTask.getUserId(), Long.parseLong(request.get("org").toString()));
exportTask.setExportProgress("100");
exportTask.setExportStatus("SUCCESS");
setFileSize(dataPath + "/" + exportTask.getFileName(), exportTask);
} catch (Exception e) {
exportTask.setMsg(e.getMessage());
LogUtil.error("Failed to export data", e);
exportTask.setExportStatus("FAILED");
} finally {
exportTaskMapper.updateById(exportTask);
}
});
Running_Task.put(exportTask.getId(), future);
}
private void startDatasetTask(CoreExportTask exportTask, DataSetExportRequest request) {
String dataPath = exportData_path + exportTask.getId();
File directory = new File(dataPath);
@ -395,7 +477,7 @@ public class ExportCenterManage {
}
if (StringUtils.isNotEmpty(request.getExpressionTree())) {
Gson gson = new Gson();
DatasetRowPermissionsTreeObj datasetRowPermissionsTreeObj =JsonUtil.parseObject(request.getExpressionTree(), DatasetRowPermissionsTreeObj.class);
DatasetRowPermissionsTreeObj datasetRowPermissionsTreeObj = JsonUtil.parseObject(request.getExpressionTree(), DatasetRowPermissionsTreeObj.class);
permissionManage.getField(datasetRowPermissionsTreeObj);
DataSetRowPermissionsTreeDTO dataSetRowPermissionsTreeDTO = new DataSetRowPermissionsTreeDTO();
dataSetRowPermissionsTreeDTO.setTree(datasetRowPermissionsTreeObj);

View File

@ -379,6 +379,7 @@ export default {
confirm_delete: 'Confirm delete?',
add_data: 'Add Data',
batch_upload: 'Upload Data',
download: 'Download Data',
download_template: 'Download Template',
insert_data: 'Insert Data',
update_data: 'Update Data',

View File

@ -280,6 +280,7 @@ export default {
confirm_delete: '確認刪除?',
add_data: '添加數據',
batch_upload: '批量上傳',
download: '下載',
download_template: '下載模板',
insert_data: '插入數據',
update_data: '更新數據',

View File

@ -2716,6 +2716,7 @@ export default {
confirm_delete: '确认删除?',
add_data: '添加数据',
batch_upload: '批量上传',
download: '下载',
download_template: '下载模板',
insert_data: '插入数据',
update_data: '更新数据',

View File

@ -471,6 +471,9 @@ defineExpose({
<template #default="scope">
<span v-if="scope.row.exportFromType === 'dataset'">{{ t('data_set.data_set') }}</span>
<span v-if="scope.row.exportFromType === 'chart'">{{ t('data_set.view') }}</span>
<span v-if="scope.row.exportFromType === 'data_filling'">{{
t('data_fill.data_fill')
}}</span>
</template>
</el-table-column>
<el-table-column

@ -1 +1 @@
Subproject commit 303250e24bf9c59dffe5d88898e7428ba8657751
Subproject commit 506b74bf3e9f136118d9a02bedb7a68b854c878e

View File

@ -0,0 +1,13 @@
package io.dataease.api.export;
import io.swagger.v3.oas.annotations.Hidden;
import java.util.HashMap;
@Hidden
public interface BaseExportApi {
void addTask(String exportFromId, String exportFromType, HashMap<String, Object> request, Long userId, Long org);
}

View File

@ -107,7 +107,7 @@ public interface DataFillingApi {
List<Map<String, Object>> listSubTaskUser(@PathVariable("id") Long id, @PathVariable("type") String type) throws Exception;
@PostMapping("/user-task/page/{goPage}/{pageSize}")
IPage<DfUserTaskVo> listUserTask(@PathVariable("goPage") int goPage, @PathVariable("pageSize") int pageSize,@RequestBody DfUserTaskRequest request) throws Exception;
IPage<DfUserTaskVo> listUserTask(@PathVariable("goPage") int goPage, @PathVariable("pageSize") int pageSize, @RequestBody DfUserTaskRequest request) throws Exception;
@GetMapping("/user-task/list/{id}")
DfUserTaskData listUserTaskData(@PathVariable("id") Long id) throws Exception;
@ -134,4 +134,11 @@ public interface DataFillingApi {
@GetMapping("/template/{itemId}")
String getTemplateByUserTaskItemId(@PathVariable("itemId") Long itemId);
void writeExcel(String file, DataFillFormTableDataRequest request, Long userId, Long org) throws Exception;
void geFullName(Long pid, List<String> fullName);
@PostMapping("/innerExport/{formId}")
void innerExport(@PathVariable("formId") Long formId) throws Exception;
}