<?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.cf.imes.module.system.dal.mysql.dict.DictDataI18nMapper">
    <select id="getLocaleDictData" resultType="com.cf.imes.module.system.dal.dataobject.dict.DictDataDO">
        select
            d.dict_type,
            i.label,
            d.value,
            d.color_type,
            d.css_class
        from system_dict_data d
        left join system_dict_data_i18n i
        on d.id = i.dict_data_id and i.locale = #{locale}
        where d.deleted = false
        and d.status = '${@com.cf.imes.framework.common.enums.CommonStatusEnum@ENABLE.status}'
        <if test="ids != null and !ids.isEmpty()">
            and d.id IN
            <foreach collection="ids" item="id" open="(" separator="," close=")">
                #{id}
            </foreach>
        </if>
    </select>

    <select id="selectListByDictType" resultType="com.cf.imes.module.system.dal.dataobject.dict.DictDataDO">
        select
            coalesce(i.label, d.label) as label,
            d.value
        from system_dict_data d
        left join system_dict_data_i18n i
        on d.id = i.dict_data_id and i.locale = #{locale}
        where d.deleted = false
        and d.dict_type = #{dictType}
        order by d.sort desc
    </select>

    <select id="selectI18nByDictTypeAndValue" resultType="com.cf.imes.module.system.dal.dataobject.dict.DictDataDO">
        select
            coalesce(i.label, d.label) as label
            from system_dict_data d
            left join system_dict_data_i18n i
            on d.id = i.dict_data_id and i.locale = #{locale}
        where d.deleted = false
          and d.dict_type = #{dictType}
          and d.value = #{value}
    </select>
</mapper>