import React, { useState, useEffect } from 'react';
import { Card, Row, Col, Form, Input, Button, Select, Switch, InputNumber, Alert, Divider, Tabs, Table, Modal } from 'antd';
import { message } from 'antd';
import { DatabaseOutlined, KeyOutlined, SettingOutlined, SaveOutlined, ToolOutlined, RobotOutlined, EditOutlined } from '@ant-design/icons';
import './AdminConfig.css';

const { Option } = Select;
const { Item } = Form;
const { TabPane } = Tabs;

const AdminConfig = () => {
  const [form] = Form.useForm();
  const [messageApi, contextHolder] = message.useMessage();
  const [aiModelModalVisible, setAiModelModalVisible] = useState(false);
  const [currentAiModel, setCurrentAiModel] = useState(null);
  const [aiModelForm] = Form.useForm();

  // 组件挂载时获取配置
  useEffect(() => {
    fetchConfig();
  }, []);

  // 数据库配置
  const databaseConfig = {
    // MySQL配置
    mysql: {
      host: 'localhost',
      port: 3306,
      database: 'alpha-futures',
      username: 'root',
      password: 'password',
      ssl: false,
      enabled: true
    },
    // Redis配置
    redis: {
      host: 'localhost',
      port: 6379,
      password: '',
      db: 0,
      enabled: true
    }
  };

  // 服务器配置
  const serverConfig = {
    port: 3005,
    host: '0.0.0.0',
    environment: 'development',
    debug: true,
    timeout: 30000,
    maxBodySize: '10mb'
  };

  // 安全配置
  const securityConfig = {
    jwtSecret: 'your-secret-key',
    jwtExpiresIn: '7d',
    rateLimit: {
      windowMs: 60000,
      max: 120
    },
    cors: {
      origin: '*',
      methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
      allowedHeaders: ['Content-Type', 'Authorization']
    }
  };

  // 数据源配置
  const dataSourceConfig = {
    // 测试数据源配置
    test: {
      enabled: true,
      timeout: 10000,
      retries: 3,
      refreshInterval: 60000
    },
    // TQSDK配置
    tqsdk: {
      enabled: true,
      username: '',
      password: '',
      timeout: 30000,
      retries: 3,
      maxConnections: 5,
      pythonPort: 8000
    },
    // Wind配置
    wind: {
      enabled: false,
      apiKey: '',
      apiSecret: '',
      url: 'https://api.wind.com.cn',
      timeout: 30000,
      retries: 3
    },
    // 新浪财经配置
    sina: {
      enabled: false,
      url: 'https://finance.sina.com.cn',
      timeout: 10000,
      retries: 3,
      refreshInterval: 60000
    },
    // 默认数据源
    defaultDataSource: 'tqsdk'
  };

  const [config, setConfig] = useState({
    database: databaseConfig,
    server: serverConfig,
    security: securityConfig,
    dataSource: dataSourceConfig,
    aiModel: {
      models: [
        {
          id: 1,
          name: "DeepSeek",
          accuracy: "85%",
          responseTime: "250ms",
          enabled: true,
          apiKey: "",
          apiBaseUrl: "https://api.deepseek.com/v1/chat/completions",
          temperature: 0.3,
          maxTokens: 1000,
          timeout: 30000,
          retries: 3,
          predictionPeriods: ["1H", "4H", "1D"],
          confidenceThreshold: 70,
          historyDataDays: 90,
          technicalIndicators: {
            enabled: true,
            indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
          },
          fundamentalAnalysis: {
            enabled: true,
            factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
          },
          riskAssessment: {
            enabled: true,
            riskLevel: "medium"
          }
        },
        {
          id: 2,
          name: "GPT-4",
          accuracy: "88%",
          responseTime: "350ms",
          enabled: false,
          apiKey: "",
          apiBaseUrl: "https://api.openai.com/v1/chat/completions",
          temperature: 0.3,
          maxTokens: 1000,
          timeout: 30000,
          retries: 3,
          predictionPeriods: ["1H", "4H", "1D"],
          confidenceThreshold: 70,
          historyDataDays: 90,
          technicalIndicators: {
            enabled: true,
            indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
          },
          fundamentalAnalysis: {
            enabled: true,
            factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
          },
          riskAssessment: {
            enabled: true,
            riskLevel: "medium"
          }
        },
        {
          id: 3,
          name: "Claude",
          accuracy: "82%",
          responseTime: "200ms",
          enabled: false,
          apiKey: "",
          apiBaseUrl: "",
          temperature: 0.3,
          maxTokens: 1000,
          timeout: 30000,
          retries: 3,
          predictionPeriods: ["1H", "4H", "1D"],
          confidenceThreshold: 70,
          historyDataDays: 90,
          technicalIndicators: {
            enabled: true,
            indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
          },
          fundamentalAnalysis: {
            enabled: true,
            factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
          },
          riskAssessment: {
            enabled: true,
            riskLevel: "medium"
          }
        },
        {
          id: 4,
          name: "自定义模型",
          accuracy: "78%",
          responseTime: "150ms",
          enabled: false,
          apiKey: "",
          apiBaseUrl: "",
          temperature: 0.3,
          maxTokens: 1000,
          timeout: 30000,
          retries: 3,
          predictionPeriods: ["1H", "4H", "1D"],
          confidenceThreshold: 70,
          historyDataDays: 90,
          technicalIndicators: {
            enabled: true,
            indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
          },
          fundamentalAnalysis: {
            enabled: true,
            factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
          },
          riskAssessment: {
            enabled: true,
            riskLevel: "medium"
          }
        }
      ],
      defaultModel: "DeepSeek",
      predictionConfig: {
        defaultPeriod: "1D",
        defaultConfidenceThreshold: 70,
        defaultHistoryDataDays: 90
      }
    }
  });

  // 处理配置变更
  const handleConfigChange = (section, key, value) => {
    setConfig(prev => ({
      ...prev,
      [section]: {
        ...prev[section],
        [key]: value
      }
    }));
  };

  // 处理AI模型配置变更
  const handleAiModelConfigChange = (modelId, key, value) => {
    setConfig(prev => ({
      ...prev,
      aiModel: {
        ...prev.aiModel,
        models: prev.aiModel.models.map(model => 
          model.id === modelId ? { ...model, [key]: value } : model
        )
      }
    }));
  };

  // 处理AI模型详细配置变更
  const handleAiModelDetailConfigChange = (modelId, section, key, value) => {
    setConfig(prev => ({
      ...prev,
      aiModel: {
        ...prev.aiModel,
        models: prev.aiModel.models.map(model => 
          model.id === modelId ? {
            ...model,
            [section]: {
              ...model[section],
              [key]: value
            }
          } : model
        )
      }
    }));
  };

  // 处理数据库配置变更
  const handleDatabaseConfigChange = (dbType, key, value) => {
    setConfig(prev => ({
      ...prev,
      database: {
        ...prev.database,
        [dbType]: {
          ...prev.database[dbType],
          [key]: value
        }
      }
    }));
  };

  // 处理数据源配置变更
  const handleDataSourceConfigChange = (dsType, key, value) => {
    setConfig(prev => ({
      ...prev,
      dataSource: {
        ...prev.dataSource,
        [dsType]: {
          ...prev.dataSource[dsType],
          [key]: value
        }
      }
    }));
  };

  // 从后端获取当前配置
  const fetchConfig = async () => {
    try {
      const response = await fetch('http://localhost:3007/api/config/get');
      const result = await response.json();
      if (result.success) {
        const newConfig = result.data;
        console.log('当前配置:', newConfig);
        
        // 确保配置结构完整
        const completeConfig = {
          database: {
            mysql: {
              host: 'localhost',
              port: 3306,
              database: 'alpha-futures',
              username: 'root',
              password: 'password',
              ssl: false,
              enabled: true,
              ...newConfig.database?.mysql
            },
            redis: {
              host: 'localhost',
              port: 6379,
              password: '',
              db: 0,
              enabled: true,
              ...newConfig.database?.redis
            }
          },
          server: newConfig.server || {
            port: 3007, host: '0.0.0.0', environment: 'development', debug: true, timeout: 30000, maxBodySize: '10mb'
          },
          security: newConfig.security || {
            jwtSecret: 'your-secret-key', jwtExpiresIn: '7d',
            rateLimit: { windowMs: 60000, max: 120 },
            cors: { origin: '*', methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'], allowedHeaders: ['Content-Type', 'Authorization'] }
          },
          dataSource: newConfig.dataSource || {
            test: { enabled: true, timeout: 10000, retries: 3, refreshInterval: 60000 },
            tqsdk: { enabled: true, username: '', password: '', timeout: 30000, retries: 3, maxConnections: 5, pythonPort: 3007 },
            wind: { enabled: false, apiKey: '', apiSecret: '', url: 'https://api.wind.com.cn', timeout: 30000, retries: 3 },
            sina: { enabled: false, url: 'https://finance.sina.com.cn', timeout: 10000, retries: 3, refreshInterval: 60000 },
            defaultDataSource: 'tqsdk'
          },
          aiModel: newConfig.aiModel || {
            models: [
              {
                id: 1,
                name: "DeepSeek",
                accuracy: "85%",
                responseTime: "250ms",
                enabled: true,
                apiKey: "",
                apiBaseUrl: "https://api.deepseek.com/v1/chat/completions",
                temperature: 0.3,
                maxTokens: 1000,
                timeout: 30000,
                retries: 3,
                predictionPeriods: ["1H", "4H", "1D"],
                confidenceThreshold: 70,
                historyDataDays: 90,
                technicalIndicators: {
                  enabled: true,
                  indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
                },
                fundamentalAnalysis: {
                  enabled: true,
                  factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
                },
                riskAssessment: {
                  enabled: true,
                  riskLevel: "medium"
                }
              },
              {
                id: 2,
                name: "GPT-4",
                accuracy: "88%",
                responseTime: "350ms",
                enabled: false,
                apiKey: "",
                apiBaseUrl: "https://api.openai.com/v1/chat/completions",
                temperature: 0.3,
                maxTokens: 1000,
                timeout: 30000,
                retries: 3,
                predictionPeriods: ["1H", "4H", "1D"],
                confidenceThreshold: 70,
                historyDataDays: 90,
                technicalIndicators: {
                  enabled: true,
                  indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
                },
                fundamentalAnalysis: {
                  enabled: true,
                  factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
                },
                riskAssessment: {
                  enabled: true,
                  riskLevel: "medium"
                }
              },
              {
                id: 3,
                name: "Claude",
                accuracy: "82%",
                responseTime: "200ms",
                enabled: false,
                apiKey: "",
                apiBaseUrl: "",
                temperature: 0.3,
                maxTokens: 1000,
                timeout: 30000,
                retries: 3,
                predictionPeriods: ["1H", "4H", "1D"],
                confidenceThreshold: 70,
                historyDataDays: 90,
                technicalIndicators: {
                  enabled: true,
                  indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
                },
                fundamentalAnalysis: {
                  enabled: true,
                  factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
                },
                riskAssessment: {
                  enabled: true,
                  riskLevel: "medium"
                }
              },
              {
                id: 4,
                name: "自定义模型",
                accuracy: "78%",
                responseTime: "150ms",
                enabled: false,
                apiKey: "",
                apiBaseUrl: "",
                temperature: 0.3,
                maxTokens: 1000,
                timeout: 30000,
                retries: 3,
                predictionPeriods: ["1H", "4H", "1D"],
                confidenceThreshold: 70,
                historyDataDays: 90,
                technicalIndicators: {
                  enabled: true,
                  indicators: ["MACD", "RSI", "KDJ", "MA", "BOLL"]
                },
                fundamentalAnalysis: {
                  enabled: true,
                  factors: ["资金流向", "持仓分析", "现货价格", "库存变化"]
                },
                riskAssessment: {
                  enabled: true,
                  riskLevel: "medium"
                }
              }
            ],
            defaultModel: "DeepSeek",
            predictionConfig: {
              defaultPeriod: "1D",
              defaultConfidenceThreshold: 70,
              defaultHistoryDataDays: 90
            }
          }
        };
        
        // 确保 security.cors 结构正确
        if (completeConfig.security.cors && Array.isArray(completeConfig.security.cors.methods)) {
          completeConfig.security.cors.methods = completeConfig.security.cors.methods.join(', ');
        }
        if (completeConfig.security.cors && Array.isArray(completeConfig.security.cors.allowedHeaders)) {
          completeConfig.security.cors.allowedHeaders = completeConfig.security.cors.allowedHeaders.join(', ');
        }
        
        console.log('完整配置:', completeConfig);
        
        // 更新表单字段值
        form.setFieldsValue({
          'database.mysql.host': completeConfig.database.mysql.host,
          'database.mysql.port': completeConfig.database.mysql.port,
          'database.mysql.database': completeConfig.database.mysql.database,
          'database.mysql.username': completeConfig.database.mysql.username,
          'database.mysql.password': completeConfig.database.mysql.password,
          'database.mysql.ssl': completeConfig.database.mysql.ssl,
          'database.mysql.enabled': completeConfig.database.mysql.enabled,
          
          'database.redis.host': completeConfig.database.redis.host,
          'database.redis.port': completeConfig.database.redis.port,
          'database.redis.password': completeConfig.database.redis.password,
          'database.redis.db': completeConfig.database.redis.db,
          'database.redis.enabled': completeConfig.database.redis.enabled,
          
          'server.port': completeConfig.server.port,
          'server.host': completeConfig.server.host,
          'server.environment': completeConfig.server.environment,
          'server.debug': completeConfig.server.debug,
          'server.timeout': completeConfig.server.timeout,
          'server.maxBodySize': completeConfig.server.maxBodySize,
          
          'security.jwtSecret': completeConfig.security.jwtSecret,
          'security.jwtExpiresIn': completeConfig.security.jwtExpiresIn,
          'security.rateLimit.windowMs': completeConfig.security.rateLimit.windowMs,
          'security.rateLimit.max': completeConfig.security.rateLimit.max,
          'security.cors.origin': completeConfig.security.cors.origin,
          'security.cors.methods': completeConfig.security.cors.methods,
          'security.cors.allowedHeaders': completeConfig.security.cors.allowedHeaders,
          
          'dataSource.defaultDataSource': completeConfig.dataSource.defaultDataSource,
          'dataSource.test.enabled': completeConfig.dataSource.test.enabled,
          'dataSource.test.timeout': completeConfig.dataSource.test.timeout,
          'dataSource.test.retries': completeConfig.dataSource.test.retries,
          'dataSource.test.refreshInterval': completeConfig.dataSource.test.refreshInterval,
          'dataSource.tqsdk.enabled': completeConfig.dataSource.tqsdk.enabled,
          'dataSource.tqsdk.username': completeConfig.dataSource.tqsdk.username,
          'dataSource.tqsdk.password': completeConfig.dataSource.tqsdk.password,
          'dataSource.tqsdk.timeout': completeConfig.dataSource.tqsdk.timeout,
          'dataSource.tqsdk.retries': completeConfig.dataSource.tqsdk.retries,
          'dataSource.tqsdk.maxConnections': completeConfig.dataSource.tqsdk.maxConnections,
          'dataSource.tqsdk.pythonPort': completeConfig.dataSource.tqsdk.pythonPort || 8000,
          'dataSource.wind.enabled': completeConfig.dataSource.wind.enabled,
          'dataSource.wind.apiKey': completeConfig.dataSource.wind.apiKey,
          'dataSource.wind.apiSecret': completeConfig.dataSource.wind.apiSecret,
          'dataSource.wind.url': completeConfig.dataSource.wind.url,
          'dataSource.wind.timeout': completeConfig.dataSource.wind.timeout,
          'dataSource.wind.retries': completeConfig.dataSource.wind.retries,
          'dataSource.sina.enabled': completeConfig.dataSource.sina.enabled,
          'dataSource.sina.url': completeConfig.dataSource.sina.url,
          'dataSource.sina.timeout': completeConfig.dataSource.sina.timeout,
          'dataSource.sina.retries': completeConfig.dataSource.sina.retries,
          'dataSource.sina.refreshInterval': completeConfig.dataSource.sina.refreshInterval
        });
        
        // 验证表单字段值是否正确设置
        setTimeout(() => {
          console.log('表单字段值:', form.getFieldsValue());
        }, 200);
        
        // 延迟更新 config 状态，确保表单字段值已更新
        setTimeout(() => {
          setConfig(completeConfig);
          console.log('表单字段值已更新');
        }, 100);
        
        messageApi.success('配置加载成功');
      } else {
        messageApi.error('配置加载失败');
      }
    } catch (error) {
      console.error('获取配置失败:', error);
      messageApi.error('获取配置失败，请检查网络连接');
    }
  };

  // 处理表单提交
  const handleSubmit = async (values) => {
    try {
      const response = await fetch('http://localhost:3007/api/config/save', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(config)
      });
      
      const result = await response.json();
      if (result.success) {
        messageApi.success(result.message);
        // 保存成功后重新获取配置
        fetchConfig();
      } else {
        messageApi.error(result.message);
      }
    } catch (error) {
      console.error('保存配置失败:', error);
      messageApi.error('保存配置失败，请检查网络连接');
    }
  };

  // 测试数据库连接
  const testDatabaseConnection = async (dbType) => {
    try {
      const response = await fetch('http://localhost:3007/api/config/test-database', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          dbType,
          config: config.database[dbType.toLowerCase()]
        })
      });
      
      const result = await response.json();
      if (result.success) {
        messageApi.success(result.message);
      } else {
        messageApi.error(result.message);
      }
    } catch (error) {
      console.error('测试数据库连接失败:', error);
      messageApi.error('测试数据库连接失败，请检查网络连接');
    }
  };

  // 测试数据源连接
  const testDataSourceConnection = async (dsType) => {
    try {
      const response = await fetch('http://localhost:3007/api/config/test-datasource', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          dsType,
          config: config.dataSource[dsType.toLowerCase()]
        })
      });
      
      const result = await response.json();
      if (result.success) {
        messageApi.success(result.message);
      } else {
        messageApi.error(result.message);
      }
    } catch (error) {
      console.error('测试数据源连接失败:', error);
      messageApi.error('测试数据源连接失败，请检查网络连接');
    }
  };

  // 打开AI模型配置模态框
  const openAiModelConfig = (model) => {
    setCurrentAiModel(model);
    // 从配置中获取模型数据
    const modelConfig = config.aiModel.models.find(m => m.id === model.id) || model;
    // 初始化表单数据
    aiModelForm.setFieldsValue({
      modelName: modelConfig.name,
      apiKey: modelConfig.apiKey || '',
      apiBaseUrl: modelConfig.apiBaseUrl || '',
      temperature: modelConfig.temperature || 0.3,
      maxTokens: modelConfig.maxTokens || 1000,
      timeout: modelConfig.timeout || 30000,
      retries: modelConfig.retries || 3,
      predictionPeriods: modelConfig.predictionPeriods || ['1H', '4H', '1D'],
      confidenceThreshold: modelConfig.confidenceThreshold || 70,
      historyDataDays: modelConfig.historyDataDays || 90,
      technicalIndicators: modelConfig.technicalIndicators || {
        enabled: true,
        indicators: ['MACD', 'RSI', 'KDJ', 'MA', 'BOLL']
      },
      fundamentalAnalysis: modelConfig.fundamentalAnalysis || {
        enabled: true,
        factors: ['资金流向', '持仓分析', '现货价格', '库存变化']
      },
      riskAssessment: modelConfig.riskAssessment || {
        enabled: true,
        riskLevel: 'medium'
      }
    });
    setAiModelModalVisible(true);
  };

  // 保存AI模型配置
  const saveAiModelConfig = (values) => {
    console.log('AI模型配置保存:', values);
    // 更新配置中的模型数据
    setConfig(prev => ({
      ...prev,
      aiModel: {
        ...prev.aiModel,
        models: prev.aiModel.models.map(model => 
          model.id === currentAiModel.id ? {
            ...model,
            apiKey: values.apiKey,
            apiBaseUrl: values.apiBaseUrl,
            temperature: values.temperature,
            maxTokens: values.maxTokens,
            timeout: values.timeout,
            retries: values.retries,
            predictionPeriods: values.predictionPeriods,
            confidenceThreshold: values.confidenceThreshold,
            historyDataDays: values.historyDataDays,
            technicalIndicators: values.technicalIndicators,
            fundamentalAnalysis: values.fundamentalAnalysis,
            riskAssessment: values.riskAssessment
          } : model
        )
      }
    }));
    setAiModelModalVisible(false);
    messageApi.success('AI模型配置已保存');
  };

  return (
    <>
      {contextHolder}
      <div className="admin-config">
      <h2>管理配置</h2>
      <Alert 
        title="警告：此页面包含敏感配置信息，请谨慎操作" 
        type="warning" 
        style={{ marginBottom: 24 }} 
      />

      <Form 
        form={form} 
        layout="vertical" 
        onFinish={handleSubmit}
      >
        <Tabs 
          defaultActiveKey="database" 
          items={[
            {
              label: <span><DatabaseOutlined /> 数据库配置</span>,
              key: 'database',
              children: (
                <>
                  {/* MySQL配置 */}
                  <Card title="MySQL配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="主机" name="database.mysql.host">
                          <Input 
                            
                            onChange={(e) => handleDatabaseConfigChange('mysql', 'host', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="端口" name="database.mysql.port">
                          <InputNumber 
                            
                            min={1} 
                            max={65535} 
                            onChange={(value) => handleDatabaseConfigChange('mysql', 'port', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="数据库" name="database.mysql.database">
                          <Input 
                            
                            onChange={(e) => handleDatabaseConfigChange('mysql', 'database', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="用户名" name="database.mysql.username">
                          <Input 
                            
                            onChange={(e) => handleDatabaseConfigChange('mysql', 'username', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="密码" name="database.mysql.password">
                          <Input.Password 
                            
                            onChange={(e) => handleDatabaseConfigChange('mysql', 'password', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="SSL" name="database.mysql.ssl">
                          <Switch 
                            defaultChecked={config.database.mysql.ssl} 
                            onChange={(checked) => handleDatabaseConfigChange('mysql', 'ssl', checked)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="启用" name="database.mysql.enabled">
                          <Switch 
                            defaultChecked={config.database.mysql.enabled} 
                            onChange={(checked) => handleDatabaseConfigChange('mysql', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="primary" 
                        onClick={() => testDatabaseConnection('MySQL')}
                        style={{ marginRight: 8 }}
                      >
                        测试连接
                      </Button>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDatabaseConfigChange('mysql', 'host', 'localhost');
                          handleDatabaseConfigChange('mysql', 'port', 3306);
                          handleDatabaseConfigChange('mysql', 'database', 'alpha-futures');
                          handleDatabaseConfigChange('mysql', 'username', 'root');
                          handleDatabaseConfigChange('mysql', 'password', 'password');
                          handleDatabaseConfigChange('mysql', 'ssl', false);
                          handleDatabaseConfigChange('mysql', 'enabled', true);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>

                  {/* Redis配置 */}
                  <Card title="Redis配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="主机" name="database.redis.host">
                          <Input 
                            
                            onChange={(e) => handleDatabaseConfigChange('redis', 'host', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="端口" name="database.redis.port">
                          <InputNumber 
                            
                            min={1} 
                            max={65535} 
                            onChange={(value) => handleDatabaseConfigChange('redis', 'port', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="密码" name="database.redis.password">
                          <Input.Password 
                            
                            onChange={(e) => handleDatabaseConfigChange('redis', 'password', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="数据库" name="database.redis.db">
                          <InputNumber 
                            
                            min={0} 
                            max={15} 
                            onChange={(value) => handleDatabaseConfigChange('redis', 'db', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={24}>
                        <Item label="启用" name="database.redis.enabled">
                          <Switch 
                            defaultChecked={config.database.redis.enabled} 
                            onChange={(checked) => handleDatabaseConfigChange('redis', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="primary" 
                        onClick={() => testDatabaseConnection('Redis')}
                        style={{ marginRight: 8 }}
                      >
                        测试连接
                      </Button>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDatabaseConfigChange('redis', 'host', 'localhost');
                          handleDatabaseConfigChange('redis', 'port', 6379);
                          handleDatabaseConfigChange('redis', 'password', '');
                          handleDatabaseConfigChange('redis', 'db', 0);
                          handleDatabaseConfigChange('redis', 'enabled', true);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>


                </>
              )
            },
            {
              label: <span><ToolOutlined /> 服务器配置</span>,
              key: 'server',
              children: (
                <Card title="服务器配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                  <Row gutter={[16, 16]}>
                    <Col span={6}>
                      <Item label="端口" name="server.port">
                        <InputNumber 
                          
                          min={1} 
                          max={65535} 
                          onChange={(value) => handleConfigChange('server', 'port', value)}
                        />
                      </Item>
                    </Col>
                    <Col span={6}>
                      <Item label="主机" name="server.host">
                        <Input 
                          
                          onChange={(e) => handleConfigChange('server', 'host', e.target.value)}
                        />
                      </Item>
                    </Col>
                    <Col span={6}>
                      <Item label="环境" name="server.environment">
                        <Select 
                          
                          onChange={(value) => handleConfigChange('server', 'environment', value)}
                        >
                          <Option value="development">开发环境</Option>
                          <Option value="production">生产环境</Option>
                          <Option value="testing">测试环境</Option>
                        </Select>
                      </Item>
                    </Col>
                    <Col span={6}>
                      <Item label="调试模式" name="server.debug">
                        <Switch 
                          defaultChecked={config.server.debug} 
                          onChange={(checked) => handleConfigChange('server', 'debug', checked)}
                        />
                      </Item>
                    </Col>
                    <Col span={6}>
                      <Item label="超时时间(ms)" name="server.timeout">
                        <InputNumber 
                          
                          min={1000} 
                          max={60000} 
                          step={1000} 
                          onChange={(value) => handleConfigChange('server', 'timeout', value)}
                        />
                      </Item>
                    </Col>
                    <Col span={6}>
                      <Item label="最大请求体大小" name="server.maxBodySize">
                        <Input 
                          
                          onChange={(e) => handleConfigChange('server', 'maxBodySize', e.target.value)}
                        />
                      </Item>
                    </Col>
                  </Row>
                </Card>
              )
            },
            {
              label: <span><KeyOutlined /> 安全配置</span>,
              key: 'security',
              children: (
                <>
                  {/* JWT配置 */}
                  <Card title="JWT配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={12}>
                        <Item label="JWT密钥" name="security.jwtSecret">
                          <Input.Password 
                            
                            onChange={(e) => handleConfigChange('security', 'jwtSecret', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="过期时间" name="security.jwtExpiresIn">
                          <Input 
                            
                            onChange={(e) => handleConfigChange('security', 'jwtExpiresIn', e.target.value)}
                          />
                        </Item>
                      </Col>
                    </Row>
                  </Card>

                  {/* 速率限制配置 */}
                  <Card title="速率限制配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={12}>
                        <Item label="时间窗口(ms)" name="security.rateLimit.windowMs">
                          <InputNumber 
                            
                            min={1000} 
                            max={3600000} 
                            step={1000} 
                            onChange={(value) => handleConfigChange('security', 'rateLimit', { ...config.security.rateLimit, windowMs: value })}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="最大请求数" name="security.rateLimit.max">
                          <InputNumber 
                            
                            min={1} 
                            max={1000} 
                            step={10} 
                            onChange={(value) => handleConfigChange('security', 'rateLimit', { ...config.security.rateLimit, max: value })}
                          />
                        </Item>
                      </Col>
                    </Row>
                  </Card>

                  {/* CORS配置 */}
                  <Card title="CORS配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={24}>
                        <Item label="允许的源" name="security.cors.origin">
                          <Input 
                            
                            onChange={(e) => handleConfigChange('security', 'cors', { ...config.security.cors, origin: e.target.value })}
                          />
                        </Item>
                      </Col>
                      <Col span={24}>
                        <Item label="允许的方法" name="security.cors.methods">
                          <Input 
                            
                            onChange={(e) => handleConfigChange('security', 'cors', { ...config.security.cors, methods: e.target.value.split(', ').map(m => m.trim()) })}
                          />
                        </Item>
                      </Col>
                      <Col span={24}>
                        <Item label="允许的头部" name="security.cors.allowedHeaders">
                          <Input 
                            
                            onChange={(e) => handleConfigChange('security', 'cors', { ...config.security.cors, allowedHeaders: e.target.value.split(', ').map(h => h.trim()) })}
                          />
                        </Item>
                      </Col>
                    </Row>
                  </Card>
                </>
              )
            },
            {
              label: <span><DatabaseOutlined /> 数据源配置</span>,
              key: 'dataSource',
              children: (
                <>
                  {/* 默认数据源配置 */}
                  <Card title="默认数据源" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={12}>
                        <Item label="默认数据源" name="dataSource.defaultDataSource">
                          <Select 
                            
                            onChange={(value) => handleConfigChange('dataSource', 'defaultDataSource', value)}
                          >
                            <Option value="tqsdk">TQSDK</Option>
                            <Option value="wind">Wind</Option>
                            <Option value="sina">新浪财经</Option>
                          </Select>
                        </Item>
                      </Col>
                    </Row>
                  </Card>

                  {/* 测试数据源配置 */}
                  <Card title="测试数据源配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="启用" name="dataSource.test.enabled">
                          <Switch 
                            onChange={(checked) => handleDataSourceConfigChange('test', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="超时时间(ms)" name="dataSource.test.timeout">
                          <InputNumber 
                            
                            min={1000} 
                            max={60000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('test', 'timeout', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="重试次数" name="dataSource.test.retries">
                          <InputNumber 
                            
                            min={0} 
                            max={10} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('test', 'retries', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="刷新间隔(ms)" name="dataSource.test.refreshInterval">
                          <InputNumber 
                            
                            min={1000} 
                            max={300000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('test', 'refreshInterval', value)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDataSourceConfigChange('test', 'enabled', true);
                          handleDataSourceConfigChange('test', 'timeout', 10000);
                          handleDataSourceConfigChange('test', 'retries', 3);
                          handleDataSourceConfigChange('test', 'refreshInterval', 60000);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>

                  {/* TQSDK配置 */}
                  <Card title="TQSDK配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="启用" name="dataSource.tqsdk.enabled">
                          <Switch 
                            onChange={(checked) => handleDataSourceConfigChange('tqsdk', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="用户名" name="dataSource.tqsdk.username">
                          <Input 
                            
                            onChange={(e) => handleDataSourceConfigChange('tqsdk', 'username', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="密码" name="dataSource.tqsdk.password">
                          <Input.Password 
                            
                            onChange={(e) => handleDataSourceConfigChange('tqsdk', 'password', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="超时时间(ms)" name="dataSource.tqsdk.timeout">
                          <InputNumber 
                            
                            min={1000} 
                            max={60000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('tqsdk', 'timeout', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="重试次数" name="dataSource.tqsdk.retries">
                          <InputNumber 
                            
                            min={0} 
                            max={10} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('tqsdk', 'retries', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="最大连接数" name="dataSource.tqsdk.maxConnections">
                          <InputNumber 
                            
                            min={1} 
                            max={20} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('tqsdk', 'maxConnections', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="Python服务端口" name="dataSource.tqsdk.pythonPort">
                          <InputNumber 
                            
                            min={1} 
                            max={65535} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('tqsdk', 'pythonPort', value)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="primary" 
                        onClick={() => testDataSourceConnection('TQSDK')}
                        style={{ marginRight: 8 }}
                      >
                        测试连接
                      </Button>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDataSourceConfigChange('tqsdk', 'enabled', true);
                          handleDataSourceConfigChange('tqsdk', 'username', '');
                          handleDataSourceConfigChange('tqsdk', 'password', '');
                          handleDataSourceConfigChange('tqsdk', 'timeout', 30000);
                          handleDataSourceConfigChange('tqsdk', 'retries', 3);
                          handleDataSourceConfigChange('tqsdk', 'maxConnections', 5);
                          handleDataSourceConfigChange('tqsdk', 'pythonPort', 3007);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>

                  {/* Wind配置 */}
                  <Card title="Wind配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="启用" name="dataSource.wind.enabled">
                          <Switch 
                            onChange={(checked) => handleDataSourceConfigChange('wind', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="API密钥" name="dataSource.wind.apiKey">
                          <Input.Password 
                            
                            onChange={(e) => handleDataSourceConfigChange('wind', 'apiKey', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="API密钥密钥" name="dataSource.wind.apiSecret">
                          <Input.Password 
                            
                            onChange={(e) => handleDataSourceConfigChange('wind', 'apiSecret', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="API URL" name="dataSource.wind.url">
                          <Input 
                            
                            onChange={(e) => handleDataSourceConfigChange('wind', 'url', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="超时时间(ms)" name="dataSource.wind.timeout">
                          <InputNumber 
                            
                            min={1000} 
                            max={60000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('wind', 'timeout', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="重试次数" name="dataSource.wind.retries">
                          <InputNumber 
                            
                            min={0} 
                            max={10} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('wind', 'retries', value)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="primary" 
                        onClick={() => testDataSourceConnection('Wind')}
                        style={{ marginRight: 8 }}
                      >
                        测试连接
                      </Button>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDataSourceConfigChange('wind', 'enabled', false);
                          handleDataSourceConfigChange('wind', 'apiKey', '');
                          handleDataSourceConfigChange('wind', 'apiSecret', '');
                          handleDataSourceConfigChange('wind', 'url', 'https://api.wind.com.cn');
                          handleDataSourceConfigChange('wind', 'timeout', 30000);
                          handleDataSourceConfigChange('wind', 'retries', 3);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>

                  {/* 新浪财经配置 */}
                  <Card title="新浪财经配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Row gutter={[16, 16]}>
                      <Col span={6}>
                        <Item label="启用" name="dataSource.sina.enabled">
                          <Switch 
                            onChange={(checked) => handleDataSourceConfigChange('sina', 'enabled', checked)}
                          />
                        </Item>
                      </Col>
                      <Col span={12}>
                        <Item label="API URL" name="dataSource.sina.url">
                          <Input 
                            
                            onChange={(e) => handleDataSourceConfigChange('sina', 'url', e.target.value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="超时时间(ms)" name="dataSource.sina.timeout">
                          <InputNumber 
                            
                            min={1000} 
                            max={60000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('sina', 'timeout', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="重试次数" name="dataSource.sina.retries">
                          <InputNumber 
                            
                            min={0} 
                            max={10} 
                            step={1} 
                            onChange={(value) => handleDataSourceConfigChange('sina', 'retries', value)}
                          />
                        </Item>
                      </Col>
                      <Col span={6}>
                        <Item label="刷新间隔(ms)" name="dataSource.sina.refreshInterval">
                          <InputNumber 
                            
                            min={1000} 
                            max={300000} 
                            step={1000} 
                            onChange={(value) => handleDataSourceConfigChange('sina', 'refreshInterval', value)}
                          />
                        </Item>
                      </Col>
                    </Row>
                    <div style={{ marginTop: 16 }}>
                      <Button 
                        type="primary" 
                        onClick={() => testDataSourceConnection('新浪财经')}
                        style={{ marginRight: 8 }}
                      >
                        测试连接
                      </Button>
                      <Button 
                        type="default" 
                        onClick={() => {
                          handleDataSourceConfigChange('sina', 'enabled', false);
                          handleDataSourceConfigChange('sina', 'url', 'https://finance.sina.com.cn');
                          handleDataSourceConfigChange('sina', 'timeout', 10000);
                          handleDataSourceConfigChange('sina', 'retries', 3);
                          handleDataSourceConfigChange('sina', 'refreshInterval', 60000);
                        }}
                      >
                        恢复默认
                      </Button>
                    </div>
                  </Card>
                </>
              )
            },
            {
              label: <span><RobotOutlined /> AI模型配置</span>,
              key: 'aiModel',
              children: (
                <>
                  {/* AI模型配置 */}
                  <Card title="AI模型配置" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Table 
                      dataSource={config.aiModel.models} 
                      columns={[
                        {
                          title: '模型名称',
                          dataIndex: 'name',
                          key: 'name'
                        },
                        {
                          title: '准确率',
                          dataIndex: 'accuracy',
                          key: 'accuracy'
                        },
                        {
                          title: '响应时间',
                          dataIndex: 'responseTime',
                          key: 'responseTime'
                        },
                        {
                          title: '默认模型',
                          dataIndex: 'enabled',
                          key: 'enabled',
                          render: (enabled, record) => (
                            <Switch 
                              checked={enabled} 
                              onChange={(checked) => handleAiModelConfigChange(record.id, 'enabled', checked)}
                            />
                          )
                        },
                        {
                          title: '操作',
                          key: 'action',
                          render: (_, record) => (
                            <Button type="link" icon={<EditOutlined />} onClick={() => openAiModelConfig(record)}>
                              配置
                            </Button>
                          )
                        }
                      ]} 
                      rowKey="id"
                    />
                  </Card>

                  {/* 模型参数调优 */}
                  <Card title="模型参数调优" className="admin-config-card" style={{ marginBottom: 24 }}>
                    <Form layout="vertical">
                      <Row gutter={[16, 16]}>
                        <Col span={8}>
                          <Item label="预测周期" name="aiModel.predictionConfig.defaultPeriod">
                            <Select 
                              defaultValue={config.aiModel.predictionConfig.defaultPeriod}
                              onChange={(value) => handleConfigChange('aiModel', 'predictionConfig', {
                                ...config.aiModel.predictionConfig,
                                defaultPeriod: value
                              })}
                            >
                              <Option value="1H">1小时</Option>
                              <Option value="4H">4小时</Option>
                              <Option value="1D">1天</Option>
                              <Option value="1W">1周</Option>
                            </Select>
                          </Item>
                        </Col>
                        <Col span={8}>
                          <Item label="置信度阈值" name="aiModel.predictionConfig.defaultConfidenceThreshold">
                            <Input 
                              addonAfter="%" 
                              type="number" 
                              defaultValue={config.aiModel.predictionConfig.defaultConfidenceThreshold} 
                              min={50} 
                              max={95}
                              onChange={(e) => handleConfigChange('aiModel', 'predictionConfig', {
                                ...config.aiModel.predictionConfig,
                                defaultConfidenceThreshold: parseInt(e.target.value) || 70
                              })}
                            />
                          </Item>
                        </Col>
                        <Col span={8}>
                          <Item label="历史数据长度" name="aiModel.predictionConfig.defaultHistoryDataDays">
                            <Input 
                              addonAfter="天" 
                              type="number" 
                              defaultValue={config.aiModel.predictionConfig.defaultHistoryDataDays} 
                              min={30} 
                              max={365}
                              onChange={(e) => handleConfigChange('aiModel', 'predictionConfig', {
                                ...config.aiModel.predictionConfig,
                                defaultHistoryDataDays: parseInt(e.target.value) || 90
                              })}
                            />
                          </Item>
                        </Col>
                      </Row>
                      <Button 
                        type="primary" 
                        style={{ marginTop: 8 }}
                        onClick={() => {
                          // 应用参数到所有模型
                          setConfig(prev => ({
                            ...prev,
                            aiModel: {
                              ...prev.aiModel,
                              models: prev.aiModel.models.map(model => ({
                                ...model,
                                predictionPeriods: [prev.aiModel.predictionConfig.defaultPeriod],
                                confidenceThreshold: prev.aiModel.predictionConfig.defaultConfidenceThreshold,
                                historyDataDays: prev.aiModel.predictionConfig.defaultHistoryDataDays
                              }))
                            }
                          }));
                          messageApi.success('模型参数已应用');
                        }}
                      >
                        应用参数
                      </Button>
                    </Form>
                  </Card>
                </>
              )
            }
          ]} 
        />

        <Divider />

        <div className="admin-config-actions">
          <Button type="default" style={{ marginRight: 8 }}>
            恢复默认配置
          </Button>
          <Button type="primary" htmlType="submit">
            <SaveOutlined /> 保存配置
          </Button>
        </div>
      </Form>

        {/* AI模型详细配置模态框 */}
        <Modal
          title={`${currentAiModel?.name || 'AI模型'}详细配置`}
          open={aiModelModalVisible}
          onCancel={() => setAiModelModalVisible(false)}
          width={900}
          footer={[
            <Button key="cancel" onClick={() => setAiModelModalVisible(false)}>
              取消
            </Button>,
            <Button key="save" type="primary" onClick={() => aiModelForm.submit()}>
              保存配置
            </Button>
          ]}
        >
          <Form
            form={aiModelForm}
            layout="vertical"
            onFinish={saveAiModelConfig}
          >
            {/* 基本配置 */}
            <Card title="基本配置" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={12}>
                  <Item label="模型名称" name="modelName">
                    <Input disabled />
                  </Item>
                </Col>
                <Col span={12}>
                  <Item label="API密钥" name="apiKey">
                    <Input.Password placeholder="请输入API密钥" />
                  </Item>
                </Col>
                <Col span={24}>
                  <Item label="API基础URL" name="apiBaseUrl">
                    <Input placeholder="请输入API基础URL" />
                  </Item>
                </Col>
              </Row>
            </Card>

            {/* 模型参数 */}
            <Card title="模型参数" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={6}>
                  <Item label="温度" name="temperature">
                    <InputNumber min={0} max={1} step={0.1} />
                  </Item>
                </Col>
                <Col span={6}>
                  <Item label="最大Tokens" name="maxTokens">
                    <InputNumber min={100} max={4000} step={100} />
                  </Item>
                </Col>
                <Col span={6}>
                  <Item label="超时时间(ms)" name="timeout">
                    <InputNumber min={5000} max={60000} step={5000} />
                  </Item>
                </Col>
                <Col span={6}>
                  <Item label="重试次数" name="retries">
                    <InputNumber min={1} max={5} step={1} />
                  </Item>
                </Col>
              </Row>
            </Card>

            {/* 预测配置 */}
            <Card title="预测配置" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={12}>
                  <Item label="预测周期" name="predictionPeriods">
                    <Select mode="multiple" placeholder="请选择预测周期">
                      <Option value="1H">1小时</Option>
                      <Option value="4H">4小时</Option>
                      <Option value="1D">1天</Option>
                      <Option value="1W">1周</Option>
                    </Select>
                  </Item>
                </Col>
                <Col span={6}>
                  <Item label="置信度阈值(%)" name="confidenceThreshold">
                    <InputNumber min={50} max={95} step={5} />
                  </Item>
                </Col>
                <Col span={6}>
                  <Item label="历史数据长度(天)" name="historyDataDays">
                    <InputNumber min={30} max={365} step={30} />
                  </Item>
                </Col>
              </Row>
            </Card>

            {/* 技术指标配置 */}
            <Card title="技术指标配置" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={24}>
                  <Item label="启用技术指标" name="technicalIndicators.enabled">
                    <Switch />
                  </Item>
                </Col>
                <Col span={24}>
                  <Item label="选择技术指标" name="technicalIndicators.indicators">
                    <Select mode="multiple" placeholder="请选择技术指标">
                      <Option value="MACD">MACD</Option>
                      <Option value="RSI">RSI</Option>
                      <Option value="KDJ">KDJ</Option>
                      <Option value="MA">MA</Option>
                      <Option value="BOLL">BOLL</Option>
                      <Option value="ATR">ATR</Option>
                      <Option value="ADX">ADX</Option>
                    </Select>
                  </Item>
                </Col>
              </Row>
            </Card>

            {/* 基本面分析配置 */}
            <Card title="基本面分析配置" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={24}>
                  <Item label="启用基本面分析" name="fundamentalAnalysis.enabled">
                    <Switch />
                  </Item>
                </Col>
                <Col span={24}>
                  <Item label="选择分析因素" name="fundamentalAnalysis.factors">
                    <Select mode="multiple" placeholder="请选择分析因素">
                      <Option value="资金流向">资金流向</Option>
                      <Option value="持仓分析">持仓分析</Option>
                      <Option value="现货价格">现货价格</Option>
                      <Option value="库存变化">库存变化</Option>
                      <Option value="政策影响">政策影响</Option>
                      <Option value="行业动态">行业动态</Option>
                    </Select>
                  </Item>
                </Col>
              </Row>
            </Card>

            {/* 风险评估配置 */}
            <Card title="风险评估配置" style={{ marginBottom: 16 }}>
              <Row gutter={[16, 16]}>
                <Col span={12}>
                  <Item label="启用风险评估" name="riskAssessment.enabled">
                    <Switch />
                  </Item>
                </Col>
                <Col span={12}>
                  <Item label="风险等级" name="riskAssessment.riskLevel">
                    <Select>
                      <Option value="low">低风险</Option>
                      <Option value="medium">中等风险</Option>
                      <Option value="high">高风险</Option>
                    </Select>
                  </Item>
                </Col>
              </Row>
            </Card>
          </Form>
        </Modal>
      </div>
    </>
  );
};

export default AdminConfig;