<?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.chinaweal.aiccs.aiccs.dict.mapper.CmsDictCodeMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.dict.entity.CmsDictCode">
        <id column="id" property="id" />
        <result column="type" property="type" />
        <result column="label" property="label" />
        <result column="code" property="code" />
        <result column="constant" property="constant" />
        <result column="description" property="description" />
        <result column="sort" property="sort" />
        <result column="level" property="level" />
        <result column="parent_id" property="parentId" />
        <result column="is_valid" property="isValid" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id, type, label, code, constant, description, sort, level, parent_id, is_valid, create_by, create_time, update_by, update_time
    </sql>

    <select id="selectCodeListPage" resultMap="BaseResultMap">
        select id, type, label, code, sort, level, parent_id, is_valid, create_time
        from cms_dict_code
        <where>
            <if test="customParamMap.type != null and customParamMap.type != ''">
                type = #{customParamMap.type}
            </if>
            <if test="customParamMap.code != null and customParamMap.code != ''">
                and code = #{customParamMap.code}
            </if>
            <if test="customParamMap.label != null and customParamMap.label != ''">
                and label like concat('%', #{customParamMap.label}, '%')
            </if>
            <if test="customParamMap.level != null">
                and level = #{customParamMap.level}
            </if>
        </where>
        order by code asc
    </select>

    <select id="getNodeList" resultType="com.chinaweal.aiccs.aiccs.dict.entity.CascadeTreeNode">
        select id, type, label, code as value, sort, level, parent_id, is_valid, create_time
        from cms_dict_code
        <where>
            is_valid = '1'
            <if test="type != null and type != ''">
                and type = #{type}
            </if>
            <if test="parentid != null and parentid != ''">
                and parent_id = #{parentid}
            </if>
            <if test="level != null and level != -99">
                and level = #{level}
            </if>
        </where>
        order by code asc
    </select>
</mapper>
