<?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.yeejoin.amos.boot.module.hygf.api.tdenginemapper.TdHYGFInverterDayGenerateMapper">

    <select id="selectDayTrend" resultType="map">
        SELECT
            <foreach collection="treeParams" item="item"  separator=",">
                #{item}
            </foreach>,
          created_time as `time`,
          work_status as workstatus
           from
        house_pv_data.td_hygf_inverter_day_generate
        <where>
            created_time >= #{time} and created_time &lt;= #{time2}
            <if test="snCode != null and snCode !=''">
               and sn_code = #{snCode}
            </if>
            <if test="thirdStationId != null and thirdStationId !=''">
               and third_station_id = #{thirdStationId}
            </if>
        </where>

    </select>

<!--    <select id="selectListPage" resultType="com.yeejoin.amos.boot.module.hygf.api.entity.TdHYGFInverterDayGenerate">-->
<!--        SELECT-->
<!--        *-->
<!--        from-->
<!--        house_pv_data.td_hygf_inverter_day_generate-->
<!--        <where>-->
<!--            created_time  >= #{startTime} and created_time &lt;= #{endTime}-->
<!--            <if test="sncodes != null and sncodes.size>0">-->
<!--                sn_code in-->
<!--                <foreach collection="sncodes" item="sncode" open="(" close=")"  separator=",">-->
<!--                    #{sncode}-->
<!--                </foreach>-->
<!--            </if>-->
<!--        </where>-->
<!--    </select>-->

    <select id="selectSnCodeList" resultType="map">
        SELECT
        sn_code, max(TO_UNIXTIMESTAMP(TO_ISO8601(created_time))) max_created_time
        from
        house_pv_data.td_hygf_inverter_day_generate
        <where>
            created_time  >= #{startTime} and created_time &lt;= #{endTime}
            <if test="sncodes != null and sncodes.size>0">
                and  sn_code in
                <foreach collection="sncodes" item="sncode" open="(" close=")"  separator=",">
                    #{sncode}
                </foreach>
            </if>
        </where>
        GROUP BY sn_code
    </select>

    <select id="selectListPage" resultType="com.yeejoin.amos.boot.module.hygf.api.entity.TdHYGFInverterDayGenerate">
        SELECT
        *
        from
        house_pv_data.td_hygf_inverter_day_generate
        <where>
            <if test="snCodeList != null and snCodeList.size>0">
                and  sn_code in
                <foreach collection="snCodeList" item="sncode" open="(" close=")"  separator=",">
                    #{sncode}
                </foreach>
            </if>
            <if test="maxCreatedTimeList != null and maxCreatedTimeList.size>0">
              and  created_time in
                <foreach collection="maxCreatedTimeList" item="maxCreatedTime" open="(" close=")"  separator=",">
                    #{maxCreatedTime}
                </foreach>
            </if>
            <if test="startTime != null">
                and  created_time >= #{startTime}
            </if>
            <if test="endTime != null">
                and  created_time &lt;= #{endTime}
            </if>
        </where>
        order by created_time desc
    </select>

</mapper>