<?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}.module.${modulePackage}.dao.${moduleClass}Dao">

    <resultMap id="${moduleClass}Entity" type="${basePackage}.module.${modulePackage}.domain.entity.${moduleClass}Entity"></resultMap>


    <select id="queryByPage" resultMap="${moduleClass}Entity">
        select
#foreach($column in $columnList)
#if($velocityCount != $columnList.size())
          $column.columnName,
#else
          $column.columnName
#end
#end
        from ${tableName}
        <where>
#foreach($queryField in $queryFieldList)
#if ($queryField.sqlOperate == 'like')
            <if test="queryDTO.${queryField.fieldName} != null and queryDTO.${queryField.fieldName} != ''">
                AND INSTR($queryField.columnName,#{queryDTO.$queryField.fieldName})
            </if>
#end
#if ($queryField.sqlOperate == 'equals')
#if ($queryField.fieldType == 'String')
            <if test="queryDTO.${queryField.fieldName} != null and queryDTO.${queryField.fieldName} != ''">
                AND $queryField.columnName = #{queryDTO.$queryField.fieldName}
            </if>
#else
            <if test="queryDTO.${queryField.fieldName} != null">
                AND $queryField.columnName = #{queryDTO.$queryField.fieldName}
            </if>
#end
#end
#if ($queryField.sqlOperate == 'time_equals')
            <if test="queryDTO.${queryField.fieldName} != null and queryDTO.${queryField.fieldName} != ''">
                AND DATE_FORMAT($queryField.columnName, '%Y-%m-%d') = #{queryDTO.$queryField.fieldName}
            </if>
#end
#if ($queryField.sqlOperate == 'time_between')
            <if test="queryDTO.startDate != null and queryDTO.startDate != ''">
                AND DATE_FORMAT($queryField.columnName, '%Y-%m-%d') &gt;= #{queryDTO.startDate}
            </if>
            <if test="queryDTO.endDate != null and queryDTO.endDate != ''">
                AND DATE_FORMAT($queryField.columnName, '%Y-%m-%d') &lt;= #{queryDTO.endDate}
            </if>
#end
#if ($queryField.sqlOperate == 'in')
            <if test="queryDTO.${queryField.fieldName}List !=null and queryDTO.${queryField.fieldName}List.size() > 0">
                and $queryField.columnName in
                <foreach collection="queryDTO.${queryField.fieldName}List" open="(" index="index" separator="," close=")" item="item">
                    #{item}
                </foreach>
            </if>
#end
#if ($queryField.sqlOperate == 'gt')
            <if test="queryDTO.startDate != null and queryDTO.startDate != ''">
                and DATE_FORMAT($queryField.columnName, '%Y-%m-%d') &gt;= DATE_FORMAT(#{queryDTO.startDate}, '%Y-%m-%d')
            </if>
#end
#end
        </where>
    </select>

    <delete id="deleteById">
        delete from ${tableName} where id = #{id}
    </delete>

    <delete id="deleteByIds">
        delete from ${tableName} where id in
        <foreach collection="idList" open="(" close=")" separator="," item="item">
            #{item}
        </foreach>
    </delete>

</mapper>