/*admin*/
ALTER TABLE `admin` MODIFY COLUMN `name` varchar(45) NOT NULL;
ALTER TABLE `admin` MODIFY COLUMN `password` varchar(45) NOT NULL;

/*data_cnj*/
ALTER TABLE `data_cnj` MODIFY COLUMN `chargeTime` float DEFAULT null COMMENT '储能时间';

/*icd_config_type*/
DROP TABLE IF EXISTS `icd_config_type`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_config_type` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `icd_ied_id` int(11) DEFAULT NULL,
  `ied_name` varchar(45) NOT NULL COMMENT 'IED名称',
  `ldevice_inst` varchar(45) NOT NULL COMMENT '设备类型',
  `ln_class` varchar(45) NOT NULL COMMENT 'LN类型',
  `ln_desc` varchar(200) DEFAULT NULL,
  `table_name` varchar(45) DEFAULT NULL COMMENT '表名',
  PRIMARY KEY (`id`),
  KEY `idxKey` (`ied_name`,`ldevice_inst`,`ln_class`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ICD配置类型表';


/*icd_config_type_att*/
DROP TABLE IF EXISTS `icd_config_type_att`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_config_type_att` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `icd_config_type_id` int(11) NOT NULL COMMENT '配置类型表id',
  `do_name` varchar(45) NOT NULL COMMENT '属性',
  `fc` varchar(45) DEFAULT NULL,
  `last_name` varchar(45) DEFAULT NULL,
  `description` varchar(200) DEFAULT NULL COMMENT '备注',
  `col_name` varchar(45) DEFAULT NULL COMMENT '字段名',
  `insts` varchar(2000) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ICD配置类型属性表';

DROP TABLE IF EXISTS `icd_config_type_inst`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_config_type_inst` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `icd_config_type_id` int(11) NOT NULL COMMENT '配置类型表id',
  `inst` varchar(45) NOT NULL COMMENT '实例',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='ICD配置类型实例表';

/*ied*/
DROP TABLE IF EXISTS `ied`;

/*icd_file*/
DROP TABLE IF EXISTS `icd_file`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_file` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `md5` varchar(45) DEFAULT NULL,
  `filename` varchar(45) DEFAULT NULL,
  `xml` longtext,
  `srv` int(11) DEFAULT NULL,
  `start` int(11) DEFAULT NULL,
  `port` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ICD文件';


/*icd_ied*/
DROP TABLE IF EXISTS `icd_ied`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_ied` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `icd_file_id` int(11) DEFAULT NULL,
  `ip` varchar(45) DEFAULT NULL,
  `ap_title` varchar(45) DEFAULT NULL,
  `start` int(11) DEFAULT NULL,
  `port` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='ied信息表';


DROP TABLE IF EXISTS `icd_transform`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `icd_transform` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `rpt_from` varchar(200) DEFAULT NULL,
  `rpt_to` varchar(200) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

/*modevtype*/
ALTER TABLE `modevtype` ADD `intervals` int(11) COMMENT '采集间隔/分钟';
update modevtype set intervals = 30;

/*oiltest*/
DROP TABLE IF EXISTS `oiltest`;


/*remote_config*/
DROP TABLE IF EXISTS `remote_config`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `remote_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(45) DEFAULT NULL,
  `ip` varchar(45) DEFAULT NULL,
  `port` int(11) DEFAULT NULL,
  `user` varchar(45) DEFAULT NULL,
  `passwd` varchar(45) DEFAULT NULL,
  `path` varchar(2000) DEFAULT NULL COMMENT '目录',
  `suffix` varchar(45) DEFAULT NULL COMMENT '后缀名',
  `todel` int(11) DEFAULT NULL COMMENT '下载后删除',
  `active` int(11) DEFAULT NULL COMMENT '0:停用; 1:启用;',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='远端服务器信息表';


/*prepos*/
DROP TABLE IF EXISTS prepos;


/*remote_download*/
DROP TABLE IF EXISTS `remote_download`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!50503 SET character_set_client = utf8mb4 */;
CREATE TABLE `remote_download` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `config_id` int(11) DEFAULT NULL COMMENT '目录',
  `remote_path` varchar(200) DEFAULT NULL,
  `filename` varchar(45) DEFAULT NULL COMMENT '下载后删除',
  `path` varchar(200) DEFAULT NULL COMMENT '后缀名',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `idx` (`config_id`,`remote_path`,`filename`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='远端文件下载记录表';


/*unit*/
INSERT INTO `unit` VALUES (32,'ch4ppm','UL/L');
INSERT INTO `unit` VALUES (33,'c2h4ppm','UL/L');
INSERT INTO `unit` VALUES (34,'c2h6ppm','UL/L');
INSERT INTO `unit` VALUES (35,'c2h2ppm','UL/L');
INSERT INTO `unit` VALUES (36,'h2ppm','UL/L');
INSERT INTO `unit` VALUES (37,'coppm','UL/L');
INSERT INTO `unit` VALUES (38,'co2ppm','UL/L');
INSERT INTO `unit` VALUES (39,'h2oppm','UL/L');
INSERT INTO `unit` VALUES (40,'totalCoreCurrent','mA');
INSERT INTO `unit` VALUES (41,'chargeTime','s');

/*modevtype_point*/
INSERT INTO `modevtype_point` VALUES (56,67,'C2H6','乙烷','float');
INSERT INTO `modevtype_point` VALUES (57,67,'CH4','甲烷','float');
INSERT INTO `modevtype_point` VALUES (58,67,'CO','一氧化碳','float');
INSERT INTO `modevtype_point` VALUES (59,67,'CO2','二氧化碳','float');
INSERT INTO `modevtype_point` VALUES (60,67,'H2','氢气','float');
INSERT INTO `modevtype_point` VALUES (61,67,'N2','氮气','float');
INSERT INTO `modevtype_point` VALUES (62,67,'O2','氧气','float');
INSERT INTO `modevtype_point` VALUES (63,67,'TotalHydrocarbon','总烃','float');
INSERT INTO `modevtype_point` VALUES (64,74,'capacitance','电容量','float');
INSERT INTO `modevtype_point` VALUES (65,74,'lossFactor','介质损耗因数','float');
INSERT INTO `modevtype_point` VALUES (66,74,'systemVoltage','系统电压','float');
INSERT INTO `modevtype_point` VALUES (67,74,'totalCurrent','全电流','float');
INSERT INTO `modevtype_point` VALUES (68,74,'unbalanceCurrent','三相不平衡电流','float');
INSERT INTO `modevtype_point` VALUES (69,74,'unbalanceVoltage','三相不平衡电压','float');
INSERT INTO `modevtype_point` VALUES (70,76,'chargeTime','储能时间','float');

CREATE TABLE `ied_dl_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `ied_id` int(11) DEFAULT NULL,
  `dev_id` int(11) DEFAULT NULL COMMENT '装置ID',
  `path` varchar(2000) DEFAULT NULL COMMENT '目录',
  `suffix` varchar(45) DEFAULT NULL COMMENT '后缀名',
  `todel` int(11) DEFAULT NULL COMMENT '下载后删除',
  `active` int(11) DEFAULT NULL COMMENT '0:停用; 1:启用;',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `ied_dl_record` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `config_id` int(11) DEFAULT NULL,
  `filename` varchar(45) DEFAULT NULL COMMENT '文件名',
  `path` varchar(200) DEFAULT NULL COMMENT '路径',
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
