<?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.artfess.sysConfig.persistence.dao.SysDictionaryDetailDao">
    <update id="updateDictionariesDetailsStatus">
        update portal_sys_dictionary_detail
        set  flag_=
        <if test="status != null">
            #{status}
        </if>
        where id_ in
        <foreach collection="ids" index="index" item="valueList"
                 separator="," open="(" close=")">
            #{valueList}
        </foreach>
    </update>

    <select id="queryDictModelItemsByCode" resultType="com.artfess.sysConfig.persistence.param.DictModel">
        select t.* from portal_sys_dictionary_detail t
        left join portal_sys_dictionary t1 on t.DICTIONARY_ID_=t1.ID_
        where t1.CODE_ = #{code}
        <if test="tenantId != null and tenantId != '' ">
            and t1.TENANT_ID_ = #{tenantId}
        </if>
        <!--        <if test="companyId == null or companyId == '' ">-->
        <!--            and t1.KIND_ID_ = 1-->
        <!--        </if>-->
    </select>

    <select id="queryDictItemsByCode" resultType="com.artfess.sysConfig.persistence.model.SysDictionaryDetail">
        select t.* from portal_sys_dictionary_detail t
        left join portal_sys_dictionary t1 on t.DICTIONARY_ID_=t1.id
        where t1.flag_ = 1 and t.flag_ = 1 and t1.code_ = #{code}
        <if test="tenantId != null and tenantId != '' ">
            and t1.TENANT_ID_ = #{tenantId}
        </if>
        <if test="tenantId == null or tenantId == '' ">
            and t1.KIND_ID_ = 1
        </if>
    </select>

    <!-- 通过上级字典项的值与其下级级联字典的id，获取级联的字典项数据 -->
    <select id="queryLowerDictionaryDetail" parameterType="String"  resultType="com.artfess.sysConfig.persistence.model.SysDictionaryDetail">
        select de.* from portal_sys_dictionary_detail de
                             INNER JOIN portal_sys_dictionary d on d.ID_ = de.DICTIONARY_ID_
                             INNER JOIN portal_sys_dictionary_cascade c on c.LOWER_DETAIL_ID_ = de.id_
        WHERE d.flag_=1 and de.flag_=1
          and c.LOWER_DIC_ID_=#{dictLowerId} and c.DETAIL_ID_=#{detailId}
    </select>

    <!-- 获取级联的字典项数据详情 -->
    <select id="queryLowers"  resultType="com.artfess.sysConfig.vo.DictionaryLowerDetailVo">
        select c.detail_id_ parentId,dic.name_ dictionaryName,dic.code_ dictionaryCode,d.*  from portal_sys_dictionary_cascade c
                                                                                                     inner join portal_sys_dictionary dic on c.lower_dic_id_ = dic.id_ and dic.flag_='1'
                                                                                                     inner join portal_sys_dictionary_detail d on c.lower_detail_id_ = d.id_ and d.flag_='1'
    </select>

    <!-- 获取字典数据 -->
    <select id="queryDictionaryDetail"  resultType="com.artfess.sysConfig.vo.DictionaryDetailVo">
        select de.id_, de.dictionary_id_, de.name_, de.value_, de.sn_ sequence,d.name_ dictionaryName,d.code_ dictionaryCode,d.sn_ dictionarySn
        from  portal_sys_dictionary d
                  left JOIN portal_sys_dictionary_detail de on d.ID_ = de.DICTIONARY_ID_
        WHERE d.flag_=1 and de.flag_=1
        order by d.sn_,de.sn_
    </select>
</mapper>
