<?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.record.mapper.SltRecordQueryMapper">

    <select id="getList" resultType="com.bonus.material.settlement.domain.SltAgreementInfo">
        SELECT saa.create_time    as createTime,
               su.user_name       as createBy,
               bui.unit_id        AS unitId,
               bui.unit_name      AS unitName,
               bp.pro_id          AS projectId,
               bp.pro_name        AS projectName,
               bai.agreement_id   AS agreementId,
               bai.agreement_code AS agreementCode,
               saa.cost           AS costs,
               saa.`status`,
               saa.remark
        FROM slt_agreement_apply saa
                 LEFT JOIN sys_user su on su.user_id = saa.creator and su.del_flag = 0
                 LEFT JOIN bm_agreement_info bai on bai.agreement_id = saa.agreement_id
                 LEFT JOIN bm_project bp ON bp.pro_id = bai.project_id
                 LEFT JOIN bm_unit bui ON bui.unit_id = bai.unit_id
        WHERE saa.status in ('1', '2', '3')
        <if test="keyWord != null and keyWord != ''">
            AND (
            su.user_name LIKE concat('%', #{keyWord}, '%') or
            bui.unit_name LIKE concat('%', #{keyWord}, '%') or
            bp.pro_name LIKE concat('%', #{keyWord}, '%') or
            bai.agreement_code LIKE concat('%', #{keyWord}, '%') or
            saa.remark LIKE concat('%', #{keyWord}, '%')
            )
        </if>
        <if test="startTime != null and endTime != ''">
            AND DATE_FORMAT( saa.create_time, '%Y-%m-%d' ) BETWEEN #{startTime} AND #{endTime}
        </if>
        <if test="startDate != null and endDate != ''">
            AND DATE_FORMAT( saa.create_time, '%Y-%m-%d' ) BETWEEN #{startDate} AND #{endDate}
        </if>
        <if test="status != null">
            AND saa.status = #{status}
        </if>
        <if test="taskStatus != null">
            AND saa.status = #{taskStatus}
        </if>
        <if test="unitId != null and unitId != ''">
            AND bui.unit_id = #{unitId}
        </if>
        <if test="projectId != null and projectId != ''">
            AND bp.pro_id = #{projectId}
        </if>
        ORDER BY saa.update_time DESC
    </select>
</mapper>