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