<?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.house365.ws.dao.mapper.ReportAttachMapper">

    <resultMap id="infoMap" type="com.house365.beans.entity.ReportAttachEntity">
        <result property="id" column="id"/>
        <result property="city" column="city"/>
        <result property="name" column="name"/>
        <result property="url" column="url"/>
        <result property="link" column="link"/>

        <result property="createId" column="create_id"/>
        <result property="createName" column="create_name"/>
        <result property="createTime" column="create_time"/>
        <result property="updateId" column="update_id"/>
        <result property="updateName" column="update_name"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <insert id="save" parameterType="com.house365.beans.entity.ReportAttachEntity">
        INSERT INTO report_attach (
            city,
            name,
            url,
            link,
            create_id,
            create_name,
            create_time,
            update_id,
            update_name,
            update_time
        )
        VALUES (
            #{city},
            #{name},
            #{url},
            #{link},
            #{createId},
            #{createName},
            #{createTime},
            #{updateId},
            #{updateName},
            #{updateTime}
        )
    </insert>

    <select id="getById" resultMap="infoMap" parameterType="map">
        SELECT
         *
        FROM
        report_attach
        where  id = #{id}
    </select>

    <select id="queryByConditions" resultMap="infoMap" parameterType="map">
        SELECT
          *
        FROM
          report_attach
        where 1 = 1
        <if test="name != null and name != ''">
            AND name LIKE CONCAT('',#{name},'%')
        </if>
        <if test="city != null and city != '' ">
            AND city = #{city}
        </if>
        <if test="type != null and type  == 1 ">
            AND (name = '市场解读' or name  = '购房政策')
        </if>
        <if test="type != null and type  == 2 ">
            AND name = '广告图'
        </if>
    </select>

    <update id="update" parameterType="com.house365.beans.entity.ReportAttachEntity">
        UPDATE report_attach
        SET
        url = #{url},
        link = #{link},
        update_id = #{updateId},
        update_name = #{updateName},
        update_time = #{updateTime}
        WHERE id = #{id}
    </update>

</mapper>