<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.zcloud.mapper.datasource.specheck.SpeBusHiddenMapper">

    <!--表名 -->
    <sql id="tableName">
        bus_hidden
    </sql>

    <sql id="Field">
        f.HIDDEN_ID,
        f.SOURCE,
        f.RISK_UNIT,
        f.IDENTIFICATION,
        f.RISK_DESCR,
        f.RISK_POSITION,
        f.LEVEL,
        f.CHECK_CONTENT,
        f.HIDDENDESCR,
        f.HIDDENPART,
        f.CREATOR,
        f.CREATTIME,
        f.RECTIFYDESCR,
        f.RECTIFICATIONTYPE,
        f.RECTIFICATIONDEPT,
        f.RECTIFICATIONOR,
        f.RECTIFICATIONDEADLINE,
        f.RECTIFICATIONTIME,
        f.HIDDENLEVEL,
        f.STATE,
        f.CHECKDEPT,
        f.CHECKOR,
        f.CHECKTIME,
        f.CHECKDESCR,
        f.ISQUALIFIED,
        f.ISDELETE,
        f.CORPINFO_ID,
        f.HIDDENFINDDEPT,
        f.CHECKRECORD_ID,
        f.RECORDITEM_ID,
        f.RISKITEM_ID,
        f.REJECTREASON,
        f.REVIEWOR,
        f.REVIEWTIME,
        f.REVIEWDEPT,
        f.HAVESCHEME,
        f.LONGITUDE,
        f.LATITUDE,
        f.LISTMANAGER_ID,
        f.HIDDENTYPE,
        f.ISCONFIRM,
        f.HAVEPLAN,
        f.HIDDENTYPE1,
        f.HIDDENTYPE2,
        f.HIDDENTYPE3,
        f.HIDDENTYPE_NAME,
        f.IS_DOCKING,
        f.OPERATTIME,
        f.HIDDEN_CATEGORY,
        f.ADD_LIBRARY_FLAG,
        f.SPECHECK_TASK_ID,
        f.TASK_ID,
        f.CHECK_TYPE,
        f.CHECK_SCORE_ID,
        f.HARM_TYPE,
        f.DEDUCT_POINT,
        f.CHECK_PAY,
        f.CHECK_ITEM_ID,
        f.CHECK_ITEM_CONTENT,
        f.CHECK_BASIS,
        f.APPLICABLE_PLACE
    </sql>
    <sql id="Field2">
        SOURCE,
		RISK_UNIT,
		IDENTIFICATION,
		RISK_DESCR,
		RISK_POSITION,
		LEVEL,
		CHECK_CONTENT,
		HIDDENDESCR,
		HIDDENPART,
		CREATOR,
		CREATTIME,
		RECTIFYDESCR,
		RECTIFICATIONTYPE,
		RECTIFICATIONOR,
		RECTIFICATIONTIME,
		HIDDENLEVEL,
		STATE,
		CHECKDEPT,
		CHECKOR,
		CHECKTIME,
		CHECKDESCR,
		ISQUALIFIED,
		ISDELETE,
		CORPINFO_ID,
		HIDDENFINDDEPT,
		RECTIFICATIONDEADLINE,
		RECTIFICATIONDEPT,
		HIDDEN_ID,
		CHECKRECORD_ID,
		RECORDITEM_ID,
		RISKITEM_ID,
		REVIEWOR,
		REVIEWTIME,
		REVIEWDEPT,
		LONGITUDE,
		LATITUDE,
		HAVESCHEME,
		HIDDENTYPE,
		HIDDENTYPE1,
		HIDDENTYPE2,
		HIDDENTYPE3,
		HIDDENTYPE_NAME,
		ISCONFIRM,
		LISTMANAGER_ID,
		OPERATTIME,
		HIDDEN_CATEGORY,
        SPECHECK_SOURCE_ID,
        SPECHECK_HIDDEN_DISCOVERER
    </sql>
    <sql id="Field2v">
        #{SOURCE},
        #{RISK_UNIT},
        #{IDENTIFICATION},
        #{RISK_DESCR},
        #{RISK_POSITION},
        #{LEVEL},
        #{CHECK_CONTENT},
        #{HIDDENDESCR},
        #{HIDDENPART},
        #{CREATOR},
        #{CREATTIME},
        #{RECTIFYDESCR},
        #{RECTIFICATIONTYPE},
        #{RECTIFICATIONOR},
        #{RECTIFICATIONTIME},
        #{HIDDENLEVEL},
        #{STATE},
        #{CHECKDEPT},
        #{CHECKOR},
        #{CHECKTIME},
        #{CHECKDESCR},
        #{ISQUALIFIED},
        #{ISDELETE},
        #{CORPINFO_ID},
        #{HIDDENFINDDEPT},
        #{RECTIFICATIONDEADLINE},
        #{RECTIFICATIONDEPT},
        #{HIDDEN_ID},
        #{CHECKRECORD_ID},
        #{RECORDITEM_ID},
        #{RISKITEM_ID},
        #{REVIEWOR},
        #{REVIEWTIME},
        #{REVIEWDEPT},
        #{LONGITUDE},
        #{LATITUDE},
        #{HAVESCHEME},
        #{HIDDENTYPE},
        #{HIDDENTYPE1},
        #{HIDDENTYPE2},
        #{HIDDENTYPE3},
        #{HIDDENTYPE_NAME},
        #{ISCONFIRM},
        #{LISTMANAGER_ID},
        #{OPERATTIME},
        #{HIDDEN_CATEGORY},
        #{SPECHECK_SOURCE_ID},
        #{SPECHECK_HIDDEN_DISCOVERER}
    </sql>
    <sql id="FieldValue2">
        #{item.HIDDEN_ID}
        #{item.SOURCE},
        #{item.RISK_UNIT},
        #{item.IDENTIFICATION},
        #{item.RISK_DESCR},
        #{item.RISK_POSITION},
        #{item.LEVEL},
        #{item.CHECK_CONTENT},
        #{item.HIDDENDESCR},
        #{item.HIDDENPART},
        #{item.CREATOR},
        #{item.CREATTIME},
        #{item.RECTIFYDESCR},
        #{item.RECTIFICATIONTYPE},
        #{item.RECTIFICATIONDEPT},
        #{item.RECTIFICATIONOR},
        #{item.RECTIFICATIONDEADLINE},
        #{item.RECTIFICATIONTIME},
        #{item.HIDDENLEVEL},
        #{item.STATE},
        #{item.CHECKDEPT},
        #{item.CHECKOR},
        #{item.CHECKTIME},
        #{item.CHECKDESCR},
        #{item.ISQUALIFIED},
        #{item.ISDELETE},
        #{item.CORPINFO_ID},
        #{item.HIDDENFINDDEPT},
        #{item.CHECKRECORD_ID},
        #{item.RECORDITEM_ID},
        #{item.RISKITEM_ID},
        #{item.REJECTREASON},
        #{item.REVIEWOR},
        #{item.REVIEWTIME},
        #{item.REVIEWDEPT},
        #{item.HAVESCHEME},
        #{item.LONGITUDE},
        #{item.LATITUDE},
        #{item.LISTMANAGER_ID},
        #{item.HIDDENTYPE},
        #{item.ISCONFIRM},
        #{item.HAVEPLAN},
        #{item.HIDDENTYPE1},
        #{item.HIDDENTYPE2},
        #{item.HIDDENTYPE3},
        #{item.HIDDENTYPE_NAME},
        #{item.IS_DOCKING},
        #{item.OPERATTIME},
        #{item.HIDDEN_CATEGORY},
        #{item.ADD_LIBRARY_FLAG},
        #{item.SPECHECK_TASK_ID},
        #{item.TASK_ID},
        #{item.CHECK_TYPE},
        #{item.CHECK_SCORE_ID},
        #{item.HARM_TYPE},
        #{item.DEDUCT_POINT},
        #{item.CHECK_PAY},
        #{item.CHECK_ITEM_ID},
        #{item.CHECK_ITEM_CONTENT},
        #{item.CHECK_BASIS},
        #{item.APPLICABLE_PLACE}
    </sql>

    <insert id="saveBatch">
        insert into
        <include refid="tableName"></include>
        (<include refid="Field2"></include>) values
        <foreach item="item" index="index" collection="list" separator=",">
            (<include refid="FieldValue2"></include>)
        </foreach>
    </insert>
    <insert id="addHidden">
        insert into
        <include refid="tableName"></include>
        (<include refid="Field2"></include>) values
            (<include refid="Field2v"></include>)

    </insert>
    <insert id="addRecordIdByHiddenId">
        update  bus_hidden
        SET CHECKRECORD_ID = #{CHECKRECORD_ID}
            where SPECHECK_SOURCE_ID = #{SPECHECK_SOURCE_ID} and ISDELETE = '0'
    </insert>
    <update id="state0T1or4">
        UPDATE bus_hidden
        SET STATE =
                CASE
                    WHEN RECTIFICATIONTYPE = 1 THEN
                        4
                    WHEN RECTIFICATIONTYPE = 2 THEN
                        1
                    END
        WHERE
           ISDELETE = 0 and SOURCE = '4' and
        HIDDEN_ID  in
        <foreach collection="hiddenList" item="id" open="(" separator="," close=")">
            #{id}
        </foreach>

    </update>
    <update id="removeChangeHidden">
        update bus_hidden set ISDELETE = '1' where (SOURCE = '4' and SPECHECK_SOURCE_ID = #{SPECHECK_SOURCE_ID}
        <if test="hiddenList != null and hiddenList.size() > 0">
            and
            HIDDEN_ID not in
            <foreach collection="hiddenList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>)
    </update>
    <update id="editHidden">
        update
        <include refid="tableName"></include>
        set
        <if test="RISK_UNIT != null and RISK_UNIT != ''">
            RISK_UNIT = #{RISK_UNIT},
        </if>
        <if test="HIDDEN_CATEGORY != null and HIDDEN_CATEGORY != ''">
            HIDDEN_CATEGORY = #{HIDDEN_CATEGORY},
        </if>
        <if test="IDENTIFICATION != null and IDENTIFICATION != ''">
            IDENTIFICATION = #{IDENTIFICATION},
        </if>
        <if test="RISK_DESCR != null and RISK_DESCR != ''">
            RISK_DESCR = #{RISK_DESCR},
        </if>
        <if test="RISK_POSITION != null and RISK_POSITION != ''">
            RISK_POSITION = #{RISK_POSITION},
        </if>
        <if test="LEVEL != null and LEVEL != ''">
            LEVEL = #{LEVEL},
        </if>
        <if test="HIDDENTYPE1 != null and HIDDENTYPE1 != ''">
            HIDDENTYPE1 = #{HIDDENTYPE1},
            HIDDENTYPE2 = #{HIDDENTYPE2},
            HIDDENTYPE3 = #{HIDDENTYPE3},
            HIDDENTYPE_NAME = #{HIDDENTYPE_NAME},
        </if>
        <if test="CHECK_CONTENT != null and CHECK_CONTENT != ''">
            CHECK_CONTENT = #{CHECK_CONTENT},
        </if>
        HIDDENDESCR = #{HIDDENDESCR},
        HIDDENPART = #{HIDDENPART},

        <if test="SPECHECK_SOURCE_ID != null and SPECHECK_SOURCE_ID != ''">
            SPECHECK_SOURCE_ID = #{SPECHECK_SOURCE_ID},
        </if>
        <if test="SPECHECK_HIDDEN_DISCOVERER != null and SPECHECK_HIDDEN_DISCOVERER != ''">
            SPECHECK_HIDDEN_DISCOVERER = #{SPECHECK_HIDDEN_DISCOVERER},
        </if>
        <if test="RECTIFYDESCR != null and RECTIFYDESCR != ''">
            RECTIFYDESCR = #{RECTIFYDESCR},
        </if>
        RECTIFICATIONTYPE = #{RECTIFICATIONTYPE},
        HIDDENLEVEL = #{HIDDENLEVEL},
        CHECKDEPT = #{CHECKDEPT},
        CHECKTIME = #{CHECKTIME},
        CHECKDESCR = #{CHECKDESCR},
        ISQUALIFIED = #{ISQUALIFIED},
        RECTIFICATIONDEADLINE = #{RECTIFICATIONDEADLINE},
        RECTIFICATIONOR = #{RECTIFICATIONOR},
        RECTIFICATIONDEPT= #{RECTIFICATIONDEPT},
        HIDDEN_ID = HIDDEN_ID
        where
        HIDDEN_ID = #{HIDDEN_ID}

    </update>
    <update id="removeHidden">
        update  <include refid="tableName"></include> set ISDELETE = 1 where HIDDEN_ID = #{HIDDEN_ID}
    </update>
    <update id="changeHiddenCheckrecordId">
        update bus_hidden set CHECKRECORD_ID = #{specheckRecordId} where (SOURCE = '4' and SPECHECK_SOURCE_ID = #{SPECHECK_SOURCE_ID}
        <if test="hiddenList != null and hiddenList.size() > 0">
            and
            HIDDEN_ID in
            <foreach collection="hiddenList" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>)
    </update>
    <select id="getHiddenInfoByIds" resultType="com.zcloud.entity.PageData">
        SELECT
        h.*,
        t.SOURCE_ID,
        u.`NAME` CREATOR_NAME,
        u1.`NAME` RECTIFICATIONOR_NAME,
        task.checkType
        FROM
        bus_hidden h
        LEFT JOIN specheck_source s ON h.SPECHECK_SOURCE_ID = s.specheckSourceId
        LEFT JOIN bus_riskunit t ON s.riskunitId = t.RISKUNIT_ID
        LEFT JOIN sys_user u on h.CREATOR = u.USER_ID
        LEFT JOIN sys_user u1 ON h.RECTIFICATIONOR = u1.USER_ID
        LEFT JOIN specheck_task task on s.specheckTaskId = task.specheckTaskId
        WHERE
        h.SOURCE = 4
        AND h.ISDELETE = '0'
        and h.HIDDEN_ID in
        <foreach collection="hiddenInfoList" item="item" open="(" separator="," close=")">
            #{item.dangerId}
        </foreach>
    </select>
    <select id="getHiddenInfoByIdsCompensate" resultType="com.zcloud.entity.PageData">
        SELECT
        h.*,
        t.SOURCE_ID,
        u.`NAME` CREATOR_NAME,
        u1.`NAME` RECTIFICATIONOR_NAME
        FROM
        bus_hidden h
        LEFT JOIN specheck_source s ON h.SPECHECK_SOURCE_ID = s.specheckSourceId
        LEFT JOIN bus_riskunit t ON s.riskunitId = t.RISKUNIT_ID
        LEFT JOIN sys_user u on h.CREATOR = u.USER_ID
        LEFT JOIN sys_user u1 ON h.RECTIFICATIONOR = u1.USER_ID
        WHERE
        h.SOURCE = 4
        AND h.ISDELETE = '0'
        and h.STATE = '4'
        and h.HIDDEN_ID in
        <foreach collection="hiddenInfoList" item="item" open="(" separator="," close=")">
            #{item.dangerId}
        </foreach>
    </select>



</mapper>
