refactor(数据源): 拆分接口

This commit is contained in:
taojinlong 2024-01-25 14:38:44 +08:00
parent aa0199a934
commit ac736abe0c
6 changed files with 26 additions and 10 deletions

View File

@ -311,6 +311,8 @@ public class DatasourceServer implements DatasourceApi {
return dataSourceDTO;
}
@Transactional
@Override
public DatasourceDTO update(DatasourceDTO dataSourceDTO) throws DEException {
Long pk = null;
if (ObjectUtils.isEmpty(pk = dataSourceDTO.getId())) {

View File

@ -91,6 +91,12 @@ export const save = async (data = {}): Promise<Dataset> => {
})
}
export const update = async (data = {}): Promise<Dataset> => {
return request.post({ url: '/datasource/update', data }).then(res => {
return res?.data
})
}
export const move = async (data = {}): Promise<Dataset> => {
return request.post({ url: '/datasource/move', data }).then(res => {
return res?.data

View File

@ -1,7 +1,7 @@
<script lang="ts" setup>
import { ref, reactive, computed, watch, nextTick } from 'vue'
import { useI18n } from '@/hooks/web/useI18n'
import { checkRepeat, listDatasources, save } from '@/api/datasource'
import { checkRepeat, listDatasources, save, update } from '@/api/datasource'
import { ElMessage, ElMessageBox, ElMessageBoxOptions } from 'element-plus-secondary'
import type { DatasetOrFolder } from '@/api/dataset'
import nothingTree from '@/assets/img/nothing-tree.png'
@ -274,10 +274,11 @@ const saveDataset = () => {
}
request.apiConfiguration = ''
checkRepeat(request).then(res => {
let method = request.id === '' ? save : update
if (res) {
ElMessageBox.confirm(t('datasource.has_same_ds'), options as ElMessageBoxOptions).then(
() => {
save({ ...request, name: datasetForm.name, pid: params.pid })
method({ ...request, name: datasetForm.name, pid: params.pid })
.then(res => {
if (res !== undefined) {
wsCache.set('ds-new-success', true)
@ -292,7 +293,7 @@ const saveDataset = () => {
}
)
} else {
save({ ...request, name: datasetForm.name, pid: params.pid })
method({ ...request, name: datasetForm.name, pid: params.pid })
.then(res => {
if (res !== undefined) {
wsCache.set('ds-new-success', true)

View File

@ -13,7 +13,7 @@ import {
nextTick
} from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus-secondary'
import { save } from '@/api/datasource'
import { save, update } from '@/api/datasource'
import type { Action } from 'element-plus-secondary'
import { Base64 } from 'js-base64'
import ExcelInfo from '../ExcelInfo.vue'
@ -255,9 +255,12 @@ const saveExcelData = (sheetFileMd5, table, params, successCb, finallyCb) => {
table.sheets[i].jsonArray = []
}
table.configuration = Base64.encode(JSON.stringify(table.sheets))
let method = save
if (!table.id || table.id === '0') {
delete table.id
table.pid = params.pid
} else {
method = update
}
if (new Set(sheetFileMd5).size !== sheetFileMd5.length && !props.param.id) {
ElMessageBox.confirm(t('dataset.merge_title'), {
@ -272,7 +275,7 @@ const saveExcelData = (sheetFileMd5, table, params, successCb, finallyCb) => {
loading.value = true
table.mergeSheet = action === 'confirm'
if (action === 'confirm') {
save(table)
method(table)
.then(res => {
emitter.emit('showFinishPage', res)
successCb?.()
@ -288,7 +291,7 @@ const saveExcelData = (sheetFileMd5, table, params, successCb, finallyCb) => {
}
if (action === 'cancel') {
save(table)
method(table)
.then(res => {
emitter.emit('showFinishPage', res)
successCb?.()
@ -307,7 +310,7 @@ const saveExcelData = (sheetFileMd5, table, params, successCb, finallyCb) => {
} else {
if (loading.value) return
loading.value = true
save(table)
method(table)
.then(res => {
emitter.emit('showFinishPage', res)
successCb?.()

View File

@ -8,7 +8,7 @@ import DsTypeList from './DsTypeList.vue'
import { useI18n } from '@/hooks/web/useI18n'
import EditorDetail from './EditorDetail.vue'
import ExcelDetail from './ExcelDetail.vue'
import { save, validate, latestUse, isShowFinishPage, checkRepeat } from '@/api/datasource'
import { save, update, validate, latestUse, isShowFinishPage, checkRepeat } from '@/api/datasource'
import { Base64 } from 'js-base64'
import type { Param } from './ExcelDetail.vue'
import { dsTypes, typeList, nameMap } from './option'
@ -403,6 +403,7 @@ const saveDS = () => {
tip: ''
}
checkRepeat(request).then(res => {
let method = request.id === '' ? save : update
if (res) {
ElMessageBox.confirm(t('datasource.has_same_ds'), options as ElMessageBoxOptions).then(
() => {
@ -410,7 +411,7 @@ const saveDS = () => {
return
}
dsLoading.value = true
save(request)
method(request)
.then(res => {
if (res !== undefined) {
handleShowFinishPage({ id: res.id, name: res.name })
@ -427,7 +428,7 @@ const saveDS = () => {
return
}
dsLoading.value = true
save(request)
method(request)
.then(res => {
if (res !== undefined) {
handleShowFinishPage({ id: res.id, name: res.name })

View File

@ -34,6 +34,9 @@ public interface DatasourceApi {
@PostMapping("/save")
DatasourceDTO save(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
@PostMapping("/update")
DatasourceDTO update(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;
@PostMapping("/move")
DatasourceDTO move(@RequestBody DatasourceDTO dataSourceDTO) throws DEException;