INSERT INTO system_settings (id, setting_key, setting_value, updated_at, updated_by)
VALUES
(2401, 'warnings.rules', '{"creditLowPercent":20,"creditCriticalPercent":10,"dormantDays":30,"expireSoonDays":7,"taskFailRatePercent":15,"ticketSlaHours":4,"invoicePendingDays":3,"auditPendingHours":2,"contentBlockTimes":3,"channels":["站内信","短信","邮件","企业微信"],"remindTimes":["09:30","16:30"],"escalationOwners":["运营一组","财务值班","技术值班","客服主管","内容运营"]}', CURRENT_TIMESTAMP, 1)
ON DUPLICATE KEY UPDATE
    setting_value = VALUES(setting_value),
    updated_at = VALUES(updated_at),
    updated_by = VALUES(updated_by);

UPDATE admin_page_data
   SET payload_json = '{"title":"运营预警表","desc":"资源、任务、审核、工单、发票、内容安全与到期风险统一扫描和闭环处理","primary":"新增预警","workflow":["规则扫描","阈值命中","通知负责人","升级/关闭","复盘归档"],"metrics":[{"label":"待处理预警","value":"8","hint":"覆盖 8 类运营场景"},{"label":"严重预警","value":"2","hint":"任务失败与内容安全"},{"label":"今日新增","value":"5","hint":"按参数自动命中"},{"label":"已升级","value":"3","hint":"同步提醒负责人"}],"filters":["预警类型","风险等级","处理状态","负责人"],"columns":[{"prop":"company","label":"企业名称","minWidth":170},{"prop":"type","label":"预警类型","minWidth":140,"tag":true},{"prop":"level","label":"风险等级","minWidth":110,"tag":true},{"prop":"reason","label":"触发原因","minWidth":240},{"prop":"triggerValue","label":"触发值","minWidth":120},{"prop":"threshold","label":"触发阈值","minWidth":120},{"prop":"owner","label":"负责人","minWidth":110,"tag":true},{"prop":"channels","label":"提醒渠道","minWidth":150},{"prop":"nextAction","label":"下一步动作","minWidth":180},{"prop":"status","label":"处理状态","minWidth":110,"tag":true}],"rows":[{"id":"WARN20260527001","company":"星火互动文化","type":"资源不足","level":"高","reason":"剩余积分低于资源不足阈值，最近 7 天消耗加速","triggerValue":"剩余 12%","threshold":"<20%","owner":"财务值班","channels":"站内信、企业微信","nextAction":"推送续费包并同步商务跟进","status":"待处理"},{"id":"WARN20260527002","company":"环声传媒","type":"任务失败率","level":"严重","reason":"近 24 小时视频生成失败率超过任务健康阈值","triggerValue":"28%","threshold":">15%","owner":"技术值班","channels":"站内信、短信、企业微信","nextAction":"检查上游模型、素材格式与失败任务日志","status":"已升级"},{"id":"WARN20260527003","company":"青石影像工作室","type":"入驻审核超时","level":"中","reason":"入驻资料待处理时间超过审核 SLA，需要复核营业执照和法人材料","triggerValue":"3.6 小时","threshold":">2 小时","owner":"运营一组","channels":"企业微信","nextAction":"复核营业执照、法人身份与授权书","status":"处理中"},{"id":"WARN20260527004","company":"灵感短剧社","type":"沉睡客户","level":"中","reason":"超过沉睡客户天数未登录，近 60 天无项目产出","triggerValue":"35 天","threshold":">30 天","owner":"客服主管","channels":"邮件、企业微信","nextAction":"进入客服回访队列并发送案例模板","status":"待处理"},{"id":"WARN20260527005","company":"南风影业","type":"工单 SLA","level":"高","reason":"加急工单超过 SLA 未解决，客户反馈视频任务卡住","triggerValue":"5.2 小时","threshold":">4 小时","owner":"客服主管","channels":"短信、企业微信","nextAction":"转主管介入并补充技术排查记录","status":"已升级"},{"id":"WARN20260527006","company":"星轨传媒","type":"发票待处理","level":"中","reason":"已付款订单超过开票处理天数未归档","triggerValue":"4 天","threshold":">3 天","owner":"财务值班","channels":"站内信、企业微信","nextAction":"核验发票抬头、税号并完成开票","status":"待处理"},{"id":"WARN20260527007","company":"北辰影视","type":"内容安全","level":"严重","reason":"同租户连续触发敏感素材拦截，需暂停相关任务并复核项目内容","triggerValue":"3 次","threshold":">=3 次","owner":"内容运营","channels":"站内信、短信","nextAction":"暂停任务、复核素材并记录风控结论","status":"处理中"},{"id":"WARN20260527008","company":"云幕传媒","type":"套餐到期","level":"中","reason":"企业版套餐即将到期，需提前触达管理员","triggerValue":"5 天","threshold":"<=7 天","owner":"商务负责人","channels":"邮件、企业微信","nextAction":"发送续费提醒并确认资源余额","status":"待处理"}],"cards":[{"title":"预警场景","value":"8 类核心运营风险","items":["资源不足、套餐到期、沉睡客户进入商业化与客服闭环","任务失败率、内容安全、工单 SLA 进入技术与客服升级链路","入驻审核超时和发票待处理分别绑定运营与财务负责人"]},{"title":"提醒策略","value":"阈值 + 渠道 + 升级负责人","items":["阈值参数从 system_settings.warnings.rules 读取","提醒渠道支持站内信、短信、邮件和企业微信多选","严重预警自动纳入升级负责人待办"]},{"title":"处置闭环","value":"待处理 / 处理中 / 已升级 / 已关闭","items":["行内处理会回写状态和处理时间","新增与编辑记录保存在 admin_page_data 页面业务数据中","删除业务记录需要二次确认，避免误删"]}],"logicRules":[{"name":"资源不足预警","scope":"按租户余额与月度消耗速度判断资源风险。","formula":"剩余比例 = tenant_balances.balance / tenant_quotas.monthly_credits；低于配置阈值触发。","owner":"财务运营","editable":"可在预警参数中调整阈值","notes":"默认 20% 提醒，10% 严重。"},{"name":"任务失败率预警","scope":"按近 24 小时任务失败率识别模型或素材异常。","formula":"失败率 = 失败任务数 / 总任务数 * 100%，超过配置阈值触发。","owner":"技术值班","editable":"可调整失败率阈值","notes":"正式任务表接入后替换当前页面记录。"},{"name":"客户沉睡预警","scope":"按登录、项目更新和资源流水综合判断客户是否沉睡。","formula":"沉睡客户 = 连续 N 天无登录、无项目更新、无资源流水。","owner":"客服主管","editable":"可调整沉睡天数","notes":"默认 N=30 天。"},{"name":"SLA 与业务待办预警","scope":"覆盖入驻审核、工单处理和发票开具的待办超时。","formula":"超时时长 = 当前时间 - 待办创建时间；超过配置小时/天数触发。","owner":"运营一组 / 财务值班 / 客服主管","editable":"可调整审核、开票和工单阈值","notes":"用于把分散待办收口到统一预警表。"}]}',
       updated_at = CURRENT_TIMESTAMP
 WHERE page_key = 'warnings';
