<?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.system.mapper.EquipmentConfigurationMapper">
    
    <resultMap type="EquipmentConfiguration" id="EquipmentConfigurationResult">
        <result property="equipmentId"    column="equipment_id"    />
        <result property="loginName"    column="login_name"    />
        <result property="loginPwd"    column="login_pwd"    />
        <result property="equipmentName"    column="equipment_name"    />
        <result property="equipmentPort"    column="equipment_port"    />
        <result property="equipmentIp"    column="equipment_ip"    />
        <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="remark"    column="remark"    />
    </resultMap>

    <sql id="selectEquipmentConfigurationVo">
        select equipment_id, login_name, login_pwd, equipment_name, equipment_port, equipment_ip, create_by, create_time, update_by, update_time, remark from equipment_configuration
    </sql>

    <select id="selectEquipmentConfigurationList" parameterType="EquipmentConfiguration" resultMap="EquipmentConfigurationResult">
        <include refid="selectEquipmentConfigurationVo"/>
        <where>  
            <if test="loginName != null  and loginName != ''"> and login_name like concat('%', #{loginName}, '%')</if>
            <if test="loginPwd != null  and loginPwd != ''"> and login_pwd = #{loginPwd}</if>
            <if test="equipmentName != null  and equipmentName != ''"> and equipment_name like concat('%', #{equipmentName}, '%')</if>
            <if test="equipmentPort != null  and equipmentPort != ''"> and equipment_port = #{equipmentPort}</if>
            <if test="equipmentIp != null  and equipmentIp != ''"> and equipment_ip = #{equipmentIp}</if>
        </where>
    </select>
    
    <select id="selectEquipmentConfigurationByEquipmentId" parameterType="Long" resultMap="EquipmentConfigurationResult">
        <include refid="selectEquipmentConfigurationVo"/>
        where equipment_id = #{equipmentId}
    </select>
    <select id="selectEquipmentConfigurationByEquipmentName" parameterType="Long" resultMap="EquipmentConfigurationResult">
        <include refid="selectEquipmentConfigurationVo"/>
        where equipment_name =  #{equipmentName} limit 1
    </select>

    <insert id="insertEquipmentConfiguration" parameterType="EquipmentConfiguration" useGeneratedKeys="true" keyProperty="equipmentId">
        insert into equipment_configuration
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="loginName != null and loginName != ''">login_name,</if>
            <if test="loginPwd != null and loginPwd != ''">login_pwd,</if>
            <if test="equipmentName != null">equipment_name,</if>
            <if test="equipmentPort != null">equipment_port,</if>
            <if test="equipmentIp != null">equipment_ip,</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>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="loginName != null and loginName != ''">#{loginName},</if>
            <if test="loginPwd != null and loginPwd != ''">#{loginPwd},</if>
            <if test="equipmentName != null">#{equipmentName},</if>
            <if test="equipmentPort != null">#{equipmentPort},</if>
            <if test="equipmentIp != null">#{equipmentIp},</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>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateEquipmentConfiguration" parameterType="EquipmentConfiguration">
        update equipment_configuration
        <trim prefix="SET" suffixOverrides=",">
            <if test="loginName != null and loginName != ''">login_name = #{loginName},</if>
            <if test="loginPwd != null and loginPwd != ''">login_pwd = #{loginPwd},</if>
            <if test="equipmentName != null">equipment_name = #{equipmentName},</if>
            <if test="equipmentPort != null">equipment_port = #{equipmentPort},</if>
            <if test="equipmentIp != null">equipment_ip = #{equipmentIp},</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="remark != null">remark = #{remark},</if>
        </trim>
        where equipment_id = #{equipmentId}
    </update>

    <delete id="deleteEquipmentConfigurationByEquipmentId" parameterType="Long">
        delete from equipment_configuration where equipment_id = #{equipmentId}
    </delete>

    <delete id="deleteEquipmentConfigurationByEquipmentIds" parameterType="String">
        delete from equipment_configuration where equipment_id in 
        <foreach item="equipmentId" collection="array" open="(" separator="," close=")">
            #{equipmentId}
        </foreach>
    </delete>
</mapper>