Unverified Commit db105663 authored by Licho's avatar Licho Committed by GitHub

feat: add watch table comboBox select. (#1860)

* feat: add watch table comboBox select. Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> * Spotless Apply * add watch table comboBox select. Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> * Spotless Apply --------- Signed-off-by: 's avatarLicho <lecho.sun@gmail.com> Co-authored-by: 's avatarleechor <leechor@users.noreply.github.com>
parent 70342d51
...@@ -26,6 +26,7 @@ import org.dinky.service.StatementService; ...@@ -26,6 +26,7 @@ import org.dinky.service.StatementService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
...@@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -35,6 +36,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -52,6 +54,7 @@ import lombok.extern.slf4j.Slf4j; ...@@ -52,6 +54,7 @@ import lombok.extern.slf4j.Slf4j;
public class StatementController { public class StatementController {
private final StatementService statementService; private final StatementService statementService;
private final ObjectMapper objectMapper = new ObjectMapper();
/** 新增或者更新 */ /** 新增或者更新 */
@PutMapping @PutMapping
...@@ -97,4 +100,16 @@ public class StatementController { ...@@ -97,4 +100,16 @@ public class StatementController {
statement = statementService.getById(statement.getId()); statement = statementService.getById(statement.getId());
return Result.succeed(statement, "获取成功"); return Result.succeed(statement, "获取成功");
} }
@PostMapping("/getWatchTables")
@SuppressWarnings("unchecked")
public Result<List<String>> getWatchTables(@RequestBody String statement) {
try {
Map<String, String> data = objectMapper.readValue(statement, Map.class);
String ss = data.get("statement");
return Result.succeed(statementService.getWatchTables(ss));
} catch (Exception e) {
return Result.failed(e.getMessage());
}
}
} }
...@@ -22,6 +22,8 @@ package org.dinky.service; ...@@ -22,6 +22,8 @@ package org.dinky.service;
import org.dinky.db.service.ISuperService; import org.dinky.db.service.ISuperService;
import org.dinky.model.Statement; import org.dinky.model.Statement;
import java.util.List;
/** /**
* StatementService * StatementService
* *
...@@ -31,4 +33,6 @@ import org.dinky.model.Statement; ...@@ -31,4 +33,6 @@ import org.dinky.model.Statement;
public interface StatementService extends ISuperService<Statement> { public interface StatementService extends ISuperService<Statement> {
boolean insert(Statement statement); boolean insert(Statement statement);
List<String> getWatchTables(String statement);
} }
...@@ -22,7 +22,14 @@ package org.dinky.service.impl; ...@@ -22,7 +22,14 @@ package org.dinky.service.impl;
import org.dinky.db.service.impl.SuperServiceImpl; import org.dinky.db.service.impl.SuperServiceImpl;
import org.dinky.mapper.StatementMapper; import org.dinky.mapper.StatementMapper;
import org.dinky.model.Statement; import org.dinky.model.Statement;
import org.dinky.parser.SqlType;
import org.dinky.service.StatementService; import org.dinky.service.StatementService;
import org.dinky.trans.Operations;
import org.dinky.utils.SqlUtil;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -40,4 +47,16 @@ public class StatementServiceImpl extends SuperServiceImpl<StatementMapper, Stat ...@@ -40,4 +47,16 @@ public class StatementServiceImpl extends SuperServiceImpl<StatementMapper, Stat
public boolean insert(Statement statement) { public boolean insert(Statement statement) {
return baseMapper.insert(statement) > 0; return baseMapper.insert(statement) > 0;
} }
@Override
public List<String> getWatchTables(String statement) {
// TODO: 2023/4/7 this function not support variable sql, because, JobManager and executor
// couple function
// and status and task execute.
final String[] statements = SqlUtil.getStatements(statement);
return Arrays.stream(statements)
.filter(t -> SqlType.WATCH.equals(Operations.getOperationType(t)))
.map(t -> t.substring(t.lastIndexOf(" ")).trim())
.collect(Collectors.toList());
}
} }
...@@ -74,7 +74,7 @@ public class Operations { ...@@ -74,7 +74,7 @@ public class Operations {
} }
public static SqlType getOperationType(String sql) { public static SqlType getOperationType(String sql) {
String sqlTrim = sql.replaceAll(SQL_EMPTY_STR, "").trim().toUpperCase(); String sqlTrim = sql.replaceAll(SQL_EMPTY_STR, " ").trim().toUpperCase();
return Arrays.stream(SqlType.values()) return Arrays.stream(SqlType.values())
.filter(sqlType -> sqlType.match(sqlTrim)) .filter(sqlType -> sqlType.match(sqlTrim))
.findFirst() .findFirst()
......
...@@ -17,17 +17,18 @@ ...@@ -17,17 +17,18 @@
* *
*/ */
import {Input, Modal, Tabs} from "antd"; import {Modal, Select, Tabs} from "antd";
import {registerWatchTable, unRegisterWatchTable} from "@/pages/DataStudio/service"; import {registerWatchTable, unRegisterWatchTable} from "@/pages/DataStudio/service";
import {Component, useEffect, useState} from "react"; import {Component, useEffect, useState} from "react";
import stompClientUtil from "@/utils/stompClientUtil" import stompClientUtil from "@/utils/stompClientUtil"
import {Scrollbars} from 'react-custom-scrollbars'; import {Scrollbars} from 'react-custom-scrollbars';
import CodeShow from "@/components/Common/CodeShow"; import CodeShow from "@/components/Common/CodeShow";
import {l} from "@/utils/intl"; import {l} from "@/utils/intl";
import {clearConsole} from "@/components/Studio/StudioEvent/DDL"; import {clearConsole, getWatchTables} from "@/components/Studio/StudioEvent/DDL";
import {StateType} from "@/pages/DataStudio/model"; import {StateType} from "@/pages/DataStudio/model";
import {connect} from "umi"; import {connect} from "umi";
import {Subscription} from "stompjs"; import {Subscription} from "stompjs";
import {Option} from "antd/es/mentions";
import TabPane = Tabs.TabPane; import TabPane = Tabs.TabPane;
const DatePage = (props: any) => { const DatePage = (props: any) => {
...@@ -51,11 +52,13 @@ const DatePage = (props: any) => { ...@@ -51,11 +52,13 @@ const DatePage = (props: any) => {
}; };
useEffect(() => { useEffect(() => {
return () => unRegisterWatchTable({id, table: tableName}).then(res => { return () => {
console.log("unsubscribe: " + tableName) unRegisterWatchTable({id, table: tableName}).then(res => {
subScription?.unsubscribe(); console.log("unsubscribe: " + tableName)
}); subScription?.unsubscribe();
}, [subScription]); });
}
}, []);
const editorDidMountHandle = (editor: any, monaco: any) => { const editorDidMountHandle = (editor: any, monaco: any) => {
onSearchName(title); onSearchName(title);
...@@ -80,17 +83,28 @@ const DatePage = (props: any) => { ...@@ -80,17 +83,28 @@ const DatePage = (props: any) => {
}; };
const StudioData = (props: any) => { const StudioData = (props: any) => {
const {height, isActive} = props; const {height, isActive, current} = props;
const [panes, setPanes] = useState<[{ title: string, key: string, content: Component }]>([]); const [panes, setPanes] = useState<[{ title: string, key: string, content: Component }]>([]);
const addTab = () => { const addTab = async () => {
let title: string let title: string
if (current == undefined) {
return
}
const result = await getWatchTables(current.value);
let tables: [string] = result.datas
Modal.confirm({ Modal.confirm({
title: 'Please enter table name', title: 'Please select table name',
content: <Input onChange={e => title = e.target.value}/>, content: <Select defaultValue="" style={{width: 120}} onChange={e => title = e}>
{tables.map(t => (
<Option value={t}>{t}</Option>
))
}
</Select>,
onOk() { onOk() {
const activeKey = `${panes.length + 1}`; const activeKey = `${panes!.length + 1}`;
const newPanes = [...panes]; const newPanes = [...panes!];
newPanes.push({ newPanes.push({
title: title, title: title,
content: <DatePage height={height} title={title} stompClient={stompClientUtil.stompClient}/>, content: <DatePage height={height} title={title} stompClient={stompClientUtil.stompClient}/>,
...@@ -105,8 +119,8 @@ const StudioData = (props: any) => { ...@@ -105,8 +119,8 @@ const StudioData = (props: any) => {
stompClientUtil.connect(); stompClientUtil.connect();
}, [isActive]) }, [isActive])
useEffect(()=>{ useEffect(() => {
return ()=>{ return () => {
stompClientUtil.disconnect(); stompClientUtil.disconnect();
} }
}, []) }, [])
...@@ -116,11 +130,11 @@ const StudioData = (props: any) => { ...@@ -116,11 +130,11 @@ const StudioData = (props: any) => {
if (action === 'add') { if (action === 'add') {
addTab(); addTab();
} else if (action === 'remove') { } else if (action === 'remove') {
const newPanes = panes.filter((pane) => pane.key !== targetKey); const newPanes = panes!.filter((pane) => pane.key !== targetKey);
setPanes(newPanes); setPanes(newPanes);
} }
}}> }}>
{panes.map((pane) => ( {panes!.map((pane) => (
<TabPane tab={pane.title} key={pane.key}> <TabPane tab={pane.title} key={pane.key}>
{pane.content} {pane.content}
</TabPane> </TabPane>
......
...@@ -342,6 +342,10 @@ export async function showMetaStoreCatalogs(task: TaskType, dispatch: any) { ...@@ -342,6 +342,10 @@ export async function showMetaStoreCatalogs(task: TaskType, dispatch: any) {
}) })
} }
export async function getWatchTables(statement: string) {
return postAll('api/statement/getWatchTables', {statement});
}
/*--- Clear Console ---*/ /*--- Clear Console ---*/
export function clearConsole() { export function clearConsole() {
return getData('api/process/clearConsole', {}); return getData('api/process/clearConsole', {});
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment