<?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.device.mapper.BaseInfoMapper">
    
    <resultMap type="BaseInfo" id="BaseInfoResult">
        <result property="objId"    column="obj_id"    />
        <result property="deviceCode"    column="device_code"    />
        <result property="deviceName"    column="device_name"    />
        <result property="deviceType"    column="device_type"    />
        <result property="useState"    column="use_state"    />
        <result property="deviceState"    column="device_state"    />
        <result property="locationName"    column="location_name"    />
        <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="openPassword"    column="open_password"    />
    </resultMap>

    <sql id="selectBaseInfoVo">
        select obj_id, device_code, device_name, device_type, use_state, device_state, location_name, create_by, create_time, update_by, update_time, open_password from device_base_info
    </sql>

    <select id="selectBaseInfoList" parameterType="BaseInfo" resultMap="BaseInfoResult">
        <include refid="selectBaseInfoVo"/>
        <where>  
            <if test="deviceCode != null  and deviceCode != ''"> and device_code = #{deviceCode}</if>
            <if test="deviceName != null  and deviceName != ''"> and device_name like concat('%', #{deviceName}, '%')</if>
            <if test="deviceType != null "> and device_type = #{deviceType}</if>
            <if test="useState != null  and useState != ''"> and use_state = #{useState}</if>
            <if test="deviceState != null  and deviceState != ''"> and device_state = #{deviceState}</if>
            <if test="locationName != null  and locationName != ''"> and location_name like concat('%', #{locationName}, '%')</if>
            <if test="openPassword != null  and openPassword != ''"> and open_password = #{openPassword}</if>
        </where>
    </select>
    
    <select id="selectBaseInfoByObjId" parameterType="Long" resultMap="BaseInfoResult">
        <include refid="selectBaseInfoVo"/>
        where obj_id = #{objId}
    </select>

    <insert id="insertBaseInfo" parameterType="BaseInfo" useGeneratedKeys="true" keyProperty="objId">
        insert into device_base_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="deviceCode != null">device_code,</if>
            <if test="deviceName != null">device_name,</if>
            <if test="deviceType != null">device_type,</if>
            <if test="useState != null">use_state,</if>
            <if test="deviceState != null">device_state,</if>
            <if test="locationName != null">location_name,</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="openPassword != null">open_password,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="deviceCode != null">#{deviceCode},</if>
            <if test="deviceName != null">#{deviceName},</if>
            <if test="deviceType != null">#{deviceType},</if>
            <if test="useState != null">#{useState},</if>
            <if test="deviceState != null">#{deviceState},</if>
            <if test="locationName != null">#{locationName},</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="openPassword != null">#{openPassword},</if>
         </trim>
    </insert>

    <update id="updateBaseInfo" parameterType="BaseInfo">
        update device_base_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="deviceCode != null">device_code = #{deviceCode},</if>
            <if test="deviceName != null">device_name = #{deviceName},</if>
            <if test="deviceType != null">device_type = #{deviceType},</if>
            <if test="useState != null">use_state = #{useState},</if>
            <if test="deviceState != null">device_state = #{deviceState},</if>
            <if test="locationName != null">location_name = #{locationName},</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="openPassword != null">open_password = #{openPassword},</if>
        </trim>
        where obj_id = #{objId}
    </update>

    <delete id="deleteBaseInfoByObjId" parameterType="Long">
        delete from device_base_info where obj_id = #{objId}
    </delete>

    <delete id="deleteBaseInfoByObjIds" parameterType="String">
        delete from device_base_info where obj_id in 
        <foreach item="objId" collection="array" open="(" separator="," close=")">
            #{objId}
        </foreach>
    </delete>

</mapper>