# Generated by Django 5.2.9 on 2026-01-04 01:56

from django.db import migrations, models


class Migration(migrations.Migration):

    dependencies = [
        ("asset_analysis", "0001_initial"),
    ]

    operations = [
        migrations.CreateModel(
            name="AssetAnalysisAlert",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "severity",
                    models.CharField(
                        choices=[
                            ("info", "信息"),
                            ("warning", "警告"),
                            ("error", "错误"),
                            ("critical", "严重"),
                        ],
                        db_index=True,
                        max_length=20,
                        verbose_name="严重程度",
                    ),
                ),
                (
                    "alert_type",
                    models.CharField(
                        choices=[
                            ("scoring_error", "评分错误"),
                            ("weight_config_error", "权重配置错误"),
                            ("data_quality_issue", "数据质量问题"),
                            ("performance_issue", "性能问题"),
                            ("api_failure", "API 调用失败"),
                            ("validation_error", "验证错误"),
                        ],
                        db_index=True,
                        max_length=50,
                        verbose_name="告警类型",
                    ),
                ),
                ("title", models.CharField(max_length=200, verbose_name="告警标题")),
                ("message", models.TextField(verbose_name="告警消息")),
                (
                    "asset_type",
                    models.CharField(
                        blank=True, max_length=20, null=True, verbose_name="相关资产类型"
                    ),
                ),
                (
                    "asset_code",
                    models.CharField(
                        blank=True, max_length=20, null=True, verbose_name="相关资产代码"
                    ),
                ),
                (
                    "context",
                    models.JSONField(
                        blank=True,
                        default=dict,
                        help_text="存储额外的调试信息",
                        verbose_name="上下文信息",
                    ),
                ),
                ("stack_trace", models.TextField(blank=True, null=True, verbose_name="堆栈跟踪")),
                (
                    "is_resolved",
                    models.BooleanField(db_index=True, default=False, verbose_name="是否已解决"),
                ),
                (
                    "resolved_at",
                    models.DateTimeField(blank=True, null=True, verbose_name="解决时间"),
                ),
                (
                    "resolved_by",
                    models.IntegerField(blank=True, null=True, verbose_name="解决人ID"),
                ),
                (
                    "resolution_notes",
                    models.TextField(blank=True, null=True, verbose_name="解决备注"),
                ),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="创建时间"),
                ),
                ("updated_at", models.DateTimeField(auto_now=True, verbose_name="更新时间")),
            ],
            options={
                "verbose_name": "资产分析告警",
                "verbose_name_plural": "资产分析告警",
                "db_table": "asset_analysis_alert",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(fields=["-created_at"], name="asset_analy_created_62007a_idx"),
                    models.Index(
                        fields=["severity", "is_resolved"], name="asset_analy_severit_2b667a_idx"
                    ),
                    models.Index(fields=["alert_type"], name="asset_analy_alert_t_e51cb3_idx"),
                ],
            },
        ),
        migrations.CreateModel(
            name="AssetScoringLog",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
                    ),
                ),
                (
                    "asset_type",
                    models.CharField(db_index=True, max_length=20, verbose_name="资产类型"),
                ),
                (
                    "request_source",
                    models.CharField(
                        help_text="如: fund_dashboard, equity_screen, api_call",
                        max_length=50,
                        verbose_name="请求来源",
                    ),
                ),
                ("user_id", models.IntegerField(blank=True, null=True, verbose_name="用户ID")),
                ("regime", models.CharField(max_length=20, verbose_name="Regime")),
                ("policy_level", models.CharField(max_length=2, verbose_name="政策档位")),
                ("sentiment_index", models.FloatField(verbose_name="情绪指数")),
                ("active_signals_count", models.IntegerField(default=0, verbose_name="激活信号数")),
                (
                    "weight_config_name",
                    models.CharField(max_length=50, verbose_name="权重配置名称"),
                ),
                ("regime_weight", models.FloatField(verbose_name="Regime 权重")),
                ("policy_weight", models.FloatField(verbose_name="Policy 权重")),
                ("sentiment_weight", models.FloatField(verbose_name="Sentiment 权重")),
                ("signal_weight", models.FloatField(verbose_name="Signal 权重")),
                ("filters", models.JSONField(blank=True, default=dict, verbose_name="筛选条件")),
                ("total_assets", models.IntegerField(default=0, verbose_name="总资产数")),
                ("scored_assets", models.IntegerField(default=0, verbose_name="已评分资产数")),
                ("filtered_assets", models.IntegerField(default=0, verbose_name="筛选后资产数")),
                (
                    "execution_time_ms",
                    models.IntegerField(blank=True, null=True, verbose_name="执行时间(毫秒)"),
                ),
                ("cache_hit", models.BooleanField(default=False, verbose_name="是否命中缓存")),
                (
                    "status",
                    models.CharField(
                        choices=[
                            ("success", "成功"),
                            ("partial_success", "部分成功"),
                            ("failed", "失败"),
                        ],
                        default="success",
                        max_length=20,
                        verbose_name="状态",
                    ),
                ),
                ("error_message", models.TextField(blank=True, null=True, verbose_name="错误信息")),
                (
                    "created_at",
                    models.DateTimeField(auto_now_add=True, db_index=True, verbose_name="创建时间"),
                ),
            ],
            options={
                "verbose_name": "资产评分日志",
                "verbose_name_plural": "资产评分日志",
                "db_table": "asset_scoring_log",
                "ordering": ["-created_at"],
                "indexes": [
                    models.Index(fields=["-created_at"], name="asset_scori_created_e59da8_idx"),
                    models.Index(fields=["asset_type"], name="asset_scori_asset_t_8dbf73_idx"),
                    models.Index(fields=["status"], name="asset_scori_status_01e410_idx"),
                    models.Index(fields=["request_source"], name="asset_scori_request_ea7ffd_idx"),
                ],
            },
        ),
    ]
