<?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.mapper.JpStationMapper">

    <select id="queryForDealerReviewPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpStationDto">


        select
        `sequence_nbr` sequenceNbr,
        `rec_date` recDate,
        `rec_user_id` recUserId,
        `rec_user_name` recUserName,
        `sn_code` snCode,
        `capacity` capacity,
        `name` ,
        `code` ,
        `system_code` systemCode,
        `access_time` accessTime,
        `create_time` createTime,
        `address` ,
        `longitude` ,
        `latitude` ,
        `price` ,
        `user_name` userName,
        `user_phone` userPhone,
        `station_contact` stationContact,
        `module_count` moduleCount,
        `on_grid_type` onGridType,
        `on_grid_time` onGridTime,
        `third_station_id` thirdStationId,
        `third_code` thirdCode,
        `station_id` stationId,
        `day_power_use` dayPowerUse,
        `month_power_use` monthPowerUse,
        `year_power_use` yearPowerUse,
        ROUND(`real_time_power`,3) realTimePower,
        ROUND(`accumulated_power`/1000,3) accumulatedPower,
        `state` ,
        `type`,
        `organizational_code` organizationalCode,
        `is_delete` isDelete,
        ROUND(`day_generate`,3) dayGenerate,
        `month_generate` monthGenerate,
        `year_generate` yearGenerate,
        `day_income` dayIncome,
        `month_income` monthIncome,
        `year_income` yearIncome,
        `area` ,
        `cumulative_income` cumulativeIncome,
        `email`,
        rated_power ratedPower


        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationIds!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.thirdStationIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
        </where>

    </select>


    <select id="queryCount" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpStationDto">


        select
        ROUND(sum(real_time_power),3) realTimePower,
        ROUND(sum(capacity)/1000,3) capacity,
        ROUND(sum(day_generate)/1000,3) dayGenerate,
        ROUND(sum(month_generate)/1000,3) monthGenerate,
        ROUND(sum(year_generate)/1000,3) yearGenerate,
        ROUND(sum(accumulated_power)/1000,3) accumulatedPower,
        ROUND( sum(day_income),3) dayIncome,
        ROUND(sum(month_income)/10000,3) monthIncome,
        ROUND(sum(year_income)/10000,3) yearIncome,
        ROUND(sum(cumulative_income)/10000,3) cumulativeIncome,
        ROUND(sum(day_power_use)/1000,3) dayPowerUse,
        ROUND(sum(month_power_use)/1000,3) monthPowerUse,
        ROUND(sum(year_power_use)/1000,3) yearPowerUse,
        ROUND(sum(rated_power),3) ratedPower,
        count(*) countBuiltNum
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
        </where>

    </select>

    <select id="countState" resultType="map">


        select
        state,
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            and hygf_jp_station.`state` is not null and hygf_jp_station.`state` in ("在线","报警","离线")

            GROUP BY state
        </where>

    </select>


    <select id="getJpStation" resultType="com.yeejoin.amos.boot.module.hygf.api.entity.JpStation">
        select
        *
        from hygf_jp_station
        <where>
            is_delete=0
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.thirdStationIds!=null and dto.thirdStationIds.size()> 0 ">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.thirdStationIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.regionalCompaniesCode!=null and dto.regionalCompaniesCode!=''">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null and dto.amosCompanyCode!=''">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            <if test="dto.state!=null">
                and hygf_jp_station.`state` =#{dto.state}
            </if>

        </where>
    </select>

    <select id="getJpStationList" resultType="com.yeejoin.amos.boot.module.hygf.api.entity.JpStation">
        select
        *
        from hygf_jp_station

        <where>
            is_delete=0
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.thirdStationIds!=null and dto.thirdStationIds.size()> 0 ">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.thirdStationIds" item="item" index="index" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.regionalCompaniesCode!=null and dto.regionalCompaniesCode!=''">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null and dto.amosCompanyCode!=''">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            <if test="dto.state!=null">
                and hygf_jp_station.`state` =#{dto.state}
            </if>

        </where>
    </select>

    <select id="getRegion" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.DropDown">
        SELECT privilege_company.ORG_CODE     orgCode,
               privilege_company.COMPANY_NAME name
        FROM privilege_company
        WHERE IS_DELETED = 0
          and privilege_company.COMPANY_TYPE = 'region'
          <if test="regionName!=null and regionName!=''">
              and privilege_company.COMPANY_NAME like concat('%',#{regionName}, '%')
          </if>

    </select>
    <select id="getRegionAll" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.DropDown">
        SELECT privilege_company.ORG_CODE     orgCode,
               privilege_company.COMPANY_NAME name
        FROM privilege_company
        WHERE IS_DELETED = 0
          and privilege_company.COMPANY_TYPE = 'region'
    </select>

    <select id="getDealer" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.DropDown">
        SELECT hygf_unit_info.`name`, hygf_unit_info.amos_company_code orgCode FROM hygf_regional_companies LEFT JOIN
        hygf_unit_info
        ON hygf_unit_info.sequence_nbr=hygf_regional_companies.unit_info_id WHERE hygf_unit_info.audit_status='2'
        AND hygf_unit_info.blacklist='0' AND hygf_unit_info.is_delete='0'
        <if test="regionalCompaniesCode!=null">
            and hygf_regional_companies.regional_companies_code =#{regionalCompaniesCode}
        </if>
        <if test="dealerName!=null and dealerName!=''">
            and hygf_unit_info.`name` like concat('%',#{dealerName}, '%')
        </if>
        and hygf_unit_info.amos_company_code is not null
        GROUP BY hygf_unit_info.amos_company_code,hygf_unit_info.`name`
    </select>

    <select id="getDealerAll" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.DropDown">
        SELECT hygf_unit_info.`name`, hygf_unit_info.amos_company_code orgCode FROM hygf_regional_companies LEFT JOIN
        hygf_unit_info
        ON hygf_unit_info.sequence_nbr=hygf_regional_companies.unit_info_id WHERE hygf_unit_info.audit_status='2'
        AND hygf_unit_info.blacklist='0' AND hygf_unit_info.is_delete='0'
        <if test="regionalCompaniesCode!=null">
            and hygf_regional_companies.regional_companies_code =#{regionalCompaniesCode}
        </if>
        and hygf_unit_info.amos_company_code is not null
        GROUP BY hygf_unit_info.amos_company_code,hygf_unit_info.`name`
    </select>

    <select id="getDealerNew" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.DropDown">
        SELECT hygf_unit_info.`name`, hygf_unit_info.sequence_nbr orgCode

        FROM hygf_regional_companies LEFT JOIN hygf_unit_info
        ON hygf_unit_info.sequence_nbr=hygf_regional_companies.unit_info_id WHERE hygf_unit_info.audit_status='2'
        AND hygf_unit_info.blacklist='0' AND hygf_unit_info.is_delete='0'
        <if test="regionalCompaniesSeq!=null">
            and hygf_regional_companies.regional_companies_seq =#{regionalCompaniesSeq}
        </if>
        and hygf_unit_info.amos_company_code is not null
        GROUP BY hygf_unit_info.sequence_nbr,hygf_unit_info.`name`
    </select>


    <select id="getCountJpStationdata" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpStationDto">
        select
        ROUND(sum(real_time_power),3) realTimePower,
        ROUND(sum(capacity)/1000,3) capacity,
        ROUND(sum(day_generate)/1000,3) dayGenerate,
        ROUND(sum(month_generate)/1000,3) monthGenerate,
        ROUND(sum(year_generate)/1000,3) yearGenerate,
        ROUND(sum(accumulated_power)/1000,3) accumulatedPower,
        ROUND( sum(day_income),3) dayIncome,
        ROUND(sum(month_income)/10000,3) monthIncome,
        ROUND(sum(year_income)/10000,3) yearIncome,
        ROUND(sum(cumulative_income)/10000,3) cumulativeIncome,
        ROUND(sum(day_power_use)/1000,3) dayPowerUse,
        ROUND(sum(month_power_use)/1000,3) monthPowerUse,
        ROUND(sum(year_power_use)/1000,3) yearPowerUse,
        ROUND(sum(rated_power),3) ratedPower,
        count(*) countBuiltNum
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
        </where>

    </select>

    <select id="getcountState" resultType="map">


        select
        state,
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            and hygf_jp_station.`state` is not null and hygf_jp_station.`state` in ("在线","报警","离线")

            GROUP BY state
        </where>

    </select>
    <select id="getcountStatetc" resultType="map">


        select
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            and hygf_jp_station.`on_grid_type` is not null
        </where>

    </select>
    <select id="getcountStatejs" resultType="map">


        select
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>

            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            and hygf_jp_station.`on_grid_type` is null and hygf_jp_station.type='家庭户用'
        </where>

    </select>

    <select id="getcountStatejr" resultType="map">


        select
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
            and hygf_jp_station.type='工商业'
        </where>

    </select>

    <select id="getcount" resultType="map">


        select
        count(*) num
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>

        </where>
    </select>
    <select id="queryForDealerReviewPagenew" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpStationDto">


        select
        `sequence_nbr` sequenceNbr,
        `rec_date` recDate,
        `rec_user_id` recUserId,
        `rec_user_name` recUserName,
        `sn_code` snCode,
        ROUND(`capacity`,3) capacity,
        `name` ,
        `code` ,
        `system_code` systemCode,
        `access_time` accessTime,
        `create_time` createTime,
        `address` ,
        `longitude` ,
        `latitude` ,
        `price` ,
        `user_name` userName,
        `user_phone` userPhone,
        `station_contact` stationContact,
        `module_count` moduleCount,
        `on_grid_type` onGridType,
        `on_grid_time` onGridTime,
        `third_station_id` thirdStationId,
        `third_code` thirdCode,
        `station_id` stationId,
        `day_power_use` dayPowerUse,
        `month_power_use` monthPowerUse,
        `year_power_use` yearPowerUse,
        ROUND(`real_time_power`,3) realTimePower,
        ROUND(`accumulated_power`/1000,3) accumulatedPower,
        `state` ,
        `type`,
        `organizational_code` organizationalCode,
        `is_delete` isDelete,
        ROUND(`day_generate`,3) dayGenerate,
        ROUND(`month_generate`,3) monthGenerate,
        ROUND(`year_generate`,3) yearGenerate,
        `day_income` dayIncome,
        `month_income` monthIncome,
        `year_income` yearIncome,
        `area` ,
        `cumulative_income` cumulativeIncome,
        `email`,
        rated_power ratedPower,
        ROUND(`day_generate`/capacity,3) fullhour,
        (select privilege_company.COMPANY_NAME from privilege_company where
        privilege_company.ORG_CODE=hygf_jp_station.regional_companies_code) regionalCompaniesName
        from hygf_jp_station
        <where>
            <if test="dto.name!=null">
                and hygf_jp_station.name like concat(concat('%',#{dto.name}),'%')
            </if>
            <if test="dto.userName!=null">
                and hygf_jp_station.user_name like concat(concat('%',#{dto.userName}),'%')
            </if>
            <if test="dto.address!=null">
                and hygf_jp_station.address like concat(concat('%',#{dto.address}),'%')
            </if>
            <if test="dto.area!=null">
                and hygf_jp_station.area like concat(concat('%',#{dto.area}),'%')
            </if>
            <if test="dto.statioId!=null">
                and hygf_jp_station.third_station_id in
                <foreach collection="dto.statioId" item="item" index="index" open="(" separator="," close=")">
                    #{item.stationId}
                </foreach>
            </if>
            <if test="dto.thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{dto.thirdStationId}
            </if>
            <if test="dto.type!=null and dto.type!=''">
                and hygf_jp_station.type =#{dto.type}
            </if>
            <if test="dto.regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{dto.regionalCompaniesCode}
            </if>
            <if test="dto.state!=null">
                and hygf_jp_station.state =#{dto.state}
            </if>
            <if test="dto.amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{dto.amosCompanyCode}
            </if>
        </where>

    </select>


    <!--    ========电站监控区域=======-->

<!--    <select id="getRegionPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerStationStatistics">-->
<!--        SELECT privilege_company.ORG_CODE code ,-->
<!--        privilege_company.COMPANY_NAME name-->
<!--        FROM privilege_company-->
<!--        <where>-->
<!--            IS_DELETED=0 and privilege_company.COMPANY_TYPE = 'region'-->
<!--            <if test="regionName != null and regionName !=''">-->
<!--                and privilege_company.COMPANY_NAME like concat("%",#{regionName},"%")-->
<!--            </if>-->
<!--        </where>-->
<!--    </select>-->

    <!--    code参数为区域公司orgCode或经销商orgCode-->
<!--    <select id="getRegionStatistics" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerStationStatistics">-->
<!--        SELECT COUNT(*)                    AS powerStationNumber,-->
<!--               ROUND(SUM(capacity)/1000, 3)     AS totalCapacity,-->
<!--               ROUND(SUM(day_generate)/1000, 3) AS totalDayGenerate,-->
<!--               ROUND(SUM(rated_power), 3)  AS totalRatedPower,-->
<!--               ROUND(SUM(real_time_power), 3)  AS totalRealTimePower,-->
<!--               ROUND(SUM(day_income), 3)   AS totalDayIncome-->
<!--        FROM hygf_jp_station hjs-->
<!--        <where>-->
<!--	        <if test="regionCode != null and regionCode !=''">-->
<!--	            and hjs.regional_companies_code LIKE CONCAT ('%',#{regionCode}) -->
<!--	        </if>-->
<!--	        <if test="code != null and code !=''">-->
<!--	            and hjs.amos_company_code LIKE CONCAT ('%',#{code})-->
<!--	        </if>-->
<!--        </where>-->
<!--    </select>-->


    <!--    根据区域orgCode查询经销商-->
<!--    <select id="getDealerPage" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.PowerStationStatistics">-->
<!--        SELECT  hygf_unit_info.`name` name,  hygf_unit_info.amos_company_code  code, hygf_regional_companies.regional_companies_code   FROM hygf_regional_companies LEFT JOIN hygf_unit_info-->
<!--        ON hygf_unit_info.sequence_nbr=hygf_regional_companies.unit_info_id  WHERE hygf_unit_info.audit_status='2'-->
<!--        AND hygf_unit_info.blacklist='0' AND hygf_unit_info.is_delete='0'-->
<!--        <if test="regionalCompaniesCode!=null and regionalCompaniesCode!=''">-->
<!--            and hygf_regional_companies.regional_companies_code = #{regionalCompaniesCode}-->
<!--        </if>-->
<!--        <if test="dealerName != null and dealerName!=''">-->
<!--            and hygf_unit_info.`name` like concat("%",#{dealerName},"%")-->
<!--        </if>-->
<!--        and hygf_unit_info.amos_company_code is not null-->
<!--    </select>-->


    <!--    查询所有场站-->
    <select id="queryAllPowerStation" resultType="com.yeejoin.amos.boot.module.hygf.api.dto.JpStationDto">
        select
        name,
        third_station_id,
        regional_companies_code
        from hygf_jp_station
        <where>
            hygf_jp_station.regional_companies_code is not null
            <if test="thirdStationId!=null">
                and hygf_jp_station.third_station_id =#{thirdStationId}
            </if>
            <if test="type!=null and type != ''">
                and hygf_jp_station.type =#{type}
            </if>
            <if test="regionalCompaniesCode!=null">
                and hygf_jp_station.regional_companies_code =#{regionalCompaniesCode}
            </if>
            <if test="amosCompanyCode!=null">
                and hygf_jp_station.amos_company_code =#{amosCompanyCode}
            </if>
        </where>
    </select>


<!--      hygf_jp_station.regional_companies_code is not null-->
<select id="selectStateCount" resultType="map">
    SELECT
    all_statuses.status,
    COALESCE(COUNT(hygf_jp_station.state), 0) AS count
    FROM (
    SELECT '在线' AS status
    UNION ALL
    SELECT '离线' AS status
    UNION ALL
    SELECT '报警' AS status
    ) AS all_statuses
    LEFT JOIN hygf_jp_station ON all_statuses.status = hygf_jp_station.state
    <where>

        <if test="type!=null">
             hygf_jp_station.type =#{type}
        </if>
        <if test="regionalCompaniesCode!=null">
            and hygf_jp_station.regional_companies_code like concat('%',#{regionalCompaniesCode},'%')
        </if>
        <if test="amosCompanyCode!=null">
            and hygf_jp_station.amos_company_code =#{amosCompanyCode}
        </if>
    </where>
    GROUP BY all_statuses.status
    ORDER BY all_statuses.status;
</select>






</mapper>
