zhuguifei
2025-06-17 c1cc49dd93d38f51790558541d6835d1598ecccf
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
import {db} from "../service/database"
 
const TableName = 'config';
 
interface config {
    id: number;
    name: string;
    code: string;
    config_data: string;
}
 
 
// 系统配置
const SYSTEM_CONFIG = 1000;
 
 
class SystemController {
    async queryConfig(id: number) {
        const systemConfig: config | null = await db.findOne(TableName, 'id = ?', [id]);
        return systemConfig;
    }
 
    async setConfig(config: config) {
        switch (config.id) {
            case SYSTEM_CONFIG: {
                const systemConfig: config | null = await db.findOne(TableName, 'id = ?', [SYSTEM_CONFIG]);
                if (systemConfig?.id) {
                    await db.update(TableName, 'id = ?', config, [SYSTEM_CONFIG]);
                } else {
                    await db.insert(TableName, config);
                }
            }
        }
 
    }
}
 
SystemController.toString = () => '[class SystemController]';
 
export default SystemController;