<?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.QueryConfigMapper">
    <resultMap id="BaseResultMap" type="com.izouma.awesomeadmin.model.QueryConfig">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="code" property="code" jdbcType="VARCHAR"/>
        <result column="table_name" property="tableName" jdbcType="VARCHAR"/>
        <result column="tableColumns" property="tablecolumns" jdbcType="VARCHAR"/>
        <result column="dataBaseType" property="databasetype" jdbcType="VARCHAR"/>
        <result column="modules" property="modules" jdbcType="VARCHAR"/>
    </resultMap>
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
            id,

            del_flag,

            code,

            table_name,

            tableColumns,

            dataBaseType,

            modules,

        </trim>
    </sql>
    <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer">
        select
        <include refid="Base_Column_List"/>
        from query_config
        where id = #{id,jdbcType=INTEGER}
    </select>
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
        delete from query_config
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <insert id="insertSelective" parameterType="com.izouma.awesomeadmin.model.QueryConfig" useGeneratedKeys="true"
            keyProperty="id">
        insert into query_config
        <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="tableName!= null">
                table_name,
            </if>
            <if test="tablecolumns!= null">
                tableColumns,
            </if>
            <if test="databasetype!= null">
                dataBaseType,
            </if>
            <if test="modules!= null">
                modules,
            </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="tableName != null">
                #{tableName,jdbcType=VARCHAR},
            </if>
            <if test="tablecolumns != null">
                #{tablecolumns,jdbcType=VARCHAR},
            </if>
            <if test="databasetype != null">
                #{databasetype,jdbcType=VARCHAR},
            </if>
            <if test="modules != null">
                #{modules,jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="com.izouma.awesomeadmin.model.QueryConfig">
        update query_config
        <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="tableName != null">
                table_name= #{tableName,jdbcType=VARCHAR},
            </if>
            <if test="tablecolumns != null">
                tableColumns= #{tablecolumns,jdbcType=VARCHAR},
            </if>
            <if test="databasetype != null">
                dataBaseType= #{databasetype,jdbcType=VARCHAR},
            </if>
            <if test="modules != null">
                modules= #{modules,jdbcType=VARCHAR},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <select id="queryQueryConfigByPage" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.QueryConfig">
        select
        <include refid="Base_Column_List"/>
        from query_config
        <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.tableName != null and !&quot;&quot;.equals(record.tableName)">
                and table_name = #{record.tableName}
            </if>
            <if test="record.tablecolumns != null and !&quot;&quot;.equals(record.tablecolumns)">
                and tableColumns = #{record.tablecolumns}
            </if>
            <if test="record.databasetype != null and !&quot;&quot;.equals(record.databasetype)">
                and dataBaseType = #{record.databasetype}
            </if>
            <if test="record.modules != null and !&quot;&quot;.equals(record.modules)">
                and modules = #{record.modules}
            </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 table_name LIKE concat('%',#{record.searchKey},'%')
                    OR tableColumns LIKE concat('%',#{record.searchKey},'%')
                    OR dataBaseType 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="queryAllQueryConfig" parameterType="java.util.Map"
            resultType="com.izouma.awesomeadmin.model.QueryConfig">
        select
        <include refid="Base_Column_List"/>
        from query_config
        <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="tableName != null and !&quot;&quot;.equals(tableName)">
                and table_name = #{tableName}
            </if>
            <if test="tablecolumns != null and !&quot;&quot;.equals(tablecolumns)">
                and tableColumns = #{tablecolumns}
            </if>
            <if test="databasetype != null and !&quot;&quot;.equals(databasetype)">
                and dataBaseType = #{databasetype}
            </if>
            <if test="modules != null and !&quot;&quot;.equals(modules)">
                and modules = #{modules}
            </if>
            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    OR code LIKE concat('%',#{searchKey},'%')
                    OR table_name LIKE concat('%',#{searchKey},'%')
                    OR tableColumns LIKE concat('%',#{searchKey},'%')
                    OR dataBaseType 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="queryQueryConfig" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.QueryConfig">
        select
        <include refid="Base_Column_List"/>
        from query_config
        <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="tableName != null and !&quot;&quot;.equals(tableName)">
                and table_name = #{tableName}
            </if>
            <if test="tablecolumns != null and !&quot;&quot;.equals(tablecolumns)">
                and tableColumns = #{tablecolumns}
            </if>
            <if test="databasetype != null and !&quot;&quot;.equals(databasetype)">
                and dataBaseType = #{databasetype}
            </if>
            <if test="modules != null and !&quot;&quot;.equals(modules)">
                and modules = #{modules}
            </if>

        </where>
        LIMIT 1
    </select>
    <update id="delete">
        UPDATE query_config SET del_flag = 'Y'
        <where>
            AND id = #{id}
        </where>
    </update>
    <select id="query" parameterType="java.util.Map" resultType="com.izouma.awesomeadmin.model.QueryConfig">
        select
        <include refid="Base_Column_List"/>
        from query_config
        <where>
            and del_flag = 'N'
        </where>
        order by id desc
    </select>
</mapper>

