Compare commits
6 Commits
d68f8a27ee
...
d354cb9733
| Author | SHA1 | Date | |
|---|---|---|---|
| d354cb9733 | |||
| aeb89e2367 | |||
| c51228bf42 | |||
| ccbefb9bdf | |||
| a273f93f7a | |||
| fef98d69e1 |
@@ -83,11 +83,20 @@ export function paginationTemplate(perPage = 20, maxButtons = 5) {
|
||||
}
|
||||
}
|
||||
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = 5242880) {
|
||||
export const size5MB = 5242880
|
||||
export const size100MB = 104857600
|
||||
export const size500MB = 524288000
|
||||
export const size1GB = 1073741824
|
||||
|
||||
export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB) {
|
||||
return {
|
||||
useChunk: true,
|
||||
accept: accept,
|
||||
maxSize: maxSize,
|
||||
autoUpload: false,
|
||||
startChunkApi: apiPost('${base}/upload/start'),
|
||||
chunkApi: apiPost('${base}/upload/slice'),
|
||||
finishChunkApi: apiPost('${base}/upload/finish'),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,294 @@
|
||||
import './dialog-resource.css'
|
||||
import {apiPost, horizontalFormOptions, inputFileFormItemCommonOptions} from "../constants.js";
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
horizontalFormOptions,
|
||||
inputFileFormItemCommonOptions,
|
||||
size1GB,
|
||||
size500MB
|
||||
} from "../constants.js";
|
||||
|
||||
const clearable = {
|
||||
clearable: true,
|
||||
clearValueOnEmpty: true,
|
||||
}
|
||||
|
||||
function detailForm() {
|
||||
return {
|
||||
type: 'form',
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
left: 2,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '资源名称',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
name: 'description',
|
||||
label: '资源描述',
|
||||
...clearable,
|
||||
showCounter: true,
|
||||
trimContents: true,
|
||||
minRows: 2,
|
||||
maxRows: 2,
|
||||
},
|
||||
{
|
||||
type: 'fieldSet',
|
||||
title: '资源类型定义',
|
||||
body: [
|
||||
{
|
||||
name: 'resourceType',
|
||||
type: 'select',
|
||||
label: '资源类型',
|
||||
selectFirst: true,
|
||||
required: true,
|
||||
options: [
|
||||
{label: 'API', value: 'API'},
|
||||
{label: '文件', value: 'FILE'},
|
||||
{label: '数据库', value: 'DATABASE'},
|
||||
{label: 'HDFS', value: 'HDFS'},
|
||||
{label: 'FTP', value: 'FTP'},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'API'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'API地址',
|
||||
name: 'apiUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'apiUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'apiPassword',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'FILE'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'fileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
name: 'fileId',
|
||||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'DATABASE'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'select',
|
||||
label: '数据库类型',
|
||||
name: 'databaseType',
|
||||
required: true,
|
||||
options: [
|
||||
{label: 'MySQL', value: 'MYSQL'},
|
||||
{label: 'Oracle', value: 'ORACLE'},
|
||||
{label: 'PostgreSQL', value: 'POSTGRESQL'},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'JDBC',
|
||||
name: 'databaseJdbc',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'databaseUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'databasePassword',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'HDFS'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'coreSiteFileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: 'core-site.xml',
|
||||
name: 'coreSiteFileId',
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'hdfsSiteFileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: 'hdfs-site.xml',
|
||||
name: 'hdfsSiteFileId',
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'FTP'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP地址',
|
||||
name: 'ftpUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP账号',
|
||||
name: 'ftpUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: 'FTP密码',
|
||||
name: 'ftpPassword',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '相对路径',
|
||||
name: 'ftpPath',
|
||||
description: '若为空,则使用用户根目录',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '文件筛选',
|
||||
name: 'ftpRegexFilter',
|
||||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'fieldSet',
|
||||
title: '资源格式定义',
|
||||
className: 'mt-5',
|
||||
body: [
|
||||
{
|
||||
name: 'formatType',
|
||||
type: 'select',
|
||||
label: '资源格式',
|
||||
selectFirst: true,
|
||||
required: true,
|
||||
options: [
|
||||
{label: '无', value: 'NONE'},
|
||||
{label: 'Line', value: 'LINE'},
|
||||
{label: 'JSON', value: 'JSON'},
|
||||
{label: 'JSON Line', value: 'JSON_LINE'},
|
||||
{label: 'CSV', value: 'CSV'},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonSchema',
|
||||
label: 'JSON格式',
|
||||
description: '(使用JSON Schema格式)',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON_LINE'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonLineSchema',
|
||||
label: 'JSON格式',
|
||||
description: 'JSON Line类型请定义单行JSON数据格式(使用JSON Schema格式)',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'CSV'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'csvSchema',
|
||||
label: 'CSV格式',
|
||||
description: '请定义单行数据中各个字段的格式(使用JSON Schema格式)',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
disabledTypes: [
|
||||
'object',
|
||||
'array',
|
||||
'null',
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${static}",
|
||||
type: 'input-text',
|
||||
label: '资源示例',
|
||||
name: 'exampleFileId',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
type: 'input-file',
|
||||
label: '资源示例',
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
name: 'exampleFileId',
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export function resourceAddDialog() {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '新增数据资源',
|
||||
// size: 'lg',
|
||||
size: 'md',
|
||||
actions: [
|
||||
{
|
||||
type: 'reset',
|
||||
@@ -24,245 +301,29 @@ export function resourceAddDialog() {
|
||||
}
|
||||
],
|
||||
body: {
|
||||
...detailForm(),
|
||||
debug: true,
|
||||
type: 'form',
|
||||
api: apiPost('${base}/data_resource/create'),
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
left: 2,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '资源名称',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
name: 'description',
|
||||
label: '资源描述',
|
||||
...clearable,
|
||||
showCounter: true,
|
||||
trimContents: true,
|
||||
minRows: 2,
|
||||
maxRows: 2,
|
||||
},
|
||||
{
|
||||
type: 'fieldSet',
|
||||
title: '资源类型定义',
|
||||
body: [
|
||||
{
|
||||
name: 'resourceType',
|
||||
type: 'select',
|
||||
label: '资源类型',
|
||||
selectFirst: true,
|
||||
required: true,
|
||||
options: [
|
||||
{label: 'API', value: 'api'},
|
||||
{label: '文件', value: 'file'},
|
||||
{label: '数据库', value: 'database'},
|
||||
{label: 'HDFS', value: 'hdfs'},
|
||||
{label: 'FTP', value: 'ftp'},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'api'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'API地址',
|
||||
name: 'apiUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'apiUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'apiPassword',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'file'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-file',
|
||||
name: 'filePath',
|
||||
description: '只适合小于2M的资源文件使用,大文件请使用其他资源类型',
|
||||
...inputFileFormItemCommonOptions('.zip', 2097152),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'database'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'select',
|
||||
label: '数据库类型',
|
||||
name: 'databaseType',
|
||||
required: true,
|
||||
options: [
|
||||
{label: 'MySQL', value: 'MYSQL'},
|
||||
{label: 'Oracle', value: 'ORACLE'},
|
||||
{label: 'PostgreSQL', value: 'POSTGRESQL'},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'JDBC',
|
||||
name: 'databaseJdbc',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'databaseUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'databasePassword',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'hdfs'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-file',
|
||||
description: 'core-site.xml',
|
||||
name: 'coreSiteFile',
|
||||
...inputFileFormItemCommonOptions('.xml', 1048576),
|
||||
},
|
||||
{
|
||||
type: 'input-file',
|
||||
description: 'hdfs-site.xml',
|
||||
name: 'hdfsSiteFile',
|
||||
...inputFileFormItemCommonOptions('.xml', 1048576),
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${resourceType === 'ftp'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP地址',
|
||||
name: 'ftpUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP账号',
|
||||
name: 'ftpUsername',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: 'FTP密码',
|
||||
name: 'ftpPassword',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '相对路径',
|
||||
name: 'ftpPath',
|
||||
description: '若为空,则使用用户根目录',
|
||||
...clearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '文件筛选',
|
||||
name: 'ftpRegexFilter',
|
||||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||||
...clearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'fieldSet',
|
||||
title: '资源格式定义',
|
||||
className: 'mt-5',
|
||||
body: [
|
||||
{
|
||||
name: 'formatType',
|
||||
type: 'select',
|
||||
label: '资源格式',
|
||||
selectFirst: true,
|
||||
required: true,
|
||||
options: [
|
||||
{label: '无', value: 'NONE'},
|
||||
{label: 'Line', value: 'LINE'},
|
||||
{label: 'JSON', value: 'JSON'},
|
||||
{label: 'JSON Line', value: 'JSON_LINE'},
|
||||
{label: 'CSV', value: 'CSV'},
|
||||
]
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonSchema',
|
||||
label: 'JSON格式',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'JSON_LINE'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'jsonLineSchema',
|
||||
label: 'JSON格式',
|
||||
description: 'JSON Line类型请定义单行JSON数据格式',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
},
|
||||
{
|
||||
visibleOn: "${formatType === 'CSV'}",
|
||||
type: 'json-schema-editor',
|
||||
name: 'csvSchema',
|
||||
label: 'CSV格式',
|
||||
description: '请定义单行数据中各个字段的格式',
|
||||
required: true,
|
||||
enableAdvancedSetting: true,
|
||||
mini: true,
|
||||
disabledTypes: [
|
||||
'object',
|
||||
'array',
|
||||
'null',
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'input-file',
|
||||
label: '资源示例',
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
name: 'example',
|
||||
...inputFileFormItemCommonOptions(),
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function resourceDetailDialog() {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '账号详情',
|
||||
actions: [],
|
||||
size: 'md',
|
||||
body: {
|
||||
...detailForm(),
|
||||
static: true,
|
||||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||||
data: {
|
||||
static: true,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
import {apiGet, useAmis} from '../../components/constants.js'
|
||||
import {userChangePasswordDialog} from "../../components/user/dialog-user-change-password.js";
|
||||
import {tabUser} from "./tab-user.js";
|
||||
import {tabOverview} from "./tab-overview.js";
|
||||
import {tabMarket} from "./tab-market.js";
|
||||
import {tabData} from "./tab-data.js";
|
||||
import {tabLog} from "./tab-log.js";
|
||||
import {tabSettings} from "./tab-settings.js";
|
||||
|
||||
useAmis(information => {
|
||||
return {
|
||||
@@ -61,7 +60,7 @@ useAmis(information => {
|
||||
// tabOverview(),
|
||||
tabMarket(),
|
||||
tabUser(),
|
||||
tabLog(),
|
||||
tabSettings(),
|
||||
]
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {resourceAddDialog} from "../../components/resource/dialog-resource.js";
|
||||
import {apiPost, inputFileFormItemCommonOptions} from "../../components/constants.js";
|
||||
import {resourceAddDialog, resourceDetailDialog} from "../../components/resource/dialog-resource.js";
|
||||
import {apiPost, copyField, crudCommonOptions} from "../../components/constants.js";
|
||||
|
||||
export function tabData() {
|
||||
return {
|
||||
@@ -7,24 +7,51 @@ export function tabData() {
|
||||
icon: 'fa fa-database',
|
||||
body: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '',
|
||||
icon: 'fa fa-plus',
|
||||
...resourceAddDialog()
|
||||
},
|
||||
{
|
||||
type: 'form',
|
||||
body: [
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiPost('${base}/data_resource/list')
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'input-file',
|
||||
name: 'file',
|
||||
label: '测试文件上传',
|
||||
...inputFileFormItemCommonOptions(undefined, 1073741824),
|
||||
useChunk: true,
|
||||
startChunkApi: apiPost('${base}/upload/start'),
|
||||
chunkApi: apiPost('${base}/upload/slice'),
|
||||
finishChunkApi: apiPost('${base}/upload/finish')
|
||||
}
|
||||
type: 'action',
|
||||
label: '新增数据资源',
|
||||
icon: 'fa fa-plus',
|
||||
...resourceAddDialog()
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
label: '名称',
|
||||
name: 'name',
|
||||
width: 200,
|
||||
...copyField(
|
||||
'name',
|
||||
'查看详情',
|
||||
undefined,
|
||||
resourceDetailDialog(),
|
||||
)
|
||||
},
|
||||
{
|
||||
label: '描述',
|
||||
name: 'description',
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
width: 150,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
width: 200,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: []
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
export function tabLog() {
|
||||
export function tabSettings() {
|
||||
return {
|
||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
||||
title: '系统日志',
|
||||
icon: 'fa fa-file',
|
||||
title: '系统管理',
|
||||
icon: 'fa fa-gear',
|
||||
body: [
|
||||
'hello world'
|
||||
]
|
||||
@@ -1,14 +1,10 @@
|
||||
package com.eshore.gringotts.web.configuration;
|
||||
|
||||
import cn.dev33.satoken.context.SaHolder;
|
||||
import cn.dev33.satoken.filter.SaServletFilter;
|
||||
import cn.dev33.satoken.interceptor.SaInterceptor;
|
||||
import cn.dev33.satoken.router.SaHttpMethod;
|
||||
import cn.dev33.satoken.router.SaRouter;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
@@ -35,7 +31,13 @@ public class SaTokenConfiguration implements WebMvcConfigurer {
|
||||
.notMatch("/assets/**")
|
||||
.notMatch("/pages/**")
|
||||
.notMatch("/user/**")
|
||||
.check(r -> StpUtil.checkLogin());
|
||||
.check(r -> {
|
||||
try {
|
||||
StpUtil.checkLogin();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("账号未登陆", e);
|
||||
}
|
||||
});
|
||||
})
|
||||
)
|
||||
.addPathPatterns("/**");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.eshore.gringotts.web.domain.entity;
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.EntityListeners;
|
||||
@@ -1,22 +1,13 @@
|
||||
package com.eshore.gringotts.web.domain.entity;
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.GenericGenerator;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
@@ -1,4 +1,4 @@
|
||||
package com.eshore.gringotts.web.domain.entity;
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.eshore.gringotts.web.domain.base.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import org.springframework.data.repository.NoRepositoryBean;
|
||||
|
||||
/**
|
||||
* 整合一下
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@NoRepositoryBean
|
||||
public interface SimpleRepository<E, ID> extends FenixJpaRepository<E, ID>, FenixJpaSpecificationExecutor<E> {
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
public abstract class SimpleService<E, ID> {
|
||||
protected abstract SimpleRepository<E, ID> repository();
|
||||
|
||||
public ImmutableList<E> list() {
|
||||
return Lists.immutable.ofAll(repository().findAll());
|
||||
}
|
||||
|
||||
public E detail(ID id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return null;
|
||||
}
|
||||
return repository().findById(id).orElse(null);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,10 @@
|
||||
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.configuration.amis.AmisListResponse;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.CsvResourceFormat;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.JsonLineResourceFormat;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.JsonResourceFormat;
|
||||
@@ -14,13 +18,19 @@ import com.eshore.gringotts.web.domain.resource.entity.type.FtpResourceType;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.type.HDFSResourceType;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
|
||||
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
@@ -32,90 +42,199 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/data_resource")
|
||||
public class DataResourceController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataResourceController.class);
|
||||
|
||||
private final ObjectMapper mapper;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public DataResourceController(Jackson2ObjectMapperBuilder builder, DataResourceService dataResourceService) {
|
||||
public DataResourceController(Jackson2ObjectMapperBuilder builder, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
this.mapper = builder.build();
|
||||
this.dataResourceService = dataResourceService;
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@PostMapping("/create")
|
||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
||||
logger.info("Create request: {}", request);
|
||||
log.info("Create request: {}", request);
|
||||
ResourceType type = null;
|
||||
switch (request.resourceType) {
|
||||
case "api":
|
||||
case API:
|
||||
type = new ApiResourceType(request.apiUrl, request.apiUsername, request.apiPassword);
|
||||
break;
|
||||
case "file":
|
||||
type = new FileResourceType(request.filePath);
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(request.fileId);
|
||||
log.info("{}", dataFile);
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case "database":
|
||||
case DATABASE:
|
||||
type = new DatabaseResourceType(
|
||||
request.databaseJdbc,
|
||||
request.databaseUsername,
|
||||
request.databasePassword,
|
||||
EnumUtil.fromString(DatabaseResourceType.Type.class, request.databaseType)
|
||||
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, request.databaseType)
|
||||
);
|
||||
break;
|
||||
case "hdfs":
|
||||
type = new HDFSResourceType(request.coreSiteFile, request.hdfsSiteFile);
|
||||
case HDFS:
|
||||
type = new HDFSResourceType(dataFileService.detail(request.coreSiteFileId), dataFileService.detail(request.hdfsSiteFileId));
|
||||
break;
|
||||
case "ftp":
|
||||
case FTP:
|
||||
type = new FtpResourceType(request.ftpUrl, request.ftpUsername, request.ftpPassword, request.ftpPath, request.ftpRegexFilter);
|
||||
break;
|
||||
}
|
||||
ResourceFormat format = null;
|
||||
switch (request.formatType) {
|
||||
case "NONE":
|
||||
case NONE:
|
||||
format = new NoneResourceFormat();
|
||||
break;
|
||||
case "LINE":
|
||||
case LINE:
|
||||
format = new LineResourceFormat();
|
||||
break;
|
||||
case "JSON":
|
||||
case JSON:
|
||||
format = new JsonResourceFormat(mapper.writeValueAsString(request.jsonSchema));
|
||||
break;
|
||||
case "JSON_LINE":
|
||||
case JSON_LINE:
|
||||
format = new JsonLineResourceFormat(mapper.writeValueAsString(request.jsonLineSchema));
|
||||
break;
|
||||
case "CSV":
|
||||
case CSV:
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(request.csvSchema));
|
||||
break;
|
||||
}
|
||||
dataResourceService.create(request.name, request.description, format, type);
|
||||
dataResourceService.create(request.name, request.description, format, type, dataFileService.detail(request.exampleFileId));
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public AmisListResponse list() {
|
||||
return AmisResponse.responseListData(dataResourceService.list().collect(DataResourceListItem::new));
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
public AmisResponse<DataResourceDetail> detail(@PathVariable Long id) throws JsonProcessingException {
|
||||
return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id)));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class CreateRequest {
|
||||
public static class CreateRequest {
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected ResourceType.Type resourceType;
|
||||
protected String apiUrl;
|
||||
protected String apiUsername;
|
||||
protected String apiPassword;
|
||||
protected String fileId;
|
||||
protected String databaseType;
|
||||
protected String databaseJdbc;
|
||||
protected String databaseUsername;
|
||||
protected String databasePassword;
|
||||
protected String coreSiteFileId;
|
||||
protected String hdfsSiteFileId;
|
||||
protected String ftpUrl;
|
||||
protected String ftpUsername;
|
||||
protected String ftpPassword;
|
||||
protected String ftpPath;
|
||||
protected String ftpRegexFilter;
|
||||
protected ResourceFormat.Type formatType;
|
||||
protected Map<?, ?> jsonSchema;
|
||||
protected Map<?, ?> jsonLineSchema;
|
||||
protected Map<?, ?> csvSchema;
|
||||
protected String exampleFileId;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DataResourceListItem {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String resourceType;
|
||||
private String apiUrl;
|
||||
private String apiUsername;
|
||||
private String apiPassword;
|
||||
private String filePath;
|
||||
private String databaseType;
|
||||
private String databaseJdbc;
|
||||
private String databaseUsername;
|
||||
private String databasePassword;
|
||||
private String coreSiteFile;
|
||||
private String hdfsSiteFile;
|
||||
private String ftpUrl;
|
||||
private String ftpUsername;
|
||||
private String ftpPassword;
|
||||
private String ftpPath;
|
||||
private String ftpRegexFilter;
|
||||
private String formatType;
|
||||
private Map<?, ?> jsonSchema;
|
||||
private Map<?, ?> jsonLineSchema;
|
||||
private Map<?, ?> csvSchema;
|
||||
private String example;
|
||||
private String type;
|
||||
private String format;
|
||||
private String createdUser;
|
||||
private LocalDateTime createdTime;
|
||||
|
||||
public DataResourceListItem(DataResource dataResource) {
|
||||
this.id = dataResource.getId();
|
||||
this.name = dataResource.getName();
|
||||
this.description = dataResource.getDescription();
|
||||
this.type = dataResource.getType().getResourceType().name();
|
||||
this.format = dataResource.getFormat().getFormatType().name();
|
||||
this.createdUser = dataResource.getCreatedUser().getUsername();
|
||||
this.createdTime = dataResource.getCreatedTime();
|
||||
}
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@NoArgsConstructor
|
||||
public static final class DataResourceDetail extends CreateRequest {
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
private String modifiedUsername;
|
||||
|
||||
public DataResourceDetail(ObjectMapper mapper, DataResource dataResource) throws JsonProcessingException {
|
||||
log.info("DataResourceDetail: {}", dataResource);
|
||||
this.name = dataResource.getName();
|
||||
this.description = dataResource.getDescription();
|
||||
this.resourceType = dataResource.getType().getResourceType();
|
||||
switch (dataResource.getType().getResourceType()) {
|
||||
case API:
|
||||
ApiResourceType apiType = (ApiResourceType) dataResource.getType();
|
||||
this.apiUrl = apiType.getUrl();
|
||||
this.apiUsername = apiType.getUsername();
|
||||
this.apiPassword = apiType.getPassword();
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
this.fileId = fileType.getFile().getFilename();
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||
this.databaseType = databaseType.getDatabaseType().name();
|
||||
this.databaseJdbc = databaseType.getJdbc();
|
||||
this.databaseUsername = databaseType.getUsername();
|
||||
this.databasePassword = databaseType.getPassword();
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
this.coreSiteFileId = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getFilename();
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||
this.ftpUrl = ftpType.getUrl();
|
||||
this.ftpUsername = ftpType.getUsername();
|
||||
this.ftpPassword = ftpType.getPassword();
|
||||
this.ftpPath = ftpType.getPath();
|
||||
this.ftpRegexFilter = ftpType.getRegexFilter();
|
||||
break;
|
||||
}
|
||||
this.formatType = dataResource.getFormat().getFormatType();
|
||||
switch (dataResource.getFormat().getFormatType()) {
|
||||
case NONE:
|
||||
case LINE:
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
|
||||
this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
|
||||
this.jsonLineSchema = mapper.readValue(csvFormat.getSchema(), Map.class);
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
this.exampleFileId = dataResource.getExample().getFilename();
|
||||
}
|
||||
|
||||
this.createdUsername = dataResource.getCreatedUser().getUsername();
|
||||
this.createdTime = dataResource.getCreatedTime();
|
||||
this.modifiedUsername = dataResource.getModifiedUser().getUsername();
|
||||
this.modifiedTime = dataResource.getModifiedTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
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.upload.entity.DataFile;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToOne;
|
||||
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;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@@ -25,14 +30,32 @@ import javax.persistence.Table;
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@DynamicUpdate
|
||||
@Table(name = Constants.TABLE_PREFIX + "data_resource")
|
||||
@NamedEntityGraph(name = "data_resource.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "type"),
|
||||
@NamedAttributeNode(value = "format"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "data_resource.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "type"),
|
||||
@NamedAttributeNode(value = "format"),
|
||||
@NamedAttributeNode(value = "example"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class DataResource extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String description;
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false)
|
||||
@ToString.Exclude
|
||||
private ResourceType type;
|
||||
@OneToOne
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(nullable = false)
|
||||
@ToString.Exclude
|
||||
private ResourceFormat format;
|
||||
@OneToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private DataFile example;
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("CSV")
|
||||
public class CsvResourceFormat extends ResourceFormat{
|
||||
public class CsvResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.CSV;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("JSON_LINE")
|
||||
public class JsonLineResourceFormat extends ResourceFormat{
|
||||
public class JsonLineResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.JSON_LINE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -22,6 +21,11 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@DiscriminatorValue("JSON")
|
||||
public class JsonResourceFormat extends ResourceFormat{
|
||||
public class JsonResourceFormat extends ResourceFormat {
|
||||
private String schema;
|
||||
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.JSON;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,9 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Entity
|
||||
@DiscriminatorValue("LINE")
|
||||
public class LineResourceFormat extends ResourceFormat{
|
||||
public class LineResourceFormat extends ResourceFormat {
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.LINE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,5 +17,9 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Entity
|
||||
@DiscriminatorValue("NONE")
|
||||
public class NoneResourceFormat extends ResourceFormat{
|
||||
public class NoneResourceFormat extends ResourceFormat {
|
||||
@Override
|
||||
public Type getFormatType() {
|
||||
return Type.NONE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.IdOnlyEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
@@ -27,7 +25,7 @@ import lombok.ToString;
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_format")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
|
||||
public class ResourceFormat extends IdOnlyEntity {
|
||||
public abstract class ResourceFormat extends IdOnlyEntity {
|
||||
public enum Type {
|
||||
NONE,
|
||||
LINE,
|
||||
@@ -35,4 +33,6 @@ public class ResourceFormat extends IdOnlyEntity {
|
||||
JSON_LINE,
|
||||
CSV,
|
||||
}
|
||||
|
||||
public abstract Type getFormatType();
|
||||
}
|
||||
|
||||
@@ -22,4 +22,9 @@ public class ApiResourceType extends ResourceType {
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.API;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,9 +26,14 @@ public class DatabaseResourceType extends ResourceType {
|
||||
private String password;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Type type;
|
||||
private DatabaseType databaseType;
|
||||
|
||||
public enum Type {
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.DATABASE;
|
||||
}
|
||||
|
||||
public enum DatabaseType {
|
||||
MYSQL,
|
||||
POSTGRESQL,
|
||||
ORACLE,
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -17,7 +23,16 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type_file")
|
||||
@NamedEntityGraph(name = "file_resource_type.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "file")
|
||||
})
|
||||
public class FileResourceType extends ResourceType {
|
||||
@Column(nullable = false)
|
||||
private String path;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile file;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.FILE;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,4 +24,9 @@ public class FtpResourceType extends ResourceType {
|
||||
private String password;
|
||||
private String path;
|
||||
private String regexFilter;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.FTP;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@@ -17,9 +23,20 @@ import lombok.ToString;
|
||||
@NoArgsConstructor
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type_hdfs")
|
||||
@NamedEntityGraph(name = "hdfs_resource_type.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "coreSite"),
|
||||
@NamedAttributeNode(value = "hdfsSite"),
|
||||
})
|
||||
public class HDFSResourceType extends ResourceType {
|
||||
@Column(nullable = false)
|
||||
private String coreSite;
|
||||
@Column(nullable = false)
|
||||
private String hdfsSite;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile coreSite;
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataFile hdfsSite;
|
||||
|
||||
@Override
|
||||
public Type getResourceType() {
|
||||
return Type.HDFS;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.IdOnlyEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
@@ -22,5 +22,14 @@ import lombok.ToString;
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public class ResourceType extends IdOnlyEntity {
|
||||
public abstract class ResourceType extends IdOnlyEntity {
|
||||
public abstract Type getResourceType();
|
||||
|
||||
public enum Type {
|
||||
API,
|
||||
DATABASE,
|
||||
FILE,
|
||||
FTP,
|
||||
HDFS,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,20 @@
|
||||
package com.eshore.gringotts.web.domain.resource.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface DataResourceRepository extends FenixJpaRepository<DataResource, Long>, FenixJpaSpecificationExecutor<DataResource> {
|
||||
public interface DataResourceRepository extends SimpleRepository<DataResource, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<DataResource> findAll();
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "data_resource.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<DataResource> findById(Long id);
|
||||
}
|
||||
|
||||
@@ -2,10 +2,11 @@ package com.eshore.gringotts.web.domain.resource.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.format.ResourceFormat;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResourceFormatRepository extends FenixJpaRepository<ResourceFormat, Long>, FenixJpaSpecificationExecutor<ResourceFormat> {
|
||||
public interface ResourceFormatRepository extends SimpleRepository<ResourceFormat, Long> {
|
||||
}
|
||||
@@ -2,10 +2,11 @@ package com.eshore.gringotts.web.domain.resource.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.type.ResourceType;
|
||||
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface ResourceTypeRepository extends FenixJpaRepository<ResourceType, Long>, FenixJpaSpecificationExecutor<ResourceType> {
|
||||
public interface ResourceTypeRepository extends SimpleRepository<ResourceType, Long> {
|
||||
}
|
||||
@@ -1,16 +1,18 @@
|
||||
package com.eshore.gringotts.web.domain.resource.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
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.repository.DataResourceRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
|
||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import javax.transaction.Transactional;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -18,10 +20,9 @@ import org.springframework.stereotype.Service;
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataResourceService {
|
||||
private static final Logger log = LoggerFactory.getLogger(DataResourceService.class);
|
||||
|
||||
public class DataResourceService extends SimpleService<DataResource, Long> {
|
||||
private final DataResourceRepository dataResourceRepository;
|
||||
private final ResourceTypeRepository resourceTypeRepository;
|
||||
private final ResourceFormatRepository resourceFormatRepository;
|
||||
@@ -34,15 +35,22 @@ public class DataResourceService {
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleRepository<DataResource, Long> repository() {
|
||||
return dataResourceRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(String name, String description, ResourceFormat format, ResourceType type) {
|
||||
public void create(String name, String description, ResourceFormat format, ResourceType type, DataFile example) {
|
||||
resourceFormatRepository.save(format);
|
||||
log.info("{}", type);
|
||||
resourceTypeRepository.save(type);
|
||||
DataResource resource = new DataResource();
|
||||
resource.setName(name);
|
||||
resource.setDescription(description);
|
||||
resource.setFormat(format);
|
||||
resource.setType(type);
|
||||
resource.setExample(example);
|
||||
User user = userService.currentLoginUser();
|
||||
resource.setCreatedUser(user);
|
||||
resource.setModifiedUser(user);
|
||||
|
||||
@@ -5,7 +5,7 @@ import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.SecureUtil;
|
||||
import com.eshore.gringotts.web.configuration.UploadConfiguration;
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.upload.service.UploadService;
|
||||
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
@@ -37,13 +37,13 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
public class UploadController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UploadController.class);
|
||||
|
||||
private final UploadService uploadService;
|
||||
private final DataFileService dataFileService;
|
||||
private final String uploadFolderPath;
|
||||
private final String cacheFolderPath;
|
||||
private final String sliceFolderPath;
|
||||
|
||||
public UploadController(UploadConfiguration uploadConfiguration, UploadService uploadService) {
|
||||
this.uploadService = uploadService;
|
||||
public UploadController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
|
||||
this.dataFileService = dataFileService;
|
||||
|
||||
this.uploadFolderPath = uploadConfiguration.getUploadPath();
|
||||
this.cacheFolderPath = StrUtil.format("{}/cache", uploadFolderPath);
|
||||
@@ -53,7 +53,7 @@ public class UploadController {
|
||||
@PostMapping("/start")
|
||||
public AmisResponse<StartResponse> start(@RequestBody StartRequest request) {
|
||||
logger.info("Request: {}", request);
|
||||
Long id = uploadService.initialDataFile(request.filename);
|
||||
Long id = dataFileService.initialDataFile(request.filename);
|
||||
return AmisResponse.responseSuccess(new StartResponse(id.toString()));
|
||||
}
|
||||
|
||||
@@ -68,7 +68,6 @@ public class UploadController {
|
||||
@RequestParam("file")
|
||||
MultipartFile file
|
||||
) throws IOException {
|
||||
logger.info("UploadId: {}, sequence: {}, size: {}, file: {}", uploadId, sequence, size, file.getName());
|
||||
byte[] bytes = file.getBytes();
|
||||
String md5 = SecureUtil.md5(new ByteArrayInputStream(bytes));
|
||||
String targetFilename = StrUtil.format("{}-{}", sequence, md5);
|
||||
@@ -84,7 +83,6 @@ public class UploadController {
|
||||
|
||||
@PostMapping("finish")
|
||||
public AmisResponse<FinishResponse> finish(@RequestBody FinishRequest request) {
|
||||
logger.info("Request: {}", request);
|
||||
if (request.partList.anySatisfy(part -> !FileUtil.exist(sliceFilePath(request.uploadId, part.eTag)))) {
|
||||
throw new RuntimeException("文件校验失败,请重新上传");
|
||||
}
|
||||
@@ -104,9 +102,12 @@ public class UploadController {
|
||||
}
|
||||
}
|
||||
}
|
||||
File targetFile = new File(StrUtil.format("{}/{}", uploadFolderPath, request.uploadId));
|
||||
FileUtil.move(cacheFile, targetFile, true);
|
||||
uploadService.updateDataFile(request.uploadId, FileUtil.getAbsolutePath(targetFile), FileUtil.size(targetFile), SecureUtil.md5(targetFile));
|
||||
String md5 = SecureUtil.md5(cacheFile);
|
||||
File targetFile = new File(StrUtil.format("{}/{}", uploadFolderPath, md5));
|
||||
if (!targetFile.exists()) {
|
||||
FileUtil.move(cacheFile, targetFile, true);
|
||||
}
|
||||
dataFileService.updateDataFile(request.uploadId, FileUtil.getAbsolutePath(targetFile), FileUtil.size(targetFile), SecureUtil.md5(targetFile));
|
||||
return AmisResponse.responseSuccess(new FinishResponse(request.uploadId.toString()));
|
||||
} else {
|
||||
throw new RuntimeException("合并文件失败");
|
||||
@@ -114,6 +115,7 @@ public class UploadController {
|
||||
} catch (Throwable throwable) {
|
||||
throw new RuntimeException(throwable);
|
||||
} finally {
|
||||
FileUtil.del(StrUtil.format("{}/{}", cacheFolderPath, request.uploadId));
|
||||
FileUtil.del(StrUtil.format("{}/{}", sliceFolderPath, request.uploadId));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.eshore.gringotts.web.domain.upload.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import javax.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.eshore.gringotts.web.domain.upload.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
@@ -9,5 +10,5 @@ import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@Repository
|
||||
public interface DataFileRepository extends FenixJpaRepository<DataFile, Long>, FenixJpaSpecificationExecutor<DataFile> {
|
||||
public interface DataFileRepository extends SimpleRepository<DataFile, Long> {
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.upload.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.eshore.gringotts.web.domain.upload.repository.DataFileRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
@@ -15,17 +17,29 @@ import org.springframework.stereotype.Service;
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Service
|
||||
public class UploadService {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UploadService.class);
|
||||
public class DataFileService extends SimpleService<DataFile, Long> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataFileService.class);
|
||||
|
||||
private final DataFileRepository dataFileRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public UploadService(DataFileRepository dataFileRepository, UserService userService) {
|
||||
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
|
||||
this.dataFileRepository = dataFileRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleRepository<DataFile, Long> repository() {
|
||||
return dataFileRepository;
|
||||
}
|
||||
|
||||
public DataFile detail(String id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
return detail(Long.valueOf(id));
|
||||
}
|
||||
|
||||
public Long initialDataFile(String filename) {
|
||||
DataFile dataFile = new DataFile();
|
||||
dataFile.setFilename(filename);
|
||||
@@ -45,6 +59,12 @@ public class UploadService {
|
||||
dataFileRepository.save(dataFile);
|
||||
}
|
||||
|
||||
public static final class DataFileNotFoundException extends RuntimeException {
|
||||
public DataFileNotFoundException() {
|
||||
super("文件未找到,请重新上传");
|
||||
}
|
||||
}
|
||||
|
||||
public static final class UpdateDataFileFailedException extends RuntimeException {
|
||||
public UpdateDataFileFailedException() {
|
||||
super("更新文件信息失败,请重新上传");
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.user.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
@@ -11,6 +11,8 @@ import javax.persistence.Enumerated;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.NamedAttributeNode;
|
||||
import javax.persistence.NamedEntityGraph;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.persistence.Table;
|
||||
import lombok.Getter;
|
||||
@@ -30,6 +32,14 @@ import org.hibernate.annotations.DynamicUpdate;
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Table(name = Constants.TABLE_PREFIX + "user")
|
||||
@NamedEntityGraph(name = "user.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "user.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
@NamedAttributeNode(value = "checkedUser"),
|
||||
})
|
||||
public class User extends SimpleEntity {
|
||||
@Column(unique = true, nullable = false)
|
||||
private String username;
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.user.repository;
|
||||
|
||||
import com.blinkfox.fenix.jpa.FenixJpaRepository;
|
||||
import com.blinkfox.fenix.specification.FenixJpaSpecificationExecutor;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.jpa.repository.Modifying;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* User操作
|
||||
@@ -15,8 +13,14 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-14
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface UserRepository extends FenixJpaRepository<User, Long>, FenixJpaSpecificationExecutor<User> {
|
||||
public interface UserRepository extends SimpleRepository<User, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "user.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<User> findAll();
|
||||
|
||||
Boolean existsByUsername(String username);
|
||||
@EntityGraph(value = "user.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<User> findByUsername(String username);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user