<?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.specialanalysis.RStatOrgPvPermeabilityMMapper">

    <resultMap id="BaseResultMap" type="com.njcn.harmonic.pojo.po.RStatOrgPvPermeabilityM">
            <id property="dataDate" column="data_date" jdbcType="DATE"/>
            <id property="orgNo" column="org_no" jdbcType="VARCHAR"/>
            <id property="permeabilityType" column="permeability_type" jdbcType="VARCHAR"/>
            <id property="monitoringObject" column="monitoring_object" jdbcType="VARCHAR"/>
            <result property="areaNum" column="area_num" jdbcType="INTEGER"/>
            <result property="overMaxNum" column="over_max_num" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        data_date,org_no,permeability_type,
        monitoring_object,area_num,over_max_num
    </sql>

    <select id="getPermeabilityList" resultType="com.njcn.harmonic.pojo.vo.PermeabilityVO">
        select
            org_no as orgId,
            monitoring_object as monitoringObject,
            sum(if(permeability_type = #{condMap.Rate_0_25}, area_num, 0)) as areaNum25,
            sum(if(permeability_type = #{condMap.Rate_25_50}, area_num, 0)) as areaNum50,
            sum(if(permeability_type = #{condMap.Rate_50_75}, area_num, 0)) as areaNum75,
            sum(if(permeability_type = #{condMap.Rate_75_100}, area_num, 0)) as areaNum99,
            sum(if(permeability_type =  #{condMap.Rate_100}, area_num, 0)) as areaNum100,
            truncate(ifnull(sum(over_max_num) / sum(area_num), 0) * 100,2) as overMaxRate
        from r_stat_org_pv_permeability_m
        where org_no in
        <foreach collection="condMap.orgIdList" item="id" open="(" close=")" separator=",">
            #{id}
        </foreach>
        <if test="condMap.startTime != null and condMap.startTime != ''">
            and DATE_FORMAT(data_date, '%Y-%m-%d') &gt;= DATE_FORMAT(#{condMap.startTime}, '%Y-%m-%d')
        </if>
        <if test="condMap.endTime != null and condMap.endTime != ''">
            and DATE_FORMAT(data_date, '%Y-%m-%d') &lt;= DATE_FORMAT(#{condMap.endTime}, '%Y-%m-%d')
        </if>

        group by org_no, monitoring_object
    </select>
</mapper>
