<?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.yeejoin.equipmanage.mapper.EquipmentOnCarMapper">
    <select id="onCarIPage" resultType="com.yeejoin.equipmanage.common.vo.EquipmentOnCarVo">
        SELECT
        e.`name` AS equipmentName,
        ed.`name` AS equipmentSpecificName,
        oc.amount,
        ed.area,
        oc.id AS equipmentOnCarId,
        sd.warehouse_id AS warehouseId,
        sd.warehouse_structure_id AS warehouseStructureId,
        sd.id AS stockDetailId,
        es.code equipmentSpecificCode,
        CASE
        sd.`status`
        WHEN 10 THEN
        '车载' ELSE ''
        END AS `status`,
        oc.create_date
        FROM
        wl_equipment_on_car oc
        LEFT JOIN wl_equipment_specific es ON oc.equipment_specific_id = es.id
        LEFT JOIN wl_equipment_detail ed ON ed.id = es.equipment_detail_id
        LEFT JOIN wl_equipment e ON e.id = ed.equipment_id
        LEFT JOIN wl_stock_detail sd ON sd.id = oc.stock_detail_id
        <where>
            <if test="dto.carId != null">
                oc.car_id = #{dto.carId}
            </if>
            <if test="dto.teamId != null">
                AND es.team_id = #{dto.teamId}
            </if>
            <if test="dto.equipmentSpecificName != null and dto.equipmentSpecificName !=''">
                AND ed.`name` LIKE CONCAT( '%', #{dto.equipmentSpecificName}, '%' )
            </if>
            <if test="dto.createDate != null">
                AND TO_DAYS( oc.create_date ) = TO_DAYS( #{dto.createDate} )
            </if>
        </where>
    </select>
</mapper>
