<?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.hardware.mapper.DoumuHardwareMapper">
    
    <resultMap type="DoumuHardware" id="DoumuHardwareResult">
        <result property="hardwareId"    column="hardware_id"    />
        <result property="hardwareName"    column="hardware_name"    />
        <result property="hardwareNum"    column="hardware_num"    />
        <result property="hardwareSource"    column="hardware_source"    />
        <result property="hardwareIp"    column="hardware_ip"    />
        <result property="hardwareUrl"    column="hardware_url"    />
        <result property="hardwareType"    column="hardware_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDoumuHardwareVo">
        select hardware_id, hardware_name, hardware_num, hardware_source, hardware_ip, hardware_url, hardware_type, create_time, create_by, update_by, update_time from doumu_hardware
    </sql>

    <select id="selectDoumuHardwareList" parameterType="DoumuHardware" resultMap="DoumuHardwareResult">
        <include refid="selectDoumuHardwareVo"/>
        <where>  
            <if test="hardwareName != null  and hardwareName != ''"> and hardware_name like concat('%', #{hardwareName}, '%')</if>
            <if test="hardwareNum != null  and hardwareNum != ''"> and hardware_num = #{hardwareNum}</if>
            <if test="hardwareSource != null  and hardwareSource != ''"> and hardware_source = #{hardwareSource}</if>
            <if test="hardwareIp != null  and hardwareIp != ''"> and hardware_ip = #{hardwareIp}</if>
            <if test="hardwareUrl != null  and hardwareUrl != ''"> and hardware_url = #{hardwareUrl}</if>
            <if test="hardwareType != null  and hardwareType != ''"> and hardware_type = #{hardwareType}</if>
        </where>
    </select>
    
    <select id="selectDoumuHardwareByHardwareId" parameterType="Long" resultMap="DoumuHardwareResult">
        <include refid="selectDoumuHardwareVo"/>
        where hardware_id = #{hardwareId}
    </select>
        
    <insert id="insertDoumuHardware" parameterType="DoumuHardware" useGeneratedKeys="true" keyProperty="hardwareId">
        insert into doumu_hardware
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="hardwareName != null">hardware_name,</if>
            <if test="hardwareNum != null">hardware_num,</if>
            <if test="hardwareSource != null">hardware_source,</if>
            <if test="hardwareIp != null">hardware_ip,</if>
            <if test="hardwareUrl != null">hardware_url,</if>
            <if test="hardwareType != null">hardware_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="hardwareName != null">#{hardwareName},</if>
            <if test="hardwareNum != null">#{hardwareNum},</if>
            <if test="hardwareSource != null">#{hardwareSource},</if>
            <if test="hardwareIp != null">#{hardwareIp},</if>
            <if test="hardwareUrl != null">#{hardwareUrl},</if>
            <if test="hardwareType != null">#{hardwareType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <update id="updateDoumuHardware" parameterType="DoumuHardware">
        update doumu_hardware
        <trim prefix="SET" suffixOverrides=",">
            <if test="hardwareName != null">hardware_name = #{hardwareName},</if>
            <if test="hardwareNum != null">hardware_num = #{hardwareNum},</if>
            <if test="hardwareSource != null">hardware_source = #{hardwareSource},</if>
            <if test="hardwareIp != null">hardware_ip = #{hardwareIp},</if>
            <if test="hardwareUrl != null">hardware_url = #{hardwareUrl},</if>
            <if test="hardwareType != null">hardware_type = #{hardwareType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where hardware_id = #{hardwareId}
    </update>
    <update id="setType" parameterType = "string">
        update doumu_hardware set hardware_type = #{hardwareType}
    </update>
    <update id="setTypeOpen">
        update doumu_hardware set hardware_type = #{hardwareType}
        where hardware_id in
        <foreach item="hardwareId" collection="hardwareIds" open="(" separator="," close=")">
            #{hardwareId}
        </foreach>
    </update>

    <delete id="deleteDoumuHardwareByHardwareId" parameterType="Long">
        delete from doumu_hardware where hardware_id = #{hardwareId}
    </delete>

    <delete id="deleteDoumuHardwareByHardwareIds" parameterType="String">
        delete from doumu_hardware where hardware_id in 
        <foreach item="hardwareId" collection="array" open="(" separator="," close=")">
            #{hardwareId}
        </foreach>
    </delete>
</mapper>