<?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.huashe.park.core.mapper.SysCustConfigMapper">

    <sql id="sqlwhereSearch">
        <where>
            <if test="configId !=null">
                and config_id = #{configId}
            </if>
            <if test="configKey !=null and configKey != ''">
                and config_key = #{configKey}
            </if>
            <if test="configType == 'Y'.toString() and tenantId  != null">and tenant_id = #{tenantId}</if>
        </where>
    </sql>

    <select id="selectTenantConfig" parameterType="CustSysConfig" resultType="CustSysConfig">
        select *
        from sys_config
        <include refid="sqlwhereSearch"/>
    </select>
    <update id="updateConfig" parameterType="CustSysConfig">
        update sys_config
        <set>
            <if test="configName != null and configName != ''">config_name = #{configName},</if>
            <if test="configKey != null and configKey != ''">config_key = #{configKey},</if>
            <if test="configValue != null and configValue != ''">config_value = #{configValue},</if>
            <if test="configType != null and configType != ''">config_type = #{configType},</if>
            <if test="updateBy != null and updateBy != ''">update_by = #{updateBy},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="cfgJson != null">cfg_json = #{cfgJson},</if>
            <if test="configType == 'Y'.toString() and tenantId  != null">tenant_id = #{tenantId},</if>
            update_time = sysdate()
        </set>
        where config_id = #{configId}
    </update>

    <select id="selectConfigById" parameterType="Long" resultType="CustSysConfig">
        select *
        from sys_config where config_id = #{configId}
    </select>

    <select id="checkConfigKeyUnique" parameterType="CustSysConfig" resultType="CustSysConfig">
        select * from sys_config
        where config_key = #{configKey}
        <if test="configType != 'Y'.toString() and tenantId !=null">
            and tenant_id = #{tenantId}
        </if>
        limit 1
    </select>
</mapper> 