<?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.njcn.harmonic.mapper.ExcelRptTempMapper">

    <select id="getReportTemplateListPage" resultType="ReportTemplateVO">
        select
        a.id,
        a.name,
        a.dept_id,
        b.name deptName,
        a.activation,
        a.update_time,
        c.name updateBy
        from sys_excel_rpt_temp a
        left join sys_dept b on a.dept_id = b.id
        left join sys_user c on a.update_by = c.id
        where a.state = 1
        <if test="baseParam.searchValue!=null and baseParam.searchValue!=''">
            and (
            a.name like CONCAT('%', #{baseParam.searchValue},'%') or
            b.name like CONCAT('%', #{baseParam.searchValue},'%')
            )
        </if>
    </select>

    <select id="getReportTemplateList" resultType="ReportTemplateVO">
        SELECT
            a.id,
            a.NAME,
            a.update_time,
            d.NAME updateBy
        FROM
            sys_excel_rpt_temp a
            LEFT JOIN sys_user d ON a.update_by = d.id
        WHERE
            a.state = 1
    </select>

    <select id="getReportTemplateByDept" resultType="ReportTemplateVO">
        SELECT
            DISTINCT
	        a.id,
            a.NAME,
            b.activation,
            a.report_form
        FROM
            sys_excel_rpt_temp a
            LEFT JOIN sys_dept_temp b ON a.Id = b.temp_id
        WHERE
            b.activation = 1
            and b.dept_id in
            <foreach collection="list" index="index" item="item" separator="," open="(" close=")">
                #{item.id}
            </foreach>
    </select>
</mapper>
