<?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.tofly.gpsboot.mapper.emergency.EmergencyMapper">

    <resultMap id="emergencyMap" type="com.tofly.pojo.emergency.Emergency">
        <id property="id" column="ID"/>
        <result property="code" column="CODE"/>
        <result property="name" column="NAME"/>
        <result property="typeId" column="TYPE_ID"/>
        <result property="address" column="ADDRESS"/>
        <result property="note" column="NOTE"/>
        <result property="foundUserId" column="FOUND_USER_ID"/>
        <result property="foundTime" column="FOUND_TIME"/>
        <result property="isDispatching" column="IS_DISPATCHING"/>
        <result property="foundPhone" column="FOUND_PHONE"/>
        <result property="disUserId" column="DIS_USER_ID"/>
        <result property="synergyUserIds" column="SYNERGY_USER_IDS"/>
        <result property="isMessage" column="IS_MESSAGE"/>
        <result property="messageNote" column="MESSAGE_NOTE"/>
        <result property="state" column="STATE"/>
        <result property="dispatchingUserId" column="DISPATCHING_USER_ID"/>
        <result property="dispatchingTime" column="DISPATCHING_TIME"/>
        <result property="fileIds" column="FILE_IDS"/>
        <result property="x" column="X"/>
        <result property="y" column="Y"/>
        <result property="disPhone" column="DIS_PHONE"/>
        <association property="stateName" column="STATE" select="getStateName"/>
        <association property="typeName" column="TYPE_ID" select="com.tofly.gpsboot.mapper.emergency.EmergencyTypeMapper.getTypeName"/>
        <association property="foundUserName" column="FOUND_USER_ID" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="isDispatchingName" column="IS_DISPATCHING" select="com.tofly.gpsboot.mapper.plan.PlanMapper.getIsDispatchingName"/>
        <association property="disUserName" column="DIS_USER_ID" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="synergyUserNames" column="SYNERGY_USER_IDS" select="getSynergyUserNames"/>
        <association property="isMessageName" column="IS_MESSAGE" select="getIsMessageName"/>
        <association property="dispatchingUserName" column="DISPATCHING_USER_ID" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getRealName"/>
        <association property="fileIdsList" column="FILE_IDS" select="com.tofly.gpsboot.mapper.plan.HydrantrecordMapper.getFilePathList"/>
        <collection property="emergencyDisList" column="ID" select="com.tofly.gpsboot.mapper.emergency.EmergencyDisMapper.getEmergencyDisList"/>
    </resultMap>

    <select id="getSynergyUserNames" resultType="string" databaseId="oracle">
        select wm_concat(real_name)
        from TF_SMPN_USER_X
        where 1=1
        <if test="synergyUserIds != null and synergyUserIds != ''  "> and id in
            <foreach item="nodeCodestr" collection="synergyUserIds.split(',')" open="(" separator="," close=")">
                #{nodeCodestr}
            </foreach>
        </if>
    </select>
    <select id="getIsMessageName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =52300
          AND
            CCODE = #{isMessage}
    </select>
    <select id="getStateName" resultType="string">
        SELECT CNAME
        FROM
            TF_YWPN_SYSCHILDCODE_D
        WHERE
            PCID =52100
          AND
            CCODE = #{state}
    </select>
</mapper>
