
CREATE TABLE IF NOT EXISTS `data_indicator_constant` (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `indicator_id` bigint(20) DEFAULT NULL,
  `server_code` varchar(64) DEFAULT NULL,
  `constant_key` varchar(32) DEFAULT NULL COMMENT '监测指标常量key',
  `create_at` bigint(20) DEFAULT NULL,
  `update_at` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `data_indicator_output_formula` (
    `id` bigint(20) NOT NULL COMMENT 'id',
    `indicator_id` bigint(20) DEFAULT NULL,
    `server_code` varchar(64) DEFAULT NULL,
    `formula_type` varchar(32) DEFAULT NULL COMMENT '公式类型：raw原始值,aviator动态公式,fixed固定公式',
    `method_annotation` varchar(32) DEFAULT NULL COMMENT '方法标注：hourly_sum小时累积,daily_sum日累积,monthly_sum月累积,annually_sum年累积,hourly_average小时平均,daily_average日平均,monthly_average月平均,annually_average年平均',
    `formula_content` text COMMENT '公式内容',
    `output_indicator` varchar(32) DEFAULT NULL COMMENT '输出指标要素',
    `element_precision` int(11) DEFAULT '4' COMMENT '精度',
    `remark` varchar(32) DEFAULT NULL COMMENT '字段备注',
    `create_at` bigint(20) DEFAULT NULL,
    `update_at` bigint(20) DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `data_alarm_summary` (
    `id` bigint(20) unsigned NOT NULL,
    `ts` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    `alarm_end_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    `new_ts` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    `release_time` timestamp NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP,
    `alarm_key` varchar(32) DEFAULT NULL,
    `alarm_value` varchar(32) DEFAULT NULL,
    `alarm_name` varchar(64) DEFAULT NULL,
    `alarm_type` tinyint(4) DEFAULT NULL,
    `status` tinyint(4) DEFAULT NULL,
    `flow_status` tinyint(4) DEFAULT '0' COMMENT '流转状态,1:已流转;0:未流转',
    `level` tinyint(4) DEFAULT NULL,
    `device_id` bigint(20) DEFAULT NULL,
    `monitor_point_id` bigint(20) DEFAULT NULL,
    `monitor_point_name` varchar(64) DEFAULT NULL,
    `alarm_rule` varchar(64) DEFAULT NULL,
    `push_condition_id` bigint(20) DEFAULT NULL,
    `monitor_tags_name` varchar(64) DEFAULT NULL,
    `indicator_id` bigint(20) DEFAULT NULL,
    `application_id` bigint(20) DEFAULT NULL,
    `tenant_id` bigint(20) DEFAULT NULL,
    `last_one` int(11) DEFAULT '1',
    `create_at` bigint(20) DEFAULT NULL,
    `update_at` bigint(20) DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `data_indicator_output_formula_rel` (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `sever_formula_id` bigint(20) DEFAULT NULL,
  `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id',
  `application_id` bigint(20) DEFAULT NULL COMMENT '应用id',
  `create_at` bigint(20) DEFAULT NULL,
  `update_at` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `data_indicator_point` (
  `id` bigint(20) unsigned NOT NULL COMMENT 'id',
  `server_code` varchar(40) DEFAULT NULL COMMENT '服务编码',
  `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id',
  `application_id` bigint(20) DEFAULT NULL COMMENT '应用id',
  `indicator_id` bigint(20) DEFAULT NULL COMMENT '监测指标id',
  `device_id` bigint(20) DEFAULT NULL COMMENT '设备id',
  `template_id` bigint(20) DEFAULT NULL COMMENT '模板id',
  `monitor_point_id` bigint(20) DEFAULT NULL COMMENT '测点id',
  `monitor_point_name` varchar(40) DEFAULT NULL COMMENT '测点名称',
  `base_point` tinyint(1) unsigned DEFAULT '0' COMMENT '是否为基站点0否1是 默认是，数据不做处理',
  `base_id` bigint(20) DEFAULT NULL COMMENT '基站点ID 不为基站点时才有',
  `monitor_tags_name` varchar(40) DEFAULT NULL COMMENT '水库名称 结构名称',
  `init_json` text COMMENT '初始化参数,json格式',
  `create_at` bigint(20) DEFAULT NULL,
  `update_at` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备的模板以及监测指标之间标识的关系';

CREATE TABLE IF NOT EXISTS `data_indicator_point_device_rel` (
  `id` bigint(20) unsigned NOT NULL COMMENT 'id',
  `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id',
  `application_id` bigint(20) DEFAULT NULL COMMENT '应用id',
  `template_field` varchar(20) DEFAULT NULL COMMENT '模板字段',
  `monitor_field` varchar(20) DEFAULT NULL COMMENT '监测指标对应的要素',
  `monitor_point_id` bigint(20) DEFAULT NULL COMMENT '测点id',
  `create_at` bigint(20) DEFAULT NULL,
  `update_at` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `INDEX_UK_MONITORID_FIELD` (`monitor_field`,`monitor_point_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备的模板以及监测指标之间标识的关系';

CREATE TABLE IF NOT EXISTS `data_indicator_point_tag_rel` (
    `id` bigint(20) unsigned NOT NULL COMMENT 'id',
    `tenant_id` bigint(20) DEFAULT NULL COMMENT '租户id',
    `application_id` bigint(20) DEFAULT NULL COMMENT '应用id',
    `tag_key` varchar(20) DEFAULT NULL COMMENT '标签key',
    `tag_value` varchar(20) DEFAULT NULL COMMENT '标签值',
    `monitor_point_id` bigint(20) DEFAULT NULL COMMENT '测点id',
    `create_at` bigint(20) DEFAULT NULL,
    `update_at` bigint(20) DEFAULT NULL,
    PRIMARY KEY (`id`),
    UNIQUE KEY `INDEX_UK_MONITORID_FIELD` (`tag_value`,`monitor_point_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='设备的模板以及监测指标之间标识的关系';
