<?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="cn.pluss.platform.mapper.DictMapper">
    <select id="getDictByCode" resultType="cn.pluss.platform.entity.Dict">
        SELECT d1.id, d1.pid, d1.sort, d1.code, d1.name, d1.desc, d1.value, d1.createTime, d1.updateTime, d2.code pCode FROM tb_pluss_dict d1 LEFT JOIN tb_pluss_dict d2 ON d1.pId = d2.id
        <where>
            d2.code IN
            <foreach collection="codeList" item="item" close=")" open="(" separator=",">
                #{item}
            </foreach>
        </where>
        ORDER BY sort
    </select>
    <select id="selectDictPage" resultType="cn.pluss.platform.entity.Dict">
        select id,pid,sort,code,name,describes,codeValue,createTime,updateTime
        from  tb_pluss_dict
        order by sort
    </select>

    <select id="selectMaxSortElem" resultType="cn.pluss.platform.entity.Dict">
        SELECT MAX(t.sort) sort, t2.id FROM tb_pluss_dict t LEFT JOIN tb_pluss_dict t2 ON t.pid = t2.id
        WHERE t2.code = #{code} GROUP BY t2.id
    </select>

    <select id="selectByNameAndPCode" resultType="cn.pluss.platform.entity.Dict">
        SELECT
               d1.code, d1.name, d1.desc, d1.value, d1.createTime, d1.updateTime
        FROM  tb_pluss_dict d1 LEFT JOIN tb_pluss_dict d2 ON d1.pid = d2.id
        WHERE d2.code = #{code} AND d1.name = #{name}
    </select>
</mapper>
