fix(web): 修复文件无法移除
This commit is contained in:
@@ -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";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user