1
0

fix(web): 修复文件无法移除

This commit is contained in:
2024-11-27 11:11:00 +08:00
parent d72ebfd1d1
commit 70d5a4549f
6 changed files with 91 additions and 96 deletions

View File

@@ -211,11 +211,11 @@ export const formInputClearable = {
clearValueOnEmpty: true,
}
export function formInputFileStatic(field) {
export function formInputFileStatic(field, label) {
return {
visibleOn: '${detail}',
type: 'input-table',
label: '相关材料',
label: label,
name: field,
required: true,
resizable: false,

View File

@@ -43,7 +43,7 @@ function detailForm() {
name: 'description',
...formInputClearable,
},
formInputFileStatic('evidenceIds'),
formInputFileStatic('evidenceIds', '相关材料'),
{
visibleOn: '${!detail}',
type: 'input-file',

View File

@@ -3,35 +3,16 @@ import {
apiGet,
apiPost,
formInputClearable,
formInputFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size1GB,
size500MB
} 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() {
return {
id: 'resource_data_form',
debug: true,
type: 'form',
...horizontalFormOptions(),
horizontal: {
@@ -106,22 +87,19 @@ function detailForm() {
visibleOn: "${resourceType === 'FILE'}",
type: 'fieldSet',
body: [
formInputFileStatic('file', '数据文件'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: '数据文件',
description: '只适合小于1GB的资源文件使用大文件请使用其他资源类型',
name: 'filename',
name: 'file',
multiple: false,
required: true,
...inputFileFormItemCommonOptions('.zip', size1GB),
...inputFileFormItemUpdateFieldOptions('fileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'filename',
autoFill: {
fileId: '${value}'
}
},
]
},
@@ -165,35 +143,29 @@ function detailForm() {
visibleOn: "${resourceType === 'HDFS'}",
type: 'fieldSet',
body: [
formInputFileStatic('coreSiteFile', 'core-site.xml'),
{
visibleOn: "${!static}",
visibleOn: "${!detail}",
type: 'input-file',
label: 'core-site.xml',
name: 'coreSiteFilename',
name: 'coreSiteFile',
required: true,
...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
autoFill: {
coreSiteFileId: '${value}'
}
},
formInputFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'coreSiteFilename',
},
{
visibleOn: "${!static}",
visibleOn: "${!detail}",
type: 'input-file',
label: 'hdfs-site.xml',
name: 'hdfsSiteFilename',
name: 'hdfsSiteFile',
required: true,
...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'hdfsSiteFilename',
autoFill: {
hdfsSiteFileId: '${value}'
}
},
]
},
@@ -313,20 +285,17 @@ function detailForm() {
label: 'JSON格式',
language: 'json',
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '资源示例',
name: 'exampleFilename',
},
formInputFileStatic('exampleFile', '资源示例'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: '资源示例',
name: 'exampleFilename',
name: 'exampleFile',
description: '可以上传用于作为格式示范的样例数据',
...inputFileFormItemCommonOptions(undefined, size500MB),
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
autoFill: {
exampleFileId: '${value}'
}
},
]
}

View File

@@ -1,5 +1,6 @@
package com.eshore.gringotts.web.domain.base.entity;
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -13,4 +14,12 @@ public final class FileInfo {
private String filename;
private Long value;
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";
}
}

View File

@@ -1,5 +1,7 @@
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.StrUtil;
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 java.util.Optional;
import javax.transaction.Transactional;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.ImmutableSet;
@@ -15,6 +18,7 @@ import org.eclipse.collections.api.set.ImmutableSet;
* @author lanyuanxiaoyao
* @date 2024-11-21
*/
@Slf4j
public abstract class SimpleService<ENTITY extends SimpleEntity> {
protected final SimpleRepository<ENTITY, Long> repository;
protected final UserService userService;
@@ -26,12 +30,23 @@ public abstract class SimpleService<ENTITY extends SimpleEntity> {
@Transactional(rollbackOn = Throwable.class)
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();
if (ObjectUtil.isNull(entity.getCreatedUser())) {
entity.setCreatedUser(user);
}
entity.setModifiedUser(user);
entity = repository.saveOrUpdateByNotNullProperties(entity);
entity = repository.save(entity);
return entity.getId();
}

View File

@@ -3,6 +3,7 @@ package com.eshore.gringotts.web.domain.resource.controller;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.ObjectUtil;
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.SimpleSaveItem;
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
@@ -28,6 +29,8 @@ import java.util.Map;
import lombok.Data;
import lombok.EqualsAndHashCode;
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.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -97,7 +100,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
case FILE:
FileResourceType fileType = (FileResourceType) dataResource.getType();
item.setFileId(fileType.getFile().getId());
item.setFilename(fileType.getFile().getFilename());
item.setFile(Lists.immutable.of(new FileInfo(fileType.getFile())));
break;
case DATABASE:
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
@@ -109,9 +112,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
case HDFS:
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
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.setHdfsSiteFilename(hdfsType.getHdfsSite().getFilename());
item.setHdfsSiteFile(Lists.immutable.of(new FileInfo(hdfsType.getHdfsSite())));
break;
case FTP:
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
@@ -145,7 +148,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
}
if (ObjectUtil.isNotNull(dataResource.getExample())) {
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.setCreatedTime(dataResource.getCreatedTime());
@@ -209,34 +212,34 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@Data
@EqualsAndHashCode(callSuper = true)
public static class SaveItem extends SimpleSaveItem<DataResource> {
protected String name;
protected String description;
protected Long resourceTypeId;
protected ResourceType.Type resourceType;
protected String apiUrl;
protected String apiUsername;
protected String apiPassword;
protected Long fileId;
protected String databaseType;
protected String databaseJdbc;
protected String databaseUsername;
protected String databasePassword;
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;
protected Map<?, ?> jsonLineSchema;
protected String jsonLineSchemaText;
protected Map<?, ?> csvSchema;
protected String csvSchemaText;
protected Long exampleFileId;
private String name;
private String description;
private Long resourceTypeId;
private ResourceType.Type resourceType;
private String apiUrl;
private String apiUsername;
private String apiPassword;
private Long fileId;
private String databaseType;
private String databaseJdbc;
private String databaseUsername;
private String databasePassword;
private Long coreSiteFileId;
private Long hdfsSiteFileId;
private String ftpUrl;
private String ftpUsername;
private String ftpPassword;
private String ftpPath;
private String ftpRegexFilter;
private Long resourceFormatId;
private ResourceFormat.Type formatType;
private Map<?, ?> jsonSchema;
private String jsonSchemaText;
private Map<?, ?> jsonLineSchema;
private String jsonLineSchemaText;
private Map<?, ?> csvSchema;
private String csvSchemaText;
private Long exampleFileId;
}
@Data
@@ -255,11 +258,10 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@EqualsAndHashCode(callSuper = true)
public static final class DetailItem extends SaveItem {
private Long id;
private Long fileId;
private String filename;
private String coreSiteFilename;
private String hdfsSiteFilename;
private String exampleFilename;
private ImmutableList<FileInfo> file;
private ImmutableList<FileInfo> coreSiteFile;
private ImmutableList<FileInfo> hdfsSiteFile;
private ImmutableList<FileInfo> exampleFile;
private LocalDateTime createdTime;
private String createdUsername;
private LocalDateTime modifiedTime;