<?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.energy.manage.service.mappers.analysis.AnalysisResultReportMapper">
    <resultMap id="BaseResultMap" type="com.energy.manage.common.po.analysis.AnalysisResultReportPo">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="batch_code" property="batchCode" jdbcType="VARCHAR"/>
        <result column="report_name" property="reportName" jdbcType="VARCHAR"/>
        <result column="report_type" property="reportType" jdbcType="INTEGER"/>
        <result column="report_addr" property="reportAddr" jdbcType="VARCHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <insert id="saveReportBatch" parameterType="com.energy.manage.service.domain.dto.analysis.AnalysisOptionRecordsDto">
        insert into analysis_result_report
            (
                 batch_code,
                 report_type,
                 report_name,
                 report_addr
             )
             values
        <foreach collection="list" separator="," item="record">
            (
                #{record.batchCode,jdbcType=VARCHAR},
                #{record.reportType,jdbcType=INTEGER},
                #{record.reportName,jdbcType=VARCHAR},
                #{record.reportAddr,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>

    <update id="updateReport" parameterType="com.energy.manage.service.domain.vo.analysis.AnalysisResultReportVo">
        update analysis_result_report
        <set>
            <if test="reportName != null">
                report_name = #{reportName,jdbcType=VARCHAR},
            </if>
            <if test="reportType != null">
                report_type = #{reportType,jdbcType=INTEGER},
            </if>
            <if test="reportAddr != null">
                report_addr = #{reportAddr,jdbcType=VARCHAR},
            </if>
        </set>
        where batch_code = #{batchCode,jdbcType=VARCHAR}
        and report_type = #{reportType,jdbcType=INTEGER}
    </update>

    <insert id="insertReport" parameterType="com.energy.manage.service.domain.vo.analysis.AnalysisResultReportVo">
        insert into analysis_result_report
            (
                 batch_code,
                 report_type,
                 report_name,
                 report_addr
             )
             values
            (
                #{batchCode,jdbcType=VARCHAR},
                #{reportType,jdbcType=INTEGER},
                #{reportName,jdbcType=VARCHAR},
                #{reportAddr,jdbcType=VARCHAR}
            )
    </insert>

    <select id="selectByBatchCode" parameterType="string" resultType="com.energy.manage.service.domain.vo.analysis.AnalysisResultReportVo">
        select batch_code,
               report_name,
               report_type,
               report_addr
        from analysis_result_report
        where batch_code = #{batchCode,jdbcType=VARCHAR}
    </select>

    <select id="selectByBatchCodeAndReportType" resultType="com.energy.manage.common.po.analysis.AnalysisResultReportPo">
        select
            id,
            batch_code,
            report_name,
            report_type,
            report_addr
        from analysis_result_report
        where batch_code = #{batchCode,jdbcType=VARCHAR}
        and report_type = #{reportType,jdbcType=INTEGER}
    </select>
</mapper>
