<?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.IsMaterialsCheckRecordMapper">

    <select id="getIsMaterialsCheckRecordPage"
            resultType="com.ktg.iscs.domain.vo.checkRecord.IsMaterialsCheckRecordVO">
        SELECT
            r.*,
            m.materials_name,
            t.materials_type_name,
            t.materials_type_icon,
            t.materials_type_picture,
            m.materials_rfid,
            mc.cabinet_name,
            p.plan_name,
            u.nick_name as check_user_name
        FROM
            is_materials_check_record r
            LEFT JOIN is_materials_check_plan p ON p.plan_id = r.plan_id
            LEFT JOIN is_materials m ON m.materials_id = r.materials_id
            LEFT JOIN is_materials_cabinet mc ON mc.cabinet_id = r.cabinet_id
            LEFT JOIN is_materials_type t ON t.materials_type_id = m.materials_type_id
            LEFT JOIN sys_user u ON u.user_id = r.check_user_id
        <where>
            <if test="dto.planId != null">
                and r.plan_id = #{dto.planId}
            </if>
            <if test="dto.cabinetId != null">
                and m.materials_cabinet_id = #{dto.cabinetId}
            </if>
            <if test="dto.planName != null and dto.planName.trim != ''">
                and p.plan_name like concat('%',#{dto.planName},'%')
            </if>
            <if test="dto.materialsName != null and dto.materialsName.trim != ''">
                and m.materials_name like concat('%',#{dto.materialsName},'%')
            </if>
            <if test="dto.materialsTypeId != null">
                and m.materials_type_id = #{dto.materialsTypeId}
            </if>
            <if test="dto.materialsRfid != null and dto.materialsRfid.trim != ''">
                and m.materials_rfid like concat('%',#{dto.materialsRfid},'%')
            </if>
            <if test="dto.startTime != null and dto.startTime.trim != ''">
                and r.check_date &gt;= #{dto.startTime}
            </if>
            <if test="dto.endTime != null and dto.endTime.trim != ''">
                and r.check_date &lt;= #{dto.endTime}
            </if>
            <if test="dto.status != null and dto.status.trim != ''">
                and r.status = #{dto.status}
            </if>
            <if test="dto.reason != null and dto.reason.trim != ''">
                and r.reason = #{dto.reason}
            </if>
        </where>
        order by r.record_id desc
    </select>
    <select id="getCheckMaterialsByCabinetCode" resultType="com.ktg.iscs.domain.IsMaterialsCheckRecord">
        SELECT
            c.*,
            m.materials_rfid,
            t.materials_type_icon,
            t.materials_type_picture,
            t.materials_type_name,
            m.materials_name
        FROM
            is_materials_check_record c
                LEFT JOIN is_materials m ON c.materials_id = m.materials_id
                LEFT JOIN is_materials_type t ON t.materials_type_id = m.materials_type_id
        <where>
            c.plan_id = #{planId} and c.cabinet_id = #{cabinetId}
        </where>

    </select>
</mapper>
