<?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.hsdataportal.mapper.ResourceCatelogMapper">
  <resultMap id="BaseResultMap" type="com.lightinit.hsdataportal.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.hsdataportal.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.hsdataportal.entity.ResourceCatelogExample">
    delete from resource_catelog
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.lightinit.hsdataportal.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.hsdataportal.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.hsdataportal.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.hsdataportal.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.hsdataportal.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="getResourceCatelogNameAndId" resultType="com.lightinit.hsdataportal.model.ResourceCatelogSearchList">
    select rc.id cateLogId,rc.catelog_name cateLogName
      from `publish_info` pi
      join resource r
      on pi.`resource_id` = r.id
      join resource_catelog rc
    <if test="resourceCatelogType=='部门分类'.toString() ">
      on rc.id = r.catelog_sector
    </if>
    <if test="resourceCatelogType=='主题分类'.toString() ">
      on rc.id = r.catelog_theme
    </if>
      where r.resource_type = #{resourceType}
      <if test="platformType=='开放平台'.toString() ">
        AND r.open_type !=""
        AND r.open_type is not null
      </if>
      <if test="platformType=='共享平台'.toString() ">
        AND r.share_type !=""
        AND r.share_type is not null
      </if>
      and pi.`publish_state`= #{publishState}
      group by rc.id,rc.catelog_name
  </select>

  <select id="SearchApiOrMicTagList" resultType="com.lightinit.hsdataportal.model.SearchApiOrMicTagListModel">
    SELECT id,catelog_name,catelog_code
    FROM resource_catelog
    WHERE is_open = 1
    AND  catelog_type = #{resourceCatelogType}
    <if test="resourceType=='API'.toString() ">
      AND is_api_catelog = 1
    </if>
    <if test="resourceType=='微应用'.toString() ">
      AND is_microapp_catelog = 1
    </if>
    and parent_id is NULL
    ORDER BY view_order DESC
    LIMIT 0,9
  </select>

  <select id="selectFourClassify" resultType="com.lightinit.hsdataportal.model.FourResourceCatelogModel">
      select rc.`catelog_name` catelogBasicName ,ra.catelog_name catelogSectorName ,
      rt.catelog_name catelogThemeName, re.catelog_name catelogCustomName
      from resource r
      left join resource_catelog rc
      on r.catelog_basic = rc.id
      left join resource_catelog ra
      on r.catelog_sector = ra.id
      left join resource_catelog rt
      on r.catelog_theme = rt.id
      left join resource_catelog re
      on r.catelog_custom = re.id
      WHERE  r.id = #{id}
  </select>

  <select id="SearchApiOrMicTagOrTagName" resultType="com.lightinit.hsdataportal.model.SearchApiOrMicTagListModel">
    SELECT id,catelog_name,catelog_code
    FROM resource_catelog
    WHERE is_open = 1
    AND  catelog_type = #{resourceCatelogType}
    <if test="resourceType=='API'.toString() ">
      AND is_api_catelog = 1
    </if>
    <if test="resourceType=='微应用'.toString() ">
      AND is_microapp_catelog = 1
    </if>
    <if test="tagName!=null ">
      AND catelog_name = #{tagName}
    </if>
    and parent_id is NULL

  </select>
</mapper>