<?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.yanzhu.manage.mapper.AttendanceUbiDeviceMapper">
    
    <resultMap type="AttendanceUbiDevice" id="AttendanceUbiDeviceResult">
        <result property="id"    column="id"    />
        <result property="comId"    column="com_id"    />
        <result property="projectId"    column="project_id"    />
        <result property="name"    column="name"    />
        <result property="tag"    column="tag"    />
        <result property="sceneGuid"    column="scene_guid"    />
        <result property="source"    column="source"    />
        <result property="deviceNo"    column="device_no"    />
        <result property="addition"    column="addition"    />
        <result property="bindDefaultScene"    column="bind_default_scene"    />
        <result property="forceEmptyDevice"    column="force_empty_device"    />
        <result property="password"    column="password"    />
        <result property="deviceModel"    column="device_model"    />
        <result property="deviceState"    column="device_state"    />
        <result property="recType"    column="rec_type"    />
        <result property="onlineState"    column="online_state"    />
        <result property="versionNo"    column="version_no"    />
        <result property="lastActiveTime"    column="last_active_time"    />
        <result property="hasRegister"    column="has_register"    />
        <result property="state"    column="state"    />
        <result property="remark"    column="remark"    />
        <result property="isDel"    column="is_del"    />
        <result property="direction"    column="direction"    />
        <result property="channel"    column="channel"    />
        <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="compName" column="comp_name"/>
        <result property="projectName" column="project_name"/>
        <result property="souceName" column="souce_name"/>
    </resultMap>

    <sql id="selectAttendanceUbiDeviceVo">
        select ud.id, ud.com_id, ud.project_id, ud.name, ud.tag, ud.scene_guid, ud.source, ud.device_no, ud.addition, ud.bind_default_scene, ud.force_empty_device,
               ud.direction,ud.channel,
               ud.device_model, ud.device_state, ud.rec_type, ud.online_state, ud.version_no, ud.last_active_time, ud.has_register, ud.state, ud.remark, ud.is_del,
               ud.create_by, ud.create_time, ud.update_by, ud.update_time ,dp.`dept_name` comp_name,pp.`project_name`,dic.`dict_label` souce_name
        from attendance_ubi_device ud
                 left join sys_dept dp on ud.`com_id`=dp.`dept_id`
                 left join pro_project_info pp on ud.`project_id`=pp.`id`
                 left join sys_dict_data dic on ud.`source`=dic.`dict_value` and dic.`dict_type`='ubi_device_source'
    </sql>

    <select id="selectAttendanceUbiDeviceList" parameterType="AttendanceUbiDevice" resultMap="AttendanceUbiDeviceResult">
        <include refid="selectAttendanceUbiDeviceVo"/>
        <where>  
            <if test="comId != null "> and ud.com_id = #{comId}</if>
            <if test="projectId != null "> and ud.project_id = #{projectId}</if>
            <if test="name != null  and name != ''"> and ud.name like concat('%', #{name}, '%')</if>
            <if test="tag != null  and tag != ''"> and ud.tag = #{tag}</if>
            <if test="sceneGuid != null  and sceneGuid != ''"> and ud.scene_guid = #{sceneGuid}</if>
            <if test="source != null  and source != ''"> and ud.source = #{source}</if>
            <if test="deviceNo != null  and deviceNo != ''"> and ud.device_no = #{deviceNo}</if>
            <if test="addition != null  and addition != ''"> and ud.addition = #{addition}</if>
            <if test="bindDefaultScene != null "> and ud.bind_default_scene = #{bindDefaultScene}</if>
            <if test="forceEmptyDevice != null "> and ud.force_empty_device = #{forceEmptyDevice}</if>
            <if test="deviceModel != null  and deviceModel != ''"> and ud.device_model = #{deviceModel}</if>
            <if test="deviceState != null "> and ud.device_state = #{deviceState}</if>
            <if test="recType != null "> and ud.rec_type = #{recType}</if>
            <if test="onlineState != null "> and ud.online_state = #{onlineState}</if>
            <if test="versionNo != null  and versionNo != ''"> and ud.version_no = #{versionNo}</if>
            <if test="lastActiveTime != null "> and ud.last_active_time = #{lastActiveTime}</if>
            <if test="hasRegister != null "> and ud.has_register = #{hasRegister}</if>
            <if test="state != null "> and ud.state = #{state}</if>
            <if test="isDel != null "> and ud.is_del = #{isDel}</if>
        </where>
    </select>
    
    <select id="selectAttendanceUbiDeviceById" parameterType="Long" resultMap="AttendanceUbiDeviceResult">
        <include refid="selectAttendanceUbiDeviceVo"/>
        where ud.id = #{id}
    </select>
    <select id="selectAttendanceUbiDeviceByNo" parameterType="String" resultMap="AttendanceUbiDeviceResult">
        <include refid="selectAttendanceUbiDeviceVo"/>
        where ud.device_no = #{no}
    </select>

    <insert id="insertAttendanceUbiDevice" parameterType="AttendanceUbiDevice" useGeneratedKeys="true" keyProperty="id">
        insert into attendance_ubi_device
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="comId != null">com_id,</if>
            <if test="projectId != null">project_id,</if>
            <if test="name != null">name,</if>
            <if test="tag != null">tag,</if>
            <if test="sceneGuid != null">scene_guid,</if>
            <if test="source != null">source,</if>
            <if test="deviceNo != null">device_no,</if>
            <if test="addition != null">addition,</if>
            <if test="bindDefaultScene != null">bind_default_scene,</if>
            <if test="forceEmptyDevice != null">force_empty_device,</if>
            <if test="password != null">password,</if>
            <if test="deviceModel != null">device_model,</if>
            <if test="deviceState != null">device_state,</if>
            <if test="recType != null">rec_type,</if>
            <if test="onlineState != null">online_state,</if>
            <if test="versionNo != null">version_no,</if>
            <if test="lastActiveTime != null">last_active_time,</if>
            <if test="hasRegister != null">has_register,</if>
            <if test="state != null">state,</if>
            <if test="remark != null">remark,</if>
            <if test="isDel != null">is_del,</if>
            <if test="direction != null">direction,</if>
            <if test="channel != null">channel,</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="id != null">#{id},</if>
            <if test="comId != null">#{comId},</if>
            <if test="projectId != null">#{projectId},</if>
            <if test="name != null">#{name},</if>
            <if test="tag != null">#{tag},</if>
            <if test="sceneGuid != null">#{sceneGuid},</if>
            <if test="source != null">#{source},</if>
            <if test="deviceNo != null">#{deviceNo},</if>
            <if test="addition != null">#{addition},</if>
            <if test="bindDefaultScene != null">#{bindDefaultScene},</if>
            <if test="forceEmptyDevice != null">#{forceEmptyDevice},</if>
            <if test="password != null">#{password},</if>
            <if test="deviceModel != null">#{deviceModel},</if>
            <if test="deviceState != null">#{deviceState},</if>
            <if test="recType != null">#{recType},</if>
            <if test="onlineState != null">#{onlineState},</if>
            <if test="versionNo != null">#{versionNo},</if>
            <if test="lastActiveTime != null">#{lastActiveTime},</if>
            <if test="hasRegister != null">#{hasRegister},</if>
            <if test="state != null">#{state},</if>
            <if test="remark != null">#{remark},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="direction != null">#{direction},</if>
            <if test="channel != null">#{channel},</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="updateAttendanceUbiDevice" parameterType="AttendanceUbiDevice">
        update attendance_ubi_device
        <trim prefix="SET" suffixOverrides=",">
            <if test="comId != null">com_id = #{comId},</if>
            <if test="projectId != null">project_id = #{projectId},</if>
            <if test="name != null">name = #{name},</if>
            <if test="tag != null">tag = #{tag},</if>
            <if test="sceneGuid != null">scene_guid = #{sceneGuid},</if>
            <if test="source != null">source = #{source},</if>
            <if test="deviceNo != null">device_no = #{deviceNo},</if>
            <if test="addition != null">addition = #{addition},</if>
            <if test="bindDefaultScene != null">bind_default_scene = #{bindDefaultScene},</if>
            <if test="forceEmptyDevice != null">force_empty_device = #{forceEmptyDevice},</if>
            <if test="password != null">password = #{password},</if>
            <if test="deviceModel != null">device_model = #{deviceModel},</if>
            <if test="deviceState != null">device_state = #{deviceState},</if>
            <if test="recType != null">rec_type = #{recType},</if>
            <if test="onlineState != null">online_state = #{onlineState},</if>
            <if test="versionNo != null">version_no = #{versionNo},</if>
            <if test="lastActiveTime != null">last_active_time = #{lastActiveTime},</if>
            <if test="hasRegister != null">has_register = #{hasRegister},</if>
            <if test="state != null">state = #{state},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="direction != null">direction = #{direction},</if>
            <if test="channel != null">channel = #{channel},</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 id = #{id}
    </update>

    <delete id="deleteAttendanceUbiDeviceById" parameterType="Long">
        delete from attendance_ubi_device where id = #{id}
    </delete>

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