<?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.base.mapper.EmsBaseEnergyTypeMapper">

    <resultMap type="EmsBaseEnergyType" id="EmsBaseEnergyTypeResult">
        <result property="objId" column="obj_id"/>
        <result property="energyTypeId" column="energy_type_id"/>
        <result property="energyName" column="energy_name"/>
        <result property="measureUnit" column="measure_unit"/>
        <result property="price" column="price"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectEmsBaseEnergyTypeVo">
        select obj_id,
               energy_type_id,
               energy_name,
               measure_unit,
               price,
               create_by,
               create_time,
               update_by,
               update_time
        from ems_base_energy_type
    </sql>

    <select id="selectEmsBaseEnergyTypeList" parameterType="EmsBaseEnergyType" resultMap="EmsBaseEnergyTypeResult">
        <include refid="selectEmsBaseEnergyTypeVo"/>
        <where>
            <if test="energyTypeId != null ">and energy_type_id = #{energyTypeId}</if>
            <if test="energyName != null  and energyName != ''">and energy_name like concat('%', #{energyName}, '%')
            </if>
            <if test="measureUnit != null  and measureUnit != ''">and measure_unit = #{measureUnit}</if>
            <if test="price != null ">and price = #{price}</if>
        </where>
    </select>

    <select id="selectEmsBaseEnergyTypeByObjId" parameterType="Long" resultMap="EmsBaseEnergyTypeResult">
        <include refid="selectEmsBaseEnergyTypeVo"/>
        where obj_id = #{objId}
    </select>

    <select id="selectEmsBaseEnergyNameByEnergyTypeId">
        select energy_name
        from ems_base_energy_type
        where energy_type_id = #{energyTypeId}
    </select>

    <insert id="insertEmsBaseEnergyType" parameterType="EmsBaseEnergyType" useGeneratedKeys="true" keyProperty="objId">
        insert into ems_base_energy_type
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="energyTypeId != null">energy_type_id,</if>
            <if test="energyName != null">energy_name,</if>
            <if test="measureUnit != null">measure_unit,</if>
            <if test="price != null">price,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="energyTypeId != null">#{energyTypeId},</if>
            <if test="energyName != null">#{energyName},</if>
            <if test="measureUnit != null">#{measureUnit},</if>
            <if test="price != null">#{price},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateEmsBaseEnergyType" parameterType="EmsBaseEnergyType">
        update ems_base_energy_type
        <trim prefix="SET" suffixOverrides=",">
            <if test="energyTypeId != null">energy_type_id = #{energyTypeId},</if>
            <if test="energyName != null">energy_name = #{energyName},</if>
            <if test="measureUnit != null">measure_unit = #{measureUnit},</if>
            <if test="price != null">price = #{price},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteEmsBaseEnergyTypeByObjId" parameterType="Long">
        delete
        from ems_base_energy_type
        where obj_id = #{objId}
    </delete>

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