<?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.interfaces.mapper.StatisticsMapper">
    <resultMap type="com.ruoyi.interfaces.domain.Statistics" id="baseResultMap">
        <id column="SRV_ID" jdbcType="VARCHAR" property="srvId"/>
        <result column="CATE_CODE" jdbcType="VARCHAR" property="cateCode"/>
        <result column="CATE_NAME" jdbcType="VARCHAR" property="cateName"/>
        <result column="NAME" jdbcType="VARCHAR" property="name"/>
        <result column="SERVICE_SOURCE" jdbcType="VARCHAR" property="serviceSource"/>
        <result property="serviceDept" column="SERVICE_DEPT" jdbcType="VARCHAR"/>
        <result property="manageName" column="MANAGE_NAME" jdbcType="VARCHAR"/>
        <result property="releaseTime" column="RELEASE_TIME" jdbcType="TIMESTAMP"/>
        <result property="developUnit" column="DEVELOP_UNIT" jdbcType="VARCHAR"/>
        <result property="developContacter" column="DEVELOP_CONTACTER" jdbcType="VARCHAR"/>
        <result property="maintainUnit" column="MAINTAIN_UNIT" jdbcType="VARCHAR"/>
        <result property="maintainContacer" column="MAINTAIN_CONTACER" jdbcType="VARCHAR"/>
        <result column="DATA_RANGE" property="dataRange" jdbcType="VARCHAR"/>
        <result column="APPLY_NUM" property="applyNum" jdbcType="INTEGER"/>
        <result column="DATA_NUM" property="dataNum" jdbcType="INTEGER"/>
    </resultMap>
    <sql id="table_columns">
        P
        .
        UP_CYCL
        ,
            P.OPEN_CNDTN,
            P.AD_NAME,
            P.DATA_FIELD,
            P.UPTM,
            P.RLSTM,
            P.DATA_RANGE,
            P.APPLY_NUM,
            P.DATA_NUM,
            P.SRV_ID,
            P.CATE_CODE,
            C.CATE_NAME,
            P.NAME,
            P.TYPE,
            P.CNT,
            P.USER_ID,
            P.TM,
            P.SERVICE_SOURCE,
            P.SERVICE_DEPT,
            P.MANAGE_NAME,
            P.RELEASE_TIME,
            P.DEVELOP_UNIT,
            P.DEVELOP_CONTACTER,
            P.MAINTAIN_UNIT,
            P.MAINTAIN_CONTACER,
            P.VIEW_NUM
    </sql>
    <select id="getStatisticsData" resultMap="baseResultMap">
        select
        <include refid="table_columns"/>
        from PT_SERVICE P
        LEFT JOIN SYS_CATE C on P.CATE_CODE = C.CATE_CODE
    </select>

    <select id="serviceByCnt" resultMap="baseResultMap">
        SELECT *
        FROM (select *
              from PT_SERVICE
              WHERE STATUS = '1'
              ORDER BY CNT DESC) A limit 10
    </select>
    <select id="viewNumByCity" resultType="com.ruoyi.interfaces.domain.vo.StatisticsVo">
        select city as name, count(*) AS value
        FROM view_log
        group by city
    </select>
    <select id="keywords" resultType="com.ruoyi.interfaces.domain.vo.StatisticsVo">
        SELECT name, value
        FROM keywords
    </select>
    <select id="getServiceTotal" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM PT_SERVICE
    </select>
    <select id="getViewNum" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM view_log
    </select>
    <select id="getUserNum" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM sys_user
    </select>
    <select id="getDataSetDownloadNum" resultType="java.lang.Integer">
        SELECT IFNULL(SUM(DOWN_NUM), 0)
        FROM PT_SERVICE
    </select>
    <select id="getCnt" resultType="java.lang.Integer">
        SELECT SUM(CNT)
        FROM PT_SERVICE
    </select>
    <select id="getDataSetNum" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM PT_SERVICE_FILE
    </select>
    <select id="getDeptNum" resultType="java.lang.Integer">
        SELECT COUNT(distinct SERVICE_DEPT)
        FROM PT_SERVICE
    </select>
    <select id="getCateNum" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM SYS_CATE
        WHERE CATE_TABLE = 'PT_SERVICE'
    </select>
</mapper>
