<?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.ruoyi.generator.mapper.DatasourceMapper">
    
    <resultMap type="Datasource" id="DatasourceResult">
        <result property="datasourceId"    column="datasource_id"    />
        <result property="datasourceName"    column="datasource_name"    />
        <result property="driver"    column="driver"    />
        <result property="url"    column="url"    />
        <result property="user"    column="user"    />
        <result property="password"    column="password"    />
    </resultMap>

    <sql id="selectDatasourceVo">
        select datasource_id, datasource_name, driver, url, user, password from sys_datasource
    </sql>

    <select id="selectDatasourceList" parameterType="Datasource" resultMap="DatasourceResult">
        <include refid="selectDatasourceVo"/>
        <where>  
            <if test="datasourceName != null  and datasourceName != ''"> and datasource_name like concat('%', #{datasourceName}, '%')</if>
            <if test="driver != null  and driver != ''"> and driver = #{driver}</if>
            <if test="url != null  and url != ''"> and url = #{url}</if>
            <if test="user != null  and user != ''"> and user = #{user}</if>
            <if test="password != null  and password != ''"> and password = #{password}</if>
        </where>
    </select>
    
    <select id="selectDatasourceByDatasourceId" parameterType="Long" resultMap="DatasourceResult">
        <include refid="selectDatasourceVo"/>
        where datasource_id = #{datasourceId}
    </select>
        
    <insert id="insertDatasource" parameterType="Datasource">
        insert into sys_datasource
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="datasourceId != null">datasource_id,</if>
            <if test="datasourceName != null">datasource_name,</if>
            <if test="driver != null">driver,</if>
            <if test="url != null">url,</if>
            <if test="user != null">user,</if>
            <if test="password != null">password,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="datasourceId != null">#{datasourceId},</if>
            <if test="datasourceName != null">#{datasourceName},</if>
            <if test="driver != null">#{driver},</if>
            <if test="url != null">#{url},</if>
            <if test="user != null">#{user},</if>
            <if test="password != null">#{password},</if>
         </trim>
    </insert>

    <update id="updateDatasource" parameterType="Datasource">
        update sys_datasource
        <trim prefix="SET" suffixOverrides=",">
            <if test="datasourceName != null">datasource_name = #{datasourceName},</if>
            <if test="driver != null">driver = #{driver},</if>
            <if test="url != null">url = #{url},</if>
            <if test="user != null">user = #{user},</if>
            <if test="password != null">password = #{password},</if>
        </trim>
        where datasource_id = #{datasourceId}
    </update>

    <delete id="deleteDatasourceByDatasourceId" parameterType="Long">
        delete from sys_datasource where datasource_id = #{datasourceId}
    </delete>

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