<?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.usky.fire.mapper.ReportConfigMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.usky.fire.domain.ReportConfig">
        <id column="id" property="id" />
        <result column="report_name" property="reportName" />
        <result column="delete_flag" property="deleteFlag" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="tenant_id" property="tenantId" />
    </resultMap>
    <select id="configNumList1" resultType="com.usky.fire.service.vo.ReportConfigVO">
        SELECT d.id,d.report_name as reportName,IF(report_id IS NULL,0,COUNT(*)) AS
        indexNum1
        FROM report_config d
        LEFT JOIN report_index_config e ON e.report_id = d.id
        <where>
            <if test="tenantId != null and tenantId != ''">
                and d.tenant_id = #{tenantId}
            </if>
            and d.delete_flag = 0
        </where>
        GROUP BY d.id
    </select>
    <select id="configNumList" resultType="com.usky.fire.service.vo.ReportConfigVO">
        SELECT d.id,IF(report_id IS NULL,0,COUNT(*)) AS
        indexNum1
        FROM report_config d
        LEFT JOIN report_index_config e ON e.report_id = d.id
        <where>
            <if test="tenantId != null and tenantId != ''">
                and d.tenant_id = #{tenantId}
            </if>
            <if test="indexGrade != null and indexGrade != ''">
                and e.index_grade = #{indexGrade}
            </if>
            and d.delete_flag = 0
        </where>
        GROUP BY d.id
    </select>
</mapper>
