<?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.TSupervisionInspectionMapper">

    <resultMap type="com.zehong.system.domain.TSupervisionInspection" id="TSupervisionInspectionResult">
        <result property="id"    column="id"    />
        <result property="fHazardId"    column="f_hazard_id"    />
        <result property="inspectionDate"    column="inspection_date"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="identifyProblems"    column="identify_problems"    />
        <result property="rectificationRequirements"    column="rectification_requirements"    />
        <result property="reviewResults"    column="review_results"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTSupervisionInspectionVo">
        select id, f_hazard_id, inspection_date, enterprise_id, enterprise_name, identify_problems, rectification_requirements, review_results, create_time from t_supervision_inspection
    </sql>

    <select id="selectTSupervisionInspectionList" parameterType="com.zehong.system.domain.TSupervisionInspection" resultMap="TSupervisionInspectionResult">
        <include refid="selectTSupervisionInspectionVo"/>
        <where>
            <if test="fHazardId != null "> and f_hazard_id = #{fHazardId}</if>
            <if test="inspectionDate != null "> and inspection_date = #{inspectionDate}</if>
            <if test="enterpriseId != null  and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
            <if test="enterpriseName != null  and enterpriseName != ''"> and enterprise_name like concat('%', #{enterpriseName}, '%')</if>
            <if test="identifyProblems != null  and identifyProblems != ''"> and identify_problems = #{identifyProblems}</if>
            <if test="rectificationRequirements != null  and rectificationRequirements != ''"> and rectification_requirements = #{rectificationRequirements}</if>
            <if test="reviewResults != null  and reviewResults != ''"> and review_results = #{reviewResults}</if>
        </where>
    </select>

    <select id="selectTSupervisionInspectionById" parameterType="Long" resultMap="TSupervisionInspectionResult">
        <include refid="selectTSupervisionInspectionVo"/>
        where id = #{id}
    </select>

    <insert id="insertTSupervisionInspection" parameterType="com.zehong.system.domain.TSupervisionInspection" useGeneratedKeys="true" keyProperty="id">
        insert into t_supervision_inspection
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fHazardId != null">f_hazard_id,</if>
            <if test="inspectionDate != null">inspection_date,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="identifyProblems != null">identify_problems,</if>
            <if test="rectificationRequirements != null">rectification_requirements,</if>
            <if test="reviewResults != null">review_results,</if>
            <if test="createTime != null">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fHazardId != null">#{fHazardId},</if>
            <if test="inspectionDate != null">#{inspectionDate},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="identifyProblems != null">#{identifyProblems},</if>
            <if test="rectificationRequirements != null">#{rectificationRequirements},</if>
            <if test="reviewResults != null">#{reviewResults},</if>
            <if test="createTime != null">#{createTime},</if>
        </trim>
    </insert>

    <update id="updateTSupervisionInspection" parameterType="com.zehong.system.domain.TSupervisionInspection">
        update t_supervision_inspection
        <trim prefix="SET" suffixOverrides=",">
            <if test="fHazardId != null">f_hazard_id = #{fHazardId},</if>
            <if test="inspectionDate != null">inspection_date = #{inspectionDate},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="identifyProblems != null">identify_problems = #{identifyProblems},</if>
            <if test="rectificationRequirements != null">rectification_requirements = #{rectificationRequirements},</if>
            <if test="reviewResults != null">review_results = #{reviewResults},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTSupervisionInspectionById" parameterType="Long">
        delete from t_supervision_inspection where id = #{id}
    </delete>

    <delete id="deleteTSupervisionInspectionByIds" parameterType="String">
        delete from t_supervision_inspection where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>