<?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.lutao.cloud.admin.mapper.SysFileMapper">

    <resultMap id="dataStatisticsMap" type="com.lutao.cloud.admin.api.vo.DataStatistics">
        <result column="dateTime" property="date_time"></result>
        <result column="amount" property="amount"></result>
        <result column="remark" property="remark"></result>
        <result column="dataId" property="data_id"></result>
    </resultMap>

    <select id="getDocTypeData" resultMap="dataStatisticsMap">
        SELECT
            di.doc_type data_id,
            count( 1 ) amount,
            dt."name" remark
        FROM
            doc_info di
                LEFT JOIN doc_type dt ON di.doc_type = dt.id
        GROUP BY
            di.doc_type,dt."name"
    </select>
    
    <select id="getDocTypeDownData" resultMap="dataStatisticsMap">
        SELECT
            di.doc_type data_id,
            SUM(dd.down_count) amount,
            dt."name" remark
        FROM
            doc_info di
                LEFT JOIN doc_type dt ON di.doc_type = dt.id
                LEFT JOIN doc_data dd ON di.id = dd.doc_id
        GROUP BY
            di.doc_type,dt."name"
    </select>

    <select id="getDocTypeNewlyAdded" resultMap="dataStatisticsMap">
        SELECT
            to_char( create_time, 'yyyy-MM-dd' ) date_time,
            count( 1 ) amount
        FROM
            doc_info
        <where>
            <if test="query.startTime != null">
               and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
               and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    create_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getpilotStatus" resultMap="dataStatisticsMap">
        SELECT
            to_char( create_time, 'yyyy-MM-dd' ) date_time,
            count( 1 ) amount,
            pilot_status remark
        FROM
            pilot_opinion
        <where>
            <if test="query.startTime != null">
               and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
               and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char( create_time, 'yyyy-MM-dd' ),
            pilot_status
    </select>

    <select id="getpilotDailyAdd" resultMap="dataStatisticsMap">
        SELECT
            to_char( apply_time, 'yyyy-MM-dd' ) data_time,
            count( 1 ) amount
        FROM
            pilot_info
        <where>
            <if test="query.startTime != null">
                and apply_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and apply_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char( apply_time, 'yyyy-MM-dd' )
    </select>

    <select id="getEffectApplyData" resultMap="dataStatisticsMap">
        SELECT
            to_char( create_time, 'yyyy-MM-dd' ) data_time,
            count( 1 ) amount,
            '申请数量' remark
        FROM
            effect_info
        <where>
            <if test="query.startTime != null">
                and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    create_time,
                    'yyyy-MM-dd')
    </select>


    <select id="getEffectAccessData" resultMap="dataStatisticsMap">
        SELECT
            to_char( assess_time, 'yyyy-MM-dd' ) data_time,
            count( 1 ) amount,
            '审核数量' remark
        FROM
            effect_info
        <where>
            progress = 6
            <if test="query.startTime != null">
                and assess_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and assess_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    assess_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getEffectNotAccessData" resultMap="dataStatisticsMap">
        SELECT
        to_char( create_time, 'yyyy-MM-dd' ) data_time,
        count( 1 ) amount,
        '未审核数量' remark
        FROM
        effect_info
        <where>
            "progress" &lt; 6
            <if test="query.startTime != null">
                and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
        to_char(
        create_time,
        'yyyy-MM-dd')
    </select>

    <select id="getEffectLevelData" resultMap="dataStatisticsMap">
        SELECT "level" remark,
               count( 1 ) amount
        FROM
            effect_info
        <where>
            "progress" = 6
            <if test="query.startTime != null">
                and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            "level"
    </select>

    <select id="getKnowledgeTypeData" resultMap="dataStatisticsMap">
        SELECT
            kt.type_name remark,
            ki.type_id data_id,
            count( 1 ) amount
        FROM
            knowledge_info ki
                LEFT JOIN knowledge_type kt ON ki.type_id = kt.id
        WHERE
            ki.progress = 5
        GROUP BY
            ki.type_id,kt.type_name
    </select>

    <select id="getKnowledgeLevelData" resultMap="dataStatisticsMap">
        SELECT
            ki.kn_level remark,
            count( 1 ) amount
        FROM
            knowledge_info ki
        WHERE
            ki.progress = 5
        GROUP BY
            ki.kn_level
    </select>

    <select id="getKnowledgeDailyData" resultMap="dataStatisticsMap">
        SELECT
            to_char( ki.create_time, 'yyyy-MM-dd' ) data_time,
            count( 1 ) amount
        FROM
            knowledge_info ki
        <where>
            ki."progress" = 5
            <if test="query.startTime != null">
                and ki.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and ki.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    ki.create_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getSpreadMonthData" resultMap="dataStatisticsMap">
        SELECT
            to_char( si.create_time, 'yyyy-MM' ) data_time,
            count( 1 ) amount
        FROM
            spread_info si
        <where>
            <if test="query.startTime != null">
                and si.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and si.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    si.create_time,
                    'yyyy-MM')
    </select>

    <select id="getSpreadDailyData" resultMap="dataStatisticsMap">
        SELECT
            to_char( si.create_time, 'yyyy-MM-dd' ) data_time,
            count( 1 ) amount
        FROM
            spread_info si
        <where>
            <if test="query.startTime != null">
                and si.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and si.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    si.create_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getDemandDailyAddData" resultMap="dataStatisticsMap">
        SELECT
            to_char( di.create_time, 'yyyy-MM-dd' ) data_time,
            COUNT( 1 ) amount
        FROM
            demand_info di
        <where>
            <if test="query.startTime != null">
                and di.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and di.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    di.create_time,
                    'yyyy-MM-dd')
    </select>
    <select id="getDemandDailyReleaseData" resultMap="dataStatisticsMap">
        SELECT
            to_char( di.create_time, 'yyyy-MM-dd' ) data_time,
            COUNT( 1 ) amount
        FROM
            demand_info di
        <where>
            di.progress = 2
            <if test="query.startTime != null">
                and di.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and di.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    di.create_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getDemandDailyDockingData" resultMap="dataStatisticsMap">
        SELECT
            to_char( di.create_time, 'yyyy-MM-dd' )  data_time,
            COUNT( 1 ) amount
        FROM
            demand_info di
        <where>
            di.progress &gt; 3
            <if test="query.startTime != null">
                and di.create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and di.create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char(
                    di.create_time,
                    'yyyy-MM-dd')
    </select>

    <select id="getEquimentData" resultMap="dataStatisticsMap">
        SELECT
            count( 1 ) amount,
            '设备数量' remark
        FROM
            equipment_info
    </select>

    <select id="getPersonnelData" resultMap="dataStatisticsMap">
        SELECT
            count( 1 ) amount,
            '人员资质数量' remark
        FROM
            personnel_info
    </select>

    <select id="getOrganData" resultMap="dataStatisticsMap">
        SELECT
            count( 1 ) amount,
            '机构资质数量' remark
        FROM
            organization_info
    </select>

    <select id="getEquimentDailyData" resultMap="dataStatisticsMap">
        SELECT
            to_char( create_time, 'yyyy-MM-dd' ) data_time,
            COUNT( 1 ) amount
        FROM
            equipment_info
        <where>
            <if test="query.startTime != null">
                and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char( create_time, 'yyyy-MM-dd' )
    </select>

    <select id="getNewsDailyData" resultMap="dataStatisticsMap">
        SELECT
            to_char( create_time, 'yyyy-MM-dd' ) data_time,
            COUNT( 1 ) amount
        FROM
            news_info
        <where>
            <if test="query.startTime != null">
                and create_time &gt;= #{query.startTime}
            </if>
            <if test="query.endTime != null">
                and create_time &lt;= #{query.endTime}
            </if>
        </where>
        GROUP BY
            to_char( create_time, 'yyyy-MM-dd' )
    </select>
</mapper>
