<?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.ktg.iscs.mapper.IsMaterialsCheckPlanMapper">

    <select id="getIsMaterialsCheckPlanPage" resultType="com.ktg.iscs.domain.IsMaterialsCheckPlan">
        SELECT * FROM (
        SELECT
        p.plan_id,
        p.plan_name,
        p.workstation_id,
        p.plan_date,
        p.check_user_id,
        p.status,
        u.nick_name as check_user_name
        FROM is_materials_check_plan p
        LEFT JOIN is_materials_plan_cabinet c ON c.plan_id = p.plan_id
        LEFT JOIN sys_user u ON u.user_id = p.check_user_id
        <where>
            <if test="dto.cabinetId != null">
                and c.cabinet_id = #{dto.cabinetId}
            </if>
            <if test="dto.startTime != null and dto.startTime.trim != ''">
                and p.plan_date &gt;= #{dto.startTime}
            </if>
            <if test="dto.endTime != null and dto.endTime.trim != ''">
                and p.plan_date &lt;= #{dto.endTime}
            </if>
            <if test="dto.checkUserName != null and dto.checkUserName.trim != ''">
                and u.nick_name like concat('%',#{dto.checkUserName},'%')
            </if>
            <if test="dto.status != null and dto.status.trim != ''">
                and p.status = #{dto.status}
            </if>
            <if test="dto.planName != null and dto.planName.trim != ''">
                and p.plan_name like concat('%',#{dto.planName},'%')
            </if>
        </where>
        GROUP BY p.plan_id, p.plan_name, p.workstation_id, p.plan_date, p.check_user_id, p.status, u.nick_name
        ) t
        ORDER BY t.plan_id DESC
    </select>
</mapper>
