Compare commits
31 Commits
246e27677e
...
jdk17
| Author | SHA1 | Date | |
|---|---|---|---|
| 6eacbfddd4 | |||
| 34e2f340c0 | |||
| 0e57f6856a | |||
| 37267b4c7c | |||
| e134006794 | |||
| be2971765e | |||
| 6742565f97 | |||
| b6418e1e3a | |||
| b072b83f80 | |||
| 4dcc10f2f7 | |||
| 4d1119997e | |||
| 1740b7bea2 | |||
| 51bca63ec6 | |||
| 5aef7728b2 | |||
| 18add92466 | |||
| 841f1af49a | |||
| 58f2173fb0 | |||
| 00e88078a2 | |||
| 3bda73badf | |||
| 499b7dc597 | |||
| 66bf1b9242 | |||
| efe393835c | |||
| aba9a1716c | |||
| f15bcc2f53 | |||
| 70d5a4549f | |||
| d72ebfd1d1 | |||
| 82a00d0313 | |||
| d781e137d8 | |||
| 7584ca3736 | |||
| 851fc02ce5 | |||
| e76236be62 |
5
.idea/inspectionProfiles/Project_Default.xml
generated
5
.idea/inspectionProfiles/Project_Default.xml
generated
@@ -1,6 +1,11 @@
|
||||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
|
||||
<Languages>
|
||||
<language minSize="47" name="Java" />
|
||||
</Languages>
|
||||
</inspection_tool>
|
||||
<inspection_tool class="HttpUrlsUsage" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||
</profile>
|
||||
</component>
|
||||
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
@@ -1,6 +1,11 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RemoteRepositoriesConfiguration">
|
||||
<remote-repository>
|
||||
<option name="id" value="central" />
|
||||
<option name="name" value="Central Repository" />
|
||||
<option name="url" value="https://repo.maven.apache.org/maven2" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="mavenCentral" />
|
||||
<option name="name" value="mavenCentral" />
|
||||
|
||||
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
@@ -8,7 +8,7 @@
|
||||
</list>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="corretto-11" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="temurin-17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/out" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.retry</groupId>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<artifactId>forest-spring-boot3-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
const information = {
|
||||
debug: false,
|
||||
// baseUrl: '',
|
||||
baseUrl: 'http://127.0.0.1:20080',
|
||||
title: '可信供给中心',
|
||||
debug: true,
|
||||
// baseUrl: '',
|
||||
baseUrl: 'http://127.0.0.1:20080',
|
||||
title: '可信供给中心',
|
||||
}
|
||||
|
||||
export function useAmis(amisObject) {
|
||||
document.title = information.title
|
||||
let amis = amisRequire('amis/embed')
|
||||
amis.embed(
|
||||
'#app',
|
||||
amisObject(information),
|
||||
{
|
||||
data: {
|
||||
base: information.baseUrl,
|
||||
},
|
||||
},
|
||||
{
|
||||
theme: 'antd',
|
||||
enableAMISDebug: information.debug,
|
||||
document.title = information.title
|
||||
let amis = amisRequire('amis/embed')
|
||||
let struct = amisObject(information)
|
||||
if (information.debug) {
|
||||
console.log(struct)
|
||||
}
|
||||
)
|
||||
amis.embed(
|
||||
'#app',
|
||||
struct,
|
||||
{
|
||||
data: {
|
||||
base: information.baseUrl,
|
||||
},
|
||||
},
|
||||
{
|
||||
theme: 'antd',
|
||||
enableAMISDebug: information.debug,
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export function crudCommonOptions() {
|
||||
@@ -100,7 +104,14 @@ export function inputFileFormItemCommonOptions(accept = '*', maxSize = size5MB)
|
||||
}
|
||||
}
|
||||
|
||||
export function copyField(field, tips = '复制', ignoreLength = 0, extra = undefined) {
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {string} tips
|
||||
* @param {number} ignoreLength
|
||||
* @param {{}} extra
|
||||
*/
|
||||
export function copyField(field, label, tips = '复制', ignoreLength = 0, extra = undefined) {
|
||||
let tpl = ignoreLength === 0 ? `\${${field}}` : `\${TRUNCATE(${field}, ${ignoreLength})}`
|
||||
let content = extra
|
||||
? {
|
||||
@@ -117,8 +128,10 @@ export function copyField(field, tips = '复制', ignoreLength = 0, extra = unde
|
||||
tpl: tpl,
|
||||
}
|
||||
return {
|
||||
name: field,
|
||||
type: 'wrapper',
|
||||
size: 'none',
|
||||
className: 'nowrap',
|
||||
body: [
|
||||
content,
|
||||
{
|
||||
@@ -135,7 +148,68 @@ export function copyField(field, tips = '复制', ignoreLength = 0, extra = unde
|
||||
}
|
||||
}
|
||||
|
||||
export function mappingField(field, mapping) {
|
||||
/**
|
||||
* @param {string} label
|
||||
* @param {number} width
|
||||
* @param {Array} buttons
|
||||
*/
|
||||
export function operationField(label, width = 100, buttons = []) {
|
||||
return {
|
||||
label: label,
|
||||
width: width,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: buttons,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {number} width
|
||||
*/
|
||||
export function timeField(field, label, width = 150) {
|
||||
return {
|
||||
label: label,
|
||||
width: width,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: `\${IF(${field}, DATETOSTR(${field}), '-')}`
|
||||
}
|
||||
}
|
||||
|
||||
export function stringWrapField(field, label, width = undefined) {
|
||||
return stringField(field, label, width, true)
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {number} width
|
||||
* @param {boolean} wrap
|
||||
*/
|
||||
export function stringField(field, label, width = undefined, wrap = false) {
|
||||
let data = {
|
||||
name: field,
|
||||
label: label,
|
||||
}
|
||||
if (width) {
|
||||
data['width'] = width
|
||||
}
|
||||
if (wrap) {
|
||||
data['className'] = 'nowrap'
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} field
|
||||
* @param {string} label
|
||||
* @param {[{label: *, value: *, color: string}]} mapping
|
||||
* @param {number} width
|
||||
*/
|
||||
export function mappingField(field, label, mapping, width = 80) {
|
||||
let mapData = {
|
||||
'*': `<span class='label bg-gray-300'>\${${field}}</span>`,
|
||||
}
|
||||
@@ -143,8 +217,11 @@ export function mappingField(field, mapping) {
|
||||
mapData[item['value']] = `<span class='label ${item['color']}'>${item['label']}</span>`
|
||||
})
|
||||
return {
|
||||
label: label,
|
||||
type: 'mapping',
|
||||
width: width,
|
||||
value: `\${${field}}`,
|
||||
align: 'center',
|
||||
map: mapData,
|
||||
}
|
||||
}
|
||||
@@ -170,6 +247,24 @@ export const userStateMapping = [
|
||||
mappingItem('禁用', 'DISABLED', 'bg-danger'),
|
||||
]
|
||||
|
||||
export const confirmationStateMapping = [
|
||||
mappingItem('未确权', 'NONE'),
|
||||
mappingItem('草稿', 'DRAFT', 'bg-primary'),
|
||||
mappingItem('审查中', 'CHECKING', 'bg-warning'),
|
||||
mappingItem('通过', 'NORMAL', 'bg-success'),
|
||||
mappingItem('驳回', 'REJECT', 'bg-danger'),
|
||||
]
|
||||
|
||||
export const checkTypeMapping = [
|
||||
mappingItem('确权审查', 'CONFIRMATION', 'bg-blue-500'),
|
||||
mappingItem('授权审查', 'AUTHENTICATION', 'bg-purple-500'),
|
||||
]
|
||||
|
||||
export const checkOverMapping = [
|
||||
mappingItem('完结', 'true', 'bg-success'),
|
||||
mappingItem('进行中', 'false', 'bg-primary'),
|
||||
]
|
||||
|
||||
function api(method, url) {
|
||||
return {
|
||||
method: method,
|
||||
@@ -187,3 +282,128 @@ export function apiGet(url) {
|
||||
export function apiPost(url) {
|
||||
return api('post', url)
|
||||
}
|
||||
|
||||
export function arrayInCheck(array, field) {
|
||||
return `\${ARRAYINCLUDES(['${array.join("','")}'], ${field})}`
|
||||
}
|
||||
|
||||
export function arrayOutCheck(array, field) {
|
||||
return `\${!ARRAYINCLUDES(['${array.join("','")}'], ${field})}`
|
||||
}
|
||||
|
||||
export const confirmationState = {
|
||||
none: 'NONE',
|
||||
draft: 'DRAFT',
|
||||
checking: 'CHECKING',
|
||||
normal: 'NORMAL',
|
||||
}
|
||||
|
||||
export function roleCheck(roles) {
|
||||
return `\${ARRAYINCLUDES(['${roles.join("','")}'], role)}`
|
||||
}
|
||||
|
||||
export const role = {
|
||||
administrator: 'ADMINISTRATOR',
|
||||
checker: 'CHECKER',
|
||||
provider: 'PROVIDER',
|
||||
customer: 'CUSTOMER',
|
||||
}
|
||||
|
||||
export const administratorOnly = roleCheck([role.administrator])
|
||||
export const checkerOnly = roleCheck([role.administrator, role.checker])
|
||||
export const userOnly = roleCheck([role.administrator, role.provider, role.customer])
|
||||
export const providerOnly = roleCheck([role.administrator, role.provider])
|
||||
export const customerOnly = roleCheck([role.administrator, role.customer])
|
||||
|
||||
|
||||
export const formInputClearable = {
|
||||
clearable: 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,
|
||||
}
|
||||
}
|
||||
|
||||
export function formCreatedUserAndModifiedUser() {
|
||||
return [
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'createdUsername',
|
||||
label: '创建人',
|
||||
},
|
||||
{
|
||||
type: 'input-datetime',
|
||||
name: 'createdTime',
|
||||
label: '创建时间',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'modifiedUsername',
|
||||
label: '最后修改人',
|
||||
},
|
||||
{
|
||||
type: 'input-datetime',
|
||||
name: 'modifiedTime',
|
||||
label: '最后修改时间',
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
textarea {
|
||||
resize: none !important;
|
||||
}
|
||||
152
gringotts-frontend/components/permission/dialog-permission.js
Normal file
152
gringotts-frontend/components/permission/dialog-permission.js
Normal file
@@ -0,0 +1,152 @@
|
||||
import './dialog-permission.css'
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
formCreatedUserAndModifiedUser,
|
||||
formInputClearable,
|
||||
formInputMultiFileStatic,
|
||||
horizontalFormOptions,
|
||||
inputFileFormItemCommonOptions,
|
||||
size100MB
|
||||
} from "../constants.js";
|
||||
import {resourceList} from "../../pages/index/tab-data.js";
|
||||
import {resourceDetailDialog} from "../resource/dialog-resource.js";
|
||||
|
||||
function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
return {
|
||||
id: 'permission_form',
|
||||
type: 'form',
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
left: 2,
|
||||
},
|
||||
body: [
|
||||
{
|
||||
type: 'hidden',
|
||||
name: 'id',
|
||||
},
|
||||
{
|
||||
type: 'picker',
|
||||
name: 'targetId',
|
||||
label: '数据资源',
|
||||
required: true,
|
||||
multiple: false,
|
||||
size: 'md',
|
||||
valueField: 'id',
|
||||
labelField: 'name',
|
||||
source: apiGet('${base}/data_resource/list'),
|
||||
pickerSchema: {
|
||||
...resourceList(),
|
||||
},
|
||||
staticSchema: {
|
||||
type: 'tpl',
|
||||
tpl: "<span class='text-primary' style='cursor: pointer'>${targetName}</span>",
|
||||
onEvent: {
|
||||
click: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'dialog',
|
||||
...resourceDetailDialog('targetId'),
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
label: '确权说明',
|
||||
name: 'description',
|
||||
...formInputClearable,
|
||||
},
|
||||
formInputMultiFileStatic('evidenceFiles', '相关材料'),
|
||||
{
|
||||
visibleOn: '${!detail}',
|
||||
type: 'input-file',
|
||||
label: '相关材料',
|
||||
name: 'evidenceFiles',
|
||||
multiple: true,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions(undefined, size100MB),
|
||||
},
|
||||
...(showCreatedUserAndModifiedUser ? formCreatedUserAndModifiedUser() : [])
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export function permissionAddDialog() {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '新增确权申请',
|
||||
size: 'md',
|
||||
actions: [
|
||||
{
|
||||
type: 'reset',
|
||||
label: '重置',
|
||||
},
|
||||
{
|
||||
type: 'submit',
|
||||
label: '确定',
|
||||
level: 'primary',
|
||||
}
|
||||
],
|
||||
body: {
|
||||
...detailForm(),
|
||||
api: apiPost('${base}/confirmation/save'),
|
||||
data: {
|
||||
add: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function permissionDetailDialog(field = 'id', actions = []) {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
title: '确权申请详情',
|
||||
size: 'md',
|
||||
actions: actions,
|
||||
body: {
|
||||
...detailForm(true),
|
||||
initApi: apiGet(`\${base}/confirmation/detail/\${${field}}`),
|
||||
static: true,
|
||||
data: {
|
||||
detail: true,
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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,
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,40 +2,17 @@ import './dialog-resource.css'
|
||||
import {
|
||||
apiGet,
|
||||
apiPost,
|
||||
formCreatedUserAndModifiedUser,
|
||||
formInputClearable,
|
||||
formInputSingleFileStatic,
|
||||
horizontalFormOptions,
|
||||
inputFileFormItemCommonOptions,
|
||||
size1GB,
|
||||
size500MB
|
||||
} from "../constants.js";
|
||||
|
||||
const clearable = {
|
||||
clearable: true,
|
||||
clearValueOnEmpty: true,
|
||||
}
|
||||
|
||||
function inputFileFormItemUpdateFieldOptions(target) {
|
||||
let value = {}
|
||||
value[target] = '${event.data.value}'
|
||||
function detailForm(showCreatedUserAndModifiedUser = false) {
|
||||
return {
|
||||
onEvent: {
|
||||
success: {
|
||||
actions: [
|
||||
{
|
||||
actionType: 'setValue',
|
||||
componentId: 'resource_data_form',
|
||||
args: {
|
||||
value: value
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function detailForm() {
|
||||
return {
|
||||
id: 'resource_data_form',
|
||||
type: 'form',
|
||||
...horizontalFormOptions(),
|
||||
horizontal: {
|
||||
@@ -50,14 +27,16 @@ function detailForm() {
|
||||
type: 'input-text',
|
||||
name: 'name',
|
||||
label: '资源名称',
|
||||
maxLength: 10,
|
||||
showCounter: true,
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'textarea',
|
||||
name: 'description',
|
||||
label: '资源描述',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
showCounter: true,
|
||||
trimContents: true,
|
||||
minRows: 2,
|
||||
@@ -90,19 +69,19 @@ function detailForm() {
|
||||
label: 'API地址',
|
||||
name: 'apiUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'apiUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'apiPassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -110,22 +89,17 @@ function detailForm() {
|
||||
visibleOn: "${resourceType === 'FILE'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
formInputSingleFileStatic('file', '数据文件'),
|
||||
{
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: '数据文件',
|
||||
description: '只适合小于1GB的资源文件使用,大文件请使用其他资源类型',
|
||||
name: 'filename',
|
||||
name: 'file',
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.zip', size1GB),
|
||||
...inputFileFormItemUpdateFieldOptions('fileId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'filename',
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -149,19 +123,19 @@ function detailForm() {
|
||||
label: 'JDBC',
|
||||
name: 'databaseJdbc',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '用户名',
|
||||
name: 'databaseUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: '密码',
|
||||
name: 'databasePassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -169,35 +143,27 @@ function detailForm() {
|
||||
visibleOn: "${resourceType === 'HDFS'}",
|
||||
type: 'fieldSet',
|
||||
body: [
|
||||
formInputSingleFileStatic('coreSiteFile', 'core-site.xml'),
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: 'core-site.xml',
|
||||
name: 'coreSiteFilename',
|
||||
name: 'coreSiteFile',
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
...inputFileFormItemUpdateFieldOptions('coreSiteFileId'),
|
||||
},
|
||||
formInputSingleFileStatic('hdfsSiteFile', 'hdfs-site.xml'),
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'coreSiteFilename',
|
||||
},
|
||||
{
|
||||
visibleOn: "${!static}",
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: 'hdfs-site.xml',
|
||||
name: 'hdfsSiteFilename',
|
||||
name: 'hdfsSiteFile',
|
||||
multiple: false,
|
||||
required: true,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions('.xml'),
|
||||
...inputFileFormItemUpdateFieldOptions('hdfsSiteFileId'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '文件名称',
|
||||
name: 'hdfsSiteFilename',
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -210,33 +176,33 @@ function detailForm() {
|
||||
label: 'FTP地址',
|
||||
name: 'ftpUrl',
|
||||
required: true,
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: 'FTP账号',
|
||||
name: 'ftpUsername',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-password',
|
||||
label: 'FTP密码',
|
||||
name: 'ftpPassword',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '相对路径',
|
||||
name: 'ftpPath',
|
||||
description: '若为空,则使用用户根目录',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
{
|
||||
type: 'input-text',
|
||||
label: '文件筛选',
|
||||
name: 'ftpRegexFilter',
|
||||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||||
...clearable,
|
||||
...formInputClearable,
|
||||
},
|
||||
]
|
||||
},
|
||||
@@ -317,23 +283,20 @@ function detailForm() {
|
||||
label: 'JSON格式',
|
||||
language: 'json',
|
||||
},
|
||||
{
|
||||
visibleOn: "${detail}",
|
||||
type: 'input-text',
|
||||
label: '资源示例',
|
||||
name: 'exampleFilename',
|
||||
},
|
||||
formInputSingleFileStatic('exampleFile', '资源示例'),
|
||||
{
|
||||
visibleOn: "${!detail}",
|
||||
type: 'input-file',
|
||||
label: '资源示例',
|
||||
name: 'exampleFilename',
|
||||
name: 'exampleFile',
|
||||
description: '可以上传用于作为格式示范的样例数据',
|
||||
multiple: false,
|
||||
joinValues: false,
|
||||
...inputFileFormItemCommonOptions(undefined, size500MB),
|
||||
...inputFileFormItemUpdateFieldOptions('exampleFileId'),
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
...(showCreatedUserAndModifiedUser ? formCreatedUserAndModifiedUser() : [])
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -366,7 +329,7 @@ export function resourceAddDialog() {
|
||||
}
|
||||
}
|
||||
|
||||
export function resourceDetailDialog() {
|
||||
export function resourceDetailDialog(field = 'id') {
|
||||
return {
|
||||
actionType: 'dialog',
|
||||
dialog: {
|
||||
@@ -374,9 +337,9 @@ export function resourceDetailDialog() {
|
||||
actions: [],
|
||||
size: 'md',
|
||||
body: {
|
||||
...detailForm(),
|
||||
...detailForm(true),
|
||||
static: true,
|
||||
initApi: apiGet('${base}/data_resource/detail/${id}'),
|
||||
initApi: apiGet(`\${base}/data_resource/detail/\${${field}}`),
|
||||
data: {
|
||||
detail: true,
|
||||
}
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
import {apiGet, horizontalFormOptions, mappingField, userRoleMapping, userStateMapping} from "../constants.js";
|
||||
import {
|
||||
apiGet,
|
||||
formCreatedUserAndModifiedUser,
|
||||
horizontalFormOptions,
|
||||
mappingField,
|
||||
userRoleMapping,
|
||||
userStateMapping
|
||||
} from "../constants.js";
|
||||
|
||||
const dialogBody = [
|
||||
{
|
||||
@@ -9,54 +16,11 @@ const dialogBody = [
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'control',
|
||||
name: 'role',
|
||||
label: '角色',
|
||||
body: [
|
||||
mappingField('role', userRoleMapping),
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'control',
|
||||
name: 'state',
|
||||
label: '账号状态',
|
||||
body: [
|
||||
mappingField('state', userStateMapping)
|
||||
]
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'createdUsername',
|
||||
label: '创建人',
|
||||
},
|
||||
{
|
||||
type: 'input-datetime',
|
||||
name: 'createdTime',
|
||||
label: '创建时间',
|
||||
},
|
||||
]
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
{
|
||||
type: 'input-text',
|
||||
name: 'modifiedUsername',
|
||||
label: '最后修改人',
|
||||
},
|
||||
{
|
||||
type: 'input-datetime',
|
||||
name: 'modifiedTime',
|
||||
label: '最后修改时间',
|
||||
},
|
||||
mappingField('role', '角色', userRoleMapping),
|
||||
mappingField('state', '账号状态', userStateMapping),
|
||||
]
|
||||
},
|
||||
...formCreatedUserAndModifiedUser(),
|
||||
{
|
||||
type: 'group',
|
||||
body: [
|
||||
|
||||
@@ -79,7 +79,6 @@ export function userAdministratorRegisterDialog() {
|
||||
{ label: '数据提供方', value: 'PROVIDER' },
|
||||
{ label: '数据使用方', value: 'CUSTOMER' },
|
||||
{ label: '审查监管方', value: 'CHECKER' },
|
||||
{ label: '系统管理员', value: 'ADMINISTRATOR' },
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import {apiGet, useAmis} from '../../components/constants.js'
|
||||
import {userChangePasswordDialog} from "../../components/user/dialog-user-change-password.js";
|
||||
import {tabUser} from "./tab-user.js";
|
||||
import {tabMarket} from "./tab-market.js";
|
||||
import {tabData} from "./tab-data.js";
|
||||
import {tabSettings} from "./tab-settings.js";
|
||||
import {tabCheck} from "./tab-check.js";
|
||||
import {tabPermissions} from "./tab-permissions.js";
|
||||
|
||||
useAmis(information => {
|
||||
return {
|
||||
@@ -56,9 +57,11 @@ useAmis(information => {
|
||||
type: 'tabs',
|
||||
tabsMode: 'vertical',
|
||||
tabs: [
|
||||
tabData(),
|
||||
// tabOverview(),
|
||||
tabMarket(),
|
||||
// tabMarket(),
|
||||
tabCheck(),
|
||||
tabData(),
|
||||
tabPermissions(),
|
||||
tabUser(),
|
||||
tabSettings(),
|
||||
]
|
||||
|
||||
77
gringotts-frontend/pages/index/tab-check.js
Normal file
77
gringotts-frontend/pages/index/tab-check.js
Normal file
@@ -0,0 +1,77 @@
|
||||
import {
|
||||
apiGet,
|
||||
checkerOnly,
|
||||
checkOverMapping,
|
||||
checkTypeMapping,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
stringField,
|
||||
timeField,
|
||||
} from "../../components/constants.js";
|
||||
import {permissionDetailDialog} from "../../components/permission/dialog-permission.js";
|
||||
|
||||
export function tabCheck() {
|
||||
return {
|
||||
visibleOn: checkerOnly,
|
||||
title: '审核审查',
|
||||
icon: 'fa fa-shield-halved',
|
||||
reload: true,
|
||||
body: [
|
||||
{
|
||||
name: 'check_order_list',
|
||||
type: 'crud',
|
||||
api: apiGet('${base}/check_order/list'),
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
],
|
||||
columns: [
|
||||
stringField('description', '描述'),
|
||||
mappingField('type', '类型', checkTypeMapping),
|
||||
mappingField('over', '状态', checkOverMapping),
|
||||
timeField('createdTime', '创建时间'),
|
||||
stringField('createdUsername', '创建人', 100),
|
||||
timeField('modifiedTime', '最后修改时间'),
|
||||
stringField('modifiedUsername', '最后操作人', 100),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
visibleOn: '${!over}',
|
||||
type: 'action',
|
||||
label: '处理',
|
||||
level: 'link',
|
||||
...permissionDetailDialog(
|
||||
'parameters.confirmationId',
|
||||
[
|
||||
{
|
||||
type: 'action',
|
||||
label: '同意',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/APPLY'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '拒绝',
|
||||
actionType: 'ajax',
|
||||
close: true,
|
||||
api: apiGet('${base}/check_order/operation/${checkOrderId}/REJECT'),
|
||||
reload: 'check_order_list',
|
||||
},
|
||||
],
|
||||
),
|
||||
},
|
||||
{
|
||||
visibleOn: '${over}',
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...permissionDetailDialog('parameters.confirmationId'),
|
||||
},
|
||||
]),
|
||||
],
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
@@ -3,78 +3,92 @@ import {
|
||||
resourceDetailDialog,
|
||||
resourceEditeDialog
|
||||
} from "../../components/resource/dialog-resource.js";
|
||||
import {apiGet, apiPost, crudCommonOptions} from "../../components/constants.js";
|
||||
import {
|
||||
apiGet,
|
||||
arrayInCheck,
|
||||
arrayOutCheck,
|
||||
confirmationState,
|
||||
confirmationStateMapping,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
timeField,
|
||||
userOnly
|
||||
} from "../../components/constants.js";
|
||||
|
||||
export function resourceList() {
|
||||
return {
|
||||
type: 'crud',
|
||||
api: apiGet('${base}/data_resource/list'),
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'action',
|
||||
label: '',
|
||||
icon: 'fa fa-plus',
|
||||
...resourceAddDialog()
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
label: '名称',
|
||||
name: 'name',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
label: '描述',
|
||||
name: 'description',
|
||||
},
|
||||
mappingField('confirmationState', '确权状态', confirmationStateMapping),
|
||||
timeField('createdTime', '创建时间'),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
type: 'action',
|
||||
label: '详情',
|
||||
level: 'link',
|
||||
...resourceDetailDialog(),
|
||||
},
|
||||
{
|
||||
type: 'dropdown-button',
|
||||
level: 'link',
|
||||
icon: 'fa fa-ellipsis-h',
|
||||
hideCaret: true,
|
||||
trigger: 'hover',
|
||||
buttons: [
|
||||
{
|
||||
disabledOn: arrayOutCheck([confirmationState.none, confirmationState.draft], 'confirmationState'),
|
||||
disabledTip: '审查或确权成功后无法编辑',
|
||||
tooltipPlacement: 'top',
|
||||
type: 'action',
|
||||
label: '编辑',
|
||||
level: 'link',
|
||||
...resourceEditeDialog(),
|
||||
},
|
||||
{
|
||||
disabledOn: arrayInCheck([confirmationState.checking], 'confirmationState'),
|
||||
disabledTip: '审查中无法删除',
|
||||
tooltipPlacement: 'bottom',
|
||||
type: 'action',
|
||||
label: "删除",
|
||||
confirmTitle: '确认删除',
|
||||
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/data_resource/remove/${id}')
|
||||
},
|
||||
]
|
||||
},
|
||||
]),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
export function tabData() {
|
||||
return {
|
||||
visibleOn: userOnly,
|
||||
title: '数据资源',
|
||||
icon: 'fa fa-database',
|
||||
body: [
|
||||
{
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiPost('${base}/data_resource/list')
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'action',
|
||||
label: '新增数据资源',
|
||||
icon: 'fa fa-plus',
|
||||
...resourceAddDialog()
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
label: '名称',
|
||||
name: 'name',
|
||||
width: 200,
|
||||
},
|
||||
{
|
||||
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: [
|
||||
{
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...resourceDetailDialog(),
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '编辑',
|
||||
level: 'link',
|
||||
...resourceEditeDialog(),
|
||||
},
|
||||
{
|
||||
type: 'action',
|
||||
label: '删除',
|
||||
level: 'link',
|
||||
className: 'text-danger',
|
||||
confirmTitle: '确认删除',
|
||||
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/data_resource/remove/${id}')
|
||||
},
|
||||
]
|
||||
},
|
||||
]
|
||||
}
|
||||
]
|
||||
reload: true,
|
||||
body: resourceList(),
|
||||
}
|
||||
}
|
||||
114
gringotts-frontend/pages/index/tab-permissions.js
Normal file
114
gringotts-frontend/pages/index/tab-permissions.js
Normal file
@@ -0,0 +1,114 @@
|
||||
import {
|
||||
apiGet,
|
||||
confirmationStateMapping,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
providerOnly,
|
||||
stringField,
|
||||
stringWrapField,
|
||||
timeField,
|
||||
userOnly,
|
||||
} from "../../components/constants.js";
|
||||
import {
|
||||
permissionAddDialog,
|
||||
permissionDetailDialog,
|
||||
permissionEditeDialog,
|
||||
} from "../../components/permission/dialog-permission.js";
|
||||
|
||||
export function tabPermissions() {
|
||||
return {
|
||||
visibleOn: userOnly,
|
||||
title: '权属管理',
|
||||
icon: 'fa fa-user-shield',
|
||||
reload: true,
|
||||
body: {
|
||||
type: 'tabs',
|
||||
tabs: [
|
||||
{
|
||||
visibleOn: providerOnly,
|
||||
title: '确权管理',
|
||||
body: {
|
||||
type: 'crud',
|
||||
api: {
|
||||
...apiGet('${base}/confirmation/list')
|
||||
},
|
||||
...crudCommonOptions(),
|
||||
headerToolbar: [
|
||||
'reload',
|
||||
{
|
||||
type: 'action',
|
||||
label: '',
|
||||
icon: 'fa fa-plus',
|
||||
...permissionAddDialog()
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
stringField('name', '名称', 200),
|
||||
stringWrapField('description', '描述'),
|
||||
mappingField('state', '状态', confirmationStateMapping),
|
||||
timeField('createdTime', '创建时间'),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
type: 'action',
|
||||
label: '查看',
|
||||
level: 'link',
|
||||
...permissionDetailDialog(),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: '撤销',
|
||||
level: 'link',
|
||||
confirmTitle: '确认撤销',
|
||||
confirmText: '确认撤销名称为「${name}」的确权申请吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/confirmation/retract/${id}'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'DRAFT' || state === 'REJECT'}",
|
||||
type: 'action',
|
||||
label: '提交',
|
||||
level: 'link',
|
||||
confirmTitle: '确认提交',
|
||||
confirmText: '确认提交名称为「${name}」的确权申请吗?',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/confirmation/submit/${id}'),
|
||||
},
|
||||
{
|
||||
type: 'dropdown-button',
|
||||
level: 'link',
|
||||
icon: 'fa fa-ellipsis-h',
|
||||
hideCaret: true,
|
||||
trigger: 'hover',
|
||||
buttons: [
|
||||
{
|
||||
disabledOn: "${state !== 'DRAFT'}",
|
||||
type: 'action',
|
||||
label: '编辑',
|
||||
level: 'link',
|
||||
...permissionEditeDialog(),
|
||||
},
|
||||
{
|
||||
disabledOn: "${state === 'CHECKING'}",
|
||||
type: 'action',
|
||||
label: "删除",
|
||||
confirmTitle: '确认删除',
|
||||
confirmText: '确认删除名称为「${name}」的确权申请吗?删除后对应的数据资源处于未确权状态。',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/confirmation/remove/${id}'),
|
||||
},
|
||||
]
|
||||
},
|
||||
]),
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '授权管理',
|
||||
body: []
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import {administratorOnly} from "../../components/constants.js";
|
||||
|
||||
export function tabSettings() {
|
||||
return {
|
||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
||||
visibleOn: administratorOnly,
|
||||
title: '系统管理',
|
||||
icon: 'fa fa-gear',
|
||||
body: [
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
import {
|
||||
administratorOnly,
|
||||
apiGet,
|
||||
copyField,
|
||||
crudCommonOptions,
|
||||
mappingField,
|
||||
operationField,
|
||||
timeField,
|
||||
userRoleMapping,
|
||||
userStateMapping
|
||||
} from '../../components/constants.js'
|
||||
@@ -11,9 +14,10 @@ import {userAdministratorRegisterDialog} from "../../components/user/dialog-user
|
||||
|
||||
export function tabUser() {
|
||||
return {
|
||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
||||
visibleOn: administratorOnly,
|
||||
title: '用户管理',
|
||||
icon: 'fa fa-user',
|
||||
reload: true,
|
||||
body: [
|
||||
{
|
||||
type: 'crud',
|
||||
@@ -29,81 +33,49 @@ export function tabUser() {
|
||||
},
|
||||
],
|
||||
columns: [
|
||||
{
|
||||
name: 'username',
|
||||
label: '邮箱',
|
||||
...copyField(
|
||||
'username',
|
||||
undefined,
|
||||
undefined,
|
||||
userDetailDialog(),
|
||||
)
|
||||
},
|
||||
{
|
||||
label: '角色',
|
||||
width: 120,
|
||||
align: 'center',
|
||||
...mappingField('role', userRoleMapping)
|
||||
},
|
||||
{
|
||||
label: '账号状态',
|
||||
width: 80,
|
||||
align: 'center',
|
||||
...mappingField('state', userStateMapping)
|
||||
},
|
||||
{
|
||||
label: '创建时间',
|
||||
width: 150,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
|
||||
},
|
||||
{
|
||||
label: '上次登陆时间',
|
||||
width: 150,
|
||||
align: 'center',
|
||||
type: 'tpl',
|
||||
tpl: "${IF(lastLoginTime, DATETOSTR(lastLoginTime), '-')}"
|
||||
},
|
||||
{
|
||||
label: '操作',
|
||||
width: 100,
|
||||
type: 'operation',
|
||||
fixed: 'right',
|
||||
className: 'nowrap',
|
||||
buttons: [
|
||||
{
|
||||
visibleOn: "${state === 'CHECKING'}",
|
||||
label: '审核',
|
||||
icon: 'fa fa-fingerprint',
|
||||
level: 'primary',
|
||||
size: 'xs',
|
||||
...userCheckDialog(),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'NORMAL' && role !== 'ADMINISTRATOR'}",
|
||||
label: '禁用',
|
||||
icon: 'fa fa-ban',
|
||||
level: 'danger',
|
||||
size: 'xs',
|
||||
confirmText: '确认禁用账号${username}?',
|
||||
confirmTitle: '禁用账号',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/user_management/disable/${username}'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'DISABLED' && role !== 'ADMINISTRATOR'}",
|
||||
label: '启用',
|
||||
icon: 'fa fa-check',
|
||||
level: 'success',
|
||||
size: 'xs',
|
||||
confirmText: '确认启用账号${username}?',
|
||||
confirmTitle: '启用账号',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/user_management/enable/${username}'),
|
||||
}
|
||||
]
|
||||
},
|
||||
copyField(
|
||||
'username',
|
||||
'邮箱',
|
||||
undefined,
|
||||
undefined,
|
||||
userDetailDialog(),
|
||||
),
|
||||
mappingField('role', '角色', userRoleMapping, 120),
|
||||
mappingField('state', '账号状态', userStateMapping),
|
||||
timeField('createdTime', '创建时间'),
|
||||
timeField('lastLoginTime', '上次登陆时间'),
|
||||
operationField('操作', undefined, [
|
||||
{
|
||||
visibleOn: "${state === 'CHECKING'}",
|
||||
label: '审核',
|
||||
icon: 'fa fa-fingerprint',
|
||||
level: 'primary',
|
||||
size: 'xs',
|
||||
...userCheckDialog(),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'NORMAL' && role !== 'ADMINISTRATOR'}",
|
||||
label: '禁用',
|
||||
icon: 'fa fa-ban',
|
||||
level: 'danger',
|
||||
size: 'xs',
|
||||
confirmText: '确认禁用账号${username}?',
|
||||
confirmTitle: '禁用账号',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/user_management/disable/${username}'),
|
||||
},
|
||||
{
|
||||
visibleOn: "${state === 'DISABLED' && role !== 'ADMINISTRATOR'}",
|
||||
label: '启用',
|
||||
icon: 'fa fa-check',
|
||||
level: 'success',
|
||||
size: 'xs',
|
||||
confirmText: '确认启用账号${username}?',
|
||||
confirmTitle: '启用账号',
|
||||
actionType: 'ajax',
|
||||
api: apiGet('${base}/user_management/enable/${username}'),
|
||||
}
|
||||
]),
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
@@ -19,6 +19,12 @@
|
||||
<dependency>
|
||||
<groupId>com.eshore</groupId>
|
||||
<artifactId>gringotts-forest</artifactId>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>commons-logging</groupId>
|
||||
<artifactId>commons-logging</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.eshore.gringotts.web.domain.authentication.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.ManyToOne;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
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-29
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.TABLE_PREFIX + "authentication")
|
||||
@NamedEntityGraph(name = "authentication.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "authentication.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "evidences"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class Authentication extends CheckingNeededEntity {
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataResource target;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private Set<DataFile> evidences;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface DetailController<DETAIL_ITEM> {
|
||||
AmisResponse<DETAIL_ITEM> detail(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface ListController<LIST_ITEM> {
|
||||
AmisResponse<ImmutableList<LIST_ITEM>> list() throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface RemoveController {
|
||||
AmisResponse<Object> remove(Long id) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SaveController<SAVE_ITEM> {
|
||||
AmisResponse<Long> save(SAVE_ITEM item) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> extends SaveController<SAVE_ITEM>, ListController<LIST_ITEM>, DetailController<DETAIL_ITEM>, RemoveController {
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package com.eshore.gringotts.web.domain.base.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
public abstract class SimpleControllerSupport<ENTITY extends SimpleEntity, SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> implements SimpleController<SAVE_ITEM, LIST_ITEM, DETAIL_ITEM> {
|
||||
protected static final String SAVE = "/save";
|
||||
protected static final String LIST = "/list";
|
||||
protected static final String DETAIL = "/detail/{id}";
|
||||
protected static final String REMOVE = "/remove/{id}";
|
||||
|
||||
private final SimpleServiceSupport<ENTITY> service;
|
||||
|
||||
public SimpleControllerSupport(SimpleServiceSupport<ENTITY> service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@PostMapping(SAVE)
|
||||
@Override
|
||||
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||
return AmisResponse.responseSuccess(service.save(fromSaveItem(item)));
|
||||
}
|
||||
|
||||
@GetMapping(LIST)
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<LIST_ITEM>> list() {
|
||||
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||
try {
|
||||
return toListItem(entity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@GetMapping(DETAIL)
|
||||
@Override
|
||||
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||
}
|
||||
|
||||
@GetMapping(REMOVE)
|
||||
@Override
|
||||
public AmisResponse<Object> remove(@PathVariable Long id) {
|
||||
service.remove(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
protected abstract ENTITY fromSaveItem(SAVE_ITEM item) throws Exception;
|
||||
|
||||
protected abstract LIST_ITEM toListItem(ENTITY entity) throws Exception;
|
||||
|
||||
protected abstract DETAIL_ITEM toDetailItem(ENTITY entity) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class CheckingNeededEntity extends LogicDeleteEntity {
|
||||
private String description;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private State state = State.DRAFT;
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 无确权
|
||||
*/
|
||||
NONE,
|
||||
/**
|
||||
* 草稿
|
||||
*/
|
||||
DRAFT,
|
||||
/**
|
||||
* 审查中
|
||||
*/
|
||||
CHECKING,
|
||||
/**
|
||||
* 正常
|
||||
*/
|
||||
NORMAL,
|
||||
/**
|
||||
* 驳回
|
||||
*/
|
||||
REJECT,
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.springframework.data.annotation.CreatedDate;
|
||||
import org.springframework.data.annotation.LastModifiedDate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class DatetimeOnlyEntity extends IdOnlyEntity {
|
||||
@CreatedDate
|
||||
private LocalDateTime createdTime;
|
||||
@LastModifiedDate
|
||||
private LocalDateTime modifiedTime;
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.TreeNode;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import java.io.IOException;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonDeserialize(using = FileInfo.FileInfoDeserializer.class)
|
||||
public final class FileInfo {
|
||||
private String id;
|
||||
private String name;
|
||||
private String filename;
|
||||
private Long value;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.GeneratedValue;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@SoftDelete(columnName = "delete")
|
||||
public class LogicDeleteEntity extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private Boolean deleted = false;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.SoftDelete;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* 实体类公共字段
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-20
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@SoftDelete(columnName = "delete")
|
||||
public class LogicDeleteIdOnlyEntity extends IdOnlyEntity {
|
||||
@Column(nullable = false)
|
||||
private Boolean deleted = false;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleDetailItem<ENTITY> {
|
||||
private Long id;
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.MappedSuperclass;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.EntityListeners;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.ForeignKey;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.persistence.OneToOne;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@ToString(callSuper = true)
|
||||
@MappedSuperclass
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
public class SimpleEntity extends IdOnlyEntity {
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleListItem<ENTITY> {
|
||||
private Long id;
|
||||
private String createdUsername;
|
||||
private LocalDateTime createdTime;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 创建对象使用的接收类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Data
|
||||
public abstract class SimpleSaveItem<ENTITY> {
|
||||
private Long id;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
|
||||
/**
|
||||
* 需要审查
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public interface CheckingService {
|
||||
void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters);
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.util.ClassUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import jakarta.persistence.Query;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class LogicDeleteService<ENTITY extends LogicDeleteEntity> extends SimpleServiceSupport<ENTITY> {
|
||||
private final EntityManager manager;
|
||||
|
||||
public LogicDeleteService(SimpleRepository<ENTITY, Long> repository, UserService userService, EntityManager manager) {
|
||||
super(repository, userService);
|
||||
this.manager = manager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableList<Predicate> extraListPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
return Lists.immutable.of(builder.equal(root.get("deleted"), false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ImmutableList<Predicate> extraDetailPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
return Lists.immutable.of(builder.equal(root.get("deleted"), false));
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
String entityName = ClassUtil.getTypeArgument(this.getClass()).getSimpleName();
|
||||
Query query = manager.createQuery(StrUtil.format("update {} entity set deleted=true where id=?1", entityName));
|
||||
query.setParameter(1, id);
|
||||
query.executeUpdate();
|
||||
}
|
||||
}
|
||||
@@ -1,25 +1,28 @@
|
||||
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 com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import java.util.Optional;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
public abstract class SimpleService<E, ID> {
|
||||
protected abstract SimpleRepository<E, ID> repository();
|
||||
public interface SimpleService<ENTITY extends SimpleEntity> {
|
||||
Long save(ENTITY entity) throws Exception;
|
||||
|
||||
public ImmutableList<E> list() {
|
||||
return Lists.immutable.ofAll(repository().findAll());
|
||||
}
|
||||
ImmutableList<ENTITY> list() throws Exception;
|
||||
|
||||
public E detail(ID id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return null;
|
||||
}
|
||||
return repository().findById(id).orElse(null);
|
||||
}
|
||||
ImmutableList<ENTITY> list(ImmutableSet<Long> ids) throws Exception;
|
||||
|
||||
Optional<ENTITY> detailOptional(Long id) throws Exception;
|
||||
|
||||
ENTITY detail(Long id) throws Exception;
|
||||
|
||||
ENTITY detailOrThrow(Long id) throws Exception;
|
||||
|
||||
ENTITY detailOrNull(Long id) throws Exception;
|
||||
|
||||
void remove(Long id) throws Exception;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,151 @@
|
||||
package com.eshore.gringotts.web.domain.base.service;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import cn.hutool.core.bean.copier.CopyOptions;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import jakarta.persistence.criteria.CriteriaBuilder;
|
||||
import jakarta.persistence.criteria.CriteriaQuery;
|
||||
import jakarta.persistence.criteria.Predicate;
|
||||
import jakarta.persistence.criteria.Root;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.Optional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Lists;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.list.MutableList;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.data.domain.Sort;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
public abstract class SimpleServiceSupport<ENTITY extends SimpleEntity> implements SimpleService<ENTITY> {
|
||||
protected final SimpleRepository<ENTITY, Long> repository;
|
||||
protected final UserService userService;
|
||||
|
||||
public SimpleServiceSupport(SimpleRepository<ENTITY, Long> repository, UserService userService) {
|
||||
this.repository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public Long save(ENTITY entity) {
|
||||
if (ObjectUtil.isNotNull(entity.getId())) {
|
||||
Long id = entity.getId();
|
||||
ENTITY targetEntity = repository.findById(entity.getId()).orElseThrow(() -> new IdNotFoundException(id));
|
||||
BeanUtil.copyProperties(
|
||||
entity,
|
||||
targetEntity,
|
||||
CopyOptions.create()
|
||||
.setIgnoreProperties("id", "createdUser", "createdTime", "modifiedUser", "modifiedTime")
|
||||
);
|
||||
entity = targetEntity;
|
||||
}
|
||||
User user = userService.currentLoginUser();
|
||||
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||
entity.setCreatedUser(user);
|
||||
}
|
||||
entity.setModifiedUser(user);
|
||||
entity = repository.save(entity);
|
||||
return entity.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list() {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.empty();
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
predicates.addAllIterable(extraListPredicates(root, query, builder));
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ImmutableList<ENTITY> list(ImmutableSet<Long> ids) {
|
||||
return Lists.immutable.ofAll(repository.findAll(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.in(root.get("id")).value(ids.select(ObjectUtil::isNotNull))
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
predicates.addAllIterable(extraListPredicates(root, query, builder));
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
},
|
||||
Sort.by("createdTime").descending()
|
||||
));
|
||||
}
|
||||
|
||||
protected ImmutableList<Predicate> extraListPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ENTITY> detailOptional(Long id) {
|
||||
if (ObjectUtil.isNull(id)) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return repository.findOne(
|
||||
(root, query, builder) -> {
|
||||
MutableList<Predicate> predicates = Lists.mutable.of(
|
||||
builder.equal(root.get("id"), id)
|
||||
);
|
||||
User user = userService.currentLoginUser();
|
||||
if (User.isNotAdministrator(user)) {
|
||||
predicates.add(builder.equal(root.get("createdUser"), user));
|
||||
}
|
||||
predicates.addAllIterable(extraDetailPredicates(root, query, builder));
|
||||
return builder.and(predicates.toArray(new Predicate[predicates.size()]));
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
protected ImmutableList<Predicate> extraDetailPredicates(Root<ENTITY> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
|
||||
return Lists.immutable.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detail(Long id) {
|
||||
return detailOrNull(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrThrow(Long id) {
|
||||
return detailOptional(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ENTITY detailOrNull(Long id) {
|
||||
return detailOptional(id).orElse(null);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
@Override
|
||||
public void remove(Long id) {
|
||||
if (ObjectUtil.isNotNull(id)) {
|
||||
repository.deleteById(id);
|
||||
}
|
||||
}
|
||||
|
||||
public static final class IdNotFoundException extends RuntimeException {
|
||||
public IdNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的资源不存在", id));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.eshore.gringotts.web.domain.check.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.ListController;
|
||||
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.check.service.CheckOrderService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.list.ImmutableList;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
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.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* 监管
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-28
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("check_order")
|
||||
public class CheckOrderController implements ListController<CheckOrderController.ListItem> {
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public CheckOrderController(CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@GetMapping("/list")
|
||||
@Override
|
||||
public AmisResponse<ImmutableList<CheckOrderController.ListItem>> list() throws Exception {
|
||||
return AmisResponse.responseSuccess(checkOrderService.list().collect(this::toListItem));
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private ListItem toListItem(CheckOrder order) {
|
||||
ListItem item = new ListItem();
|
||||
item.setCheckOrderId(order.getId());
|
||||
item.setDescription(order.getDescription());
|
||||
item.setType(order.getType());
|
||||
item.setParameters(mapper.readValue(order.getParameters(), new TypeReference<>() {}));
|
||||
item.setOver(order.getOver());
|
||||
item.setCreatedUsername(order.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(order.getCreatedTime());
|
||||
item.setModifiedUsername(order.getModifiedUser().getUsername());
|
||||
item.setModifiedTime(order.getModifiedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/operation/{id}/{operation}")
|
||||
public AmisResponse<Object> operation(@PathVariable Long id, @PathVariable CheckOrder.Operation operation) throws JsonProcessingException {
|
||||
log.info("id:{}, operation:{}", id, operation);
|
||||
checkOrderService.operation(id, operation);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class ListItem {
|
||||
private Long checkOrderId;
|
||||
private String description;
|
||||
private CheckOrder.Type type;
|
||||
private ImmutableMap<String, Object> parameters;
|
||||
private Boolean over;
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
private String modifiedUsername;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
package com.eshore.gringotts.web.domain.check.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.hibernate.annotations.DynamicUpdate;
|
||||
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.TABLE_PREFIX + "check_order")
|
||||
@NamedEntityGraph(name = "check_order.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "check_order.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
@NoArgsConstructor
|
||||
public class CheckOrder extends SimpleEntity {
|
||||
@Column(nullable = false)
|
||||
private String keyword;
|
||||
@Column(nullable = false)
|
||||
private String description;
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Type type;
|
||||
/**
|
||||
* JSON 结构 Map<String, Object>
|
||||
*/
|
||||
@Column(nullable = false)
|
||||
private String parameters;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Enumerated(EnumType.STRING)
|
||||
private Target target;
|
||||
@Column(nullable = false)
|
||||
private String targetClass;
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private User targetUser;
|
||||
@Enumerated(EnumType.STRING)
|
||||
private User.Role targetRole;
|
||||
|
||||
@Column(nullable = false)
|
||||
private Boolean over = false;
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User targetUser
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.USER;
|
||||
this.targetClass = targetClass;
|
||||
this.targetUser = targetUser;
|
||||
}
|
||||
|
||||
public CheckOrder(
|
||||
String keyword,
|
||||
String description,
|
||||
Type type,
|
||||
String parameters,
|
||||
String targetClass,
|
||||
User.Role targetRole
|
||||
) {
|
||||
this.keyword = keyword;
|
||||
this.description = description;
|
||||
this.type = type;
|
||||
this.parameters = parameters;
|
||||
this.target = Target.ROLE;
|
||||
this.targetClass = targetClass;
|
||||
this.targetRole = targetRole;
|
||||
}
|
||||
|
||||
public enum Operation {
|
||||
APPLY,
|
||||
REJECT,
|
||||
}
|
||||
|
||||
public enum Type {
|
||||
CONFIRMATION,
|
||||
AUTHENTICATION,
|
||||
}
|
||||
|
||||
public enum Target {
|
||||
USER,
|
||||
ROLE,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.eshore.gringotts.web.domain.check.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface CheckOrderRepository extends SimpleRepository<CheckOrder, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<CheckOrder> findAll(Specification<CheckOrder> specification);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<CheckOrder> findAll(Specification<CheckOrder> specification, Sort sort);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "check_order.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<CheckOrder> findOne(Specification<CheckOrder> specification);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update CheckOrder check set check.over = true, check.modifiedUser = ?2, check.modifiedTime = current_timestamp where check.id = ?1")
|
||||
void overById(Long id, User modifiedUser);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.eshore.gringotts.web.domain.check.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.check.repository.CheckOrderRepository;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-29
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CheckOrderService extends SimpleServiceSupport<CheckOrder> {
|
||||
private final ApplicationContext applicationContext;
|
||||
private final ObjectMapper mapper;
|
||||
private final CheckOrderRepository checkOrderRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public CheckOrderService(CheckOrderRepository repository, UserService userService, ApplicationContext applicationContext, Jackson2ObjectMapperBuilder builder) {
|
||||
super(repository, userService);
|
||||
this.applicationContext = applicationContext;
|
||||
this.mapper = builder.build();
|
||||
this.checkOrderRepository = repository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
public void operation(Long id, CheckOrder.Operation operation) throws JsonProcessingException {
|
||||
CheckOrder order = detailOrThrow(id);
|
||||
CheckingService service = applicationContext.getBean(order.getTargetClass(), CheckingService.class);
|
||||
if (ObjectUtil.isNull(service)) {
|
||||
throw new RuntimeException(StrUtil.format("名为「{}」的服务未找到", order.getTargetClass()));
|
||||
}
|
||||
ImmutableMap<String, Object> parameters = mapper.readValue(order.getParameters(), new TypeReference<>() {});
|
||||
service.onChecked(order, operation, parameters);
|
||||
}
|
||||
|
||||
public void over(Long id) {
|
||||
checkOrderRepository.overById(id, userService.currentLoginUser());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.controller;
|
||||
|
||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
||||
import com.eshore.gringotts.web.domain.base.controller.SimpleControllerSupport;
|
||||
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService;
|
||||
import com.eshore.gringotts.web.domain.resource.service.DataResourceService;
|
||||
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import java.time.LocalDateTime;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Sets;
|
||||
import org.eclipse.collections.api.set.ImmutableSet;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("confirmation")
|
||||
public class ConfirmationController extends SimpleControllerSupport<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||
private final ConfirmationService confirmationService;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public ConfirmationController(ConfirmationService service, ConfirmationService confirmationService, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
super(service);
|
||||
this.confirmationService = confirmationService;
|
||||
this.dataResourceService = dataResourceService;
|
||||
this.dataFileService = dataFileService;
|
||||
}
|
||||
|
||||
@GetMapping("/submit/{id}")
|
||||
public AmisResponse<Object> submit(@PathVariable Long id) throws JsonProcessingException {
|
||||
confirmationService.submit(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@GetMapping("/retract/{id}")
|
||||
public AmisResponse<Object> retract(@PathVariable Long id) {
|
||||
confirmationService.retract(id);
|
||||
return AmisResponse.responseSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Confirmation fromSaveItem(SaveItem item) {
|
||||
Confirmation confirmation = new Confirmation();
|
||||
confirmation.setId(item.getId());
|
||||
confirmation.setDescription(item.getDescription());
|
||||
confirmation.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
|
||||
confirmation.setEvidences(dataFileService.list(item.getEvidenceFiles().collect(FileInfo::getValue)).toSet());
|
||||
return confirmation;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ListItem toListItem(Confirmation entity) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(entity.getId());
|
||||
item.setName(entity.getTarget().getName());
|
||||
item.setDescription(entity.getDescription());
|
||||
item.setState(entity.getState().name());
|
||||
item.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(entity.getCreatedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected DetailItem toDetailItem(Confirmation entity) {
|
||||
return new DetailItem(entity);
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SaveItem extends SimpleSaveItem<Confirmation> {
|
||||
private Long targetId;
|
||||
private String description;
|
||||
private ImmutableSet<FileInfo> evidenceFiles;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class ListItem extends SimpleListItem<Confirmation> {
|
||||
private String name;
|
||||
private String description;
|
||||
private String state;
|
||||
}
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class DetailItem extends SaveItem {
|
||||
private String targetName;
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
private String modifiedUsername;
|
||||
|
||||
public DetailItem(Confirmation confirmation) {
|
||||
this.setId(confirmation.getId());
|
||||
this.setTargetId(confirmation.getTarget().getId());
|
||||
this.setTargetName(confirmation.getTarget().getName());
|
||||
this.setDescription(confirmation.getDescription());
|
||||
this.setEvidenceFiles(Sets.immutable.ofAll(confirmation.getEvidences()).collect(FileInfo::new));
|
||||
this.setCreatedTime(confirmation.getCreatedTime());
|
||||
this.setCreatedUsername(confirmation.getCreatedUser().getUsername());
|
||||
this.setModifiedTime(confirmation.getModifiedTime());
|
||||
this.setModifiedUsername(confirmation.getModifiedUser().getUsername());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.CheckingNeededEntity;
|
||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.JoinTable;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
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-26
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString(callSuper = true)
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@Table(name = Constants.TABLE_PREFIX + "confirmation")
|
||||
@NamedEntityGraph(name = "confirmation.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "confirmation.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "target"),
|
||||
@NamedAttributeNode(value = "evidences"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class Confirmation extends CheckingNeededEntity {
|
||||
@OneToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
private DataResource target;
|
||||
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private Set<DataFile> evidences;
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.repository;
|
||||
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import jakarta.transaction.Transactional;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
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;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@Repository
|
||||
public interface ConfirmationRepository extends SimpleRepository<Confirmation, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Confirmation> findAll(Specification<Confirmation> specification);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<Confirmation> findAll(Specification<Confirmation> specification, Sort sort);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<Confirmation> findOne(Specification<Confirmation> specification);
|
||||
|
||||
Boolean existsByTarget_Id(Long id);
|
||||
|
||||
@Transactional
|
||||
@Modifying
|
||||
@Query("update Confirmation confirmation \n" +
|
||||
"set confirmation.state = ?2, \n" +
|
||||
" confirmation.modifiedUser = ?3, \n" +
|
||||
" confirmation.modifiedTime = current_timestamp \n" +
|
||||
"where confirmation.id = ?1")
|
||||
void updateStateById(Long id, Confirmation.State state, User modifiedUser);
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.eshore.gringotts.web.domain.confirmation.service;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.service.CheckingService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
import com.eshore.gringotts.web.domain.check.entity.CheckOrder;
|
||||
import com.eshore.gringotts.web.domain.check.service.CheckOrderService;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
import com.eshore.gringotts.web.domain.confirmation.repository.ConfirmationRepository;
|
||||
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import jakarta.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.eclipse.collections.api.factory.Maps;
|
||||
import org.eclipse.collections.api.map.ImmutableMap;
|
||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-26
|
||||
*/
|
||||
@Slf4j
|
||||
@Service("com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService")
|
||||
public class ConfirmationService extends SimpleServiceSupport<Confirmation> implements CheckingService {
|
||||
private final ConfirmationRepository confirmationRepository;
|
||||
private final UserService userService;
|
||||
private final CheckOrderService checkOrderService;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
public ConfirmationService(ConfirmationRepository confirmationRepository, UserService userService, CheckOrderService checkOrderService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(confirmationRepository, userService);
|
||||
this.confirmationRepository = confirmationRepository;
|
||||
this.userService = userService;
|
||||
this.checkOrderService = checkOrderService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long save(Confirmation entity) {
|
||||
if (ObjectUtil.isNull(entity.getId()) && confirmationRepository.existsByTarget_Id(entity.getTarget().getId())) {
|
||||
throw new ConfirmationDuplicatedException();
|
||||
}
|
||||
return super.save(entity);
|
||||
}
|
||||
|
||||
@Transactional(rollbackOn = Throwable.class)
|
||||
public void submit(Long id) throws JsonProcessingException {
|
||||
Confirmation confirmation = detailOrThrow(id);
|
||||
log.info("confirmation: {}", confirmation);
|
||||
confirmation.setState(Confirmation.State.CHECKING);
|
||||
checkOrderService.save(new CheckOrder(
|
||||
"confirmation_check",
|
||||
StrUtil.format("数据资源「{}」的确权申请", confirmation.getTarget().getName()),
|
||||
CheckOrder.Type.CONFIRMATION,
|
||||
mapper.writeValueAsString(Maps.immutable.of("confirmationId", confirmation.getId())),
|
||||
"com.eshore.gringotts.web.domain.confirmation.service.ConfirmationService",
|
||||
User.Role.ADMINISTRATOR
|
||||
));
|
||||
save(confirmation);
|
||||
}
|
||||
|
||||
public void retract(Long id) {
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChecked(CheckOrder order, CheckOrder.Operation operation, ImmutableMap<String, Object> parameters) {
|
||||
if (StrUtil.equals(order.getKeyword(), "confirmation_check")) {
|
||||
Long id = (Long) parameters.get("confirmationId");
|
||||
switch (operation) {
|
||||
case APPLY:
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.NORMAL, userService.currentLoginUser());
|
||||
checkOrderService.over(order.getId());
|
||||
break;
|
||||
case REJECT:
|
||||
confirmationRepository.updateStateById(id, Confirmation.State.DRAFT, userService.currentLoginUser());
|
||||
checkOrderService.over(order.getId());
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static final class ConfirmationDuplicatedException extends RuntimeException {
|
||||
public ConfirmationDuplicatedException() {
|
||||
super("数据资源已绑定确权申请,无法再次申请");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,8 +2,11 @@ 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.base.controller.SimpleControllerSupport;
|
||||
import com.eshore.gringotts.web.domain.base.entity.FileInfo;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||
import com.eshore.gringotts.web.domain.confirmation.entity.Confirmation;
|
||||
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;
|
||||
@@ -26,14 +29,8 @@ import java.time.LocalDateTime;
|
||||
import java.util.Map;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.ToString;
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -46,234 +43,228 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/data_resource")
|
||||
public class DataResourceController {
|
||||
public class DataResourceController extends SimpleControllerSupport<DataResource, DataResourceController.SaveItem, DataResourceController.ListItem, DataResourceController.DetailItem> {
|
||||
private final ObjectMapper mapper;
|
||||
private final DataResourceService dataResourceService;
|
||||
private final DataFileService dataFileService;
|
||||
|
||||
public DataResourceController(Jackson2ObjectMapperBuilder builder, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||
this.mapper = builder.build();
|
||||
this.dataResourceService = dataResourceService;
|
||||
public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) {
|
||||
super(dataResourceService);
|
||||
this.dataFileService = dataFileService;
|
||||
this.mapper = builder.build();
|
||||
}
|
||||
|
||||
@PostMapping("/save")
|
||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
||||
log.info("Save request: {}", request);
|
||||
ResourceType type = request.generateResourceType(dataFileService);
|
||||
ResourceFormat format = request.generateResourceFormat(mapper);
|
||||
dataResourceService.create(request.id, request.name, request.description, type, format, dataFileService.detail(request.exampleFileId));
|
||||
@Override
|
||||
protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException {
|
||||
ResourceType type = generateResourceType(item);
|
||||
ResourceFormat format = generateResourceFormat(item);
|
||||
DataResource dataResource = new DataResource();
|
||||
dataResource.setId(item.getId());
|
||||
dataResource.setName(item.getName());
|
||||
dataResource.setDescription(item.getDescription());
|
||||
dataResource.setType(type);
|
||||
dataResource.setFormat(format);
|
||||
if (ObjectUtil.isNotNull(item.getExampleFile())) {
|
||||
dataResource.setExample(dataFileService.detail(item.getExampleFile().getValue()));
|
||||
}
|
||||
return dataResource;
|
||||
}
|
||||
|
||||
@PostMapping("/list")
|
||||
public AmisListResponse list() {
|
||||
return AmisResponse.responseListData(dataResourceService.list().collect(DataResourceListItem::new));
|
||||
@Override
|
||||
protected ListItem toListItem(DataResource dataResource) {
|
||||
ListItem item = new ListItem();
|
||||
item.setId(dataResource.getId());
|
||||
item.setName(dataResource.getName());
|
||||
item.setDescription(dataResource.getDescription());
|
||||
item.setType(dataResource.getType().getResourceType().name());
|
||||
item.setFormat(dataResource.getFormat().getFormatType().name());
|
||||
if (ObjectUtil.isNotNull(dataResource.getConfirmation())) {
|
||||
item.setConfirmationId(dataResource.getConfirmation().getId());
|
||||
item.setConfirmationState(dataResource.getConfirmation().getState());
|
||||
} else {
|
||||
item.setConfirmationState(Confirmation.State.NONE);
|
||||
}
|
||||
item.setCreatedUser(dataResource.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(dataResource.getCreatedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/detail/{id}")
|
||||
public AmisResponse<DataResourceDetail> detail(@PathVariable Long id) throws JsonProcessingException {
|
||||
return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id)));
|
||||
@Override
|
||||
protected DetailItem toDetailItem(DataResource dataResource) throws Exception {
|
||||
DetailItem item = new DetailItem();
|
||||
item.setId(dataResource.getId());
|
||||
item.setResourceTypeId(dataResource.getType().getId());
|
||||
item.setResourceFormatId(dataResource.getFormat().getId());
|
||||
item.setName(dataResource.getName());
|
||||
item.setDescription(dataResource.getDescription());
|
||||
item.setResourceType(dataResource.getType().getResourceType());
|
||||
switch (dataResource.getType().getResourceType()) {
|
||||
case API:
|
||||
ApiResourceType apiType = (ApiResourceType) dataResource.getType();
|
||||
item.setApiUrl(apiType.getUrl());
|
||||
item.setApiUsername(apiType.getUsername());
|
||||
item.setApiPassword(apiType.getPassword());
|
||||
break;
|
||||
case FILE:
|
||||
FileResourceType fileType = (FileResourceType) dataResource.getType();
|
||||
item.setFile(new FileInfo(fileType.getFile()));
|
||||
break;
|
||||
case DATABASE:
|
||||
DatabaseResourceType databaseType = (DatabaseResourceType) dataResource.getType();
|
||||
item.setDatabaseType(databaseType.getDatabaseType().name());
|
||||
item.setDatabaseJdbc(databaseType.getJdbc());
|
||||
item.setDatabaseUsername(databaseType.getUsername());
|
||||
item.setDatabasePassword(databaseType.getPassword());
|
||||
break;
|
||||
case HDFS:
|
||||
HDFSResourceType hdfsType = (HDFSResourceType) dataResource.getType();
|
||||
item.setCoreSiteFile(new FileInfo(hdfsType.getCoreSite()));
|
||||
item.setHdfsSiteFile(new FileInfo(hdfsType.getHdfsSite()));
|
||||
break;
|
||||
case FTP:
|
||||
FtpResourceType ftpType = (FtpResourceType) dataResource.getType();
|
||||
item.setFtpUrl(ftpType.getUrl());
|
||||
item.setFtpUsername(ftpType.getUsername());
|
||||
item.setFtpPassword(ftpType.getPassword());
|
||||
item.setFtpPath(ftpType.getPath());
|
||||
item.setFtpRegexFilter(ftpType.getRegexFilter());
|
||||
break;
|
||||
}
|
||||
item.setFormatType(dataResource.getFormat().getFormatType());
|
||||
switch (dataResource.getFormat().getFormatType()) {
|
||||
case NONE:
|
||||
case LINE:
|
||||
break;
|
||||
case JSON:
|
||||
JsonResourceFormat jsonFormat = (JsonResourceFormat) dataResource.getFormat();
|
||||
item.setJsonSchemaText(jsonFormat.getSchema());
|
||||
item.setJsonSchema(mapper.readValue(jsonFormat.getSchema(), Map.class));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
item.setJsonLineSchemaText(jsonLineFormat.getSchema());
|
||||
item.setJsonLineSchema(mapper.readValue(jsonLineFormat.getSchema(), Map.class));
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
|
||||
item.setCsvSchemaText(csvFormat.getSchema());
|
||||
item.setCsvSchema(mapper.readValue(csvFormat.getSchema(), Map.class));
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
item.setExampleFile(new FileInfo(dataResource.getExample()));
|
||||
}
|
||||
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
|
||||
item.setCreatedTime(dataResource.getCreatedTime());
|
||||
item.setModifiedUsername(dataResource.getModifiedUser().getUsername());
|
||||
item.setModifiedTime(dataResource.getModifiedTime());
|
||||
return item;
|
||||
}
|
||||
|
||||
@GetMapping("/remove/{id}")
|
||||
public void remove(@PathVariable Long id) {
|
||||
dataResourceService.remove(id);
|
||||
private ResourceType generateResourceType(SaveItem item) {
|
||||
ResourceType type = null;
|
||||
switch (item.getResourceType()) {
|
||||
case API:
|
||||
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
|
||||
break;
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(item.getFile().getValue());
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case DATABASE:
|
||||
type = new DatabaseResourceType(
|
||||
item.getDatabaseJdbc(),
|
||||
item.getDatabaseUsername(),
|
||||
item.getDatabasePassword(),
|
||||
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, item.getDatabaseType())
|
||||
);
|
||||
break;
|
||||
case HDFS:
|
||||
type = new HDFSResourceType(dataFileService.detail(item.getCoreSiteFile().getValue()), dataFileService.detail(item.getHdfsSiteFile().getValue()));
|
||||
break;
|
||||
case FTP:
|
||||
type = new FtpResourceType(item.getFtpUrl(), item.getFtpUsername(), item.getFtpPassword(), item.getFtpPath(), item.getFtpRegexFilter());
|
||||
break;
|
||||
}
|
||||
type.setId(item.getResourceTypeId());
|
||||
return type;
|
||||
}
|
||||
|
||||
private ResourceFormat generateResourceFormat(SaveItem item) throws JsonProcessingException {
|
||||
ResourceFormat format = null;
|
||||
switch (item.getFormatType()) {
|
||||
case NONE:
|
||||
format = new NoneResourceFormat();
|
||||
break;
|
||||
case LINE:
|
||||
format = new LineResourceFormat();
|
||||
break;
|
||||
case JSON:
|
||||
format = new JsonResourceFormat(mapper.writeValueAsString(item.getJsonSchema()));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
format = new JsonLineResourceFormat(mapper.writeValueAsString(item.getJsonLineSchema()));
|
||||
break;
|
||||
case CSV:
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(item.getCsvSchema()));
|
||||
break;
|
||||
}
|
||||
format.setId(item.getResourceFormatId());
|
||||
return format;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class CreateRequest {
|
||||
protected Long id;
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected Long resourceTypeId;
|
||||
protected ResourceType.Type resourceType;
|
||||
protected String apiUrl;
|
||||
protected String apiUsername;
|
||||
protected String apiPassword;
|
||||
protected Long fileId;
|
||||
protected String databaseType;
|
||||
protected String databaseJdbc;
|
||||
protected String databaseUsername;
|
||||
protected String databasePassword;
|
||||
protected Long coreSiteFileId;
|
||||
protected Long hdfsSiteFileId;
|
||||
protected String ftpUrl;
|
||||
protected String ftpUsername;
|
||||
protected String ftpPassword;
|
||||
protected String ftpPath;
|
||||
protected String ftpRegexFilter;
|
||||
protected Long resourceFormatId;
|
||||
protected ResourceFormat.Type formatType;
|
||||
protected Map<?, ?> jsonSchema;
|
||||
protected String jsonSchemaText;
|
||||
protected Map<?, ?> jsonLineSchema;
|
||||
protected String jsonLineSchemaText;
|
||||
protected Map<?, ?> csvSchema;
|
||||
protected String csvSchemaText;
|
||||
protected Long exampleFileId;
|
||||
|
||||
public ResourceType generateResourceType(DataFileService dataFileService) {
|
||||
ResourceType type = null;
|
||||
switch (resourceType) {
|
||||
case API:
|
||||
type = new ApiResourceType(apiUrl, apiUsername, apiPassword);
|
||||
break;
|
||||
case FILE:
|
||||
DataFile dataFile = dataFileService.detail(fileId);
|
||||
type = new FileResourceType(dataFile);
|
||||
break;
|
||||
case DATABASE:
|
||||
type = new DatabaseResourceType(
|
||||
databaseJdbc,
|
||||
databaseUsername,
|
||||
databasePassword,
|
||||
EnumUtil.fromString(DatabaseResourceType.DatabaseType.class, databaseType)
|
||||
);
|
||||
break;
|
||||
case HDFS:
|
||||
type = new HDFSResourceType(dataFileService.detail(coreSiteFileId), dataFileService.detail(hdfsSiteFileId));
|
||||
break;
|
||||
case FTP:
|
||||
type = new FtpResourceType(ftpUrl, ftpUsername, ftpPassword, ftpPath, ftpRegexFilter);
|
||||
break;
|
||||
}
|
||||
type.setId(resourceTypeId);
|
||||
return type;
|
||||
}
|
||||
|
||||
public ResourceFormat generateResourceFormat(ObjectMapper mapper) throws JsonProcessingException {
|
||||
ResourceFormat format = null;
|
||||
switch (formatType) {
|
||||
case NONE:
|
||||
format = new NoneResourceFormat();
|
||||
break;
|
||||
case LINE:
|
||||
format = new LineResourceFormat();
|
||||
break;
|
||||
case JSON:
|
||||
format = new JsonResourceFormat(mapper.writeValueAsString(jsonSchema));
|
||||
break;
|
||||
case JSON_LINE:
|
||||
format = new JsonLineResourceFormat(mapper.writeValueAsString(jsonLineSchema));
|
||||
break;
|
||||
case CSV:
|
||||
format = new CsvResourceFormat(mapper.writeValueAsString(csvSchema));
|
||||
break;
|
||||
}
|
||||
format.setId(resourceFormatId);
|
||||
return format;
|
||||
}
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static class SaveItem extends SimpleSaveItem<DataResource> {
|
||||
private String name;
|
||||
private String description;
|
||||
private Long resourceTypeId;
|
||||
private ResourceType.Type resourceType;
|
||||
private String apiUrl;
|
||||
private String apiUsername;
|
||||
private String apiPassword;
|
||||
private FileInfo file;
|
||||
private String databaseType;
|
||||
private String databaseJdbc;
|
||||
private String databaseUsername;
|
||||
private String databasePassword;
|
||||
private FileInfo coreSiteFile;
|
||||
private FileInfo hdfsSiteFile;
|
||||
private String ftpUrl;
|
||||
private String ftpUsername;
|
||||
private String ftpPassword;
|
||||
private String ftpPath;
|
||||
private String ftpRegexFilter;
|
||||
private Long resourceFormatId;
|
||||
private ResourceFormat.Type formatType;
|
||||
private Map<?, ?> jsonSchema;
|
||||
private String jsonSchemaText;
|
||||
private Map<?, ?> jsonLineSchema;
|
||||
private String jsonLineSchemaText;
|
||||
private Map<?, ?> csvSchema;
|
||||
private String csvSchemaText;
|
||||
private FileInfo exampleFile;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static final class DataResourceListItem {
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class ListItem extends SimpleListItem<DataResource> {
|
||||
private Long id;
|
||||
private String name;
|
||||
private String description;
|
||||
private String type;
|
||||
private String format;
|
||||
private Long confirmationId;
|
||||
private Confirmation.State confirmationState;
|
||||
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 = false)
|
||||
@NoArgsConstructor
|
||||
@ToString(callSuper = true)
|
||||
public static final class DataResourceDetail extends CreateRequest {
|
||||
private Long id;
|
||||
private Long fileId;
|
||||
private String filename;
|
||||
private String coreSiteFilename;
|
||||
private String hdfsSiteFilename;
|
||||
private String exampleFilename;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public static final class DetailItem extends SaveItem {
|
||||
private LocalDateTime createdTime;
|
||||
private String createdUsername;
|
||||
private LocalDateTime modifiedTime;
|
||||
private String modifiedUsername;
|
||||
|
||||
public DataResourceDetail(ObjectMapper mapper, DataResource dataResource) throws JsonProcessingException {
|
||||
this.id = dataResource.getId();
|
||||
this.resourceTypeId = dataResource.getType().getId();
|
||||
this.resourceFormatId = dataResource.getFormat().getId();
|
||||
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().getId();
|
||||
this.filename = 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().getId();
|
||||
this.coreSiteFilename = hdfsType.getCoreSite().getFilename();
|
||||
this.hdfsSiteFileId = hdfsType.getHdfsSite().getId();
|
||||
this.hdfsSiteFilename = 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.jsonSchemaText = jsonFormat.getSchema();
|
||||
this.jsonSchema = mapper.readValue(jsonFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case JSON_LINE:
|
||||
JsonLineResourceFormat jsonLineFormat = (JsonLineResourceFormat) dataResource.getFormat();
|
||||
this.jsonLineSchemaText = jsonLineFormat.getSchema();
|
||||
this.jsonLineSchema = mapper.readValue(jsonLineFormat.getSchema(), Map.class);
|
||||
break;
|
||||
case CSV:
|
||||
CsvResourceFormat csvFormat = (CsvResourceFormat) dataResource.getFormat();
|
||||
this.csvSchemaText = csvFormat.getSchema();
|
||||
this.csvSchema = mapper.readValue(csvFormat.getSchema(), Map.class);
|
||||
break;
|
||||
}
|
||||
if (ObjectUtil.isNotNull(dataResource.getExample())) {
|
||||
this.exampleFileId = dataResource.getExample().getId();
|
||||
this.exampleFilename = dataResource.getExample().getFilename();
|
||||
}
|
||||
|
||||
this.createdUsername = dataResource.getCreatedUser().getUsername();
|
||||
this.createdTime = dataResource.getCreatedTime();
|
||||
this.modifiedUsername = dataResource.getModifiedUser().getUsername();
|
||||
this.modifiedTime = dataResource.getModifiedTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,26 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import com.eshore.gringotts.web.domain.authentication.entity.Authentication;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
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.type.ResourceType;
|
||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
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 jakarta.persistence.CascadeType;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EntityListeners;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToMany;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.util.Set;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -25,7 +29,7 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@ToString(callSuper = true)
|
||||
@Entity
|
||||
@EntityListeners(AuditingEntityListener.class)
|
||||
@DynamicUpdate
|
||||
@@ -33,29 +37,37 @@ import org.springframework.data.jpa.domain.support.AuditingEntityListener;
|
||||
@NamedEntityGraph(name = "data_resource.list", attributeNodes = {
|
||||
@NamedAttributeNode(value = "type"),
|
||||
@NamedAttributeNode(value = "format"),
|
||||
@NamedAttributeNode(value = "confirmation"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
})
|
||||
@NamedEntityGraph(name = "data_resource.detail", attributeNodes = {
|
||||
@NamedAttributeNode(value = "type"),
|
||||
@NamedAttributeNode(value = "format"),
|
||||
@NamedAttributeNode(value = "example"),
|
||||
@NamedAttributeNode(value = "confirmation"),
|
||||
@NamedAttributeNode(value = "createdUser"),
|
||||
@NamedAttributeNode(value = "modifiedUser"),
|
||||
})
|
||||
public class DataResource extends SimpleEntity {
|
||||
public class DataResource extends LogicDeleteEntity {
|
||||
@Column(nullable = false)
|
||||
private String name;
|
||||
private String description;
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
|
||||
@OneToOne(cascade = CascadeType.REMOVE)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private ResourceType type;
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
|
||||
@OneToOne(cascade = CascadeType.REMOVE)
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private ResourceFormat format;
|
||||
@OneToOne(fetch = FetchType.LAZY)
|
||||
@OneToOne(cascade = CascadeType.REMOVE)
|
||||
@JoinColumn(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
@ToString.Exclude
|
||||
private DataFile example;
|
||||
@OneToOne(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
|
||||
@ToString.Exclude
|
||||
private Confirmation confirmation;
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "target")
|
||||
@ToString.Exclude
|
||||
private Set<Authentication> authentications;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import javax.persistence.DiscriminatorValue;
|
||||
import javax.persistence.Entity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.format;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.DiscriminatorColumn;
|
||||
import javax.persistence.DiscriminatorType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteIdOnlyEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -24,8 +22,7 @@ import lombok.ToString;
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_format")
|
||||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
|
||||
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
|
||||
public abstract class ResourceFormat extends IdOnlyEntity {
|
||||
public abstract class ResourceFormat extends LogicDeleteIdOnlyEntity {
|
||||
public enum Type {
|
||||
NONE,
|
||||
LINE,
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.Table;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
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 jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -23,9 +21,6 @@ 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 {
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@@ -2,14 +2,12 @@ package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
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 jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
@@ -23,10 +21,6 @@ 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 {
|
||||
@OneToOne
|
||||
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
package com.eshore.gringotts.web.domain.resource.entity.type;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.IdOnlyEntity;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Inheritance;
|
||||
import javax.persistence.InheritanceType;
|
||||
import javax.persistence.Table;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteIdOnlyEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Inheritance;
|
||||
import jakarta.persistence.InheritanceType;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -21,8 +21,8 @@ import lombok.ToString;
|
||||
@ToString
|
||||
@Entity
|
||||
@Table(name = Constants.TABLE_PREFIX + "resource_type")
|
||||
@Inheritance(strategy = InheritanceType.JOINED)
|
||||
public abstract class ResourceType extends IdOnlyEntity {
|
||||
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
public abstract class ResourceType extends LogicDeleteIdOnlyEntity {
|
||||
public abstract Type getResourceType();
|
||||
|
||||
public enum Type {
|
||||
|
||||
@@ -4,6 +4,8 @@ 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.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
import org.springframework.data.jpa.repository.EntityGraph;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@@ -12,9 +14,9 @@ import org.springframework.stereotype.Repository;
|
||||
public interface DataResourceRepository extends SimpleRepository<DataResource, Long> {
|
||||
@Override
|
||||
@EntityGraph(value = "data_resource.list", type = EntityGraph.EntityGraphType.FETCH)
|
||||
List<DataResource> findAll();
|
||||
List<DataResource> findAll(Specification<DataResource> specification, Sort sort);
|
||||
|
||||
@Override
|
||||
@EntityGraph(value = "data_resource.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||
Optional<DataResource> findById(Long id);
|
||||
Optional<DataResource> findOne(Specification<DataResource> specification);
|
||||
}
|
||||
|
||||
@@ -1,18 +1,13 @@
|
||||
package com.eshore.gringotts.web.domain.resource.service;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.eshore.gringotts.web.domain.base.repository.SimpleRepository;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||
import com.eshore.gringotts.web.domain.base.service.SimpleServiceSupport;
|
||||
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.service.UserService;
|
||||
import com.eshore.gringotts.web.helper.EntityHelper;
|
||||
import javax.transaction.Transactional;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@@ -23,47 +18,22 @@ import org.springframework.stereotype.Service;
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataResourceService extends SimpleService<DataResource, Long> {
|
||||
private final DataResourceRepository dataResourceRepository;
|
||||
public class DataResourceService extends SimpleServiceSupport<DataResource> {
|
||||
private final ResourceTypeRepository resourceTypeRepository;
|
||||
private final ResourceFormatRepository resourceFormatRepository;
|
||||
|
||||
private final UserService userService;
|
||||
|
||||
public DataResourceService(DataResourceRepository dataResourceRepository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||
this.dataResourceRepository = dataResourceRepository;
|
||||
public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||
super(repository, userService);
|
||||
this.resourceTypeRepository = resourceTypeRepository;
|
||||
this.resourceFormatRepository = resourceFormatRepository;
|
||||
this.userService = userService;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SimpleRepository<DataResource, Long> repository() {
|
||||
return dataResourceRepository;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void create(Long id, String name, String description, ResourceType type, ResourceFormat format, DataFile example) {
|
||||
type = resourceTypeRepository.save(type);
|
||||
format = resourceFormatRepository.save(format);
|
||||
DataResource dataResource = EntityHelper.fillCreatorAndModifier(new DataResource(), userService);
|
||||
dataResource.setId(id);
|
||||
dataResource.setName(name);
|
||||
dataResource.setDescription(description);
|
||||
dataResource.setType(type);
|
||||
dataResource.setFormat(format);
|
||||
dataResource.setExample(example);
|
||||
dataResourceRepository.saveOrUpdateByNotNullProperties(dataResource);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void remove(Long id) {
|
||||
dataResourceRepository.deleteById(id);
|
||||
}
|
||||
|
||||
public static final class DataResourceNotFoundException extends RuntimeException {
|
||||
public DataResourceNotFoundException(Long id) {
|
||||
super(StrUtil.format("ID为{}的数据资源未找到", id));
|
||||
}
|
||||
public Long save(DataResource entity) {
|
||||
ResourceType type = resourceTypeRepository.save(entity.getType());
|
||||
ResourceFormat format = resourceFormatRepository.save(entity.getFormat());
|
||||
entity.setType(type);
|
||||
entity.setFormat(format);
|
||||
return super.save(entity);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,15 +34,15 @@ import org.springframework.web.multipart.MultipartFile;
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/upload")
|
||||
public class UploadController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(UploadController.class);
|
||||
public class DataFileController {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataFileController.class);
|
||||
|
||||
private final DataFileService dataFileService;
|
||||
private final String uploadFolderPath;
|
||||
private final String cacheFolderPath;
|
||||
private final String sliceFolderPath;
|
||||
|
||||
public UploadController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
|
||||
public DataFileController(UploadConfiguration uploadConfiguration, DataFileService dataFileService) {
|
||||
this.dataFileService = dataFileService;
|
||||
|
||||
this.uploadFolderPath = uploadConfiguration.getUploadPath();
|
||||
@@ -1,9 +1,9 @@
|
||||
package com.eshore.gringotts.web.domain.upload.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import com.eshore.gringotts.web.domain.base.entity.LogicDeleteEntity;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.Table;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -21,7 +21,7 @@ import org.hibernate.annotations.DynamicUpdate;
|
||||
@Entity
|
||||
@DynamicUpdate
|
||||
@Table(name = Constants.TABLE_PREFIX + "data_file")
|
||||
public class DataFile extends SimpleEntity {
|
||||
public class DataFile extends LogicDeleteEntity {
|
||||
private String filename;
|
||||
private Long size;
|
||||
private String md5;
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
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.base.service.SimpleServiceSupport;
|
||||
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;
|
||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
/**
|
||||
@@ -16,23 +14,18 @@ import org.springframework.stereotype.Service;
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-11-21
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class DataFileService extends SimpleService<DataFile, Long> {
|
||||
private static final Logger logger = LoggerFactory.getLogger(DataFileService.class);
|
||||
|
||||
public class DataFileService extends SimpleServiceSupport<DataFile> {
|
||||
private final DataFileRepository dataFileRepository;
|
||||
private final UserService userService;
|
||||
|
||||
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
|
||||
super(dataFileRepository, 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;
|
||||
|
||||
@@ -2,19 +2,19 @@ package com.eshore.gringotts.web.domain.user.entity;
|
||||
|
||||
import com.eshore.gringotts.core.Constants;
|
||||
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.ConstraintMode;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.FetchType;
|
||||
import jakarta.persistence.ForeignKey;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.NamedAttributeNode;
|
||||
import jakarta.persistence.NamedEntityGraph;
|
||||
import jakarta.persistence.OneToOne;
|
||||
import jakarta.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.ConstraintMode;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
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;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
@@ -58,6 +58,42 @@ public class User extends SimpleEntity {
|
||||
@ToString.Exclude
|
||||
private User checkedUser;
|
||||
|
||||
public static boolean isAdministrator(User user) {
|
||||
return Role.ADMINISTRATOR.equals(user.role);
|
||||
}
|
||||
|
||||
public static boolean isNotAdministrator(User user) {
|
||||
return !isAdministrator(user);
|
||||
}
|
||||
|
||||
public static boolean isChecker(User user) {
|
||||
return Role.CHECKER.equals(user.role);
|
||||
}
|
||||
|
||||
public static boolean isNotChecker(User user) {
|
||||
return !isChecker(user);
|
||||
}
|
||||
|
||||
public static boolean isProvider(User user) {
|
||||
return Role.PROVIDER.equals(user.role);
|
||||
}
|
||||
|
||||
public static boolean isNotProvider(User user) {
|
||||
return !isProvider(user);
|
||||
}
|
||||
|
||||
public static boolean isCustomer(User user) {
|
||||
return Role.CUSTOMER.equals(user.role);
|
||||
}
|
||||
|
||||
public static boolean isNotCustomer(User user) {
|
||||
return !isCustomer(user);
|
||||
}
|
||||
|
||||
public static boolean isUser(User user) {
|
||||
return isProvider(user) || isCustomer(user);
|
||||
}
|
||||
|
||||
public enum State {
|
||||
/**
|
||||
* 审查中
|
||||
|
||||
@@ -32,6 +32,21 @@ logging:
|
||||
sdk:
|
||||
eventsub:
|
||||
EventSubscribeImp: error
|
||||
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: macOS
|
||||
gringotts:
|
||||
upload:
|
||||
upload-path: /Users/lanyuanxiaoyao/Project/IdeaProjects/gringotts/gringotts-web/target/upload
|
||||
upload-path: /Users/lanyuanxiaoyao/Project/IdeaProjects/gringotts/gringotts-web/target/upload
|
||||
|
||||
---
|
||||
spring:
|
||||
config:
|
||||
activate:
|
||||
on-profile: windows
|
||||
gringotts:
|
||||
upload:
|
||||
upload-path: C:\Users\lanyuanxiaoyao\Projects\gringotts\gringotts-web\target
|
||||
14
pom.xml
14
pom.xml
@@ -19,12 +19,12 @@
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>11</maven.compiler.source>
|
||||
<maven.compiler.target>11</maven.compiler.target>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<spring-boot.version>2.6.15</spring-boot.version>
|
||||
<spring-cloud.version>2021.0.9</spring-cloud.version>
|
||||
<spring-boot.version>3.2.1</spring-boot.version>
|
||||
<spring-cloud.version>2023.0.4</spring-cloud.version>
|
||||
|
||||
<hutool.version>5.8.32</hutool.version>
|
||||
<fisco.sdk.version>2.10.0</fisco.sdk.version>
|
||||
@@ -75,7 +75,7 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-spring-boot-starter</artifactId>
|
||||
<artifactId>forest-spring-boot3-starter</artifactId>
|
||||
<version>1.5.36</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -95,13 +95,13 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
<version>1.39.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.blinkfox</groupId>
|
||||
<artifactId>fenix-spring-boot-starter</artifactId>
|
||||
<version>2.7.0</version>
|
||||
<version>3.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Others -->
|
||||
|
||||
Reference in New Issue
Block a user