Skip to content

Commit

Permalink
Support wechat custom url (#2680)
Browse files Browse the repository at this point in the history
* Spotless Apply

* support-wechat-custom-url

* Spotless Apply

---------

Co-authored-by: Zzm0809 <[email protected]>
  • Loading branch information
Zzm0809 and Zzm0809 authored Dec 18, 2023
1 parent f1ef316 commit 5b80c76
Show file tree
Hide file tree
Showing 19 changed files with 782 additions and 724 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@
public class WeChatConstants extends AlertBaseConstant {
public static final String TYPE = "WeChat";
/** WeChat alert baseconstant */
public static final String WECHAT_PUSH_URL = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=%s";
public static final String WECHAT_PUSH_URL = "%s/message/send?access_token=%s";

public static final String WECHAT_TOKEN_URL =
"https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
public static final String WECHAT_TOKEN_URL = "%s/gettoken?corpid=%s&corpsecret=%s";
public static final String CORP_ID = "corpId";
public static final String TEAM_SEND_MSG = "teamSendMsg";
public static final String AGENT_ID = "agentId";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ public class WeChatSender {
if (wechatParams.getSendType().equals(WeChatType.CHAT.getValue())) {
requireNonNull(wechatParams.getWebhook(), WeChatConstants.WEB_HOOK + " must not null");
}
weChatTokenUrlReplace =
String.format(WeChatConstants.WECHAT_TOKEN_URL, wechatParams.getCorpId(), wechatParams.getSecret());
weChatTokenUrlReplace = String.format(
WeChatConstants.WECHAT_TOKEN_URL,
wechatParams.getSendUrl(),
wechatParams.getCorpId(),
wechatParams.getSecret());
}

/**
Expand Down Expand Up @@ -99,7 +102,7 @@ public AlertResult send(String content) {
if (WeChatType.APP.getValue().equals(wechatParams.getSendType())) {
String token = getToken();
assert token != null;
url = String.format(WeChatConstants.WECHAT_PUSH_URL, token);
url = String.format(WeChatConstants.WECHAT_PUSH_URL, wechatParams.getSendUrl(), token);
} else {
url = wechatParams.getWebhook();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@ public class WechatParams {
private int agentId;
private List<String> atUsers = new ArrayList<>();
private String webhook;
private String sendUrl = "https://qyapi.weixin.qq.com/cgi-bin";
private String keyword;
}
67 changes: 36 additions & 31 deletions dinky-web/src/components/CallBackButton/CircleBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,51 @@
*
*/

import {TabsItemType, TaskDataType} from '@/pages/DataStudio/model';
import {Button} from 'antd';
import { TabsItemType, TaskDataType } from '@/pages/DataStudio/model';
import { Tab } from '@/pages/DataStudio/route';
import { Button } from 'antd';
import React from 'react';
import {Tab} from '@/pages/DataStudio/route';

export type CircleButtonProps = {
icon: React.ReactNode;
loading?: boolean;
onClick?: () => void;
title?: string;
key?: string;
icon: React.ReactNode;
loading?: boolean;
onClick?: () => void;
title?: string;
key?: string;
};
export type CircleBottomButtonProps = {
icon: React.ReactNode;
loading?: boolean;
onClick?: (tabs: Tab[], key: string, data: TaskDataType | undefined,refresh:any) => Promise<void>;
title?: string;
key?: string;
icon: React.ReactNode;
loading?: boolean;
onClick?: (
tabs: Tab[],
key: string,
data: TaskDataType | undefined,
refresh: any
) => Promise<void>;
title?: string;
key?: string;
};
export type CircleDataStudioButtonProps = {
icon: React.ReactNode;
loading?: boolean;
onClick?: (panes: TabsItemType[], activeKey: string) => void;
title?: string;
key?: string;
isShow?: boolean;
icon: React.ReactNode;
loading?: boolean;
onClick?: (panes: TabsItemType[], activeKey: string) => void;
title?: string;
key?: string;
isShow?: boolean;
};

export const CircleBtn: React.FC<CircleButtonProps> = (props) => {
const {onClick, title, icon, loading} = props;
const { onClick, title, icon, loading } = props;

return (
<Button
title={title}
loading={loading}
icon={icon}
block
type={'text'}
shape={'circle'}
onClick={onClick}
/>
);
return (
<Button
title={title}
loading={loading}
icon={icon}
block
type={'text'}
shape={'circle'}
onClick={onClick}
/>
);
};
5 changes: 5 additions & 0 deletions dinky-web/src/locales/en-US/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,11 @@ export default {
'rc.ai.actionPleaseHolder': 'Please enter the interface method',
'rc.ai.agentId': 'AgentId',
'rc.ai.agentIdPleaseHolder': 'Please enter AgentId',
'rc.ai.sendUrl': 'QiWei Send Addr',
'rc.ai.sendUrlPleaseHolder': 'Please enter the sending address or the proxy address',
'rc.ai.sendUrlValidate': 'Please enter the correct sending address, no / is required at the end',
'rc.ai.sendUrlTooltip':
'You can enter the proxy address for the sending address, such as: http://127.0.0.1:8080/cgi-bin, the default is: https://qyapi.weixin.qq.com/cgi-bin ',
'rc.ai.apikey': 'Account unique identifier',
'rc.ai.apikeyPleaseHolder': 'Please enter the unique ID of the account',
'rc.ai.appId': 'App ID',
Expand Down
5 changes: 5 additions & 0 deletions dinky-web/src/locales/zh-CN/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,11 @@ export default {
'rc.ai.actionPleaseHolder': '请输入接口方法',
'rc.ai.agentId': '代理ID',
'rc.ai.agentIdPleaseHolder': '请输入 AgentId',
'rc.ai.sendUrl': '企微发送地址',
'rc.ai.sendUrlPleaseHolder': '请输入发送地址可输入代理地址',
'rc.ai.sendUrlValidate': '请输入正确的发送地址,末尾不需要带 /',
'rc.ai.sendUrlTooltip':
'发送地址可输入代理地址,如:http://127.0.0.1:8080/cgi-bin ,默认为:https://qyapi.weixin.qq.com/cgi-bin',
'rc.ai.apikey': '账号唯一标识',
'rc.ai.apikeyPleaseHolder': '请输入账号唯一标识',
'rc.ai.appId': '应用 ID',
Expand Down
126 changes: 66 additions & 60 deletions dinky-web/src/pages/DataStudio/BottomContainer/TableData/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,79 +17,85 @@
*
*/

import {SseData} from '@/models/Sse';
import {TaskDataType} from '@/pages/DataStudio/model';
import {SSE_TOPIC} from '@/pages/DevOps/constants';
import {postAll} from '@/services/api';
import {l} from '@/utils/intl';
import {useModel} from '@@/exports';
import {Modal, Select} from 'antd';
import { SseData } from '@/models/Sse';
import { TaskDataType } from '@/pages/DataStudio/model';
import { SSE_TOPIC } from '@/pages/DevOps/constants';
import { postAll } from '@/services/api';
import { l } from '@/utils/intl';
import { useModel } from '@@/exports';
import { Modal, Select } from 'antd';
import TextArea from 'antd/es/input/TextArea';
import {Tab} from 'rc-tabs/lib/interface.d';
import * as React from 'react';
import {useEffect, useState} from 'react';
import { Tab } from 'rc-tabs/lib/interface.d';
import { useEffect, useState } from 'react';

export async function getPrintTables(statement: string) {
return postAll('api/printTable/getPrintTables', {statement});
return postAll('api/printTable/getPrintTables', { statement });
}

/*--- Clear Console ---*/
export type PrintTable = {
tableName: string;
fullTableName: string;
tableName: string;
fullTableName: string;
};

export const DataPage = (props: any) => {
const {style, title} = props;
const [consoleInfo, setConsoleInfo] = useState<string>('');
const {subscribeTopic} = useModel('Sse', (model: any) => ({
subscribeTopic: model.subscribeTopic
}));
const [tableName, setTableName] = useState<string>('');
const { style, title } = props;
const [consoleInfo, setConsoleInfo] = useState<string>('');
const { subscribeTopic } = useModel('Sse', (model: any) => ({
subscribeTopic: model.subscribeTopic
}));
const [tableName, setTableName] = useState<string>('');

useEffect(() => {
if (title) {
setTableName(title.tableName);
const topic = `${SSE_TOPIC.PRINT_TABLE}/${title.fullTableName}`;
return subscribeTopic([topic], (data: SseData) => {
setConsoleInfo((preConsoleInfo) => preConsoleInfo + '\n' + data.data);
});
}
}, []);
useEffect(() => {
if (title) {
setTableName(title.tableName);
const topic = `${SSE_TOPIC.PRINT_TABLE}/${title.fullTableName}`;
return subscribeTopic([topic], (data: SseData) => {
setConsoleInfo((preConsoleInfo) => preConsoleInfo + '\n' + data.data);
});
}
}, []);

return <TextArea value={consoleInfo} style={{width: style.width, height: style.height}}/>;
return <TextArea value={consoleInfo} style={{ width: style.width, height: style.height }} />;
};

export const onAdd = async (tabs: Tab[], key: string, data: TaskDataType | undefined, refresh: any) => {
const statement = data?.statement;
export const onAdd = async (
tabs: Tab[],
key: string,
data: TaskDataType | undefined,
refresh: any
) => {
const statement = data?.statement;

if (!statement) return;
const tabNames = tabs.map((tab) => tab.label);
const result = await getPrintTables(statement);
const tables: PrintTable[] = result.data.filter((table: PrintTable) => !tabNames.includes(table.tableName));
if (!statement) return;
const tabNames = tabs.map((tab) => tab.label);
const result = await getPrintTables(statement);
const tables: PrintTable[] = result.data.filter(
(table: PrintTable) => !tabNames.includes(table.tableName)
);

let selectTable: PrintTable;
Modal.confirm({
title: l('pages.datastudio.print.table.inputTableName'),
content: (
<Select
defaultValue=''
style={{width: '90%'}}
onChange={(e, t: any) => {
selectTable = {tableName: t.label, fullTableName: t.value};
}}
options={tables.map((table) => ({label: table.tableName, value: table.fullTableName}))}
/>
),
onOk() {
tabs.push({
key: key + "/" + selectTable.tableName,
label: selectTable.tableName,
children: <DataPage title={selectTable} style={{width: '100%', height: '100%'}}/>
});
refresh()
// onOk(selectTable);
},
zIndex: 1000
});
}
let selectTable: PrintTable;
Modal.confirm({
title: l('pages.datastudio.print.table.inputTableName'),
content: (
<Select
defaultValue=''
style={{ width: '90%' }}
onChange={(e, t: any) => {
selectTable = { tableName: t.label, fullTableName: t.value };
}}
options={tables.map((table) => ({ label: table.tableName, value: table.fullTableName }))}
/>
),
onOk() {
tabs.push({
key: key + '/' + selectTable.tableName,
label: selectTable.tableName,
children: <DataPage title={selectTable} style={{ width: '100%', height: '100%' }} />
});
refresh();
// onOk(selectTable);
},
zIndex: 1000
});
};
Loading

0 comments on commit 5b80c76

Please sign in to comment.