<?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.zehong.system.mapper.TInsInsListInforMapper">
    
    <resultMap type="TInsInsListInfor" id="TInsInsListInforResult">
        <result property="fInsInsListInforId"    column="f_ins_ins_list_infor_id"    />
        <result property="fCheckTaskCode"    column="f_check_task_code"    />
        <result property="fUniqueCode"    column="f_unique_code"    />
        <result property="fCheckTimeName"    column="f_check_time_name"    />
        <result property="fCheckClassification"    column="f_check_classification"    />
        <result property="fCheckMethod"    column="f_check_method"    />
        <result property="fCheckCount"    column="f_check_count"    />
        <result property="fHazardLevel"    column="f_hazard_level"    />
        <result property="fEnableState"    column="f_enable_state"    />
        <result property="fCheckBasis"    column="f_check_basis"    />
        <result property="fHazardTypeLevelId"    column="f_hazard_type_level_id"    />
        <result property="fCreateBy"    column="f_create_by"    />
        <result property="fCreateTime"    column="f_create_time"    />
        <result property="fUpdateBy"    column="f_update_by"    />
        <result property="fUpdateTime"    column="f_update_time"    />
        <result property="fDeleteFlag"    column="f_delete_flag"    />
    </resultMap>

    <sql id="selectTInsInsListInforVo">
        SELECT
            inspect.f_ins_ins_list_infor_id,
            inspect.f_check_task_code,
            inspect.f_unique_code,
            inspect.f_check_time_name,
            inspect.f_check_classification,
            inspect.f_check_method,
            inspect.f_check_count,
            inspect.f_hazard_level,
            inspect.f_enable_state,
            inspect.f_check_basis,
            inspect.f_hazard_type_level_id,
            inspect.f_create_by,
            inspect.f_create_time,
            inspect.f_update_by,
            inspect.f_update_time,
            inspect.f_delete_flag,
            hidden.f_hazard_name AS hazardName
        FROM
            t_ins_ins_list_infor inspect
        LEFT JOIN t_ins_task_infor task ON task.f_unique_code = inspect.f_check_task_code
        LEFT JOIN t_ins_sta_infor hidden ON hidden.f_ins_sta_infor_id = inspect.f_hazard_type_level_id
    </sql>

    <select id="selectTInsInsListInforList" parameterType="TInsInsListInfor" resultMap="TInsInsListInforResult">
        <include refid="selectTInsInsListInforVo"/>
        <where>  
            <if test="fCheckTimeName != null  and fCheckTimeName != ''"> and inspect.f_check_time_name like concat('%', #{fCheckTimeName}, '%')</if>
            <if test="fCheckTaskCode != null  and fCheckTaskCode != ''"> and inspect.f_check_task_code = #{fCheckTaskCode}</if>
        </where>
        ORDER BY inspect.f_create_time DESC
    </select>
    
    <select id="selectTInsInsListInforById" parameterType="Long" resultMap="TInsInsListInforResult">
        <include refid="selectTInsInsListInforVo"/>
        where inspect.f_ins_ins_list_infor_id = #{fInsInsListInforId}
    </select>
        
    <insert id="insertTInsInsListInfor" parameterType="TInsInsListInfor" useGeneratedKeys="true" keyProperty="fInsInsListInforId">
        insert into t_ins_ins_list_infor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCheckTaskCode != null">f_check_task_code,</if>
            <if test="fUniqueCode != null">f_unique_code,</if>
            <if test="fCheckTimeName != null">f_check_time_name,</if>
            <if test="fCheckClassification != null">f_check_classification,</if>
            <if test="fCheckMethod != null">f_check_method,</if>
            <if test="fCheckCount != null">f_check_count,</if>
            <if test="fHazardLevel != null">f_hazard_level,</if>
            <if test="fEnableState != null">f_enable_state,</if>
            <if test="fCheckBasis != null">f_check_basis,</if>
            <if test="fHazardTypeLevelId != null">f_hazard_type_level_id,</if>
            <if test="fCreateBy != null">f_create_by,</if>
            <if test="fCreateTime != null">f_create_time,</if>
            <if test="fUpdateBy != null">f_update_by,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fDeleteFlag != null">f_delete_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fCheckTaskCode != null">#{fCheckTaskCode},</if>
            <if test="fUniqueCode != null">#{fUniqueCode},</if>
            <if test="fCheckTimeName != null">#{fCheckTimeName},</if>
            <if test="fCheckClassification != null">#{fCheckClassification},</if>
            <if test="fCheckMethod != null">#{fCheckMethod},</if>
            <if test="fCheckCount != null">#{fCheckCount},</if>
            <if test="fHazardLevel != null">#{fHazardLevel},</if>
            <if test="fEnableState != null">#{fEnableState},</if>
            <if test="fCheckBasis != null">#{fCheckBasis},</if>
            <if test="fHazardTypeLevelId != null">#{fHazardTypeLevelId},</if>
            <if test="fCreateBy != null">#{fCreateBy},</if>
            <if test="fCreateTime != null">#{fCreateTime},</if>
            <if test="fUpdateBy != null">#{fUpdateBy},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fDeleteFlag != null">#{fDeleteFlag},</if>
         </trim>
    </insert>

    <update id="updateTInsInsListInfor" parameterType="TInsInsListInfor">
        update t_ins_ins_list_infor
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCheckTaskCode != null">f_check_task_code = #{fCheckTaskCode},</if>
            <if test="fUniqueCode != null">f_unique_code = #{fUniqueCode},</if>
            <if test="fCheckTimeName != null">f_check_time_name = #{fCheckTimeName},</if>
            <if test="fCheckClassification != null">f_check_classification = #{fCheckClassification},</if>
            <if test="fCheckMethod != null">f_check_method = #{fCheckMethod},</if>
            <if test="fCheckCount != null">f_check_count = #{fCheckCount},</if>
            <if test="fHazardLevel != null">f_hazard_level = #{fHazardLevel},</if>
            <if test="fEnableState != null">f_enable_state = #{fEnableState},</if>
            <if test="fCheckBasis != null">f_check_basis = #{fCheckBasis},</if>
            <if test="fHazardTypeLevelId != null">f_hazard_type_level_id = #{fHazardTypeLevelId},</if>
            <if test="fCreateBy != null">f_create_by = #{fCreateBy},</if>
            <if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
            <if test="fUpdateBy != null">f_update_by = #{fUpdateBy},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fDeleteFlag != null">f_delete_flag = #{fDeleteFlag},</if>
        </trim>
        where f_ins_ins_list_infor_id = #{fInsInsListInforId}
    </update>

    <delete id="deleteTInsInsListInforById" parameterType="Long">
        delete from t_ins_ins_list_infor where f_ins_ins_list_infor_id = #{fInsInsListInforId}
    </delete>

    <delete id="deleteTInsInsListInforByIds" parameterType="String">
        delete from t_ins_ins_list_infor where f_ins_ins_list_infor_id in 
        <foreach item="fInsInsListInforId" collection="array" open="(" separator="," close=")">
            #{fInsInsListInforId}
        </foreach>
    </delete>


    <insert id="batchInsertTInsInsListInfor" parameterType="TInsInsListInfor" useGeneratedKeys="true" keyProperty="fInsInsListInforId">
        insert into t_ins_ins_list_infor(
            f_check_task_code,
            f_unique_code,
            f_check_time_name,
            f_check_classification,
            f_check_method,f_check_count,
            f_hazard_level,
            f_enable_state,
            f_check_basis,
            f_hazard_type_level_id,
            f_create_by,
            f_create_time,
            f_update_by,
            f_update_time,
            f_delete_flag
        )VALUES
        <foreach collection="list" separator="," item="item">
            (
                #{item.fCheckTaskCode},
                #{item.fUniqueCode},
                #{item.fCheckTimeName},
                #{item.fCheckClassification},
                #{item.fCheckMethod},
                #{item.fCheckCount},
                #{item.fHazardLevel},
                #{item.fEnableState},
                #{item.fCheckBasis},
                #{item.fHazardTypeLevelId},
                #{item.fCreateBy},
                #{item.fCreateTime},
                #{item.fUpdateBy},
                #{item.fUpdateTime},
                #{item.fDeleteFlag}
            )
        </foreach>
    </insert>
</mapper>