-- =====================================================
-- 质检参数项自动判断功能 SQL 变更脚本
-- 执行时间：2026-06-22
-- 功能说明：
--   1. 检测标准参数表增加判断类型、是否必要判断、范围上下限字段
--   2. 检验记录参数表增加相应字段
--   3. 质检主表增加自动判断结果字段
-- =====================================================

-- 1. 检测标准参数表增加判断类型、是否必要判断、范围上下限
ALTER TABLE quality_test_standard_param
ADD COLUMN judge_type VARCHAR(20) DEFAULT NULL COMMENT '判断类型：大于等于/小于等于/范围/文字描述' AFTER default_value;

ALTER TABLE quality_test_standard_param
ADD COLUMN is_required TINYINT(1) DEFAULT 0 COMMENT '是否必要判断：0-否，1-是' AFTER judge_type;

ALTER TABLE quality_test_standard_param
ADD COLUMN min_value DECIMAL(20,4) DEFAULT NULL COMMENT '范围下限值（范围类型使用）' AFTER is_required;

ALTER TABLE quality_test_standard_param
ADD COLUMN max_value DECIMAL(20,4) DEFAULT NULL COMMENT '范围上限值（范围类型使用）' AFTER min_value;

-- 2. 检验记录参数表增加相应字段
ALTER TABLE quality_inspect_param
ADD COLUMN judge_type VARCHAR(20) DEFAULT NULL COMMENT '判断类型' AFTER test_value;

ALTER TABLE quality_inspect_param
ADD COLUMN is_required TINYINT(1) DEFAULT 0 COMMENT '是否必要判断' AFTER judge_type;

ALTER TABLE quality_inspect_param
ADD COLUMN is_qualified TINYINT(1) DEFAULT NULL COMMENT '单项是否合格：0-不合格，1-合格，null-未判断' AFTER is_required;

ALTER TABLE quality_inspect_param
ADD COLUMN min_value DECIMAL(20,4) DEFAULT NULL COMMENT '范围下限值' AFTER is_qualified;

ALTER TABLE quality_inspect_param
ADD COLUMN max_value DECIMAL(20,4) DEFAULT NULL COMMENT '范围上限值' AFTER min_value;

-- 3. 质检主表增加自动判断结果
ALTER TABLE quality_inspect
ADD COLUMN auto_judge_result VARCHAR(20) DEFAULT NULL COMMENT '自动判断结果：合格/不合格/null(需手动判断)' AFTER sample_quantity;

-- =====================================================
-- 回滚脚本（如需回滚，请执行以下语句）
-- =====================================================
-- ALTER TABLE quality_test_standard_param DROP COLUMN judge_type;
-- ALTER TABLE quality_test_standard_param DROP COLUMN is_required;
-- ALTER TABLE quality_test_standard_param DROP COLUMN min_value;
-- ALTER TABLE quality_test_standard_param DROP COLUMN max_value;
-- ALTER TABLE quality_inspect_param DROP COLUMN judge_type;
-- ALTER TABLE quality_inspect_param DROP COLUMN is_required;
-- ALTER TABLE quality_inspect_param DROP COLUMN is_qualified;
-- ALTER TABLE quality_inspect_param DROP COLUMN min_value;
-- ALTER TABLE quality_inspect_param DROP COLUMN max_value;
-- ALTER TABLE quality_inspect DROP COLUMN auto_judge_result;
