<?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.TEventReceiveMapper">
    
    <resultMap type="TEventReceive" id="TEventReceiveResult">
        <result property="id"    column="id"    />
        <result property="eventName"    column="event_name"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventGrade"    column="event_grade"    />
        <result property="address"    column="address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="informant"    column="informant"    />
        <result property="inforTime"    column="infor_time"    />
        <result property="informantPhone"    column="informant_phone"    />
        <result property="describe"    column="describe"    />
        <result property="status"    column="status"    />
        <result property="enterpriseId"    column="enterprise_id"    />
        <result property="enterpriseName"    column="enterprise_name"    />
        <result property="remarks"    column="remarks"    />
        <result property="companyRead"    column="company_read"    />
        <result property="governmentRead"    column="government_read"    />
        <result property="isDel"    column="is_del"    />
        <result property="createTime"    column="create_time"    />
    </resultMap>

    <sql id="selectTEventReceiveVo">
        select id, event_name, event_type, event_grade, address, longitude, latitude,
         company_read,government_read,informant, infor_time, informant_phone, `describe`, `status`,enterprise_id, enterprise_name, remarks, is_del, create_time from t_event_receive
    </sql>
    <select id="getReadReceiveList" resultMap="TEventReceiveResult">
        <include refid="selectTEventReceiveVo"/>
        <where>
            <if test="enterpriseId != null and enterpriseId != -2"> and enterprise_id = #{enterpriseId}</if>
        </where>
    </select>
    <select id="selectTEventReceiveList" parameterType="TEventReceive" resultMap="TEventReceiveResult">
        <include refid="selectTEventReceiveVo"/>
        <where>  
            <if test="eventName != null  and eventName != ''"> and event_name like concat('%', #{eventName}, '%')</if>
            <if test="eventType != null "> and event_type = #{eventType}</if>
            <if test="eventGrade != null "> and event_grade = #{eventGrade}</if>
            <if test="enterpriseId != null and enterpriseId != ''"> and enterprise_id = #{enterpriseId}</if>
            <if test="status != null and status!=5"> and status = #{status}</if>
            <if test="companyRead != null"> and company_read = #{companyRead}</if>
            <if test="governmentRead != null"> and government_read = #{governmentRead}</if>
            <if test="status ==5"> and status !=4 </if>
            and is_del = 0
        </where>
        order by infor_time
    </select>
    
    <select id="selectTEventReceiveById" parameterType="String" resultMap="TEventReceiveResult">
        <include refid="selectTEventReceiveVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTEventReceive" parameterType="TEventReceive">
        insert into t_event_receive
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="eventName != null">event_name,</if>
            <if test="eventType != null">event_type,</if>
            <if test="eventGrade != null">event_grade,</if>
            <if test="address != null">address,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="informant != null">informant,</if>
            <if test="inforTime != null">infor_time,</if>
            <if test="informantPhone != null">informant_phone,</if>
            <if test="describe != null">`describe`,</if>
            <if test="status != null">`status`,</if>
            <if test="enterpriseId != null">enterprise_id,</if>
            <if test="enterpriseName != null">enterprise_name,</if>
            <if test="remarks != null">remarks,</if>
            <if test="companyRead != null">company_read,</if>
            <if test="governmentRead != null">government_read,</if>
            <if test="isDel != null">is_del,</if>
            <if test="createTime != null">create_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="eventName != null">#{eventName},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="eventGrade != null">#{eventGrade},</if>
            <if test="address != null">#{address},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="informant != null">#{informant},</if>
            <if test="inforTime != null">#{inforTime},</if>
            <if test="informantPhone != null">#{informantPhone},</if>
            <if test="describe != null">#{describe},</if>
            <if test="status != null">#{status},</if>
            <if test="enterpriseId != null">#{enterpriseId},</if>
            <if test="enterpriseName != null">#{enterpriseName},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="companyRead != null">#{companyRead},</if>
            <if test="governmentRead != null">#{governmentRead},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="createTime != null">#{createTime},</if>
         </trim>
    </insert>

    <update id="updateTEventReceive" parameterType="TEventReceive">
        update t_event_receive
        <trim prefix="SET" suffixOverrides=",">
            <if test="eventName != null">event_name = #{eventName},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="eventGrade != null">event_grade = #{eventGrade},</if>
            <if test="address != null">address = #{address},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="informant != null">informant = #{informant},</if>
            <if test="inforTime != null">infor_time = #{inforTime},</if>
            <if test="informantPhone != null">informant_phone = #{informantPhone},</if>
            <if test="describe != null">`describe` = #{describe},</if>
            <if test="status != null">`status` = #{status},</if>
            <if test="enterpriseId != null">enterprise_id = #{enterpriseId},</if>
            <if test="enterpriseName != null">enterprise_name = #{enterpriseName},</if>
            <if test="remarks != null">remarks = #{remarks},</if>
            <if test="companyRead != null">company_read = #{companyRead},</if>
            <if test="governmentRead != null">government_read = #{governmentRead},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTEventReceiveById" parameterType="String">
        delete from t_event_receive where id = #{id}
    </delete>

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