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

    <select id="getIsMaterialsInstructionsPage" resultType="com.ktg.iscs.domain.IsMaterialsInstructions">
        SELECT
            i.*,
            t.materials_type_name
        FROM
            is_materials_instructions i
            LEFT JOIN is_materials_type t ON t.materials_type_id = i.materials_type_id
            <where>
                <if test="isMaterialsInstructions.instructionsTitle != null and isMaterialsInstructions.instructionsTitle.trim != ''">
                    and i.instructions_title like concat('%',#{isMaterialsInstructions.instructionsTitle},'%')
                </if>
                <if test="isMaterialsInstructions.materialsTypeId != null">
                    and i.materials_type_id = #{isMaterialsInstructions.materialsTypeId}
                </if>
                <if test="isMaterialsInstructions.fileType != null and isMaterialsInstructions.fileType.trim != ''">
                    and i.file_type = #{isMaterialsInstructions.fileType}
                </if>
            </where>
            order by i.order_num asc, i.instructions_id desc
    </select>
</mapper>
