<?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.ff.base.system.mapper.SysDatasourceMapper">

    <resultMap type="SysDatasource" id="SysDatasourceResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="url"    column="url"    />
        <result property="username"    column="username"    />
        <result property="password"    column="password"    />
        <result property="driverClassName"    column="driver_class_name"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="timeZone"    column="time_zone"    />
        <result property="timeZoneName"    column="time_zone_name"    />
    </resultMap>

    <sql id="selectSysDatasourceVo">
        select id, tenant_id, url,time_zone_name, username, password, driver_class_name, status, create_by, create_time, update_by, update_time, time_zone from sys_datasource
    </sql>

    <select id="selectSysDatasourceList" parameterType="SysDatasource" resultMap="SysDatasourceResult">
        <include refid="selectSysDatasourceVo"/>
        <where>
            <if test="tenantId != null  and tenantId != ''"> and tenant_id = #{tenantId}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="username != null  and username != ''"> and username like concat('%', #{username}, '%')</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
            <if test="driverClassName != null  and driverClassName != ''"> and driver_class_name like concat('%', #{driverClassName}, '%')</if>
            <if test="status != null  and status != ''"> and status = #{status}</if>
            <if test="timeZone != null  and timeZone != ''"> and time_zone = #{timeZone}</if>
            <if test="timeZoneName != null  and timeZoneName != ''"> and time_zone_name = #{timeZoneName}</if>
        </where>
    </select>

    <select id="selectSysDatasourceById" parameterType="Long" resultMap="SysDatasourceResult">
        <include refid="selectSysDatasourceVo"/>
        where id = #{id}
    </select>

    <select id="selectSysDatasourceByTenantId" parameterType="java.lang.String" resultMap="SysDatasourceResult">
        <include refid="selectSysDatasourceVo"/>
        where tenant_id = #{tenantId}
    </select>

    <insert id="insertSysDatasource" parameterType="SysDatasource">
        insert into sys_datasource
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="tenantId != null">tenant_id,</if>
            <if test="url != null">url,</if>
            <if test="username != null">username,</if>
            <if test="password != null">password,</if>
            <if test="driverClassName != null">driver_class_name,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="timeZone != null">time_zone,</if>
            <if test="timeZoneName != null">time_zone_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="tenantId != null">#{tenantId},</if>
            <if test="url != null">#{url},</if>
            <if test="username != null">#{username},</if>
            <if test="password != null">#{password},</if>
            <if test="driverClassName != null">#{driverClassName},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="timeZone != null">#{timeZone},</if>
            <if test="timeZoneName != null">#{timeZoneName},</if>
        </trim>
    </insert>

    <update id="updateSysDatasource" parameterType="SysDatasource">
        update sys_datasource
        <trim prefix="SET" suffixOverrides=",">
            <if test="tenantId != null">tenant_id = #{tenantId},</if>
            <if test="url != null">url = #{url},</if>
            <if test="username != null">username = #{username},</if>
            <if test="password != null">password = #{password},</if>
            <if test="driverClassName != null">driver_class_name = #{driverClassName},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="timeZone != null">time_zone = #{timeZone},</if>
            <if test="timeZoneName != null">time_zone_name = #{timeZoneName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteSysDatasourceById" parameterType="Long">
        delete from sys_datasource where id = #{id}
    </delete>

    <delete id="deleteSysDatasourceByIds" parameterType="String">
        delete from sys_datasource where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

</mapper>
