<?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.ReportHeadlineMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.ReportHeadline">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="placeholder" property="placeholder" />
        <result column="headline" property="headline" />
        <result column="headline_num" property="headlineNum" />
        <result column="style" property="style" />
        <result column="parent_id" property="parentId" />
        <result column="order_num" property="orderNum" />
        <result column="action" property="action" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        placeholder, headline, headline_num, style, parent_id, order_num,level,root_id,action
    </sql>

    <select id="getHeadline" parameterType="java.lang.Long" resultType="com.dayou.entity.ReportHeadline">
        SELECT
            id,
            placeholder,
            concat( headline_num, ' ', headline ) AS headline,
            headline_num,
            style,
            parent_id,
            order_num,
            LEVEL,
            root_id
        FROM
            report_headline
            where deleted = 0
            <if test="rootId!=null">
                and root_id =#{rootId}
            </if>

    </select>

    <select id="getAllHeadlineTree" resultType="com.dayou.common.CascaderDTO">
        SELECT
            id,
            id as `value`,
            concat( headline_num, ' ', headline ) AS `name`,
            concat( headline_num, ' ', headline ) AS label,
            parent_id,
            order_num
        FROM
            report_headline
        where deleted = 0
    </select>

    <select id="getHeadlinesByType" parameterType="java.lang.String" resultType="com.dayou.entity.ReportHeadline">
        select <include refid="Base_Column_List"/> from report_headline where root_id =
                (select id from report_headline where placeholder = #{reportType})
    </select>

</mapper>
