/*
 Navicat Premium Data Transfer

 Source Server         : fourfaith
 Source Server Type    : MySQL
 Source Server Version : 50725
 Source Host           : 192.168.9.226:3306
 Source Schema         : fourfaith_application_parent

 Target Server Type    : MySQL
 Target Server Version : 50725
 File Encoding         : 65001

 Date: 08/09/2022 18:13:17
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for data_alarm_push_condition
-- ----------------------------
CREATE TABLE `data_alarm_push_condition`  (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `push_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送内容',
  `level` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '等级',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `push_type` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '推送类型0 短信 1邮箱',
  `contact_info` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系方式 json数组格式，只能存在手机或者邮箱一种',
  `monitor_point_id` bigint(20) NULL DEFAULT NULL COMMENT '测点id 水库用',
  `rule_id` bigint(20) NULL DEFAULT NULL COMMENT '规则id',
  `alarm_status` tinyint(1) UNSIGNED NULL DEFAULT 1 COMMENT '告警状态 1告警状态 0解除告警',
  `push_object` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '推送对象，用于设备管家回显',
  `create_at` bigint(20) NULL DEFAULT NULL COMMENT '创建时间',
  `update_at` bigint(20) NULL DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '需要告警后推送的条件' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_alarm_push_record
-- ----------------------------
CREATE TABLE `data_alarm_push_record`  (
  `id` bigint(20) NOT NULL,
  `push_content` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '推送内容',
  `push_type` tinyint(1) NULL DEFAULT NULL COMMENT '推送类型',
  `status` tinyint(1) NULL DEFAULT NULL COMMENT '推送状态',
  `monitor_indicator` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '监测指标',
  `monitor_point_id` bigint(20) NULL DEFAULT NULL COMMENT '测点id',
  `level` tinyint(1) NULL DEFAULT NULL COMMENT '告警等级',
  `reservoir_id` bigint(20) NULL DEFAULT NULL COMMENT '水库id',
  `alarm_type` tinyint(1) NULL DEFAULT NULL COMMENT '告警类型',
  `push_condition_id` bigint(20) NULL DEFAULT NULL COMMENT '推送条件id',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `alarm_time` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '告警时间',
  `contact_add` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '联系地址',
  `create_at` bigint(20) NULL DEFAULT NULL COMMENT '推送时间',
  `update_at` bigint(20) NULL DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_alarm_rule_rel
-- ----------------------------
CREATE TABLE `data_alarm_rule_rel`  (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `monitor_alarm_id` bigint(255) NULL DEFAULT NULL COMMENT '告警规则 json格式',
  `alarm_type` tinyint(1) UNSIGNED NULL DEFAULT NULL COMMENT '告警类型 0：设备离线；1：设备失联；2：监测指标/测点要素；3：原始要素/设备要素；4：特征值告警；5：设备离线比例',
  `level` tinyint(1) NULL DEFAULT 1 COMMENT '告警等级',
  `alarm_rule` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '具体告警配置',
  `create_at` bigint(20) NULL DEFAULT NULL,
  `update_at` bigint(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_device_alarm_rel
-- ----------------------------
CREATE TABLE `data_device_alarm_rel`  (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `device_id` bigint(20) NULL DEFAULT NULL COMMENT '局部告警的设备id',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `create_at` bigint(20) NULL DEFAULT NULL,
  `update_at` bigint(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '局部告警的设备数据表' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_device_monitor_formula
-- ----------------------------
CREATE TABLE `data_device_monitor_formula`  (
  `id` bigint(20) NOT NULL COMMENT 'id',
  `formula` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '计算公式',
  `indicator` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '计算获取的指标 多个逗号隔开',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `monitor_point_id` bigint(20) NULL DEFAULT NULL COMMENT '测点id',
  `parameter` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '计算参数 多个逗号隔开',
  `tenant_id` bigint(20) NULL DEFAULT NULL COMMENT '租户id',
  `type` tinyint(1) NULL DEFAULT NULL COMMENT '类型 0EL 1外部接口 ',
  `formula_param` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '公式参数json',
  `create_at` bigint(20) NULL DEFAULT NULL,
  `update_at` bigint(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_device_monitor_rel
-- ----------------------------
CREATE TABLE `data_device_monitor_rel`  (
  `id` bigint(20) UNSIGNED NOT NULL COMMENT 'id',
  `server_code` varchar(40) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '服务编码',
  `tenant_id` bigint(20) NULL DEFAULT NULL COMMENT '租户id',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `device_id` bigint(20) NULL DEFAULT NULL COMMENT '设备id',
  `template_id` bigint(20) NULL DEFAULT NULL COMMENT '模板id',
  `template_field` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '模板字段',
  `monitor_indicator` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '监测指标',
  `monitor_field` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '监测指标对应的要素',
  `monitor_point_id` bigint(20) NULL DEFAULT NULL COMMENT '测点id',
  `create_at` bigint(20) NULL DEFAULT NULL,
  `update_at` bigint(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '设备的模板以及监测指标之间标识的关系' ROW_FORMAT = Dynamic;

-- ----------------------------
-- Table structure for data_monitor_alarm_rule
-- ----------------------------
CREATE TABLE `data_monitor_alarm_rule`  (
  `id` bigint(20) UNSIGNED NOT NULL COMMENT 'id',
  `application_id` bigint(20) NULL DEFAULT NULL COMMENT '应用id',
  `template_id` bigint(20) NULL DEFAULT NULL COMMENT '模板id',
  `device_id` bigint(20) NULL DEFAULT NULL COMMENT '设备id',
  `tenant_id` bigint(20) NULL DEFAULT NULL COMMENT '租户id',
  `monitor_point_id` bigint(20) NULL DEFAULT NULL COMMENT '测点id',
  `alarm_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '告警名称',
  `global_flag` tinyint(1) UNSIGNED NULL DEFAULT 0 COMMENT '使用范围 默认0全局 1局部',
  `enable` tinyint(1) NULL DEFAULT 1 COMMENT '是否启用1启用 0关闭',
  `push_rule_id` bigint(20) NULL DEFAULT NULL COMMENT '推送规则id',
  `create_at` bigint(20) NULL DEFAULT NULL,
  `update_at` bigint(20) NULL DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '用于设定监测的告警类型、推送规则以及相关规则' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;
