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

    <resultMap type="com.ruoyi.ems.domain.CaMeterD" id="CaMeterDResult">
        <result property="id"    column="id"    />
        <result property="areaCode"    column="area_code"    />
        <result property="date"    column="date"    />
        <result property="caEmissionQuantity"    column="ca_emission_quantity"    />
        <result property="caSinkQuantity"    column="ca_sink_quantity"    />
    </resultMap>

    <sql id="selectCaMeterDVo">
        select id, area_code, date, ca_emission_quantity, ca_sink_quantity from adm_ems_ca_meter_d
    </sql>

    <select id="selectCaMeterDList" parameterType="com.ruoyi.ems.domain.CaMeterD" resultMap="CaMeterDResult">
        select d.id, d.area_code,area.area_name, date, ca_emission_quantity, ca_sink_quantity from adm_ems_ca_meter_d 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.area_name like concat('%', #{areaName}, '%')</if>
            <if test="areaCode != null  and areaCode != ''"> and d.area_code = #{areaCode}</if>
            <if test="date != null "> and date = #{date}</if>
            <if test="caEmissionQuantity != null "> and ca_emission_quantity = #{caEmissionQuantity}</if>
            <if test="caSinkQuantity != null "> and ca_sink_quantity = #{caSinkQuantity}</if>
        </where>
        order by date desc
    </select>

    <select id="selectCaMeterDById" parameterType="Long" resultMap="CaMeterDResult">
        <include refid="selectCaMeterDVo"/>
        where id = #{id}
    </select>

    <insert id="insertCaMeterD" parameterType="com.ruoyi.ems.domain.CaMeterD" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_ca_meter_d
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code,</if>
            <if test="date != null">date,</if>
            <if test="caEmissionQuantity != null">ca_emission_quantity,</if>
            <if test="caSinkQuantity != null">ca_sink_quantity,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">#{areaCode},</if>
            <if test="date != null">#{date},</if>
            <if test="caEmissionQuantity != null">#{caEmissionQuantity},</if>
            <if test="caSinkQuantity != null">#{caSinkQuantity},</if>
         </trim>
    </insert>

    <update id="updateCaMeterD" parameterType="com.ruoyi.ems.domain.CaMeterD">
        update adm_ems_ca_meter_d
        <trim prefix="SET" suffixOverrides=",">
            <if test="areaCode != null and areaCode != ''">area_code = #{areaCode},</if>
            <if test="date != null">date = #{date},</if>
            <if test="caEmissionQuantity != null">ca_emission_quantity = #{caEmissionQuantity},</if>
            <if test="caSinkQuantity != null">ca_sink_quantity = #{caSinkQuantity},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteCaMeterDById" parameterType="Long">
        delete from adm_ems_ca_meter_d where id = #{id}
    </delete>

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