<?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="1587367889717-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_point" columnName="last_check_id"/>
            </not>
        </preConditions>
        <comment>p_point ADD COLUMN last_check_id</comment>
        <sql>
            ALTER TABLE p_point ADD COLUMN `last_check_id` varchar(32) DEFAULT NULL COMMENT '最近检查记录（漏检不算）' AFTER
            `original_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-1" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="check_type"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN check_type</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `check_type` varchar(32) DEFAULT NULL COMMENT '检查类别' AFTER
            `test_requirement`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-2" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_parent"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_parent</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_parent` varchar(50) DEFAULT NULL COMMENT '父类检查项id' AFTER
            `check_type`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-3" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_classify"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_classify</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_classify` varchar(50) DEFAULT NULL COMMENT '检查项分类' AFTER
            `item_parent`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-4" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_type_classify"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_type_classify</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_type_classify` varchar(50) DEFAULT NULL COMMENT '适用检查类别' AFTER
            `item_classify`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-5" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_level"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_level</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_level` varchar(50) DEFAULT NULL COMMENT '检查项等级' AFTER
            `item_type_classify`;修改列
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629261435-6" runOnChange="true">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_start"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_start</comment>
        <sql>
            ALTER TABLE p_input_item ADD COLUMN `item_start` bit(1) DEFAULT b'0' COMMENT '检查项状态' AFTER `item_level`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task_detail" columnName="executor_id"/>
        </preConditions>
        <comment>p_plan_task_detail modify column executor_id</comment>
        <sql>
            alter table `p_plan_task_detail` modify column `executor_id` text COMMENT '执行人id' after `status`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="executor_name"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN executor_name</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `executor_name` text DEFAULT null COMMENT '执行人名称' AFTER
            `executor_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="item_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN item_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `item_num` int(11) DEFAULT 0 COMMENT '检查项个数' AFTER
            `executor_name`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="executed_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN executed_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `executed_num` int(11) DEFAULT 0 COMMENT '已执行个数' AFTER
            `item_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-5">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="safety_danger_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN safety_danger_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `safety_danger_num` int(11) DEFAULT 0 COMMENT '安全隐患个数' AFTER
            `executed_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629688658-6">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_plan_task_detail" columnName="major_danger_num"/>
            </not>
        </preConditions>
        <comment>p_plan_task_detail ADD COLUMN major_danger_num</comment>
        <sql>
            ALTER TABLE `p_plan_task_detail` ADD COLUMN `major_danger_num` int(11) DEFAULT 0 COMMENT '重大隐患个数' AFTER
            `safety_danger_num`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629863569-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan_task_detail" columnName="is_finish"/>
        </preConditions>
        <comment>p_plan_task_detail modify column is_finish</comment>
        <sql>
            alter table `p_plan_task_detail` modify column `is_finish` int(11) COMMENT
            '0-未开始，1-执行中，2-已完成，3-超时漏检(有一个检查项漏检则为漏检)' after `create_date`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check" columnName="company_id"/>
            </not>
        </preConditions>
        <comment>p_check ADD COLUMN company_id</comment>
        <sql>
            ALTER TABLE `p_check` ADD COLUMN `company_id` varchar(32) DEFAULT NULL COMMENT '责任单位id' AFTER `dep_name`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check" columnName="company_name"/>
            </not>
        </preConditions>
        <comment>p_check ADD COLUMN company_name</comment>
        <sql>
            ALTER TABLE `p_check` ADD COLUMN `company_name` varchar(255) DEFAULT NULL COMMENT '责任单位名称' AFTER
            `company_id`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="safety_danger_num"/>
            </not>
        </preConditions>
        <comment>p_check_input ADD COLUMN safety_danger_num</comment>
        <sql>
            ALTER TABLE `p_check_input` ADD COLUMN `safety_danger_num` int(11) DEFAULT NULL COMMENT '安全隐患个数' AFTER
            `danger_handle_state`;
        </sql>
    </changeSet>

    <changeSet author="keyong" id="1629886127-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="major_danger_num"/>
            </not>
        </preConditions>
        <comment>p_check_input ADD COLUMN major_danger_num</comment>
        <sql>
            ALTER TABLE `p_check_input` ADD COLUMN `major_danger_num` int(11) DEFAULT NULL COMMENT '重大隐患个数' AFTER
            `safety_danger_num`;
        </sql>
    </changeSet>
    <changeSet author="gaojianqiang" id="1630567666-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="check_type_id"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN check_type_id</comment>
        <sql>
            ALTER TABLE `p_input_item` ADD COLUMN `check_type_id` varchar(32) DEFAULT NULL COMMENT '检查类别字典值';
        </sql>
    </changeSet>
    <changeSet author="gaojianqiang" id="1630567666-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_route_point_item" columnName="input_item_id"/>
            </not>
        </preConditions>
        <comment>p_route_point_item ADD COLUMN input_item_id</comment>
        <sql>
            ALTER TABLE `p_route_point_item` ADD COLUMN `input_item_id` bigint(20) DEFAULT NULL COMMENT '巡检项id';
        </sql>
    </changeSet>
    <changeSet author="gaojianqiang" id="1630567666-3">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_route_point_item" columnName="plan_id"/>
            </not>
        </preConditions>
        <comment>p_route_point_item ADD COLUMN plan_id</comment>
        <sql>
            ALTER TABLE `p_route_point_item` ADD COLUMN `plan_id` bigint(20) DEFAULT NULL COMMENT '计划ID';
        </sql>
    </changeSet>
    <changeSet author="gaojianqiang" id="1630567666-4">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_input_item" columnName="item_type_classify_ids"/>
            </not>
        </preConditions>
        <comment>p_input_item ADD COLUMN item_type_classify_ids</comment>
        <sql>
            ALTER TABLE `p_input_item` ADD COLUMN `item_type_classify_ids` varchar(64) DEFAULT NULL COMMENT '检查类别IDS';
        </sql>
    </changeSet>

    <changeSet author="tb" id="2021-11-19-01">
        <preConditions onFail="MARK_RAN">
            <not>
                <tableExists tableName="p_check_report"/>
            </not>
        </preConditions>
        <comment>add p_check_report table</comment>
        <sql>
            CREATE TABLE `p_check_report` (
            `id` bigint(30) NOT NULL COMMENT '主键',
            `name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '报告名称',
            `plan_type` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT
            '计划类型（0单位级/1公司级）',
            `plan_task_id` bigint(30) NULL DEFAULT NULL COMMENT '关联计划任务id',
            `check_user` varchar(500) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '执行人',
            `start_check_date` datetime NULL DEFAULT NULL COMMENT '检查实际开始时间',
            `end_check_date` datetime NULL DEFAULT NULL COMMENT '检查实际结束时间',
            `company_count` int(255) NULL DEFAULT 0 COMMENT '检查单位数量',
            `problem_company_count` int(255) NULL DEFAULT 0 COMMENT '存在问题单位数量',
            `has_major_danger` bit(1) NULL DEFAULT b'0' COMMENT '是否有重大隐患（1有，0无）',
            `danger_ids` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '隐患id（,逗号分割）',
            `danger_count` int(255) NULL DEFAULT 0 COMMENT '存在安全隐患数量',
            `review_danger_ids` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '复查隐患id(,逗号分割)',
            `onsite_reform_count` int(255) NULL DEFAULT 0 COMMENT '现场已整改隐患数量',
            `review_danger_count` int(255) NULL DEFAULT 0 COMMENT '复查隐患数量',
            `review_reformed_count` int(255) NULL DEFAULT 0 COMMENT '复查已整改隐患数量',
            `review_reforming_count` int(255) NULL DEFAULT 0 COMMENT '复查整改中隐患数量',
            `remaining_danger_count` int(255) NULL DEFAULT NULL COMMENT '剩余隐患数量',
            `org_code` varchar(20) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '机构代码',
            `create_date` datetime NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '创建日期',
            PRIMARY KEY (`id`) USING BTREE
            ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
        </sql>
    </changeSet>
    <changeSet author="tb" id="20211125-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_check_report" columnName="id"/>
        </preConditions>
        <comment>modify p_check_report COLUMN id</comment>
        <sql>
            ALTER TABLE `p_check_report` MODIFY COLUMN `id` bigint(30) NOT NULL AUTO_INCREMENT COMMENT '主键';
        </sql>
    </changeSet>
    <changeSet author="xxz" id="20211201-1">
        <preConditions onFail="MARK_RAN">
            <columnExists tableName="p_plan" columnName="create_date"/>
        </preConditions>
        <comment>modify p_plan COLUMN create_date</comment>
        <sql>
            ALTER TABLE `p_plan` MODIFY COLUMN `create_date` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间';
        </sql>
    </changeSet>

    <changeSet author="helinlin" id="2022-1-5-1">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="accompany_user_id"/>
            </not>
        </preConditions>
        <comment>p_check_input add column</comment>
        <sql>
            alter table `p_check_input` add column `accompany_user_id` text  DEFAULT NULL COMMENT '陪同检查人ids';
        </sql>
    </changeSet>

    <changeSet author="helinlin" id="2022-1-5-2">
        <preConditions onFail="MARK_RAN">
            <not>
                <columnExists tableName="p_check_input" columnName="accompany_user_name"/>
            </not>
        </preConditions>
        <comment>p_check_input add column</comment>
        <sql>
            alter table `p_check_input` add column `accompany_user_name` text  DEFAULT NULL COMMENT '陪同检查人名称';
        </sql>
    </changeSet>

</databaseChangeLog>