<?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.dsk.cscec.mapper.BizDictDataMapper">

    <resultMap type="com.dsk.cscec.domain.BizDictData" id="BizDictDataResult">
        <result property="id" column="id"/>
        <result property="code" column="code"/>
        <result property="name" column="name"/>
        <result property="type" column="type"/>
        <result property="parentId" column="parent_id"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="Base_Column_List">
        id,code,name,type,parent_id,remark
    </sql>

    <select id="findIdByName" resultType="java.lang.Long">
        select id from biz_dict_data where `name` like concat('%',#{name},'%')
    </select>

    <select id="findByNameAndType" resultType="com.dsk.cscec.domain.BizDictData">
        select id,name,code,ancestors from biz_dict_data
        where `name` = #{name}
        and type = #{type}
        and del_flag = 0
    </select>

    <select id="countByName" resultType="java.lang.Integer">
        SELECT
            count( id )
        FROM
            biz_dict_data
        WHERE
            del_flag = 0
            <if test="type != null and type != ''">
                AND `type` = #{type}
            </if>
          AND `name` = #{name}

    </select>
    <select id="exportListVo" resultType="com.dsk.cscec.domain.BizDictData">
        select t.id,t.name,t.parent_id,t1.name parentName, t.unit,t.remark,t.code,t.feature from biz_dict_data t
        left join biz_dict_data t1 on t.parent_id=t1.id
        where
            t.del_flag=0
          and t.`type`=#{bo.type}
          <if test="bo.name != null and bo.name != ''">
              and (t.name like concat('%',#{bo.name},'%') or t1.name like concat('%',#{bo.name},'%'))
          </if>
    </select>

    <select id="queryByID" resultType="com.dsk.cscec.domain.BizDictData">
        select <include refid="Base_Column_List"/>
        from biz_dict_data where del_flag = 0
        and id = #{id}
    </select>
</mapper>
