<?xml version="1.0" encoding="utf-8"?>

<databaseChangeLog
        xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.4.xsd">

    <changeSet author="suhuiguang" id="1587367587716-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="ue4_rotation"/>
            </not>
        </preConditions>
        <comment>p_point add column ue4_rotation</comment>
        <sql>
            alter table `p_point` add column `ue4_rotation` text comment 'ue4旋转' after `coordinates`;
        </sql>
    </changeSet>
    <changeSet author="suhuiguang" id="1587367889717-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="ue4_location"/>
            </not>
        </preConditions>
        <comment>p_point add column ue4_location</comment>
        <sql>
            alter table `p_point` add column `ue4_location` text comment 'ue4旋转' after `coordinates`;
        </sql>
    </changeSet>

    <changeSet author="maoying" id="1590476067001-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_task" columnName="dep_id"/>
            </not>
        </preConditions>
        <comment>p_task add column dep_id</comment>
        <sql>
            ALTER TABLE `p_task`
			ADD COLUMN `dep_id`  varchar(255) NULL COMMENT '部门id';
        </sql>
    </changeSet>

    <changeSet author="maoying" id="1590476067001-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_task" columnName="dep_id"/>
            </not>
        </preConditions>
        <comment>p_task add column dep_id</comment>
        <sql>
            ALTER TABLE `p_task`
			ADD COLUMN `dep_id`  varchar(255) NULL COMMENT '部门id';
 		</sql>
    </changeSet>

     <changeSet author="suhuiguang" id="1587367889717-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="charge_dept_id"/>
            </not>
        </preConditions>
        <comment>p_point </comment>
        <sql>
             ALTER TABLE p_point MODIFY COLUMN charge_dept_id VARCHAR(100)  DEFAULT '0' COMMENT '责任部门id';
        </sql>
    </changeSet>

    <changeSet author="suhuiguang" id="1587367889717-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="charge_person_id"/>
            </not>
        </preConditions>
        <comment>p_point </comment>
        <sql>
             ALTER TABLE p_point MODIFY COLUMN charge_person_id varchar(255)  COMMENT '负责人id',
        </sql>
    </changeSet>
     <changeSet author="maoying" id="1591336116001-1">
        <preConditions onFail="MARK_RAN">
                <columnExists tableName="p_plan_task" columnName="user_id"/>
        </preConditions>
        <comment>p_plan_task MODIFY user_id</comment>
        <sql>
             ALTER TABLE `p_plan_task`
		MODIFY COLUMN `user_id`  varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '用户编号' AFTER `route_id`;
        </sql>
    </changeSet>
    <changeSet author="zhouyi" id="1590476067003-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan" columnName="user_dept"/>
            </not>
        </preConditions>
        <comment>p_plan add column user_dept</comment>
        <sql>
            ALTER TABLE `p_plan`
            ADD COLUMN `user_dept`  varchar(255) NULL COMMENT '冗余部门用户信息';
        </sql>
    </changeSet>
    <changeSet author="zhouyi" id="1590476067004-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task" columnName="user_dept"/>
            </not>
        </preConditions>
        <comment>p_plan_task add column user_dept</comment>
        <sql>
            ALTER TABLE `p_plan_task`
            ADD COLUMN `user_dept`  varchar(255) NULL COMMENT '冗余部门用户信息';
        </sql>
    </changeSet>

    <changeSet author="tb" id="1580000025-2">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task" columnName="user_id"/>
        </preConditions>
        <sql>
            ALTER TABLE `p_plan_task`
            MODIFY COLUMN `user_id` text COMMENT '用户编号';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="input_classify"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `input_classify`  varchar(255) NULL COMMENT '检查点分类';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="input_type"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `input_type`  Integer NULL COMMENT '0.表示手动录入，1.表示规则同步';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="equipment_name"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `equipment_name`  varchar(255) NULL COMMENT '装备定义名称';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-5">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="title"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `title`  varchar(255) NULL COMMENT '内容';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-6">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="title"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `check_method`  varchar(255) NULL COMMENT '检查方法';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-8">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point_classify" columnName="equipment_id"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_point_classify`
            ADD COLUMN `equipment_id`  varchar(255) NULL COMMENT '装备id';
        </sql>
    </changeSet>
    <changeSet author="tb" id="1580000026-9">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point_classify" columnName="inspection_spec_name"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_point_classify`
            ADD COLUMN `inspection_spec_name`  varchar(255) NULL COMMENT '巡查规范名称';
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1611628333-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="p_latent_danger"/>
            </not>
        </preConditions>
    <comment>创建隐患表p_latent_danger</comment>
        <sql>
            CREATE TABLE `p_latent_danger`  (
            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
            `business_key` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务唯一标识',
            `org_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '公司',
            `danger_name` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '隐患名称',
            `current_flow_record_id` bigint(20) NULL DEFAULT NULL COMMENT '当前工作流记录编号',
            `instance_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '工作流实例编号',
            `danger_level` tinyint(4) NOT NULL DEFAULT 1 COMMENT '隐患等级（1：一般隐患；2：重大隐患；0：安全问题）',
            `danger_position` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '隐患地点',
            `danger_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '隐患类型（1：无码无计划隐患；2：巡检隐患；3：有码无计划隐患）',
            `remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '备注',
            `overtime_state` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否逾期（0：否；1：是）',
            `reform_type` tinyint(4) NULL DEFAULT NULL COMMENT '整改类型（1：常规整改；2：安措计划；3：延期治理）',
            `reform_limit_date` datetime(0) NULL DEFAULT NULL COMMENT '整改限制时间',
            `reform_json` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '整改对象',
            `danger_state` tinyint(4) NOT NULL DEFAULT 1 COMMENT '隐患状态（1：待评审；2：待治理；3：安措计划中；4：待验证；5：治理完毕；6：已撤销；7：延期治理中；8：延期治理待车间部门审核；9：延期治理待公司审核',
            `discoverer_user_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '发现人',
            `discoverer_department_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '发现人部门编号',
            `photo_urls` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '图片',
            `deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除（0：否；1：是）',
            `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '记录创建时间',
            `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '记录修改时间',
            `delay_limit_date` datetime(0) NULL DEFAULT NULL COMMENT '延期治理时间',
            `problem_description` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '问题描述',
            `reason_analysis` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '原因分析',
            `infer_other_things` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '举一反三',
            `check_input_id` bigint(20) NULL DEFAULT NULL COMMENT '检查记录创建隐患对应check_input_id',
            PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = InnoDB AUTO_INCREMENT = 983 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '隐患表' ROW_FORMAT = Dynamic;
        </sql>
    </changeSet>
    <changeSet author="keyong" id="1611628333-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="p_latent_danger_flow_record"/>
            </not>
        </preConditions>
        <comment>创建隐患工作流记录表p_latent_danger_flow_record</comment>
        <sql>
            CREATE TABLE `p_latent_danger_flow_record`  (
            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
            `danger_id` bigint(20) NOT NULL COMMENT '隐患编号',
            `action_flag` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '执行标志',
            `flow_task_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前节点名称',
            `flow_task_user_ids` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '当前节点可执行人（多个逗号分开）',
            `flow_task_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '当前节点编号',
            `excute_state` tinyint(4) NOT NULL DEFAULT 1 COMMENT '执行状态（1：未执行；2：通过；3：驳回）',
            `excute_user_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '执行人',
            `excute_department_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '执行部门编号',
            `excute_result` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '执行结果',
            `remark` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '备注',
            `flow_json` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '上传数据',
            `deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除（0：否；1：是）',
            `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '记录创建时间',
            `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '记录修改时间',
            PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = InnoDB AUTO_INCREMENT = 2180 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '隐患工作流记录表' ROW_FORMAT = Dynamic;
        </sql>
    </changeSet>
    <changeSet author="keyong" id="1611628333-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="p_latent_danger_patrol"/>
            </not>
        </preConditions>
        <comment>创建隐患巡检关系表p_latent_danger_patrol</comment>
        <sql>
            CREATE TABLE `p_latent_danger_patrol`  (
            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
            `latent_danger_id` bigint(20) NULL DEFAULT NULL COMMENT '隐患编号',
            `point_classify_id` bigint(20) NULL DEFAULT NULL COMMENT '巡检项分类编号',
            `check_id` bigint(20) NULL DEFAULT NULL COMMENT '检查记录编号',
            `item_id` bigint(20) NULL DEFAULT NULL COMMENT '巡检项编号',
            `risk_factor_flow_id` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '风险因素工作流编号',
            `point_id` bigint(20) NULL DEFAULT NULL COMMENT '巡检点编号',
            `route_id` bigint(20) NULL DEFAULT NULL COMMENT '巡检路线编号',
            `route_point_item_id` bigint(20) NULL DEFAULT NULL COMMENT '路线、点、检查项关联编号',
            `deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除（0：否；1：是）',
            `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '记录创建时间',
            `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '记录修改时间',
            PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = InnoDB AUTO_INCREMENT = 467 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '隐患巡检关系表' ROW_FORMAT = Dynamic;
        </sql>
    </changeSet>
    <changeSet author="keyong" id="1611628333-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="p_latent_danger_photo"/>
            </not>
        </preConditions>
        <comment>创建隐患图片表p_latent_danger_photo</comment>
        <sql>
            CREATE TABLE `p_latent_danger_photo`  (
            `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键自增',
            `biz_code` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '类型编码',
            `url` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '图片路径',
            `biz_id` bigint(20) NULL DEFAULT NULL COMMENT '业务编号',
            `deleted` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否删除（0：否；1：是）',
            `create_date` datetime(0) NULL DEFAULT CURRENT_TIMESTAMP(0) COMMENT '记录创建时间',
            `update_date` datetime(0) NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP(0) COMMENT '记录修改时间',
            PRIMARY KEY (`id`) USING BTREE,
            INDEX `index_latent_danger_id`(`biz_id`) USING BTREE COMMENT '隐患编号索引'
            ) ENGINE = InnoDB AUTO_INCREMENT = 64 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '隐患图片' ROW_FORMAT = Dynamic;
        </sql>
    </changeSet>
    <changeSet author="ky" id="1611890480-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_latent_danger" columnName="structure_id"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_latent_danger` ADD COLUMN `structure_id`  bigint(20) NULL COMMENT '建筑ID';
        </sql>
    </changeSet>

    <changeSet author="ky" id="1611890480-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_latent_danger" columnName="structure_name"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_latent_danger` ADD COLUMN `structure_name`  varchar(255) NULL COMMENT '建筑名称';
        </sql>
    </changeSet>

    <changeSet author="ky" id="1611890480-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_latent_danger" columnName="instance_key"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_latent_danger` ADD COLUMN `instance_key`  varchar(255) NULL COMMENT '流程实例key';
        </sql>
    </changeSet>

    <changeSet author="ky" id="161195101-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="danger_handle_state"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_check_input` ADD COLUMN `danger_handle_state`  tinyint(4) NULL COMMENT '隐患处理状态 0：处理中；1：处理完成';
        </sql>
    </changeSet>

    <changeSet author="tb" id="1611716870-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <indexExists tableName="p_point_classify" indexName="point_id_index"/>
            </not>
        </preConditions>
        <createIndex tableName="p_point_classify" indexName="point_id_index">
            <column name="point_id"></column>
        </createIndex>
    </changeSet>

    <changeSet author="tb" id="1611716870-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <indexExists tableName="p_task" indexName="check_id_index"/>
            </not>
        </preConditions>
        <createIndex tableName="p_task" indexName="check_id_index">
            <column name="check_id"></column>
        </createIndex>
    </changeSet>

    <changeSet author="tb" id="1611716870-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <indexExists tableName="p_check" indexName="check_time_index"/>
            </not>
        </preConditions>
        <createIndex tableName="p_check" indexName="check_time_index">
            <column name="check_time"></column>
        </createIndex>
    </changeSet>

    <changeSet author="tb" id="1611716870-4">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task" columnName="org_code"/>
        </preConditions>
        <sql>
            ALTER TABLE `p_plan_task`
            MODIFY COLUMN `org_code` varchar(255) COMMENT '计划任务执行人orgCode';
        </sql>
    </changeSet>

    <changeSet author="tb" id="1611716870-5">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_exec_statistics" columnName="org_code"/>
        </preConditions>
        <sql>
            ALTER TABLE `p_plan_exec_statistics`
            MODIFY COLUMN `org_code` varchar(255) COMMENT '计划任务执行人orgCode';
        </sql>
    </changeSet>
    <changeSet author="wjk" id="1611716870-5">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_point" columnName="risk_source_id"/>
        </preConditions>
        <sql>
            ALTER TABLE `p_point`
            MODIFY COLUMN `risk_source_id` varchar(255) COMMENT '风险区域id';
        </sql>
    </changeSet>
    <changeSet author="wjk" id="1616047461-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="unit"/>
            </not>
        </preConditions>
        <sql>
            ALTER TABLE `p_input_item`
            ADD COLUMN `unit`  varchar(255) NULL COMMENT '数字项默认值单位';
        </sql>
    </changeSet>
    <changeSet author="xixinzhao" id="1618828879-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task" columnName="user_name"/>
            </not>
        </preConditions>
        <comment>p_plan_task add column user_name</comment>
        <sql>
            ALTER TABLE `p_plan_task`
            ADD COLUMN `user_name`  varchar(255) NULL COMMENT '冗余用户姓名';
        </sql>
    </changeSet>
</databaseChangeLog>