1
0

fix(web): 优化文件上传适配

This commit is contained in:
2024-11-27 18:05:15 +08:00
parent f15bcc2f53
commit aba9a1716c
16 changed files with 318 additions and 114 deletions

View File

@@ -1,5 +1,5 @@
const information = {
debug: false,
debug: true,
// baseUrl: '',
baseUrl: 'http://127.0.0.1:20080',
title: '可信供给中心',
@@ -170,6 +170,13 @@ export const userStateMapping = [
mappingItem('禁用', 'DISABLED', 'bg-danger'),
]
export const confirmationStateMapping = [
mappingItem('草稿', 'DRAFT', 'bg-primary'),
mappingItem('审查中', 'CHECKING', 'bg-warning'),
mappingItem('通过', 'NORMAL', 'bg-success'),
mappingItem('驳回', 'REJECT', 'bg-danger'),
]
function api(method, url) {
return {
method: method,
@@ -211,7 +218,47 @@ export const formInputClearable = {
clearValueOnEmpty: true,
}
export function formInputFileStatic(field, label) {
const formInputFileStaticColumns = [
{
name: 'filename',
label: '文件名',
},
{
type: 'operation',
label: '操作',
width: 140,
buttons: [
{
type: 'action',
label: '预览',
level: 'link',
icon: 'fas fa-eye'
},
{
type: 'action',
label: '下载',
level: 'link',
icon: 'fa fa-download'
}
]
}
]
export function formInputSingleFileStatic(field, label) {
return {
visibleOn: '${detail}',
type: 'control',
label: label,
required: true,
body: {
type: 'table',
source: `\${${field}|asArray}`,
columns: formInputFileStaticColumns,
}
}
}
export function formInputMultiFileStatic(field, label) {
return {
visibleOn: '${detail}',
type: 'input-table',
@@ -219,30 +266,6 @@ export function formInputFileStatic(field, label) {
name: field,
required: true,
resizable: false,
columns: [
{
name: 'filename',
label: '文件名',
},
{
type: 'operation',
label: '操作',
width: 140,
buttons: [
{
type: 'action',
label: '预览',
level: 'link',
icon: 'fas fa-eye'
},
{
type: 'action',
label: '下载',
level: 'link',
icon: 'fa fa-download'
}
]
}
]
columns: formInputFileStaticColumns,
}
}

View File

@@ -3,7 +3,7 @@ import {
apiGet,
apiPost,
formInputClearable,
formInputFileStatic,
formInputMultiFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size100MB
@@ -43,15 +43,15 @@ function detailForm() {
name: 'description',
...formInputClearable,
},
formInputFileStatic('evidenceIds', '相关材料'),
formInputMultiFileStatic('evidenceFiles', '相关材料'),
{
visibleOn: '${!detail}',
type: 'input-file',
label: '相关材料',
name: 'evidenceIds',
name: 'evidenceFiles',
multiple: true,
required: true,
extractValue: true,
joinValues: false,
...inputFileFormItemCommonOptions(undefined, size100MB),
}
]
@@ -76,7 +76,6 @@ export function permissionAddDialog() {
}
],
body: {
debug: true,
...detailForm(),
api: apiPost('${base}/confirmation/save'),
data: {
@@ -95,7 +94,6 @@ export function permissionDetailDialog(field = 'id') {
size: 'md',
actions: [],
body: {
debug: true,
...detailForm(),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
static: true,
@@ -106,3 +104,32 @@ export function permissionDetailDialog(field = 'id') {
}
}
}
export function permissionEditeDialog(field = 'id') {
return {
actionType: 'dialog',
dialog: {
title: '确权申请详情',
size: 'md',
actions: [
{
type: 'reset',
label: '重置',
},
{
type: 'submit',
label: '确定',
level: 'primary',
}
],
body: {
...detailForm(),
api: apiPost('${base}/confirmation/save'),
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
data: {
edit: true,
}
},
}
}
}

View File

@@ -3,7 +3,7 @@ import {
apiGet,
apiPost,
formInputClearable,
formInputFileStatic,
formInputSingleFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size1GB,
@@ -12,7 +12,6 @@ import {
function detailForm() {
return {
debug: true,
type: 'form',
...horizontalFormOptions(),
horizontal: {
@@ -87,7 +86,7 @@ function detailForm() {
visibleOn: "${resourceType === 'FILE'}",
type: 'fieldSet',
body: [
formInputFileStatic('file', '数据文件'),
formInputSingleFileStatic('file', '数据文件'),
{
visibleOn: "${!detail}",
type: 'input-file',
@@ -96,10 +95,8 @@ function detailForm() {
name: 'file',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.zip', size1GB),
autoFill: {
fileId: '${value}'
}
},
]
},
@@ -143,29 +140,27 @@ function detailForm() {
visibleOn: "${resourceType === 'HDFS'}",
type: 'fieldSet',
body: [
formInputFileStatic('coreSiteFile', 'core-site.xml'),
formInputSingleFileStatic('coreSiteFile', 'core-site.xml'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: 'core-site.xml',
name: 'coreSiteFile',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'),
autoFill: {
coreSiteFileId: '${value}'
}
},
formInputFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: 'hdfs-site.xml',
name: 'hdfsSiteFile',
multiple: false,
required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'),
autoFill: {
hdfsSiteFileId: '${value}'
}
},
]
},
@@ -285,17 +280,16 @@ function detailForm() {
label: 'JSON格式',
language: 'json',
},
formInputFileStatic('exampleFile', '资源示例'),
formInputSingleFileStatic('exampleFile', '资源示例'),
{
visibleOn: "${!detail}",
type: 'input-file',
label: '资源示例',
name: 'exampleFile',
description: '可以上传用于作为格式示范的样例数据',
multiple: false,
joinValues: false,
...inputFileFormItemCommonOptions(undefined, size500MB),
autoFill: {
exampleFileId: '${value}'
}
},
]
}

View File

@@ -19,6 +19,9 @@ export function resourceList() {
...resourceAddDialog()
},
],
rowSelection: {
disableOn: '${confirmationId}',
},
columns: [
{
label: '名称',
@@ -57,6 +60,7 @@ export function resourceList() {
trigger: 'hover',
buttons: [
{
disabledOn: '${confirmationId}',
type: 'action',
label: '编辑',
level: 'link',
@@ -65,7 +69,7 @@ export function resourceList() {
{
disabledOn: '${confirmationId}',
type: 'action',
label: "${IF(confirmationId, '删除(确权中)', '删除')}",
label: "删除",
confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的数据资源吗?',
actionType: 'ajax',

View File

@@ -1,5 +1,16 @@
import {apiGet, crudCommonOptions, providerOnly, userOnly} from "../../components/constants.js";
import {permissionAddDialog, permissionDetailDialog} from "../../components/permission/dialog-permission.js";
import {
apiGet,
confirmationStateMapping,
crudCommonOptions,
mappingField,
providerOnly,
userOnly
} from "../../components/constants.js";
import {
permissionAddDialog,
permissionDetailDialog,
permissionEditeDialog
} from "../../components/permission/dialog-permission.js";
export function tabPermissions() {
return {
@@ -37,6 +48,12 @@ export function tabPermissions() {
label: '描述',
name: 'description',
},
{
label: '状态',
width: 80,
align: 'center',
...mappingField('state', confirmationStateMapping)
},
{
label: '创建时间',
width: 150,
@@ -58,9 +75,49 @@ export function tabPermissions() {
...permissionDetailDialog(),
},
{
visibleOn: "${state === 'CHECKING'}",
type: 'action',
label: '编辑',
label: '撤销',
level: 'link',
confirmTitle: '确认撤销',
confirmText: '确认撤销名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/retract/${id}'),
},
{
visibleOn: "${state === 'DRAFT' || state === 'REJECT'}",
type: 'action',
label: '提交',
level: 'link',
confirmTitle: '确认提交',
confirmText: '确认提交名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/submit/${id}'),
},
{
type: 'dropdown-button',
level: 'link',
icon: 'fa fa-ellipsis-h',
hideCaret: true,
trigger: 'hover',
buttons: [
{
disabledOn: "${state === 'CHECKING'}",
type: 'action',
label: '编辑',
level: 'link',
...permissionEditeDialog(),
},
{
disabledOn: "${state === 'CHECKING'}",
type: 'action',
label: "删除",
confirmTitle: '确认删除',
confirmText: '确认删除名称为「${name}」的确权申请吗?',
actionType: 'ajax',
api: apiGet('${base}/confirmation/remove/${id}'),
},
]
},
]
},

View File

@@ -19,7 +19,7 @@ public abstract class SimpleController<ENTITY extends SimpleEntity, SAVE_ITEM, L
protected static final String DETAIL = "/detail/{id}";
protected static final String REMOVE = "/remove/{id}";
protected final SimpleService<ENTITY> service;
private final SimpleService<ENTITY> service;
public SimpleController(SimpleService<ENTITY> service) {
this.service = service;

View File

@@ -1,6 +1,13 @@
package com.eshore.gringotts.web.domain.base.entity;
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.IOException;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@@ -8,18 +15,37 @@ import lombok.NoArgsConstructor;
@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonDeserialize(using = FileInfo.FileInfoDeserializer.class)
public final class FileInfo {
private Long id;
private String id;
private String name;
private String filename;
private Long value;
private String state;
public FileInfo(DataFile dataFile) {
this.id = dataFile.getId();
this.id = dataFile.getId().toString();
this.name = dataFile.getFilename();
this.filename = dataFile.getFilename();
this.value = dataFile.getId();
this.state = "uploaded";
}
public static final class FileInfoDeserializer extends JsonDeserializer<FileInfo> {
@Override
public FileInfo deserialize(JsonParser parser, DeserializationContext context) throws IOException {
TreeNode root = parser.readValueAsTree();
if (root instanceof ObjectNode) {
ObjectNode node = (ObjectNode) root;
return new FileInfo(
node.get("id").asText(),
node.get("name").asText(),
node.get("filename").asText(),
node.get("value").asLong(),
node.get("state").asText()
);
}
return null;
}
}
}

View File

@@ -20,8 +20,8 @@ import org.eclipse.collections.api.set.ImmutableSet;
*/
@Slf4j
public abstract class SimpleService<ENTITY extends SimpleEntity> {
protected final SimpleRepository<ENTITY, Long> repository;
protected final UserService userService;
private final SimpleRepository<ENTITY, Long> repository;
private final UserService userService;
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
this.repository = repository;

View File

@@ -1,8 +1,8 @@
package com.eshore.gringotts.web.domain.confirmation.controller;
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
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.SimpleDetailItem;
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
@@ -14,6 +14,8 @@ import lombok.EqualsAndHashCode;
import lombok.extern.slf4j.Slf4j;
import org.eclipse.collections.api.factory.Sets;
import org.eclipse.collections.api.set.ImmutableSet;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -25,22 +27,36 @@ import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("confirmation")
public class ConfirmationController extends SimpleController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
private final ConfirmationService confirmationService;
private final DataResourceService dataResourceService;
private final DataFileService dataFileService;
public ConfirmationController(ConfirmationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
public ConfirmationController(ConfirmationService service, ConfirmationService confirmationService, DataResourceService dataResourceService, DataFileService dataFileService) {
super(service);
this.confirmationService = confirmationService;
this.dataResourceService = dataResourceService;
this.dataFileService = dataFileService;
}
@GetMapping("/submit/{id}")
public AmisResponse<Object> submit(@PathVariable Long id) {
confirmationService.submit(id);
return AmisResponse.responseSuccess();
}
@GetMapping("/retract/{id}")
public AmisResponse<Object> retract(@PathVariable Long id) {
confirmationService.retract(id);
return AmisResponse.responseSuccess();
}
@Override
protected Confirmation fromSaveItem(SaveItem item) {
Confirmation confirmation = new Confirmation();
confirmation.setId(item.getId());
confirmation.setDescription(item.getDescription());
confirmation.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
confirmation.setEvidences(dataFileService.list(item.getEvidenceIds()).toSet());
confirmation.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
return confirmation;
}
@@ -50,13 +66,14 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
item.setId(entity.getId());
item.setName(entity.getTarget().getName());
item.setDescription(entity.getDescription());
item.setState(entity.getState().name());
item.setCreatedUsername(entity.getCreatedUser().getUsername());
item.setCreatedTime(entity.getCreatedTime());
return item;
}
@Override
protected DetailItem toDetailItem(Confirmation entity) throws Exception {
protected DetailItem toDetailItem(Confirmation entity) {
return new DetailItem(entity);
}
@@ -65,7 +82,7 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
public static class SaveItem extends SimpleSaveItem<Confirmation> {
private Long targetId;
private String description;
private ImmutableSet<Long> evidenceIds;
private ImmutableSet<FileInfo> evidenceFiles;
}
@Data
@@ -73,31 +90,20 @@ public class ConfirmationController extends SimpleController<Confirmation, Confi
public static class ListItem extends SimpleListItem<Confirmation> {
private String name;
private String description;
private String state;
}
@Data
@EqualsAndHashCode(callSuper = true)
public static final class DetailItem extends SimpleDetailItem<Confirmation> {
private Long targetId;
public static final class DetailItem extends SaveItem {
private String targetName;
private String description;
private ImmutableSet<FileInfo> evidenceIds;
public DetailItem(Confirmation confirmation) {
this.setId(confirmation.getId());
this.setTargetId(confirmation.getTarget().getId());
this.setTargetName(confirmation.getTarget().getName());
this.setDescription(confirmation.getDescription());
this.setEvidenceIds(
Sets.immutable.ofAll(confirmation.getEvidences())
.collect(file -> new FileInfo(
file.getId(),
file.getFilename(),
file.getFilename(),
file.getId(),
"uploaded"
))
);
this.setEvidenceFiles(Sets.immutable.ofAll(confirmation.getEvidences()).collect(FileInfo::new));
}
}
}

View File

@@ -57,9 +57,13 @@ public class Confirmation extends SimpleEntity {
private Set<DataFile> evidences;
@Column(nullable = false)
@Enumerated(EnumType.STRING)
private State state = State.CHECKING;
private State state = State.DRAFT;
public enum State {
/**
* 草稿
*/
DRAFT,
/**
* 审查中
*/
@@ -69,8 +73,8 @@ public class Confirmation extends SimpleEntity {
*/
NORMAL,
/**
* 禁用
* 驳回
*/
DISABLED,
REJECT,
}
}

View File

@@ -4,7 +4,10 @@ import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
import java.util.List;
import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
/**
@@ -21,4 +24,11 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
@Override
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Confirmation> findById(Long id);
Boolean existsByTarget_Id(Long id);
@Transactional
@Modifying
@Query("update Confirmation confirmation set confirmation.state = ?2 where confirmation.id = ?1")
void updateStateById(Long id, Confirmation.State state);
}

View File

@@ -14,7 +14,32 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class ConfirmationService extends SimpleService<Confirmation> {
public ConfirmationService(ConfirmationRepository repository, UserService userService) {
super(repository, userService);
private final ConfirmationRepository confirmationRepository;
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService) {
super(confirmationRepository, userService);
this.confirmationRepository = confirmationRepository;
}
@Override
public Long save(Confirmation entity) {
if (confirmationRepository.existsByTarget_Id(entity.getTarget().getId())) {
throw new ConfirmationDuplicatedException();
}
return super.save(entity);
}
public void submit(Long id) {
confirmationRepository.updateStateById(id, Confirmation.State.CHECKING);
}
public void retract(Long id) {
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT);
}
public static final class ConfirmationDuplicatedException extends RuntimeException {
public ConfirmationDuplicatedException() {
super("数据资源已绑定确权申请,无法再次申请");
}
}
}

View File

@@ -0,0 +1,32 @@
package com.eshore.gringotts.web.domain.order.entity;
import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Table;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
/**
* 工单
*
* @author lanyuanxiaoyao
* @date 2024-11-27
*/
@Getter
@Setter
@ToString
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicUpdate
@Table(name = Constants.TABLE_PREFIX + "work_order")
public class WorkOrder extends SimpleEntity {
@Column(nullable = false)
private String name;
private String description;
}

View File

@@ -29,8 +29,6 @@ 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;
@@ -64,7 +62,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
dataResource.setDescription(item.getDescription());
dataResource.setType(type);
dataResource.setFormat(format);
dataResource.setExample(dataFileService.detail(item.getExampleFileId()));
if (ObjectUtil.isNotNull(item.getExampleFile())) {
dataResource.setExample(dataFileService.detail(item.getExampleFile().getValue()));
}
return dataResource;
}
@@ -102,8 +102,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break;
case FILE:
FileResourceType fileType = (FileResourceType) dataResource.getType();
item.setFileId(fileType.getFile().getId());
item.setFile(Lists.immutable.of(new FileInfo(fileType.getFile())));
item.setFile(new FileInfo(fileType.getFile()));
break;
case DATABASE:
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
@@ -114,10 +113,8 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break;
case HDFS:
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
item.setCoreSiteFileId(hdfsType.getCoreSite().getId());
item.setCoreSiteFile(Lists.immutable.of(new FileInfo(hdfsType.getCoreSite())));
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
item.setHdfsSiteFile(Lists.immutable.of(new FileInfo(hdfsType.getHdfsSite())));
item.setCoreSiteFile(new FileInfo(hdfsType.getCoreSite()));
item.setHdfsSiteFile(new FileInfo(hdfsType.getHdfsSite()));
break;
case FTP:
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
@@ -150,8 +147,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break;
}
if (ObjectUtil.isNotNull(dataResource.getExample())) {
item.setExampleFileId(dataResource.getExample().getId());
item.setExampleFile(Lists.immutable.of(new FileInfo(dataResource.getExample())));
item.setExampleFile(new FileInfo(dataResource.getExample()));
}
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
item.setCreatedTime(dataResource.getCreatedTime());
@@ -167,7 +163,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
break;
case FILE:
DataFile dataFile = dataFileService.detail(item.getFileId());
DataFile dataFile = dataFileService.detail(item.getFile().getValue());
type = new FileResourceType(dataFile);
break;
case DATABASE:
@@ -179,7 +175,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
);
break;
case HDFS:
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFileId()), dataFileService.detail(item.getHdfsSiteFileId()));
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFile().getValue()), dataFileService.detail(item.getHdfsSiteFile().getValue()));
break;
case FTP:
type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter());
@@ -222,13 +218,13 @@ public class DataResourceController extends SimpleController<DataResource, DataR
private String apiUrl;
private String apiUsername;
private String apiPassword;
private Long fileId;
private FileInfo file;
private String databaseType;
private String databaseJdbc;
private String databaseUsername;
private String databasePassword;
private Long coreSiteFileId;
private Long hdfsSiteFileId;
private FileInfo coreSiteFile;
private FileInfo hdfsSiteFile;
private String ftpUrl;
private String ftpUsername;
private String ftpPassword;
@@ -242,7 +238,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
private String jsonLineSchemaText;
private Map<?, ?> csvSchema;
private String csvSchemaText;
private Long exampleFileId;
private FileInfo exampleFile;
}
@Data
@@ -261,11 +257,6 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@Data
@EqualsAndHashCode(callSuper = true)
public static final class DetailItem extends SaveItem {
private Long id;
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;

View File

@@ -34,15 +34,15 @@ import org.springframework.web.multipart.MultipartFile;
*/
@RestController
@RequestMapping("/upload")
public class UploadController {
private static final Logger logger = LoggerFactory.getLogger(UploadController.class);
public class DataFileController {
private static final Logger logger = LoggerFactory.getLogger(DataFileController.class);
private final DataFileService dataFileService;
private final String uploadFolderPath;
private final String cacheFolderPath;
private final String sliceFolderPath;
public UploadController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
public DataFileController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
this.dataFileService = dataFileService;
this.uploadFolderPath = uploadConfiguration.getUploadPath();

View File

@@ -17,8 +17,13 @@ import org.springframework.stereotype.Service;
@Slf4j
@Service
public class DataFileService extends SimpleService<DataFile> {
public DataFileService(DataFileRepository repository, UserService userService) {
super(repository, userService);
private final DataFileRepository dataFileRepository;
private final UserService userService;
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
super(dataFileRepository, userService);
this.dataFileRepository = dataFileRepository;
this.userService = userService;
}
public DataFile detail(String id) {
@@ -34,17 +39,17 @@ public class DataFileService extends SimpleService<DataFile> {
User loginUser = userService.currentLoginUser();
dataFile.setCreatedUser(loginUser);
dataFile.setModifiedUser(loginUser);
return repository.save(dataFile).getId();
return dataFileRepository.save(dataFile).getId();
}
public void updateDataFile(Long id, String path, Long size, String md5) {
DataFile dataFile = repository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
DataFile dataFile = dataFileRepository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
dataFile.setSize(size);
dataFile.setMd5(md5);
dataFile.setPath(path);
User loginUser = userService.currentLoginUser();
dataFile.setModifiedUser(loginUser);
repository.save(dataFile);
dataFileRepository.save(dataFile);
}
public static final class DataFileNotFoundException extends RuntimeException {