<?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.energy.manage.service.mappers.anemometertower.AnemometerTowerMapper">

    <select id="selectAnemometerTowerPage" resultType="com.energy.manage.service.domain.vo.anemometertower.AnemometerTowerPageVo">
        SELECT
        at.id as id,
        at.anemometer_code as anemometerCode,
        at.anemometer_name  as anemometerName,
        at.longitude,
        at.state,
        at.latitude,
        aotr.fieldNumber,
        at.create_time
        FROM
        anemometer_tower at
        left join
        (SELECT
        atr.tower_code  ,
        count(1) as fieldNumber
        from anemometer_tower_relation atr
        group by tower_code) aotr on at.anemometer_code = aotr.tower_code
        where 1=1 and del_state  = 0
        <if test="item.anemometerName!=null">
            and at.anemometer_name like CONCAT("%", #{item.anemometerName} ,"%")
        </if>
        <if test="item.anemometerCode!=null">
        and at.anemometer_code = #{item.anemometerCode}
        </if>
        <if test="item.state!=null">
        and at.state = #{item.state}
        </if>
        <if test="item.beginTime != null and item.beginTime != ''">
            and at.create_time  <![CDATA[>= ]]>  #{item.beginTime}
        </if>
        <if test="item.endTime != null and item.endTime != ''">
            and at.create_time <![CDATA[<= ]]> #{item.endTime}
        </if>
        order by id desc
     </select>


    <select id="selectAnemometerTowerByfieldCode" resultType="com.energy.manage.service.domain.vo.anemometertower.AnemometerTowerByFieldVo">
        select
        ato.anemometer_code,
        ato.anemometer_name,
        ato.longitude,
        ato.latitude,
        ah.anemometerHeightStrings
        FROM
        anemometer_tower_relation atr
        left join
        anemometer_tower ato on atr.tower_code = ato.anemometer_code
        left join
        (select anemometer_code,group_concat(anemometer_height SEPARATOR '/') as anemometerHeightStrings from anemometer_tower_height group by anemometer_code) as  ah on ato.anemometer_code = ah.anemometer_code
        where 1=1
        AND
        atr.field_code = #{fieldCode}
    </select>

</mapper>
