<?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.elephant.framework.galaxy.aroad.module.emergency.mapper.EmergencyEquipmentMapper">

    <resultMap id="emergencyEquipmentMap"
               type="com.elephant.framework.galaxy.aroad.module.emergency.entity.EmergencyEquipment">
        <id property="rowId" column="row_id"/>
        <result property="emergencyType" column="emergency_type"/>
        <result property="teamId" column="team_id"/>
        <result property="teamName" column="team_name"/>
        <result property="parentOrganizeId" column="parent_organize_id"/>
        <result property="parentOrganizeName" column="parent_organize_name"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="equipmentType" column="equipment_type"/>
        <result property="equipmentName" column="equipment_name"/>
        <result property="unit" column="unit"/>
        <result property="number" column="number"/>
        <result property="manager" column="manager"/>
        <result property="telephone" column="telephone"/>
        <result property="bz" column="bz"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="address" column="address"/>

<!--        <result column="t_longitude" property="longitude"/>-->
<!--        <result column="t_latitude" property="latitude"/>-->
<!--        <result column="t_team_name" property="teamName"/>-->
    </resultMap>

    <resultMap id="teamMap" type="com.elephant.framework.galaxy.aroad.module.emergency.dto.TeamEquipmentInfoDto">
        <id property="rowId" column="row_id"/>
        <result property="teamId" column="team_id"/>
        <result property="teamName" column="team_name"/>
        <result property="parentOrganizeName" column="parent_organize_name"/>
        <result property="parentOrganizeId" column="parent_organize_id"/>
    </resultMap>

    <select id="getEmergencyEquipmentPage" resultMap="emergencyEquipmentMap">
        select * from emergency_equipment
        <where>
            <if test="text != null">
                team_name like CONCAT('%',#{text},'%')
                or
                parent_organize_name like CONCAT('%',#{text},'%')
            </if>
        </where>
    </select>

    <select id="getCoordinates" resultMap="emergencyEquipmentMap">
        SELECT
        DISTINCT (team_id),longitude,latitude,address
        From emergency_equipment
        WHERE team_id
#         DISTINCT (t.team_id),
#         t.longitude AS t_longitude,
#         t.latitude AS t_latitude
#         FROM emergency_team_equipment t,emergency_equipment a
#         WHERE a.team_id=t.team_id AND t.team_id
        IN
        <foreach item="item" index="index" collection="teamids" open="(" separator="," close=")">
            #{item}
        </foreach>
    </select>

    <select id="getTeams" resultMap="teamMap">
        SELECT row_id, team_id, team_name,parent_organize_name,parent_organize_id
        FROM emergency_team_equipment;
    </select>
</mapper>
