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



<select id="queryExtinguishantOnCarlist" resultType="Map" >
SELECT car.id as 'carId', (CASE WHEN car.car_num IS NOT NULL AND car.car_num != ''
				 THEN car.car_num ELSE '无车牌号' END) as 'carNum' FROM wl_car car 
				  WHERE car.car_state NOT IN
				  <foreach collection="list" item="names" open="(" close=")" separator=",">
					#{names}
				  </foreach>
				<!--  LEFT JOIN wl_system_dic system_dic ON car.car_state_id = system_dic.id 
				 WHERE system_dic.code NOT IN ('03','04','06','07','08')  -->
 
 
 
</select>


<select id="getCarExtinguishants" resultType="Map" >

SELECT table_1.car_id, 
  equipment_detail.name equipmentName, unit.name unitName, table_1.amount, table_1.equipment_detail_id equipmentDetailId,  
  (CASE WHEN equipment_detail.img IS NULL OR equipment_detail.img = '' THEN equipment.img ELSE equipment_detail.img END) img  
  FROM (SELECT SUM(amount) amount, equipment_detail_id, car_id FROM wl_extinguishant_on_car WHERE car_id =#{carId}
  GROUP  BY equipment_detail_id,car_id ) table_1 
  INNER JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = table_1.equipment_detail_id  
  INNER JOIN wl_equipment equipment ON equipment.id = equipment_detail.equipment_id  
  INNER JOIN wl_unit unit ON unit.id = equipment.unit_id  
  
	<where>
	<if test="code != null and code != '' ">
	  equipment_detail.code like  CONCAT(#{code},"%" )
	</if>
	<if test="codedate != null and codedate != '' ">
	 and equipment_detail.code like  CONCAT(#{codedate},"%" )
	</if>
	</where>
  LIMIT #{start},#{page}				 
</select>

<select id="getCarExtinguishantscount" resultType="Integer" >
		SELECT
			COUNT(1)
  FROM (SELECT SUM(amount) amount, equipment_detail_id, car_id FROM wl_extinguishant_on_car WHERE car_id =#{carId}
  GROUP  BY equipment_detail_id,car_id ) table_1
  INNER JOIN wl_equipment_detail equipment_detail ON equipment_detail.id = table_1.equipment_detail_id  
  INNER JOIN wl_equipment equipment ON equipment.id = equipment_detail.equipment_id  
  INNER JOIN wl_unit unit ON unit.id = equipment.unit_id  
  
	<where>
	<if test="code != null and code != '' ">
	  equipment_detail.code like  CONCAT(#{code},"%" )
	</if>
	<if test="codedate != null and codedate != '' ">
	 and equipment_detail.code like  CONCAT(#{codedate},"%" )
	</if>
	</where>
			 
</select>

</mapper>

