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

    <resultMap type="com.zehong.system.domain.TEmergencyResources" id="TEmergencyResourcesResult">
        <result property="id"    column="id"    />
        <result property="resourceName"    column="resource_name"    />
        <result property="resourceType"    column="resource_type"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="contacts"    column="contacts"    />
        <result property="contactNumber"    column="contact_number"    />
        <result property="resourceDescription"    column="resource_description"    />
    </resultMap>

    <sql id="selectTEmergencyResourcesVo">
        select id, resource_name, resource_type, longitude, latitude, contacts, contact_number, resource_description from t_emergency_resources
    </sql>

    <select id="selectTEmergencyResourcesList" parameterType="com.zehong.system.domain.TEmergencyResources" resultMap="TEmergencyResourcesResult">
        <include refid="selectTEmergencyResourcesVo"/>
        <where>
            <if test="resourceName != null  and resourceName != ''"> and resource_name like concat('%', #{resourceName}, '%')</if>
            <if test="resourceType != null  and resourceType != ''"> and resource_type = #{resourceType}</if>
            <if test="contacts != null  and contacts != ''"> and contacts = #{contacts}</if>
        </where>
    </select>

    <select id="selectTEmergencyResourcesById" parameterType="Long" resultMap="TEmergencyResourcesResult">
        <include refid="selectTEmergencyResourcesVo"/>
        where id = #{id}
    </select>

    <insert id="insertTEmergencyResources" parameterType="com.zehong.system.domain.TEmergencyResources" useGeneratedKeys="true" keyProperty="id">
        insert into t_emergency_resources
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="resourceName != null">resource_name,</if>
            <if test="resourceType != null">resource_type,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="contacts != null">contacts,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="resourceDescription != null">resource_description,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="resourceName != null">#{resourceName},</if>
            <if test="resourceType != null">#{resourceType},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="contacts != null">#{contacts},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="resourceDescription != null">#{resourceDescription},</if>
        </trim>
    </insert>

    <update id="updateTEmergencyResources" parameterType="com.zehong.system.domain.TEmergencyResources">
        update t_emergency_resources
        <trim prefix="SET" suffixOverrides=",">
            <if test="resourceName != null">resource_name = #{resourceName},</if>
            <if test="resourceType != null">resource_type = #{resourceType},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="contacts != null">contacts = #{contacts},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="resourceDescription != null">resource_description = #{resourceDescription},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteTEmergencyResourcesById" parameterType="Long">
        delete from t_emergency_resources where id = #{id}
    </delete>

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