<?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.CpComponentLibraryDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.platform.dto.comlibrary.CpComponentLibraryDetailDto">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                        <!-- 库名 -->
    <result column="library_name" jdbcType="VARCHAR" property="libraryName"/>
        <!-- 库别名 -->
    <result column="library_alias" jdbcType="VARCHAR" property="libraryAlias"/>
        <!-- 库文件名 -->
    <result column="file_name" jdbcType="VARCHAR" property="fileName"/>
        <!-- 库文件地址 -->
    <result column="file_path" jdbcType="VARCHAR" property="filePath"/>
        <!-- 使用状态0-可用1-禁用 -->
    <result column="library_status" jdbcType="INTEGER" property="libraryStatus"/>
        <!--  -->
    <result column="library_intro" jdbcType="VARCHAR" property="libraryIntro"/>
        <!-- 版本更新日志 -->
    <result column="change_log" jdbcType="VARCHAR" property="changeLog"/>
        <!-- 组件库版本号 -->
    <result column="library_version" jdbcType="VARCHAR" property="libraryVersion"/>
        <!-- 组件库类别0-公共，1-接口，2-pcbs，3-pccs，4-安卓，5-ios， -->
    <result column="library_type" jdbcType="INTEGER" property="libraryType"/>
        <!-- 创建人 -->
    <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.CpComponentLibrary">
    select
    id
    ,library_name
    ,library_alias
    ,file_name
    ,file_path
    ,library_status
    ,library_intro
    ,change_log
    ,library_version
    ,library_type
    ,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="libraryName != null">
        AND library_name = #{libraryName,jdbcType=VARCHAR}
      </if>
      <if test="libraryAlias != null">
        AND library_alias = #{libraryAlias,jdbcType=VARCHAR}
      </if>
      <if test="fileName != null">
        AND file_name = #{fileName,jdbcType=VARCHAR}
      </if>
      <if test="filePath != null">
        AND file_path = #{filePath,jdbcType=VARCHAR}
      </if>
      <if test="libraryStatus != null">
        AND library_status = #{libraryStatus,jdbcType=INTEGER}
      </if>
      <if test="libraryIntro != null">
        AND library_intro = #{libraryIntro,jdbcType=VARCHAR}
      </if>
      <if test="changeLog != null">
        AND change_log = #{changeLog,jdbcType=VARCHAR}
      </if>
      <if test="libraryVersion != null">
        AND library_version = #{libraryVersion,jdbcType=VARCHAR}
      </if>
      <if test="libraryType != null">
        AND library_type = #{libraryType,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>
<!--      <if test="tenantId != null">-->
<!--        AND tenant_id = #{tenantId,jdbcType=VARCHAR}-->
<!--      </if>-->
    </trim>
  </select>

  <select id="queryLibraryListTree" resultType="net.northking.cctp.platform.dto.comlibrary.CpComLibraryTree" >
    select
    id
    ,library_name as treeName
    ,library_alias as treeAlias
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      1=1
      <if test="libraryName != null">
        AND LOCATE(#{libraryName},library_name) > 0
      </if>
      <if test="libraryStatus != null">
        AND library_status = #{libraryStatus,jdbcType=INTEGER}
      </if>
      <if test="libraryType != null">
        AND library_type = #{libraryType,jdbcType=INTEGER}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      order by library_name
    </trim>
  </select>

  <select id="queryRecordList" resultType="net.northking.cctp.platform.db.entity.CpComponentLibrary">
    select
    id
    ,library_name
    ,library_alias
    ,file_name
    ,file_path
    ,library_status
    ,library_intro
    ,change_log
    ,library_version
    ,library_type
    from
    <include refid="Table_Name"/>
      where library_status = 0
        AND (id in (select distinct library_id from cp_component_list
          where 1=1
          <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="comName != null">
          OR LOCATE(#{comName},library_name) > 0
        </if> )
  </select>

  <select id="queryLibListByNames" resultType="net.northking.cctp.platform.db.entity.CpComponentLibrary"
          parameterType="java.util.List">
    select
    id,library_name,library_status
    from
    <include refid="Table_Name"/>
    where library_name in
    <foreach collection="list" item="name" open="(" separator="," close=")">
      #{name, jdbcType=VARCHAR}
    </foreach>
  </select>
</mapper>