<?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.yzt.airconditionersystem.mapper.ProjectMapper">

    <resultMap id="project" type="com.yzt.airconditionersystem.bean.Project" >
        <id column="id" property="id"></id>
        <result column="client_name" property="clientName"></result>
        <result column="operator_id" property="operatorId"></result>
        <result column="district" property="district"></result>
        <result column="detailed_address" property="detailedAddress"></result>
        <association property="operator">
            <id column="id" property="id"></id>
            <result column="username" property="username"></result>
            <result column="company_name" property="companyName"></result>
            <result column="district" property="district"></result>
            <result column="detailed_address" property="detailedAddress"></result>
            <result column="contact" property="contact"></result>
            <result column="phone" property="phone"></result>
        </association>
    </resultMap>

<!--    public List<Project> selectByClientNameAndDistrictAndCompanyName();-->
    <select id="selectByClientNameAndDistrictAndCompanyName" resultMap="project">
        SELECT
            project.id AS id,
            project.client_name,
            project.operator_id,
            project.district,
            project.detailed_address,
            operator.id AS "operId",
            operator.username,
            operator.company_name,
            operator.district AS "operatorDistrict",
            operator.detailed_address AS "operatorDetailAddress",
            operator.contact,
            operator.phone
        FROM
            project, operator
        <where>
                project.operator_id = operator.id
            <if test="clientName != null and clientName != ''">
                AND project.client_name like "%"#{clientName}"%"
            </if>
            <if test="district != null and district != ''">
                AND  project.district like "%"#{district}"%"
            </if>
            <if test="operatorName != null and operatorName != ''">
                AND operator.company_name like "%"#{operatorName}"%"
            </if>
        </where>
<!--        LIMIT #{startRow} ,#{limit}-->
    </select>
    <select id="selectIdByOperatorId" resultType="integer">
        select id
        from project
        where operator_id = #{operatorId,jdbcType=NUMERIC}
    </select>

</mapper>