18 changed files with 392 additions and 25 deletions
@ -0,0 +1,185 @@ |
|||||
|
<template> |
||||
|
<div> |
||||
|
<w-form |
||||
|
v-model="valueReactive" |
||||
|
:cols-num="12" |
||||
|
:fields="[ |
||||
|
{ |
||||
|
colSpan: 2, |
||||
|
name: 'datasource', |
||||
|
label: $t('developer.backend.export.liquibase.datasource'), |
||||
|
type: 'w-select', |
||||
|
options: datasourceOptionsRef, |
||||
|
onUpdateValue: (args) => { |
||||
|
datasourceChanged(args.value); |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
colSpan: 2, |
||||
|
name: 'catalog', |
||||
|
label: $t('developer.backend.export.liquibase.catalog'), |
||||
|
type: 'w-select', |
||||
|
options: catalogOptionsRef, |
||||
|
onUpdateValue: (args) => { |
||||
|
catalogChanged(valueReactive.datasource, args.value); |
||||
|
}, |
||||
|
}, |
||||
|
{ |
||||
|
colSpan: 2, |
||||
|
name: 'schema', |
||||
|
label: $t('developer.backend.export.liquibase.schema'), |
||||
|
type: 'w-select', |
||||
|
options: schemaOptionsRef, |
||||
|
}, |
||||
|
{ |
||||
|
colSpan: 6, |
||||
|
name: 'tables', |
||||
|
label: $t('developer.backend.export.liquibase.tables'), |
||||
|
type: 'w-grid-select', |
||||
|
multiple: true, |
||||
|
|
||||
|
displayValue: 'name', |
||||
|
grid: { |
||||
|
toolbarConfigure: { noIcon: false }, |
||||
|
hideBottom: true, |
||||
|
configButton: true, |
||||
|
checkboxSelection: true, |
||||
|
dataUrl: Environment.apiContextPath( |
||||
|
'/api/jdbc/metadata/getTables?datasource=' + |
||||
|
(valueReactive.datasource || '') + |
||||
|
'&catalog=' + |
||||
|
(valueReactive.catalog || '') + |
||||
|
'&schema=' + |
||||
|
(valueReactive.schema || ''), |
||||
|
), |
||||
|
pageable: false, |
||||
|
sortBy: ['name'], |
||||
|
sortNo: true, |
||||
|
toolbarActions: ['refresh'], |
||||
|
primaryKey: 'name', |
||||
|
columns: [ |
||||
|
{ name: 'name', label: $t('name') }, |
||||
|
{ name: 'remarks', label: $t('remarks') }, |
||||
|
], |
||||
|
}, |
||||
|
}, |
||||
|
]" |
||||
|
> |
||||
|
</w-form> |
||||
|
<div class="row justify-center q-gutter-md py-2"> |
||||
|
<w-progress-btn |
||||
|
ref="progressBtnRef" |
||||
|
icon="bi-database-down" |
||||
|
:label="$t('export')" |
||||
|
data-url="/api/jdbc/data/traceSchemaExporterExecuteProgress" |
||||
|
@click="exportData" |
||||
|
@success=" |
||||
|
(progressInfo) => { |
||||
|
Downloader.get(Environment.apiContextPath('/api/mvc/download?filePath=' + encodeURIComponent(progressInfo.result))); |
||||
|
} |
||||
|
" |
||||
|
></w-progress-btn> |
||||
|
</div> |
||||
|
</div> |
||||
|
</template> |
||||
|
<script setup lang="ts"> |
||||
|
import 'tailwindcss/utilities.css'; |
||||
|
import { ref, reactive, onMounted, onUpdated } from 'vue'; |
||||
|
|
||||
|
import { t, axios, Environment, DialogManager, Downloader } from 'platform-core'; |
||||
|
|
||||
|
const progressBtnRef = ref(); |
||||
|
const datasourceOptionsRef = ref([]); |
||||
|
const catalogOptionsRef = ref([]); |
||||
|
const schemaOptionsRef = ref([]); |
||||
|
const tablesOptionsRef = ref([]); |
||||
|
|
||||
|
const valueReactive = reactive({ |
||||
|
datasource: undefined, |
||||
|
catalog: undefined, |
||||
|
schema: undefined, |
||||
|
tables: [], |
||||
|
sql: undefined, |
||||
|
}); |
||||
|
|
||||
|
const loadDatasource = () => { |
||||
|
axios.get(Environment.apiContextPath('/api/system/datasource?pageable=false&sortBy=name')).then((response) => { |
||||
|
const data = response?.data.content; |
||||
|
const datasourceOptions = [{ label: t('default'), value: '' }]; |
||||
|
if (data && data.length > 0) { |
||||
|
for (let item of data) { |
||||
|
datasourceOptions.push({ label: item.name, value: item.name }); |
||||
|
} |
||||
|
} |
||||
|
datasourceOptionsRef.value = datasourceOptions; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const datasourceChanged = (datasource: string) => { |
||||
|
datasource = datasource || ''; |
||||
|
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getCatalogs?datasource=' + datasource)).then((response) => { |
||||
|
const data = response?.data; |
||||
|
const catalogOptions = []; |
||||
|
if (data && data.length > 0) { |
||||
|
for (let item of data) { |
||||
|
catalogOptions.push({ label: item.name, value: item.name }); |
||||
|
} |
||||
|
} |
||||
|
catalogOptionsRef.value = catalogOptions; |
||||
|
schemaOptionsRef.value = []; |
||||
|
tablesOptionsRef.value = []; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const catalogChanged = (datasource: string, catalog: string) => { |
||||
|
datasource = datasource || ''; |
||||
|
axios.get(Environment.apiContextPath('/api/jdbc/metadata/getSchemas?datasource=' + datasource + '&catalog=' + catalog)).then((response) => { |
||||
|
const data = response?.data; |
||||
|
const schemaOptions = []; |
||||
|
if (data && data.length > 0) { |
||||
|
for (let item of data) { |
||||
|
schemaOptions.push({ label: item.name, value: item.name }); |
||||
|
} |
||||
|
} |
||||
|
schemaOptionsRef.value = schemaOptions; |
||||
|
tablesOptionsRef.value = []; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const schemaChanged = (datasource: string, catalog: string, schema: string) => { |
||||
|
datasource = datasource || ''; |
||||
|
catalog = catalog || ''; |
||||
|
schema = schema || ''; |
||||
|
axios |
||||
|
.get(Environment.apiContextPath('/api/jdbc/metadata/getTables?datasource=' + datasource + '&catalog=' + catalog + '&schema=' + schema)) |
||||
|
.then((response) => { |
||||
|
const data = response?.data; |
||||
|
const tablesOptions = []; |
||||
|
if (data && data.length > 0) { |
||||
|
for (let item of data) { |
||||
|
tablesOptions.push({ label: item.name + ' - ' + item.remarks, value: item.name }); |
||||
|
} |
||||
|
} |
||||
|
tablesOptionsRef.value = tablesOptions; |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
const exportData = (e) => { |
||||
|
DialogManager.confirm(t('developer.backend.export.liquibase.export.tip'), () => { |
||||
|
const data = valueReactive; |
||||
|
const config = { |
||||
|
datasource: data.datasource, |
||||
|
catalog: data.catalog, |
||||
|
schema: data.schema, |
||||
|
tables: data.tables, |
||||
|
}; |
||||
|
axios.post(Environment.apiContextPath('/api/jdbc/data/exportSchema'), config).then((response) => { |
||||
|
progressBtnRef.value.start(); |
||||
|
}); |
||||
|
}); |
||||
|
}; |
||||
|
|
||||
|
onMounted(() => { |
||||
|
loadDatasource(); |
||||
|
}); |
||||
|
</script> |
@ -0,0 +1,38 @@ |
|||||
|
package io.sc.platform.jdbc.controller.support; |
||||
|
|
||||
|
import io.sc.platform.core.enums.ProgressStatus; |
||||
|
import io.sc.platform.core.support.ProgressableThread; |
||||
|
import io.sc.platform.jdbc.exporter.support.DataExportConfigure; |
||||
|
import io.sc.platform.jdbc.exporter.support.SchemaExportConfigure; |
||||
|
import io.sc.platform.jdbc.service.JdbcDataService; |
||||
|
import io.sc.platform.util.StringUtil; |
||||
|
import org.slf4j.Logger; |
||||
|
import org.slf4j.LoggerFactory; |
||||
|
|
||||
|
import java.util.Locale; |
||||
|
|
||||
|
public class SchemaExporterThread extends ProgressableThread { |
||||
|
private Logger log = LoggerFactory.getLogger(SchemaExporterThread.class); |
||||
|
private JdbcDataService jdbcDataService; |
||||
|
private SchemaExportConfigure configure; |
||||
|
private Locale locale; |
||||
|
|
||||
|
public SchemaExporterThread(JdbcDataService jdbcDataService, SchemaExportConfigure configure, Locale locale){ |
||||
|
this.jdbcDataService =jdbcDataService; |
||||
|
this.configure =configure; |
||||
|
this.locale =locale; |
||||
|
} |
||||
|
@Override |
||||
|
public void run() { |
||||
|
try { |
||||
|
progressInfo.setStatus(ProgressStatus.RUNNING); |
||||
|
jdbcDataService.exportSchema(configure,progressInfo,locale); |
||||
|
progressInfo.setStatus(ProgressStatus.COMPLETED); |
||||
|
} catch (Exception e) { |
||||
|
log.error("",e); |
||||
|
progressInfo.setStatus(ProgressStatus.ERROR); |
||||
|
progressInfo.setErrorMessage(e.getMessage()); |
||||
|
progressInfo.setErrorStackTrace(StringUtil.getStackTrace(e)); |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue