<?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.fuyuanshen.equipment.mapper.DeviceAssignmentsMapper">

    <resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.DeviceAssignments">
        <id property="id" column="id"/>
        <result property="deviceId" column="device_id"/>
        <result property="fromCustomerId" column="from_customer_id"/>
        <result property="toCustomerId" column="to_customer_id"/>
        <result property="assignedAt" column="assigned_at"/>
        <result property="deviceTypeGranted" column="device_type_granted"/>
    </resultMap>

    <sql id="Base_Column_List">
        id
        ,device_id,from_customer_id,to_customer_id,assigned_at,device_type_granted
    </sql>


    <!-- 查询设备分配信息 -->
    <select id="deviceAssignmentsMapper" resultType="com.fuyuanshen.equipment.domain.DeviceAssignments"
            parameterType="com.fuyuanshen.equipment.domain.query.DeviceAssignmentQuery">
        SELECT *
        FROM device_assignments
        <where>
            <if test="query.deviceId != null">
                AND device_id = #{query.deviceId}
            </if>
            <if test="query.assigneeId != null">
                AND assignee_id = #{query.assigneeId}
            </if>
            <if test="query.active != null">
                AND active = #{query.active}
            </if>
            <if test="query.assignerId != null">
                AND assigner_id = #{query.assignerId}
            </if>
            <if test="query.lever != null">
                AND lever LIKE CONCAT('%', #{query.lever}, '%')
            </if>
        </where>
    </select>
</mapper>
