<?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.fastbee.iot.mapper.OrderControlMapper">

    <resultMap type="com.fastbee.iot.domain.OrderControl" id="OrderControlResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="selectOrder"    column="select_order"    />
        <result property="status"    column="status"    />
        <result property="userId"    column="user_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="count"    column="count"    />
        <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"    />
        <result property="imgUrl" column="img_url" />
        <result property="filePath" column="file_path"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
    </resultMap>

    <resultMap type="com.fastbee.iot.model.vo.OrderControlVO" id="OrderControlVOResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="selectOrder"    column="select_order"    />
        <result property="status"    column="status"    />
        <result property="userId"    column="user_id"    />
        <result property="deviceId"    column="device_id"    />
        <result property="count"    column="count"    />
        <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"    />
        <result property="imgUrl" column="img_url" />
        <result property="filePath" column="file_path"/>
        <result property="startTime" column="start_time"/>
        <result property="endTime" column="end_time"/>
        <result property="deviceName" column="device_name" />
        <result property="userName" column="user_name" />
    </resultMap>

    <sql id="selectOrderControlVo">
        select id, tenant_id, select_order, status, user_id, device_id, count, create_by, create_time, update_by, update_time, remark,img_url,file_path,start_time,end_time from order_control
    </sql>

    <select id="selectOrderControlVoPage" parameterType="com.fastbee.iot.model.vo.OrderControlVO" resultMap="OrderControlVOResult">
        select c.id, c.tenant_id, c.select_order, c.status, c.user_id, c.device_id, c.count,
        c.create_by, c.create_time, c.update_by,
        c.update_time, c.remark,c.img_url,c.file_path,c.start_time,c.end_time,
        d.device_name, u.user_name
        from order_control c
        left join iot_device d on c.device_id = d.device_id
        left join sys_user u on c.user_id = u.user_id
        <where>
            <if test="orderControlVO.tenantId != null "> and c.tenant_id = #{orderControlVO.tenantId}</if>
            <if test="orderControlVO.selectOrder != null  and orderControlVO.selectOrder != ''"> and c.select_order = #{orderControlVO.selectOrder}</if>
            <if test="orderControlVO.status != null "> and c.status = #{orderControlVO.status}</if>
            <if test="orderControlVO.userId != null "> and c.user_id = #{orderControlVO.userId}</if>
            <if test="orderControlVO.deviceId != null "> and c.device_id = #{orderControlVO.deviceId}</if>
            <if test="orderControlVO.count != null "> and count = #{orderControlVO.count}</if>
        </where>
    </select>

</mapper>
