<?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.dayou.mapper.DictDataMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.DictData">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="dict_type_id" property="dictTypeId" />
        <result column="dict_sort" property="dictSort" />
        <result column="name" property="name" />
        <result column="remark" property="remark" />
        <result column="enabled" property="enabled" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        dict_type_id, dict_sort, name, remark, enabled
    </sql>

    <select id="findByDataTypeAndName" resultType="com.dayou.entity.DictData">

        SELECT
            dd.id,
            dd.dict_type_id,
            dd.NAME,
            dd.remark,
            dd.enabled
        FROM
            dict_type dt
                LEFT JOIN dict_data dd ON dd.dict_type_id = dt.id
        WHERE
            dt.`code` = #{dataType}
          AND dd.remark = #{remark}
          AND dd.enabled = 1
          AND dd.deleted = 0
    </select>

    <select id="findByDataTypeByCode" parameterType="java.lang.String" resultType="com.dayou.entity.DictData">
        SELECT
            dd.id,
            dd.dict_type_id,
            dd.NAME,
            dd.remark,
            dd.enabled
        FROM
            dict_type dt
                LEFT JOIN dict_data dd ON dd.dict_type_id = dt.id
        WHERE
            dt.`code` = #{code}

          AND dd.enabled = 1
          AND dd.deleted = 0
    </select>
</mapper>
