<?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.hw.ems.base.mapper.BaseEnergyTypeMapper">

    <resultMap type="BaseEnergyType" id="BaseEnergyTypeResult">
        <result property="objid"    column="objid"    />
        <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="deptId"    column="dept_id"    />
        <result property="userId"    column="user_id"    />
        <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="selectBaseEnergyTypeVo">
        select objid, energy_type_id, energy_name, measure_unit, price, dept_id,
               user_id, create_by, create_time, update_by, update_time from base_energy_type
    </sql>

    <select id="selectBaseEnergyTypeList" parameterType="BaseEnergyType" resultMap="BaseEnergyTypeResult">
        select t.objid, t.energy_type_id, dict.dict_label energy_name, t.measure_unit, t.price, t.dept_id,
               t.user_id, t.create_by, t.create_time, t.update_by, t.update_time
        from base_energy_type t
        left join sys_dict_data dict on dict.dict_value = t.energy_type_id and dict.dict_type = 'energy_type'
        <where>
            <if test="energyTypeId != null "> and t.energy_type_id = #{energyTypeId}</if>
            <if test="energyName != null  and energyName != ''"> and t.energy_name like concat('%', #{energyName}, '%')</if>
            <if test="measureUnit != null  and measureUnit != ''"> and t.measure_unit = #{measureUnit}</if>
            <if test="price != null "> and t.price = #{price}</if>
            <if test="deptId != null "> and t.dept_id = #{deptId}</if>
            <if test="userId != null "> and t.user_id = #{userId}</if>
        </where>
    </select>
<!--    <select id="selectBaseEnergyTypeList" parameterType="BaseEnergyType" resultMap="BaseEnergyTypeResult">-->
<!--        <include refid="selectBaseEnergyTypeVo"/>-->
<!--        <where>-->
<!--            <if test="energyTypeId != null "> and t.energy_type_id = #{energyTypeId}</if>-->
<!--            <if test="energyName != null  and energyName != ''"> and t.energy_name like concat('%', #{energyName}, '%')</if>-->
<!--            <if test="measureUnit != null  and measureUnit != ''"> and t.measure_unit = #{measureUnit}</if>-->
<!--            <if test="price != null "> and t.price = #{price}</if>-->
<!--            <if test="deptId != null "> and t.dept_id = #{deptId}</if>-->
<!--            <if test="userId != null "> and t.user_id = #{userId}</if>-->
<!--        </where>-->
<!--    </select>-->

    <select id="selectBaseEnergyTypeByObjid" parameterType="Long" resultMap="BaseEnergyTypeResult">
        <include refid="selectBaseEnergyTypeVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseEnergyType" parameterType="BaseEnergyType" useGeneratedKeys="true" keyProperty="objid">
        insert into 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="deptId != null">dept_id,</if>
            <if test="userId != null">user_id,</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="deptId != null">#{deptId},</if>
            <if test="userId != null">#{userId},</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="updateBaseEnergyType" parameterType="BaseEnergyType">
        update 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="deptId != null">dept_id = #{deptId},</if>
            <if test="userId != null">user_id = #{userId},</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 objid = #{objid}
    </update>

    <delete id="deleteBaseEnergyTypeByObjid" parameterType="Long">
        delete from base_energy_type where objid = #{objid}
    </delete>

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