<?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.SysConfigMapper">

    <!-- 基础结果映射 -->
    <resultMap id="BaseResultMap" type="org.xyzh.common.dto.system.TbSysConfig">
        <id column="id" property="id" jdbcType="VARCHAR"/>
        <result column="config_key" property="configKey" jdbcType="VARCHAR"/>
        <result column="config_value" property="configValue" jdbcType="LONGVARCHAR"/>
        <result column="config_type" property="configType" jdbcType="VARCHAR"/>
        <result column="config_group" property="configGroup" jdbcType="VARCHAR"/>
        <result column="description" property="description" jdbcType="VARCHAR"/>
        <result column="is_system" property="isSystem" jdbcType="BOOLEAN"/>
        <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, config_key, config_value, config_type, config_group, description, 
        is_system, creator, updater, create_time, update_time, delete_time, deleted
    </sql>

    <!-- 通用条件 -->
    <sql id="Where_Clause">
        <where>
            deleted = 0
            <if test="configKey != null and configKey != ''">
                AND config_key = #{configKey}
            </if>
            <if test="configGroup != null and configGroup != ''">
                AND config_group = #{configGroup}
            </if>
            <if test="configType != null and configType != ''">
                AND config_type = #{configType}
            </if>
            <if test="isSystem != null">
                AND is_system = #{isSystem}
            </if>
        </where>
    </sql>

    <!-- selectSysConfigs -->
    <select id="selectSysConfigs" resultMap="BaseResultMap">
        SELECT 
        <include refid="Base_Column_List"/>
        FROM tb_sys_config
        <include refid="Where_Clause"/>
        ORDER BY config_group, config_key
    </select>

</mapper>
