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

    <resultMap id="emergencyCarMap" type="com.elephant.framework.galaxy.aroad.module.emergency.entity.EmergencyCar">
        <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="equipmentType" column="equipment_type"/>
        <result property="carName" column="car_name"/>
        <result property="unit" column="unit"/>
        <result property="carNumber" column="car_number"/>
        <result property="driver" column="driver"/>
        <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="getEmergencyCarPage" resultMap="emergencyCarMap">
        select * from emergency_car
        <where>
            <if test="text != null">
                team_name like CONCAT('%',#{text},'%')
                or
                parent_organize_name like CONCAT('%',#{text},'%')
            </if>
        </where>
    </select>

    <select id="getCoordinates" resultMap="emergencyCarMap">
        SELECT
        DISTINCT (team_id),longitude,latitude,address
        From emergency_car
        WHERE team_id
        # DISTINCT (t.team_id),
        # t.longitude AS t_longitude,
        # t.latitude AS t_latitude
        # FROM emergency_team_equipment t,emergency_car 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>
