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

	<select id="page"
		resultType="com.yeejoin.equipmanage.common.entity.EquipmentDetail">
		SELECT
		wed.id AS id,
		wec.name AS categoryName,
		wed.name,
		wed.code,
		wed.standard,
		wed.maintenance_cycle
		AS maintenanceCycle,
		wmi.name AS
		manufacturerName,
		wed.brand,
		wed.equipment_id AS equipmentId,
		wed.create_date AS createDate,
		wed.update_date AS
		updateDate,
		wlu.name unitName
		FROM
		wl_equipment_detail wed
		LEFT JOIN
		wl_equipment we ON we.id =
		wed.equipment_id
		LEFT JOIN
		wl_equipment_category wec ON wec.id =
		we.category_id
		LEFT JOIN
		wl_manufacturer_info wmi ON wmi.id =
		wed.manufacturer_id
		LEFT JOIN
		wl_unit wlu ON we.unit_id= wlu.id
		<where>
			<if test="equip!=null ">
				<if test="equip.name != null and equip.name != ''"> AND wed.name LIKE CONCAT('%',#{equip.name},'%' )</if>
				<if test="equip.standard != null and equip.standard != ''"> AND wed.standard LIKE CONCAT('%',#{equip.standard},'%'
					)
				</if>
				<if
					test="equip.manufacturerName != null and equip.manufacturerName != ''"> AND wmi.name LIKE CONCAT('%',#{equip.manufacturerName},'%' )
				</if>
			</if>
		</where>
		ORDER BY wed.id DESC
		LIMIT #{offset},#{size}
	</select>

	<select id="count" resultType="Integer">
		SELECT
		COUNT(1)
		FROM
		wl_equipment_detail wed
		LEFT JOIN wl_equipment we ON
		we.id =
		wed.equipment_id
		LEFT JOIN wl_equipment_category wec ON wec.id =
		we.category_id
		LEFT JOIN wl_manufacturer_info wmi ON wmi.id =
		wed.manufacturer_id
		<where>
			<if test="equip!=null ">
				<if test="equip.name != null and equip.name != ''"> AND wed.name LIKE CONCAT('%',#{equip.name},'%' )</if>
				<if test="equip.standard != null and equip.standard != ''"> AND wed.standard LIKE CONCAT('%',#{equip.standard},'%'
					)
				</if>
				<if
					test="equip.manufacturerName != null and equip.manufacturerName != ''"> AND wmi.name LIKE CONCAT('%',#{equip.manufacturerName},'%' )
				</if>
			</if>
		</where>
	</select>

	<select id="pageCategory"
		resultType="com.yeejoin.equipmanage.common.entity.EquipmentDetail">
		SELECT
		wed.id AS id,
		wec.name AS categoryName,
		wed.name,
		wed.code,
		wed.standard,
		wed.maintenance_cycle
		AS maintenanceCycle,
		wmi.name AS
		manufacturerName,
		wed.brand,
		wed.equipment_id AS equipmentId,
		wed.create_date AS
		createDate,
		wed.update_date AS updateDate
		FROM
		wl_equipment_detail wed
		LEFT JOIN
		wl_equipment we ON we.id =
		wed.equipment_id
		LEFT JOIN
		wl_equipment_category wec ON wec.id =
		we.category_id
		LEFT JOIN
		wl_manufacturer_info wmi ON wmi.id =
		wed.manufacturer_id
		<where>
			<if test="list!=null">
				AND we.category_id IN
				<foreach item="item" collection="list" separator=","
					open="(" close=")" index=""> #{item.id}
				</foreach>
			</if>
		</where>
		LIMIT #{offset},#{size}
	</select>

	<select id="countCategory" resultType="Integer">
		SELECT
		COUNT(1)
		FROM
		wl_equipment_detail wed
		LEFT JOIN
		wl_equipment we ON
		we.id =
		wed.equipment_id
		LEFT JOIN
		wl_equipment_category wec ON wec.id =
		we.category_id
		LEFT JOIN
		wl_manufacturer_info wmi ON wmi.id =
		wed.manufacturer_id
		<where>
			<if test="list!=null">
				AND we.category_id IN
				<foreach item="item" collection="list" separator=","
					open="(" close=")" index=""> #{item.id}
				</foreach>
			</if>
		</where>
		LIMIT #{offset},#{size}
	</select>

	<update id="quotaUpdate">
		update
		wl_equipment_index
		set perf_value =#{value}
		where id =#{equipmentIndexId}
	</update>
	<select id="getPref" resultType="String">
		 select
			 pref_quota
			 from
			 wl_equipment
			 where id=#{id}
	</select>

	<select id="checkDelete" resultType="String">
		select
		(select name from wl_equipment_detail eq where eq.id = sto.equipment_detail_id) as  name
		from wl_stock_detail as sto
		where
		equipment_detail_id = #{id}
		group by equipment_detail_id
	</select>
	<select id="getWareId" resultType="Long">
	 select  id from  wl_warehouse_structure where parent_id in(
		 select id from
		 wl_warehouse_structure
		 where
		 id = #{id}
		 or parent_id = #{id}
		 )
	</select>
</mapper>
