-- 自动分配日志：支持回退（撤回已自动分配的医助至上一任/一中心原医助）
-- 表：zyt_tcm_diagnosis_auto_assign_log
-- 接口权限：stats.autoAssignLog/rollback

ALTER TABLE `zyt_tcm_diagnosis_auto_assign_log`
  ADD COLUMN `rollback_time` int unsigned NOT NULL DEFAULT 0 COMMENT '回退时间戳，0=未回退' AFTER `create_time`,
  ADD COLUMN `rollback_admin_id` int unsigned NOT NULL DEFAULT 0 COMMENT '回退操作人管理员ID' AFTER `rollback_time`,
  ADD COLUMN `rollback_admin_name` varchar(64) NOT NULL DEFAULT '' COMMENT '回退操作人姓名' AFTER `rollback_admin_id`;

SET @menu_id = (SELECT id FROM zyt_system_menu WHERE perms = 'stats.autoAssignLog/lists' LIMIT 1);

INSERT INTO `zyt_system_menu`
    (`pid`, `type`, `name`, `icon`, `sort`, `perms`, `paths`, `component`, `selected`, `params`, `is_show`, `is_disable`, `create_time`, `update_time`)
SELECT
    @menu_id, 'A', '回退自动分配', '', 1,
    'stats.autoAssignLog/rollback', '', '',
    '', '', 1, 0, UNIX_TIMESTAMP(), UNIX_TIMESTAMP()
FROM DUAL
WHERE @menu_id IS NOT NULL
  AND NOT EXISTS (SELECT 1 FROM zyt_system_menu WHERE perms = 'stats.autoAssignLog/rollback');
