<?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="cn.com.countrygarden.bi.main.dao.propertyAgreement.PropertyAgreementMapper">
    <resultMap id="BasePropertyAgreementMap" type="cn.com.countrygarden.bi.main.dto.propertyAgreement.PropertyAgreementDto">
        <id     property="propertyAgreementId"    column="property_agreement_id"/>
        <result property="regionName"              column="region_name"/>
        <result property="salesRegionName"        column="sales_region_name"/>
        <result property="cstname"                  column="cstname"/>
        <result property="fileName"                column="file_name"/>
        <result property="signedTime"              column="signed_time"/>
        <result property="roomid"                   column="roomid"/>
        <result property="htRoomName"             column="ht_room_name"/>
        <result property="areaid"                   column="areaid"/>
        <result property="areaName"                column="area_name"/>
        <result property="fileUrl"                 column="file_url"/>
    </resultMap>

    <select id="findList" resultMap="BasePropertyAgreementMap">
        SELECT
        *
        FROM property_agreement u
        <include refid="BaseSql"></include>
        ORDER BY roomid
        limit #{pageOffset}, #{pageSize}
    </select>

    <select id="findCount" resultType="int">
        SELECT
        count(1)
        FROM property_agreement u
        <include refid="BaseSql"></include>
    </select>

    <sql id="BaseSql">
        <where>
            <if test="regionName != null and regionName != ''">
                and (u.region_name like concat('%', #{regionName}, '%') or u.sales_region_name like concat('%', #{regionName}, '%'))
            </if>
            <if test="fileName != null and fileName != ''">
                and u.file_name like concat('%', #{fileName}, '%')
            </if>
            <if test="cstname != null and cstname != ''">
                and u.cstname like concat('%', #{cstname}, '%')
            </if>
            <if test="htRoomName != null and htRoomName != ''">
                and u.ht_room_name like concat('%', #{htRoomName}, '%')
            </if>
            <if test="areaid != null and areaid != ''">
                and u.areaid like concat('%', #{areaid}, '%')
            </if>
            <if test="roomid != null and roomid != ''">
                and u.roomid like concat('%', #{roomid}, '%')
            </if>
            <if test="signedTimeStart != null">
                and u.signed_time <![CDATA[>=]]> #{signedTimeStart}
            </if>
            <if test="signedTimeEnd != null">
                and u.signed_time <![CDATA[<=]]> #{signedTimeEnd}
            </if>
            <if test="areaName != null and areaName != ''">
                and u.area_name like concat('%',#{areaName},'%')
            </if>
        </where>
    </sql>

    <select id="findOrganList">
--         select
--         from property_agreement
--         group by
--         union all
--         select
--         from property_agreement
--         group by
    </select>
    <select id="findMaxTime" resultType="date">
        select max(create_time) from  property_agreement
    </select>

    <select id="selectClick" resultMap="BasePropertyAgreementMap">
          SELECT `property_agreement_id`,`region_name`, `sales_region_name`,`cstname`,`file_name`,`signed_time`,
  `roomid`,`ht_room_name`,`areaid`,`area_name`,`file_url`,`create_time` FROM `property_agreement`
   <where>
       <if test="regionName!=null and regionName!=''">
           and region_name=#{regionName}
       </if>
       <if test="salesRegionName!=null and salesRegionName!=''">
           and sales_region_name=#{salesRegionName}
       </if>
       <if test="cstname!=null and cstname!=''">
           and cstname=#{cstname}
       </if>
       <if test="fileName!=null and fileName!=''">
           and file_name=#{fileName}
       </if>
       <if test="roomid!=null and roomid!=''">
           and roomid=#{roomid}
       </if>
       <if test="htRoomName!=null and htRoomName!=''">
           and ht_room_name=#{htRoomName}
       </if>
       <if test="areaid!=null and areaid!=''">
           and areaid=#{areaid}
       </if>
       <if test="areaName!=null and areaName!=''">
           and area_name=#{areaName}
       </if>
   </where>
    </select>

</mapper>
