<?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.TInsScopeInforMapper">
    
    <resultMap type="TInsScopeInfor" id="TInsScopeInforResult">
        <result property="fScopeInforId"    column="f_scope_infor_id"    />
        <result property="fHazardCheckTaskId"    column="f_hazard_check_task_id"    />
        <result property="fObjectType"    column="f_object_type"    />
        <result property="fHazardCheckTableRecordId"    column="f_hazard_check_table_record_id"    />
        <result property="fSpotCheckType"    column="f_spot_check_type"    />
        <result property="fSpotCheck"    column="f_spot_check"    />
        <result property="fSpecialFlag"    column="f_special_flag"    />
        <result property="fLotCount"    column="f_lot_count"    />
        <result property="fSubobjecttypeCheckTypeDesc"    column="f_subobjecttype_check_type_desc"    />
        <result property="fDeleteFlag"    column="f_delete_flag"    />
        <result property="fRemark"    column="f_remark"    />
        <result property="fCreateTime"    column="f_create_time"    />
        <result property="fCreateBy"    column="f_create_by"    />
        <result property="fUpdateTime"    column="f_update_time"    />
        <result property="fModifyBy"    column="f_modify_by"    />
    </resultMap>

    <sql id="selectTInsScopeInforVo">
        SELECT
            scope.f_scope_infor_id,
            scope.f_hazard_check_task_id,
            scope.f_object_type,
            scope.f_hazard_check_table_record_id,
            scope.f_spot_check_type,
            scope.f_spot_check,
            scope.f_special_flag,
            scope.f_lot_count,
            scope.f_subobjecttype_check_type_desc,
            scope.f_delete_flag,
            scope.f_remark,
            scope.f_create_time,
            scope.f_create_by,
            scope.f_update_time,
            scope.f_modify_by,
            task.f_name AS fName
        FROM
            t_ins_scope_infor scope
        LEFT JOIN t_ins_task_infor task ON task.f_ins_task_infor_id = scope.f_hazard_check_task_id
    </sql>

    <select id="selectTInsScopeInforList" parameterType="TInsScopeInfor" resultMap="TInsScopeInforResult">
        <include refid="selectTInsScopeInforVo"/>
        <where>
            <if test="fName != null  and fName != ''"> and task.f_name like concat('%', #{fName}, '%')</if>
            <if test="fObjectType != null  and fObjectType != ''"> and scope.f_object_type = #{fObjectType}</if>
            <if test="fSpotCheckType != null  and fSpotCheckType != ''"> and scope.f_spot_check_type = #{fSpotCheckType}</if>
            <if test="fHazardCheckTaskId != null"> and scope.f_hazard_check_task_id = #{fHazardCheckTaskId}</if>
        </where>
        ORDER BY scope.f_create_time DESC
    </select>
    
    <select id="selectTInsScopeInforById" parameterType="Long" resultMap="TInsScopeInforResult">
        <include refid="selectTInsScopeInforVo"/>
        where scope.f_scope_infor_id = #{fScopeInforId}
    </select>
        
    <insert id="insertTInsScopeInfor" parameterType="TInsScopeInfor" useGeneratedKeys="true" keyProperty="fScopeInforId">
        insert into t_ins_scope_infor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fHazardCheckTaskId != null">f_hazard_check_task_id,</if>
            <if test="fObjectType != null and fObjectType != ''">f_object_type,</if>
            <if test="fHazardCheckTableRecordId != null">f_hazard_check_table_record_id,</if>
            <if test="fSpotCheckType != null">f_spot_check_type,</if>
            <if test="fSpotCheck != null">f_spot_check,</if>
            <if test="fSpecialFlag != null">f_special_flag,</if>
            <if test="fLotCount != null">f_lot_count,</if>
            <if test="fSubobjecttypeCheckTypeDesc != null">f_subobjecttype_check_type_desc,</if>
            <if test="fDeleteFlag != null">f_delete_flag,</if>
            <if test="fRemark != null">f_remark,</if>
            <if test="fCreateTime != null">f_create_time,</if>
            <if test="fCreateBy != null">f_create_by,</if>
            <if test="fUpdateTime != null">f_update_time,</if>
            <if test="fModifyBy != null">f_modify_by,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fHazardCheckTaskId != null">#{fHazardCheckTaskId},</if>
            <if test="fObjectType != null and fObjectType != ''">#{fObjectType},</if>
            <if test="fHazardCheckTableRecordId != null">#{fHazardCheckTableRecordId},</if>
            <if test="fSpotCheckType != null">#{fSpotCheckType},</if>
            <if test="fSpotCheck != null">#{fSpotCheck},</if>
            <if test="fSpecialFlag != null">#{fSpecialFlag},</if>
            <if test="fLotCount != null">#{fLotCount},</if>
            <if test="fSubobjecttypeCheckTypeDesc != null">#{fSubobjecttypeCheckTypeDesc},</if>
            <if test="fDeleteFlag != null">#{fDeleteFlag},</if>
            <if test="fRemark != null">#{fRemark},</if>
            <if test="fCreateTime != null">#{fCreateTime},</if>
            <if test="fCreateBy != null">#{fCreateBy},</if>
            <if test="fUpdateTime != null">#{fUpdateTime},</if>
            <if test="fModifyBy != null">#{fModifyBy},</if>
         </trim>
    </insert>

    <update id="updateTInsScopeInfor" parameterType="TInsScopeInfor">
        update t_ins_scope_infor
        <trim prefix="SET" suffixOverrides=",">
            <if test="fHazardCheckTaskId != null">f_hazard_check_task_id = #{fHazardCheckTaskId},</if>
            <if test="fObjectType != null and fObjectType != ''">f_object_type = #{fObjectType},</if>
            <if test="fHazardCheckTableRecordId != null">f_hazard_check_table_record_id = #{fHazardCheckTableRecordId},</if>
            <if test="fSpotCheckType != null">f_spot_check_type = #{fSpotCheckType},</if>
            <if test="fSpotCheck != null">f_spot_check = #{fSpotCheck},</if>
            <if test="fSpecialFlag != null">f_special_flag = #{fSpecialFlag},</if>
            <if test="fLotCount != null">f_lot_count = #{fLotCount},</if>
            <if test="fSubobjecttypeCheckTypeDesc != null">f_subobjecttype_check_type_desc = #{fSubobjecttypeCheckTypeDesc},</if>
            <if test="fDeleteFlag != null">f_delete_flag = #{fDeleteFlag},</if>
            <if test="fRemark != null">f_remark = #{fRemark},</if>
            <if test="fCreateTime != null">f_create_time = #{fCreateTime},</if>
            <if test="fCreateBy != null">f_create_by = #{fCreateBy},</if>
            <if test="fUpdateTime != null">f_update_time = #{fUpdateTime},</if>
            <if test="fModifyBy != null">f_modify_by = #{fModifyBy},</if>
        </trim>
        where f_scope_infor_id = #{fScopeInforId}
    </update>

    <delete id="deleteTInsScopeInforById" parameterType="Long">
        delete from t_ins_scope_infor where f_scope_infor_id = #{fScopeInforId}
    </delete>

    <delete id="deleteTInsScopeInforByIds" parameterType="String">
        delete from t_ins_scope_infor where f_scope_infor_id in 
        <foreach item="fScopeInforId" collection="array" open="(" separator="," close=")">
            #{fScopeInforId}
        </foreach>
    </delete>


    <insert id="batchInsertTInsScopeInfor" parameterType="TInsScopeInfor" useGeneratedKeys="true" keyProperty="fScopeInforId">
        insert into t_ins_scope_infor(
            f_hazard_check_task_id,
            f_object_type,
            f_hazard_check_table_record_id,
            f_spot_check_type,
            f_spot_check,
            f_special_flag,
            f_lot_count,
            f_subobjecttype_check_type_desc,
            f_delete_flag,
            f_remark,
            f_create_time,
            f_create_by,
            f_update_time,
            f_modify_by
        )VALUES
        <foreach collection="list" separator="," item="item">
            (
                #{item.fHazardCheckTaskId},
                #{item.fObjectType},
                #{item.fHazardCheckTableRecordId},
                #{item.fSpotCheckType},
                #{item.fSpotCheck},
                #{item.fSpecialFlag},
                #{item.fLotCount},
                #{item.fSubobjecttypeCheckTypeDesc},
                #{item.fDeleteFlag},
                #{item.fRemark},
                #{item.fCreateTime},
                #{item.fCreateBy},
                #{item.fUpdateTime},
                #{item.fModifyBy}
            )
        </foreach>
    </insert>
</mapper>