<?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.repair.mapper.RepairEvaluateMapper">

    <resultMap type="com.repair.model.vo.EvaluateVo" id="repairEvaluatePageMap">
        <result property="id" column="id"/>
        <result property="recordNo" column="record_no"/>
        <result property="userName" column="user_name"/>
        <result property="userPhone" column="user_phone"/>
        <result property="description" column="description"/>
        <result property="reportTime" column="report_time"/>
        <result property="maintenancerName" column="maintenancer_name"/>
        <result property="star" column="star"/>
        <result property="content" column="content"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

    <select id="queryEvaluatePageList" resultType="com.repair.model.vo.EvaluateVo" resultMap="repairEvaluatePageMap">
        select
        re.id,rr.record_no,rr.user_name,rr.user_phone,rr.description,rr.report_time,rr.maintenancer_name,re.star,re.content,re.create_time
        from repair_evaluate re
        left join repair_record rr on rr.id = re.record_id and rr.deleted = 0
        <where>
            and re.deleted = 0
            <if test="keyWord != null and keyWord != ''">
                and (rr.user_name like '%' #{keyWord} '%' or rr.record_no like '%' #{keyWord} '%')
            </if>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
                and re.create_time BETWEEN #{startTime} and #{endTime}
            </if>
        </where>
        order by re.create_time desc
    </select>

    <resultMap type="com.repair.model.vo.RecordEvaluateVo" id="repairRecordEvaluateMap">
        <result property="id" column="id"/>
        <result property="userId" column="user_id"/>
        <result property="maintenancerId" column="maintenancer_id"/>
    </resultMap>
    <!--当前时间-24小时-->
    <select id="queryEvaluateList" resultType="com.repair.model.vo.RecordEvaluateVo" resultMap="repairRecordEvaluateMap">
        SELECT rr.id,rr.user_id,rr.maintenancer_id FROM repair_record rr
        where rr.deleted = 0 and rr.maintenance_state = 7 and rr.update_time &lt;= #{dateStr}
        and NOT EXISTS (select id from repair_evaluate where deleted = 0 and record_id = rr.id)
    </select>
</mapper>
