<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：组件清单 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-08-29 10:24:48  -->
<mapper namespace="net.northking.cctp.platform.db.dao.CpComponentListDao">


  <!-- 请在本文件内添加自定义SQL语句 -->

  <resultMap id="DetailMap" type="net.northking.cctp.platform.dto.comlibrary.CpComponentListDetailDto">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                  <!-- 所属组件库 -->
    <result column="library_id" jdbcType="VARCHAR" property="libraryId"/>
        <!-- 组件名 -->
    <result column="com_name" jdbcType="VARCHAR" property="comName"/>
        <!-- 组件别名 -->
    <result column="com_alias" jdbcType="VARCHAR" property="comAlias"/>
        <!-- 使用类别：0-基础，1-插件2-函数 -->
    <result column="com_category" jdbcType="VARCHAR" property="comCategory"/>
    <result column="com_attributes" jdbcType="VARCHAR" property="comAttributes"/>
        <!-- 组建介绍 -->
    <result column="com_intro" jdbcType="VARCHAR" property="comIntro"/>
        <!-- 是否推荐使用0-推荐，1-不推荐 -->
    <result column="is_deprecated" jdbcType="INTEGER" property="isDeprecated"/>
        <!-- 创建人 -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <!-- 修改人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <!-- 修改时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.platform.db.entity.CpComponentList">
    select
    id
    ,library_id
    ,com_name
    ,com_alias
    ,com_category
    ,com_attributes
    ,com_intro
    ,is_deprecated
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    ,tenant_id
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="libraryId != null">
        AND library_id = #{libraryId,jdbcType=VARCHAR}
      </if>
      <if test="comName != null">
        AND LOCATE(#{comName},com_name) > 0
      </if>
      <if test="comAlias != null">
        AND LOCATE(#{comAlias},com_alias) > 0
      </if>
      <if test="comCategory != null">
        AND LOCATE(#{comCategory},com_category) > 0
      </if>
      <if test="comIntro != null">
        AND com_intro = #{comIntro,jdbcType=VARCHAR}
      </if>
      <if test="isDeprecated != null">
        AND is_deprecated = #{isDeprecated,jdbcType=INTEGER}
      </if>
      <if test="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="updatedBy != null">
        AND updated_by = #{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND updated_time = #{updatedTime,jdbcType=TIMESTAMP}
      </if>
    </trim>
    and library_id in (select id from cp_component_library where library_status = 0)
  </select>

  <select id="queryComListTree" resultType="net.northking.cctp.platform.dto.comlibrary.CpComLibraryTree">
    select
    id
    ,library_id as faId
    ,com_name as treeName
    ,com_alias as treeAlias
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      1=1
      <if test="comName != null">
        AND LOCATE(#{comName},com_name) > 0
      </if>
      <if test="comAlias != null">
        AND LOCATE(#{comAlias},com_alias) > 0
      </if>
      <if test="libraryId != null">
        AND library_id= #{libraryId,jdbcType=VARCHAR}
      </if>
      <if test="isDeprecated != null">
        AND is_deprecated = #{isDeprecated,jdbcType=INTEGER}
      </if>
      order by com_name
    </trim>
  </select>

  <select id="queryRecordList" resultType="net.northking.cctp.platform.db.entity.CpComponentList">
    select
    id
    ,library_id
    ,com_name
    ,com_alias
    ,com_category
    ,com_attributes
    ,com_intro
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      1=1
      <if test="comAlias != null">
        AND LOCATE(#{comAlias},com_alias) > 0
      </if>
      <if test="comName != null">
        AND LOCATE(#{comName},com_name) > 0
      </if>
      <if test="comCategory != null">
        AND LOCATE(#{comCategory},com_category) > 0
      </if>
      <if test="comAttributes != null">
        AND com_attributes REGEXP #{comAttributes}
      </if>
      <if test="isDeprecated != null">
        AND is_deprecated = #{isDeprecated,jdbcType=INTEGER}
      </if>
      <if test="libraryId != null">
        AND library_id= #{libraryId,jdbcType=VARCHAR}
      </if>
      <if test="isCommonlyUse != null">
        AND is_commonly_use = #{isCommonlyUse,jdbcType=INTEGER}
      </if>
      order by com_name
    </trim>
  </select>
</mapper>