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


	<select id="page"
		resultType="com.yeejoin.equipmanage.common.entity.EquipmentQrcode">
		SELECT
		weq.id AS id,
		weq.equipment_detail_id AS equipmentDetailId,
		weq.q_r_code AS
		qRCode,
		weq.car_id AS carId,
		weq.product_date AS productDate,
		wsd.STATUS,
		wsd.update_date AS updateDate,
		wsd.create_date AS createDate,
		wws.full_name AS location
		FROM
		wl_equipment_qrcode weq
		LEFT
		JOIN wl_stock_detail wsd ON
		wsd.qr_code =
		weq.q_r_code
		LEFT JOIN
		wl_warehouse_structure wws ON wws.id =
		wsd.warehouse_structure_id
		<where>
			<if test="equipment.qRCode != null and equipment.qRCode != ''">
				AND weq.q_r_code LIKE CONCAT('%',#{equipment.qRCode},'%')
			</if>
			<if
				test="equipment.equipmentDetailId != null and equipment.equipmentDetailId != ''">
				AND weq.equipment_detail_id = #{equipment.equipmentDetailId}
			</if>
			<if test="equipment.status != null and equipment.status != ''">
				AND find_in_set(wsd.status,#{equipment.status})
			</if>
		</where>
		LIMIT #{start},#{size}
	</select>

	<select id="count" resultType="Integer">
		SELECT
		COUNT(1)
		FROM
		wl_equipment_qrcode weq
		LEFT JOIN wl_stock_detail wsd
		ON
		wsd.qr_code = weq.q_r_code
		LEFT JOIN
		wl_warehouse_structure wws ON wws.id = wsd.warehouse_structure_id
		<where>
			<if test="equipment.qRCode != null and equipment.qRCode != ''">
				AND weq.q_r_code LIKE CONCAT('%',#{equipment.qRCode},'%')
			</if>
			<if
				test="equipment.equipmentDetailId != null and equipment.equipmentDetailId != ''">
				AND weq.equipment_detail_id = #{equipment.equipmentDetailId}
			</if>
			<if test="equipment.status != null and equipment.status != ''">
				AND find_in_set(wsd.status,#{equipment.status})
			</if>
		</where>
	</select>
</mapper>
