<?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.nursestationItemconsumable.NurseStationItemConsumableMapper">

    <resultMap type="NurseStationItemConsumable" id="NurseStationItemConsumableResult">
        <result property="id" column="id"/>
        <result property="nurseStationItemId" column="nurse_station_item_id"/>
        <result property="nurseStationConsumableId" column="nurse_station_consumable_id"/>
        <result property="consumableDetail" column="consumable_detail"/>
        <result property="consumableUnit" column="consumable_unit"/>
        <result property="consumableCount" column="consumable_count"/>
        <result property="consumablePrice" column="consumable_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="selectNurseStationItemConsumableVo">
        select id,
               nurse_station_item_id,
               nurse_station_consumable_id,
               consumable_detail,
               consumable_unit,
               consumable_count,
               consumable_price,
               create_by,
               create_time,
               update_by,
               update_time
        from nurse_station_item_consumable
    </sql>

    <select id="selectNurseStationItemConsumableList" parameterType="NurseStationItemConsumable"
            resultType="com.xinelu.manage.vo.nursestationitemconsumable.NurseStationItemConsumableVO">
        select nsic.*, nsc.consumable_detail, nsc.consumable_code,nsc.consumable_unit
        from nurse_station_item_consumable nsic
        LEFT JOIN nurse_station_consumable nsc ON nsc.id = nsic.nurse_station_consumable_id
        <where>
            <if test="nurseStationItemId != null ">
                and nsic.nurse_station_item_id = #{nurseStationItemId}
            </if>
            <if test="nurseStationConsumableId != null ">
                and nsic.nurse_station_consumable_id = #{nurseStationConsumableId}
            </if>
            <if test="consumableCount != null ">
                and nsic.consumable_count = #{consumableCount}
            </if>
            <if test="consumablePrice != null ">
                and nsic.consumable_price = #{consumablePrice}
            </if>
        </where>
    </select>

    <select id="selectNurseStationItemConsumableById" parameterType="Long"
            resultType="com.xinelu.manage.vo.nursestationitemconsumable.NurseStationItemConsumableVO">
        select nsic.*, nsc.consumable_detail, nsc.consumable_code, nsc.consumable_unit
        from nurse_station_item_consumable nsic
                 LEFT JOIN nurse_station_consumable nsc ON nsc.id = nsic.nurse_station_consumable_id
        where nsic.id = #{id}
    </select>

    <!--   <insert id="insertNurseStationItemConsumable" parameterType="NurseStationItemConsumable" useGeneratedKeys="true"
               keyProperty="id">
           insert into nurse_station_item_consumable
           <trim prefix="(" suffix=")" suffixOverrides=",">
               <if test="nurseStationItemId != null">nurse_station_item_id,
               </if>
               <if test="nurseStationConsumableId != null">nurse_station_consumable_id,
               </if>
               <if test="consumableCount != null">consumable_count,
               </if>
               <if test="consumablePrice != null">consumable_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="nurseStationItemId != null">#{nurseStationItemId},
               </if>
               <if test="nurseStationConsumableId != null">#{nurseStationConsumableId},
               </if>
               <if test="consumableCount != null">#{consumableCount},
               </if>
               <if test="consumablePrice != null">#{consumablePrice},
               </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="insertNurseStationItemConsumable" parameterType="java.util.List">
        INSERT INTO
        nurse_station_item_consumable(nurse_station_item_id,
        nurse_station_consumable_id,consumable_detail,consumable_unit, consumable_count,
        consumable_price,create_by, create_time, update_by, update_time)
        VALUES
        <foreach collection="list" item="productCategory" index="index"
                 separator=",">
            (
            #{productCategory.nurseStationItemId},
            #{productCategory.nurseStationConsumableId},
            #{productCategory.consumableDetail},
            #{productCategory.consumableUnit},
            #{productCategory.consumableCount},
            #{productCategory.consumablePrice},
            #{productCategory.createBy},
            #{productCategory.createTime},
            #{productCategory.updateBy},
            #{productCategory.updateTime}
            )
        </foreach>
    </insert>

    <update id="updateNurseStationItemConsumable" parameterType="NurseStationItemConsumable">
        update nurse_station_item_consumable
        <trim prefix="SET" suffixOverrides=",">
            <if test="nurseStationItemId != null">nurse_station_item_id =
                #{nurseStationItemId},
            </if>
            <if test="nurseStationConsumableId != null">nurse_station_consumable_id =
                #{nurseStationConsumableId},
            </if>
            <if test="consumableDetail != null">consumable_detail =
                #{consumableDetail},
            </if>
            <if test="consumableUnit != null">consumable_unit =
                #{consumableUnit},
            </if>
            <if test="consumableCount != null">consumable_count =
                #{consumableCount},
            </if>
            <if test="consumablePrice != null">consumable_price =
                #{consumablePrice},
            </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 id = #{id}
    </update>

    <delete id="deleteNurseStationItemConsumableById" parameterType="Long">
        delete
        from nurse_station_item_consumable
        where id = #{id}
    </delete>

    <delete id="deleteNurseStationItemConsumableByItemId" parameterType="Long">
        delete
        from nurse_station_item_consumable
        where nurse_station_item_id = #{id}
    </delete>

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

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