<?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.lightinit.hsdataplatform.mapper.ResourceCatelogMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="parent_id" jdbcType="BIGINT" property="parentId" />
    <result column="catelog_type" jdbcType="VARCHAR" property="catelogType" />
    <result column="catelog_code" jdbcType="VARCHAR" property="catelogCode" />
    <result column="catelog_name" jdbcType="VARCHAR" property="catelogName" />
    <result column="catelog_level" jdbcType="VARCHAR" property="catelogLevel" />
    <result column="is_open" jdbcType="TINYINT" property="isOpen" />
    <result column="is_share" jdbcType="TINYINT" property="isShare" />
    <result column="is_data_catelog" jdbcType="TINYINT" property="isDataCatelog" />
    <result column="is_api_catelog" jdbcType="TINYINT" property="isApiCatelog" />
    <result column="is_microapp_catelog" jdbcType="TINYINT" property="isMicroappCatelog" />
    <result column="catelog_img" jdbcType="VARCHAR" property="catelogImg" />
    <result column="view_order" jdbcType="INTEGER" property="viewOrder" />
    <result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
    <result column="created_by" jdbcType="BIGINT" property="createdBy" />
    <result column="deleted_at" jdbcType="TIMESTAMP" property="deletedAt" />
    <result column="deleted_by" jdbcType="BIGINT" property="deletedBy" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, parent_id, catelog_type, catelog_code, catelog_name, catelog_level, is_open, 
    is_share, is_data_catelog, is_api_catelog, is_microapp_catelog, catelog_img, view_order, 
    created_at, created_by, deleted_at, deleted_by
  </sql>
  <select id="selectByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelogExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from resource_catelog
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from resource_catelog
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    delete from resource_catelog
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <delete id="deleteByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelogExample">
    delete from resource_catelog
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_catelog (parent_id, catelog_type, catelog_code, 
      catelog_name, catelog_level, is_open, 
      is_share, is_data_catelog, is_api_catelog, 
      is_microapp_catelog, catelog_img, view_order, 
      created_at, created_by, deleted_at, 
      deleted_by)
    values (#{parentId,jdbcType=BIGINT}, #{catelogType,jdbcType=VARCHAR}, #{catelogCode,jdbcType=VARCHAR}, 
      #{catelogName,jdbcType=VARCHAR}, #{catelogLevel,jdbcType=VARCHAR}, #{isOpen,jdbcType=TINYINT}, 
      #{isShare,jdbcType=TINYINT}, #{isDataCatelog,jdbcType=TINYINT}, #{isApiCatelog,jdbcType=TINYINT}, 
      #{isMicroappCatelog,jdbcType=TINYINT}, #{catelogImg,jdbcType=VARCHAR}, #{viewOrder,jdbcType=INTEGER}, 
      #{createdAt,jdbcType=TIMESTAMP}, #{createdBy,jdbcType=BIGINT}, #{deletedAt,jdbcType=TIMESTAMP}, 
      #{deletedBy,jdbcType=BIGINT})
  </insert>
  <insert id="insertSelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    <selectKey keyProperty="id" order="AFTER" resultType="java.lang.Long">
      SELECT LAST_INSERT_ID()
    </selectKey>
    insert into resource_catelog
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="parentId != null">
        parent_id,
      </if>
      <if test="catelogType != null">
        catelog_type,
      </if>
      <if test="catelogCode != null">
        catelog_code,
      </if>
      <if test="catelogName != null">
        catelog_name,
      </if>
      <if test="catelogLevel != null">
        catelog_level,
      </if>
      <if test="isOpen != null">
        is_open,
      </if>
      <if test="isShare != null">
        is_share,
      </if>
      <if test="isDataCatelog != null">
        is_data_catelog,
      </if>
      <if test="isApiCatelog != null">
        is_api_catelog,
      </if>
      <if test="isMicroappCatelog != null">
        is_microapp_catelog,
      </if>
      <if test="catelogImg != null">
        catelog_img,
      </if>
      <if test="viewOrder != null">
        view_order,
      </if>
      <if test="createdAt != null">
        created_at,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="deletedAt != null">
        deleted_at,
      </if>
      <if test="deletedBy != null">
        deleted_by,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="parentId != null">
        #{parentId,jdbcType=BIGINT},
      </if>
      <if test="catelogType != null">
        #{catelogType,jdbcType=VARCHAR},
      </if>
      <if test="catelogCode != null">
        #{catelogCode,jdbcType=VARCHAR},
      </if>
      <if test="catelogName != null">
        #{catelogName,jdbcType=VARCHAR},
      </if>
      <if test="catelogLevel != null">
        #{catelogLevel,jdbcType=VARCHAR},
      </if>
      <if test="isOpen != null">
        #{isOpen,jdbcType=TINYINT},
      </if>
      <if test="isShare != null">
        #{isShare,jdbcType=TINYINT},
      </if>
      <if test="isDataCatelog != null">
        #{isDataCatelog,jdbcType=TINYINT},
      </if>
      <if test="isApiCatelog != null">
        #{isApiCatelog,jdbcType=TINYINT},
      </if>
      <if test="isMicroappCatelog != null">
        #{isMicroappCatelog,jdbcType=TINYINT},
      </if>
      <if test="catelogImg != null">
        #{catelogImg,jdbcType=VARCHAR},
      </if>
      <if test="viewOrder != null">
        #{viewOrder,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        #{deletedBy,jdbcType=BIGINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelogExample" resultType="java.lang.Long">
    select count(*) from resource_catelog
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update resource_catelog
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=BIGINT},
      </if>
      <if test="record.parentId != null">
        parent_id = #{record.parentId,jdbcType=BIGINT},
      </if>
      <if test="record.catelogType != null">
        catelog_type = #{record.catelogType,jdbcType=VARCHAR},
      </if>
      <if test="record.catelogCode != null">
        catelog_code = #{record.catelogCode,jdbcType=VARCHAR},
      </if>
      <if test="record.catelogName != null">
        catelog_name = #{record.catelogName,jdbcType=VARCHAR},
      </if>
      <if test="record.catelogLevel != null">
        catelog_level = #{record.catelogLevel,jdbcType=VARCHAR},
      </if>
      <if test="record.isOpen != null">
        is_open = #{record.isOpen,jdbcType=TINYINT},
      </if>
      <if test="record.isShare != null">
        is_share = #{record.isShare,jdbcType=TINYINT},
      </if>
      <if test="record.isDataCatelog != null">
        is_data_catelog = #{record.isDataCatelog,jdbcType=TINYINT},
      </if>
      <if test="record.isApiCatelog != null">
        is_api_catelog = #{record.isApiCatelog,jdbcType=TINYINT},
      </if>
      <if test="record.isMicroappCatelog != null">
        is_microapp_catelog = #{record.isMicroappCatelog,jdbcType=TINYINT},
      </if>
      <if test="record.catelogImg != null">
        catelog_img = #{record.catelogImg,jdbcType=VARCHAR},
      </if>
      <if test="record.viewOrder != null">
        view_order = #{record.viewOrder,jdbcType=INTEGER},
      </if>
      <if test="record.createdAt != null">
        created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.createdBy != null">
        created_by = #{record.createdBy,jdbcType=BIGINT},
      </if>
      <if test="record.deletedAt != null">
        deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="record.deletedBy != null">
        deleted_by = #{record.deletedBy,jdbcType=BIGINT},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update resource_catelog
    set id = #{record.id,jdbcType=BIGINT},
      parent_id = #{record.parentId,jdbcType=BIGINT},
      catelog_type = #{record.catelogType,jdbcType=VARCHAR},
      catelog_code = #{record.catelogCode,jdbcType=VARCHAR},
      catelog_name = #{record.catelogName,jdbcType=VARCHAR},
      catelog_level = #{record.catelogLevel,jdbcType=VARCHAR},
      is_open = #{record.isOpen,jdbcType=TINYINT},
      is_share = #{record.isShare,jdbcType=TINYINT},
      is_data_catelog = #{record.isDataCatelog,jdbcType=TINYINT},
      is_api_catelog = #{record.isApiCatelog,jdbcType=TINYINT},
      is_microapp_catelog = #{record.isMicroappCatelog,jdbcType=TINYINT},
      catelog_img = #{record.catelogImg,jdbcType=VARCHAR},
      view_order = #{record.viewOrder,jdbcType=INTEGER},
      created_at = #{record.createdAt,jdbcType=TIMESTAMP},
      created_by = #{record.createdBy,jdbcType=BIGINT},
      deleted_at = #{record.deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{record.deletedBy,jdbcType=BIGINT}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    update resource_catelog
    <set>
      <if test="parentId != null">
        parent_id = #{parentId,jdbcType=BIGINT},
      </if>
      <if test="catelogType != null">
        catelog_type = #{catelogType,jdbcType=VARCHAR},
      </if>
      <if test="catelogCode != null">
        catelog_code = #{catelogCode,jdbcType=VARCHAR},
      </if>
      <if test="catelogName != null">
        catelog_name = #{catelogName,jdbcType=VARCHAR},
      </if>
      <if test="catelogLevel != null">
        catelog_level = #{catelogLevel,jdbcType=VARCHAR},
      </if>
      <if test="isOpen != null">
        is_open = #{isOpen,jdbcType=TINYINT},
      </if>
      <if test="isShare != null">
        is_share = #{isShare,jdbcType=TINYINT},
      </if>
      <if test="isDataCatelog != null">
        is_data_catelog = #{isDataCatelog,jdbcType=TINYINT},
      </if>
      <if test="isApiCatelog != null">
        is_api_catelog = #{isApiCatelog,jdbcType=TINYINT},
      </if>
      <if test="isMicroappCatelog != null">
        is_microapp_catelog = #{isMicroappCatelog,jdbcType=TINYINT},
      </if>
      <if test="catelogImg != null">
        catelog_img = #{catelogImg,jdbcType=VARCHAR},
      </if>
      <if test="viewOrder != null">
        view_order = #{viewOrder,jdbcType=INTEGER},
      </if>
      <if test="createdAt != null">
        created_at = #{createdAt,jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy,jdbcType=BIGINT},
      </if>
      <if test="deletedAt != null">
        deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      </if>
      <if test="deletedBy != null">
        deleted_by = #{deletedBy,jdbcType=BIGINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    update resource_catelog
    set parent_id = #{parentId,jdbcType=BIGINT},
      catelog_type = #{catelogType,jdbcType=VARCHAR},
      catelog_code = #{catelogCode,jdbcType=VARCHAR},
      catelog_name = #{catelogName,jdbcType=VARCHAR},
      catelog_level = #{catelogLevel,jdbcType=VARCHAR},
      is_open = #{isOpen,jdbcType=TINYINT},
      is_share = #{isShare,jdbcType=TINYINT},
      is_data_catelog = #{isDataCatelog,jdbcType=TINYINT},
      is_api_catelog = #{isApiCatelog,jdbcType=TINYINT},
      is_microapp_catelog = #{isMicroappCatelog,jdbcType=TINYINT},
      catelog_img = #{catelogImg,jdbcType=VARCHAR},
      view_order = #{viewOrder,jdbcType=INTEGER},
      created_at = #{createdAt,jdbcType=TIMESTAMP},
      created_by = #{createdBy,jdbcType=BIGINT},
      deleted_at = #{deletedAt,jdbcType=TIMESTAMP},
      deleted_by = #{deletedBy,jdbcType=BIGINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
  <select id="selectResourceCatelogByCode" resultType="com.lightinit.hsdataplatform.entity.ResourceCatelog">
    <if test="catelogCode != null and catelogCode !=''">
      <bind name="catelogCode" value="catelogCode + '%'" />
    </if>
    SELECT *
    FROM resource_catelog
    WHERE catelog_code LIKE #{catelogCode}
  </select>
  <select id="queryList" parameterType="com.lightinit.hsdataplatform.model.admin.CatelogCountSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.CatelogCountListModel">
    <!--SELECT rc1.id-->
<!--, rc1.`catelog_name`-->
<!--, SUM(rvt1.`view_times`) viewTimesData-->
<!--, SUM(apply1.`apply_times`) applyCountdata-->
<!--, SUM(apply1.`follow_times`) followData-->
<!--&#45;&#45; , SUM(apply1.`user_count`)-->
<!--, SUM(rvt2.`view_times`) viewTimesApi-->
<!--, SUM(apply2.`apply_times`) applyCountApi-->
<!--, SUM(apply2.`follow_times`) followApi-->
<!--&#45;&#45; , SUM(apply2.`user_count`)-->
<!--, SUM(rvt3.`view_times`) viewTimesaMicroapp-->
<!--, SUM(apply3.`apply_times`) applyCountMicroapp-->
<!--, SUM(apply3.`follow_times`) followMicroapp-->
<!--&#45;&#45; , SUM(apply3.`user_count`)-->
<!--FROM resource_catelog rc1-->
<!--LEFT JOIN resource_catelog rc2 ON rc2.`catelog_code` LIKE CONCAT(rc1.`catelog_code`, '%')-->
<!--LEFT JOIN resource r ON r.`catelog_theme` = rc2.`id`-->
<!--LEFT JOIN resource_data rd ON r.`id` = rd.`id` AND r.`resource_type`= '数据'-->
<!--LEFT JOIN resource_view_times rvt1 ON rd.`id` = rvt1.`id`-->
<!--LEFT JOIN (-->
	<!--SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times, COUNT(rf.`id`) follow_times-->
	<!--FROM publish_info p-->
	<!--LEFT JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`-->
	<!--LEFT JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`-->
	<!--LEFT JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`-->
	<!--GROUP BY p.`resource_id`-->
<!--) apply1 ON rd.`id` = apply1.`resource_id`-->
<!--LEFT JOIN resource_api api ON r.`id` = api.`id` AND r.`resource_type`= 'API'-->
<!--LEFT JOIN resource_view_times rvt2 ON api.`id` = rvt2.`id`-->
<!--LEFT JOIN (-->
	<!--SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times, COUNT(rf.`id`) follow_times-->
	<!--FROM publish_info p-->
	<!--LEFT JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`-->
	<!--LEFT JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`-->
	<!--LEFT JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`-->
	<!--GROUP BY p.`resource_id`-->
<!--) apply2 ON api.`id` = apply2.`resource_id`-->
<!--LEFT JOIN resource_microapp rm ON r.`id` = rm.`id` AND r.`resource_type`= '微应用'-->
<!--LEFT JOIN resource_view_times rvt3 ON rm.`id` = rvt3.`id`-->
<!--LEFT JOIN (-->
	<!--SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times, COUNT(rf.`id`) follow_times-->
	<!--FROM publish_info p-->
	<!--LEFT JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`-->
	<!--LEFT JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`-->
	<!--LEFT JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`-->
	<!--GROUP BY p.`resource_id`-->
<!--) apply3 ON rm.`id` = apply3.`resource_id`-->
<!--WHERE rc1.`catelog_type` = '主题分类' AND rc1.`parent_id` IS NULL-->

    <!--<if test="catelog != null and catelog.length() > 0">-->
      <!--AND rc1.id = #{catelog}-->
    <!--</if>-->
    <!--<if test="fromDate != null">-->
      <!--AND r.register_date &gt;= #{fromDate}-->
    <!--</if>-->
    <!--<if test="toDate != null">-->
      <!--AND r.register_date &lt; #{toDate}-->
    <!--</if>-->
    <!--GROUP BY rc1.id, rc1.`catelog_name`-->
    SELECT rc1.id
    , rc1.`catelog_name`
    , SUM(rvt1.`view_times`) viewTimesData
    , SUM(apply1.`apply_times`) applyCountdata
    , SUM(flow1.`follow_times`) followData
    -- , SUM(apply1.`user_count`)
    , SUM(rvt2.`view_times`) viewTimesApi
    , SUM(apply2.`apply_times`) applyCountApi
    , SUM(flow2.`follow_times`) followApi
    -- , SUM(apply2.`user_count`)
    , SUM(rvt3.`view_times`) viewTimesMicroapp
    , SUM(apply3.`apply_times`) applyCountMicroapp
    , SUM(flow3.`follow_times`) followMicroapp
    -- , SUM(apply3.`user_count`)
    FROM resource_catelog rc1
    LEFT JOIN resource_catelog rc2 ON rc2.`catelog_code` LIKE CONCAT(rc1.`catelog_code`, '%')
    LEFT JOIN resource r ON r.`catelog_theme` = rc2.`id`
    LEFT JOIN resource_data rd ON r.`id` = rd.`id` AND r.`resource_type`= '数据'
    LEFT JOIN resource_view_times rvt1 ON rd.`id` = rvt1.`id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) apply1 ON rd.`id` = apply1.`resource_id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(rf.`id`) follow_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) flow1 ON rd.`id` = flow1.`resource_id`
    LEFT JOIN resource_api api ON r.`id` = api.`id` AND r.`resource_type`= 'API'
    LEFT JOIN resource_view_times rvt2 ON api.`id` = rvt2.`id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) apply2 ON api.`id` = apply2.`resource_id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(rf.`id`) follow_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) flow2 ON api.`id` = flow2.`resource_id`
    LEFT JOIN resource_microapp rm ON r.`id` = rm.`id` AND r.`resource_type`= '微应用'
    LEFT JOIN resource_view_times rvt3 ON rm.`id` = rvt3.`id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(ps.`id`) apply_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_auth ra ON ps.`id` = ra.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) apply3 ON rm.`id` = apply3.`resource_id`
    LEFT JOIN (
    SELECT p.`resource_id` resource_id, COUNT(rf.`id`) follow_times
    FROM publish_info p
    JOIN publish_setting ps ON p.`id` = ps.`publish_info_id`
    JOIN resource_follow rf ON ps.`id` = rf.`publish_setting_id`
    GROUP BY p.`resource_id`
    ) flow3 ON rm.`id` = flow3.`resource_id`
    WHERE rc1.`catelog_type` = '主题分类' AND rc1.`parent_id` IS NULL
    <if test="catelog != null and catelog.length() > 0">
    AND rc1.id = #{catelog}
    </if>
    <if test="fromDate != null">
    AND r.register_date &gt;= #{fromDate}
    </if>
    <if test="toDate != null">
    AND r.register_date &lt; #{toDate}
    </if>
    GROUP BY rc1.id, rc1.`catelog_name`

  </select>


  <!--sun-->
  <select id="getEveryThemeTotal" parameterType="com.lightinit.hsdataplatform.model.admin.StatisiticSearchModel" resultType="map">
    SELECT CONCAT(A.catelog_name,'-',A.resource_type) AS title ,COUNT(*) AS total FROM(
    SELECT rc.catelog_code,rc.catelog_name,r.id,r.resource_type,r.resource_name,r.catelog_type,catelog_theme
    FROM resource_data rd
    INNER JOIN resource r ON r.id=rd.id
    INNER JOIN resource_catelog rc ON r.catelog_theme=rc.id
    WHERE rc.catelog_code LIKE '001%'
    <if test="registerFrom !=null">
      AND r.created_at &gt;= #{registerFrom}
    </if>
    <if test="registerTo !=null">
      AND r.created_at &lt;= #{registerTo}
    </if>
    ) AS A
    GROUP BY A.resource_type,A.catelog_name

    UNION

    SELECT CONCAT(B.catelog_name,'-',B.service_type),COUNT(*) FROM(
    SELECT sa.service_type,rc.catelog_type,rc.catelog_code,rc.catelog_name
    FROM resource_api sa
    INNER JOIN resource r ON r.id=sa.id
    INNER JOIN resource_catelog rc ON rc.id=r.catelog_theme
    WHERE rc.catelog_code LIKE '001%'
    <if test="registerFrom !=null">
      AND r.created_at &gt;= #{registerFrom}
    </if>
    <if test="registerTo !=null">
      AND r.created_at &lt;= #{registerTo}
    </if>
    ) AS B
    GROUP BY B.catelog_name,B.service_type

  UNION

  SELECT CONCAT(C.catelog_name,'-',C.resource_type),COUNT(*) FROM(
  SELECT rc.catelog_type,rc.catelog_code,rc.catelog_name,r.resource_type
  FROM resource_microapp rm
  INNER JOIN resource r ON r.id=rm.id
  INNER JOIN resource_catelog rc ON rc.id=r.catelog_theme
  WHERE rc.catelog_code LIKE '001%'
  <if test="registerFrom !=null">
      AND r.created_at &gt;= #{registerFrom}
  </if>
  <if test="registerTo !=null">
      AND r.created_at &lt;= #{registerTo}
  </if>
  ) AS C
  GROUP BY C.catelog_name,C.resource_type
  </select>

  <!--sun-->
  <select id="getCatelogTypeIsTheme" resultType="string">
    SELECT rc.catelog_name FROM resource_catelog rc
    WHERE rc.catelog_code LIKE '001%'
  </select>

  <!--sun-->
  <select id="getSectorList" resultType="string">
    SELECT sector_name FROM sector
  </select>

  <!--sun-->
  <select id="getEverySectorTotal" parameterType="com.lightinit.hsdataplatform.model.admin.StatisiticSearchModel" resultType="map">
    SELECT CONCAT(s.sector_name,'-',IFNULL(r.resource_type,'其他')) AS title,COUNT(*) AS total
    FROM sector s
    INNER JOIN resource_data rd ON rd.belong_to=s.id
    INNER JOIN resource r ON r.id=rd.id
    <where>
      <if test="registerFrom !=null">
        AND r.created_at &gt;= #{registerFrom}
      </if>
      <if test="registerTo !=null">
        AND r.created_at &lt;= #{registerTo}
      </if>
    </where>
    GROUP BY s.sector_name
    UNION
    SELECT CONCAT(sector_name,'-',IFNULL(service_type,'其他')),COUNT(*) FROM (
    SELECT  s.id,s.sector_name,r.catelog_theme,r.resource_type,ra.service_type
    FROM sector s
    INNER JOIN resource_api ra ON ra.provider=s.id
    INNER JOIN resource r ON r.id=ra.id
    <where>
      <if test="registerFrom !=null">
        AND r.created_at &gt;= #{registerFrom}
      </if>
      <if test="registerTo !=null">
        AND r.created_at &lt;= #{registerTo}
      </if>
    </where>
    ) AS A
    GROUP BY A.sector_name,A.service_type

    UNION

    SELECT CONCAT(s.sector_name,'-',IFNULL(r.resource_type,'其他')),COUNT(*)
    FROM sector s
    INNER JOIN resource_microapp rm ON rm.provider=s.id
    INNER JOIN resource r ON r.id=rm.id
    <where>
      <if test="registerFrom !=null">
        AND r.created_at &gt;= #{registerFrom}
      </if>
      <if test="registerTo !=null">
        AND r.created_at &lt;= #{registerTo}
      </if>
    </where>
    GROUP BY s.sector_name

  </select>

  <!--主题-->
  <!--sun-->
  <select id="getResourceRankByThemeAndResourceToltal" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT catelog_name as `name`,COUNT(r.id) AS `total`
    FROM resource_catelog rc
    LEFT JOIN resource r ON rc.id=r.catelog_theme
    WHERE rc.catelog_type=#{catelogType}
  <if test="dateFrom !=null">
      AND  r.created_at &gt;= #{dateFrom}
  </if>
  <if test="dateTo !=null">
      AND r.created_at  &lt;= #{dateTo}
  </if>
    GROUP BY rc.catelog_name
    ORDER BY total DESC
  <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
  </if>
  </select>
  <!--sun-->
  <select id="getResourceRankByThemeAndApplyTimes" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
       SELECT rc.catelog_name as `name`,COUNT(ra.id) AS `total`
        FROM resource_catelog rc
        LEFT JOIN resource r ON rc.id=r.catelog_theme
        LEFT JOIN publish_info pu ON r.id=pu.resource_id
        LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
        WHERE rc.catelog_type=#{catelogType}
      <if test="dateFrom !=null">
          AND  ra.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
      </if>
        GROUP BY rc.id
        ORDER BY total  DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>
  <!--sun-->
  <select id="getResourceRankByThemeAndTradeTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
   SELECT rc1.catelog_name as `name`,IFNULL(total,0) AS `total` FROM
    resource_catelog rc1
    LEFT JOIN (
    SELECT catelog_name,COUNT(*) AS total,o.created_at
    FROM resource_catelog rc
    INNER JOIN resource r ON rc.id=r.catelog_theme
    INNER JOIN publish_info pu ON r.id=pu.resource_id
    INNER JOIN resource_auth ra ON pu.id=ra.publish_info_id
    INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
    INNER JOIN orders o ON og.order_id=o.id
    WHERE rc.catelog_type=#{catelogType} AND ra.auth_state='授权成功'
    GROUP BY rc.catelog_name) A
    ON rc1.catelog_name=A.catelog_name
    WHERE rc1.catelog_type=#{catelogType}
      <if test="dateFrom !=null">
          AND  A.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
      </if>
    ORDER BY total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>
  <!--sun-->
  <select id="getResourceRankByThemeAndTradeSum" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT rc.catelog_name as `name`,ifnull(SUM(order_amount),0) AS `total`
    FROM resource_catelog rc
    left JOIN resource r ON rc.id=r.catelog_theme
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
    LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
    LEFT JOIN orders o ON og.order_id=o.id
    WHERE rc.catelog_type=#{catelogType}
      <if test="dateFrom !=null">
          AND  o.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
      </if>
    GROUP BY rc.catelog_name
    order by total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>

  <!--部门-->
  <!--sun-->
  <select id="getResourceRankBySectorAndApplyTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT s.sector_name as `name`,COUNT(ra.id) AS `total`
    FROM sector s
    LEFT JOIN resource_data rd ON s.id=rd.belong_to
    LEFT JOIN resource r ON rd.id=r.id
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
  <where>
      <if test="dateFrom !=null">
          AND ra.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
      </if>
  </where>
    GROUP BY s.id
    ORDER BY total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>
 <!--sun-->
  <select id="getResourceRankBySectorAndTradeTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT s1.sector_name as `name`,IFNULL(total,0) AS `total` FROM
    sector s1
    LEFT JOIN (
    SELECT s.id,s.sector_name,COUNT(*) AS total,o.created_at
    FROM sector s
    LEFT JOIN resource_data rd ON s.id=rd.belong_to
    INNER JOIN resource r ON rd.id=r.id
    INNER JOIN publish_info pu ON r.id=pu.resource_id
    INNER JOIN resource_auth ra ON pu.id=ra.publish_info_id
    INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
    INNER JOIN orders o ON og.order_id=o.id
    GROUP BY s.sector_name) A
    ON s1.id=A.id
  <where>
      <if test="dateFrom !=null">
          AND A.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
      </if>
  </where>
    ORDER BY total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>
 <!--sun-->
  <select id="getResourceRankBySectorAndTradeSum" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT s.sector_name as `name`,IFNULL(SUM(order_amount),0) AS `total`
    FROM sector s
    LEFT JOIN resource_data rd ON s.id=rd.belong_to
     LEFT JOIN resource r ON rd.id=r.id
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
    LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
    LEFT JOIN orders o ON og.order_id=o.id
  <where>
      <if test="dateFrom !=null">
          AND ra.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
      </if>
  </where>
    GROUP BY s.id
    ORDER BY total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>
 <!--sun-->
  <select id="getResourceRankBySectorAndResourceToltal" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT s.sector_name as `name`,COUNT(rd.id) AS `total`
    FROM sector s
    LEFT JOIN resource_data rd ON s.id=rd.belong_to
  <where>
      <if test="dateFrom !=null">
          AND rd.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
          AND rd.created_at  &lt;= #{dateTo}
      </if>
  </where>
    GROUP BY s.id
    ORDER BY total DESC
      <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
      </if>
  </select>

  <!--单个资源-->
  <!--sun-->
  <select id="getResourceRankBySingleResourceAndResourceToltal" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT r.resource_name AS `name`,COUNT(r.id) AS `total`
    FROM resource r
    <where>
      <if test="dateFrom !=null">
        AND  r.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
        AND r.created_at  &lt;= #{dateTo}
      </if>
    </where>
    GROUP BY r.id
    ORDER BY r.created_at
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <!--sun-->
  <select id="getResourceRankBySingleResourceAndApplyTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT r.resource_name AS `name`,COUNT(ra.publish_info_id) AS `total`
    FROM resource r
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
    <where>
      <if test="dateFrom !=null">
        AND  ra.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
        AND ra.created_at  &lt;= #{dateTo}
      </if>
    </where>
    GROUP BY r.id
    ORDER BY total DESC
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>
  <!--sun-->
  <select id="getResourceRankBySingleResourceAndTradeTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT r.resource_name as `name`,COUNT(o.id) AS `total`
    FROM resource r
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
    LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
    LEFT JOIN orders o ON og.order_id=o.id
    <where>
      <if test="dateFrom !=null">
        AND  o.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
        AND o.created_at  &lt;= #{dateTo}
      </if>
    </where>
    GROUP BY r.id
    ORDER BY total DESC
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select> <!--sun-->
  <!--sun-->
  <select id="getResourceRankBySingleResourceAndTradeSum" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
    SELECT r.resource_name as `name`,SUM(o.order_amount) AS `total`
    FROM resource r
    LEFT JOIN publish_info pu ON r.id=pu.resource_id
    LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
    LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
    LEFT JOIN orders o ON og.order_id=o.id
    <where>
      <if test="dateFrom !=null">
        AND  o.created_at &gt;= #{dateFrom}
      </if>
      <if test="dateTo !=null">
        AND o.created_at  &lt;= #{dateTo}
      </if>
    </where>
    GROUP BY r.id
    ORDER BY total DESC
    <if test="page != null" >
      limit ${page.beginIndex},${page.pageSize}
    </if>
  </select>

  <!--用户-->
  <!--sun-->
  <select id="getResourceRankByUserAndApplyTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
        select u.username as `name`,count(ra.id) as total
        from `user` u
        left join resource_auth ra on u.id=ra.applier
        <where>
            <if test="dateFrom !=null">
               AND  ra.created_at &gt;= #{dateFrom}
            </if>
            <if test="dateTo !=null">
                AND ra.created_at  &lt;= #{dateTo}
            </if>
        </where>
        GROUP BY u.id
        ORDER BY total desc
        <if test="page != null" >
          limit ${page.beginIndex},${page.pageSize}
        </if>
    </select>
  <!--sun-->
  <select id="getResourceRankByUserAndTradeTimes" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
        SELECT u1.username AS `name`,IFNULL(total,0) AS `total` FROM
        `user` u1
        LEFT JOIN (
        SELECT u.id,u.username AS `name`,COUNT(o.id) AS total,o.created_at
        FROM `user` u
        LEFT JOIN resource_auth ra ON u.id=ra.applier
        INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
        INNER JOIN orders o ON og.order_id=o.id GROUP BY u.id) AS A
        ON u1.id=A.id
        <where>
            <if test="dateFrom !=null">
                AND A.created_at &gt;= #{dateFrom}
            </if>
            <if test="dateTo !=null">
                AND A.created_at  &lt;= #{dateTo}
            </if>
        </where>
        ORDER BY total DESC
        <if test="page != null" >
            limit ${page.beginIndex},${page.pageSize}
        </if>
  </select>
  <!--sun-->
  <select id="getResourceRankByUserAndTradeSum" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
        SELECT u.username AS `name`,IFNULL(SUM(order_amount),0) AS `total`
        FROM `user` u
        LEFT JOIN resource_auth ra ON u.id=ra.applier
        LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
        LEFT JOIN orders o ON og.order_id=o.id
        <where>
            <if test="dateFrom !=null">
                AND o.created_at &gt;= #{dateFrom}
            </if>
            <if test="dateTo !=null">
                AND o.created_at  &lt;= #{dateTo}
            </if>
        </where>
        GROUP BY u.id
        ORDER BY total DESC
        <if test="page != null" >
            limit ${page.beginIndex},${page.pageSize}
        </if>
  </select>
  <!--sun-->
  <select id="getResourceRankByUserAndResourceToltal" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="com.lightinit.hsdataplatform.model.admin.ResourceRankModel">
        SELECT u1.username as `name`,IFNULL(total,0) as `total` FROM `user`u1
        LEFT JOIN(
        SELECT u.id,u.username AS `name`,COUNT(ra.id) AS total,ra.created_at
        FROM `user` u
        LEFT JOIN resource_auth ra ON u.id=ra.applier
        WHERE ra.auth_state='授权成功' GROUP BY u.id ) AS A ON u1.id=A.id
        <where>
            <if test="dateFrom !=null">
                AND A.created_at &gt;= #{dateFrom}
            </if>
            <if test="dateTo !=null">
                AND A.created_at  &lt;= #{dateTo}
            </if>
        </where>
        ORDER BY total DESC
        <if test="page != null" >
            limit ${page.beginIndex},${page.pageSize}
        </if>
  </select>

  <!--条件分页-->
  <!--sun-->
  <select id="getPagerTotalByTheme" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="long">
    SELECT count(distinct(rc.catelog_name))
    FROM resource_catelog rc
    <if test="category =='资源数量'">
      LEFT JOIN resource r ON rc.id=r.catelog_theme
      <where>
        rc.catelog_type=#{catelogType}
        <if test="dateFrom !=null">
          AND r.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND r.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='申请次数'">
      LEFT JOIN resource r ON rc.id=r.catelog_theme
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
      <where>
        rc.catelog_type=#{catelogType}
        <if test="dateFrom !=null">
          AND ra.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易次数'">
      LEFT JOIN (
      SELECT catelog_name,COUNT(*) AS total,o.created_at
      FROM resource_catelog rc1
      INNER JOIN resource r ON rc1.id=r.catelog_theme
      INNER JOIN publish_info pu ON r.id=pu.resource_id
      INNER JOIN resource_auth ra ON pu.id=ra.publish_info_id
      INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
      INNER JOIN orders o ON og.order_id=o.id
      WHERE rc1.catelog_type=#{catelogType} AND ra.auth_state='授权成功'
      GROUP BY rc1.catelog_name) A
      ON rc.catelog_name=A.catelog_name
      <where>
        rc.catelog_type=#{catelogType}
        <if test="dateFrom !=null">
          AND A.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易金额'">
      LEFT JOIN resource r ON rc.id=r.catelog_theme
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
      LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
      LEFT JOIN orders o ON og.order_id=o.id
      <where>
        rc.catelog_type=#{catelogType}
        <if test="dateFrom !=null">
          AND o.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
  </select>

  <!--sun-->
  <select id="getPagerTotalBySector" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="long">
    SELECT COUNT(DISTINCT(s.sector_name))
    FROM sector s
    <if test="category =='资源数量'">
      LEFT JOIN resource_data rd ON s.id=rd.belong_to
      <where>
        <if test="dateFrom !=null">
          AND rd.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND rd.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='申请次数'">
      LEFT JOIN resource_data rd ON s.id=rd.belong_to
      LEFT JOIN resource r ON rd.id=r.id
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
      <where>
        <if test="dateFrom !=null">
          AND ra.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易次数'">
      LEFT JOIN (
      SELECT s1.id,s1.sector_name,COUNT(*) AS total,o.created_at
      FROM sector s1
      LEFT JOIN resource_data rd ON s1.id=rd.belong_to
      INNER JOIN resource r ON rd.id=r.id
      INNER JOIN publish_info pu ON r.id=pu.resource_id
      INNER JOIN resource_auth ra ON pu.id=ra.publish_info_id
      INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
      INNER JOIN orders o ON og.order_id=o.id
      GROUP BY s1.sector_name) A
      ON s.id=A.id
      <where>
        <if test="dateFrom !=null">
          AND A.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易金额'">
      LEFT JOIN resource_data rd ON s.id=rd.belong_to
      LEFT JOIN resource r ON rd.id=r.id
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON pu.id=ra.publish_info_id
      LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
      LEFT JOIN orders o ON og.order_id=o.id
      <where>
        <if test="dateFrom !=null">
          AND o.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
  </select>

  <!--sun-->
  <select id="getPagerTotalBySingleResource" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="long">
    SELECT COUNT(DISTINCT(r.id))
    FROM resource r
    <if test="category =='资源数量'">
      <where>
        <if test="dateFrom !=null">
          AND  r.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND r.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='申请次数'">
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
      <where>
        <if test="dateFrom !=null">
          AND  ra.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易次数'">
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
      LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
      LEFT JOIN orders o ON og.order_id=o.id
      <where>
        <if test="dateFrom !=null">
          AND  o.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易金额'">
      LEFT JOIN publish_info pu ON r.id=pu.resource_id
      LEFT JOIN resource_auth ra ON ra.publish_info_id=pu.id
      LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
      LEFT JOIN orders o ON og.order_id=o.id
      <where>
        <if test="dateFrom !=null">
          AND  o.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
  </select>

  <!--sun-->
  <select id="getPagerTotalByUser" parameterType="com.lightinit.hsdataplatform.model.admin.RankSearchModel" resultType="long">
        SELECT COUNT(DISTINCT username)
        FROM `user` u
    <if test="category =='资源数量'">
      LEFT JOIN (
      SELECT u1.id,u1.username AS `name`,COUNT(ra.id) AS total,ra.created_at
      FROM `user` u1
      LEFT JOIN resource_auth ra ON u1.id=ra.applier
      WHERE ra.auth_state='授权成功' GROUP BY u1.id ) AS A ON u.id=A.id
      <where>
        <if test="dateFrom !=null">
          AND A.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='申请次数'">
      left join resource_auth ra on u.id=ra.applier
      <where>
        <if test="dateFrom !=null">
          AND  ra.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND ra.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易次数'">
      LEFT JOIN (
      SELECT u1.id,u1.username AS `name`,COUNT(o.id) AS total,o.created_at
      FROM `user` u1
      LEFT JOIN resource_auth ra ON u1.id=ra.applier
      INNER  JOIN order_goods og ON ra.id=og.resource_auth_id
      INNER JOIN orders o ON og.order_id=o.id GROUP BY u1.id) AS A
      ON u.id=A.id
      <where>
        <if test="dateFrom !=null">
          AND A.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND A.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    <if test="category =='交易金额'">
      LEFT JOIN resource_auth ra ON u.id=ra.applier
      LEFT  JOIN order_goods og ON ra.id=og.resource_auth_id
      LEFT JOIN orders o ON og.order_id=o.id
      <where>
        <if test="dateFrom !=null">
          AND o.created_at &gt;= #{dateFrom}
        </if>
        <if test="dateTo !=null">
          AND o.created_at  &lt;= #{dateTo}
        </if>
      </where>
    </if>
    </select>

  <!--sun:主题排名-->
  <select id="getThemeSortTotal" resultType="com.lightinit.hsdataplatform.model.admin.StatisticModel">
  SELECT title `name`,SUM(total) `value`
  FROM(
    SELECT A.catelog_name AS title ,COUNT(*) AS total FROM(
    SELECT rc.catelog_code,rc.catelog_name,r.id,r.resource_type,r.resource_name,r.catelog_type,catelog_theme
    FROM resource_data rd
    INNER JOIN resource r ON r.id=rd.id
    INNER JOIN resource_catelog rc ON r.catelog_theme=rc.id
    WHERE rc.catelog_code LIKE '001%'
    <if test="registerFrom !=null">
      AND Date(r.`created_at`)>= Date(#{registerFrom})
    </if>
    <if test="registerTo !=null">
      AND Date(r.`created_at`) &lt;= Date(#{registerTo})
    </if>
    ) AS A
    GROUP BY A.catelog_name

    UNION ALL

    SELECT B.catelog_name,COUNT(*) FROM(
    SELECT sa.service_type,rc.catelog_type,rc.catelog_code,rc.catelog_name
    FROM resource_api sa
    INNER JOIN resource r ON r.id=sa.id
    INNER JOIN resource_catelog rc ON rc.id=r.catelog_theme
    WHERE rc.catelog_code LIKE '001%'
    <if test="registerFrom !=null">
      AND Date(r.`created_at`)>= Date(#{registerFrom})
    </if>
    <if test="registerTo !=null">
      AND Date(r.`created_at`) &lt;= Date(#{registerTo})
    </if>
    ) AS B
    GROUP BY B.catelog_name

    UNION ALL

     SELECT C.catelog_name,COUNT(*) FROM(
    SELECT rc.catelog_type,rc.catelog_code,rc.catelog_name
    FROM resource_microapp sa
    INNER JOIN resource r ON r.id=sa.id
    INNER JOIN resource_catelog rc ON rc.id=r.catelog_theme
    WHERE rc.catelog_code LIKE '001%'
    <if test="registerFrom !=null">
      AND Date(r.`created_at`)>= Date(#{registerFrom})
    </if>
    <if test="registerTo !=null">
      AND Date(r.`created_at`) &lt;= Date(#{registerTo})
    </if>
     ) AS C
      GROUP BY C.catelog_name
 ) AS D
 GROUP BY D.title
 ORDER BY `value` DESC
  </select>


  <!--sun:部门排名-->
 <select id="getSectorSortList" resultType="com.lightinit.hsdataplatform.model.admin.StatisticModel">
    SELECT title `name`,SUM(total) `value`
    FROM(
    SELECT s.sector_name AS title,COUNT(*) AS total
    FROM sector s
    INNER JOIN resource_data rd ON rd.belong_to=s.id
    INNER JOIN resource r ON r.id=rd.id
   WHERE 1=1
   <if test="registerFrom !=null">
     AND Date(r.`created_at`)>= Date(#{registerFrom})
   </if>
   <if test="registerTo !=null">
     AND Date(r.`created_at`) &lt;= Date(#{registerTo})
   </if>
   GROUP BY s.sector_name

    UNION ALL

    SELECT sector_name AS title,COUNT(*) AS total
    FROM
    ( SELECT s.id,s.sector_name,r.catelog_theme,r.resource_type,ra.service_type
    FROM sector s
    INNER JOIN resource_api ra ON ra.provider=s.id
    INNER JOIN resource r ON r.id=ra.id
    WHERE 1=1
    <if test="registerFrom !=null">
       AND Date(r.`created_at`)>= Date(#{registerFrom})
    </if>
     <if test="registerTo !=null">
       AND Date(r.`created_at`) &lt;= Date(#{registerTo})
    </if>
    ) AS A
    GROUP BY A.sector_name,A.service_type

   UNION ALL

   SELECT sector_name AS title,COUNT(*) AS total
   FROM sector s
   INNER JOIN resource_microapp rm ON rm.provider=s.id
   INNER JOIN resource r ON r.id=rm.id
   WHERE 1=1
   <if test="registerFrom !=null">
     AND Date(r.`created_at`)>= Date(#{registerFrom})
   </if>
   <if test="registerTo !=null">
     AND Date(r.`created_at`) &lt;= Date(#{registerTo})
   </if>
   GROUP BY s.sector_name
   ) AS D
    GROUP BY `name`
   ORDER BY `value` DESC
 </select>
</mapper>