<?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.TInsRecInforMapper">
    
    <resultMap type="TInsRecInfor" id="TInsRecInforResult">
        <result property="fInsRecInforId"    column="f_ins_rec_infor_id"    />
        <result property="fCheckCode"    column="f_check_code"    />
        <result property="fCheckTaskCode"    column="f_check_task_code"    />
        <result property="fRegionCode"    column="f_region_code"    />
        <result property="fObjectType"    column="f_object_type"    />
        <result property="fObjectCode"    column="f_object_code"    />
        <result property="fCheckUserId"    column="f_check_user_id"    />
        <result property="fCheckManName"    column="f_check_man_name"    />
        <result property="fCheckManPhone"    column="f_check_man_phone"    />
        <result property="fCheckTime"    column="f_check_time"    />
        <result property="fHazardsNum"    column="f_hazards_num"    />
        <result property="fDoscNeedExecute"    column="f_dosc_need_execute"    />
        <result property="fAnnex"    column="f_annex"    />
        <result property="fLastUpdateTime"    column="f_last_update_time"    />
        <result property="fRemark"    column="f_remark"    />

        <result property="govUploadState"    column="f_gov_upload_state"    />
        <result property="govUploadTime"    column="f_gov_upload_time"    />
    </resultMap>

    <sql id="selectTInsRecInforVo">
        SELECT
            rec.f_ins_rec_infor_id,
            rec.f_check_code,
            rec.f_check_task_code,
            rec.f_region_code,
            rec.f_object_type,
            rec.f_object_code,
            rec.f_check_user_id,
            rec.f_check_man_name,
            rec.f_check_man_phone,
            rec.f_check_time,
            rec.f_hazards_num,
            rec.f_dosc_need_execute,
            rec.f_annex,
            rec.f_last_update_time,
            rec.f_remark,
            rec.f_gov_upload_state,
            rec.f_gov_upload_time,
            task.f_name as taskName,
            (select f_name from t_county_level_region where f_county_code = rec.f_region_code) AS countyName
        FROM
            t_ins_rec_infor rec
        LEFT JOIN t_ins_task_infor task ON task.f_unique_code = rec.f_check_task_code
    </sql>

    <select id="selectTInsRecInforList" parameterType="TInsRecInfor" resultMap="TInsRecInforResult">
        <include refid="selectTInsRecInforVo"/>
        <where>  
            <if test="fCheckCode != null  and fCheckCode != ''"> and rec.f_check_code = #{fCheckCode}</if>
            <if test="fObjectType != null  and fObjectType != ''"> and rec.f_object_type = #{fObjectType}</if>
            <if test="fCheckManName != null  and fCheckManName != ''"> and rec.f_check_man_name like concat('%', #{fCheckManName}, '%')</if>
            <if test="fCheckManPhone != null  and fCheckManPhone != ''"> and rec.f_check_man_phone like concat('%', #{fCheckManPhone}, '%')</if>
            <if test="govUploadState != null  and govUploadState != ''"> and rec.f_gov_upload_state = #{govUploadState}</if>
        </where>
        ORDER BY f_last_update_time DESC
    </select>
    
    <select id="selectTInsRecInforById" parameterType="Long" resultMap="TInsRecInforResult">
        <include refid="selectTInsRecInforVo"/>
        where rec.f_ins_rec_infor_id = #{fInsRecInforId}
    </select>
        
    <insert id="insertTInsRecInfor" parameterType="TInsRecInfor" useGeneratedKeys="true" keyProperty="fInsRecInforId">
        insert into t_ins_rec_infor
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="fCheckCode != null and fCheckCode != ''">f_check_code,</if>
            <if test="fCheckTaskCode != null and fCheckTaskCode != ''">f_check_task_code,</if>
            <if test="fRegionCode != null and fRegionCode != ''">f_region_code,</if>
            <if test="fObjectType != null and fObjectType != ''">f_object_type,</if>
            <if test="fObjectCode != null and fObjectCode != ''">f_object_code,</if>
            <if test="fCheckUserId != null and fCheckUserId != ''">f_check_user_id,</if>
            <if test="fCheckManName != null and fCheckManName != ''">f_check_man_name,</if>
            <if test="fCheckManPhone != null">f_check_man_phone,</if>
            <if test="fCheckTime != null and fCheckTime != ''">f_check_time,</if>
            <if test="fHazardsNum != null">f_hazards_num,</if>
            <if test="fDoscNeedExecute != null">f_dosc_need_execute,</if>
            <if test="fAnnex != null">f_annex,</if>
            <if test="fLastUpdateTime != null">f_last_update_time,</if>
            <if test="fRemark != null">f_remark,</if>

            <if test="govUploadState != null">f_gov_upload_state,</if>
            <if test="govUploadTime != null">f_gov_upload_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="fCheckCode != null and fCheckCode != ''">#{fCheckCode},</if>
            <if test="fCheckTaskCode != null and fCheckTaskCode != ''">#{fCheckTaskCode},</if>
            <if test="fRegionCode != null and fRegionCode != ''">#{fRegionCode},</if>
            <if test="fObjectType != null and fObjectType != ''">#{fObjectType},</if>
            <if test="fObjectCode != null and fObjectCode != ''">#{fObjectCode},</if>
            <if test="fCheckUserId != null and fCheckUserId != ''">#{fCheckUserId},</if>
            <if test="fCheckManName != null and fCheckManName != ''">#{fCheckManName},</if>
            <if test="fCheckManPhone != null">#{fCheckManPhone},</if>
            <if test="fCheckTime != null and fCheckTime != ''">#{fCheckTime},</if>
            <if test="fHazardsNum != null">#{fHazardsNum},</if>
            <if test="fDoscNeedExecute != null">#{fDoscNeedExecute},</if>
            <if test="fAnnex != null">#{fAnnex},</if>
            <if test="fLastUpdateTime != null">#{fLastUpdateTime},</if>
            <if test="fRemark != null">#{fRemark},</if>

            <if test="govUploadState != null">#{govUploadState},</if>
            <if test="govUploadTime != null">#{govUploadTime},</if>

         </trim>
    </insert>

    <update id="updateTInsRecInfor" parameterType="TInsRecInfor">
        update t_ins_rec_infor
        <trim prefix="SET" suffixOverrides=",">
            <if test="fCheckCode != null and fCheckCode != ''">f_check_code = #{fCheckCode},</if>
            <if test="fCheckTaskCode != null and fCheckTaskCode != ''">f_check_task_code = #{fCheckTaskCode},</if>
            <if test="fRegionCode != null and fRegionCode != ''">f_region_code = #{fRegionCode},</if>
            <if test="fObjectType != null and fObjectType != ''">f_object_type = #{fObjectType},</if>
            <if test="fObjectCode != null and fObjectCode != ''">f_object_code = #{fObjectCode},</if>
            <if test="fCheckUserId != null and fCheckUserId != ''">f_check_user_id = #{fCheckUserId},</if>
            <if test="fCheckManName != null and fCheckManName != ''">f_check_man_name = #{fCheckManName},</if>
            <if test="fCheckManPhone != null">f_check_man_phone = #{fCheckManPhone},</if>
            <if test="fCheckTime != null and fCheckTime != ''">f_check_time = #{fCheckTime},</if>
            <if test="fHazardsNum != null">f_hazards_num = #{fHazardsNum},</if>
            <if test="fDoscNeedExecute != null">f_dosc_need_execute = #{fDoscNeedExecute},</if>
            <if test="fAnnex != null">f_annex = #{fAnnex},</if>
            <if test="fLastUpdateTime != null">f_last_update_time = #{fLastUpdateTime},</if>
            <if test="fRemark != null">f_remark = #{fRemark},</if>

            <if test="govUploadState != null">f_gov_upload_state = #{govUploadState},</if>
            <if test="govUploadTime != null">f_gov_upload_time = #{govUploadTime},</if>
        </trim>
        where f_ins_rec_infor_id = #{fInsRecInforId}
    </update>

    <delete id="deleteTInsRecInforById" parameterType="Long">
        delete from t_ins_rec_infor where f_ins_rec_infor_id = #{fInsRecInforId}
    </delete>

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