<?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.ylcm.sys.mapper.AdMediaMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.ylcm.sys.domain.AdMedia">
        <id column="id" property="id" />
        <result column="name" property="name" />
        <result column="rank" property="rank" />
        <result column="img_url" property="imgUrl" />
        <result column="status" property="status" />
        <result column="crt_time" property="crtTime" />
        <result column="upd_time" property="updTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, name, rank, img_url, status, crt_time, upd_time
    </sql>

    <select id="getListByPage" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List" />
        FROM ad_media
        <trim prefix="WHERE" prefixOverrides="AND |OR ">
            AND status = 0
            <if test="name != null and name != '' ">
                AND name LIKE CONCAT('%',#{name},'%')
            </if>
            <if test="rank != null ">
                AND rank = #{rank}
            </if>
        </trim>
        ORDER BY (name+0)
        ,(lower(case when name REGEXP '^[a-zA-Z]' then LEFT(name, 1)
        when name REGEXP '^[0-9]' then LEFT(name, 1)
        else ELT(INTERVAL(CONV(HEX(LEFT(CONVERT(name USING gbk),1)),16,10),
        0xB0A1,0xB0C5,0xB2C1,0xB4EE,0xB6EA,0xB7A2,0xB8C1,0xB9FE,0xBBF7,
        0xBFA6,0xC0AC,0xC2E8,0xC4C3,0xC5B6,0xC5BE,0xC6DA,0xC8BB,0xC8F6,
        0xCBFA,0xCDDA,0xCEF4,0xD1B9,0xD4D1),
        'A','B','C','D','E','F','G','H','J','K','L','M','N','O','P',
        'Q','R','S','T','W','X','Y','Z')
        end)
        ) ASC
        ,name
        <if test="pageNo != null">
            LIMIT #{pageSize} OFFSET #{pageNo}
        </if>
    </select>

</mapper>
