<?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.TInsHazRefMapper">
    
    <resultMap type="TInsHazRef" id="TInsHazRefResult">
        <result property="fInsHazRefId"    column="f_ins_haz_ref_id"    />
        <result property="fHazardUniqueCode"    column="f_hazard_unique_code"    />
        <result property="fHazardOutUniqueCode"    column="f_hazard_out_unique_code"    />
        <result property="fCheckCode"    column="f_check_code"    />
        <result property="fInvolveEnterpriseCode"    column="f_involve_enterprise_code"    />
        <result property="fObjType"    column="f_obj_type"    />
        <result property="fObjCode"    column="f_obj_code"    />
        <result property="fObjBelongRegionId"    column="f_obj_belong_region_id"    />
        <result property="fCheckTime"    column="f_check_time"    />
        <result property="fHazardTypeLevelId"    column="f_hazard_type_level_id"    />
        <result property="fHazardDesc"    column="f_hazard_desc"    />
        <result property="fRectificationStatus"    column="f_rectification_status"    />
        <result property="fRectificationFund"    column="f_rectification_fund"    />
        <result property="fCompletionDate"    column="f_completion_date"    />
        <result property="fControlMeasure"    column="f_control_measure"    />
        <result property="fBeforePicture"    column="f_before_picture"    />
        <result property="fAfterPicture"    column="f_after_picture"    />
        <result property="fIsEnforcement"    column="f_is_enforcement"    />
        <result property="fEnforcementType"    column="f_enforcement_type"    />
        <result property="fPenaltyAmount"    column="f_penalty_amount"    />
        <result property="fPenaltyDesc"    column="f_penalty_desc"    />
        <result property="fPenaltyDate"    column="f_penalty_date"    />
        <result property="fRemark"    column="f_remark"    />
        <result property="fLastTime"    column="f_last_time"    />
    </resultMap>

    <sql id="selectTInsHazRefVo">
        select f_ins_haz_ref_id, f_hazard_unique_code, f_hazard_out_unique_code, f_check_code, f_involve_enterprise_code, f_obj_type, f_obj_code, f_obj_belong_region_id, f_check_time, f_hazard_type_level_id, f_hazard_desc, f_rectification_status, f_rectification_fund, f_completion_date, f_control_measure, f_before_picture, f_after_picture, f_is_enforcement, f_enforcement_type, f_penalty_amount, f_penalty_desc, f_penalty_date, f_remark, f_last_time from t_ins_haz_ref
    </sql>

    <select id="selectTInsHazRefList" parameterType="TInsHazRef" resultMap="TInsHazRefResult">
        <include refid="selectTInsHazRefVo"/>
        <where>  
            <if test="fHazardUniqueCode != null  and fHazardUniqueCode != ''"> and f_hazard_unique_code like concat('%', #{fHazardUniqueCode}, '%')</if>
            <if test="fObjType != null  and fObjType != ''"> and f_obj_type = #{fObjType}</if>
            <if test="fHazardTypeLevelId != null  and fHazardTypeLevelId != ''"> and f_hazard_type_level_id = #{fHazardTypeLevelId}</if>
            <if test="fRectificationStatus != null  and fRectificationStatus != ''"> and f_rectification_status = #{fRectificationStatus}</if>
            <if test="fIsEnforcement != null  and fIsEnforcement != ''"> and f_is_enforcement = #{fIsEnforcement}</if>
            <if test="fEnforcementType != null  and fEnforcementType != ''"> and f_enforcement_type = #{fEnforcementType}</if>
            <if test="fCheckCode != null  and fCheckCode != ''"> and f_check_code = #{fCheckCode}</if>
        </where>
        ORDER BY f_last_time DESC
    </select>
    
    <select id="selectTInsHazRefById" parameterType="Long" resultMap="TInsHazRefResult">
        <include refid="selectTInsHazRefVo"/>
        where f_ins_haz_ref_id = #{fInsHazRefId}
    </select>
        
    <insert id="insertTInsHazRef" parameterType="TInsHazRef" useGeneratedKeys="true" keyProperty="fInsHazRefId">
        insert into t_ins_haz_ref
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fHazardUniqueCode != null">f_hazard_unique_code,</if>
            <if test="fHazardOutUniqueCode != null">f_hazard_out_unique_code,</if>
            <if test="fCheckCode != null and fCheckCode != ''">f_check_code,</if>
            <if test="fInvolveEnterpriseCode != null">f_involve_enterprise_code,</if>
            <if test="fObjType != null and fObjType != ''">f_obj_type,</if>
            <if test="fObjCode != null and fObjCode != ''">f_obj_code,</if>
            <if test="fObjBelongRegionId != null and fObjBelongRegionId != ''">f_obj_belong_region_id,</if>
            <if test="fCheckTime != null and fCheckTime != ''">f_check_time,</if>
            <if test="fHazardTypeLevelId != null and fHazardTypeLevelId != ''">f_hazard_type_level_id,</if>
            <if test="fHazardDesc != null">f_hazard_desc,</if>
            <if test="fRectificationStatus != null">f_rectification_status,</if>
            <if test="fRectificationFund != null">f_rectification_fund,</if>
            <if test="fCompletionDate != null">f_completion_date,</if>
            <if test="fControlMeasure != null">f_control_measure,</if>
            <if test="fBeforePicture != null">f_before_picture,</if>
            <if test="fAfterPicture != null">f_after_picture,</if>
            <if test="fIsEnforcement != null">f_is_enforcement,</if>
            <if test="fEnforcementType != null">f_enforcement_type,</if>
            <if test="fPenaltyAmount != null">f_penalty_amount,</if>
            <if test="fPenaltyDesc != null">f_penalty_desc,</if>
            <if test="fPenaltyDate != null">f_penalty_date,</if>
            <if test="fRemark != null">f_remark,</if>
            <if test="fLastTime != null">f_last_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fHazardUniqueCode != null">#{fHazardUniqueCode},</if>
            <if test="fHazardOutUniqueCode != null">#{fHazardOutUniqueCode},</if>
            <if test="fCheckCode != null and fCheckCode != ''">#{fCheckCode},</if>
            <if test="fInvolveEnterpriseCode != null">#{fInvolveEnterpriseCode},</if>
            <if test="fObjType != null and fObjType != ''">#{fObjType},</if>
            <if test="fObjCode != null and fObjCode != ''">#{fObjCode},</if>
            <if test="fObjBelongRegionId != null and fObjBelongRegionId != ''">#{fObjBelongRegionId},</if>
            <if test="fCheckTime != null and fCheckTime != ''">#{fCheckTime},</if>
            <if test="fHazardTypeLevelId != null and fHazardTypeLevelId != ''">#{fHazardTypeLevelId},</if>
            <if test="fHazardDesc != null">#{fHazardDesc},</if>
            <if test="fRectificationStatus != null">#{fRectificationStatus},</if>
            <if test="fRectificationFund != null">#{fRectificationFund},</if>
            <if test="fCompletionDate != null">#{fCompletionDate},</if>
            <if test="fControlMeasure != null">#{fControlMeasure},</if>
            <if test="fBeforePicture != null">#{fBeforePicture},</if>
            <if test="fAfterPicture != null">#{fAfterPicture},</if>
            <if test="fIsEnforcement != null">#{fIsEnforcement},</if>
            <if test="fEnforcementType != null">#{fEnforcementType},</if>
            <if test="fPenaltyAmount != null">#{fPenaltyAmount},</if>
            <if test="fPenaltyDesc != null">#{fPenaltyDesc},</if>
            <if test="fPenaltyDate != null">#{fPenaltyDate},</if>
            <if test="fRemark != null">#{fRemark},</if>
            <if test="fLastTime != null">#{fLastTime},</if>
         </trim>
    </insert>

    <update id="updateTInsHazRef" parameterType="TInsHazRef">
        update t_ins_haz_ref
        <trim prefix="SET" suffixOverrides=",">
            <if test="fHazardUniqueCode != null">f_hazard_unique_code = #{fHazardUniqueCode},</if>
            <if test="fHazardOutUniqueCode != null">f_hazard_out_unique_code = #{fHazardOutUniqueCode},</if>
            <if test="fCheckCode != null and fCheckCode != ''">f_check_code = #{fCheckCode},</if>
            <if test="fInvolveEnterpriseCode != null">f_involve_enterprise_code = #{fInvolveEnterpriseCode},</if>
            <if test="fObjType != null and fObjType != ''">f_obj_type = #{fObjType},</if>
            <if test="fObjCode != null and fObjCode != ''">f_obj_code = #{fObjCode},</if>
            <if test="fObjBelongRegionId != null and fObjBelongRegionId != ''">f_obj_belong_region_id = #{fObjBelongRegionId},</if>
            <if test="fCheckTime != null and fCheckTime != ''">f_check_time = #{fCheckTime},</if>
            <if test="fHazardTypeLevelId != null and fHazardTypeLevelId != ''">f_hazard_type_level_id = #{fHazardTypeLevelId},</if>
            <if test="fHazardDesc != null">f_hazard_desc = #{fHazardDesc},</if>
            <if test="fRectificationStatus != null">f_rectification_status = #{fRectificationStatus},</if>
            <if test="fRectificationFund != null">f_rectification_fund = #{fRectificationFund},</if>
            <if test="fCompletionDate != null">f_completion_date = #{fCompletionDate},</if>
            <if test="fControlMeasure != null">f_control_measure = #{fControlMeasure},</if>
            <if test="fBeforePicture != null">f_before_picture = #{fBeforePicture},</if>
            <if test="fAfterPicture != null">f_after_picture = #{fAfterPicture},</if>
            <if test="fIsEnforcement != null">f_is_enforcement = #{fIsEnforcement},</if>
            <if test="fEnforcementType != null">f_enforcement_type = #{fEnforcementType},</if>
            <if test="fPenaltyAmount != null">f_penalty_amount = #{fPenaltyAmount},</if>
            <if test="fPenaltyDesc != null">f_penalty_desc = #{fPenaltyDesc},</if>
            <if test="fPenaltyDate != null">f_penalty_date = #{fPenaltyDate},</if>
            <if test="fRemark != null">f_remark = #{fRemark},</if>
            <if test="fLastTime != null">f_last_time = #{fLastTime},</if>
        </trim>
        where f_ins_haz_ref_id = #{fInsHazRefId}
    </update>

    <delete id="deleteTInsHazRefById" parameterType="Long">
        delete from t_ins_haz_ref where f_ins_haz_ref_id = #{fInsHazRefId}
    </delete>

    <delete id="deleteTInsHazRefByIds" parameterType="String">
        delete from t_ins_haz_ref where f_ins_haz_ref_id in 
        <foreach item="fInsHazRefId" collection="array" open="(" separator="," close=")">
            #{fInsHazRefId}
        </foreach>
    </delete>

    <delete id="deleteTInsHazRefByCheckCode" parameterType="String">
        delete from t_ins_haz_ref where f_check_code = #{fCheckCode}
    </delete>
</mapper>