<?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.appointmentorderconsumable.AppointmentOrderConsumableMapper">

    <resultMap type="AppointmentOrderConsumable" id="AppointmentOrderConsumableResult">
        <result property="id" column="id"/>
        <result property="appointOrderDetailsId" column="appoint_order_details_id"/>
        <result property="orderConsumableName" column="order_consumable_name"/>
        <result property="orderConsumablePrice" column="order_consumable_price"/>
        <result property="orderConsumableCount" column="order_consumable_count"/>
        <result property="delFlag" column="del_flag"/>
        <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="selectAppointmentOrderConsumableVo">
        select id,
               appoint_order_details_id,
               order_consumable_name,
               order_consumable_price,
               order_consumable_count,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from appointment_order_consumable
    </sql>

    <select id="selectAppointmentOrderConsumableList" parameterType="AppointmentOrderConsumable"
            resultMap="AppointmentOrderConsumableResult">
        <include refid="selectAppointmentOrderConsumableVo"/>
        <where>
            <if test="appointOrderDetailsId != null ">
                and appoint_order_details_id = #{appointOrderDetailsId}
            </if>
            <if test="orderConsumableName != null  and orderConsumableName != ''">
                and order_consumable_name like concat('%', #{orderConsumableName}, '%')
            </if>
            <if test="orderConsumablePrice != null ">
                and order_consumable_price = #{orderConsumablePrice}
            </if>
        </where>
    </select>

    <select id="selectAppointmentOrderConsumableById" parameterType="Long"
            resultMap="AppointmentOrderConsumableResult">
        <include refid="selectAppointmentOrderConsumableVo"/>
        where id = #{id}
    </select>

    <insert id="insertAppointmentOrderConsumable" parameterType="AppointmentOrderConsumable" useGeneratedKeys="true"
            keyProperty="id">
        insert into appointment_order_consumable
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="appointOrderDetailsId != null">appoint_order_details_id,
            </if>
            <if test="orderConsumableName != null">order_consumable_name,
            </if>
            <if test="orderConsumablePrice != null">order_consumable_price,
            </if>
            <if test="orderConsumableCount != null">order_consumable_count,
            </if>
            <if test="delFlag != null">del_flag,
            </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="appointOrderDetailsId != null">#{appointOrderDetailsId},
            </if>
            <if test="orderConsumableName != null">#{orderConsumableName},
            </if>
            <if test="orderConsumablePrice != null">#{orderConsumablePrice},
            </if>
            <if test="orderConsumableCount != null">#{orderConsumableCount},
            </if>
            <if test="delFlag != null">#{delFlag},
            </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="updateAppointmentOrderConsumable" parameterType="AppointmentOrderConsumable">
        update appointment_order_consumable
        <trim prefix="SET" suffixOverrides=",">
            <if test="appointOrderDetailsId != null">appoint_order_details_id =
                #{appointOrderDetailsId},
            </if>
            <if test="orderConsumableName != null">order_consumable_name =
                #{orderConsumableName},
            </if>
            <if test="orderConsumablePrice != null">order_consumable_price =
                #{orderConsumablePrice},
            </if>
            <if test="orderConsumableCount != null">order_consumable_count =
                #{orderConsumableCount},
            </if>
            <if test="delFlag != null">del_flag =
                #{delFlag},
            </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>

    <update id="updateAppointmentOrderConsumableById" parameterType="Long">
        update
        appointment_order_consumable
        set del_flag = 1 ,update_time = now()
        where id = #{id}
    </update>

    <select id="getAppointmentOrderDetailsList" parameterType="AppointmentOrderConsumable"
            resultMap="AppointmentOrderConsumableResult">
        select id,
               appoint_order_details_id,
               order_consumable_name,
               order_consumable_price,
               order_consumable_count,
               del_flag,
               create_by,
               create_time,
               update_by,
               update_time
        from appointment_order_consumable
        where id = #{id}
    </select>

    <update id="updateAppointmentOrderConsumableByIds" parameterType="String">
        update appointment_order_consumable set del_flag = 1 ,update_time = now() where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="getByAppointOrderDetailsId" parameterType="AppointmentOrderConsumable"
            resultMap="AppointmentOrderConsumableResult">
        SELECT
        id,
        appoint_order_details_id,
        order_consumable_name,
        order_consumable_price,
        order_consumable_count,
        del_flag,
        create_by,
        create_time,
        update_by,
        update_time
        FROM
        appointment_order_consumable
        <where>
            <if test="appointOrderDetailsId != null  and appointOrderDetailsId != ''">
                appoint_order_details_id = #{appointOrderDetailsId}
            </if>
        </where>
    </select>
</mapper>
