-- =====================================================
-- 修改数据库字段排序规则脚本
-- 从 utf8mb4_unicode_ci 改为 utf8mb4_general_ci
-- 目标表：3 个表，45 个字段
-- 执行时间：2026-02-28
-- =====================================================

USE
ccdi;

-- =====================================================
-- 1. 修改 ccdi_base_staff 表（5 个字段）
-- =====================================================
ALTER TABLE ccdi_base_staff MODIFY COLUMN name varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '姓名';
ALTER TABLE ccdi_base_staff MODIFY COLUMN phone varchar (11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '电话';
ALTER TABLE ccdi_base_staff MODIFY COLUMN status char (1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '状态（0在职 1离职）';
ALTER TABLE ccdi_base_staff MODIFY COLUMN create_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建者';
ALTER TABLE ccdi_base_staff MODIFY COLUMN update_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新者';

-- =====================================================
-- 2. 修改 ccdi_biz_intermediary 表（20 个字段）
-- =====================================================
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN biz_id varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '人员ID';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN person_type varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '人员类型';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN person_sub_type varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '人员子类型';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN name varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '姓名';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN gender char (1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '性别';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN id_type varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '身份证' COMMENT '证件类型';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN person_id varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '证件号码';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN mobile varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '手机号码';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN wechat_no varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '微信号';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN contact_address varchar (200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '联系地址';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN company varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '所在公司';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN social_credit_code varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '企业统一信用码';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN position varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '职位';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN related_num_id varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '关联人员ID';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN relation_type varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '关联关系';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN data_source varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'MANUAL' COMMENT '数据来源';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN remark varchar (500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注信息';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN created_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '记录创建人';
ALTER TABLE ccdi_biz_intermediary MODIFY COLUMN updated_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '记录更新人';

-- =====================================================
-- 3. 修改 ccdi_enterprise_base_info 表（20 个字段）
-- =====================================================
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN social_credit_code varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '统一社会信用代码';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN enterprise_name varchar (200) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '企业名称';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN enterprise_type varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '企业类型';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN enterprise_nature varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '企业性质';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN industry_class varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '行业分类';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN industry_name varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '所属行业';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN register_address varchar (500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '注册地址';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN legal_representative varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '法定代表人';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN legal_cert_type varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '法定代表人证件类型';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN legal_cert_no varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '法定代表人证件号码';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN shareholder1 varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '股东1';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN shareholder2 varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '股东2';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN shareholder3 varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '股东3';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN shareholder4 varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '股东4';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN shareholder5 varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '股东5';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN status varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '经营状态';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN risk_level varchar (1) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '3' COMMENT '风险等级：1-高风险, 2-中风险, 3-低风险';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN ent_source varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'GENERAL' COMMENT '企业来源：GENERAL-一般企业, EMP_RELATION-员工关系人, CREDIT_CUSTOMER-信贷客户, INTERMEDIARY-中介, BOTH-兼有';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN data_source varchar (20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'MANUAL' COMMENT '数据来源';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN created_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '创建人';
ALTER TABLE ccdi_enterprise_base_info MODIFY COLUMN updated_by varchar (64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '更新人';

-- =====================================================
-- 验证修改结果
-- =====================================================
SELECT COUNT(*) as remaining_unicode_ci_columns
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA = 'ccdi'
  AND COLLATION_NAME = 'utf8mb4_unicode_ci';

-- 应该返回 0
