<?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.aucma.dms.mapper.DmsBaseDeviceSuppliesMapper">
    
    <resultMap type="DmsBaseDeviceSupplies" id="DmsBaseDeviceSuppliesResult">
        <result property="deviceSuppliesId"    column="device_supplies_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="suppliesName"    column="supplies_name"    />
        <result property="suppliesType"    column="supplies_type"    />
        <result property="requireAmount"    column="require_amount"    />
        <result property="remark"    column="remark"    />
        <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="selectDmsBaseDeviceSuppliesVo">
        select device_supplies_id, device_id, supplies_name, supplies_type, require_amount, remark, create_by, create_time, update_by, update_time from dms_base_device_supplies
    </sql>



    <select id="selectDmsBaseDeviceSuppliesListByDeviceId" parameterType="Long" resultMap="DmsBaseDeviceSuppliesResult">
        <include refid="selectDmsBaseDeviceSuppliesVo"/>
        where device_id = #{deviceId}
    </select>



    <select id="selectDmsBaseDeviceSuppliesList" parameterType="DmsBaseDeviceSupplies" resultMap="DmsBaseDeviceSuppliesResult">
        <include refid="selectDmsBaseDeviceSuppliesVo"/>
        <where>  
            <if test="deviceId != null "> and device_id = #{deviceId}</if>
            <if test="suppliesName != null  and suppliesName != ''"> and supplies_name like concat('%', #{suppliesName}, '%')</if>
            <if test="suppliesType != null  and suppliesType != ''"> and supplies_type = #{suppliesType}</if>
            <if test="requireAmount != null "> and require_amount = #{requireAmount}</if>
        </where>
    </select>
    
    <select id="selectDmsBaseDeviceSuppliesByDeviceSuppliesId" parameterType="Long" resultMap="DmsBaseDeviceSuppliesResult">
        <include refid="selectDmsBaseDeviceSuppliesVo"/>
        where device_supplies_id = #{deviceSuppliesId}
    </select>
        
    <insert id="insertDmsBaseDeviceSupplies" parameterType="DmsBaseDeviceSupplies" useGeneratedKeys="true" keyProperty="deviceSuppliesId">
        insert into dms_base_device_supplies
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceId != null">device_id,</if>
            <if test="suppliesName != null and suppliesName != ''">supplies_name,</if>
            <if test="suppliesType != null and suppliesType != ''">supplies_type,</if>
            <if test="requireAmount != null">require_amount,</if>
            <if test="remark != null">remark,</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="deviceId != null">#{deviceId},</if>
            <if test="suppliesName != null and suppliesName != ''">#{suppliesName},</if>
            <if test="suppliesType != null and suppliesType != ''">#{suppliesType},</if>
            <if test="requireAmount != null">#{requireAmount},</if>
            <if test="remark != null">#{remark},</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="updateDmsBaseDeviceSupplies" parameterType="DmsBaseDeviceSupplies">
        update dms_base_device_supplies
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceId != null">device_id = #{deviceId},</if>
            <if test="suppliesName != null and suppliesName != ''">supplies_name = #{suppliesName},</if>
            <if test="suppliesType != null and suppliesType != ''">supplies_type = #{suppliesType},</if>
            <if test="requireAmount != null">require_amount = #{requireAmount},</if>
            <if test="remark != null">remark = #{remark},</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 device_supplies_id = #{deviceSuppliesId}
    </update>

    <delete id="deleteDmsBaseDeviceSuppliesByDeviceSuppliesId" parameterType="Long">
        delete from dms_base_device_supplies where device_supplies_id = #{deviceSuppliesId}
    </delete>

    <delete id="deleteDmsBaseDeviceSuppliesByDeviceSuppliesIds" parameterType="String">
        delete from dms_base_device_supplies where device_supplies_id in 
        <foreach item="deviceSuppliesId" collection="array" open="(" separator="," close=")">
            #{deviceSuppliesId}
        </foreach>
    </delete>
</mapper>