<?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.CommonQueryMapper">


    <select id="getTableListByPage" resultType="java.util.Map">

        SELECT * FROM ${record.tableName}
        <where>
            and del_flag = 'N'

            <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>


            <if test="record.searchKey != null and !&quot;&quot;.equals(record.searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    <foreach item="item" index="index" collection="record.searchColumn.split('_,')">
                        OR ${item} LIKE concat('%',#{record.searchKey},'%')
                    </foreach>
                </trim>
            </if>


        </where>

        <if test="record.orderByStr != null and !&quot;&quot;.equals(record.orderByStr)">

            order by
            <trim suffixOverrides=",">
                <foreach item="item" index="index" separator="," collection="record.orderByStr.split('_;')">
                    <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                        ${itemDetail}
                    </foreach>
                </foreach>
            </trim>

        </if>

    </select>

    <select id="getTableListAll" resultType="java.util.Map">

        SELECT * FROM ${tableName}
        <where>
            and del_flag = 'N'
            <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>

            <if test="searchKey != null and !&quot;&quot;.equals(searchKey)">
                <trim prefix="and (" suffix=")" prefixOverrides="OR">
                    <foreach item="item" index="index" collection="searchColumn.split('_,')">
                        OR ${item} LIKE concat('%',#{searchKey},'%')
                    </foreach>
                </trim>
            </if>

        </where>

        <if test="orderByStr != null and !&quot;&quot;.equals(orderByStr)">

            order by
            <trim suffixOverrides=",">
                <foreach item="item" index="index" separator="," collection="orderByStr.split('_;')">
                    <foreach item="itemDetail" index="detailIndex" collection="item.split('_,')">
                        ${itemDetail}
                    </foreach>
                </foreach>
            </trim>

        </if>

    </select>


    <select id="selectByPrimaryKey" resultType="java.util.Map" parameterType="java.util.Map">
        select
        *
        from ${tableName}
        where id = #{primaryKey,jdbcType=INTEGER}
    </select>

    <insert id="insertSelective" parameterType="java.util.Map" useGeneratedKeys="true"
            keyProperty="id">
        insert into ${tableName}

        <trim prefix="(" suffix=")" suffixOverrides=",">

            <foreach item="item" index="index" collection="formData.keys">
                <if test="formData[item]!= null">
                    ${item},
                </if>
            </foreach>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">

            <foreach item="item" index="index" collection="formData.keys">
                <if test="formData[item]!= null">
                    #{formData[${item}]},
                </if>
            </foreach>
        </trim>
    </insert>
    <update id="updateByPrimaryKeySelective" parameterType="java.util.Map">
        update ${tableName}
        <set>

            <foreach item="item" index="index" collection="formData.keys">
                <if test="formData[item]!= null">
                    ${item} = #{formData[${item}]},
                </if>
            </foreach>

        </set>
        where id = #{primaryKey,jdbcType=INTEGER}
    </update>

    <update id="delete">
        UPDATE ${tableName} SET del_flag = 'Y'
        <where>
            AND id = #{primaryKey}
        </where>
    </update>
</mapper>