<?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="cn.fateverse.query.mapper.DataSourceManageMapper">

    <resultMap id="QueryDataSourceResult" type="cn.fateverse.query.entity.DataSourceManage">
        <id column="id" property="id"/>
        <result column="ds_name" property="dsName"/>
        <result column="username" property="username"/>
        <result column="password" property="password"/>
        <result column="host" property="host"/>
        <result column="port" property="port"/>
        <result column="type" property="type"/>
        <result column="db_name" property="dbName"/>
        <result column="config_type" property="configType"/>
        <result column="url" property="url"/>
        <result column="remark" property="remark"/>
        <result column="create_by" property="createBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_by" property="updateBy"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <sql id="selectQueryDataSourceVo">
        select id, ds_name, username, `password`, `host`, `port`, args, params, type, db_name, config_type, url, remark, create_by, create_time, update_by, update_time        from data_source_manage
    </sql>



    <select id="selectList" resultMap="QueryDataSourceResult">
        <include refid="selectQueryDataSourceVo"/>
        <where>
            <if test="dsName != null  and dsName != ''"> and ds_name like concat('%', #{dsName}, '%')</if>
            <if test="dbName != null  and dbName != ''"> and db_name like concat('%', #{dbName}, '%')</if>
            <if test="configType != null "> and config_type = #{configType}</if>
        </where>
    </select>

    <select id="selectById" resultMap="QueryDataSourceResult">
        <include refid="selectQueryDataSourceVo"/>
        where id = #{id}
    </select>

    <insert id="insert" >
        insert into data_source_manage
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dsName != null">ds_name,</if>
            <if test="username != null">username,</if>
            <if test="password != null">`password`,</if>
            <if test="host != null">`host`,</if>
            <if test="port != null">`port`,</if>
            <if test="args != null and args != ''">args,</if>
            <if test="params != null and params != ''">params,</if>
            <if test="type != null">type,</if>
            <if test="dbName != null">db_name,</if>
            <if test="configType != null">config_type,</if>
            <if test="url != null">url,</if>
            <if test="createBy != null and createBy != ''">create_by,</if>
            <if test="createTime != null ">create_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dsName != null">#{dsName},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="host != null">#{host},</if>
            <if test="port != null">#{port},</if>
            <if test="args != null and args != ''">#{args},</if>
            <if test="params != null and params != ''">#{params},</if>
            <if test="type != null">#{type},</if>
            <if test="dbName != null">#{dbName},</if>
            <if test="configType != null">#{configType},</if>
            <if test="url != null">#{url},</if>
            <if test="createBy != null and createBy != ''">#{createBy},</if>
            <if test="createTime != null ">#{createTime},</if>
        </trim>
    </insert>

    <update id="update">
        update data_source_manage
        <set>
            <if test="dsName != null">ds_name = #{dsName},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">`password` = #{password},</if>
            <if test="host != null">`host` = #{host},</if>
            <if test="port != null">`port` = #{port},</if>
            <if test="args != null and args != ''">args = #{args},</if>
            <if test="params != null and params != ''">params = #{params},</if>
            <if test="type != null">type = #{type},</if>
            <if test="dbName != null">db_name = #{dbName},</if>
            <if test="configType != null">config_type = #{configType},</if>
            <if test="url != null">url = #{url},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="updateTime != null ">update_time = #{updateTime},</if>
        </set>
        where id = #{id}
    </update>

    <delete id="deleteById">
        delete from data_source_manage
        where id = #{id}
    </delete>

    <delete id="deleteBatchByIdList" parameterType="Long">
        delete from data_source_manage
        where id in
        <foreach collection="list" open="(" close=")" separator="," item="id">
            #{id}
        </foreach>
    </delete>

</mapper>