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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.ReportSection">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="report_id" property="reportId" />
        <result column="headline_id" property="headlineId" />
        <result column="section" property="section" />
        <result column="user_id" property="userId" />
        <result column="calculate_data" property="calculateData" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
        report_id, headline_id, section, user_id,calculate_data
    </sql>

    <select id="getReportSectionTree" parameterType="java.lang.Long" resultType="com.dayou.vo.ReportSectionTreeVO">
        SELECT
            rh.id,
            rs.id as sectionId,
            rs.headline_name AS headline,
            rh.parent_id,
            rh.order_num,
            rh.root_id,
            rs.section,
            rs.report_id,
            u.NAME AS preUserName,
            rs.modified,
            rh.action
        FROM
            report_section rs
                LEFT JOIN report_main rm ON rm.id = rs.report_id
                AND rm.id = #{reportId}
                LEFT JOIN report_headline rh ON rs.headline_id = rh.id
                LEFT JOIN user u ON u.id = rs.user_id
        WHERE
            rh.deleted = 0
          AND rs.deleted = 0
          AND rm.deleted = 0
    </select>
</mapper>
