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

    <select id="getIsMachineryPage" resultType="com.ktg.iscs.domain.vo.machinery.IsMachineryVO">
        SELECT
        t.*,
        w.workstation_name,
        l.loto_name
        FROM
        is_machinery t
        LEFT JOIN is_workstation w ON w.workstation_id = t.workstation_id
        LEFT JOIN is_loto_station l ON l.loto_id = t.loto_id
        <where>
            <if test="isMachinery.machineryId != null">
                and t.machinery_id = #{isMachinery.machineryId}
            </if>
            <if test="isMachinery.machineryName != null and isMachinery.machineryName.trim != ''">
                and t.machinery_name like concat('%',#{isMachinery.machineryName},'%')
            </if>
            <if test="isMachinery.machineryCode != null and isMachinery.machineryCode.trim != ''">
                and t.machinery_code like concat('%',#{isMachinery.machineryCode},'%')
            </if>
            <if test="isMachinery.workstationId != null">
                and t.workstation_id = #{isMachinery.workstationId}
            </if>
            <if test="isMachinery.machineryType != null and isMachinery.machineryType.trim != ''">
                and t.machinery_type = #{isMachinery.machineryType}
            </if>
            <if test="isMachinery.parentId != null">
                and t.parent_id = #{isMachinery.parentId}
            </if>
        </where>
        ORDER BY
        t.machinery_id DESC
    </select>

</mapper>
