<?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.bonus.material.warningAnalysis.mapper.UseMaintenanceWarningMapper">

    <select id="getList" resultType="com.bonus.material.warningAnalysis.domain.UseMaintenanceWarningBean">
        SELECT
        mm.ma_id as maId,
        mm.next_check_time as nextCheckTime,
        mt2.type_name as typeName,
        mt.type_name as typeModelName,
        mm.ma_code as maCode,
        bu.unit_name as unitName,
        bp.pro_name as projectName,
        bai.agreement_code as agreementCode,
        DATEDIFF(CURDATE(), mm.next_check_time) AS overDays
        FROM
        ma_machine mm
        LEFT JOIN ma_type mt on mt.type_id=mm.type_id
        LEFT JOIN ma_type mt2 on mt2.type_id=mt.parent_id
        LEFT JOIN slt_agreement_info sai on sai.ma_id=mm.ma_id and mm.type_id=sai.type_id and sai.`status`='0' and
        sai.end_time is null
        LEFT JOIN bm_agreement_info bai on bai.agreement_id=sai.agreement_id
        LEFT JOIN bm_unit bu ON bai.unit_id = bu.unit_id
        AND bu.del_flag = '0'
        LEFT JOIN bm_project bp ON bai.project_id = bp.pro_id
        AND bp.del_flag = '0'
        WHERE
        mm.ma_status='2'
        and bp.pro_name is not null
        AND mm.next_check_time &lt; CURDATE()
        <if test="keyWord != null  and keyWord != ''">
            and (mt2.type_name like concat('%', #{keyWord}, '%') or
            mt.type_name like concat('%', #{keyWord}, '%') or
            mm.ma_code like concat('%', #{keyWord}, '%') or
            bu.unit_name like concat('%', #{keyWord}, '%') or
            bp.pro_name like concat('%', #{keyWord}, '%') or
            bai.agreement_code like concat('%', #{keyWord}, '%')
            )
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            AND DATE_FORMAT( mm.next_check_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
        </if>
        ORDER BY mm.next_check_time ASC
    </select>

</mapper>