SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for alarm
-- ----------------------------
CREATE TABLE IF NOT EXISTS `alarm` (
  `id` int NOT NULL AUTO_INCREMENT,
  `ne_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '网元类型',
  `ne_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '网元ID',
  `ne_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元名称',
  `province` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元省份地域',
  `pv_flag` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元标识虚拟化标识',
  `alarm_seq` int DEFAULT '0' COMMENT '告警序号 连续递增',
  `alarm_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '告警ID',
  `alarm_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警标题',
  `alarm_code` int DEFAULT '0' COMMENT '告警状态码',
  `event_time` bigint DEFAULT '0' COMMENT '事件产生时间',
  `alarm_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警类型',
  `orig_severity` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Minor' COMMENT '严重程度',
  `perceived_severity` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Minor' COMMENT '告警级别',
  `object_uid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '对象ID',
  `object_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '对象名称',
  `object_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '对象类型',
  `location_info` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警定位信息',
  `alarm_status` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Active' COMMENT '告警状态',
  `specific_problem` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警问题原因',
  `specific_problem_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警问题原因ID',
  `add_info` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '告警辅助信息',
  `ack_state` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'NotAck' COMMENT '确认状态',
  `ack_time` bigint DEFAULT '0' COMMENT '确认时间',
  `ack_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '确认用户',
  `clear_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'NotClear' COMMENT '清除状态',
  `clear_time` bigint DEFAULT '0' COMMENT '清除时间',
  `clear_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '清除用户',
  `timestamp` bigint DEFAULT '0' COMMENT '创建时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE KEY `uk_uni_ne_aid` (`ne_type`,`ne_id`,`alarm_id`) USING BTREE,
  KEY `idx_status_severity_time` (`alarm_status`,`orig_severity`,`event_time`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='告警_记录表';

-- ----------------------------
-- COLUMN for alarm
-- ----------------------------
ALTER TABLE `alarm` DROP COLUMN `counter`;
ALTER TABLE `alarm` DROP COLUMN `latest_event_time`;
ALTER TABLE `alarm` DROP INDEX `idx_pk_id`;
ALTER TABLE `alarm` DROP INDEX `idx_uni_aid_ne_aseq`;
ALTER TABLE `alarm` DROP INDEX `idx_event_time`;
ALTER TABLE `alarm` DROP INDEX `idx_severity_status`;
ALTER TABLE `alarm` COMMENT = '告警_记录表';
ALTER TABLE `alarm` MODIFY COLUMN `ne_type` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '网元类型' AFTER `id`;
ALTER TABLE `alarm` MODIFY COLUMN `ne_id` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '网元ID' AFTER `ne_type`;
ALTER TABLE `alarm` MODIFY COLUMN `ne_name` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '网元名称' AFTER `ne_id`;
ALTER TABLE `alarm` MODIFY COLUMN `province` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '网元省份地域' AFTER `ne_name`;
ALTER TABLE `alarm` MODIFY COLUMN `pv_flag` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '网元标识虚拟化标识' AFTER `province`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_seq` int(11) NULL DEFAULT 0 COMMENT '告警序号 连续递增' AFTER `pv_flag`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '告警ID' AFTER `alarm_seq`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_title` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警标题' AFTER `alarm_id`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_code` int(11) NULL DEFAULT 0 COMMENT '告警状态码' AFTER `alarm_title`;
ALTER TABLE `alarm` MODIFY COLUMN `event_time` bigint(20) NULL DEFAULT 0 COMMENT '事件产生时间' AFTER `alarm_code`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警类型' AFTER `event_time`;
ALTER TABLE `alarm` MODIFY COLUMN `orig_severity` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Minor' COMMENT '严重程度' AFTER `alarm_type`;
ALTER TABLE `alarm` MODIFY COLUMN `perceived_severity` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Minor' COMMENT '告警级别' AFTER `orig_severity`;
ALTER TABLE `alarm` MODIFY COLUMN `object_uid` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '对象ID' AFTER `perceived_severity`;
ALTER TABLE `alarm` MODIFY COLUMN `object_name` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '对象名称' AFTER `object_uid`;
ALTER TABLE `alarm` MODIFY COLUMN `object_type` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '对象类型' AFTER `object_name`;
ALTER TABLE `alarm` MODIFY COLUMN `location_info` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警定位信息' AFTER `object_type`;
ALTER TABLE `alarm` MODIFY COLUMN `alarm_status` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'Active' COMMENT '告警状态' AFTER `location_info`;
ALTER TABLE `alarm` MODIFY COLUMN `specific_problem` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警问题原因' AFTER `alarm_status`;
ALTER TABLE `alarm` MODIFY COLUMN `specific_problem_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警问题原因ID' AFTER `specific_problem`;
ALTER TABLE `alarm` MODIFY COLUMN `add_info` varchar(2048) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '告警辅助信息' AFTER `specific_problem_id`;
ALTER TABLE `alarm` MODIFY COLUMN `ack_state` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'NotAck' COMMENT '确认状态' AFTER `add_info`;
ALTER TABLE `alarm` MODIFY COLUMN `ack_time` bigint(20) NULL DEFAULT 0 COMMENT '确认时间' AFTER `ack_state`;
ALTER TABLE `alarm` MODIFY COLUMN `ack_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '确认用户' AFTER `ack_time`;
ALTER TABLE `alarm` MODIFY COLUMN `clear_type` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT 'NotClear' COMMENT '清除状态' AFTER `ack_user`;
ALTER TABLE `alarm` MODIFY COLUMN `clear_time` bigint(20) NULL DEFAULT 0 COMMENT '清除时间' AFTER `clear_type`;
ALTER TABLE `alarm` MODIFY COLUMN `clear_user` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '清除用户' AFTER `clear_time`;
ALTER TABLE `alarm` MODIFY COLUMN `timestamp` bigint(20) NULL DEFAULT 0 COMMENT '创建时间' AFTER `clear_user`;
ALTER TABLE `alarm` ADD UNIQUE INDEX `uk_uni_ne_aid`(`ne_type`, `ne_id`, `alarm_id`) USING BTREE;
ALTER TABLE `alarm` ADD INDEX `idx_status_severity_time`(`alarm_status`, `orig_severity`, `event_time`) USING BTREE;
-- 更新数据
UPDATE `alarm` SET `alarm_type` = 'CommunicationAlarm' WHERE `alarm_type` = '1';
UPDATE `alarm` SET `alarm_type` = 'EquipmentAlarm' WHERE `alarm_type` = '2';
UPDATE `alarm` SET `alarm_type` = 'ProcessingFailure' WHERE `alarm_type` = '3';
UPDATE `alarm` SET `alarm_type` = 'EnvironmentalAlarm' WHERE `alarm_type` = '4';
UPDATE `alarm` SET `alarm_type` = 'QualityOfServiceAlarm' WHERE `alarm_type` = '5';
UPDATE `alarm` SET `orig_severity` = 'Critical', `perceived_severity` = 'Critical' WHERE `orig_severity` = '1';
UPDATE `alarm` SET `orig_severity` = 'Major', `perceived_severity` = 'Major' WHERE `orig_severity` = '2';
UPDATE `alarm` SET `orig_severity` = 'Minor', `perceived_severity` = 'Minor' WHERE `orig_severity` = '3';
UPDATE `alarm` SET `orig_severity` = 'Warning', `perceived_severity` = 'Warning' WHERE `orig_severity` = '4';
UPDATE `alarm` SET `orig_severity` = 'Event', `perceived_severity` = 'Event' WHERE `orig_severity` = '5';
UPDATE `alarm` SET `alarm_status` = 'Clear' WHERE `alarm_status` = '0';
UPDATE `alarm` SET `alarm_status` = 'Active' WHERE `alarm_status` = '1';
UPDATE `alarm` SET `ack_state` = 'NotAck' WHERE `ack_state` = '0';
UPDATE `alarm` SET `ack_state` = 'Ack' WHERE `ack_state` = '1';
UPDATE `alarm` SET `clear_type` = 'NotClear' WHERE `clear_type` = '0';
UPDATE `alarm` SET `clear_type` = 'AutoClear' WHERE `clear_type` = '1';
UPDATE `alarm` SET `clear_type` = 'ManualClear' WHERE `clear_type` = '2';

SET FOREIGN_KEY_CHECKS = 1;

-- Dump completed on 2025-02-14 15:26:56
