DROP TABLE IF EXISTS `yfsjglpt_model_approval_flow`;

CREATE TABLE `yfsjglpt_model_approval_flow`
(
    `id`                varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `template_id`       varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '关联模板ID',
    `current_node`      varchar(20) COLLATE utf8mb4_general_ci          DEFAULT NULL COMMENT '当前节点(PROOFREAD, REVIEW, COUNTERSIGN, APPROVE)',
    `flow_status`       varchar(20) COLLATE utf8mb4_general_ci NOT NULL COMMENT '流程状态',
    `proofread_users`   text COLLATE utf8mb4_general_ci        NOT NULL COMMENT '校对人员',
    `review_users`      text COLLATE utf8mb4_general_ci        NOT NULL COMMENT '审核人员',
    `countersign_users` text COLLATE utf8mb4_general_ci COMMENT '会签人员(可选)',
    `approve_users`     text COLLATE utf8mb4_general_ci        NOT NULL COMMENT '批准人员',
    `create_by`         varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `created_time`      timestamp                              NULL     DEFAULT CURRENT_TIMESTAMP,
    `flow_type`         int(11)                                NOT NULL DEFAULT '1' COMMENT '流程类型:1模板审批流程,2对标审批流程',
    `explanation`       varchar(255) COLLATE utf8mb4_general_ci         DEFAULT NULL,
    `return_num` int(11) DEFAULT 0 COMMENT '退回次数',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT '流程表';


DROP TABLE IF EXISTS `yfsjglpt_model_approval_record`;

CREATE TABLE `yfsjglpt_model_approval_record`
(
    `id`            varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `flow_id`       varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `node`          varchar(20) COLLATE utf8mb4_general_ci NOT NULL,
    `user_id`       varchar(64) COLLATE utf8mb4_general_ci NOT NULL COMMENT '处理人',
    `opinion`       varchar(255) COLLATE utf8mb4_general_ci     DEFAULT NULL COMMENT '审批意见',
    `result`        varchar(10) COLLATE utf8mb4_general_ci NOT NULL COMMENT '结果(PASS, REJECT)',
    `approval_time` timestamp                              NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT '流程节点表';


DROP TABLE IF EXISTS `yfsjglpt_model_benchmarking_report`;

CREATE TABLE `yfsjglpt_model_benchmarking_report`
(
    `id`                        varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `title`                     varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '标题名称',
    `manufacturer_name`         varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '厂家名称（全称）',
    `model_name`                varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品型号（全称）',
    `module`                    varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '领域/模块',
    `manufacturer_abbreviation` varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '厂家简称',
    `model_abbreviation`        varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品型号简称',
    `product_number`            varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '产品编号',
    `plate`                     varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '板块',
    `platform`                  varchar(100) COLLATE utf8mb4_general_ci      DEFAULT NULL COMMENT '平台',
    `series`                    varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '系列',
    `market_segment`            varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '细分市场',
    `project_name`              varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '项目名称',
    `project_number`            varchar(100) COLLATE utf8mb4_general_ci      DEFAULT NULL COMMENT '项目编号',
    `upload_time`               timestamp                               NULL DEFAULT CURRENT_TIMESTAMP COMMENT '上传时间',
    `create_by`                 varchar(64) COLLATE utf8mb4_general_ci  NOT NULL COMMENT '上传人',
    `file_path`                 varchar(500) COLLATE utf8mb4_general_ci      DEFAULT NULL COMMENT '文件地址',
    `status`                    varchar(20) COLLATE utf8mb4_general_ci       DEFAULT 'DRAFT' COMMENT '状态 DRAFT(草稿)、APPROVING（审批中）、COMPLETE(已完成)、RETURNED(已撤回)、REJECTED(已拒绝)',
    `is_delete` int(11) DEFAULT 0 COMMENT '删除标志',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='对标报告表';


DROP TABLE IF EXISTS `yfsjglpt_model_parameter`;

CREATE TABLE `yfsjglpt_model_parameter`
(
    `id`                varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `parameter_number`  int(11)                                 DEFAULT NULL COMMENT '序号',
    `subsystem_name`    varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '子系统',
    `parameter_type`    varchar(30) COLLATE utf8mb4_general_ci  DEFAULT NULL COMMENT '类型',
    `parts_name`        varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '零部件名称',
    `parameter_name`    varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '参数名称',
    `unit`              varchar(10) COLLATE utf8mb4_general_ci  DEFAULT NULL COMMENT '单位',
    `parameter_source`  varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '参数计划来源',
    `number_or_formula` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '当前可适用的分类属性表编号（需要修订）或公式',
    `department`        varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '填写部门',
    `remarks`           varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '备注',
    `created_by`        varchar(100) COLLATE utf8mb4_general_ci NOT NULL COMMENT '创建者',
    PRIMARY KEY (`id`),
    KEY `idx_subsystem_name` (`subsystem_name`),
    KEY `idx_type` (`parameter_type`),
    KEY `idx_parts_name` (`parts_name`),
    KEY `idx_parameter_name` (`parameter_name`),
    KEY `idx_department` (`department`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='参数表';


DROP TABLE IF EXISTS `yfsjglpt_model_parameter_and_template`;

CREATE TABLE `yfsjglpt_model_parameter_and_template`
(
    `id`           varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `parameter_id` varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    `template_id`  varchar(64) COLLATE utf8mb4_general_ci NOT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_template_parameter` (`template_id`, `parameter_id`),
    KEY `idx_parameter_id` (`parameter_id`),
    KEY `idx_template_id` (`template_id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='模板参数关联表';

DROP TABLE IF EXISTS `yfsjglpt_model_template`;

CREATE TABLE `yfsjglpt_model_template`
(
    `id`             varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `template_name`  varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
    `version`        int(11)                                 NOT NULL DEFAULT '1',
    `status`         varchar(20) COLLATE utf8mb4_general_ci  NOT NULL DEFAULT '草稿' COMMENT '草稿, 已发布, 审核中',
    `created_time`   timestamp                               NULL     DEFAULT CURRENT_TIMESTAMP,
    `published_time` timestamp                               NULL     DEFAULT NULL,
    `order_num`      int                                     NOT NULL DEFAULT '1',
    `create_by`      varchar(10) COLLATE utf8mb4_general_ci  NOT NULL,
    `return_num` int(11) DEFAULT 0 COMMENT '退回次数',
    PRIMARY KEY (`id`),
    UNIQUE KEY `uk_template_version` (`template_name`, `version`),
    KEY `idx_template_name` (`template_name`),
    KEY `idx_status` (`status`),
    KEY `idx_created_time` (`created_time`),
    KEY `idx_create_by` (`create_by`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='模板表';



DROP TABLE IF EXISTS `yfsjglpt_model_revision_record`;

CREATE TABLE `yfsjglpt_model_revision_record`
(
    `id`               varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `template_name`    varchar(100) COLLATE utf8mb4_general_ci NOT NULL,
    `version`          varchar(10) COLLATE utf8mb4_general_ci  NOT NULL DEFAULT '1',
    `parameter_number` int(11)                                          DEFAULT NULL COMMENT '序号',
    `modify_details`   text COLLATE utf8mb4_general_ci,
    `template_id`      varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `pre_template_id`  varchar(64) COLLATE utf8mb4_general_ci           DEFAULT NULL,
    `create_time`      timestamp                               NULL     DEFAULT CURRENT_TIMESTAMP,
    `parameter_id`     varchar(64) COLLATE utf8mb4_general_ci  NOT NULL,
    `return_num` int(11) DEFAULT 0 COMMENT '退回次数',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='变更记录表';



DROP TABLE IF EXISTS `yfsjglpt_model_responsible_person`;
CREATE TABLE `yfsjglpt_model_responsible_person`
(
    `id`            varchar(50) COLLATE utf8mb4_general_ci                        NOT NULL COMMENT 'ID',
    `department_id` varchar(128) COLLATE utf8mb4_general_ci                       NOT NULL COMMENT '填写部门id',
    `user_id`       varchar(50) COLLATE utf8mb4_general_ci                        NOT NULL COMMENT '责任人id',
    `department`    varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '部门名',
    `subsystem`     varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '子系统',
    `parts_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '零部件名称',
    `person_level`  int(11)                                                       NOT NULL DEFAULT '1' COMMENT '1：责任人；2：填写人',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='责任人表';

DROP TABLE IF EXISTS yfsjglpt_common_parameter;
CREATE TABLE yfsjglpt_common_parameter
(
    `id`          varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID',
    `common_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用名称',
    `common_type` int COLLATE utf8mb4_general_ci                               NOT NULL COMMENT '常用类型',
    `create_by`   varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '用户ID',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='常用参数表';

DROP TABLE IF EXISTS yfsjglpt_model_common_parameters;
-- 新增机型参数常用参数表
CREATE TABLE yfsjglpt_model_common_parameters
(
    `id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID',
    `parameter_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '参数ID',
    `common_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用id',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='机型参数常用参数表';

DROP TABLE IF EXISTS yfsjglpt_analysis_common_parameters;
-- 新增分析常用参数表
CREATE TABLE yfsjglpt_analysis_common_parameters
(
    `id`               varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT 'ID',
    `model_name`       varchar(100) COLLATE utf8mb4_general_ci                      NOT NULL COMMENT '产品型号',
    `plate`            varchar(100) COLLATE utf8mb4_general_ci                      NOT NULL COMMENT '板块',
    `platform`         varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '平台',
    `series`           varchar(100) COLLATE utf8mb4_general_ci                      NOT NULL COMMENT '系列',
    `project_name`     varchar(100) COLLATE utf8mb4_general_ci                      NOT NULL COMMENT '项目名称',
    `project_number`   varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '项目编号',
    `emission`         bigint COLLATE utf8mb4_general_ci       DEFAULT NULL COMMENT '排放',
    `displacement_min` bigint COLLATE utf8mb4_general_ci       DEFAULT NULL COMMENT '排放下限',
    `displacement_max` bigint COLLATE utf8mb4_general_ci       DEFAULT NULL COMMENT '排放上限',
    `combustion_type`  varchar(100) COLLATE utf8mb4_general_ci DEFAULT NULL COMMENT '燃烧类型',
    `common_id`        varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '常用id',
    PRIMARY KEY (`id`)
) ENGINE = InnoDB
  DEFAULT CHARSET = utf8mb4
  COLLATE = utf8mb4_general_ci COMMENT ='统计分析常用参数表';


-- 角色表
DROP TABLE IF EXISTS yfsjglpt_model_roles;
CREATE TABLE yfsjglpt_model_roles
(
    `id`            VARCHAR(64)  NOT NULL COMMENT 'ID',
    `role_name`     VARCHAR(128) NOT NULL COMMENT '角色名称',
    `role_code`     VARCHAR(128) COMMENT '角色代号',
    `role_description` VARCHAR(128) COMMENT '角色描述',
    `is_enabled`    INT(128) DEFAULT 1 COMMENT '是否启用',
    `created_by`    VARCHAR(64) COMMENT '创建人',
    `creation_date` DATETIME COMMENT '创建时间',
    `last_updated_by` VARCHAR(64) COMMENT '最后更新人',
    `last_update_date` DATETIME COMMENT '最后更新时间',
    PRIMARY KEY (`id`)
) COMMENT '角色表';

-- 菜单权限

DROP TABLE IF EXISTS yfsjglpt_model_menu_dictionary;
CREATE TABLE yfsjglpt_model_menu_dictionary
(
    `id`            VARCHAR(64) NOT NULL COMMENT 'ID',
    `parent_id`     VARCHAR(64) COMMENT '上级ID',
    `menu_name`     VARCHAR(64) COMMENT '菜单名称',
    `menu_code`     VARCHAR(64) COMMENT '菜单代码',
    `menu_desc`     VARCHAR(128) COMMENT '菜单描述',
    `is_enable`     INT DEFAULT 1 COMMENT '是否可用',
    `created_by`    VARCHAR(64) COMMENT '创建人',
    `creation_date` DATETIME COMMENT '创建时间',
    `last_updated_by` VARCHAR(64) COMMENT '最后更新人',
    `last_update_date` DATETIME COMMENT '最后更新时间',
    PRIMARY KEY (`id`)
) COMMENT '菜单字典表';


-- 菜单参数关联表(权限路径表)
DROP TABLE IF EXISTS yfsjglpt_model_menu_parameter;
CREATE TABLE yfsjglpt_model_menu_parameter
(
    `id`            VARCHAR(64) NOT NULL COMMENT 'ID',
    `menu_id`       VARCHAR(128) COMMENT '菜单ID',
    `subsystem`     VARCHAR(64) COMMENT '子系统',
    `parameter_id`  VARCHAR(64) COMMENT '参数ID',
    `parameter_per` INT COMMENT '参数权限;1：查看；2：编辑',
    `created_by`    VARCHAR(64) COMMENT '创建人',
    `creation_date` DATETIME COMMENT '创建时间',
    `last_updated_by` VARCHAR(64) COMMENT '最后更新人',
    `last_update_date` DATETIME COMMENT '最后更新时间',
    PRIMARY KEY (`id`)
) COMMENT '菜单参数关联表(权限路径表)';

-- 部门或用户关联角色表
DROP TABLE IF EXISTS yfsjglpt_model_dep_user_role;
CREATE TABLE yfsjglpt_model_dep_user_role
(
    `id`            VARCHAR(64) NOT NULL COMMENT 'ID',
    `user_or_dep`   VARCHAR(64) COMMENT '用户或部门ID',
    `role_id`       VARCHAR(64) COMMENT '角色ID',
    `is_dep`        INT COMMENT '是否是部门;0：个人；1：部门',
    `is_enable`     INT COMMENT '是否启用;0：未启用；1：启用',
    `created_by`    VARCHAR(64) COMMENT '创建人',
    `creation_date` DATETIME COMMENT '创建时间',
    `last_updated_by` VARCHAR(64) COMMENT '最后更新人',
    `last_update_date` DATETIME COMMENT '最后更新时间',
    PRIMARY KEY (`id`)
) COMMENT '部门或用户关联角色表';


-- 角色权限关联表
DROP TABLE IF EXISTS yc_datasource_0.yfsjglpt_model_role_permission;
CREATE TABLE yc_datasource_0.yfsjglpt_model_role_permission
(
    `id`            VARCHAR(64) NOT NULL COMMENT 'ID',
    `role_id`       VARCHAR(64) COMMENT '角色ID',
    `per_id`        VARCHAR(64) COMMENT '权限路径ID',
    `is_enable`     INT DEFAULT 1 COMMENT '是否启用;0：未启用；1：启用',
    `created_by`    VARCHAR(64) COMMENT '创建人',
    `creation_date` DATETIME COMMENT '创建时间',
    `last_updated_by` VARCHAR(64) COMMENT '最后更新人',
    `last_update_date` DATETIME COMMENT '最后更新时间',
    PRIMARY KEY (`id`)
) COMMENT '角色权限关联表';

DELETE
FROM yfsjglpt_model_template;
DELETE
FROM yfsjglpt_model_parameter_and_template;
DELETE
FROM yfsjglpt_model_parameter;
DELETE
FROM yfsjglpt_model_revision_record;
DELETE
FROM yfsjglpt_model_benchmarking_report;

DELETE
FROM yfsjglpt_model_approval_flow;
DELETE
FROM yfsjglpt_model_approval_record;

DELETE
FROM yfsjglpt_model_responsible_person;



delete
from data_entry_engine_model;
delete
from engine_param_detail;
delete
from todo_task;
delete
from data_change_comment;
delete
from approval_config;
delete
from engine_review_list;
delete
from param_approval_record;