-- =============================================
-- 安全评价业务库初始建表脚本
-- 数据库：safety_eval_db
-- 字符集：utf8mb4，排序规则：utf8mb4_0900_ai_ci
-- =============================================

CREATE DATABASE IF NOT EXISTS `safety_eval_db`
    CHARACTER SET utf8mb4
    COLLATE utf8mb4_0900_ai_ci;

USE `safety_eval_db`;

-- =============================================
-- 评价机构主档案
-- =============================================
CREATE TABLE IF NOT EXISTS `se_institution` (
    `id` bigint NOT NULL AUTO_INCREMENT COMMENT '主键ID',
    `name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '机构名称',
    `credit_code` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '统一社会信用代码',
    `legal_person_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '法人姓名',
    `contact_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系人姓名',
    `contact_phone` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '联系电话',
    `status` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NOT NULL COMMENT '入驻状态(PENDING/APPROVED/REJECTED)',
    -- GBS默认字段
    `delete_enum` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT 'false' COMMENT '删除标识true/false',
    `remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '备注',
    `create_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '创建人姓名',
    `update_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '更新人姓名',
    `tenant_id` bigint DEFAULT NULL COMMENT '租户id',
    `org_id` bigint DEFAULT NULL COMMENT '单位id',
    `version` int DEFAULT NULL COMMENT '版本',
    `create_time` datetime DEFAULT NULL COMMENT '创建时间',
    `update_time` datetime DEFAULT NULL COMMENT '修改时间',
    `create_id` bigint DEFAULT NULL COMMENT '创建人id',
    `update_id` bigint DEFAULT NULL COMMENT '更新人id',
    `env` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci DEFAULT NULL COMMENT '环境',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_credit_code` (`credit_code`, `delete_enum`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='评价机构主档案';