<?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="pwc.taxtech.atms.dao.MyStatisticAttributeMapper">
    <resultMap id="BaseResultMap"
               type="pwc.taxtech.atms.dpo.StatisticAttributeDisplayDto">
        <id column="ID" jdbcType="VARCHAR" property="id"/>
        <result column="ATTRIBUTE_ID" jdbcType="VARCHAR" property="attributeId"/>
        <result column="ATTRIBUTE_NAME" jdbcType="NVARCHAR" property="attributeName"/>
        <result column="DIMENSION_ID" jdbcType="VARCHAR" property="dimensionId"/>
        <result column="DIMENSION_NAME" jdbcType="VARCHAR" property="dimensionName"/>
        <result column="ORDER_INDEX" jdbcType="SMALLINT" property="orderIndex"/>
    </resultMap>

    <select id="selectByParentDimensionId" parameterType="map"
            resultMap="BaseResultMap"><![CDATA[
         SELECT
            P.id AS ATTRIBUTE_ID,
            P.name AS ATTRIBUTE_NAME,
            D.id AS DIMENSION_ID,
            D.name AS DIMENSION_NAME,
            SD.order_index AS ORDER_INDEX
        FROM
            statistic_attribute P
            JOIN statistic_attribute_dimension SD ON P.id = SD.statistics_attribute_id
            JOIN dimension D ON SD.dimension_id = D.id
        WHERE
            P.is_active = 1
            AND D.is_active = 1 AND D.id = #{parentDimensionId,jdbcType=VARCHAR}
         ORDER BY SD.order_index
   ]]></select>


    <select id="selectByOrgSubChildrenId" parameterType="map"
            resultMap="BaseResultMap"><![CDATA[
         SELECT
            P.statistics_attribute_id AS ATTRIBUTE_ID,
            D.dict_value AS ATTRIBUTE_NAME,
            #{parentDimensionId} AS  DIMENSION_ID,
            "" AS DIMENSION_NAME,
            P.order_index AS  ORDER_INDEX
        FROM
            statistic_attribute_dimension P
            JOIN dictionary D ON P.statistics_attribute_id = D.id
        WHERE
            P.dimension_id=#{parentDimensionId}
   ]]></select>
</mapper>