fix(web): 修复文件无法移除
This commit is contained in:
@@ -211,11 +211,11 @@ export const formInputClearable = {
|
|||||||
clearValueOnEmpty: true,
|
clearValueOnEmpty: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function formInputFileStatic(field) {
|
export function formInputFileStatic(field, label) {
|
||||||
return {
|
return {
|
||||||
visibleOn: '${detail}',
|
visibleOn: '${detail}',
|
||||||
type: 'input-table',
|
type: 'input-table',
|
||||||
label: '相关材料',
|
label: label,
|
||||||
name: field,
|
name: field,
|
||||||
required: true,
|
required: true,
|
||||||
resizable: false,
|
resizable: false,
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ function detailForm() {
|
|||||||
name: 'description',
|
name: 'description',
|
||||||
...formInputClearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
formInputFileStatic('evidenceIds'),
|
formInputFileStatic('evidenceIds', '相关材料'),
|
||||||
{
|
{
|
||||||
visibleOn: '${!detail}',
|
visibleOn: '${!detail}',
|
||||||
type: 'input-file',
|
type: 'input-file',
|
||||||
|
|||||||
@@ -3,35 +3,16 @@ import {
|
|||||||
apiGet,
|
apiGet,
|
||||||
apiPost,
|
apiPost,
|
||||||
formInputClearable,
|
formInputClearable,
|
||||||
|
formInputFileStatic,
|
||||||
horizontalFormOptions,
|
horizontalFormOptions,
|
||||||
inputFileFormItemCommonOptions,
|
inputFileFormItemCommonOptions,
|
||||||
size1GB,
|
size1GB,
|
||||||
size500MB
|
size500MB
|
||||||
} from "../constants.js";
|
} from "../constants.js";
|
||||||
|
|
||||||
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',
|
debug: true,
|
||||||
type: 'form',
|
type: 'form',
|
||||||
...horizontalFormOptions(),
|
...horizontalFormOptions(),
|
||||||
horizontal: {
|
horizontal: {
|
||||||
@@ -106,22 +87,19 @@ function detailForm() {
|
|||||||
visibleOn: "${resourceType === 'FILE'}",
|
visibleOn: "${resourceType === 'FILE'}",
|
||||||
type: 'fieldSet',
|
type: 'fieldSet',
|
||||||
body: [
|
body: [
|
||||||
|
formInputFileStatic('file', '数据文件'),
|
||||||
{
|
{
|
||||||
visibleOn: "${!detail}",
|
visibleOn: "${!detail}",
|
||||||
type: 'input-file',
|
type: 'input-file',
|
||||||
label: '数据文件',
|
label: '数据文件',
|
||||||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||||||
name: 'filename',
|
name: 'file',
|
||||||
multiple: false,
|
multiple: false,
|
||||||
required: true,
|
required: true,
|
||||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||||
...inputFileFormItemUpdateFieldOptions('fileId'),
|
autoFill: {
|
||||||
},
|
fileId: '${value}'
|
||||||
{
|
}
|
||||||
visibleOn: "${detail}",
|
|
||||||
type: 'input-text',
|
|
||||||
label: '文件名称',
|
|
||||||
name: 'filename',
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -165,35 +143,29 @@ function detailForm() {
|
|||||||
visibleOn: "${resourceType === 'HDFS'}",
|
visibleOn: "${resourceType === 'HDFS'}",
|
||||||
type: 'fieldSet',
|
type: 'fieldSet',
|
||||||
body: [
|
body: [
|
||||||
|
formInputFileStatic('coreSiteFile', 'core-site.xml'),
|
||||||
{
|
{
|
||||||
visibleOn: "${!static}",
|
visibleOn: "${!detail}",
|
||||||
type: 'input-file',
|
type: 'input-file',
|
||||||
label: 'core-site.xml',
|
label: 'core-site.xml',
|
||||||
name: 'coreSiteFilename',
|
name: 'coreSiteFile',
|
||||||
required: true,
|
required: true,
|
||||||
...inputFileFormItemCommonOptions('.xml'),
|
...inputFileFormItemCommonOptions('.xml'),
|
||||||
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
|
autoFill: {
|
||||||
|
coreSiteFileId: '${value}'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
formInputFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
||||||
{
|
{
|
||||||
visibleOn: "${detail}",
|
visibleOn: "${!detail}",
|
||||||
type: 'input-text',
|
|
||||||
label: '文件名称',
|
|
||||||
name: 'coreSiteFilename',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
visibleOn: "${!static}",
|
|
||||||
type: 'input-file',
|
type: 'input-file',
|
||||||
label: 'hdfs-site.xml',
|
label: 'hdfs-site.xml',
|
||||||
name: 'hdfsSiteFilename',
|
name: 'hdfsSiteFile',
|
||||||
required: true,
|
required: true,
|
||||||
...inputFileFormItemCommonOptions('.xml'),
|
...inputFileFormItemCommonOptions('.xml'),
|
||||||
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
|
autoFill: {
|
||||||
},
|
hdfsSiteFileId: '${value}'
|
||||||
{
|
}
|
||||||
visibleOn: "${detail}",
|
|
||||||
type: 'input-text',
|
|
||||||
label: '文件名称',
|
|
||||||
name: 'hdfsSiteFilename',
|
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -313,20 +285,17 @@ function detailForm() {
|
|||||||
label: 'JSON格式',
|
label: 'JSON格式',
|
||||||
language: 'json',
|
language: 'json',
|
||||||
},
|
},
|
||||||
{
|
formInputFileStatic('exampleFile', '资源示例'),
|
||||||
visibleOn: "${detail}",
|
|
||||||
type: 'input-text',
|
|
||||||
label: '资源示例',
|
|
||||||
name: 'exampleFilename',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
visibleOn: "${!detail}",
|
visibleOn: "${!detail}",
|
||||||
type: 'input-file',
|
type: 'input-file',
|
||||||
label: '资源示例',
|
label: '资源示例',
|
||||||
name: 'exampleFilename',
|
name: 'exampleFile',
|
||||||
description: '可以上传用于作为格式示范的样例数据',
|
description: '可以上传用于作为格式示范的样例数据',
|
||||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||||
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
|
autoFill: {
|
||||||
|
exampleFileId: '${value}'
|
||||||
|
}
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.entity;
|
package com.eshore.gringotts.web.domain.base.entity;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
@@ -13,4 +14,12 @@ public final class FileInfo {
|
|||||||
private String filename;
|
private String filename;
|
||||||
private Long value;
|
private Long value;
|
||||||
private String state;
|
private String state;
|
||||||
|
|
||||||
|
public FileInfo(DataFile dataFile) {
|
||||||
|
this.id = dataFile.getId();
|
||||||
|
this.name = dataFile.getFilename();
|
||||||
|
this.filename = dataFile.getFilename();
|
||||||
|
this.value = dataFile.getId();
|
||||||
|
this.state = "uploaded";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.service;
|
package com.eshore.gringotts.web.domain.base.service;
|
||||||
|
|
||||||
|
import cn.hutool.core.bean.BeanUtil;
|
||||||
|
import cn.hutool.core.bean.copier.CopyOptions;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
@@ -8,6 +10,7 @@ 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 java.util.Optional;
|
import java.util.Optional;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.eclipse.collections.api.factory.Sets;
|
import org.eclipse.collections.api.factory.Sets;
|
||||||
import org.eclipse.collections.api.set.ImmutableSet;
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
|
||||||
@@ -15,6 +18,7 @@ import org.eclipse.collections.api.set.ImmutableSet;
|
|||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @date 2024-11-21
|
* @date 2024-11-21
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
||||||
protected final SimpleRepository<ENTITY, Long> repository;
|
protected final SimpleRepository<ENTITY, Long> repository;
|
||||||
protected final UserService userService;
|
protected final UserService userService;
|
||||||
@@ -26,12 +30,23 @@ public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
|||||||
|
|
||||||
@Transactional(rollbackOn = Throwable.class)
|
@Transactional(rollbackOn = Throwable.class)
|
||||||
public Long save(ENTITY entity) {
|
public Long save(ENTITY entity) {
|
||||||
|
if (ObjectUtil.isNotNull(entity.getId())) {
|
||||||
|
Long id = entity.getId();
|
||||||
|
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
|
||||||
|
BeanUtil.copyProperties(
|
||||||
|
entity,
|
||||||
|
targetEntity,
|
||||||
|
CopyOptions.create()
|
||||||
|
.setIgnoreProperties("id", "createdUser", "createdTime", "modifiedUser", "modifiedTime")
|
||||||
|
);
|
||||||
|
entity = targetEntity;
|
||||||
|
}
|
||||||
User user = userService.currentLoginUser();
|
User user = userService.currentLoginUser();
|
||||||
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||||
entity.setCreatedUser(user);
|
entity.setCreatedUser(user);
|
||||||
}
|
}
|
||||||
entity.setModifiedUser(user);
|
entity.setModifiedUser(user);
|
||||||
entity = repository.saveOrUpdateByNotNullProperties(entity);
|
entity = repository.save(entity);
|
||||||
return entity.getId();
|
return entity.getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.eshore.gringotts.web.domain.resource.controller;
|
|||||||
import cn.hutool.core.util.EnumUtil;
|
import cn.hutool.core.util.EnumUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||||
|
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||||
@@ -28,6 +29,8 @@ import java.util.Map;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.eclipse.collections.api.factory.Lists;
|
||||||
|
import org.eclipse.collections.api.list.ImmutableList;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
@@ -97,7 +100,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
|
|||||||
case FILE:
|
case FILE:
|
||||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||||
item.setFileId(fileType.getFile().getId());
|
item.setFileId(fileType.getFile().getId());
|
||||||
item.setFilename(fileType.getFile().getFilename());
|
item.setFile(Lists.immutable.of(new FileInfo(fileType.getFile())));
|
||||||
break;
|
break;
|
||||||
case DATABASE:
|
case DATABASE:
|
||||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||||
@@ -109,9 +112,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
|
|||||||
case HDFS:
|
case HDFS:
|
||||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||||
item.setCoreSiteFileId(hdfsType.getCoreSite().getId());
|
item.setCoreSiteFileId(hdfsType.getCoreSite().getId());
|
||||||
item.setCoreSiteFilename(hdfsType.getCoreSite().getFilename());
|
item.setCoreSiteFile(Lists.immutable.of(new FileInfo(hdfsType.getCoreSite())));
|
||||||
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
|
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
|
||||||
item.setHdfsSiteFilename(hdfsType.getHdfsSite().getFilename());
|
item.setHdfsSiteFile(Lists.immutable.of(new FileInfo(hdfsType.getHdfsSite())));
|
||||||
break;
|
break;
|
||||||
case FTP:
|
case FTP:
|
||||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||||
@@ -145,7 +148,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
|
|||||||
}
|
}
|
||||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||||
item.setExampleFileId(dataResource.getExample().getId());
|
item.setExampleFileId(dataResource.getExample().getId());
|
||||||
item.setExampleFilename(dataResource.getExample().getFilename());
|
item.setExampleFile(Lists.immutable.of(new FileInfo(dataResource.getExample())));
|
||||||
}
|
}
|
||||||
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
|
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
|
||||||
item.setCreatedTime(dataResource.getCreatedTime());
|
item.setCreatedTime(dataResource.getCreatedTime());
|
||||||
@@ -209,34 +212,34 @@ public class DataResourceController extends SimpleController<DataResource, DataR
|
|||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static class SaveItem extends SimpleSaveItem<DataResource> {
|
public static class SaveItem extends SimpleSaveItem<DataResource> {
|
||||||
protected String name;
|
private String name;
|
||||||
protected String description;
|
private String description;
|
||||||
protected Long resourceTypeId;
|
private Long resourceTypeId;
|
||||||
protected ResourceType.Type resourceType;
|
private ResourceType.Type resourceType;
|
||||||
protected String apiUrl;
|
private String apiUrl;
|
||||||
protected String apiUsername;
|
private String apiUsername;
|
||||||
protected String apiPassword;
|
private String apiPassword;
|
||||||
protected Long fileId;
|
private Long fileId;
|
||||||
protected String databaseType;
|
private String databaseType;
|
||||||
protected String databaseJdbc;
|
private String databaseJdbc;
|
||||||
protected String databaseUsername;
|
private String databaseUsername;
|
||||||
protected String databasePassword;
|
private String databasePassword;
|
||||||
protected Long coreSiteFileId;
|
private Long coreSiteFileId;
|
||||||
protected Long hdfsSiteFileId;
|
private Long hdfsSiteFileId;
|
||||||
protected String ftpUrl;
|
private String ftpUrl;
|
||||||
protected String ftpUsername;
|
private String ftpUsername;
|
||||||
protected String ftpPassword;
|
private String ftpPassword;
|
||||||
protected String ftpPath;
|
private String ftpPath;
|
||||||
protected String ftpRegexFilter;
|
private String ftpRegexFilter;
|
||||||
protected Long resourceFormatId;
|
private Long resourceFormatId;
|
||||||
protected ResourceFormat.Type formatType;
|
private ResourceFormat.Type formatType;
|
||||||
protected Map<?, ?> jsonSchema;
|
private Map<?, ?> jsonSchema;
|
||||||
protected String jsonSchemaText;
|
private String jsonSchemaText;
|
||||||
protected Map<?, ?> jsonLineSchema;
|
private Map<?, ?> jsonLineSchema;
|
||||||
protected String jsonLineSchemaText;
|
private String jsonLineSchemaText;
|
||||||
protected Map<?, ?> csvSchema;
|
private Map<?, ?> csvSchema;
|
||||||
protected String csvSchemaText;
|
private String csvSchemaText;
|
||||||
protected Long exampleFileId;
|
private Long exampleFileId;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@@ -255,11 +258,10 @@ public class DataResourceController extends SimpleController<DataResource, DataR
|
|||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
public static final class DetailItem extends SaveItem {
|
public static final class DetailItem extends SaveItem {
|
||||||
private Long id;
|
private Long id;
|
||||||
private Long fileId;
|
private ImmutableList<FileInfo> file;
|
||||||
private String filename;
|
private ImmutableList<FileInfo> coreSiteFile;
|
||||||
private String coreSiteFilename;
|
private ImmutableList<FileInfo> hdfsSiteFile;
|
||||||
private String hdfsSiteFilename;
|
private ImmutableList<FileInfo> exampleFile;
|
||||||
private String exampleFilename;
|
|
||||||
private LocalDateTime createdTime;
|
private LocalDateTime createdTime;
|
||||||
private String createdUsername;
|
private String createdUsername;
|
||||||
private LocalDateTime modifiedTime;
|
private LocalDateTime modifiedTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user