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

    <resultMap id="infoMap" type="com.house365.beans.entity.ReportHouseEntity">
        <result property="id" column="id"/>
        <result property="relateId" column="relate_id"/>
        <result property="houseName" column="house_name"/>
        <result property="projectId" column="project_id"/>
        <result property="channel" column="channel"/>
        <result property="city" column="city"/>
        <result property="isDirect" column="is_direct"/>
        <result property="district" column="district"/>
        <result property="unitType" column="unit_type"/>
        <result property="area" column="area"/>
        <result property="unitPrice" column="unit_price"/>
        <result property="downPayment" column="down_payment"/>
        <result property="monthPay" column="month_pay"/>
        <result property="totalPrice" column="total_price"/>
        <result property="isSell" column="is_sell"/>

        <result property="property" column="property"/>
        <result property="decoration" column="decoration"/>
        <result property="volumeRate" column="volume_rate"/>
        <result property="parkMatch" column="park_match"/>
        <result property="averagePrice" column="average_price"/>
        <result property="deliveryTime" column="delivery_time"/>
        <result property="goods" column="goods"/>
        <result property="imageUrl" column="image_url"/>
        <result property="orderNo" column="order_no"/>
        <result property="houseUrl" column="house_url"/>
    </resultMap>

    <insert id="save" parameterType="com.house365.beans.entity.ReportHouseEntity">
        INSERT INTO report_house (
            relate_id,
            house_name,
            project_id,
            channel,
            city,
            is_direct,
            district,
            unit_type,
            area,
            unit_price,
            down_payment,
            month_pay,
            total_price,
            is_sell,
            property,
            decoration,
            volume_rate,
            park_match,
            average_price,
            delivery_time,
            goods,
            image_url,
            order_no,
            house_url
        )
        VALUES (
            #{relateId},
            #{houseName},
            #{projectId},
            #{channel},
            #{city},
            #{isDirect},
            #{district},
            #{unitType},
            #{area},
            #{unitPrice},
            #{downPayment},
            #{monthPay},
            #{totalPrice},
            #{isSell},
            #{property},
            #{decoration},
            #{volumeRate},
            #{parkMatch},
            #{averagePrice},
            #{deliveryTime},
            #{goods},
            #{imageUrl},
            #{orderNo},
            #{houseUrl}
        )
    </insert>

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

    <delete id="delete" parameterType="Integer">
        delete FROM report_house
        where id = #{id}
    </delete>

    <select id="queryByConditions" resultMap="infoMap" parameterType="map">
        SELECT
        *
        FROM
        report_house
        where 1 = 1
        <if test="houseName != null and houseName != ''">
            AND house_name LIKE CONCAT('',#{houseName},'%')
        </if>
        <if test="city != null and city != '' ">
            AND city = #{city}
        </if>
        <if test="relateId != null and relateId != '' ">
            AND relate_id = #{relateId}
        </if>
        <if test="group != null and group > 0 ">
            group BY house_name
        </if>
        <if test="order != null and order > 0 ">
            ORDER BY order_no,CONVERT(total_price,DECIMAL) ASC
        </if>
    </select>

</mapper>