<?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="org.xyzh.system.mapper.SysDictDataMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysDictData">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="dict_type" property="dictType" jdbcType="VARCHAR"/>
        <result column="dict_label" property="dictLabel" jdbcType="VARCHAR"/>
        <result column="dict_value" property="dictValue" jdbcType="VARCHAR"/>
        <result column="dict_sort" property="dictSort" jdbcType="INTEGER"/>
        <result column="css_class" property="cssClass" jdbcType="VARCHAR"/>
        <result column="list_class" property="listClass" jdbcType="VARCHAR"/>
        <result column="is_default" property="isDefault" jdbcType="BOOLEAN"/>
        <result column="status" property="status" jdbcType="INTEGER"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <result column="creator" property="creator" jdbcType="VARCHAR"/>
        <result column="updater" property="updater" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="delete_time" property="deleteTime" jdbcType="TIMESTAMP"/>
        <result column="deleted" property="deleted" jdbcType="BOOLEAN"/>
    </resultMap>

    <!-- 基础字段 -->
    <sql id="Base_Column_List">
        id, dict_type, dict_label, dict_value, dict_sort, css_class, list_class, 
        is_default, status, remark, creator, updater, create_time, update_time, 
        delete_time, deleted
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            deleted = 0
            <if test="dictType != null and dictType != ''">
                AND dict_type = #{dictType}
            </if>
            <if test="dictLabel != null and dictLabel != ''">
                AND dict_label LIKE CONCAT('%', #{dictLabel}, '%')
            </if>
            <if test="dictValue != null and dictValue != ''">
                AND dict_value = #{dictValue}
            </if>
            <if test="status != null">
                AND status = #{status}
            </if>
            <if test="isDefault != null">
                AND is_default = #{isDefault}
            </if>
        </where>
    </sql>

    <!-- selectSysDictData -->
    <select id="selectSysDictData" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_sys_dict_data
        <include refid="Where_Clause"/>
        ORDER BY dict_type, dict_sort ASC
    </select>

</mapper>
