<?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.ManageDeviceDictionaryMapper">

    <resultMap type="ManageDeviceDictionary" id="ManageDeviceDictionaryResult">
        <result property="id" column="id"/>
        <result property="domain" column="domain"/>
        <result property="deviceType" column="device_type"/>
        <result property="subType" column="sub_type"/>
        <result property="deviceName" column="device_name"/>
        <result property="deviceDesc" column="device_desc"/>
    </resultMap>

    <sql id="selectManageDeviceDictionaryVo">
        select id, domain, device_type, sub_type, device_name, device_desc
        from manage_device_dictionary
    </sql>

    <select id="selectManageDeviceDictionaryList" parameterType="ManageDeviceDictionary"
            resultMap="ManageDeviceDictionaryResult">
        <include refid="selectManageDeviceDictionaryVo"/>
        <where>
            <if test="domain != null ">and domain = #{domain}</if>
            <if test="deviceType != null ">and device_type = #{deviceType}</if>
            <if test="subType != null ">and sub_type = #{subType}</if>
            <if test="deviceName != null  and deviceName != ''">and device_name like concat('%', #{deviceName}, '%')
            </if>
            <if test="deviceDesc != null  and deviceDesc != ''">and device_desc = #{deviceDesc}</if>
        </where>
    </select>

    <select id="selectManageDeviceDictionaryById" parameterType="Integer" resultMap="ManageDeviceDictionaryResult">
        <include refid="selectManageDeviceDictionaryVo"/>
        where id = #{id}
    </select>

    <select id="selectManageDeviceDictionaryByCondition" resultMap="ManageDeviceDictionaryResult">
        select *
        from manage_device_dictionary
        where domain = #{domain}
          and device_type = #{deviceType}
          and sub_type = #{subType}
    </select>

    <insert id="insertManageDeviceDictionary" parameterType="ManageDeviceDictionary" useGeneratedKeys="true"
            keyProperty="id">
        insert into manage_device_dictionary
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="domain != null">domain,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="subType != null">sub_type,</if>
            <if test="deviceName != null and deviceName != ''">device_name,</if>
            <if test="deviceDesc != null">device_desc,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="domain != null">#{domain},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="subType != null">#{subType},</if>
            <if test="deviceName != null and deviceName != ''">#{deviceName},</if>
            <if test="deviceDesc != null">#{deviceDesc},</if>
        </trim>
    </insert>

    <update id="updateManageDeviceDictionary" parameterType="ManageDeviceDictionary">
        update manage_device_dictionary
        <trim prefix="SET" suffixOverrides=",">
            <if test="domain != null">domain = #{domain},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="subType != null">sub_type = #{subType},</if>
            <if test="deviceName != null and deviceName != ''">device_name = #{deviceName},</if>
            <if test="deviceDesc != null">device_desc = #{deviceDesc},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteManageDeviceDictionaryById" parameterType="Integer">
        delete
        from manage_device_dictionary
        where id = #{id}
    </delete>

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