<?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="me.zhengjie.modules.system.mapper.BusUserCommandMapper">
    <resultMap id="BaseResultMap" type="me.zhengjie.modules.system.domain.BusUserCommand">
        <id column="id" property="id"/>
        <result column="user_id" property="userId"/>
        <result column="device_id" property="deviceId"/>
        <result column="command_id" property="commandId"/>
        <result column="create_by" property="createBy"/>
        <result column="update_by" property="updateBy"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <insert id="bindingCommand">
        insert into bus_user_device_command (user_id, device_id, command_id)
        select #{userId}, device_id, id from bus_device_command where id in
        <foreach collection="commandIds" item="id" index="index" open="(" close=")" separator=",">
            #{id}
        </foreach>
    </insert>

    <sql id="Base_Column_List">
        id, user_id, device_id, command_id, create_by, update_by, create_time, update_time
    </sql>

    <select id="findAll" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from bus_user_device_command
        <where>
        </where>
        order by id desc
    </select>
</mapper>