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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.dayou.entity.ReportMain">
        <result column="id" property="id" />
        <result column="deleted" property="deleted" />
        <result column="created" property="created" />
        <result column="modified" property="modified" />
        <result column="headline_root_id" property="headlineRootId"/>
        <result column="report_type" property="reportType" />
        <result column="report_params" property="reportParams" />
        <result column="report_key" property="reportKey" />
        <result column="title" property="title" />
        <result column="url" property="url" />
        <result column="user_id" property="userId" />
        <result column="checker_id" property="checkerId" />
        <result column="status" property="status" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        id,
        deleted,
        created,
        modified,
            headline_root_id,
            report_type,
        report_params, report_key, title, url, user_id, checker_id, status
    </sql>

    <select id="getPage" parameterType="com.dayou.vo.ReportMainVO" resultType="com.dayou.vo.ReportMainVO">
        SELECT
            rm.id,
            rm.created,
            rm.report_type,
            rm.report_key,
            rm.title,
            rm.url,
            u.name AS creator,
            u1.name as checker,
            status
        FROM
            report_main rm
                LEFT JOIN user u ON u.id = rm.user_id
                LEFT JOIN user u1 ON u1.id = rm.checker_id
        where rm.deleted = 0
            <if test="report!=null and report.reportType!=null">
                    and rm.report_type = #{report.reportType}
            </if>
            <if test="report!=null and report.title and report.title!=''">
                    and rm.title like concat('%',#{report.title},'%')
            </if>
            <if test="report!=null and report.creator!=null and report.creator!= '' ">
                    and u.name like concat('%',#{report.creator},'%')
            </if>
            <if test="report!=null and report.checker!=null and report.checker!='' ">
                    and u1.name like concat('%',#{report.checker},'%')
            </if>
            <if test="report!=null and report.status!=null and report.status!=''">
                    and rm.status = #{report.status}
            </if>
            <if test="report!=null and report.url!=null and report.url!=''">
                and rm.url is not null
            </if>
        order by rm.id DESC
    </select>

    <select id="getReportMainSection" parameterType="java.lang.Long" resultType="com.dayou.dto.SectionTitleDTO">
        SELECT
            ifnull(rs.section,'') as section,
            rh.placeholder AS title
        FROM
            report_section rs
                LEFT JOIN report_headline rh ON rs.headline_id = rh.id
        WHERE
            rs.report_id =#{reportId} and rs.deleted = 0 and rh.deleted = 0
    </select>

    <select id="getReportMainVO" parameterType="java.lang.Long" resultType="com.dayou.vo.ReportMainVO">
        SELECT
            rm.id,
            rh.placeholder,
            rm.created,
            rh.headline AS type,
            rm.report_key,
            rm.title,
            rm.url,
            u.name AS creator,
            u1.name as checker,
            rm.status,
            rm.report_params
        FROM
            report_main rm
                LEFT JOIN report_headline rh ON rm.headline_root_id = rh.id
                LEFT JOIN user u ON u.id = rm.user_id
                LEFT JOIN user u1 ON u1.id = rm.checker_id
        where rm.deleted = 0 and rm.id = #{id}
    </select>

    <select id="getFtlConfig" parameterType="java.lang.String" resultType="com.dayou.bo.RichObject">
        SELECT
            ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'DOC_SRC_PARENT' ) AS 'docSrcParent',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'DOC_SRC_LOCATION_PRE' ) AS 'docSrcLocationPrex',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'NEXT_PART_ID' ) AS 'nextPartId',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'SHAPE_ID_PREX' ) AS 'shapeidPrex',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'SP_ID_PREX' ) AS 'spidPrex',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'TYPE_ID' ) AS 'typeid',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'FTL_PATH' ) AS 'ftlPath',
                ( SELECT `value` FROM global_config WHERE `key` = #{type} AND field = 'FTL_NAME' ) AS 'ftlName'
    </select>
</mapper>
