feat(web): 完成数据资源编辑接口
This commit is contained in:
@@ -13,8 +13,29 @@ const clearable = {
|
||||
clearValueOnEmpty: true,
|
||||
}
|
||||
|
||||
function inputFileFormItemUpdateFieldOptions(target) {
|
||||
let value = {}
|
||||
value[target] = '${event.data.value}'
|
||||
return {
|
||||
onEvent: {
|
||||
success: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'resource_data_form',
|
||||
args: {
|
||||
value: value
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function detailForm() {
|
||||
return {
|
||||
id: 'resource_data_form',
|
||||
type: 'form',
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
@@ -90,22 +111,21 @@ function detailForm() {
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'fileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: '数据文件',
|
||||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||||
name: 'filename',
|
||||
multiple: false,
|
||||
required: true,
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
autoFill: {
|
||||
fileId: '${value|default:undefined}'
|
||||
}
|
||||
...inputFileFormItemUpdateFieldOptions('fileId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'filename',
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -149,12 +169,6 @@ function detailForm() {
|
||||
visibleOn: "${resourceType === 'HDFS'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'coreSiteFileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
@@ -162,15 +176,13 @@ function detailForm() {
|
||||
name: 'coreSiteFilename',
|
||||
required: true,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
autoFill: {
|
||||
coreSiteFileId: '${value|default:undefined}'
|
||||
}
|
||||
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'hdfsSiteFileId',
|
||||
name: 'coreSiteFilename',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
@@ -179,9 +191,13 @@ function detailForm() {
|
||||
name: 'hdfsSiteFilename',
|
||||
required: true,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
autoFill: {
|
||||
hdfsSiteFileId: '${value|default:undefined}'
|
||||
}
|
||||
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'hdfsSiteFilename',
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -246,14 +262,7 @@ function detailForm() {
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON' && static}",
|
||||
type: 'editor',
|
||||
name: 'jsonSchemaText',
|
||||
label: 'JSON格式',
|
||||
language: 'json',
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON' && !static}",
|
||||
visibleOn: "${formatType === 'JSON' && !detail}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonSchema',
|
||||
label: 'JSON格式',
|
||||
@@ -263,14 +272,14 @@ function detailForm() {
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON_LINE' && static}",
|
||||
visibleOn: "${formatType === 'JSON' && detail}",
|
||||
type: 'editor',
|
||||
name: 'jsonLineSchemaText',
|
||||
name: 'jsonSchemaText',
|
||||
label: 'JSON格式',
|
||||
language: 'json',
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON_LINE' && !static}",
|
||||
visibleOn: "${formatType === 'JSON_LINE' && !detail}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonLineSchema',
|
||||
label: 'JSON格式',
|
||||
@@ -280,14 +289,14 @@ function detailForm() {
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'CSV' && static}",
|
||||
visibleOn: "${formatType === 'JSON_LINE' && detail}",
|
||||
type: 'editor',
|
||||
name: 'csvSchemaText',
|
||||
name: 'jsonLineSchemaText',
|
||||
label: 'JSON格式',
|
||||
language: 'json',
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'CSV' && !static}",
|
||||
visibleOn: "${formatType === 'CSV' && !detail}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'csvSchema',
|
||||
label: 'CSV格式',
|
||||
@@ -302,21 +311,26 @@ function detailForm() {
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '资源示例',
|
||||
name: 'exampleFileId',
|
||||
visibleOn: "${formatType === 'CSV' && detail}",
|
||||
type: 'editor',
|
||||
name: 'csvSchemaText',
|
||||
label: 'JSON格式',
|
||||
language: 'json',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '资源示例',
|
||||
name: 'exampleFilename',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: '资源示例',
|
||||
name: 'exampleFilename',
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||
autoFill: {
|
||||
exampleFileId: '${value|default:undefined}'
|
||||
},
|
||||
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
|
||||
},
|
||||
]
|
||||
}
|
||||
@@ -343,8 +357,10 @@ export function resourceAddDialog() {
|
||||
],
|
||||
body: {
|
||||
...detailForm(),
|
||||
debug: true,
|
||||
api: apiPost('${base}/data_resource/create'),
|
||||
api: apiPost('${base}/data_resource/save'),
|
||||
data: {
|
||||
add: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -362,7 +378,7 @@ export function resourceDetailDialog() {
|
||||
static: true,
|
||||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||||
data: {
|
||||
static: true,
|
||||
detail: true,
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -388,9 +404,11 @@ export function resourceEditeDialog() {
|
||||
],
|
||||
body: {
|
||||
...detailForm(),
|
||||
debug: true,
|
||||
api: apiPost('${base}/data_resource/update'),
|
||||
api: apiPost('${base}/data_resource/save'),
|
||||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||||
data: {
|
||||
edit: true,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -56,12 +57,12 @@ public class DataResourceController {
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
@PostMapping("/save")
|
||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
||||
log.info("Create request: {}", request);
|
||||
log.info("Save request: {}", request);
|
||||
ResourceType type = request.generateResourceType(dataFileService);
|
||||
ResourceFormat format = request.generateResourceFormat(mapper);
|
||||
dataResourceService.create(request.name, request.description, format, type, dataFileService.detail(request.exampleFileId));
|
||||
dataResourceService.create(request.id, request.name, request.description, type, format, dataFileService.detail(request.exampleFileId));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
@@ -81,24 +82,27 @@ public class DataResourceController {
|
||||
|
||||
@Data
|
||||
public static class CreateRequest {
|
||||
protected Long id;
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected Long resourceTypeId;
|
||||
protected ResourceType.Type resourceType;
|
||||
protected String apiUrl;
|
||||
protected String apiUsername;
|
||||
protected String apiPassword;
|
||||
protected String fileId;
|
||||
protected Long fileId;
|
||||
protected String databaseType;
|
||||
protected String databaseJdbc;
|
||||
protected String databaseUsername;
|
||||
protected String databasePassword;
|
||||
protected String coreSiteFileId;
|
||||
protected String hdfsSiteFileId;
|
||||
protected Long coreSiteFileId;
|
||||
protected Long hdfsSiteFileId;
|
||||
protected String ftpUrl;
|
||||
protected String ftpUsername;
|
||||
protected String ftpPassword;
|
||||
protected String ftpPath;
|
||||
protected String ftpRegexFilter;
|
||||
protected Long resourceFormatId;
|
||||
protected ResourceFormat.Type formatType;
|
||||
protected Map<?, ?> jsonSchema;
|
||||
protected String jsonSchemaText;
|
||||
@@ -106,7 +110,7 @@ public class DataResourceController {
|
||||
protected String jsonLineSchemaText;
|
||||
protected Map<?, ?> csvSchema;
|
||||
protected String csvSchemaText;
|
||||
protected String exampleFileId;
|
||||
protected Long exampleFileId;
|
||||
|
||||
public ResourceType generateResourceType(DataFileService dataFileService) {
|
||||
ResourceType type = null;
|
||||
@@ -116,7 +120,6 @@ public class DataResourceController {
|
||||
break;
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(fileId);
|
||||
log.info("{}", dataFile);
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case DATABASE:
|
||||
@@ -134,6 +137,7 @@ public class DataResourceController {
|
||||
type = new FtpResourceType(ftpUrl, ftpUsername, ftpPassword, ftpPath, ftpRegexFilter);
|
||||
break;
|
||||
}
|
||||
type.setId(resourceTypeId);
|
||||
return type;
|
||||
}
|
||||
|
||||
@@ -156,16 +160,11 @@ public class DataResourceController {
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(csvSchema));
|
||||
break;
|
||||
}
|
||||
format.setId(resourceFormatId);
|
||||
return format;
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class UpdateRequest extends CreateRequest {
|
||||
private Long id;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DataResourceListItem {
|
||||
private Long id;
|
||||
@@ -188,9 +187,12 @@ public class DataResourceController {
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public static final class DataResourceDetail extends CreateRequest {
|
||||
private Long id;
|
||||
private Long fileId;
|
||||
private String filename;
|
||||
private String coreSiteFilename;
|
||||
private String hdfsSiteFilename;
|
||||
@@ -201,7 +203,9 @@ public class DataResourceController {
|
||||
private String modifiedUsername;
|
||||
|
||||
public DataResourceDetail(ObjectMapper mapper, DataResource dataResource) throws JsonProcessingException {
|
||||
log.info("DataResourceDetail: {}", dataResource);
|
||||
this.id = dataResource.getId();
|
||||
this.resourceTypeId = dataResource.getType().getId();
|
||||
this.resourceFormatId = dataResource.getFormat().getId();
|
||||
this.name = dataResource.getName();
|
||||
this.description = dataResource.getDescription();
|
||||
this.resourceType = dataResource.getType().getResourceType();
|
||||
@@ -214,7 +218,7 @@ public class DataResourceController {
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
this.fileId = fileType.getFile().getId().toString();
|
||||
this.fileId = fileType.getFile().getId();
|
||||
this.filename = fileType.getFile().getFilename();
|
||||
break;
|
||||
case DATABASE:
|
||||
@@ -226,9 +230,9 @@ public class DataResourceController {
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getId().toString();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getId();
|
||||
this.coreSiteFilename = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId().toString();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId();
|
||||
this.hdfsSiteFilename = hdfsType.getHdfsSite().getFilename();
|
||||
break;
|
||||
case FTP:
|
||||
@@ -262,7 +266,7 @@ public class DataResourceController {
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
this.exampleFileId = dataResource.getExample().getId().toString();
|
||||
this.exampleFileId = dataResource.getExample().getId();
|
||||
this.exampleFilename = dataResource.getExample().getFilename();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.resource.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
@@ -9,8 +10,8 @@ import com.eshore.gringotts.web.domain.resource.repository.DataResourceRepositor
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import com.eshore.gringotts.web.helper.EntityHelper;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -26,6 +27,7 @@ public class DataResourceService extends SimpleService<DataResource, Long> {
|
||||
private final DataResourceRepository dataResourceRepository;
|
||||
private final ResourceTypeRepository resourceTypeRepository;
|
||||
private final ResourceFormatRepository resourceFormatRepository;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public DataResourceService(DataResourceRepository dataResourceRepository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||
@@ -41,19 +43,27 @@ public class DataResourceService extends SimpleService<DataResource, Long> {
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(String name, String description, ResourceFormat format, ResourceType type, DataFile example) {
|
||||
resourceFormatRepository.save(format);
|
||||
log.info("{}", type);
|
||||
resourceTypeRepository.save(type);
|
||||
DataResource resource = new DataResource();
|
||||
resource.setName(name);
|
||||
resource.setDescription(description);
|
||||
resource.setFormat(format);
|
||||
resource.setType(type);
|
||||
resource.setExample(example);
|
||||
User user = userService.currentLoginUser();
|
||||
resource.setCreatedUser(user);
|
||||
resource.setModifiedUser(user);
|
||||
dataResourceRepository.save(resource);
|
||||
public void create(Long id, String name, String description, ResourceType type, ResourceFormat format, DataFile example) {
|
||||
type = resourceTypeRepository.save(type);
|
||||
format = resourceFormatRepository.save(format);
|
||||
DataResource dataResource = EntityHelper.fillCreatorAndModifier(new DataResource(), userService);
|
||||
dataResource.setId(id);
|
||||
dataResource.setName(name);
|
||||
dataResource.setDescription(description);
|
||||
dataResource.setType(type);
|
||||
dataResource.setFormat(format);
|
||||
dataResource.setExample(example);
|
||||
dataResourceRepository.saveOrUpdateByNotNullProperties(dataResource);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
dataResourceRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public static final class DataResourceNotFoundException extends RuntimeException {
|
||||
public DataResourceNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的数据资源未找到", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +108,12 @@ public class UploadController {
|
||||
FileUtil.move(cacheFile, targetFile, true);
|
||||
}
|
||||
dataFileService.updateDataFile(request.uploadId, FileUtil.getAbsolutePath(targetFile), FileUtil.size(targetFile), SecureUtil.md5(targetFile));
|
||||
return AmisResponse.responseSuccess(new FinishResponse(request.uploadId.toString()));
|
||||
return AmisResponse.responseSuccess(new FinishResponse(
|
||||
request.uploadId,
|
||||
request.filename,
|
||||
request.uploadId,
|
||||
StrUtil.format("https://localhost:9090")
|
||||
));
|
||||
} else {
|
||||
throw new RuntimeException("合并文件失败");
|
||||
}
|
||||
@@ -159,6 +164,9 @@ public class UploadController {
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static final class FinishResponse {
|
||||
private String value;
|
||||
private Long id;
|
||||
private String filename;
|
||||
private Long value;
|
||||
private String url;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user