<?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.EquipmentStandardMapper">
 <resultMap id="EquipmentStandardDetail" type="com.yeejoin.equipmanage.common.entity.vo.EquipmentStandardVO">
        <result column="id" property="id"></result>
        <result column="equipmentId" property="equipment_id"></result>
        <result column="equipmentName" property="equipment_name"></result>
        <result column="equipmentStyleCode" property="equipment_style_code"></result>
        <result column="equipmentStyleName" property="equipment_style_name"></result>
         <result column="standardName" property="standard_name"></result>
         <result column="standardKey" property="standard_key"></result>
    </resultMap>
<select id="findEquipmentStandardList"
            resultMap="EquipmentStandardDetail" >
       select
     	    equ_stand.id as id,
	        equ.code as equipment_code,
			equ.name as equipment_name,
			equ_cate.code as equipment_style_code,
			equ_cate.name as equipment_style_name,
			equ_stand.standard_name as standard_name
		from wl_equipment_standard equ_stand 
		left join  wl_equipment equ on equ_stand.equipment_id = equ.`id`
 		left join  wl_equipment_category equ_cate on equ.category_id = equ_cate.id
		where  equ_stand.org_code=#{orgCode} 
		  <if test="standardKey != null and standardKey != ''">
            AND equ_stand.standard_key = #{standardKey}
        </if>
        <if test="equipmentName != null and equipmentName != ''">
            AND equ.name like CONCAT('%',#{equipmentName},'%')
        </if>
		order by equ_stand.create_date desc	 
    </select>
    
    <select id="findById"
            resultMap="EquipmentStandardDetail" >
       select
     	    equ_stand.id as id,
			equ_stand.equipment_id as equipment_id,
			equ.name as equipment_name,
			equ_cate.code as equipment_style_code,
			equ_cate.name as equipment_style_name,
			equ_stand.standard_name as standard_name,
            equ_stand.standard_key as standard_key
		from wl_equipment_standard equ_stand 
			left join  wl_equipment equ 
				on  equ_stand.equipment_id = equ.`id`
 			 left join  wl_equipment_category equ_cate 
   				on  equ.category_id = equ_cate.id 
		where  equ_stand.id=#{id} 
    </select>
    
    <select id="getNoAddEquipmentStandardNameList"
            resultType="java.util.Map" parameterType="java.lang.String">
   		
		     	SELECT equ.id,equ.code ,equ.`name` from wl_equipment equ
               			 where not EXISTS (select euq_stand.equipment_id from wl_equipment_standard euq_stand where euq_stand.org_code=#{orgCode} and equ.id = euq_stand.equipment_id)
		
    </select>
</mapper>
