-- 检查并修复任务类型和状态为NULL的记录
-- 执行时间: 2025-10-26

-- 1. 检查task_type为NULL的记录数量
SELECT COUNT(*) as null_task_type_count 
FROM sys_task 
WHERE task_type IS NULL AND del_flag = '0';

-- 2. 检查task_status为NULL的记录数量
SELECT COUNT(*) as null_task_status_count 
FROM sys_task 
WHERE task_status IS NULL AND del_flag = '0';

-- 3. 查看task_type为NULL的记录详情
SELECT task_id, task_code, task_type, task_status, create_time 
FROM sys_task 
WHERE task_type IS NULL AND del_flag = '0'
ORDER BY create_time DESC
LIMIT 10;

-- 4. 查看task_status为NULL的记录详情
SELECT task_id, task_code, task_type, task_status, create_time 
FROM sys_task 
WHERE task_status IS NULL AND del_flag = '0'
ORDER BY create_time DESC
LIMIT 10;

-- 5. 修复task_type为NULL的记录（设置为OTHER）
UPDATE sys_task 
SET task_type = 'OTHER' 
WHERE task_type IS NULL AND del_flag = '0';

-- 6. 修复task_status为NULL的记录（设置为PENDING）
UPDATE sys_task 
SET task_status = 'PENDING' 
WHERE task_status IS NULL AND del_flag = '0';

-- 7. 验证修复结果
SELECT COUNT(*) as remaining_null_task_type 
FROM sys_task 
WHERE task_type IS NULL AND del_flag = '0';

SELECT COUNT(*) as remaining_null_task_status 
FROM sys_task 
WHERE task_status IS NULL AND del_flag = '0';

-- 8. 添加NOT NULL约束（可选，确保未来不会再出现NULL值）
-- 注意：执行前需要先确保所有记录都已修复
-- ALTER TABLE sys_task MODIFY COLUMN task_type VARCHAR(50) NOT NULL DEFAULT 'OTHER';
-- ALTER TABLE sys_task MODIFY COLUMN task_status VARCHAR(50) NOT NULL DEFAULT 'PENDING';
