Compare commits
3 Commits
246e27677e
...
7584ca3736
| Author | SHA1 | Date | |
|---|---|---|---|
| 7584ca3736 | |||
| 851fc02ce5 | |||
| e76236be62 |
@@ -1,26 +1,26 @@
|
|||||||
const information = {
|
const information = {
|
||||||
debug: false,
|
debug: false,
|
||||||
// baseUrl: '',
|
// baseUrl: '',
|
||||||
baseUrl: 'http://127.0.0.1:20080',
|
baseUrl: 'http://127.0.0.1:20080',
|
||||||
title: '可信供给中心',
|
title: '可信供给中心',
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useAmis(amisObject) {
|
export function useAmis(amisObject) {
|
||||||
document.title = information.title
|
document.title = information.title
|
||||||
let amis = amisRequire('amis/embed')
|
let amis = amisRequire('amis/embed')
|
||||||
amis.embed(
|
amis.embed(
|
||||||
'#app',
|
'#app',
|
||||||
amisObject(information),
|
amisObject(information),
|
||||||
{
|
{
|
||||||
data: {
|
data: {
|
||||||
base: information.baseUrl,
|
base: information.baseUrl,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
theme: 'antd',
|
theme: 'antd',
|
||||||
enableAMISDebug: information.debug,
|
enableAMISDebug: information.debug,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function crudCommonOptions() {
|
export function crudCommonOptions() {
|
||||||
@@ -187,3 +187,26 @@ export function apiGet(url) {
|
|||||||
export function apiPost(url) {
|
export function apiPost(url) {
|
||||||
return api('post', url)
|
return api('post', url)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
textarea {
|
||||||
|
resize: none !important;
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
import './dialog-permission.css'
|
||||||
|
import {apiPost, horizontalFormOptions} from "../constants.js";
|
||||||
|
|
||||||
|
function detailForm() {
|
||||||
|
return {
|
||||||
|
id: 'resource_data_form',
|
||||||
|
type: 'form',
|
||||||
|
...horizontalFormOptions(),
|
||||||
|
horizontal: {
|
||||||
|
left: 2,
|
||||||
|
},
|
||||||
|
body: [
|
||||||
|
{
|
||||||
|
type: 'hidden',
|
||||||
|
name: 'id',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'textarea',
|
||||||
|
label: '确权说明',
|
||||||
|
name: 'description',
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export function permissionAddDialog() {
|
||||||
|
return {
|
||||||
|
actionType: 'dialog',
|
||||||
|
dialog: {
|
||||||
|
title: '新增确权申请',
|
||||||
|
size: 'md',
|
||||||
|
actions: [
|
||||||
|
{
|
||||||
|
type: 'reset',
|
||||||
|
label: '重置',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'submit',
|
||||||
|
label: '确定',
|
||||||
|
level: 'primary',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
body: {
|
||||||
|
debug: true,
|
||||||
|
...detailForm(),
|
||||||
|
api: apiPost('${base}/confirmation/save'),
|
||||||
|
data: {
|
||||||
|
add: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,17 +2,13 @@ import './dialog-resource.css'
|
|||||||
import {
|
import {
|
||||||
apiGet,
|
apiGet,
|
||||||
apiPost,
|
apiPost,
|
||||||
|
formInputClearable,
|
||||||
horizontalFormOptions,
|
horizontalFormOptions,
|
||||||
inputFileFormItemCommonOptions,
|
inputFileFormItemCommonOptions,
|
||||||
size1GB,
|
size1GB,
|
||||||
size500MB
|
size500MB
|
||||||
} from "../constants.js";
|
} from "../constants.js";
|
||||||
|
|
||||||
const clearable = {
|
|
||||||
clearable: true,
|
|
||||||
clearValueOnEmpty: true,
|
|
||||||
}
|
|
||||||
|
|
||||||
function inputFileFormItemUpdateFieldOptions(target) {
|
function inputFileFormItemUpdateFieldOptions(target) {
|
||||||
let value = {}
|
let value = {}
|
||||||
value[target] = '${event.data.value}'
|
value[target] = '${event.data.value}'
|
||||||
@@ -51,13 +47,13 @@ function detailForm() {
|
|||||||
name: 'name',
|
name: 'name',
|
||||||
label: '资源名称',
|
label: '资源名称',
|
||||||
required: true,
|
required: true,
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'textarea',
|
type: 'textarea',
|
||||||
name: 'description',
|
name: 'description',
|
||||||
label: '资源描述',
|
label: '资源描述',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
showCounter: true,
|
showCounter: true,
|
||||||
trimContents: true,
|
trimContents: true,
|
||||||
minRows: 2,
|
minRows: 2,
|
||||||
@@ -90,19 +86,19 @@ function detailForm() {
|
|||||||
label: 'API地址',
|
label: 'API地址',
|
||||||
name: 'apiUrl',
|
name: 'apiUrl',
|
||||||
required: true,
|
required: true,
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
label: '用户名',
|
label: '用户名',
|
||||||
name: 'apiUsername',
|
name: 'apiUsername',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-password',
|
type: 'input-password',
|
||||||
label: '密码',
|
label: '密码',
|
||||||
name: 'apiPassword',
|
name: 'apiPassword',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -149,19 +145,19 @@ function detailForm() {
|
|||||||
label: 'JDBC',
|
label: 'JDBC',
|
||||||
name: 'databaseJdbc',
|
name: 'databaseJdbc',
|
||||||
required: true,
|
required: true,
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
label: '用户名',
|
label: '用户名',
|
||||||
name: 'databaseUsername',
|
name: 'databaseUsername',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-password',
|
type: 'input-password',
|
||||||
label: '密码',
|
label: '密码',
|
||||||
name: 'databasePassword',
|
name: 'databasePassword',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -210,33 +206,33 @@ function detailForm() {
|
|||||||
label: 'FTP地址',
|
label: 'FTP地址',
|
||||||
name: 'ftpUrl',
|
name: 'ftpUrl',
|
||||||
required: true,
|
required: true,
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
label: 'FTP账号',
|
label: 'FTP账号',
|
||||||
name: 'ftpUsername',
|
name: 'ftpUsername',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-password',
|
type: 'input-password',
|
||||||
label: 'FTP密码',
|
label: 'FTP密码',
|
||||||
name: 'ftpPassword',
|
name: 'ftpPassword',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
label: '相对路径',
|
label: '相对路径',
|
||||||
name: 'ftpPath',
|
name: 'ftpPath',
|
||||||
description: '若为空,则使用用户根目录',
|
description: '若为空,则使用用户根目录',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'input-text',
|
type: 'input-text',
|
||||||
label: '文件筛选',
|
label: '文件筛选',
|
||||||
name: 'ftpRegexFilter',
|
name: 'ftpRegexFilter',
|
||||||
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
description: '正则表达式,用于匹配文件的路径,只有符合筛选条件的文件才会被采集;若为空则默认采集全部文件',
|
||||||
...clearable,
|
...formInputClearable,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
import {apiGet, useAmis} from '../../components/constants.js'
|
import {apiGet, useAmis} from '../../components/constants.js'
|
||||||
import {userChangePasswordDialog} from "../../components/user/dialog-user-change-password.js";
|
import {userChangePasswordDialog} from "../../components/user/dialog-user-change-password.js";
|
||||||
import {tabUser} from "./tab-user.js";
|
import {tabUser} from "./tab-user.js";
|
||||||
import {tabMarket} from "./tab-market.js";
|
|
||||||
import {tabData} from "./tab-data.js";
|
import {tabData} from "./tab-data.js";
|
||||||
import {tabSettings} from "./tab-settings.js";
|
import {tabSettings} from "./tab-settings.js";
|
||||||
|
import {tabCheck} from "./tab-check.js";
|
||||||
|
import {tabPermissions} from "./tab-permissions.js";
|
||||||
|
|
||||||
useAmis(information => {
|
useAmis(information => {
|
||||||
return {
|
return {
|
||||||
@@ -56,9 +57,11 @@ useAmis(information => {
|
|||||||
type: 'tabs',
|
type: 'tabs',
|
||||||
tabsMode: 'vertical',
|
tabsMode: 'vertical',
|
||||||
tabs: [
|
tabs: [
|
||||||
tabData(),
|
|
||||||
// tabOverview(),
|
// tabOverview(),
|
||||||
tabMarket(),
|
// tabMarket(),
|
||||||
|
tabPermissions(),
|
||||||
|
tabData(),
|
||||||
|
tabCheck(),
|
||||||
tabUser(),
|
tabUser(),
|
||||||
tabSettings(),
|
tabSettings(),
|
||||||
]
|
]
|
||||||
|
|||||||
12
gringotts-frontend/pages/index/tab-check.js
Normal file
12
gringotts-frontend/pages/index/tab-check.js
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
import {checkerOnly} from "../../components/constants.js";
|
||||||
|
|
||||||
|
export function tabCheck() {
|
||||||
|
return {
|
||||||
|
visibleOn: checkerOnly,
|
||||||
|
title: '审核审查',
|
||||||
|
icon: 'fa fa-shield-halved',
|
||||||
|
body: [
|
||||||
|
'hello world'
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,24 +3,25 @@ import {
|
|||||||
resourceDetailDialog,
|
resourceDetailDialog,
|
||||||
resourceEditeDialog
|
resourceEditeDialog
|
||||||
} from "../../components/resource/dialog-resource.js";
|
} from "../../components/resource/dialog-resource.js";
|
||||||
import {apiGet, apiPost, crudCommonOptions} from "../../components/constants.js";
|
import {apiGet, crudCommonOptions, userOnly} from "../../components/constants.js";
|
||||||
|
|
||||||
export function tabData() {
|
export function tabData() {
|
||||||
return {
|
return {
|
||||||
|
visibleOn: userOnly,
|
||||||
title: '数据资源',
|
title: '数据资源',
|
||||||
icon: 'fa fa-database',
|
icon: 'fa fa-database',
|
||||||
body: [
|
body: [
|
||||||
{
|
{
|
||||||
type: 'crud',
|
type: 'crud',
|
||||||
api: {
|
api: {
|
||||||
...apiPost('${base}/data_resource/list')
|
...apiGet('${base}/data_resource/list')
|
||||||
},
|
},
|
||||||
...crudCommonOptions(),
|
...crudCommonOptions(),
|
||||||
headerToolbar: [
|
headerToolbar: [
|
||||||
'reload',
|
'reload',
|
||||||
{
|
{
|
||||||
type: 'action',
|
type: 'action',
|
||||||
label: '新增数据资源',
|
label: '',
|
||||||
icon: 'fa fa-plus',
|
icon: 'fa fa-plus',
|
||||||
...resourceAddDialog()
|
...resourceAddDialog()
|
||||||
},
|
},
|
||||||
@@ -44,7 +45,7 @@ export function tabData() {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: '操作',
|
label: '操作',
|
||||||
width: 200,
|
width: 100,
|
||||||
type: 'operation',
|
type: 'operation',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
className: 'nowrap',
|
className: 'nowrap',
|
||||||
@@ -62,14 +63,26 @@ export function tabData() {
|
|||||||
...resourceEditeDialog(),
|
...resourceEditeDialog(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'action',
|
type: 'dropdown-button',
|
||||||
label: '删除',
|
|
||||||
level: 'link',
|
level: 'link',
|
||||||
className: 'text-danger',
|
icon: 'fa fa-ellipsis-h',
|
||||||
confirmTitle: '确认删除',
|
hideCaret: true,
|
||||||
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
trigger: 'hover',
|
||||||
actionType: 'ajax',
|
buttons: [
|
||||||
api: apiGet('${base}/data_resource/remove/${id}')
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '申请确权',
|
||||||
|
level: 'link',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '删除',
|
||||||
|
confirmTitle: '确认删除',
|
||||||
|
confirmText: '确认删除名称为「${name}」的数据资源吗?',
|
||||||
|
actionType: 'ajax',
|
||||||
|
api: apiGet('${base}/data_resource/remove/${id}')
|
||||||
|
},
|
||||||
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
|||||||
76
gringotts-frontend/pages/index/tab-permissions.js
Normal file
76
gringotts-frontend/pages/index/tab-permissions.js
Normal file
@@ -0,0 +1,76 @@
|
|||||||
|
import {apiGet, crudCommonOptions, providerOnly, userOnly} from "../../components/constants.js";
|
||||||
|
import {permissionAddDialog} from "../../components/permission/dialog-permission.js";
|
||||||
|
|
||||||
|
export function tabPermissions() {
|
||||||
|
return {
|
||||||
|
visibleOn: userOnly,
|
||||||
|
title: '权属管理',
|
||||||
|
icon: 'fa fa-user-shield',
|
||||||
|
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: [
|
||||||
|
{
|
||||||
|
label: '名称',
|
||||||
|
name: 'name',
|
||||||
|
width: 200,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '描述',
|
||||||
|
name: 'description',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '创建时间',
|
||||||
|
width: 150,
|
||||||
|
align: 'center',
|
||||||
|
type: 'tpl',
|
||||||
|
tpl: "${IF(createdTime, DATETOSTR(createdTime), '-')}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: '操作',
|
||||||
|
width: 100,
|
||||||
|
type: 'operation',
|
||||||
|
fixed: 'right',
|
||||||
|
className: 'nowrap',
|
||||||
|
buttons: [
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '查看',
|
||||||
|
level: 'link',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
type: 'action',
|
||||||
|
label: '编辑',
|
||||||
|
level: 'link',
|
||||||
|
},
|
||||||
|
]
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title: '授权管理',
|
||||||
|
body: []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
|
import {administratorOnly} from "../../components/constants.js";
|
||||||
|
|
||||||
export function tabSettings() {
|
export function tabSettings() {
|
||||||
return {
|
return {
|
||||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
visibleOn: administratorOnly,
|
||||||
title: '系统管理',
|
title: '系统管理',
|
||||||
icon: 'fa fa-gear',
|
icon: 'fa fa-gear',
|
||||||
body: [
|
body: [
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
administratorOnly,
|
||||||
apiGet,
|
apiGet,
|
||||||
copyField,
|
copyField,
|
||||||
crudCommonOptions,
|
crudCommonOptions,
|
||||||
@@ -11,7 +12,7 @@ import {userAdministratorRegisterDialog} from "../../components/user/dialog-user
|
|||||||
|
|
||||||
export function tabUser() {
|
export function tabUser() {
|
||||||
return {
|
return {
|
||||||
visibleOn: '${role === "ADMINISTRATOR"}',
|
visibleOn: administratorOnly,
|
||||||
title: '用户管理',
|
title: '用户管理',
|
||||||
icon: 'fa fa-user',
|
icon: 'fa fa-user',
|
||||||
body: [
|
body: [
|
||||||
|
|||||||
@@ -0,0 +1,60 @@
|
|||||||
|
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.SimpleService;
|
||||||
|
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.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-26
|
||||||
|
*/
|
||||||
|
public abstract class SimpleController<ENTITY extends SimpleEntity, 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}";
|
||||||
|
|
||||||
|
protected final SimpleService<ENTITY> service;
|
||||||
|
|
||||||
|
public SimpleController(SimpleService<ENTITY> service) {
|
||||||
|
this.service = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(SAVE)
|
||||||
|
public AmisResponse<Long> save(@RequestBody SAVE_ITEM item) throws Exception {
|
||||||
|
return AmisResponse.responseSuccess(service.save(fromSaveItem(item)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(LIST)
|
||||||
|
public AmisResponse<ImmutableSet<LIST_ITEM>> list() {
|
||||||
|
return AmisResponse.responseSuccess(service.list().collect(entity -> {
|
||||||
|
try {
|
||||||
|
return toListItem(entity);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(DETAIL)
|
||||||
|
public AmisResponse<DETAIL_ITEM> detail(@PathVariable Long id) throws Exception {
|
||||||
|
return AmisResponse.responseSuccess(toDetailItem(service.detail(id)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping(REMOVE)
|
||||||
|
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,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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,25 +1,79 @@
|
|||||||
package com.eshore.gringotts.web.domain.base.service;
|
package com.eshore.gringotts.web.domain.base.service;
|
||||||
|
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
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.base.repository.SimpleRepository;
|
||||||
import org.eclipse.collections.api.factory.Lists;
|
import com.eshore.gringotts.web.domain.user.entity.User;
|
||||||
import org.eclipse.collections.api.list.ImmutableList;
|
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||||
|
import java.util.Optional;
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import org.eclipse.collections.api.factory.Sets;
|
||||||
|
import org.eclipse.collections.api.set.ImmutableSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @date 2024-11-21
|
* @date 2024-11-21
|
||||||
*/
|
*/
|
||||||
public abstract class SimpleService<E, ID> {
|
public abstract class SimpleService<ENTITY extends SimpleEntity> {
|
||||||
protected abstract SimpleRepository<E, ID> repository();
|
protected final SimpleRepository<ENTITY, Long> repository;
|
||||||
|
protected final UserService userService;
|
||||||
|
|
||||||
public ImmutableList<E> list() {
|
public SimpleService(SimpleRepository<ENTITY, Long> repository, UserService userService) {
|
||||||
return Lists.immutable.ofAll(repository().findAll());
|
this.repository = repository;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public E detail(ID id) {
|
@Transactional(rollbackOn = Throwable.class)
|
||||||
|
public Long save(ENTITY entity) {
|
||||||
|
User user = userService.currentLoginUser();
|
||||||
|
if (ObjectUtil.isNull(entity.getCreatedUser())) {
|
||||||
|
entity.setCreatedUser(user);
|
||||||
|
}
|
||||||
|
entity.setModifiedUser(user);
|
||||||
|
entity = repository.saveOrUpdateByNotNullProperties(entity);
|
||||||
|
return entity.getId();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableSet<ENTITY> list() {
|
||||||
|
return Sets.immutable.ofAll(repository.findAll());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ImmutableSet<ENTITY> list(ImmutableSet<Long> ids) {
|
||||||
|
return Sets.immutable.ofAll(repository.findAllById(ids.select(ObjectUtil::isNotNull)));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ENTITY detail(Long id) {
|
||||||
if (ObjectUtil.isNull(id)) {
|
if (ObjectUtil.isNull(id)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return repository().findById(id).orElse(null);
|
return repository.findById(id).orElse(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ENTITY> detailOptional(Long id) {
|
||||||
|
if (ObjectUtil.isNull(id)) {
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
return repository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ENTITY detailOrThrow(Long id) {
|
||||||
|
if (ObjectUtil.isNull(id)) {
|
||||||
|
throw new IdNotFoundException(id);
|
||||||
|
}
|
||||||
|
return repository.findById(id).orElseThrow(() -> new IdNotFoundException(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(rollbackOn = Throwable.class)
|
||||||
|
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,86 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.confirmation.controller;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||||
|
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.entity.DataFile;
|
||||||
|
import com.eshore.gringotts.web.domain.upload.service.DataFileService;
|
||||||
|
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.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-26
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("confirmation")
|
||||||
|
public class ConfirmationController extends SimpleController<Confirmation, ConfirmationController.SaveItem, ConfirmationController.ListItem, ConfirmationController.DetailItem> {
|
||||||
|
private final DataResourceService dataResourceService;
|
||||||
|
private final DataFileService dataFileService;
|
||||||
|
|
||||||
|
public ConfirmationController(ConfirmationService service, DataResourceService dataResourceService, DataFileService dataFileService) {
|
||||||
|
super(service);
|
||||||
|
this.dataResourceService = dataResourceService;
|
||||||
|
this.dataFileService = dataFileService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Confirmation fromSaveItem(SaveItem item) {
|
||||||
|
Confirmation confirmation = new Confirmation();
|
||||||
|
confirmation.setId(item.getId());
|
||||||
|
confirmation.setDescription(item.getDescription());
|
||||||
|
confirmation.setTarget(dataResourceService.detailOrThrow(item.getTargetId()));
|
||||||
|
confirmation.setEvidences(dataFileService.list(item.getEvidenceIds()).toSet());
|
||||||
|
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.setCreatedUsername(entity.getCreatedUser().getUsername());
|
||||||
|
item.setCreatedTime(entity.getCreatedTime());
|
||||||
|
return item;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected DetailItem toDetailItem(Confirmation entity) throws Exception {
|
||||||
|
return new DetailItem(entity);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class SaveItem extends SimpleSaveItem<Confirmation> {
|
||||||
|
private Long targetId;
|
||||||
|
private String description;
|
||||||
|
private ImmutableSet<Long> evidenceIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static class ListItem extends SimpleListItem<Confirmation> {
|
||||||
|
private String name;
|
||||||
|
private String description;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static final class DetailItem extends SaveItem {
|
||||||
|
public DetailItem(Confirmation confirmation) {
|
||||||
|
this.setId(confirmation.getId());
|
||||||
|
this.setDescription(confirmation.getDescription());
|
||||||
|
this.setEvidenceIds(Sets.immutable.ofAll(confirmation.getEvidences()).collect(DataFile::getId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.confirmation.entity;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.core.Constants;
|
||||||
|
import com.eshore.gringotts.web.domain.base.entity.SimpleEntity;
|
||||||
|
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
||||||
|
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||||
|
import java.util.Set;
|
||||||
|
import javax.persistence.CascadeType;
|
||||||
|
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.JoinTable;
|
||||||
|
import javax.persistence.NamedAttributeNode;
|
||||||
|
import javax.persistence.NamedEntityGraph;
|
||||||
|
import javax.persistence.OneToMany;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import org.hibernate.annotations.DynamicUpdate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 确权
|
||||||
|
*
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-26
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
@Entity
|
||||||
|
@DynamicUpdate
|
||||||
|
@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 SimpleEntity {
|
||||||
|
@OneToOne(fetch = FetchType.EAGER)
|
||||||
|
@JoinColumn(nullable = false, foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private DataResource target;
|
||||||
|
private String description;
|
||||||
|
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
|
||||||
|
@JoinTable(foreignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT), inverseForeignKey = @ForeignKey(ConstraintMode.NO_CONSTRAINT))
|
||||||
|
private Set<DataFile> evidences;
|
||||||
|
@Column(nullable = false)
|
||||||
|
@Enumerated(EnumType.STRING)
|
||||||
|
private State state = State.CHECKING;
|
||||||
|
|
||||||
|
public enum State {
|
||||||
|
/**
|
||||||
|
* 审查中
|
||||||
|
*/
|
||||||
|
CHECKING,
|
||||||
|
/**
|
||||||
|
* 正常
|
||||||
|
*/
|
||||||
|
NORMAL,
|
||||||
|
/**
|
||||||
|
* 禁用
|
||||||
|
*/
|
||||||
|
DISABLED,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
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 java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import org.springframework.data.jpa.repository.EntityGraph;
|
||||||
|
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();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@EntityGraph(value = "confirmation.detail", type = EntityGraph.EntityGraphType.FETCH)
|
||||||
|
Optional<Confirmation> findById(Long id);
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.eshore.gringotts.web.domain.confirmation.service;
|
||||||
|
|
||||||
|
import com.eshore.gringotts.web.domain.base.service.SimpleService;
|
||||||
|
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.service.UserService;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author lanyuanxiaoyao
|
||||||
|
* @date 2024-11-26
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
public class ConfirmationService extends SimpleService<Confirmation> {
|
||||||
|
public ConfirmationService(ConfirmationRepository repository, UserService userService) {
|
||||||
|
super(repository, userService);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,8 +2,9 @@ package com.eshore.gringotts.web.domain.resource.controller;
|
|||||||
|
|
||||||
import cn.hutool.core.util.EnumUtil;
|
import cn.hutool.core.util.EnumUtil;
|
||||||
import cn.hutool.core.util.ObjectUtil;
|
import cn.hutool.core.util.ObjectUtil;
|
||||||
import com.eshore.gringotts.web.configuration.amis.AmisListResponse;
|
import com.eshore.gringotts.web.domain.base.controller.SimpleController;
|
||||||
import com.eshore.gringotts.web.configuration.amis.AmisResponse;
|
import com.eshore.gringotts.web.domain.base.entity.SimpleListItem;
|
||||||
|
import com.eshore.gringotts.web.domain.base.entity.SimpleSaveItem;
|
||||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
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.CsvResourceFormat;
|
||||||
import com.eshore.gringotts.web.domain.resource.entity.format.JsonLineResourceFormat;
|
import com.eshore.gringotts.web.domain.resource.entity.format.JsonLineResourceFormat;
|
||||||
@@ -26,14 +27,8 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import lombok.NoArgsConstructor;
|
|
||||||
import lombok.ToString;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
@@ -46,43 +41,174 @@ import org.springframework.web.bind.annotation.RestController;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/data_resource")
|
@RequestMapping("/data_resource")
|
||||||
public class DataResourceController {
|
public class DataResourceController extends SimpleController<DataResource, DataResourceController.SaveItem, DataResourceController.ListItem, DataResourceController.DetailItem> {
|
||||||
private final ObjectMapper mapper;
|
private final ObjectMapper mapper;
|
||||||
private final DataResourceService dataResourceService;
|
|
||||||
private final DataFileService dataFileService;
|
private final DataFileService dataFileService;
|
||||||
|
|
||||||
public DataResourceController(Jackson2ObjectMapperBuilder builder, DataResourceService dataResourceService, DataFileService dataFileService) {
|
public DataResourceController(DataResourceService dataResourceService, DataFileService dataFileService, Jackson2ObjectMapperBuilder builder) {
|
||||||
this.mapper = builder.build();
|
super(dataResourceService);
|
||||||
this.dataResourceService = dataResourceService;
|
|
||||||
this.dataFileService = dataFileService;
|
this.dataFileService = dataFileService;
|
||||||
|
this.mapper = builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/save")
|
@Override
|
||||||
public void create(@RequestBody CreateRequest request) throws JsonProcessingException {
|
protected DataResource fromSaveItem(SaveItem item) throws JsonProcessingException {
|
||||||
log.info("Save request: {}", request);
|
ResourceType type = generateResourceType(item);
|
||||||
ResourceType type = request.generateResourceType(dataFileService);
|
ResourceFormat format = generateResourceFormat(item);
|
||||||
ResourceFormat format = request.generateResourceFormat(mapper);
|
DataResource dataResource = new DataResource();
|
||||||
dataResourceService.create(request.id, request.name, request.description, type, format, dataFileService.detail(request.exampleFileId));
|
dataResource.setId(item.getId());
|
||||||
|
dataResource.setName(item.getName());
|
||||||
|
dataResource.setDescription(item.getDescription());
|
||||||
|
dataResource.setType(type);
|
||||||
|
dataResource.setFormat(format);
|
||||||
|
dataResource.setExample(dataFileService.detail(item.getExampleFileId()));
|
||||||
|
return dataResource;
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/list")
|
@Override
|
||||||
public AmisListResponse list() {
|
protected ListItem toListItem(DataResource dataResource) {
|
||||||
return AmisResponse.responseListData(dataResourceService.list().collect(DataResourceListItem::new));
|
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());
|
||||||
|
item.setCreatedUser(dataResource.getCreatedUser().getUsername());
|
||||||
|
item.setCreatedTime(dataResource.getCreatedTime());
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/detail/{id}")
|
@Override
|
||||||
public AmisResponse<DataResourceDetail> detail(@PathVariable Long id) throws JsonProcessingException {
|
protected DetailItem toDetailItem(DataResource dataResource) throws Exception {
|
||||||
return AmisResponse.responseSuccess(new DataResourceDetail(mapper, dataResourceService.detail(id)));
|
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.setFileId(fileType.getFile().getId());
|
||||||
|
item.setFilename(fileType.getFile().getFilename());
|
||||||
|
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.setCoreSiteFileId(hdfsType.getCoreSite().getId());
|
||||||
|
item.setCoreSiteFilename(hdfsType.getCoreSite().getFilename());
|
||||||
|
item.setHdfsSiteFileId(hdfsType.getHdfsSite().getId());
|
||||||
|
item.setHdfsSiteFilename(hdfsType.getHdfsSite().getFilename());
|
||||||
|
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.setExampleFileId(dataResource.getExample().getId());
|
||||||
|
item.setExampleFilename(dataResource.getExample().getFilename());
|
||||||
|
}
|
||||||
|
item.setCreatedUsername(dataResource.getCreatedUser().getUsername());
|
||||||
|
item.setCreatedTime(dataResource.getCreatedTime());
|
||||||
|
item.setModifiedUsername(dataResource.getModifiedUser().getUsername());
|
||||||
|
item.setModifiedTime(dataResource.getModifiedTime());
|
||||||
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/remove/{id}")
|
private ResourceType generateResourceType(SaveItem item) {
|
||||||
public void remove(@PathVariable Long id) {
|
ResourceType type = null;
|
||||||
dataResourceService.remove(id);
|
switch (item.getResourceType()) {
|
||||||
|
case API:
|
||||||
|
type = new ApiResourceType(item.getApiUrl(), item.getApiUsername(), item.getApiPassword());
|
||||||
|
break;
|
||||||
|
case FILE:
|
||||||
|
DataFile dataFile = dataFileService.detail(item.getFileId());
|
||||||
|
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.getCoreSiteFileId()), dataFileService.detail(item.getHdfsSiteFileId()));
|
||||||
|
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
|
@Data
|
||||||
public static class CreateRequest {
|
@EqualsAndHashCode(callSuper = true)
|
||||||
protected Long id;
|
public static class SaveItem extends SimpleSaveItem<DataResource> {
|
||||||
protected String name;
|
protected String name;
|
||||||
protected String description;
|
protected String description;
|
||||||
protected Long resourceTypeId;
|
protected Long resourceTypeId;
|
||||||
@@ -111,62 +237,11 @@ public class DataResourceController {
|
|||||||
protected Map<?, ?> csvSchema;
|
protected Map<?, ?> csvSchema;
|
||||||
protected String csvSchemaText;
|
protected String csvSchemaText;
|
||||||
protected Long exampleFileId;
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public static final class DataResourceListItem {
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
public static final class ListItem extends SimpleListItem<DataResource> {
|
||||||
private Long id;
|
private Long id;
|
||||||
private String name;
|
private String name;
|
||||||
private String description;
|
private String description;
|
||||||
@@ -174,23 +249,11 @@ public class DataResourceController {
|
|||||||
private String format;
|
private String format;
|
||||||
private String createdUser;
|
private String createdUser;
|
||||||
private LocalDateTime createdTime;
|
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
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
@NoArgsConstructor
|
public static final class DetailItem extends SaveItem {
|
||||||
@ToString(callSuper = true)
|
|
||||||
public static final class DataResourceDetail extends CreateRequest {
|
|
||||||
private Long id;
|
private Long id;
|
||||||
private Long fileId;
|
private Long fileId;
|
||||||
private String filename;
|
private String filename;
|
||||||
@@ -201,79 +264,5 @@ public class DataResourceController {
|
|||||||
private String createdUsername;
|
private String createdUsername;
|
||||||
private LocalDateTime modifiedTime;
|
private LocalDateTime modifiedTime;
|
||||||
private String modifiedUsername;
|
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,7 +1,5 @@
|
|||||||
package com.eshore.gringotts.web.domain.resource.service;
|
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.SimpleService;
|
||||||
import com.eshore.gringotts.web.domain.resource.entity.DataResource;
|
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.format.ResourceFormat;
|
||||||
@@ -9,10 +7,7 @@ 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.DataResourceRepository;
|
||||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
|
import com.eshore.gringotts.web.domain.resource.repository.ResourceFormatRepository;
|
||||||
import com.eshore.gringotts.web.domain.resource.repository.ResourceTypeRepository;
|
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.domain.user.service.UserService;
|
||||||
import com.eshore.gringotts.web.helper.EntityHelper;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@@ -23,47 +18,22 @@ import org.springframework.stereotype.Service;
|
|||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class DataResourceService extends SimpleService<DataResource, Long> {
|
public class DataResourceService extends SimpleService<DataResource> {
|
||||||
private final DataResourceRepository dataResourceRepository;
|
|
||||||
private final ResourceTypeRepository resourceTypeRepository;
|
private final ResourceTypeRepository resourceTypeRepository;
|
||||||
private final ResourceFormatRepository resourceFormatRepository;
|
private final ResourceFormatRepository resourceFormatRepository;
|
||||||
|
|
||||||
private final UserService userService;
|
public DataResourceService(DataResourceRepository repository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
||||||
|
super(repository, userService);
|
||||||
public DataResourceService(DataResourceRepository dataResourceRepository, ResourceTypeRepository resourceTypeRepository, ResourceFormatRepository resourceFormatRepository, UserService userService) {
|
|
||||||
this.dataResourceRepository = dataResourceRepository;
|
|
||||||
this.resourceTypeRepository = resourceTypeRepository;
|
this.resourceTypeRepository = resourceTypeRepository;
|
||||||
this.resourceFormatRepository = resourceFormatRepository;
|
this.resourceFormatRepository = resourceFormatRepository;
|
||||||
this.userService = userService;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected SimpleRepository<DataResource, Long> repository() {
|
public Long save(DataResource entity) {
|
||||||
return dataResourceRepository;
|
ResourceType type = resourceTypeRepository.save(entity.getType());
|
||||||
}
|
ResourceFormat format = resourceFormatRepository.save(entity.getFormat());
|
||||||
|
entity.setType(type);
|
||||||
@Transactional
|
entity.setFormat(format);
|
||||||
public void create(Long id, String name, String description, ResourceType type, ResourceFormat format, DataFile example) {
|
return super.save(entity);
|
||||||
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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
package com.eshore.gringotts.web.domain.upload.service;
|
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.SimpleService;
|
||||||
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
import com.eshore.gringotts.web.domain.upload.entity.DataFile;
|
||||||
import com.eshore.gringotts.web.domain.upload.repository.DataFileRepository;
|
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.entity.User;
|
||||||
import com.eshore.gringotts.web.domain.user.service.UserService;
|
import com.eshore.gringotts.web.domain.user.service.UserService;
|
||||||
import org.slf4j.Logger;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,21 +14,11 @@ import org.springframework.stereotype.Service;
|
|||||||
* @author lanyuanxiaoyao
|
* @author lanyuanxiaoyao
|
||||||
* @date 2024-11-21
|
* @date 2024-11-21
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Service
|
@Service
|
||||||
public class DataFileService extends SimpleService<DataFile, Long> {
|
public class DataFileService extends SimpleService<DataFile> {
|
||||||
private static final Logger logger = LoggerFactory.getLogger(DataFileService.class);
|
public DataFileService(DataFileRepository repository, UserService userService) {
|
||||||
|
super(repository, userService);
|
||||||
private final DataFileRepository dataFileRepository;
|
|
||||||
private final UserService userService;
|
|
||||||
|
|
||||||
public DataFileService(DataFileRepository dataFileRepository, UserService userService) {
|
|
||||||
this.dataFileRepository = dataFileRepository;
|
|
||||||
this.userService = userService;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected SimpleRepository<DataFile, Long> repository() {
|
|
||||||
return dataFileRepository;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataFile detail(String id) {
|
public DataFile detail(String id) {
|
||||||
@@ -46,17 +34,17 @@ public class DataFileService extends SimpleService<DataFile, Long> {
|
|||||||
User loginUser = userService.currentLoginUser();
|
User loginUser = userService.currentLoginUser();
|
||||||
dataFile.setCreatedUser(loginUser);
|
dataFile.setCreatedUser(loginUser);
|
||||||
dataFile.setModifiedUser(loginUser);
|
dataFile.setModifiedUser(loginUser);
|
||||||
return dataFileRepository.save(dataFile).getId();
|
return repository.save(dataFile).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateDataFile(Long id, String path, Long size, String md5) {
|
public void updateDataFile(Long id, String path, Long size, String md5) {
|
||||||
DataFile dataFile = dataFileRepository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
|
DataFile dataFile = repository.findById(id).orElseThrow(UpdateDataFileFailedException::new);
|
||||||
dataFile.setSize(size);
|
dataFile.setSize(size);
|
||||||
dataFile.setMd5(md5);
|
dataFile.setMd5(md5);
|
||||||
dataFile.setPath(path);
|
dataFile.setPath(path);
|
||||||
User loginUser = userService.currentLoginUser();
|
User loginUser = userService.currentLoginUser();
|
||||||
dataFile.setModifiedUser(loginUser);
|
dataFile.setModifiedUser(loginUser);
|
||||||
dataFileRepository.save(dataFile);
|
repository.save(dataFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final class DataFileNotFoundException extends RuntimeException {
|
public static final class DataFileNotFoundException extends RuntimeException {
|
||||||
|
|||||||
Reference in New Issue
Block a user