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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.ReportSectionTemplate">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="headline_id" property="headlineId" />
        <result column="section" property="section" />
        <result column="name" property="name" />
        <result column="user_id" property="userId" />
        <result column="headline_ids" property="headlineIds" />
    </resultMap>

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

    <select id="getPage" parameterType="com.dayou.vo.HeadlineSectionVO" resultType="com.dayou.vo.HeadlineSectionVO">
        SELECT
        rs.id,
        rs.name,
        concat( rh.headline_num, ' ', rh.headline ) AS reportHeadline,
        xrh.headline as reportType,
        rs.section,
        u.name as userName,
        rs.created

        FROM
        report_headline rh left join report_section_template rs on rh.id = rs.headline_id
        left join report_headline xrh on xrh.id = rh.root_id
        left join user u on u.id = rs.user_id
        WHERE
        rh.deleted = 0 and rs.deleted = 0
        <if test="section!=null and section.headlineId!=null">
            and rs.headline_Id = #{section.headlineId}
        </if>
        <if test="section!=null and section.name!=null and section.name!= ''">
            and rs.name like concat('%',#{section.name},'%')
        </if>
        order by rs.id desc
    </select>

</mapper>
