<?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.DeviceRepairRecordsMapper">
    <resultMap id="BaseResultMap" type="com.fuyuanshen.equipment.domain.vo.DeviceRepairRecordsVo">
        <id column="record_id" property="recordId"/>
        <result column="device_id" property="deviceId"/>
        <result column="deviceName" property="deviceName"/>
        <result column="repair_time" property="repairTime"/>
        <result column="repair_part" property="repairPart"/>
        <result column="repair_reason" property="repairReason"/>
        <result column="repair_person" property="repairPerson"/>
        <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>

    <!-- 查询所有设备类型 -->
    <select id="findAll" resultMap="BaseResultMap">
        SELECT DISTINCT dr.*,d.device_name as deviceName
        FROM device_repair_records dr
        JOIN device d ON dr.device_id = d.id
        <where>
            <if test="criteria.searchValue != null">
                and d.device_name like concat('%', TRIM(#{criteria.searchValue}), '%')
            </if>
            <if test="criteria.deviceId != null">
                and dr.device_id = #{criteria.deviceId}
            </if>
            <if test="criteria.repairPart != null">
                and dr.repair_part like concat('%', TRIM(#{criteria.repairPart}), '%')
            </if>
            <if test="criteria.repairPerson != null">
                and dr.repair_person like concat('%', TRIM(#{criteria.repairPerson}), '%')
            </if>
            <!-- 时间段条件 -->
            <if test="criteria.repairBeginTime != null">
                AND dr.repair_time <![CDATA[ >= ]]> #{criteria.repairBeginTime}
            </if>
            <if test="criteria.repairEndTime != null">
                <!-- 如果想默认包含当天 23:59:59，可在 Java 代码里把结束时间设为 endOfDay -->
                AND dr.repair_time <![CDATA[ <= ]]> #{criteria.repairEndTime}
            </if>
        </where>
        ORDER BY dr.create_time DESC
    </select>
</mapper>
