1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
import React, { useEffect, useState } from 'react';
import {
Card,
Button,
Table,
Space,
Modal,
Popconfirm,
notification,
Spin,
Pagination,
} from 'antd';
import copy from 'copy-to-clipboard';
import PageContainer from '@/components/BasePageContainer';
import styles from './ManagementDataBase.less';
import {
tableCheck,
tableCheckNew,
updateDateBase,
databaseStandardGetLog,
databaseStandardGetLogNew,
} from '@/services/database/api';
import { CheckSquareFilled, ConsoleSqlOutlined } from '@ant-design/icons';
const ManagementDataBase = () => {
const [autoCheckList, setAutoCheckList] = useState([]); // 自动列表
const [checkList, setCheckList] = useState([]); // 手动列表
const [logList, setLogList] = useState([]); // 日志列表
const [checkFlag, setCheckFlag] = useState(1);
const [upFlag, setUpFlag] = useState(1); //
const [checkLoading, setCheckLoading] = useState(false); // 按钮loading
const [logLoading, setLogLoading] = useState(false);
const [modalVisible, setModalVisible] = useState(false); // 弹窗
const [content, setContent] = useState(null);
const [modalTitle, setModalTitle] = useState('详细信息');
const [currentPage, setCurrentPage] = useState(1);
const [pageSize, setPageSize] = useState(10);
const [checkSql, setCheckSql] = useState('');
const [sqlVisible, setSqlVisible] = useState(false);
// 检查数据库表
useEffect(() => {
setCheckLoading(true);
// tableCheck({
// _version: 9999,
// _dc: new Date().getTime(),
// })
// .then(res => {
// setCheckLoading(false);
// console.log(res);
// if (res.sucess) {
// const { list, messageList } = res;
// // 自动检测列表
// let arr = list.map((item, index) => {
// item.key = index;
// return item;
// });
// // 手动检查列表
// let arr2 = messageList.map((item, index) => {
// item.key = index;
// return item;
// });
// setAutoCheckList(arr);
// setCheckList(arr2);
// }
// })
// .catch(err => {
// setCheckLoading(false);
// console.error(err);
// });
tableCheckNew()
.then(resnew => {
setCheckLoading(false);
console.log(resnew);
if (resnew.code == 0) {
let res = resnew.data;
const { Autolist, ManualList } = res;
// 自动检测列表
let arr = Autolist.map((item, index) => {
item.key = index;
return item;
});
// 手动检查列表
let arr2 = ManualList.map((item, index) => {
item.key = index;
return item;
});
setAutoCheckList(arr);
setCheckList(arr2);
}
})
.catch(err => {
setCheckLoading(false);
console.error(err);
});
}, [checkFlag]);
// 获取数据库升级记录
useEffect(() => {
setLogLoading(true);
// databaseStandardGetLog({
// _version: 9999,
// _dc: new Date().getTime(),
// })
// .then(res => {
// setLogLoading(false);
// if (res) {
// let arr = [];
// res.map((item, index) => {
// item.key = index;
// arr.push(item);
// });
// setLogList(res);
// }
// })
// .catch(err => {
// setLogLoading(false);
// console.error(err);
// });
databaseStandardGetLogNew()
.then(resnew => {
setLogLoading(false);
if (resnew.code == 0) {
let res = resnew.data.list;
let arr = [];
res.map((item, index) => {
item.key = index;
arr.push(item);
});
setLogList(res);
}
})
.catch(err => {
setLogLoading(false);
console.error(err);
});
}, [upFlag]);
// 检查功能
const handleCheck = () => {
setCheckFlag(checkFlag + 1);
};
// 升级功能
const handleUpdate = () => {
setCheckLoading(true);
updateDateBase()
.then(res => {
setCheckLoading(false);
setCheckFlag(checkFlag + 1);
setUpFlag(upFlag + 1);
if (res.code === 0) {
notification.success({
message: '通知',
duration: 3,
description: '修复成功',
});
} else {
notification.error({
message: '通知',
duration: 15,
description: res.msg,
});
}
})
.catch(err => {
setCheckLoading(false);
console.error(err);
});
};
const handleErrLog = (text, val) => {
setModalTitle(val);
let arr = [];
arr.push(text.split(/(\r\n)|(\n)/).map((item, index) => <p key={index}>{item}</p>));
setModalVisible(true);
// setContent(text);
setContent(arr);
};
const handleLog = (text, val) => {
setModalTitle(val);
let arr = [];
arr.push(
text
.split(/(\r\n)|(\n)/)
.map((item, index) => <p key={index} dangerouslySetInnerHTML={{ __html: item }} />),
);
setModalVisible(true);
// setContent(text);
setContent(arr);
};
// 复制SQL
const copySql = text => {
if (copy(text)) {
notification.success({
message: '提示',
duration: 3,
description: '复制成功',
});
} else {
notification.error({
message: '提示',
duration: 3,
description: '复制失败',
});
}
};
const autoCheckColumns = [
{
title: '表名称',
dataIndex: 'TableName',
key: 'TableName',
width: 200,
ellipsis: true,
},
{
title: '类型',
dataIndex: 'Type',
key: 'Type',
width: 180,
ellipsis: true,
},
{
title: '差异比较',
dataIndex: 'Message',
key: 'message',
},
];
const checkColumns = [
{
title: '表名称',
dataIndex: 'TableName',
key: 'TableName',
width: 200,
ellipsis: true,
},
{
title: '差异比较',
dataIndex: 'Message',
key: 'Message',
width: 400,
ellipsis: true,
},
{
title: 'SQL语句',
dataIndex: 'DiffSql',
key: 'DiffSql',
render: (text, record) => (
<Button
size="small"
type="primary"
onClick={() => {
// copySql(text);
check(record);
setSqlVisible(true);
}}
>
查看SQL
</Button>
),
},
];
const logColumns = [
{
title: '登录名',
dataIndex: 'UpdateBy',
key: 'UpdateBy',
width: 200,
ellipsis: true,
},
{
title: '数据库名称',
dataIndex: 'Name',
key: 'Name',
width: 200,
ellipsis: true,
},
{
title: '解决方案',
dataIndex: 'DbProductName',
key: 'DbProductName',
width: 200,
ellipsis: true,
},
// {
// title: '数据库版本',
// dataIndex: 'Version',
// key: 'Version',
// width: 200,
// ellipsis: true,
// },
{
title: '升级时间',
dataIndex: 'UpdateTime',
key: 'UpdateTime',
width: 200,
ellipsis: true,
},
// {
// title: '版本日志',
// dataIndex: 'Oklog',
// key: 'Oklog',
// render: text => (
// <Button
// size="small"
// disabled={!text}
// onClick={() => {
// handleLog(text, '版本日志');
// }}
// >
// 日志
// </Button>
// ),
// },
{
title: '成功日志',
dataIndex: 'Oklog',
key: 'Oklog',
ellipsis: true,
render: text => (
<Button
size="small"
type="primary"
onClick={() => {
handleLog(text, '详细信息');
}}
>
升级内容
</Button>
),
},
{
title: '错误日志',
dataIndex: 'Errlog',
key: 'Errlog',
ellipsis: true,
render: text => {
if (text && text.length > 0) {
return (
<Button
size="small"
type="primary"
onClick={() => {
handleLog(text, '详细信息');
}}
style={{ backgroundColor: 'red' }}
>
错误内容
</Button>
);
}
},
},
];
const paginationChange = (page, pageSizes) => {
console.log(page);
console.log(pageSizes);
setCurrentPage(page);
setPageSize(pageSizes);
};
const check = e => {
console.log(e);
setCheckSql(e);
};
return (
<>
<PageContainer>
<Card>
<div className={styles.tableTitle}>表结构自动化修复</div>
<Spin tip="loading..." spinning={checkLoading}>
<Table
className={styles.mgTop20}
columns={autoCheckColumns}
dataSource={autoCheckList}
bordered
size="small"
/>
<div className={styles.btnBox}>
<Space>
<Button type="primary" onClick={handleCheck}>
检查
</Button>
<Popconfirm
title="
是否升级当前连接数据库?"
okText="确认"
cancelText="取消"
onConfirm={() => {
handleUpdate();
}}
>
<Button danger type="primary">
升级
</Button>
</Popconfirm>
</Space>
</div>
</Spin>
</Card>
<Card className={styles.mgTop20}>
<div className={styles.tableTitle}>
手动修复 (字段长度不统一,请手动修改差异,数据可能会截断,请谨慎操作)
</div>
<Table
className={styles.mgTop20}
columns={checkColumns}
dataSource={checkList}
bordered
loading={checkLoading}
size="small"
/>
</Card>
<Card className={styles.mgTop20}>
<div className={styles.tableTitle}>数据库版本记录</div>
<Table
className={styles.mgTop20}
columns={logColumns}
dataSource={logList}
bordered
loading={logLoading}
size="small"
/>
</Card>
</PageContainer>
<Modal
title={modalTitle}
visible={modalVisible}
keyboard={false}
maskClosable
centered
onOk={() => setModalVisible(false)}
onCancel={() => setModalVisible(false)}
width="1000px"
bodyStyle={{
minHeight: '100px',
maxHeight: '600px',
overflowY: 'scroll',
}}
style={{ top: '40px' }}
footer={[
<Button type="primary" onClick={() => setModalVisible(false)} key="back">
关闭窗口
</Button>,
]}
>
{content}
</Modal>
<Modal
title={checkSql.TableName}
visible={sqlVisible}
maskClosable
centered
onOk={() => setSqlVisible(false)}
onCancel={() => setSqlVisible(false)}
width="500px"
bodyStyle={{
minHeight: '100px',
overflowY: 'scroll',
}}
footer={[
<Button type="primary" onClick={() => copySql(checkSql.DiffSql)}>
复制SQL
</Button>,
<Button type="primary" onClick={() => setSqlVisible(false)} key="back">
关闭窗口
</Button>,
]}
>
{checkSql.DiffSql}
</Modal>
</>
);
};
export default ManagementDataBase;