-- 企业微信用户ID同步定时任务
-- 该任务每天凌晨2点执行一次，同步OA系统中的企业微信用户ID到本地系统

-- 删除已存在的同名任务
DELETE FROM QRTZ_JOB_DETAILS WHERE sched_name = 'RuoyiScheduler' AND job_name = 'qyWechatUserSyncTask' AND job_group = 'DEFAULT';
DELETE FROM QRTZ_TRIGGERS WHERE sched_name = 'RuoyiScheduler' AND trigger_name = 'qyWechatUserSyncTask' AND trigger_group = 'DEFAULT';
DELETE FROM QRTZ_CRON_TRIGGERS WHERE sched_name = 'RuoyiScheduler' AND trigger_name = 'qyWechatUserSyncTask' AND trigger_group = 'DEFAULT';

-- 插入任务详细信息
INSERT INTO QRTZ_JOB_DETAILS (
    sched_name,
    job_name,
    job_group,
    description,
    job_class_name,
    is_durable,
    is_nonconcurrent,
    is_update_data,
    requests_recovery,
    job_data
) VALUES (
    'RuoyiScheduler',
    'qyWechatUserSyncTask',
    'DEFAULT',
    '企业微信用户ID同步任务',
    'com.ruoyi.quartz.task.QyWechatUserSyncTask',
    '1',
    '0',
    '0',
    '0',
    ''
);

-- 插入触发器信息
INSERT INTO QRTZ_TRIGGERS (
    sched_name,
    trigger_name,
    trigger_group,
    job_name,
    job_group,
    description,
    next_fire_time,
    prev_fire_time,
    priority,
    trigger_state,
    trigger_type,
    start_time,
    end_time,
    calendar_name,
    misfire_instr,
    job_data
) VALUES (
    'RuoyiScheduler',
    'qyWechatUserSyncTask',
    'DEFAULT',
    'qyWechatUserSyncTask',
    'DEFAULT',
    '企业微信用户ID同步任务触发器',
    0,
    0,
    5,
    'WAITING',
    'CRON',
    1702281600000,
    0,
    '',
    0,
    ''
);

-- 插入Cron触发器信息（每天凌晨2点执行）
INSERT INTO QRTZ_CRON_TRIGGERS (
    sched_name,
    trigger_name,
    trigger_group,
    cron_expression,
    time_zone_id
) VALUES (
    'RuoyiScheduler',
    'qyWechatUserSyncTask',
    'DEFAULT',
    '0 0 2 * * ?',
    'Asia/Shanghai'
);

COMMIT;