## 1.生成dt_define_rel的初始化数据语句
```sql
SELECT
    'REPLACE INTO `dt_define_rel` ( `id`, `attribute`, `valid`, `directional`, `modified_time`, `code`, `modifier`, `remark`, `graph_code`, `creator`, `ts`, `creation_time`, `target_objs`, `name`, `before_cal_rel`, `cal_rule`, `from_obj_type`, `to_obj_type`, `automatic_flag`, `source_flag`, `manual`, `system_type`, `mep_system_type`, `zone_types`, `cal_flag`, `prompting`) VALUES '
FROM
    DUAL UNION
SELECT
    CONCAT(
            '(\'',
            id,
            '\',',
            IFNULL( CONCAT( '\'', attribute, '\'' ), 'NULL' ),
            ',',
            valid,
            ',\'',
            directional,
            '\',',
            IFNULL( CONCAT( '\'', modified_time, '\'' ), 'NULL' ),
            ',\'',
            `code`,
            '\',',
            IFNULL( CONCAT( '\'', modifier, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', remark, '\'' ), 'NULL' ),
            ',\'',
            graph_code,
            '\',',
            IFNULL( CONCAT( '\'', creator, '\'' ), 'NULL' ),
            ',\'',
            ts,
            '\',',
            IFNULL( CONCAT( '\'', creation_time, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', target_objs, '\'' ), 'NULL' ),
            ',\'',
            `name`,
            '\',',
            IFNULL( CONCAT( '\'', before_cal_rel, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', cal_rule, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', from_obj_type, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', to_obj_type, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', automatic_flag, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', source_flag, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', manual, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', system_type, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', mep_system_type, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', zone_types, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', cal_flag, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', prompting, '\'' ), 'NULL' ),
            '),'
        )
FROM
    dt_define_rel
```

## 2.快速生成integrated_config表配置的sql
```sql
SELECT
	CONCAT(
		'INSERT INTO `integrated_config`(`PKEY`, `PVALUE`, `APPLICATION`, `PPROFILE`, `LABLE` , `DESCRIPTION`, `ISUPDATE`, `BELONGTO`) SELECT \'',
		PKEY,
		'\', \'',
		PVALUE,
		'\', \'',
		'dmp-dic',
		'\', \'',
		PPROFILE,
		'\', \'',
		LABLE,
		'\', ',
		IFNULL( CONCAT( '\'', DESCRIPTION, '\'' ), 'NULL' ),
		', \'',
		ISUPDATE,
		'\', ',
		IFNULL( CONCAT( '\'', BELONGTO, '\'' ), 'NULL' ),
		' FROM DUAL WHERE NOT EXISTS (SELECT PKEY FROM integrated_config WHERE PKEY = \'',
		PKEY,
		'\' AND APPLICATION = \'',
		'dmp-dic',
		'\');' 
) 
FROM
	`integrated_config`
WHERE
	`APPLICATION` = 'dc-dic';
```

## 3.获得dt_define_rel的更新语句
```sql
SELECT
	CONCAT(
		'UPDATE dt_define_rel SET source_flag=',
		IFNULL( CONCAT( '\'', is_source, '\'' ), 'NULL' ),
		', automatic_flag=',
		IFNULL( CONCAT( '\'', is_automatic, '\'' ), 'NULL' ),
		', manual=',
		IFNULL( CONCAT( '\'', manual, '\'' ), 'NULL' ),
		', system_type=',
		IFNULL( CONCAT( '\'', system_type, '\'' ), 'NULL' ),
		', mep_system_type=',
		IFNULL( CONCAT( '\'', mep_system_type, '\'' ), 'NULL' ),
		', cal_flag=\'1\'',
		' WHERE graph_code=\'',
		graphic_type,
		'\' AND code=\'',
		rel_code,
		'\';' 
) 
FROM
	relation_type 
WHERE
	graphic_type IS NOT NULL 
	AND rel_code IS NOT NULL;
```

## 4.2021年10月14日16:02:28 dt_define_rel表新增字段
```sql
ALTER TABLE dt_define_rel ADD COLUMN  `before_cal_rel` json NULL COMMENT '计算关系之前需要计算的关系';
ALTER TABLE dt_define_rel ADD COLUMN  `cal_rule` json NULL COMMENT '计算器,就是计算规则';
ALTER TABLE dt_define_rel ADD COLUMN  `from_obj_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '边关系左侧的对象分类';
ALTER TABLE dt_define_rel ADD COLUMN  `to_obj_type` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '关系右侧的对象分类';
ALTER TABLE dt_define_rel ADD COLUMN  `automatic_flag` tinyint(0) NULL DEFAULT NULL COMMENT '自动计算类型,0-手动计算,1-自动计算';
ALTER TABLE dt_define_rel ADD COLUMN  `source_flag` tinyint(0) NULL DEFAULT NULL COMMENT '是否需要配置源末端';
ALTER TABLE dt_define_rel ADD COLUMN  `manual` int(0) NULL DEFAULT NULL COMMENT '手动计算类型 1 禁用  2提示引导 3手动维护';
ALTER TABLE dt_define_rel ADD COLUMN  `system_type` tinyint(0) NULL DEFAULT NULL COMMENT '风系统1,水系统0';
ALTER TABLE dt_define_rel ADD COLUMN  `mep_system_type` json NULL COMMENT '机电系统类型';
ALTER TABLE dt_define_rel ADD COLUMN  `zone_types` json NULL COMMENT '分区类型code集合';
ALTER TABLE dt_define_rel ADD COLUMN  `cal_flag` tinyint(0) NULL DEFAULT NULL COMMENT '是否参与计算';
ALTER TABLE dt_define_graph ADD COLUMN  `second_category_mes` json DEFAULT NULL COMMENT '二级分类信息';
ALTER TABLE dt_equip_class_rel ADD COLUMN  `rel_code_name` json DEFAULT NULL COMMENT '边类型名称';
```

## 5.生成dt_define_graph的初始化语句
```sql
SELECT
    'REPLACE INTO `dt_define_graph` ( `id`, `name`, `valid`, `modified_time`, `code`, `second_category`, `remark`, `modifier`, `creator`, `ts`, `creation_time`, `object_types`, `first_category`,`second_category_mes`) VALUES '
FROM
    DUAL
UNION
SELECT
    CONCAT(
            '(\'',
            id,
            '\',',
            IFNULL( CONCAT( '\'', `name`, '\'' ), 'NULL' ),
            ',',
            valid,
            ',',
            IFNULL( CONCAT( '\'', modified_time, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', `code`, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', second_category, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', remark, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', modifier, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', creator, '\'' ), 'NULL' ),
            ',\'',
            ts,
            '\',',
            IFNULL( CONCAT( '\'', creation_time, '\'' ), 'NULL' ),
            ',',
            IFNULL( CONCAT( '\'', object_types, '\'' ), 'NULL' ),
						',',
            IFNULL( CONCAT( '\'', first_category, '\'' ), 'NULL' ),
						',',
            IFNULL( CONCAT( '\'', second_category_mes, '\'' ), 'NULL' ),
            '),'
        )
FROM
    dt_define_graph
```
