<?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.ems.mapper.CaEmissionForecastMapper">

    <resultMap type="com.ruoyi.ems.domain.CaEmissionForecast" id="CaEmissionForecastResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="date"    column="date"    />
        <result property="caEmission"    column="ca_emission"    />
    </resultMap>

    <sql id="selectCaEmissionForecastVo">
        select id, area_code, date, ca_emission from adm_ems_ca_emission_forecast
    </sql>

    <select id="selectCaEmissionForecastList" parameterType="com.ruoyi.ems.domain.CaEmissionForecast" resultMap="CaEmissionForecastResult">
        select d.id, d.area_code,area.area_name, date, ca_emission from adm_ems_ca_emission_forecast d
        inner join adm_area area on area.area_code = d.area_code and area.parent_code = '0'
        <where>
            <if test="areaName != null  and areaName != ''">and area_name like concat('%', #{areaName}, '%')</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="caEmission != null "> and ca_emission = #{caEmission}</if>
        </where>
    </select>

    <select id="selectCaEmissionForecastById" parameterType="Long" resultMap="CaEmissionForecastResult">
        <include refid="selectCaEmissionForecastVo"/>
        where id = #{id}
    </select>

    <insert id="insertCaEmissionForecast" parameterType="com.ruoyi.ems.domain.CaEmissionForecast" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_ca_emission_forecast
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="date != null">date,</if>
            <if test="caEmission != null">ca_emission,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="date != null">#{date},</if>
            <if test="caEmission != null">#{caEmission},</if>
         </trim>
    </insert>

    <update id="updateCaEmissionForecast" parameterType="com.ruoyi.ems.domain.CaEmissionForecast">
        update adm_ems_ca_emission_forecast
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="date != null">date = #{date},</if>
            <if test="caEmission != null">ca_emission = #{caEmission},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCaEmissionForecastById" parameterType="Long">
        delete from adm_ems_ca_emission_forecast where id = #{id}
    </delete>

    <delete id="deleteCaEmissionForecastByIds" parameterType="String">
        delete from adm_ems_ca_emission_forecast where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>
