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

    <resultMap type="EmsBaseSharePrice" id="EmsBaseSharePriceResult">
        <result property="objId" column="obj_id"/>
        <result property="yearMonthDate" column="year_month_date"/>
        <result property="priceType" column="price_type"/>
        <result property="startHour" column="start_hour"/>
        <result property="endHour" column="end_hour"/>
        <result property="dnbPrice" column="dnb_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"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectEmsBaseSharePriceVo">
        select obj_id,
               year_month_date,
               price_type,
               start_hour,
               end_hour,
               dnb_price,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from ems_base_share_price
    </sql>

    <select id="selectEmsBaseSharePriceList" parameterType="EmsBaseSharePrice" resultMap="EmsBaseSharePriceResult">
        <include refid="selectEmsBaseSharePriceVo"/>
        <where>
            <if test="yearMonthDate != null  and yearMonthDate != ''">and year_month_date = #{yearMonthDate}</if>
            <if test="priceType != null  and priceType != ''">and price_type = #{priceType}</if>
            <if test="startHour != null ">and start_hour = #{startHour}</if>
            <if test="endHour != null ">and end_hour = #{endHour}</if>
            <if test="dnbPrice != null ">and dnb_price = #{dnbPrice}</if>
        </where>
        order by year_month_date desc
    </select>

    <select id="selectEmsBaseSharePriceByObjId" parameterType="Long" resultMap="EmsBaseSharePriceResult">
        <include refid="selectEmsBaseSharePriceVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertEmsBaseSharePrice" parameterType="EmsBaseSharePrice" useGeneratedKeys="true" keyProperty="objId">
        insert into ems_base_share_price
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="yearMonthDate != null">year_month_date,</if>
            <if test="priceType != null">price_type,</if>
            <if test="startHour != null">start_hour,</if>
            <if test="endHour != null">end_hour,</if>
            <if test="dnbPrice != null">dnb_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>
            <if test="remark != null">remark,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="yearMonthDate != null">#{yearMonthDate},</if>
            <if test="priceType != null">#{priceType},</if>
            <if test="startHour != null">#{startHour},</if>
            <if test="endHour != null">#{endHour},</if>
            <if test="dnbPrice != null">#{dnbPrice},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updateEmsBaseSharePrice" parameterType="EmsBaseSharePrice">
        update ems_base_share_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="yearMonthDate != null">year_month_date = #{yearMonthDate},</if>
            <if test="priceType != null">price_type = #{priceType},</if>
            <if test="startHour != null">start_hour = #{startHour},</if>
            <if test="endHour != null">end_hour = #{endHour},</if>
            <if test="dnbPrice != null">dnb_price = #{dnbPrice},</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>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where obj_id = #{objId}
    </update>

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

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