<?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.njcn.csdevice.mapper.CsDictMapper">
  <resultMap id="BaseResultMap" type="com.njcn.csdevice.pojo.po.CsDictPO">
    <!--@mbg.generated-->
    <!--@Table cs_dict-->
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="pid" jdbcType="VARCHAR" property="pid" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="another_name" jdbcType="VARCHAR" property="anotherName" />
    <result column="state" jdbcType="BOOLEAN" property="state" />
    <result column="sort" jdbcType="TINYINT" property="sort" />
    <result column="create_by" jdbcType="VARCHAR" property="createBy" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="update_by" jdbcType="VARCHAR" property="updateBy" />
    <result column="update_time" jdbcType="TIMESTAMP" property="updateTime" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--@mbg.generated-->
    id, pid, `name`, another_name, `state`, sort, create_by, create_time, update_by, 
    update_time
  </sql>

  <select id="getOwnAndFatherData" resultType="com.njcn.csdevice.pojo.dto.CsDictDTO">
    select
        id,
        (
        select
            id
        from
            cs_dict
        where
            id = t0.pid
            and state = 1) fatherId,
        (
        select
            name
        from
            cs_dict
        where
            id = t0.pid
            and state = 1) fatherName,
        another_name name
    from
        cs_dict t0
    where
        name = #{name}
        and state = 1
  </select>
</mapper>