<?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.xrtymis.mapper.GdpersonMapper">

    <resultMap id="gdpersonMap" type="com.tofly.xrtymis.entity.Gdperson">
        <id property="id" column="ID"/>
        <result property="node" column="NODE"/>
        <result property="childNode" column="CHILD_NODE"/>
        <result property="configId" column="CONFIG_ID"/>
        <result property="departId" column="DEPART_ID"/>
        <result property="departName" column="DEPART_NAME"/>
        <result property="personId" column="PERSON_ID"/>
        <result property="personName" column="PERSON_NAME"/>
        <association property="phone" column="PERSON_ID"
                     select="getUserPhone"/>
    </resultMap>

    <select id="getUserPhone" resultType="string">
        SELECT PHONE
        FROM TF_SMPN_USER_X
        WHERE id = #{personId}
    </select>
    <select id="personMaxId" resultType="java.lang.Long">
        select nvl(max(id), 0) + 1
        from TF_YWPN_GDPERSON_W
    </select>

    <insert id="insertBatchPerson">
        insert into TF_YWPN_GDPERSON_W(ID , CONFIG_ID , DEPART_ID , DEPART_NAME , PERSON_ID , PERSON_NAME , NODE ,
        CHILD_NODE)
        <foreach collection="list" item="info" separator="union all">
            SELECT
            #{info.id},
            #{info.configId},
            #{info.departId},
            #{info.departName},
            #{info.personId},
            #{info.personName},
            #{info.node},
            #{info.childNode,jdbcType=NUMERIC}
            FROM DUAL
        </foreach>
    </insert>

    <select id="getGdperson" resultMap="gdpersonMap">
        SELECT * FROM(SELECT * FROM TF_YWPN_GDPERSON_W where CONFIG_ID = #{gdlcid} and NODE = #{node}
                     ) WHERE rownum=1
    </select>

</mapper>
