<?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.upyuns.platform.rs.website.mapper.ApiDocMapper">

    <resultMap id="BaseResultMap" type="com.upyuns.platform.rs.website.entity.ApiDoc">
            <id property="id" column="id" jdbcType="INTEGER"/>
            <result property="name" column="name" jdbcType="VARCHAR"/>
            <result property="docType" column="doc_type" jdbcType="TINYINT"/>
            <result property="docUrl" column="doc_url" jdbcType="VARCHAR"/>
            <result property="jsonContent" column="json_content" jdbcType="VARCHAR"/>
            <result property="rewriteDomain" column="rewrite_domain" jdbcType="VARCHAR"/>
            <result property="openVisit" column="open_visit" jdbcType="TINYINT"/>
            <result property="shareUuid" column="share_uuid" jdbcType="VARCHAR"/>
            <result property="shareInstruction" column="share_instruction" jdbcType="VARCHAR"/>
            <result property="status" column="status" jdbcType="TINYINT"/>
            <result property="isDel" column="is_del" jdbcType="TINYINT"/>
            <result property="createTime" column="create_time" jdbcType="TIMESTAMP"/>
            <result property="createUser" column="create_user" jdbcType="BIGINT"/>
            <result property="lastUpdateTime" column="last_update_time" jdbcType="TIMESTAMP"/>
            <result property="lastUpdateUser" column="last_update_user" jdbcType="BIGINT"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,`name`,doc_type,
        doc_url,json_content,rewrite_domain,
        open_visit,share_uuid,
        share_instruction,status,is_del,
        create_time,create_user,last_update_time,
        last_update_user
    </sql>
    <select id="selectList" resultType="com.upyuns.platform.rs.website.vo.ApiDocTreeVo">
        SELECT
            d.*
        FROM
            api_doc d
                LEFT JOIN api_custom_node n ON n.doc_id = d.id
        WHERE
            d.is_del = 0
            <if test="keyWord != null and keyWord != ''">
                AND d.`name` LIKE concat( '%', #{keyWord}, '%' )
                OR n.node_name LIKE concat( '%', #{keyWord}, '%' )
            </if>
        GROUP BY
            d.id
        ORDER BY d.create_time,d.id desc
    </select>
    <select id="selectListV2" resultType="com.upyuns.platform.rs.website.entity.ApiDoc">
        SELECT
        ad.`id`,
        ad.`name`,
        ad.doc_type,
        ad.doc_url,
        ad.download_url,
        ad.path,
        ad.json_content,
        ad.rewrite_domain,
        ad.open_visit,
        ad.share_uuid,
        ad.share_instruction,
        ad.`status`,
        ad.create_time,
        ad.create_user,
        ad.last_update_time,
        ad.last_update_user
        FROM api_doc ad
        WHERE ad.`is_del` = 0
        <if test="name != null and name != ''">
            AND ad.`name` LIKE concat( '%', #{name}, '%' )
        </if>
        <if test="docType != null">
            AND ad.`doc_type` = #{docType}
        </if>
        <if test="status != null">
            AND ad.`status` = #{status}
        </if>
        <if test="docUrl != null and docUrl != ''">
            AND ad.`doc_url` LIKE concat( '%', #{docUrl}, '%' )
        </if>
        <if test="path != null and path != ''">
            AND ad.`path` LIKE concat( '%', #{path}, '%' )
        </if>
        <if test="openVisit != null and openVisit != 0">
            AND ad.`open_visit` = #{openVisit}
        </if>
        ORDER BY ad.create_time,ad.id desc
    </select>
</mapper>
