<?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.ruoyi.project.statistics.mapper.StatisticsMapper">

    <resultMap type="Statistics" id="StatisticsResult">
        <result property="plantId" column="plant_id"/>
        <result property="pointId" column="point_id"/>
        <result property="repairId" column="repair_id"/>
        <result property="company" column="company"/>
        <result property="plantName" column="plant_name"/>
        <result property="content" column="content"/>
        <result property="count" column="num"/>
    </resultMap>

    <select id="countPlant" parameterType="Statistics" resultMap="StatisticsResult">
        select plant_name, plant_id, count(1) num
        from t_base_plant d
        <where>
            and approve_status = 2
            and del_flag = 0
            <if test="company!=null and company!=''">and company like concat('%',#{company},'%')</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
        group by plant_name;
    </select>

    <select id="countDevice" parameterType="Statistics" resultMap="StatisticsResult">
        select count(1) num
        from t_base_device
        where plant_id = #{plantId}
          and approve_status = 2
          and del_flag = 0;
    </select>

    <select id="countPoint" parameterType="Statistics" resultMap="StatisticsResult">
        select point_type content, count(1) num
        from t_base_point
        where plant_id = #{plantId}
          and approve_status = 2
          and del_flag = 0
        group by point_type;
    </select>

    <select id="countXlcd" parameterType="Statistics" resultMap="StatisticsResult">
        select leakage_degree content, count(1) num
        from t_check_checkpoints
        where plant_id = #{plantId}
          and approve_status = 2
          and del_flag = 0
          and leakage_degree is not null
          and YEAR(check_date) = #{year}
        group by leakage_degree;
    </select>

    <select id="countPfl" parameterType="Statistics" resultMap="StatisticsResult">
        select d.plant_name,net_test_value,repair_id,point_id,point_type,check_date
        from t_check_checkpoints d left join t_base_plant bp on bp.plant_id=d.plant_id
        <where>
            <if test="plantId!=null">and d.plant_id = #{plantId}</if>
            and d.approve_status = 2
            and YEAR(check_date) = #{year}
            and leakage_degree is not null
            <if test="company!=null and company!=''">and bp.company like concat('%',#{company},'%')</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
        ORDER BY d.plant_id,d.point_type,d.point_id,d.check_date;
    </select>

    <select id="countXlcdByPoint" parameterType="Statistics" resultMap="StatisticsResult">
        select point_type,leakage_degree content, count(1) num
        from t_check_checkpoints d left join t_base_plant bp on bp.plant_id=d.plant_id
        <where>
            and d.approve_status = 2
            and d.del_flag = 0
            and leakage_degree is not null
            and YEAR(check_date) = #{year}
            <if test="company!=null and company!=''">and bp.company like concat('%',#{company},'%')</if>
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScopePlant}
        group by point_type,leakage_degree
        order by point_type;
    </select>
</mapper>
