<?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.ruoyi.web.report.mapper.ReportPrintTemplateMapper">

    <resultMap id="ReportPrintTemplateResult" type="com.ruoyi.web.report.domain.print.ReportPrintTemplateVo">
        <result property="templateName" column="template_name"/>
        <result property="pageSize" column="page_size"/>
        <result property="pageOrientation" column="page_orientation"/>
        <result property="titleText" column="title_text"/>
        <result property="titleStyleJson" column="title_style_json"/>
        <result property="headerLayoutJson" column="header_layout_json"/>
        <result property="tableStyleJson" column="table_style_json"/>
        <result property="footerText" column="footer_text"/>
        <result property="isDefault" column="is_default"/>
    </resultMap>

    <select id="selectByReportId" resultMap="ReportPrintTemplateResult">
        select template_name, page_size, page_orientation, title_text, title_style_json, header_layout_json, table_style_json, footer_text, is_default
        from rpt_print_template
        where report_id = #{reportId}
        limit 1
    </select>

    <insert id="insertTemplate">
        insert into rpt_print_template (
            report_id, template_name, page_size, page_orientation, title_text, title_style_json, header_layout_json, table_style_json, footer_text, is_default
        ) values (
            #{reportId},
            #{template.templateName},
            #{template.pageSize},
            #{template.pageOrientation},
            #{template.titleText},
            #{template.titleStyleJson},
            #{template.headerLayoutJson},
            #{template.tableStyleJson},
            #{template.footerText},
            #{template.isDefault}
        )
    </insert>

    <update id="updateTemplate">
        update rpt_print_template
        set template_name = #{template.templateName},
            page_size = #{template.pageSize},
            page_orientation = #{template.pageOrientation},
            title_text = #{template.titleText},
            title_style_json = #{template.titleStyleJson},
            header_layout_json = #{template.headerLayoutJson},
            table_style_json = #{template.tableStyleJson},
            footer_text = #{template.footerText},
            is_default = #{template.isDefault},
            updated_at = now()
        where report_id = #{reportId}
    </update>
</mapper>
