<?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.sundot.airport.ledger.mapper.ScoreIndicatorMapper">

    <resultMap id="ScoreIndicatorResult" type="com.sundot.airport.ledger.domain.ScoreIndicator">
        <id     property="id"           column="id"/>
        <result property="dimensionId"  column="dimension_id"/>
        <result property="parentId"     column="parent_id"/>
        <result property="level"        column="level"/>
        <result property="name"         column="name"/>
        <result property="type"         column="type"/>
        <result property="scoreValue"   column="score_value"/>
        <result property="cascadeRule"  column="cascade_rule"/>
        <result property="sortOrder"    column="sort_order"/>
        <result property="status"       column="status"/>
        <result property="org"       column="org"/>
        <result property="remark"       column="remark"/>
        <result property="createBy"     column="create_by"/>
        <result property="createTime"   column="create_time"/>
        <result property="updateBy"     column="update_by"/>
        <result property="updateTime"   column="update_time"/>
    </resultMap>

    <sql id="selectVo">
        SELECT id, dimension_id, parent_id, level, name, type, score_value, cascade_rule,
               sort_order, status, org, remark, create_by, create_time, update_by, update_time
        FROM score_indicator
        WHERE del_flag = '0'
    </sql>

    <select id="selectList" parameterType="com.sundot.airport.ledger.domain.ScoreIndicator"
            resultMap="ScoreIndicatorResult">
        <include refid="selectVo"/>
        <if test="dimensionId != null">AND dimension_id = #{dimensionId}</if>
        <if test="parentId != null">AND parent_id = #{parentId}</if>
        <if test="level != null">AND level = #{level}</if>
        <if test="name != null and name != ''">AND name LIKE CONCAT('%', #{name}, '%')</if>
        <if test="status != null and status != ''">AND status = #{status}</if>
        <if test="org != null and org != ''">AND org = #{org}</if>
        ORDER BY dimension_id ASC, sort_order ASC, id ASC
    </select>

    <select id="selectByDimensionId" parameterType="java.lang.Long"
            resultMap="ScoreIndicatorResult">
        <include refid="selectVo"/>
        AND dimension_id = #{dimensionId}
        ORDER BY sort_order ASC, id ASC
    </select>

</mapper>
