<?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="${packageName}.mapper.${ClassName}Mapper">

    <resultMap type="${packageName}.domain.${ClassName}" id="${ClassName}Result">
        #foreach ($column in $columns)
            <result property="${column.javaField}" column="${column.columnName}"/>
        #end
    </resultMap>

    <sql id="select${ClassName}Vo">
        select#foreach($column in $columns) $column.columnName#if($foreach.count != $columns.size()),#end#end from ${tableName}
    </sql>

    <sql id="defaultDeleteCondition">
        is_deleted = 0
    </sql>

    <select id="select${ClassName}List" resultMap="${ClassName}Result">
        <include refid="select${ClassName}Vo"/>
        <where>
            <include refid="defaultDeleteCondition"/>
            #foreach($column in $columns)
                #set($queryType=$column.queryType)
                #set($javaField=$column.javaField)
                #set($javaType=$column.javaType)
                #set($columnName=$column.columnName)
                #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)})
                #if($column.query)
                    #if($column.queryType == "EQ")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName = #{query.$javaField}
                        </if>
                    #elseif($queryType == "NE")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName != #{query.$javaField}
                        </if>
                    #elseif($queryType == "GT")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName &gt; #{query.$javaField}
                        </if>
                    #elseif($queryType == "GTE")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName &gt;= #{query.$javaField}
                        </if>
                    #elseif($queryType == "LT")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName &lt; #{query.$javaField}
                        </if>
                    #elseif($queryType == "LTE")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName &lt;= #{query.$javaField}
                        </if>
                    #elseif($queryType == "LIKE")
                        <if test="query.$javaField != null #if($javaType ==
                            'String' ) and query.$javaField.trim() != ''#end">and $columnName like concat('%',
                            #{query.$javaField}, '%')
                        </if>
                    #elseif($queryType == "BETWEEN")
                        <if test="query.params.begin$AttrName != null and query.params.begin$AttrName != '' and query.params.end$AttrName != null and query.params.end$AttrName != ''">
                            and $columnName between #{query.params.begin$AttrName} and #{query.params.end$AttrName}
                        </if>
                    #end
                #end
            #end
        </where>
    </select>

    <update id="logicalDelete${ClassName}By${pkColumn.capJavaField}s" parameterType="String">
        update ${tableName} set is_deleted = #{query.isDeleted},
        update_by_id = #{query.updateById}, update_by = #{query.updateBy},
        update_time = #{query.updateTime} where ${pkColumn.columnName} in
        <foreach item="${pkColumn.javaField}" collection="${pkColumn.javaField}s" open="(" separator="," close=")">
            #{${pkColumn.javaField}}
        </foreach>
    </update>

    <delete id="delete${ClassName}By${pkColumn.capJavaField}s" parameterType="String">
        delete from ${tableName} where ${pkColumn.columnName} in
        <foreach item="${pkColumn.javaField}" collection="array" open="(" separator="," close=")">
            #{${pkColumn.javaField}}
        </foreach>
    </delete>
</mapper>
