Skip to content

Commit da02311

Browse files
author
lrhh123
committed
add: 添加消息列表处理
1 parent 2a4927d commit da02311

File tree

19 files changed

+769
-538
lines changed

19 files changed

+769
-538
lines changed

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,10 @@
135135
"react-hook-form": "^7.50.1",
136136
"react-icons": "^5.0.1",
137137
"react-markdown": "^9.0.1",
138+
"react-paginate": "^8.2.0",
138139
"react-router-dom": "^6.16.0",
139140
"react-spinners": "^0.13.8",
141+
"react-table": "^7.8.0",
140142
"react-use-websocket": "^4.8.1",
141143
"reflect-metadata": "^0.2.2",
142144
"remark-gfm": "^4.0.0",
@@ -170,6 +172,7 @@
170172
"@types/node": "20.6.2",
171173
"@types/react": "^18.2.21",
172174
"@types/react-dom": "^18.2.7",
175+
"@types/react-table": "^7.7.20",
173176
"@types/react-test-renderer": "^18.0.1",
174177
"@types/source-map-support": "^0.5.10",
175178
"@types/terser-webpack-plugin": "^5.0.4",

pnpm-lock.yaml

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/backend/backend.ts

Lines changed: 76 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ import { DispatchService } from './services/dispatchService';
1414
import { PluginService } from './services/pluginService';
1515
import { AppService } from './services/appService';
1616

17-
const configController = new ConfigController();
18-
const messageController = new MessageController();
19-
const keywordReplyController = new KeywordReplyController();
20-
2117
class BKServer {
2218
private app: express.Application;
2319

@@ -27,6 +23,12 @@ class BKServer {
2723

2824
private io: Server;
2925

26+
private configController: ConfigController;
27+
28+
private messageController: MessageController;
29+
30+
private keywordReplyController: KeywordReplyController;
31+
3032
private messageService: MessageService;
3133

3234
private pluginService: PluginService;
@@ -55,22 +57,23 @@ class BKServer {
5557
transports: ['websocket'],
5658
});
5759

58-
this.messageService = new MessageService(
59-
configController,
60-
keywordReplyController,
61-
);
60+
this.configController = new ConfigController();
61+
this.messageController = new MessageController();
62+
this.keywordReplyController = new KeywordReplyController(port);
63+
64+
this.messageService = new MessageService(this.keywordReplyController);
6265

6366
this.pluginService = new PluginService(
64-
configController,
67+
this.configController,
6568
this.messageService,
6669
);
6770

6871
this.dispatchService = new DispatchService(
6972
mainWindow,
7073
this.io,
71-
configController,
74+
this.configController,
7275
this.messageService,
73-
messageController,
76+
this.messageController,
7477
this.pluginService,
7578
);
7679

@@ -98,48 +101,51 @@ class BKServer {
98101
}
99102

100103
private setupRoutes(): void {
101-
// 查看消息列表
102-
// this.app.get(
103-
// '/api/v1/msg/list',
104-
// asyncHandler(async (req, res) => {
105-
// const {
106-
// page,
107-
// page_size: pageSize,
108-
// platform_id: platformId,
109-
// keyword,
110-
// start_time: startTime,
111-
// end_time: endTime,
112-
// } = req.query;
113-
114-
// const query = {
115-
// page,
116-
// pageSize,
117-
// platformId,
118-
// keyword,
119-
// startTime,
120-
// endTime,
121-
// orderBy: 'messages.created_at desc',
122-
// };
123-
124-
// const { total, msgs } =
125-
// // @ts-ignore
126-
// await sessionController.listMessagesWithSessions(query);
127-
128-
// // group messages
129-
// const groupedMsgs = msgs.reduce((acc: any, msg) => {
130-
// acc[msg.username] = acc[msg.username] || [];
131-
// acc[msg.username].push(msg);
132-
// return acc;
133-
// }, {});
134-
// res.json({
135-
// success: true,
136-
// data: groupedMsgs,
137-
// total,
138-
// page,
139-
// page_size: pageSize,
140-
// });
141-
// }),
142-
// );
104+
// 查询聊天会话
105+
this.app.post(
106+
'/api/v1/message/session',
107+
asyncHandler(async (req, res) => {
108+
const { page, pageSize, keyword, platformId } = req.body;
109+
const data = await this.messageController.getSessions({
110+
page,
111+
pageSize,
112+
keyword,
113+
platformId,
114+
});
115+
116+
res.json({
117+
success: true,
118+
data,
119+
});
120+
}),
121+
);
122+
123+
// 查询聊天消息
124+
this.app.post(
125+
'/api/v1/message/list',
126+
asyncHandler(async (req, res) => {
127+
const { sessionId } = req.body;
128+
const data = await this.messageController.getMessages(sessionId);
129+
res.json({
130+
success: true,
131+
data,
132+
});
133+
}),
134+
);
135+
136+
// 导出消息到 Excel
137+
this.app.get('/api/v1/message/excel', async (req, res) => {
138+
try {
139+
const path = await this.messageController.exportExcel();
140+
shell.openPath(path);
141+
res.json({ success: true, data: path });
142+
} catch (error) {
143+
res.status(500).json({
144+
success: false,
145+
message: error instanceof Error ? error.message : String(error),
146+
});
147+
}
148+
});
143149

144150
// 获取所有平台
145151
this.app.get(
@@ -158,7 +164,7 @@ class BKServer {
158164
'/api/v1/base/platform/active',
159165
asyncHandler(async (req, res) => {
160166
const { appId, instanceId } = req.query;
161-
const active = await configController.checkConfigActive({
167+
const active = await this.configController.checkConfigActive({
162168
appId: appId ? String(appId) : undefined,
163169
instanceId: instanceId ? String(instanceId) : undefined,
164170
});
@@ -176,7 +182,7 @@ class BKServer {
176182
'/api/v1/base/platform/active',
177183
asyncHandler(async (req, res) => {
178184
const { appId, instanceId, active } = req.body;
179-
await configController.activeConfig({
185+
await this.configController.activeConfig({
180186
appId: appId ? String(appId) : undefined,
181187
instanceId: instanceId ? String(instanceId) : undefined,
182188
active,
@@ -198,8 +204,8 @@ class BKServer {
198204
type: type ? String(type) : ('generic' as any),
199205
};
200206

201-
const obj = await configController.getConfigByType(data);
202-
const active = await configController.checkConfigActive(data);
207+
const obj = await this.configController.getConfigByType(data);
208+
const active = await this.configController.checkConfigActive(data);
203209

204210
res.json({
205211
success: true,
@@ -223,7 +229,7 @@ class BKServer {
223229
cfg,
224230
};
225231

226-
await configController.updateConfigByType(data);
232+
await this.configController.updateConfigByType(data);
227233
await this.dispatchService.syncConfig();
228234
res.json({ success: true });
229235
}),
@@ -250,8 +256,9 @@ class BKServer {
250256
platformId,
251257
};
252258

253-
// @ts-ignore
254-
const { total, autoReplies } = await keywordReplyController.list(query);
259+
const { total, autoReplies } =
260+
// @ts-ignore
261+
await this.keywordReplyController.list(query);
255262

256263
const data = autoReplies;
257264
const ptfs = await this.dispatchService.getAllPlatforms();
@@ -285,7 +292,7 @@ class BKServer {
285292

286293
this.app.post('/api/v1/reply/create', async (req, res) => {
287294
const { platform_id: platformId, keyword, reply, mode } = req.body;
288-
await keywordReplyController.create({
295+
await this.keywordReplyController.create({
289296
mode,
290297
platform_id: platformId,
291298
keyword,
@@ -296,7 +303,7 @@ class BKServer {
296303

297304
this.app.post('/api/v1/reply/update', async (req, res) => {
298305
const { id, platform_id: platformId, keyword, reply, mode } = req.body;
299-
await keywordReplyController.update(id, {
306+
await this.keywordReplyController.update(id, {
300307
mode,
301308
platform_id: platformId,
302309
keyword,
@@ -307,14 +314,14 @@ class BKServer {
307314

308315
this.app.post('/api/v1/reply/delete', async (req, res) => {
309316
const { id } = req.body;
310-
await keywordReplyController.delete(id);
317+
await this.keywordReplyController.delete(id);
311318
res.json({ success: true });
312319
});
313320

314321
this.app.post('/api/v1/reply/excel', async (req, res) => {
315322
const { path } = req.body;
316323
try {
317-
await keywordReplyController.importExcel(path);
324+
await this.keywordReplyController.importExcel(path);
318325
res.json({ success: true });
319326
} catch (error) {
320327
// @ts-ignore
@@ -324,12 +331,14 @@ class BKServer {
324331

325332
this.app.get('/api/v1/reply/excel', async (req, res) => {
326333
try {
327-
const path = await keywordReplyController.exportExcel();
334+
const path = await this.keywordReplyController.exportExcel();
328335
shell.openPath(path);
329336
res.json({ success: true, data: path });
330337
} catch (error) {
331-
// @ts-ignore
332-
res.status(500).json({ success: false, message: error.message });
338+
res.status(500).json({
339+
success: false,
340+
message: error instanceof Error ? error.message : String(error),
341+
});
333342
}
334343
});
335344

0 commit comments

Comments
 (0)