diff --git a/gringotts-frontend/components/constants.js b/gringotts-frontend/components/constants.js index cafda85..4d10d94 100644 --- a/gringotts-frontend/components/constants.js +++ b/gringotts-frontend/components/constants.js @@ -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, diff --git a/gringotts-frontend/components/permission/dialog-permission.js b/gringotts-frontend/components/permission/dialog-permission.js index 5ff14ae..d9a5a19 100644 --- a/gringotts-frontend/components/permission/dialog-permission.js +++ b/gringotts-frontend/components/permission/dialog-permission.js @@ -43,7 +43,7 @@ function detailForm() { name: 'description', ...formInputClearable, }, - formInputFileStatic('evidenceIds'), + formInputFileStatic('evidenceIds', '相关材料'), { visibleOn: '${!detail}', type: 'input-file', diff --git a/gringotts-frontend/components/resource/dialog-resource.js b/gringotts-frontend/components/resource/dialog-resource.js index f5d776d..7c829d2 100644 --- a/gringotts-frontend/components/resource/dialog-resource.js +++ b/gringotts-frontend/components/resource/dialog-resource.js @@ -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}' + } }, ] } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/FileInfo.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/FileInfo.java index 956e700..e4e4a55 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/FileInfo.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/entity/FileInfo.java @@ -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"; + } } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java index b25f56a..acb0bd0 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/base/service/SimpleService.java @@ -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 { protected final SimpleRepository repository; protected final UserService userService; @@ -26,12 +30,23 @@ public abstract class SimpleService { @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(); } diff --git a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java index ea9ae79..7bbd30d 100644 --- a/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java +++ b/gringotts-web/src/main/java/com/eshore/gringotts/web/domain/resource/controller/DataResourceController.java @@ -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 { - 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 file; + private ImmutableList coreSiteFile; + private ImmutableList hdfsSiteFile; + private ImmutableList exampleFile; private LocalDateTime createdTime; private String createdUsername; private LocalDateTime modifiedTime;