-- 分拣员自动分配规则:按分类 / 按客户 CREATE TABLE IF NOT EXISTS picking_assign_rules ( id UUID PRIMARY KEY DEFAULT gen_random_uuid(), branch_code TEXT NOT NULL, rule_type TEXT NOT NULL CHECK (rule_type IN ('category', 'customer')), scope_key TEXT NOT NULL, picker_id UUID NOT NULL REFERENCES profiles(id) ON DELETE CASCADE, is_active BOOLEAN NOT NULL DEFAULT true, created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), UNIQUE (branch_code, rule_type, scope_key) ); CREATE INDEX IF NOT EXISTS idx_picking_assign_rules_branch ON picking_assign_rules (branch_code, rule_type, is_active); COMMENT ON TABLE picking_assign_rules IS '分拣员自动分配:分公司 + 分类/客户 → 默认分拣员';