<?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.zksy.property.mapper.AContractInfoMapper">

    <resultMap id="BaseResultMap" type="com.zksy.property.domain.AContractInfo">
            <id property="id" column="id" jdbcType="VARCHAR"/>
            <result property="simplifiedHouseId" column="simplified_house_id" jdbcType="VARCHAR"/>
            <result property="contractNumber" column="contract_number" jdbcType="VARCHAR"/>
            <result property="contractDate" column="contract_date" jdbcType="DATE"/>
            <result property="contractTime" column="contract_time" jdbcType="VARCHAR"/>
            <result property="contractExpirationDate" column="contract_expiration_date" jdbcType="DATE"/>
            <result property="contractDeposit" column="contract_deposit" jdbcType="DECIMAL"/>
            <result property="contractStatus" column="contract_status" jdbcType="VARCHAR"/>
            <result property="originalContractUrl" column="original_contract_url" jdbcType="VARCHAR"/>
            <result property="signContractUrl" column="sign_contract_url" jdbcType="VARCHAR"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="updateTime" column="update_time" jdbcType="TIMESTAMP"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,simplified_house_id,contract_number,
        contract_date,contract_time,contract_expiration_date,
        contract_deposit,contract_status,original_contract_url,sign_contract_url,create_time,
        update_time
    </sql>
    <select id="selectContractWithHouse" resultType="com.zksy.property.domain.AContractInfo">
        SELECT
        c.*,
        h.asset_type as assetType,
        h.building,
        h.floor,
        h.house_name as houseName
        FROM a_contract_info c
        LEFT JOIN a_simplified_house_info h
        ON c.simplified_house_id = h.id
        <where>
            <!-- 合同编号模糊查询 -->
            <if test="contractNumber != null and contractNumber != ''">
                AND c.contract_number LIKE CONCAT('%', #{contractNumber}, '%')
            </if>
            <!-- 合同日期精确查询 -->
            <if test="contractDate != null and contractDate != ''">
                AND c.contract_date = #{contractDate}
            </if>
            <!-- 合同状态模糊查询 -->
            <if test="contractStatus != null and contractStatus != ''">
                AND c.contract_status LIKE CONCAT('%', #{contractStatus}, '%')
            </if>
            <if test="assetType != null and assetType != ''">
                AND h.asset_type LIKE CONCAT('%', #{assetType}, '%')
            </if>
            <if test="building != null and building != ''">
                AND h.building LIKE CONCAT('%', #{building}, '%')
            </if>
            <if test="floor != null and floor != ''">
                AND h.floor LIKE CONCAT('%', #{floor}, '%')
            </if>
            <if test="houseName != null and houseName != ''">
                AND h.house_name LIKE CONCAT('%', #{houseName}, '%')
            </if>
        </where>
        ORDER BY c.update_time DESC
    </select>
</mapper>
