<?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.sgzb.material.mapper.InputRecordMapper">

    <select id="getInputRecordList" resultType="com.bonus.sgzb.material.domain.InputRecord">
        SELECT mt2.type_name   as typeName,
               mt.type_name    as typeModelName,
               mm.qr_code      as qrCode,
               mm.ma_code      as maCode,
               mt.unit_name    as unit,
               iad.input_num   as inputNum,
               iad.create_time as createTime,
               su.user_name    as userName,
               CASE iad.input_type
                   WHEN 1 THEN
                       '新购入库'
                   WHEN 2 THEN
                       '退料入库'
                   WHEN 3 THEN
                       '修试后入库'
                   WHEN 4 THEN
                       '盘点入库'
                   ELSE
                       ''
                   END            inputType

        FROM input_apply_details iad
                 LEFT JOIN ma_type mt on mt.type_id = iad.type_id
                 LEFT JOIN ma_type mt2 on mt2.type_id = mt.parent_id
                 LEFT JOIN ma_machine mm on mm.ma_id = iad.ma_id
                 LEFT JOIN sys_user su on su.user_id = iad.create_by
        where 1 = 1
        <if test="keyWord != null and keyWord != ''">
            and (mt2.type_name like concat('%',#{keyWord},'%') or
            mt.type_name like concat('%',#{keyWord},'%') or
            mm.ma_code like concat('%',#{keyWord},'%') or
            mt.unit_name like concat('%',#{keyWord},'%') or
            su.user_name like concat('%',#{keyWord},'%') or
            mm.qr_code like concat('%',#{keyWord},'%'))
        </if>
        <if test="typeName != null and typeName != ''">
            and mt2.type_name like concat('%',#{typeName},'%')
        </if>
        <if test="typeModelName != null and typeModelName != ''">
            and mt.type_name like concat('%',#{typeModelName},'%')
        </if>
        <if test="startTime != null and startTime != '' and endTime != null and endTime != ''">
            AND iad.create_time BETWEEN CONCAT(#{startTime}, ' 00:00:00') AND CONCAT(#{endTime}, ' 23:59:59')
        </if>
    </select>
</mapper>