<?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.njcn.harmonic.mapper.distribution.RStatPwPermeabilityMMapper">

    <resultMap id="BaseResultMap" type="com.njcn.harmonic.pojo.po.RStatPwPermeabilityM">
            <id property="orgNo" column="org_no" jdbcType="VARCHAR"/>
            <id property="dataDate" column="data_date" jdbcType="DATE"/>
            <id property="psrId" column="psr_id" jdbcType="VARCHAR"/>
            <result property="voltageAvg" column="voltage_avg" jdbcType="FLOAT"/>
            <result property="voltageSd" column="voltage_sd" jdbcType="FLOAT"/>
            <result property="unbalanceAvg" column="unbalance_avg" jdbcType="FLOAT"/>
            <result property="unbalanceSd" column="unbalance_sd" jdbcType="FLOAT"/>
            <result property="vthdAvg" column="vthd_avg" jdbcType="FLOAT"/>
            <result property="vthdSd" column="vthd_sd" jdbcType="FLOAT"/>
            <result property="flickerAvg" column="flicker_avg" jdbcType="FLOAT"/>
            <result property="flickerSd" column="flicker_sd" jdbcType="FLOAT"/>
            <result property="permeabilityType" column="permeability_type" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="Base_Column_List">
        org_no,data_date,psr_id,
        voltage_avg,voltage_sd,unbalance_avg,
        unbalance_sd,vthd_avg,vthd_sd,
        flicker_avg,flicker_sd,permeability_type
    </sql>

    <select id="getPwPermeabilityList" resultType="com.njcn.harmonic.pojo.vo.RStatPwPermeabilityMVO">
        select
            rspp25.org_no as orgNO, rspp25.psr_id as psrId,

            rspp25.voltage_avg as voltageAvg25,rspp25.voltage_sd as voltageSd25,rspp25.unbalance_avg as unbalanceAvg25,
            rspp25.unbalance_sd as unbalanceSd25, rspp25.vthd_avg as vthdAvg25,rspp25.vthd_sd as vthdSd25,
            rspp25.flicker_avg as flickerAvg25, rspp25.flicker_sd as flickerSd25,

            rspp50.voltage_avg as voltageAvg50,rspp50.voltage_sd as voltageSd50,rspp50.unbalance_avg as unbalanceAvg50,
            rspp50.unbalance_sd as unbalanceSd50, rspp50.vthd_avg as vthdAvg50,rspp50.vthd_sd as vthdSd50,
            rspp50.flicker_avg as flickerAvg50, rspp50.flicker_sd as flickerSd50,

            rspp75.voltage_avg as voltageAvg75,rspp75.voltage_sd as voltageSd75,rspp75.unbalance_avg as unbalanceAvg75,
            rspp75.unbalance_sd as unbalanceSd75, rspp75.vthd_avg as vthdAvg75,rspp75.vthd_sd as vthdSd75,
            rspp75.flicker_avg as flickerAvg75, rspp75.flicker_sd as flickerSd75,

            rspp99.voltage_avg as voltageAvg99,rspp99.voltage_sd as voltageSd99,rspp99.unbalance_avg as unbalanceAvg99,
            rspp99.unbalance_sd as unbalanceSd99, rspp99.vthd_avg as vthdAvg99,rspp99.vthd_sd as vthdSd99,
            rspp99.flicker_avg as flickerAvg99, rspp99.flicker_sd as flickerSd99,

            rspp100.voltage_avg as voltageAvg100,rspp100.voltage_sd as voltageSd100,rspp100.unbalance_avg as unbalanceAvg100,
            rspp100.unbalance_sd as unbalanceSd100, rspp100.vthd_avg as vthdAvg100,rspp100.vthd_sd as vthdSd100,
            rspp100.flicker_avg as flickerAvg100, rspp100.flicker_sd as flickerSd100
        from
            r_stat_pw_permeability_m  rspp25
                left join r_stat_pw_permeability_m rspp50 on rspp25.psr_id = rspp50.psr_id
                left join r_stat_pw_permeability_m rspp75 on rspp25.psr_id = rspp75.psr_id
                left join r_stat_pw_permeability_m rspp99 on rspp25.psr_id = rspp99.psr_id
                left join r_stat_pw_permeability_m rspp100 on rspp25.psr_id = rspp100.psr_id
        where 1 = 1

            <if test="condMap.startTime != null and condMap.startTime != ''">
                and DATE_FORMAT(rspp25.data_date, '%Y-%m') &gt;= DATE_FORMAT(#{condMap.startTime}, '%Y-%m')
            </if>
            <if test="condMap.endTime != null and condMap.endTime != ''">
                and DATE_FORMAT(rspp25.data_date, '%Y-%m') &lt;= DATE_FORMAT(#{condMap.endTime}, '%Y-%m')
            </if>
            and rspp25.data_date = rspp50.data_date
            and rspp25.data_date = rspp75.data_date
            and rspp25.data_date = rspp99.data_date
            and rspp25.data_date = rspp100.data_date

            and rspp25.permeability_type = #{condMap.Rate_0_25}
            and rspp50.permeability_type = #{condMap.Rate_25_50}
            and rspp75.permeability_type = #{condMap.Rate_50_75}
            and rspp99.permeability_type = #{condMap.Rate_75_100}
            and rspp100.permeability_type = #{condMap.Rate_100}

            and rspp25.psr_id in
            <foreach collection="condMap.idList" open="(" close=")" separator="," item="id">
                #{id}
            </foreach>
    </select>
</mapper>
