SET NAMES utf8mb4;
SET
FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for country
-- ----------------------------
DROP TABLE IF EXISTS `country`;
CREATE TABLE `country`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '国家名称',
    `turn`  int(11) DEFAULT 0 COMMENT '排序',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;



-- ----------------------------
-- Table structure for province
-- ----------------------------
DROP TABLE IF EXISTS `province`;
CREATE TABLE `province`
(
    `id`         bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '省份名称',
    `country_id` bigint(20) NULL DEFAULT NULL COMMENT '国家id',
    `turn`       int(11) DEFAULT 0 COMMENT '排序',
    `color`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for city
-- ----------------------------
DROP TABLE IF EXISTS `city`;
CREATE TABLE `city`
(
    `id`          bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '城市名称',
    `province_id` bigint(20) NULL DEFAULT NULL COMMENT '省id',
    `turn`        int(11) DEFAULT 0 COMMENT '排序',
    `color`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for region
-- ----------------------------
DROP TABLE IF EXISTS `region`;
CREATE TABLE `region`
(
    `id`      bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '区域名称',
    `city_id` bigint(20) NULL DEFAULT NULL COMMENT '市id',
    `turn`    int(11) DEFAULT 0 COMMENT '排序',
    `color`   varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for contacts
-- ----------------------------
DROP TABLE IF EXISTS `contact`;
CREATE TABLE `contact`
(
    `id`          bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci not Null COMMENT '联系人名称',
    `number`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci not Null COMMENT '联系人编号',
    `client_id`   bigint(20) NULL DEFAULT NULL COMMENT '客户id',
    `position`    varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '职位',
    `phone`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机',
    `member_id`   bigint(20) not Null COMMENT '负责人id',
    `is_first`    tinyint(1) NULL DEFAULT NULL COMMENT '是否首要联系人',
    `wechat`      varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '微信',
    `birthday`    datetime(0) NULL DEFAULT NULL COMMENT '生日',
    `email`       varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '邮箱',
    `desc`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
    `file`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '附件',
    `country_id`  bigint(20) NULL DEFAULT NULL COMMENT '国家id',
    `province_id` bigint(20) NULL DEFAULT NULL COMMENT '省id',
    `city_id`     bigint(20) NULL DEFAULT NULL COMMENT '市id',
    `region_id`   bigint(20) NULL DEFAULT NULL COMMENT '区域id',
    `created_at`  datetime(3) NULL DEFAULT NULL,
    `updated_at`  datetime(3) NULL DEFAULT NULL,
    `deleted_at`  datetime(3) NULL DEFAULT NULL,

    PRIMARY KEY (`id`) USING BTREE,
    INDEX         `idx_contacts_deleted_at`(`deleted_at`) USING BTREE,
    INDEX         `idx_contacts_client_id`(`client_id`) USING BTREE,
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;


-- ----------------------------
-- Table structure for client
-- ----------------------------
DROP TABLE IF EXISTS `client`;
CREATE TABLE `client`
(
    `id`                    bigint(20) NOT NULL AUTO_INCREMENT,
    `name`                  varchar(255) CHARACTER UNIQUE SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '客户名称',
    `number`                varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '客户编号',
    `client_status_id`      int(11) NULL DEFAULT NULL COMMENT '客户状态ID',
    `client_type_id`        int(11) NULL DEFAULT NULL COMMENT '客户类型ID',
    `client_origin_id`      int(11) NULL DEFAULT NULL COMMENT '客户来源ID',
    `client_level_id`       int(11) NULL DEFAULT NULL COMMENT '客户等级ID',
    `member_id`             int(11) NULL DEFAULT NULL COMMENT '销售负责人ID',
    `service_member_id`     int(11) NULL DEFAULT NULL COMMENT '服务负责人ID',
    `detail_address`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '详细地址',
    `remark`                varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
    `next_visit_time`       datetime(0) NULL DEFAULT NULL COMMENT '下次回访时间',
    `latest_service_time`   datetime(0) NULL DEFAULT NULL COMMENT '最晚服务时间',
    `country_id`            bigint(20) NULL DEFAULT NULL,
    `province_id`           bigint(20) NULL DEFAULT NULL,
    `city_id`               bigint(20) NULL DEFAULT NULL,
    `region_id`             bigint(20) NULL DEFAULT NULL,
    `representative`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '法人代表',
    `registration_time`     datetime(0) NULL DEFAULT NULL COMMENT '注册时间',
    `registered_capital_id` int(11) NULL DEFAULT NULL COMMENT '注册资金',
    `industry_id`           int(11) NULL DEFAULT NULL COMMENT '所属行业',
    `enterprise_nature_id`  int(11) NULL DEFAULT NULL COMMENT '企业性质',
    `enterprise_scale_id`   int(11) NULL DEFAULT NULL COMMENT '企业规模',
    `business_scope`        varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '经营范围',
    `created_at`            datetime(3) NULL DEFAULT NULL,
    `updated_at`            datetime(3) NULL DEFAULT NULL,
    `deleted_at`            datetime(3) NULL DEFAULT NULL,
    PRIMARY KEY (`id`) USING BTREE,
    INDEX                   `idx_clients_deleted_at`(`deleted_at`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for client_status
-- ----------------------------
DROP TABLE IF EXISTS `client_status`;
CREATE TABLE `client_status`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '客户状态名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for client_type
-- ----------------------------
DROP TABLE IF EXISTS `client_type`;
CREATE TABLE `client_type`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '客户类型名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for client_origin
-- ----------------------------
DROP TABLE IF EXISTS `client_origin`;
CREATE TABLE `client_origin`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '客户来源名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for client_level
-- ----------------------------
DROP TABLE IF EXISTS `client_level`;
CREATE TABLE `client_level`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '客户级别名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for industry
-- ----------------------------
DROP TABLE IF EXISTS `industry`;
CREATE TABLE `industry`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '行业名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for registered_capital
-- ----------------------------
DROP TABLE IF EXISTS `registered_capital`;
CREATE TABLE `registered_capital`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '注册资金名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for registered_capital
-- ----------------------------
DROP TABLE IF EXISTS `enterprise_nature`;
CREATE TABLE `enterprise_nature`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '企业性质名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for registered_capital
-- ----------------------------
DROP TABLE IF EXISTS `enterprise_scale`;
CREATE TABLE `enterprise_scale`
(
    `id`    bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id',
    `name`  varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL UNIQUE COMMENT '企业规模名称',
    `color` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '颜色',
    PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;
