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

    <resultMap id="emergencyTeamEquipmentMap"
               type="com.elephant.framework.galaxy.aroad.module.emergency.entity.EmergencyTeamEquipment">
        <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="organizeId" column="organize_id"/>
        <result property="organizeName" column="organize_name"/>
        <result property="parentOrganizeId" column="parent_organize_id"/>
        <result property="parentOrganizeName" column="parent_organize_name"/>
        <result property="address" column="address"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="departmentManager" column="department_manager"/>
        <result property="managerTelephone" column="manager_telephone"/>
        <result property="contactPeople" column="contact_people"/>
        <result property="contactTelephone" column="contact_telephone"/>
        <result property="peopleAmount" column="people_amount"/>
        <result property="carAmount" column="car_amount"/>
        <result property="equipmentAmount" column="equipment_amount"/>
        <result property="bz" column="bz"/>
    </resultMap>

    <resultMap id="teamEquipmentCoordinateMap"
               type="com.elephant.framework.galaxy.aroad.module.emergency.dto.TeamEquipmentCoordinateDto">
        <id column="row_id" property="rowId"/>
        <result column="longitude" property="longitude"/>
        <result column="latitude" property="latitude"/>
    </resultMap>

    <select id="getCoordinates" resultMap="teamEquipmentCoordinateMap">
        select row_id, longitude, latitude
        from `emergency_team_equipment`;
    </select>

    <insert id="save">
        insert into emergency_team_equipment (row_id, emergency_type, team_id, team_name, organize_id, organize_name,
                                              parent_organize_id, parent_organize_name, address, longitude, latitude,
                                              department_manager, manager_telephone, contact_people, contact_telephone,
                                              people_amount, car_amount, equipment_amount, bz)
        values (#{rowId}, #{emergencyType}, #{teamId}, #{teamName}, #{organizeId}, #{organizeName},
                #{parentOrganizeId}, #{parentOrganizeName}, #{equipmentAdress}, #{longitude}, #{latitude},
                #{departmentManager}, #{managerTelephone}, #{contactPeople}, #{contactTelephone},
                #{peopleAmount}, #{carAmount}, #{equipmentAmount}, #{bz});
    </insert>

    <update id="updateWithId">
        update emergency_team_equipment
        set emergency_type=#{emergencyType},
            team_name=#{teamName},
            organize_id=#{organizeId},
            organize_name=#{organizeName},
            parent_organize_id=#{parentOrganizeId},
            parent_organize_name=#{parentOrganizeName},
            address=#{equipmentAdress},
            longitude=#{longitude},
            latitude=#{latitude},
            department_manager=#{departmentManager},
            manager_telephone=#{managerTelephone},
            contact_people=#{contactPeople},
            contact_telephone=#{contactTelephone},
            people_amount=#{peopleAmount},
            car_amount=#{carAmount},
            equipment_amount=#{equipmentAmount},
            bz=#{bz}
        where team_id = #{teamId};
    </update>

</mapper>
