<?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="${basePackage}.${moduleName}.mpr.${table.getCName()}Mapper">


<#if dataBase == 'ORACLE'>
    <sql id="table">"${module.modulePrefix?default("")}${table.tableName}"</sql>
<#elseif dataBase='MYSQL'>
    <sql id="table">`${module.modulePrefix?default("")}${table.tableName}`</sql>
</#if>

    <sql id="entityColumnList">
    <#if dataBase == 'ORACLE'>
        <#list table.fields as f>"${f.fieldName}"<#if f_has_next>,</#if></#list>
    <#elseif dataBase='MYSQL'>
        <#list table.fields as f>`${f.fieldName}`<#if f_has_next>,</#if></#list>
    </#if>
    </sql>

    <resultMap id="${table.getFName()}" type="${basePackage}.${moduleName}.ent.${table.getCName()}">
    <#list table.fields as f>
        <result column="${f.fieldName}"  jdbcType="${f.fieldType.jdbcType()}" property="${f.getFName()}"/>
    </#list>
    </resultMap>

    <select id="find" resultMap="${table.getFName()}">
        SELECT
        <include refid="entityColumnList"/>
        FROM
        <include refid="table"/>
        WHERE
            1 = 1
<#list table.fields as f>
<#if f.isQuery>
<#if dataBase == 'ORACLE'>
<#if f.fieldType.javaType() == "String">
        <if test="request.${f.getFName()} != null and request.${f.getFName()} != ''">
            AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}}
        </if>
</#if>
<#if f.fieldType.javaType() == "Boolean">
        <if test="request.${f.getFName()} != null">
            AND "${f.fieldName}" = ${r"#{"}request.${f.getFName()}}
        </if>
</#if>
<#elseif dataBase='MYSQL'>
<#if f.fieldType.javaType() == "String">
        <if test="request.${f.getFName()} != null and request.${f.getFName()} != ''">
            AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}}
        </if>
</#if>
<#if f.fieldType.javaType() == "Boolean">
        <if test="request.${f.getFName()} != null">
            AND `${f.fieldName}` = ${r"#{"}request.${f.getFName()}}
        </if>
</#if>
</#if>
</#if>
</#list>
    </select>

    <insert id="insert">
        INSERT INTO
        <include refid="table"/>
        (
        <include refid="entityColumnList"/>
        )
        VALUES
        (
        <#list table.fields as f>
        ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
        </#list>
        )
    </insert>

    <delete id="delete">
        DELETE FROM
        <include refid="table"/>
        WHERE
        1 = 2
    </delete>

    <update id="update">
        UPDATE
        <include refid="table"/>
        SET
    <#if dataBase == 'ORACLE'>
        <#list table.fields as f>
        "${f.fieldName}" = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
        </#list>
    <#elseif dataBase='MYSQL'>
        <#list table.fields as f>
        `${f.fieldName}` = ${r"#{"}request.${f.getFName()},jdbcType=${f.fieldType.jdbcType()}}<#if f_has_next>,</#if>
        </#list>
    </#if>
        WHERE
        1 = 2
    </update>
</mapper>