<?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.product.system.dict.mapper.DictDataMapper">


    <!--获取字典分页列表-->
    <select id="page" resultType="DictDataVO">
        SELECT sys_dict_data.*,
               sys_dict_type.name typeName
        FROM sys_dict_data sys_dict_data
             ,sys_dict_type sys_dict_type
        WHERE sys_dict_data.type_id = sys_dict_type.id
          AND ${ew.sqlSegment}
    </select>

   <!-- 根据字典类型名称查询字典数据-->
    <select id="getDicDataByTypeName" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data,
             sys_dict_type sys_dict_type
        WHERE sys_dict_data.type_id = sys_dict_type.id
        AND sys_dict_type.name = #{dictypeName}
        and sys_dict_data.state = 1
        order by sys_dict_data.sort
    </select>
    <!-- 根据字典名称查询字典数据-->
    <select id="getDicDataByName" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data
        WHERE sys_dict_data.name = #{dicName}
        and sys_dict_data.state = 1
        order by sys_dict_data.sort
    </select>

    <select id="getDicDataByNameAndType" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data
                 LEFT JOIN sys_dict_type sdt ON sdt.Id = sys_dict_data.Type_Id
        WHERE sys_dict_data.name = #{dicName}
          and sys_dict_data.state = 1
          and sdt.Name= #{typeName}
        order by sys_dict_data.sort
    </select>

    <!-- 根据字典名称查询字典数据-->
    <select id="getDicDataByCode" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data
        WHERE sys_dict_data.code = #{code}
        and sys_dict_data.state = 1
         order by sys_dict_data.sort
    </select>

    <select id="getDicDataByNameAndTypeName" resultType="DictData">
        SELECT
            T2.*
        FROM
            sys_dict_type t1,
            sys_dict_data t2
        WHERE
            t1.id = t2.Type_Id
          AND T1.State = 1
          AND T2.State = 1
          AND t1.NAME = #{dicTypeName}
          AND t2.NAME = #{dicDataName}
    </select>

    <!-- 根据字典类型名称查询字典数据-->
    <select id="getDicDataByTypeCode" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data,
             sys_dict_type sys_dict_type
        WHERE sys_dict_data.type_id = sys_dict_type.id
          AND sys_dict_type.code = #{dictTypeCode}
          and sys_dict_data.state = 1
        order by sort
    </select>

    <select id="getDicDataByCodeAndType" resultType="DictData">
        SELECT sys_dict_data.*
        FROM sys_dict_data sys_dict_data
                 LEFT JOIN sys_dict_type sdt ON sdt.Id = sys_dict_data.Type_Id
        WHERE sys_dict_data.code = #{dicCode}
          and sys_dict_data.state = 1
          and sdt.code= #{typeCode}
        order by sys_dict_data.sort
    </select>
</mapper>
