<?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.xinelu.manage.mapper.nursestationitemprice.NurseStationItemPriceMapper">

    <resultMap type="NurseStationItemPrice" id="NurseStationItemPriceResult">
        <result property="id" column="id"/>
        <result property="nurseStationItemId" column="nurse_station_item_id"/>
        <result property="serveDurationUnit" column="serve_duration_unit"/>
        <result property="price" column="price"/>
        <result property="description" column="description"/>
        <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="commissionAmount" column="commission_amount"/>
        <result property="commissionRate" column="commission_rate"/>
    </resultMap>

    <sql id="selectNurseStationItemPriceVo">
        select id,
               nurse_station_item_id,
               serve_duration_unit,
               price,
               description,
               create_by,
               create_time,
               update_by,
               update_time,
               commission_amount,
               commission_rate
        from nurse_station_item_price
    </sql>

    <select id="selectNurseStationItemPriceList" parameterType="NurseStationItemPrice"
            resultMap="NurseStationItemPriceResult">
        <include refid="selectNurseStationItemPriceVo"/>
        <where>
            <if test="nurseStationItemId != null ">
                and nurse_station_item_id = #{nurseStationItemId}
            </if>
            <if test="serveDurationUnit != null  and serveDurationUnit != ''">
                and serve_duration_unit = #{serveDurationUnit}
            </if>
            <if test="price != null ">
                and price = #{price}
            </if>
            <if test="description != null  and description != ''">
                and description = #{description}
            </if>
        </where>
    </select>

    <select id="selectNurseStationItemPriceById" parameterType="Long"
            resultMap="NurseStationItemPriceResult">
        <include refid="selectNurseStationItemPriceVo"/>
        where id = #{id}
    </select>

    <!--    <insert id="insertNurseStationItemPrice" parameterType="NurseStationItemPrice" useGeneratedKeys="true"
                keyProperty="id">
            insert into nurse_station_item_price
            <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="nurseStationItemId != null">nurse_station_item_id,
                </if>
                <if test="serveDurationUnit != null">serve_duration_unit,
                </if>
                <if test="price != null">price,
                </if>
                <if test="description != null">description,
                </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="nurseStationItemId != null">#{nurseStationItemId},
                </if>
                <if test="serveDurationUnit != null">#{serveDurationUnit},
                </if>
                <if test="price != null">#{price},
                </if>
                <if test="description != null">#{description},
                </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>-->
    <insert id="insertNurseStationItemPrice" parameterType="java.util.List">
        INSERT INTO
        nurse_station_item_price(nurse_station_item_id, serve_duration_unit, price, description,create_by, create_time,
        update_by, update_time,commission_amount,commission_rate)
        VALUES
        <foreach collection="list" item="productCategory" index="index"
                 separator=",">
            (
            #{productCategory.nurseStationItemId},
            #{productCategory.serveDurationUnit},
            #{productCategory.price},
            #{productCategory.description},
            #{productCategory.createBy},
            #{productCategory.createTime},
            #{productCategory.updateBy},
            #{productCategory.updateTime},
            #{productCategory.commissionAmount},
            #{productCategory.commissionRate}
            )
        </foreach>
    </insert>
    <update id="updateNurseStationItemPrice" parameterType="NurseStationItemPrice">
        update nurse_station_item_price
        <trim prefix="SET" suffixOverrides=",">
            <if test="nurseStationItemId != null">nurse_station_item_id =
                #{nurseStationItemId},
            </if>
            <if test="serveDurationUnit != null">serve_duration_unit =
                #{serveDurationUnit},
            </if>
            <if test="price != null">price =
                #{price},
            </if>
            <if test="description != null">description =
                #{description},
            </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="commissionAmount != null">commission_amount =
                #{commissionAmount},
            </if>
            <if test="commissionRate != null">commission_rate =
                #{commissionRate},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteNurseStationItemPriceById" parameterType="Long">
        delete
        from nurse_station_item_price
        where id = #{id}
    </delete>
    <delete id="deleteNurseStationItemPriceByItemId" parameterType="Long">
        delete
        from nurse_station_item_price
        where nurse_station_item_id = #{id}
    </delete>

    <delete id="deleteNurseStationItemPriceByIds" parameterType="String">
        delete from nurse_station_item_price where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <delete id="deleteNurseStationItemPriceByItemIds" parameterType="String">
        delete from nurse_station_item_price where nurse_station_item_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
    <select id="getNurseStationItemPriceByList" parameterType="NurseStationItemPrice"
            resultType="NurseStationItemPrice">
        <include refid="selectNurseStationItemPriceVo"/>
        <where>
            <if test="idList != null and idList.size() > 0">
                and nurse_station_item_id in
                <foreach item="nurseStationId" collection="idList" open="(" separator="," close=")">
                    #{nurseStationId}
                </foreach>
            </if>
        </where>
    </select>
</mapper>