<?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.EmsDisStaCoalMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsDisStaCoal" id="disStaCoalResult">
        <result property="id"    column="id"    />
        <result property="energyCode"    column="energy_code"    />
        <result property="energyName"    column="energy_name"    />
        <result property="coefficientValue"    column="coefficient_value"    />
        <result property="coefficientUnit"    column="coefficient_unit"    />
    </resultMap>

    <sql id="selectDisStaCoalVo">
        select id, energy_code, energy_name, coefficient_value, coefficient_unit from dim_ems_discount_scoal
    </sql>

    <select id="selectDisStaCoalList" parameterType="com.ruoyi.ems.domain.EmsDisStaCoal" resultMap="disStaCoalResult">
        <include refid="selectDisStaCoalVo"/>
        <where>
            <if test="energyCode != null and energyCode != ''">
                and energy_code = #{energyCode}
            </if>
        </where>
    </select>
    
    <select id="selectDisStaCoalById" parameterType="Long" resultMap="disStaCoalResult">
        <include refid="selectDisStaCoalVo"/>
        where id = #{id}
    </select>

    <select id="selectDisStaCoalByCode" parameterType="String" resultMap="disStaCoalResult">
        <include refid="selectDisStaCoalVo"/>
        where energy_code = #{code}
    </select>
        
    <insert id="insertDisStaCoal" parameterType="com.ruoyi.ems.domain.EmsDisStaCoal" useGeneratedKeys="true" keyProperty="id">
        insert into dim_ems_discount_scoal
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="energyCode != null and energyCode != ''">energy_code,</if>
            <if test="energyName != null">energy_name,</if>
            <if test="coefficientValue != null">coefficient_value,</if>
            <if test="coefficientUnit != null">coefficient_unit,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="energyCode != null and energyCode != ''">#{energyCode},</if>
            <if test="energyName != null">#{energyName},</if>
            <if test="coefficientValue != null">#{coefficientValue},</if>
            <if test="coefficientUnit != null">#{coefficientUnit},</if>
         </trim>
    </insert>

    <update id="updateDisStaCoal" parameterType="com.ruoyi.ems.domain.EmsDisStaCoal">
        update dim_ems_discount_scoal
        <trim prefix="SET" suffixOverrides=",">
            <if test="energyCode != null and energyCode != ''">energy_code = #{energyCode},</if>
            <if test="energyName != null">energy_name = #{energyName},</if>
            <if test="coefficientValue != null">coefficient_value = #{coefficientValue},</if>
            <if test="coefficientUnit != null">coefficient_unit = #{coefficientUnit},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDisStaCoalById" parameterType="Long">
        delete from dim_ems_discount_scoal where id = #{id}
    </delete>
</mapper>