<?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.izouma.awesomeadmin.dao.DataSourceInfoMapper" >
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.DataSourceInfo" >
                <id column="id" property="id" jdbcType="INTEGER" />
                                        <result column="del_flag" property="delFlag" jdbcType="CHAR" />
                                <result column="code" property="code" jdbcType="VARCHAR" />
                                <result column="database_type" property="databaseType" jdbcType="VARCHAR" />
                                <result column="url" property="url" jdbcType="VARCHAR" />
                                <result column="username" property="username" jdbcType="VARCHAR" />
                                <result column="password" property="password" jdbcType="VARCHAR" />
                                <result column="database_name" property="databaseName" jdbcType="VARCHAR" />
            </resultMap>
    <sql id="Base_Column_List" >
        <trim  suffixOverrides="," >
            id,

            del_flag,

            code,

            database_type,

            url,

            username,

            password,

            database_name,

            </trim>
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
        select
        <include refid="Base_Column_List" />
        from data_source_info
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer" >
        delete from data_source_info
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.DataSourceInfo" useGeneratedKeys="true" keyProperty="id">
        insert into data_source_info
        <trim prefix="(" suffix=")" suffixOverrides="," >
                <if test="id!= null" >
                id,
            </if>
                <if test="delFlag!= null" >
                del_flag,
            </if>
                <if test="code!= null" >
                code,
            </if>
                <if test="databaseType!= null" >
                database_type,
            </if>
                <if test="url!= null" >
                url,
            </if>
                <if test="username!= null" >
                username,
            </if>
                <if test="password!= null" >
                password,
            </if>
                <if test="databaseName!= null" >
                database_name,
            </if>
            </trim>
        <trim prefix="values (" suffix=")" suffixOverrides="," >
                    <if test="id != null" >
                #{id,jdbcType=INTEGER},
            </if>
                    <if test="delFlag != null" >
                #{delFlag,jdbcType=CHAR},
            </if>
                    <if test="code != null" >
                #{code,jdbcType=VARCHAR},
            </if>
                    <if test="databaseType != null" >
                #{databaseType,jdbcType=VARCHAR},
            </if>
                    <if test="url != null" >
                #{url,jdbcType=VARCHAR},
            </if>
                    <if test="username != null" >
                #{username,jdbcType=VARCHAR},
            </if>
                    <if test="password != null" >
                #{password,jdbcType=VARCHAR},
            </if>
                    <if test="databaseName != null" >
                #{databaseName,jdbcType=VARCHAR},
            </if>
                </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.DataSourceInfo" >
        update data_source_info
        <set >
                    <if test="id != null" >
               id= #{id,jdbcType=INTEGER},
            </if>
                     <if test="delFlag != null" >
               del_flag= #{delFlag,jdbcType=CHAR},
            </if>
                     <if test="code != null" >
               code= #{code,jdbcType=VARCHAR},
            </if>
                     <if test="databaseType != null" >
               database_type= #{databaseType,jdbcType=VARCHAR},
            </if>
                     <if test="url != null" >
               url= #{url,jdbcType=VARCHAR},
            </if>
                     <if test="username != null" >
               username= #{username,jdbcType=VARCHAR},
            </if>
                     <if test="password != null" >
               password= #{password,jdbcType=VARCHAR},
            </if>
                     <if test="databaseName != null" >
               database_name= #{databaseName,jdbcType=VARCHAR},
            </if>
                 </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="queryDataSourceInfoByPage" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DataSourceInfo">
        select <include refid="Base_Column_List"/> from data_source_info
        <where>
            and del_flag = 'N'
                    <if test="record.id != null and !&quot;&quot;.equals(record.id)">
                and  id = #{record.id}
            </if>
                     <if test="record.delFlag != null and !&quot;&quot;.equals(record.delFlag)">
                and  del_flag = #{record.delFlag}
            </if>
                     <if test="record.code != null and !&quot;&quot;.equals(record.code)">
                and  code = #{record.code}
            </if>
                     <if test="record.databaseType != null and !&quot;&quot;.equals(record.databaseType)">
                and  database_type = #{record.databaseType}
            </if>
                     <if test="record.url != null and !&quot;&quot;.equals(record.url)">
                and  url = #{record.url}
            </if>
                     <if test="record.username != null and !&quot;&quot;.equals(record.username)">
                and  username = #{record.username}
            </if>
                     <if test="record.password != null and !&quot;&quot;.equals(record.password)">
                and  password = #{record.password}
            </if>
                     <if test="record.databaseName != null and !&quot;&quot;.equals(record.databaseName)">
                and  database_name = #{record.databaseName}
            </if>
                  <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
             <trim prefix="and (" suffix=")" prefixOverrides="OR" >
                                                                                                                                                                OR  code LIKE concat('%',#{record.searchKey},'%')
                                                                                                    OR  database_type LIKE concat('%',#{record.searchKey},'%')
                                                                                                    OR  url LIKE concat('%',#{record.searchKey},'%')
                                                                                                    OR  username LIKE concat('%',#{record.searchKey},'%')
                                                                                                    OR  password LIKE concat('%',#{record.searchKey},'%')
                                                                                                    OR  database_name LIKE concat('%',#{record.searchKey},'%')
                                                             </trim>
         </if>

            <if test="record.advancedQuery != null and !&quot;&quot;.equals(record.advancedQuery)">
                <foreach item="item" index="index" collection="record.advancedQuery.split('_;')">
                    <choose>
                        <when test="item.indexOf('like') != -1">
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    concat('%',#{itemDetail},'%')
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </when>
                        <otherwise>
                            <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                                <if test="detailIndex == 3">
                                    #{itemDetail}
                                </if>

                                <if test="detailIndex &lt; 3">
                                    ${itemDetail}
                                </if>

                            </foreach>
                        </otherwise>
                    </choose>


                </foreach>


            </if>

        </where>
        order by id desc
    </select>
    <select id="queryAllDataSourceInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DataSourceInfo">
        select <include refid="Base_Column_List"/> from data_source_info
        <where>
            and del_flag = 'N'
                    <if test="id != null and !&quot;&quot;.equals(id)">
                and  id = #{id}
            </if>
                    <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and  del_flag = #{delFlag}
            </if>
                    <if test="code != null and !&quot;&quot;.equals(code)">
                and  code = #{code}
            </if>
                    <if test="databaseType != null and !&quot;&quot;.equals(databaseType)">
                and  database_type = #{databaseType}
            </if>
                    <if test="url != null and !&quot;&quot;.equals(url)">
                and  url = #{url}
            </if>
                    <if test="username != null and !&quot;&quot;.equals(username)">
                and  username = #{username}
            </if>
                    <if test="password != null and !&quot;&quot;.equals(password)">
                and  password = #{password}
            </if>
                    <if test="databaseName != null and !&quot;&quot;.equals(databaseName)">
                and  database_name = #{databaseName}
            </if>
                    <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR" >
                                                                                                                                                                                                                                                OR  code LIKE concat('%',#{searchKey},'%')
                                                                                                                                                        OR  database_type LIKE concat('%',#{searchKey},'%')
                                                                                                                                                        OR  url LIKE concat('%',#{searchKey},'%')
                                                                                                                                                        OR  username LIKE concat('%',#{searchKey},'%')
                                                                                                                                                        OR  password LIKE concat('%',#{searchKey},'%')
                                                                                                                                                        OR  database_name LIKE concat('%',#{searchKey},'%')
                                                                                        </trim>
            </if>
<if test="advancedQuery != null and !&quot;&quot;.equals(advancedQuery)">
    <foreach item="item" index="index" collection="advancedQuery.split('_;')">
        <choose>
            <when test="item.indexOf('like') != -1">
                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                    <if test="detailIndex == 3">
                        concat('%',#{itemDetail},'%')
                    </if>

                    <if test="detailIndex &lt; 3">
                        ${itemDetail}
                    </if>

                </foreach>
            </when>
            <otherwise>
                <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                    <if test="detailIndex == 3">
                        #{itemDetail}
                    </if>

                    <if test="detailIndex &lt; 3">
                        ${itemDetail}
                    </if>

                </foreach>
            </otherwise>
        </choose>


    </foreach>


</if>
        </where>
        order by id desc
    </select>
    <select id="queryDataSourceInfo" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DataSourceInfo">
        select <include refid="Base_Column_List"/> from data_source_info
        <where>
            and del_flag = 'N'
                    <if test="id != null and !&quot;&quot;.equals(id)">
                and id = #{id}
            </if>
                     <if test="delFlag != null and !&quot;&quot;.equals(delFlag)">
                and del_flag = #{delFlag}
            </if>
                     <if test="code != null and !&quot;&quot;.equals(code)">
                and code = #{code}
            </if>
                     <if test="databaseType != null and !&quot;&quot;.equals(databaseType)">
                and database_type = #{databaseType}
            </if>
                     <if test="url != null and !&quot;&quot;.equals(url)">
                and url = #{url}
            </if>
                     <if test="username != null and !&quot;&quot;.equals(username)">
                and username = #{username}
            </if>
                     <if test="password != null and !&quot;&quot;.equals(password)">
                and password = #{password}
            </if>
                     <if test="databaseName != null and !&quot;&quot;.equals(databaseName)">
                and database_name = #{databaseName}
            </if>
         
        </where>
        LIMIT 1
    </select>
    <update id="delete">
        UPDATE data_source_info SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>
    <select id="query" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.DataSourceInfo">
        select <include refid="Base_Column_List"/> from data_source_info
        <where>
            and del_flag = 'N'
                                                                                                                                                                                                                                                    </where>
        order by id desc
    </select>
</mapper>

