1
0

5 Commits

18 changed files with 423 additions and 171 deletions

View File

@@ -1,5 +1,5 @@
const information = { const information = {
debug: false, debug: true,
// baseUrl: '', // baseUrl: '',
baseUrl: 'http://127.0.0.1:20080', baseUrl: 'http://127.0.0.1:20080',
title: '可信供给中心', title: '可信供给中心',
@@ -170,6 +170,13 @@ export const userStateMapping = [
mappingItem('禁用', 'DISABLED', 'bg-danger'), 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) { function api(method, url) {
return { return {
method: method, method: method,
@@ -210,3 +217,55 @@ export const formInputClearable = {
clearable: true, clearable: true,
clearValueOnEmpty: true, clearValueOnEmpty: true,
} }
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',
label: label,
name: field,
required: true,
resizable: false,
columns: formInputFileStaticColumns,
}
}

View File

@@ -1,27 +1,15 @@
import './dialog-permission.css' import './dialog-permission.css'
import {apiGet, apiPost, horizontalFormOptions, inputFileFormItemCommonOptions, size100MB} from "../constants.js"; import {
apiGet,
apiPost,
formInputClearable,
formInputMultiFileStatic,
horizontalFormOptions,
inputFileFormItemCommonOptions,
size100MB
} from "../constants.js";
import {resourceList} from "../../pages/index/tab-data.js"; import {resourceList} from "../../pages/index/tab-data.js";
function inputFileFormItemUpdateFieldOptions(target) {
let value = {}
value[target] = '${event.data.value}'
return {
onEvent: {
success: {
actions: [
// {
// actionType: 'setValue',
// componentId: 'permission_form',
// args: {
// value: value
// }
// }
]
}
}
}
}
function detailForm() { function detailForm() {
return { return {
id: 'permission_form', id: 'permission_form',
@@ -41,7 +29,7 @@ function detailForm() {
label: '数据资源', label: '数据资源',
required: true, required: true,
multiple: false, multiple: false,
size: 'lg', size: 'md',
valueField: 'id', valueField: 'id',
labelField: 'name', labelField: 'name',
source: apiGet('${base}/data_resource/list'), source: apiGet('${base}/data_resource/list'),
@@ -53,14 +41,17 @@ function detailForm() {
type: 'textarea', type: 'textarea',
label: '确权说明', label: '确权说明',
name: 'description', name: 'description',
...formInputClearable,
}, },
formInputMultiFileStatic('evidenceFiles', '相关材料'),
{ {
visibleOn: '${!detail}',
type: 'input-file', type: 'input-file',
label: '相关材料', label: '相关材料',
name: 'evidenceIds', name: 'evidenceFiles',
multiple: true, multiple: true,
required: true, required: true,
extractValue: true, joinValues: false,
...inputFileFormItemCommonOptions(undefined, size100MB), ...inputFileFormItemCommonOptions(undefined, size100MB),
} }
] ]
@@ -85,7 +76,6 @@ export function permissionAddDialog() {
} }
], ],
body: { body: {
debug: true,
...detailForm(), ...detailForm(),
api: apiPost('${base}/confirmation/save'), api: apiPost('${base}/confirmation/save'),
data: { data: {
@@ -96,17 +86,16 @@ export function permissionAddDialog() {
} }
} }
export function permissionDetailDialog() { export function permissionDetailDialog(field = 'id') {
return { return {
actionType: 'dialog', actionType: 'dialog',
dialog: { dialog: {
title: '新增确权申请', title: '确权申请详情',
size: 'md', size: 'md',
actions: [], actions: [],
body: { body: {
debug: true,
...detailForm(), ...detailForm(),
initApi: apiGet('${base}/confirmation/detail/${id}'), initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
static: true, static: true,
data: { data: {
detail: true, detail: true,
@@ -115,3 +104,32 @@ export function permissionDetailDialog() {
} }
} }
} }
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,35 +3,15 @@ import {
apiGet, apiGet,
apiPost, apiPost,
formInputClearable, formInputClearable,
formInputSingleFileStatic,
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',
type: 'form', type: 'form',
...horizontalFormOptions(), ...horizontalFormOptions(),
horizontal: { horizontal: {
@@ -106,22 +86,17 @@ function detailForm() {
visibleOn: "${resourceType === 'FILE'}", visibleOn: "${resourceType === 'FILE'}",
type: 'fieldSet', type: 'fieldSet',
body: [ body: [
formInputSingleFileStatic('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,
joinValues: false,
...inputFileFormItemCommonOptions('.zip', size1GB), ...inputFileFormItemCommonOptions('.zip', size1GB),
...inputFileFormItemUpdateFieldOptions('fileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'filename',
}, },
] ]
}, },
@@ -165,35 +140,27 @@ function detailForm() {
visibleOn: "${resourceType === 'HDFS'}", visibleOn: "${resourceType === 'HDFS'}",
type: 'fieldSet', type: 'fieldSet',
body: [ body: [
formInputSingleFileStatic('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',
multiple: false,
required: true, required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'), ...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
}, },
formInputSingleFileStatic('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',
multiple: false,
required: true, required: true,
joinValues: false,
...inputFileFormItemCommonOptions('.xml'), ...inputFileFormItemCommonOptions('.xml'),
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
},
{
visibleOn: "${detail}",
type: 'input-text',
label: '文件名称',
name: 'hdfsSiteFilename',
}, },
] ]
}, },
@@ -313,20 +280,16 @@ function detailForm() {
label: 'JSON格式', label: 'JSON格式',
language: 'json', language: 'json',
}, },
{ formInputSingleFileStatic('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: '可以上传用于作为格式示范的样例数据',
multiple: false,
joinValues: false,
...inputFileFormItemCommonOptions(undefined, size500MB), ...inputFileFormItemCommonOptions(undefined, size500MB),
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
}, },
] ]
} }

View File

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

View File

@@ -1,5 +1,16 @@
import {apiGet, crudCommonOptions, providerOnly, userOnly} from "../../components/constants.js"; import {
import {permissionAddDialog, permissionDetailDialog} from "../../components/permission/dialog-permission.js"; apiGet,
confirmationStateMapping,
crudCommonOptions,
mappingField,
providerOnly,
userOnly
} from "../../components/constants.js";
import {
permissionAddDialog,
permissionDetailDialog,
permissionEditeDialog
} from "../../components/permission/dialog-permission.js";
export function tabPermissions() { export function tabPermissions() {
return { return {
@@ -37,6 +48,12 @@ export function tabPermissions() {
label: '描述', label: '描述',
name: 'description', name: 'description',
}, },
{
label: '状态',
width: 80,
align: 'center',
...mappingField('state', confirmationStateMapping)
},
{ {
label: '创建时间', label: '创建时间',
width: 150, width: 150,
@@ -58,9 +75,49 @@ export function tabPermissions() {
...permissionDetailDialog(), ...permissionDetailDialog(),
}, },
{ {
visibleOn: "${state === 'CHECKING'}",
type: 'action', type: 'action',
label: '编辑', label: '撤销',
level: 'link', 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 DETAIL = "/detail/{id}";
protected static final String REMOVE = "/remove/{id}"; protected static final String REMOVE = "/remove/{id}";
protected final SimpleService<ENTITY> service; private final SimpleService<ENTITY> service;
public SimpleController(SimpleService<ENTITY> service) { public SimpleController(SimpleService<ENTITY> service) {
this.service = service; this.service = service;

View File

@@ -1,5 +1,13 @@
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 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.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@@ -7,10 +15,37 @@ import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
@JsonDeserialize(using = FileInfo.FileInfoDeserializer.class)
public final class FileInfo { public final class FileInfo {
private Long id; private String id;
private String name; private String name;
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().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

@@ -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,9 +18,10 @@ 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; private final SimpleRepository<ENTITY, Long> repository;
protected final UserService userService; private final UserService userService;
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) { public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
this.repository = repository; this.repository = repository;
@@ -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();
} }

View File

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

View File

@@ -57,9 +57,13 @@ public class Confirmation extends SimpleEntity {
private Set<DataFile> evidences; private Set<DataFile> evidences;
@Column(nullable = false) @Column(nullable = false)
@Enumerated(EnumType.STRING) @Enumerated(EnumType.STRING)
private State state = State.CHECKING; private State state = State.DRAFT;
public enum State { public enum State {
/**
* 草稿
*/
DRAFT,
/** /**
* 审查中 * 审查中
*/ */
@@ -69,8 +73,8 @@ public class Confirmation extends SimpleEntity {
*/ */
NORMAL, 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 com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import javax.transaction.Transactional;
import org.springframework.data.jpa.repository.EntityGraph; 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; import org.springframework.stereotype.Repository;
/** /**
@@ -21,4 +24,11 @@ public interface ConfirmationRepository extends SimpleRepository<Confirmation, L
@Override @Override
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH) @EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
Optional<Confirmation> findById(Long id); 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 @Slf4j
@Service @Service
public class ConfirmationService extends SimpleService<Confirmation> { public class ConfirmationService extends SimpleService<Confirmation> {
public ConfirmationService(ConfirmationRepository repository, UserService userService) { private final ConfirmationRepository confirmationRepository;
super(repository, userService);
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

@@ -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;
@@ -61,7 +62,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
dataResource.setDescription(item.getDescription()); dataResource.setDescription(item.getDescription());
dataResource.setType(type); dataResource.setType(type);
dataResource.setFormat(format); dataResource.setFormat(format);
dataResource.setExample(dataFileService.detail(item.getExampleFileId())); if (ObjectUtil.isNotNull(item.getExampleFile())) {
dataResource.setExample(dataFileService.detail(item.getExampleFile().getValue()));
}
return dataResource; return dataResource;
} }
@@ -73,6 +76,9 @@ public class DataResourceController extends SimpleController<DataResource, DataR
item.setDescription(dataResource.getDescription()); item.setDescription(dataResource.getDescription());
item.setType(dataResource.getType().getResourceType().name()); item.setType(dataResource.getType().getResourceType().name());
item.setFormat(dataResource.getFormat().getFormatType().name()); item.setFormat(dataResource.getFormat().getFormatType().name());
if (ObjectUtil.isNotNull(dataResource.getConfirmation())) {
item.setConfirmationId(dataResource.getConfirmation().getId());
}
item.setCreatedUser(dataResource.getCreatedUser().getUsername()); item.setCreatedUser(dataResource.getCreatedUser().getUsername());
item.setCreatedTime(dataResource.getCreatedTime()); item.setCreatedTime(dataResource.getCreatedTime());
return item; return item;
@@ -96,8 +102,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break; break;
case FILE: case FILE:
FileResourceType fileType = (FileResourceType) dataResource.getType(); FileResourceType fileType = (FileResourceType) dataResource.getType();
item.setFileId(fileType.getFile().getId()); item.setFile(new FileInfo(fileType.getFile()));
item.setFilename(fileType.getFile().getFilename());
break; break;
case DATABASE: case DATABASE:
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType(); DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
@@ -108,10 +113,8 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break; break;
case HDFS: case HDFS:
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType(); HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
item.setCoreSiteFileId(hdfsType.getCoreSite().getId()); item.setCoreSiteFile(new FileInfo(hdfsType.getCoreSite()));
item.setCoreSiteFilename(hdfsType.getCoreSite().getFilename()); item.setHdfsSiteFile(new FileInfo(hdfsType.getHdfsSite()));
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
item.setHdfsSiteFilename(hdfsType.getHdfsSite().getFilename());
break; break;
case FTP: case FTP:
FtpResourceType ftpType = (FtpResourceType) dataResource.getType(); FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
@@ -144,8 +147,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
break; break;
} }
if (ObjectUtil.isNotNull(dataResource.getExample())) { if (ObjectUtil.isNotNull(dataResource.getExample())) {
item.setExampleFileId(dataResource.getExample().getId()); item.setExampleFile(new FileInfo(dataResource.getExample()));
item.setExampleFilename(dataResource.getExample().getFilename());
} }
item.setCreatedUsername(dataResource.getCreatedUser().getUsername()); item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
item.setCreatedTime(dataResource.getCreatedTime()); item.setCreatedTime(dataResource.getCreatedTime());
@@ -161,7 +163,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword()); type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
break; break;
case FILE: case FILE:
DataFile dataFile = dataFileService.detail(item.getFileId()); DataFile dataFile = dataFileService.detail(item.getFile().getValue());
type = new FileResourceType(dataFile); type = new FileResourceType(dataFile);
break; break;
case DATABASE: case DATABASE:
@@ -173,7 +175,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
); );
break; break;
case HDFS: 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; break;
case FTP: case FTP:
type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter()); type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter());
@@ -209,34 +211,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 FileInfo file;
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 FileInfo coreSiteFile;
protected Long hdfsSiteFileId; private FileInfo hdfsSiteFile;
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 FileInfo exampleFile;
} }
@Data @Data
@@ -247,6 +249,7 @@ public class DataResourceController extends SimpleController<DataResource, DataR
private String description; private String description;
private String type; private String type;
private String format; private String format;
private Long confirmationId;
private String createdUser; private String createdUser;
private LocalDateTime createdTime; private LocalDateTime createdTime;
} }
@@ -254,12 +257,6 @@ public class DataResourceController extends SimpleController<DataResource, DataR
@Data @Data
@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 fileId;
private String filename;
private String coreSiteFilename;
private String hdfsSiteFilename;
private String exampleFilename;
private LocalDateTime createdTime; private LocalDateTime createdTime;
private String createdUsername; private String createdUsername;
private LocalDateTime modifiedTime; private LocalDateTime modifiedTime;

View File

@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.resource.entity;
import com.eshore.gringotts.core.Constants; import com.eshore.gringotts.core.Constants;
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity; import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat; import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType; import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
import com.eshore.gringotts.web.domain.upload.entity.DataFile; import com.eshore.gringotts.web.domain.upload.entity.DataFile;
@@ -33,12 +34,14 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
@NamedEntityGraph(name = "data_resource.list", attributeNodes = { @NamedEntityGraph(name = "data_resource.list", attributeNodes = {
@NamedAttributeNode(value = "type"), @NamedAttributeNode(value = "type"),
@NamedAttributeNode(value = "format"), @NamedAttributeNode(value = "format"),
@NamedAttributeNode(value = "confirmation"),
@NamedAttributeNode(value = "createdUser"), @NamedAttributeNode(value = "createdUser"),
}) })
@NamedEntityGraph(name = "data_resource.detail", attributeNodes = { @NamedEntityGraph(name = "data_resource.detail", attributeNodes = {
@NamedAttributeNode(value = "type"), @NamedAttributeNode(value = "type"),
@NamedAttributeNode(value = "format"), @NamedAttributeNode(value = "format"),
@NamedAttributeNode(value = "example"), @NamedAttributeNode(value = "example"),
@NamedAttributeNode(value = "confirmation"),
@NamedAttributeNode(value = "createdUser"), @NamedAttributeNode(value = "createdUser"),
@NamedAttributeNode(value = "modifiedUser"), @NamedAttributeNode(value = "modifiedUser"),
}) })
@@ -58,4 +61,7 @@ public class DataResource extends SimpleEntity {
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT)) @JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
@ToString.Exclude @ToString.Exclude
private DataFile example; private DataFile example;
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
@ToString.Exclude
private Confirmation confirmation;
} }

View File

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

View File

@@ -17,8 +17,13 @@ import org.springframework.stereotype.Service;
@Slf4j @Slf4j
@Service @Service
public class DataFileService extends SimpleService<DataFile> { public class DataFileService extends SimpleService<DataFile> {
public DataFileService(DataFileRepository repository, UserService userService) { private final DataFileRepository dataFileRepository;
super(repository, userService); private final UserService userService;
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
super(dataFileRepository, userService);
this.dataFileRepository = dataFileRepository;
this.userService = userService;
} }
public DataFile detail(String id) { public DataFile detail(String id) {
@@ -34,17 +39,17 @@ public class DataFileService extends SimpleService<DataFile> {
User loginUser = userService.currentLoginUser(); User loginUser = userService.currentLoginUser();
dataFile.setCreatedUser(loginUser); dataFile.setCreatedUser(loginUser);
dataFile.setModifiedUser(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) { 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.setSize(size);
dataFile.setMd5(md5); dataFile.setMd5(md5);
dataFile.setPath(path); dataFile.setPath(path);
User loginUser = userService.currentLoginUser(); User loginUser = userService.currentLoginUser();
dataFile.setModifiedUser(loginUser); dataFile.setModifiedUser(loginUser);
repository.save(dataFile); dataFileRepository.save(dataFile);
} }
public static final class DataFileNotFoundException extends RuntimeException { public static final class DataFileNotFoundException extends RuntimeException {

View File

@@ -32,6 +32,21 @@ logging:
sdk: sdk:
eventsub: eventsub:
EventSubscribeImp: error EventSubscribeImp: error
---
spring:
config:
activate:
on-profile: macOS
gringotts:
upload:
upload-path: /Users/lanyuanxiaoyao/Project/IdeaProjects/gringotts/gringotts-web/target/upload
---
spring:
config:
activate:
on-profile: windows
gringotts: gringotts:
upload: upload:
upload-path: C:\Users\lanyuanxiaoyao\Projects\gringotts\gringotts-web\target upload-path: C:\Users\lanyuanxiaoyao\Projects\gringotts\gringotts-web\target